mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00: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
|
||||
},
|
||||
|
||||
+13
-3
@@ -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 {
|
||||
|
||||
+24
-25
@@ -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;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
tests/cases/conformance/es6/binaryAndOctalIntegerLiteral/binaryIntegerLiteralError.ts(2,17): error TS1163: Binary digits expected.
|
||||
tests/cases/conformance/es6/binaryAndOctalIntegerLiteral/binaryIntegerLiteralError.ts(3,17): error TS1163: Binary digits expected.
|
||||
tests/cases/conformance/es6/binaryAndOctalIntegerLiteral/binaryIntegerLiteralError.ts(2,17): error TS1005: ',' expected.
|
||||
tests/cases/conformance/es6/binaryAndOctalIntegerLiteral/binaryIntegerLiteralError.ts(3,17): error TS1005: ',' expected.
|
||||
tests/cases/conformance/es6/binaryAndOctalIntegerLiteral/binaryIntegerLiteralError.ts(6,5): error TS2300: Duplicate identifier '0b11010'.
|
||||
tests/cases/conformance/es6/binaryAndOctalIntegerLiteral/binaryIntegerLiteralError.ts(7,5): error TS2300: Duplicate identifier '26'.
|
||||
tests/cases/conformance/es6/binaryAndOctalIntegerLiteral/binaryIntegerLiteralError.ts(8,5): error TS2300: Duplicate identifier '"26"'.
|
||||
@@ -8,11 +8,11 @@ tests/cases/conformance/es6/binaryAndOctalIntegerLiteral/binaryIntegerLiteralErr
|
||||
==== tests/cases/conformance/es6/binaryAndOctalIntegerLiteral/binaryIntegerLiteralError.ts (5 errors) ====
|
||||
// error
|
||||
var bin1 = 0B1102110;
|
||||
|
||||
!!! error TS1163: Binary digits expected.
|
||||
~~~~
|
||||
!!! error TS1005: ',' expected.
|
||||
var bin1 = 0b11023410;
|
||||
|
||||
!!! error TS1163: Binary digits expected.
|
||||
~~~~~
|
||||
!!! error TS1005: ',' expected.
|
||||
|
||||
var obj1 = {
|
||||
0b11010: "hi",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
tests/cases/conformance/es6/binaryAndOctalIntegerLiteral/octalIntegerLiteralError.ts(2,19): error TS1164: Octal digits expected.
|
||||
tests/cases/conformance/es6/binaryAndOctalIntegerLiteral/octalIntegerLiteralError.ts(3,18): error TS1164: Octal digits expected.
|
||||
tests/cases/conformance/es6/binaryAndOctalIntegerLiteral/octalIntegerLiteralError.ts(2,19): error TS1005: ',' expected.
|
||||
tests/cases/conformance/es6/binaryAndOctalIntegerLiteral/octalIntegerLiteralError.ts(3,18): error TS1005: ',' expected.
|
||||
tests/cases/conformance/es6/binaryAndOctalIntegerLiteral/octalIntegerLiteralError.ts(6,5): error TS2300: Duplicate identifier '0O45436'.
|
||||
tests/cases/conformance/es6/binaryAndOctalIntegerLiteral/octalIntegerLiteralError.ts(7,5): error TS2300: Duplicate identifier '19230'.
|
||||
tests/cases/conformance/es6/binaryAndOctalIntegerLiteral/octalIntegerLiteralError.ts(8,5): error TS2300: Duplicate identifier '"19230"'.
|
||||
@@ -8,11 +8,11 @@ tests/cases/conformance/es6/binaryAndOctalIntegerLiteral/octalIntegerLiteralErro
|
||||
==== tests/cases/conformance/es6/binaryAndOctalIntegerLiteral/octalIntegerLiteralError.ts (5 errors) ====
|
||||
// error
|
||||
var oct1 = 0O13334823;
|
||||
|
||||
!!! error TS1164: Octal digits expected.
|
||||
~~~
|
||||
!!! error TS1005: ',' expected.
|
||||
var oct2 = 0o34318592;
|
||||
|
||||
!!! error TS1164: Octal digits expected.
|
||||
~~~~
|
||||
!!! error TS1005: ',' expected.
|
||||
|
||||
var obj1 = {
|
||||
0O45436: "hi",
|
||||
|
||||
Reference in New Issue
Block a user