From fb46273d1535f6ccb9dcbc68acbfbf7cfb1a0446 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Tue, 14 Jul 2020 00:39:08 +0300 Subject: [PATCH 1/5] restrict leading zero before separator for decimal integers --- src/tokenizer.ts | 12 +++++++----- tests/parser/numeric-separators.ts | 5 ++++- tests/parser/numeric-separators.ts.fixture.ts | 4 ++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/tokenizer.ts b/src/tokenizer.ts index 02f8dae7da..e201e8b653 100644 --- a/src/tokenizer.ts +++ b/src/tokenizer.ts @@ -1362,6 +1362,11 @@ export class Tokenizer extends DiagnosticEmitter { : DiagnosticCode.Multiple_consecutive_numeric_separators_are_not_permitted, this.range(pos) ); + } else if (pos - 1 == start && text.charCodeAt(pos - 1) == CharCode._0) { + this.error( + DiagnosticCode.Numeric_separators_are_not_allowed_here, + this.range(pos) + ); } sepEnd = pos + 1; } else { @@ -1497,9 +1502,7 @@ export class Tokenizer extends DiagnosticEmitter { var text = this.source.text; var end = this.end; var start = this.pos; - var sepCount = 0; - - sepCount += this.readDecimalFloatPartial(false); + var sepCount = this.readDecimalFloatPartial(false); if (this.pos < end && text.charCodeAt(this.pos) == CharCode.DOT) { ++this.pos; sepCount += this.readDecimalFloatPartial(); @@ -1518,7 +1521,7 @@ export class Tokenizer extends DiagnosticEmitter { } } let result = text.substring(start, this.pos); - if (sepCount > 0) result = result.replaceAll("_", ""); + if (sepCount) result = result.replaceAll("_", ""); return parseFloat(result); } @@ -1553,7 +1556,6 @@ export class Tokenizer extends DiagnosticEmitter { } else if (!isDecimalDigit(c)) { break; } - ++pos; } diff --git a/tests/parser/numeric-separators.ts b/tests/parser/numeric-separators.ts index 3341aef2fa..984b7429f1 100644 --- a/tests/parser/numeric-separators.ts +++ b/tests/parser/numeric-separators.ts @@ -35,6 +35,9 @@ 1e2_; // 6188 1e-1__0; // 6189 +0_0; // 6188 0_0.0; // 6188 0_0.0_0; // 6188 -0_0e0_0; // 6188 \ No newline at end of file +0_0e0_0; // 6188 + +0x_12_12_12; // 6188 \ No newline at end of file diff --git a/tests/parser/numeric-separators.ts.fixture.ts b/tests/parser/numeric-separators.ts.fixture.ts index a0cb362767..6590456114 100644 --- a/tests/parser/numeric-separators.ts.fixture.ts +++ b/tests/parser/numeric-separators.ts.fixture.ts @@ -28,6 +28,8 @@ 0; 0; 0; +0; +1184274; // ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(14,9+0) // ERROR 6189: "Multiple consecutive numeric separators are not permitted." in numeric-separators.ts(15,4+0) // ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(17,11+0) @@ -48,3 +50,5 @@ // ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(38,2+0) // ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(39,2+0) // ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(40,2+0) +// ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(41,2+0) +// ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(43,3+0) From b1766364d82f35a6ff1161de3005f0943b57f7de Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Tue, 14 Jul 2020 09:54:22 +0300 Subject: [PATCH 2/5] more tests --- tests/parser/numeric-separators.ts | 4 +++- tests/parser/numeric-separators.ts.fixture.ts | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/parser/numeric-separators.ts b/tests/parser/numeric-separators.ts index 984b7429f1..6f0a5828d5 100644 --- a/tests/parser/numeric-separators.ts +++ b/tests/parser/numeric-separators.ts @@ -40,4 +40,6 @@ 0_0.0_0; // 6188 0_0e0_0; // 6188 -0x_12_12_12; // 6188 \ No newline at end of file +0x_11_11; // 6188 +0o_11_11; // 6188 +0b_11_11; // 6188 \ No newline at end of file diff --git a/tests/parser/numeric-separators.ts.fixture.ts b/tests/parser/numeric-separators.ts.fixture.ts index 6590456114..d9ffbd9f5b 100644 --- a/tests/parser/numeric-separators.ts.fixture.ts +++ b/tests/parser/numeric-separators.ts.fixture.ts @@ -29,7 +29,9 @@ 0; 0; 0; -1184274; +4369; +585; +15; // ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(14,9+0) // ERROR 6189: "Multiple consecutive numeric separators are not permitted." in numeric-separators.ts(15,4+0) // ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(17,11+0) @@ -52,3 +54,5 @@ // ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(40,2+0) // ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(41,2+0) // ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(43,3+0) +// ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(44,3+0) +// ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(45,3+0) From 2fbc563fabf3512c5eb01d93ae9e5bde2929c5ab Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Wed, 15 Jul 2020 08:59:26 +0300 Subject: [PATCH 3/5] refactor readIdentifier --- src/tokenizer.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/tokenizer.ts b/src/tokenizer.ts index e201e8b653..7d070b1967 100644 --- a/src/tokenizer.ts +++ b/src/tokenizer.ts @@ -1052,13 +1052,15 @@ export class Tokenizer extends DiagnosticEmitter { readIdentifier(): string { var text = this.source.text; - var start = this.pos; var end = this.end; + var pos = this.pos; + var start = pos; while ( - ++this.pos < end && - isIdentifierPart(text.charCodeAt(this.pos)) + ++pos < end && + isIdentifierPart(text.charCodeAt(pos)) ); - return text.substring(start, this.pos); + this.pos = pos; + return text.substring(start, pos); } readString(): string { From 8d762756f588906396d234ca1883648861c91a7c Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Wed, 15 Jul 2020 18:51:05 +0300 Subject: [PATCH 4/5] add double leading zeros test --- tests/parser/numeric-separators.ts | 4 +++- tests/parser/numeric-separators.ts.fixture.ts | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/parser/numeric-separators.ts b/tests/parser/numeric-separators.ts index 6f0a5828d5..738bc2e893 100644 --- a/tests/parser/numeric-separators.ts +++ b/tests/parser/numeric-separators.ts @@ -42,4 +42,6 @@ 0x_11_11; // 6188 0o_11_11; // 6188 -0b_11_11; // 6188 \ No newline at end of file +0b_11_11; // 6188 + +00_1 // 1121 diff --git a/tests/parser/numeric-separators.ts.fixture.ts b/tests/parser/numeric-separators.ts.fixture.ts index d9ffbd9f5b..e92309190a 100644 --- a/tests/parser/numeric-separators.ts.fixture.ts +++ b/tests/parser/numeric-separators.ts.fixture.ts @@ -32,6 +32,7 @@ 4369; 585; 15; +1; // ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(14,9+0) // ERROR 6189: "Multiple consecutive numeric separators are not permitted." in numeric-separators.ts(15,4+0) // ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(17,11+0) @@ -56,3 +57,4 @@ // ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(43,3+0) // ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(44,3+0) // ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(45,3+0) +// ERROR 1121: "Octal literals are not allowed in strict mode." in numeric-separators.ts(47,1+4) From 5e0e9e4720cb9a9d4693b48244acbee24b8111fd Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Wed, 15 Jul 2020 19:13:03 +0300 Subject: [PATCH 5/5] commit again --- tests/parser/numeric-separators.ts | 2 +- tests/parser/numeric-separators.ts.fixture.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/parser/numeric-separators.ts b/tests/parser/numeric-separators.ts index 738bc2e893..05037b0034 100644 --- a/tests/parser/numeric-separators.ts +++ b/tests/parser/numeric-separators.ts @@ -44,4 +44,4 @@ 0o_11_11; // 6188 0b_11_11; // 6188 -00_1 // 1121 +00_01 // 1121 diff --git a/tests/parser/numeric-separators.ts.fixture.ts b/tests/parser/numeric-separators.ts.fixture.ts index e92309190a..acc3384c8f 100644 --- a/tests/parser/numeric-separators.ts.fixture.ts +++ b/tests/parser/numeric-separators.ts.fixture.ts @@ -57,4 +57,4 @@ // ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(43,3+0) // ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(44,3+0) // ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(45,3+0) -// ERROR 1121: "Octal literals are not allowed in strict mode." in numeric-separators.ts(47,1+4) +// ERROR 1121: "Octal literals are not allowed in strict mode." in numeric-separators.ts(47,1+5)