mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-26 20:14:05 -05:00
Address code review
This commit is contained in:
@@ -125,8 +125,8 @@ module ts {
|
||||
Unterminated_template_literal: { code: 1160, category: DiagnosticCategory.Error, key: "Unterminated template literal." },
|
||||
Unterminated_regular_expression_literal: { code: 1161, category: DiagnosticCategory.Error, key: "Unterminated regular expression literal." },
|
||||
An_object_member_cannot_be_declared_optional: { code: 1162, category: DiagnosticCategory.Error, key: "An object member cannot be declared optional." },
|
||||
Binary_digits_expected: { code: 1163, category: DiagnosticCategory.Error, key: "Binary digits expected." },
|
||||
Octal_digits_expected: { code: 1164, category: DiagnosticCategory.Error, key: "Octal digits expected." },
|
||||
Binary_digit_expected: { code: 1163, category: DiagnosticCategory.Error, key: "Binary digit expected." },
|
||||
Octal_digit_expected: { code: 1164, category: DiagnosticCategory.Error, key: "Octal digit expected." },
|
||||
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
|
||||
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
|
||||
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },
|
||||
|
||||
@@ -491,11 +491,11 @@
|
||||
"category": "Error",
|
||||
"code": 1162
|
||||
},
|
||||
"Binary digits expected.": {
|
||||
"Binary digit expected.": {
|
||||
"category": "Error",
|
||||
"code": 1163
|
||||
},
|
||||
"Octal digits expected.": {
|
||||
"Octal digit expected.": {
|
||||
"category": "Error",
|
||||
"code": 1164
|
||||
},
|
||||
|
||||
@@ -788,6 +788,18 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function isBinaryOrOctalIntegerLiteral(text: string): boolean {
|
||||
if (text.length <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (text.charCodeAt(1) === CharacterCodes.B || text.charCodeAt(1) === CharacterCodes.b ||
|
||||
text.charCodeAt(1) === CharacterCodes.O || text.charCodeAt(1) === CharacterCodes.o) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function emitLiteral(node: LiteralExpression): void {
|
||||
var text = getLiteralText();
|
||||
|
||||
@@ -795,9 +807,7 @@ module ts {
|
||||
writer.writeLiteral(text);
|
||||
}
|
||||
// For version below ES6, emit binary integer literal and octal integer literal as decimal value
|
||||
else if (compilerOptions.target < ScriptTarget.ES6 && node.kind === SyntaxKind.NumericLiteral &&
|
||||
((text.charCodeAt(1) === CharacterCodes.B || text.charCodeAt(1) === CharacterCodes.b ||
|
||||
text.charCodeAt(1) === CharacterCodes.O || text.charCodeAt(1) === CharacterCodes.o))) {
|
||||
else if (compilerOptions.target < ScriptTarget.ES6 && node.kind === SyntaxKind.NumericLiteral && isBinaryOrOctalIntegerLiteral(text)) {
|
||||
write(node.text);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -520,27 +520,6 @@ module ts {
|
||||
return +(text.substring(start, pos));
|
||||
}
|
||||
|
||||
function scanBinaryOrOctalDigits(base: number): number {
|
||||
if (base !== 2 && base !== 8) {
|
||||
return -1;
|
||||
}
|
||||
var value = 0;
|
||||
while (true) {
|
||||
var ch = text.charCodeAt(pos);
|
||||
var valueOfCh = ch - CharacterCodes._0;
|
||||
if (!isDigit(ch)) {
|
||||
break;
|
||||
}
|
||||
// We know at this point that ch must be digit
|
||||
if (valueOfCh >= base) {
|
||||
return -1;
|
||||
}
|
||||
value = value * base + valueOfCh;
|
||||
pos++;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function scanHexDigits(count: number, mustMatchCount?: boolean): number {
|
||||
var digits = 0;
|
||||
var value = 0;
|
||||
@@ -774,6 +753,26 @@ module ts {
|
||||
return token = SyntaxKind.Identifier;
|
||||
}
|
||||
|
||||
function scanBinaryOrOctalDigits(base: number): number {
|
||||
Debug.assert(base !== 2 || base !== 8, "Expected either base 2 or base 8");
|
||||
|
||||
var value = 0;
|
||||
while (true) {
|
||||
var ch = text.charCodeAt(pos);
|
||||
var valueOfCh = ch - CharacterCodes._0;
|
||||
if (!isDigit(ch)) {
|
||||
break;
|
||||
}
|
||||
// We know at this point that ch must be digit
|
||||
if (valueOfCh >= base) {
|
||||
break;
|
||||
}
|
||||
value = value * base + valueOfCh;
|
||||
pos++;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function scan(): SyntaxKind {
|
||||
startPos = pos;
|
||||
precedingLineBreak = false;
|
||||
@@ -956,9 +955,9 @@ module ts {
|
||||
}
|
||||
else if (pos + 2 < len && (text.charCodeAt(pos + 1) === CharacterCodes.B || text.charCodeAt(pos + 1) === CharacterCodes.b)) {
|
||||
pos += 2;
|
||||
var value = scanBinaryOrOctalDigits(/* binary */2);
|
||||
var value = scanBinaryOrOctalDigits(/* base */ 2);
|
||||
if (value < 0) {
|
||||
error(Diagnostics.Binary_digits_expected);
|
||||
error(Diagnostics.Binary_digit_expected);
|
||||
value = 0;
|
||||
}
|
||||
tokenValue = "" + value;
|
||||
@@ -966,9 +965,9 @@ module ts {
|
||||
}
|
||||
else if (pos + 2 < len && (text.charCodeAt(pos + 1) === CharacterCodes.O || text.charCodeAt(pos + 1) === CharacterCodes.o)) {
|
||||
pos += 2;
|
||||
var value = scanBinaryOrOctalDigits(/* octal */8);
|
||||
var value = scanBinaryOrOctalDigits(/* base */ 8);
|
||||
if (value < 0) {
|
||||
error(Diagnostics.Octal_digits_expected);
|
||||
error(Diagnostics.Octal_digit_expected);
|
||||
value = 0;
|
||||
}
|
||||
tokenValue = "" + value;
|
||||
|
||||
Reference in New Issue
Block a user