Skip to content

Commit 4bb38a8

Browse files
Remove strict mode and target check; Refactoring
1 parent d1ba506 commit 4bb38a8

File tree

68 files changed

+1757
-3878
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1757
-3878
lines changed

src/compiler/binder.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ import {
237237
nodeIsPresent,
238238
NonNullChain,
239239
NonNullExpression,
240-
NumericLiteral,
241240
objectAllocator,
242241
ObjectLiteralExpression,
243242
OptionalChain,
@@ -278,7 +277,6 @@ import {
278277
SyntaxKind,
279278
TextRange,
280279
ThrowStatement,
281-
TokenFlags,
282280
tokenToString,
283281
tracing,
284282
TracingNode,
@@ -2627,19 +2625,6 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
26272625
}
26282626
}
26292627

2630-
function checkStrictModeStringLiteral(node: StringLiteral) {
2631-
if (languageVersion >= ScriptTarget.ES5 && inStrictMode && node.rangesOfOctalSequences) {
2632-
file.bindDiagnostics.push(...node.rangesOfOctalSequences.map(
2633-
range => createFileDiagnostic(file, range.pos, range.end - range.pos, Diagnostics.Octal_escape_sequences_are_not_allowed_in_strict_mode)));
2634-
}
2635-
}
2636-
2637-
function checkStrictModeNumericLiteral(node: NumericLiteral) {
2638-
if (languageVersion >= ScriptTarget.ES5 && inStrictMode && node.numericLiteralFlags & TokenFlags.Octal) {
2639-
file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Octal_literals_are_not_allowed_in_strict_mode));
2640-
}
2641-
}
2642-
26432628
function checkStrictModePostfixUnaryExpression(node: PostfixUnaryExpression) {
26442629
// Grammar checking
26452630
// The identifier eval or arguments may not appear as the LeftHandSideExpression of an
@@ -2882,10 +2867,6 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
28822867
return checkStrictModeCatchClause(node as CatchClause);
28832868
case SyntaxKind.DeleteExpression:
28842869
return checkStrictModeDeleteExpression(node as DeleteExpression);
2885-
case SyntaxKind.StringLiteral:
2886-
return checkStrictModeStringLiteral(node as StringLiteral);
2887-
case SyntaxKind.NumericLiteral:
2888-
return checkStrictModeNumericLiteral(node as NumericLiteral);
28892870
case SyntaxKind.PostfixUnaryExpression:
28902871
return checkStrictModePostfixUnaryExpression(node as PostfixUnaryExpression);
28912872
case SyntaxKind.PrefixUnaryExpression:

src/compiler/checker.ts

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,6 @@ import {
434434
isCatchClause,
435435
isCatchClauseVariableDeclarationOrBindingElement,
436436
isCheckJsEnabledForFile,
437-
isChildOfNodeWithKind,
438437
isClassDeclaration,
439438
isClassElement,
440439
isClassExpression,
@@ -46922,33 +46921,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4692246921
return false;
4692346922
}
4692446923

46925-
function checkGrammarNumericLiteral(node: NumericLiteral): boolean {
46926-
// Grammar checking
46927-
if (node.numericLiteralFlags & TokenFlags.Octal) {
46928-
let diagnosticMessage: DiagnosticMessage | undefined;
46929-
if (languageVersion >= ScriptTarget.ES5) {
46930-
diagnosticMessage = Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0;
46931-
}
46932-
else if (isChildOfNodeWithKind(node, SyntaxKind.LiteralType)) {
46933-
diagnosticMessage = Diagnostics.Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0;
46934-
}
46935-
else if (isChildOfNodeWithKind(node, SyntaxKind.EnumMember)) {
46936-
diagnosticMessage = Diagnostics.Octal_literals_are_not_allowed_in_enums_members_initializer_Use_the_syntax_0;
46937-
}
46938-
if (diagnosticMessage) {
46939-
const withMinus = isPrefixUnaryExpression(node.parent) && node.parent.operator === SyntaxKind.MinusToken;
46940-
const literal = (withMinus ? "-" : "") + "0o" + node.text;
46941-
return grammarErrorOnNode(withMinus ? node.parent : node, diagnosticMessage, literal);
46942-
}
46943-
}
46944-
46924+
function checkGrammarNumericLiteral(node: NumericLiteral) {
4694546925
// Realism (size) checking
46946-
checkNumericLiteralValueSize(node);
46947-
46948-
return false;
46949-
}
46950-
46951-
function checkNumericLiteralValueSize(node: NumericLiteral) {
4695246926
// We should test against `getTextOfNode(node)` rather than `node.text`, because `node.text` for large numeric literals can contain "."
4695346927
// e.g. `node.text` for numeric literal `1100000000000000000000` is `1.1e21`.
4695446928
const isFractional = getTextOfNode(node).indexOf(".") !== -1;

src/compiler/diagnosticMessages.json

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,6 @@
227227
"category": "Error",
228228
"code": 1084
229229
},
230-
"Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '{0}'.": {
231-
"category": "Error",
232-
"code": 1085
233-
},
234230
"'{0}' modifier cannot appear on a constructor declaration.": {
235231
"category": "Error",
236232
"code": 1089
@@ -351,7 +347,7 @@
351347
"category": "Error",
352348
"code": 1120
353349
},
354-
"Octal literals are not allowed in strict mode.": {
350+
"Octal literals are not allowed. Use the syntax '{0}'.": {
355351
"category": "Error",
356352
"code": 1121
357353
},
@@ -1549,14 +1545,18 @@
15491545
"category": "Message",
15501546
"code": 1483
15511547
},
1552-
"Octal escape sequences are not allowed in strict mode.": {
1548+
"Octal escape sequences are not allowed. Use the syntax '{0}'.": {
15531549
"category": "Error",
15541550
"code": 1484
15551551
},
1556-
"Octal escape sequences are not allowed in template strings.": {
1552+
"'{0}' is not allowed.": {
15571553
"category": "Error",
15581554
"code": 1485
15591555
},
1556+
"Decimals with leading zeros are not allowed.": {
1557+
"category": "Error",
1558+
"code": 1486
1559+
},
15601560

15611561
"The types of '{0}' are incompatible between these types.": {
15621562
"category": "Error",
@@ -6332,14 +6332,6 @@
63326332
"category": "Error",
63336333
"code": 8016
63346334
},
6335-
"Octal literal types must use ES2015 syntax. Use the syntax '{0}'.": {
6336-
"category": "Error",
6337-
"code": 8017
6338-
},
6339-
"Octal literals are not allowed in enums members initializer. Use the syntax '{0}'.": {
6340-
"category": "Error",
6341-
"code": 8018
6342-
},
63436335
"Report errors in .js files.": {
63446336
"category": "Message",
63456337
"code": 8019

src/compiler/factory/nodeFactory.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,6 @@ import {
374374
QuestionDotToken,
375375
QuestionToken,
376376
ReadonlyKeyword,
377-
ReadonlyTextRange,
378377
reduceLeft,
379378
RegularExpressionLiteral,
380379
RestTypeNode,
@@ -1293,11 +1292,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
12931292
}
12941293

12951294
// @api
1296-
function createStringLiteral(text: string, isSingleQuote?: boolean, hasExtendedUnicodeEscape?: boolean, rangesOfOctalSequences?: ReadonlyTextRange[]): StringLiteral {
1295+
function createStringLiteral(text: string, isSingleQuote?: boolean, hasExtendedUnicodeEscape?: boolean): StringLiteral {
12971296
const node = createBaseStringLiteral(text, isSingleQuote);
12981297
node.hasExtendedUnicodeEscape = hasExtendedUnicodeEscape;
12991298
if (hasExtendedUnicodeEscape) node.transformFlags |= TransformFlags.ContainsES2015;
1300-
node.rangesOfOctalSequences = rangesOfOctalSequences;
13011299
return node;
13021300
}
13031301

src/compiler/parser.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,8 +2097,8 @@ namespace Parser {
20972097
parseErrorAt(range.pos, range.end, message, arg0);
20982098
}
20992099

2100-
function scanError(message: DiagnosticMessage, length: number): void {
2101-
parseErrorAtPosition(scanner.getTextPos(), length, message);
2100+
function scanError(message: DiagnosticMessage, length: number, arg0?: any): void {
2101+
parseErrorAtPosition(scanner.getTextPos(), length, message, arg0);
21022102
}
21032103

21042104
function getNodePos(): number {
@@ -2153,6 +2153,10 @@ namespace Parser {
21532153
return currentToken = scanner.reScanTemplateToken(isTaggedTemplate);
21542154
}
21552155

2156+
function reScanTemplateHeadOrNoSubstitutionTemplate(): SyntaxKind {
2157+
return currentToken = scanner.reScanTemplateHeadOrNoSubstitutionTemplate();
2158+
}
2159+
21562160
function reScanLessThanToken(): SyntaxKind {
21572161
return currentToken = scanner.reScanLessThanToken();
21582162
}
@@ -3602,7 +3606,9 @@ namespace Parser {
36023606
}
36033607

36043608
function parseTemplateHead(isTaggedTemplate: boolean): TemplateHead {
3605-
reScanTemplateToken(isTaggedTemplate);
3609+
if (!isTaggedTemplate && scanner.getTokenFlags() & TokenFlags.ContainsInvalidEscape) {
3610+
reScanTemplateHeadOrNoSubstitutionTemplate();
3611+
}
36063612
const fragment = parseLiteralLikeNode(token());
36073613
Debug.assert(fragment.kind === SyntaxKind.TemplateHead, "Template head has wrong token kind");
36083614
return fragment as TemplateHead;
@@ -3630,7 +3636,7 @@ namespace Parser {
36303636
// We also do not need to check for negatives because any prefix operator would be part of a
36313637
// parent unary expression.
36323638
kind === SyntaxKind.NumericLiteral ? factory.createNumericLiteral(scanner.getTokenValue(), scanner.getNumericLiteralFlags()) :
3633-
kind === SyntaxKind.StringLiteral ? factory.createStringLiteral(scanner.getTokenValue(), /*isSingleQuote*/ undefined, scanner.hasExtendedUnicodeEscape(), scanner.getRangesOfOctalSequences()) :
3639+
kind === SyntaxKind.StringLiteral ? factory.createStringLiteral(scanner.getTokenValue(), /*isSingleQuote*/ undefined, scanner.hasExtendedUnicodeEscape()) :
36343640
isLiteralKind(kind) ? factory.createLiteralLikeNode(kind, scanner.getTokenValue()) :
36353641
Debug.fail();
36363642

@@ -6408,8 +6414,8 @@ namespace Parser {
64086414
function parsePrimaryExpression(): PrimaryExpression {
64096415
switch (token()) {
64106416
case SyntaxKind.NoSubstitutionTemplateLiteral:
6411-
if (scanner.getTokenFlags() & TokenFlags.ContainsOctalOrInvalidEscape) {
6412-
reScanTemplateToken(/* isTaggedTemplate */ false);
6417+
if (scanner.getTokenFlags() & TokenFlags.ContainsInvalidEscape) {
6418+
reScanTemplateHeadOrNoSubstitutionTemplate();
64136419
}
64146420
// falls through
64156421
case SyntaxKind.NumericLiteral:

src/compiler/program.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,6 @@ export const plainJSErrors: Set<number> = new Set([
12971297
Diagnostics.Invalid_use_of_0_Modules_are_automatically_in_strict_mode.code,
12981298
Diagnostics.Invalid_use_of_0_in_strict_mode.code,
12991299
Diagnostics.A_label_is_not_allowed_here.code,
1300-
Diagnostics.Octal_literals_are_not_allowed_in_strict_mode.code,
13011300
Diagnostics.with_statements_are_not_allowed_in_strict_mode.code,
13021301
// grammar errors
13031302
Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement.code,

0 commit comments

Comments
 (0)