tsc-ts 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/api/compiler/ast.d.ts +67 -27
- package/dist/api/compiler/ast.js +156 -55
- package/dist/api/compiler/binder-utilities.js +4 -3
- package/dist/api/compiler/binder.js +14 -13
- package/dist/api/compiler/checker-calls.js +7 -6
- package/dist/api/compiler/checker-contextual.js +1 -1
- package/dist/api/compiler/checker-declaration-order.js +2 -1
- package/dist/api/compiler/checker-declarations.js +14 -14
- package/dist/api/compiler/checker-declared-types.d.ts +1 -1
- package/dist/api/compiler/checker-declared-types.js +12 -11
- package/dist/api/compiler/checker-decorators.js +3 -3
- package/dist/api/compiler/checker-deprecation.js +17 -18
- package/dist/api/compiler/checker-destructuring.d.ts +1 -1
- package/dist/api/compiler/checker-destructuring.js +3 -3
- package/dist/api/compiler/checker-elaboration.js +8 -7
- package/dist/api/compiler/checker-emit-helpers.d.ts +2 -1
- package/dist/api/compiler/checker-emit-helpers.js +5 -4
- package/dist/api/compiler/checker-emit-resolver.d.ts +1 -1
- package/dist/api/compiler/checker-emit-resolver.js +5 -4
- package/dist/api/compiler/checker-grammar.js +23 -9
- package/dist/api/compiler/checker-heritage.d.ts +1 -1
- package/dist/api/compiler/checker-heritage.js +14 -13
- package/dist/api/compiler/checker-inference.d.ts +21 -11
- package/dist/api/compiler/checker-inference.js +57 -34
- package/dist/api/compiler/checker-javascript.d.ts +1 -1
- package/dist/api/compiler/checker-javascript.js +5 -4
- package/dist/api/compiler/checker-jsx.d.ts +1 -1
- package/dist/api/compiler/checker-jsx.js +4 -4
- package/dist/api/compiler/checker-literals.js +2 -2
- package/dist/api/compiler/checker-members.d.ts +32 -3
- package/dist/api/compiler/checker-members.js +240 -53
- package/dist/api/compiler/checker-modules.d.ts +15 -1
- package/dist/api/compiler/checker-modules.js +86 -14
- package/dist/api/compiler/checker-object-literals.d.ts +1 -1
- package/dist/api/compiler/checker-object-literals.js +11 -7
- package/dist/api/compiler/checker-overloads.d.ts +1 -1
- package/dist/api/compiler/checker-overloads.js +4 -3
- package/dist/api/compiler/checker-property-access.d.ts +1 -1
- package/dist/api/compiler/checker-property-access.js +2 -2
- package/dist/api/compiler/checker-services.js +2 -2
- package/dist/api/compiler/checker-signatures.d.ts +1 -1
- package/dist/api/compiler/checker-signatures.js +9 -8
- package/dist/api/compiler/checker-symbol-types.d.ts +2 -18
- package/dist/api/compiler/checker-symbol-types.js +22 -952
- package/dist/api/compiler/checker-symbols.d.ts +2 -2
- package/dist/api/compiler/checker-symbols.js +29 -27
- package/dist/api/compiler/checker-type-factory.d.ts +2 -2
- package/dist/api/compiler/checker-type-factory.js +57 -16
- package/dist/api/compiler/checker-type-nodes.d.ts +1 -1
- package/dist/api/compiler/checker-type-nodes.js +2 -2
- package/dist/api/compiler/checker-type-operators.d.ts +1 -1
- package/dist/api/compiler/checker-type-operators.js +5 -5
- package/dist/api/compiler/checker-types.d.ts +73 -7
- package/dist/api/compiler/checker-types.js +220 -43
- package/dist/api/compiler/checker-unused.d.ts +1 -1
- package/dist/api/compiler/checker-unused.js +3 -3
- package/dist/api/compiler/checker.d.ts +45 -8
- package/dist/api/compiler/checker.js +46 -9
- package/dist/api/compiler/diagnostics.d.ts +2 -8
- package/dist/api/compiler/diagnostics.js +13 -45
- package/dist/api/compiler/file-include.d.ts +35 -8
- package/dist/api/compiler/file-include.js +81 -18
- package/dist/api/compiler/file-loader.d.ts +33 -4
- package/dist/api/compiler/file-loader.js +90 -24
- package/dist/api/compiler/instantiation.d.ts +1 -1
- package/dist/api/compiler/instantiation.js +86 -50
- package/dist/api/compiler/link-tables.d.ts +69 -0
- package/dist/api/compiler/link-tables.js +236 -0
- package/dist/api/compiler/name-resolver.js +3 -3
- package/dist/api/compiler/node-builder-names.d.ts +1 -1
- package/dist/api/compiler/node-builder-names.js +12 -12
- package/dist/api/compiler/node-builder-pseudo.d.ts +1 -1
- package/dist/api/compiler/node-builder-pseudo.js +2 -1
- package/dist/api/compiler/node-builder.d.ts +1 -1
- package/dist/api/compiler/node-builder.js +16 -16
- package/dist/api/compiler/parallel-parse.d.ts +2 -0
- package/dist/api/compiler/parallel-parse.js +7 -1
- package/dist/api/compiler/parser.d.ts +33 -16
- package/dist/api/compiler/parser.js +127 -98
- package/dist/api/compiler/printer/emit-context.d.ts +5 -2
- package/dist/api/compiler/printer/emit-context.js +19 -13
- package/dist/api/compiler/printer/factory-base.js +8 -8
- package/dist/api/compiler/printer/factory.js +4 -4
- package/dist/api/compiler/printer/printer.js +6 -6
- package/dist/api/compiler/program-checker.d.ts +5 -0
- package/dist/api/compiler/program-checker.js +14 -1
- package/dist/api/compiler/program.js +9 -1
- package/dist/api/compiler/relations.d.ts +1 -1
- package/dist/api/compiler/relations.js +18 -13
- package/dist/api/compiler/reparser.js +13 -5
- package/dist/api/compiler/symbol-accessibility.d.ts +1 -1
- package/dist/api/compiler/symbol-accessibility.js +123 -26
- package/dist/api/compiler/symbol.d.ts +45 -3
- package/dist/api/compiler/symbol.js +121 -10
- package/dist/api/compiler/transformers/alias-references.d.ts +1 -1
- package/dist/api/compiler/transformers/alias-references.js +2 -1
- package/dist/api/compiler/transformers/class-fields.js +3 -3
- package/dist/api/compiler/transformers/commonjs-module.js +3 -3
- package/dist/api/compiler/transformers/declarations-diagnostics.js +2 -1
- package/dist/api/compiler/transformers/declarations-pseudo.js +6 -4
- package/dist/api/compiler/transformers/declarations-syntactic.d.ts +1 -1
- package/dist/api/compiler/transformers/declarations-syntactic.js +9 -9
- package/dist/api/compiler/transformers/declarations-tracker.d.ts +1 -1
- package/dist/api/compiler/transformers/declarations-tracker.js +3 -2
- package/dist/api/compiler/transformers/declarations.js +6 -5
- package/dist/api/compiler/transformers/module.js +2 -2
- package/dist/api/compiler/transformers/optional-chain.js +3 -3
- package/dist/api/compiler/transformers/reference-resolver.d.ts +2 -1
- package/dist/api/compiler/transformers/reference-resolver.js +26 -24
- package/dist/api/compiler/transformers/subtree-facts.d.ts +1 -0
- package/dist/api/compiler/transformers/subtree-facts.js +9 -7
- package/dist/api/compiler/transformers/syntax-facts.d.ts +1 -0
- package/dist/api/compiler/transformers/syntax-facts.js +9 -5
- package/dist/api/compiler/transformers/tagged-template.js +2 -2
- package/dist/api/compiler/transformers/type-eraser.js +2 -2
- package/dist/api/compiler/transformers/type-serialization.js +12 -12
- package/dist/api/compiler/transformers/visitor-base.js +3 -3
- package/dist/api/compiler/tsconfig.js +2 -2
- package/package.json +9 -9
- package/src/compiler/ast.ts +211 -78
- package/src/compiler/binder-utilities.ts +4 -3
- package/src/compiler/binder.ts +26 -16
- package/src/compiler/checker-calls.ts +8 -6
- package/src/compiler/checker-contextual.ts +1 -1
- package/src/compiler/checker-declaration-order.ts +2 -2
- package/src/compiler/checker-declarations.ts +21 -14
- package/src/compiler/checker-declared-types.ts +12 -12
- package/src/compiler/checker-decorators.ts +3 -3
- package/src/compiler/checker-deprecation.ts +17 -21
- package/src/compiler/checker-destructuring.ts +3 -3
- package/src/compiler/checker-elaboration.ts +8 -8
- package/src/compiler/checker-emit-helpers.ts +5 -4
- package/src/compiler/checker-emit-resolver.ts +5 -5
- package/src/compiler/checker-grammar.ts +22 -8
- package/src/compiler/checker-heritage.ts +21 -14
- package/src/compiler/checker-inference.ts +66 -34
- package/src/compiler/checker-javascript.ts +5 -5
- package/src/compiler/checker-jsx.ts +12 -8
- package/src/compiler/checker-literals.ts +2 -2
- package/src/compiler/checker-members.ts +255 -47
- package/src/compiler/checker-modules.ts +115 -14
- package/src/compiler/checker-object-literals.ts +22 -6
- package/src/compiler/checker-overloads.ts +6 -6
- package/src/compiler/checker-property-access.ts +2 -2
- package/src/compiler/checker-services.ts +2 -2
- package/src/compiler/checker-signatures.ts +9 -9
- package/src/compiler/checker-symbol-types.ts +20 -940
- package/src/compiler/checker-symbols.ts +42 -35
- package/src/compiler/checker-type-factory.ts +53 -16
- package/src/compiler/checker-type-nodes.ts +2 -2
- package/src/compiler/checker-type-operators.ts +13 -5
- package/src/compiler/checker-types.ts +223 -43
- package/src/compiler/checker-unused.ts +3 -3
- package/src/compiler/checker.ts +50 -9
- package/src/compiler/decoder.ts +5 -4
- package/src/compiler/diagnostics.ts +14 -48
- package/src/compiler/encoder.ts +10 -5
- package/src/compiler/file-include.ts +85 -17
- package/src/compiler/file-loader.ts +104 -35
- package/src/compiler/incremental.ts +39 -5
- package/src/compiler/instantiation.ts +99 -55
- package/src/compiler/link-tables.ts +245 -0
- package/src/compiler/name-resolver.ts +3 -3
- package/src/compiler/node-builder-names.ts +21 -19
- package/src/compiler/node-builder-pseudo.ts +2 -2
- package/src/compiler/node-builder.ts +24 -16
- package/src/compiler/parallel-check.ts +11 -8
- package/src/compiler/parallel-parse.ts +8 -1
- package/src/compiler/parse-thread.ts +0 -4
- package/src/compiler/parser.ts +173 -93
- package/src/compiler/printer/emit-context.ts +20 -15
- package/src/compiler/printer/factory-base.ts +14 -7
- package/src/compiler/printer/factory.ts +5 -3
- package/src/compiler/printer/printer.ts +8 -6
- package/src/compiler/program-checker.ts +12 -1
- package/src/compiler/program.ts +8 -1
- package/src/compiler/relations.ts +20 -12
- package/src/compiler/reparser.ts +14 -4
- package/src/compiler/symbol-accessibility.ts +120 -25
- package/src/compiler/symbol.ts +127 -9
- package/src/compiler/transformers/alias-references.ts +2 -2
- package/src/compiler/transformers/class-fields.ts +12 -2
- package/src/compiler/transformers/commonjs-module.ts +3 -2
- package/src/compiler/transformers/declarations-diagnostics.ts +2 -1
- package/src/compiler/transformers/declarations-pseudo.ts +9 -5
- package/src/compiler/transformers/declarations-syntactic.ts +17 -9
- package/src/compiler/transformers/declarations-tracker.ts +3 -3
- package/src/compiler/transformers/declarations.ts +7 -7
- package/src/compiler/transformers/module.ts +2 -1
- package/src/compiler/transformers/optional-chain.ts +5 -2
- package/src/compiler/transformers/reference-resolver.ts +37 -25
- package/src/compiler/transformers/subtree-facts.ts +15 -6
- package/src/compiler/transformers/syntax-facts.ts +10 -5
- package/src/compiler/transformers/tagged-template.ts +2 -2
- package/src/compiler/transformers/type-eraser.ts +2 -1
- package/src/compiler/transformers/type-serialization.ts +12 -12
- package/src/compiler/transformers/visitor-base.ts +10 -5
- package/src/compiler/tsc-build.ts +17 -13
- package/src/compiler/tsc-cli.ts +9 -6
- package/src/compiler/tsc-compile.ts +16 -7
- package/src/compiler/tsc-watch.ts +94 -26
- package/src/compiler/tsconfig.ts +2 -1
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// const file = parseSourceFile('/src/main.ts', text);
|
|
6
6
|
// for (const statement of file.statements.nodes) console.log(statement.kind);
|
|
7
7
|
// ```
|
|
8
|
-
import { ArrayLiteralExpression, ArrayTypeNode, ArrowFunction, AsExpression, AwaitExpression, BigIntLiteral, BinaryExpression, BindingElement, BindingPattern, Block, BreakStatement, CallExpression, CallSignatureDeclaration, CaseBlock, CaseOrDefaultClause, CatchClause, CheckJsDirective, ClassDeclaration, ClassExpression, ClassStaticBlockDeclaration, ComputedPropertyName, ConditionalExpression, ConditionalTypeNode, ConstructSignatureDeclaration, ConstructorDeclaration, ConstructorTypeNode, ContinueStatement, DebuggerStatement, Decorator, DeleteExpression, DoStatement, ElementAccessExpression, EmptyStatement, EnumDeclaration, EnumMember, ExportAssignment, ExportDeclaration, ExportSpecifier, ExpressionStatement, ExpressionWithTypeArguments, ExternalModuleIndicatorOptions, ExternalModuleReference, FileReference, ForInOrOfStatement, ForStatement, FunctionDeclaration, FunctionExpression, FunctionTypeNode, GetAccessorDeclaration, HeritageClause, Identifier, IfStatement, ImportAttribute, ImportAttributes, ImportClause, ImportDeclaration, ImportEqualsDeclaration, ImportSpecifier, ImportTypeNode, IndexSignatureDeclaration, IndexedAccessTypeNode, InferTypeNode, InterfaceDeclaration, IntersectionTypeNode, JSDocAllType, JSDocNonNullableType, JSDocNullableType, JSDocOptionalType, JSDocVariadicType, JsxAttribute, JsxAttributes, JsxClosingElement, JsxClosingFragment, JsxElement, JsxExpression, JsxFragment, JsxNamespacedName, JsxOpeningElement, JsxOpeningFragment, JsxSelfClosingElement, JsxSpreadAttribute, JsxText, KeywordExpression, KeywordTypeNode, LabeledStatement, LiteralTypeNode, MappedTypeNode, MetaProperty, MethodDeclaration, MethodSignatureDeclaration, MissingDeclaration, MissingNodeList, ModifierList, ModuleBlock, ModuleDeclaration, NamedExports, NamedImports, NamedTupleMember, NamespaceExport, NamespaceExportDeclaration, NamespaceImport, NewExpression, NoSubstitutionTemplateLiteral, NodeList, NodeVisitor, NonNullExpression, NumericLiteral, ObjectLiteralExpression, OmittedExpression, OptionalTypeNode, ParameterDeclaration, ParenthesizedExpression, ParenthesizedTypeNode, PostfixUnaryExpression, Pragma, PragmaArgument, PrefixUnaryExpression, PrivateIdentifier, PropertyAccessExpression, PropertyAssignment, PropertyDeclaration, PropertySignatureDeclaration, QualifiedName, RegularExpressionLiteral, RestTypeNode, ReturnStatement, SatisfiesExpression, SemicolonClassElement, SetAccessorDeclaration, ShorthandPropertyAssignment, SourceFile, SpreadAssignment, SpreadElement, StringLiteral, SwitchStatement, TaggedTemplateExpression, TemplateExpression, TemplateHead, TemplateLiteralTypeNode, TemplateLiteralTypeSpan, TemplateMiddle, TemplateSpan, TemplateTail, ThisTypeNode, ThrowStatement, Token, TryStatement, TupleTypeNode, TypeAliasDeclaration, TypeAssertion, TypeLiteralNode, TypeOfExpression, TypeOperatorNode, TypeParameterDeclaration, TypePredicateNode, TypeQueryNode, TypeReferenceNode, UnionTypeNode, VariableDeclaration, VariableDeclarationList, VariableStatement, VoidExpression, WhileStatement, WithStatement, YieldExpression, getBody, getIsTypeOnly, getModifiers, getName, getPostfixToken, getQuestionToken, getStatements, getText, getType, getTypeArguments, getTypeParameters, } from './ast.js';
|
|
8
|
+
import { appendToList, ArrayLiteralExpression, ArrayTypeNode, ArrowFunction, AsExpression, AwaitExpression, BigIntLiteral, BinaryExpression, BindingElement, BindingPattern, Block, BreakStatement, CallExpression, CallSignatureDeclaration, CaseBlock, CaseOrDefaultClause, CatchClause, CheckJsDirective, ClassDeclaration, ClassExpression, ClassStaticBlockDeclaration, ComputedPropertyName, ConditionalExpression, ConditionalTypeNode, ConstructSignatureDeclaration, ConstructorDeclaration, ConstructorTypeNode, ContinueStatement, DebuggerStatement, Decorator, DeleteExpression, DoStatement, ElementAccessExpression, emptyCommentDirectives, emptyDiagnostics, emptyFileReferences, emptyNodes, emptyPragmas, EmptyStatement, EnumDeclaration, EnumMember, ExportAssignment, ExportDeclaration, ExportSpecifier, ExpressionStatement, ExpressionWithTypeArguments, ExternalModuleIndicatorOptions, ExternalModuleReference, FileReference, ForInOrOfStatement, ForStatement, FunctionDeclaration, FunctionExpression, FunctionTypeNode, GetAccessorDeclaration, HeritageClause, Identifier, IfStatement, ImportAttribute, ImportAttributes, ImportClause, ImportDeclaration, ImportEqualsDeclaration, ImportSpecifier, ImportTypeNode, IndexSignatureDeclaration, IndexedAccessTypeNode, InferTypeNode, InterfaceDeclaration, IntersectionTypeNode, JSDocAllType, JSDocNonNullableType, JSDocNullableType, JSDocOptionalType, JSDocVariadicType, JsxAttribute, JsxAttributes, JsxClosingElement, JsxClosingFragment, JsxElement, JsxExpression, JsxFragment, JsxNamespacedName, JsxOpeningElement, JsxOpeningFragment, JsxSelfClosingElement, JsxSpreadAttribute, JsxText, KeywordExpression, KeywordTypeNode, LabeledStatement, LiteralTypeNode, MappedTypeNode, MetaProperty, MethodDeclaration, MethodSignatureDeclaration, MissingDeclaration, MissingNodeList, ModifierList, ModuleBlock, ModuleDeclaration, NamedExports, NamedImports, NamedTupleMember, NamespaceExport, NamespaceExportDeclaration, NamespaceImport, NewExpression, NoSubstitutionTemplateLiteral, NodeList, NodeVisitor, NonNullExpression, NumericLiteral, ObjectLiteralExpression, OmittedExpression, OptionalTypeNode, ParameterDeclaration, ParenthesizedExpression, ParenthesizedTypeNode, PostfixUnaryExpression, Pragma, PragmaArgument, PrefixUnaryExpression, PrivateIdentifier, PropertyAccessExpression, PropertyAssignment, PropertyDeclaration, PropertySignatureDeclaration, QualifiedName, ReferenceIdentifier, RegularExpressionLiteral, RestTypeNode, ReturnStatement, SatisfiesExpression, SemicolonClassElement, SetAccessorDeclaration, ShorthandPropertyAssignment, SourceFile, SpreadAssignment, SpreadElement, StringLiteral, SwitchStatement, TaggedTemplateExpression, TemplateExpression, TemplateHead, TemplateLiteralTypeNode, TemplateLiteralTypeSpan, TemplateMiddle, TemplateSpan, TemplateTail, ThisTypeNode, ThrowStatement, Token, TryStatement, TupleTypeNode, TypeAliasDeclaration, TypeAssertion, TypeLiteralNode, TypeOfExpression, TypeOperatorNode, TypeParameterDeclaration, TypePredicateNode, TypeQueryNode, TypeReferenceNode, UnionTypeNode, VariableDeclaration, VariableDeclarationList, VariableStatement, VoidExpression, WhileStatement, WithStatement, YieldExpression, getBody, getIsTypeOnly, getModifiers, getName, getPostfixToken, getQuestionToken, getStatements, getText, getType, getTypeArguments, getTypeParameters, newCallExpression, newPropertyAssignment, } from './ast.js';
|
|
9
9
|
import { canHaveDecorators, canHaveIllegalDecorators, compareNodePositions, getBinaryOperatorPrecedence, getExternalModuleName, getImportTypeNodeLiteral, getTextOfNodeFromSourceText, isAmbientModule, isAnyImportOrReExport, isAssignmentOperator, isClassMemberModifier, isFunctionLike, isImportCall, isImportMeta, isInJSFile, isKeyword, isKeywordOrPunctuation, isLeftHandSideExpression, isModifierKind, isRequireCall, isReservedWord, isStringLiteralLike, modifierToFlag, modifiersToFlags, nodeIsMissing, nodeIsPresent, tagNamesAreEquivalent, tokenIsIdentifierOrKeyword, tokenIsIdentifierOrKeywordOrGreaterThan, } from './ast-utilities.js';
|
|
10
10
|
import { isLineBreak } from './character-codes.js';
|
|
11
11
|
import { Diagnostic, messageCode } from './diagnostics.js';
|
|
@@ -52,6 +52,10 @@ function appendRange(to, from, start, end) {
|
|
|
52
52
|
for (let i = start; i < end; i += 1)
|
|
53
53
|
to.push(from[i]);
|
|
54
54
|
}
|
|
55
|
+
// The nodes of every empty parsed list. A list's nodes are pushed into a new `[]`, which natively
|
|
56
|
+
// reserves room for its first elements (112 bytes); a parsed list never changes, so an empty one
|
|
57
|
+
// keeps this shared array instead and its builder is freed.
|
|
58
|
+
const emptyListNodes = [];
|
|
55
59
|
/** Parses `text` as the file `fileName`. The script kind defaults to the one implied by the extension. */
|
|
56
60
|
export function parseSourceFile(fileName, text, options) {
|
|
57
61
|
const path = options === undefined ? fileName : options.path;
|
|
@@ -211,12 +215,15 @@ export class Parser extends ScannerErrorReporter {
|
|
|
211
215
|
this.scanner.setLanguageVariant(this.languageVariant);
|
|
212
216
|
}
|
|
213
217
|
/**
|
|
214
|
-
* Frees the scanner's copy of the text once the parser is done
|
|
215
|
-
*
|
|
216
|
-
* come much later
|
|
218
|
+
* Frees the scanner's copy of the text once the parser is done, and drops the references back to
|
|
219
|
+
* this parser from its scanner and JSDoc parser. Natively, the parser is then freed as soon as its
|
|
220
|
+
* caller lets go of it, instead of at a cycle collection, which may come much later (on a parse
|
|
221
|
+
* thread, not before the thread exits).
|
|
217
222
|
*/
|
|
218
223
|
release() {
|
|
219
224
|
this.scanner.setText('');
|
|
225
|
+
this.scanner.setOnError(undefined);
|
|
226
|
+
this.jsdoc = releasedParser().jsdoc;
|
|
220
227
|
}
|
|
221
228
|
token() {
|
|
222
229
|
return this.currentToken;
|
|
@@ -365,10 +372,10 @@ export class Parser extends ScannerErrorReporter {
|
|
|
365
372
|
}
|
|
366
373
|
// Nodes
|
|
367
374
|
newNodeList(pos, end, nodes) {
|
|
368
|
-
return new NodeList(pos, end, nodes);
|
|
375
|
+
return new NodeList(pos, end, nodes.length === 0 ? emptyListNodes : nodes);
|
|
369
376
|
}
|
|
370
377
|
newModifierList(pos, end, nodes) {
|
|
371
|
-
return new ModifierList(pos, end, nodes, modifiersToFlags(nodes));
|
|
378
|
+
return new ModifierList(pos, end, nodes.length === 0 ? emptyListNodes : nodes, modifiersToFlags(nodes));
|
|
372
379
|
}
|
|
373
380
|
finishNode(node, pos) {
|
|
374
381
|
return this.finishNodeWithEnd(node, pos, this.nodePos());
|
|
@@ -421,23 +428,18 @@ export class Parser extends ScannerErrorReporter {
|
|
|
421
428
|
collectExternalModuleReferences(result);
|
|
422
429
|
if (result.isJS())
|
|
423
430
|
result.jsDiagnostics = attachFileToDiagnostics(this.jsDiagnostics, result);
|
|
424
|
-
//
|
|
425
|
-
// `useThreadTextCaches`)
|
|
426
|
-
//
|
|
427
|
-
|
|
428
|
-
if (result.isDeclarationFile)
|
|
429
|
-
result.diagnosticFile();
|
|
430
|
-
else if (scanner.text === result.text && scanner.end === result.text.length)
|
|
431
|
-
result.computeCachesFromUnits(scanner.chars);
|
|
432
|
-
else
|
|
433
|
-
result.computeCaches();
|
|
431
|
+
// Files get their line starts on first use (in a thread's copy once they may be shared,
|
|
432
|
+
// `useThreadTextCaches`): most files are never pointed into by a diagnostic. The file's
|
|
433
|
+
// DiagnosticFile exists from here on, so reading it never writes to the file.
|
|
434
|
+
result.diagnosticFile();
|
|
434
435
|
return result;
|
|
435
436
|
}
|
|
436
437
|
newSourceFile(statements, eof) {
|
|
437
438
|
return new SourceFile(this.fileName, this.path, this.sourceText, this.externalModuleIndicatorOptions, statements, eof);
|
|
438
439
|
}
|
|
439
440
|
finishSourceFile(result, isDeclarationFile) {
|
|
440
|
-
|
|
441
|
+
const commentDirectives = this.scanner.getCommentDirectives();
|
|
442
|
+
result.commentDirectives = commentDirectives.length === 0 ? emptyCommentDirectives : commentDirectives;
|
|
441
443
|
result.pragmas = getCommentPragmas(this.sourceText);
|
|
442
444
|
this.processPragmasIntoFields(result);
|
|
443
445
|
result.diagnostics = attachFileToDiagnostics(this.diagnostics, result);
|
|
@@ -455,9 +457,13 @@ export class Parser extends ScannerErrorReporter {
|
|
|
455
457
|
// The table stays with the parser: when top-level await reparsing produces a second source
|
|
456
458
|
// file, it finishes with the same table, which still holds the JSDoc of retained statements.
|
|
457
459
|
result.jsDocs = this.jsDocTable;
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
460
|
+
if (this.reparsedClones.length === 0)
|
|
461
|
+
result.reparsedClones = emptyNodes;
|
|
462
|
+
else {
|
|
463
|
+
const clones = this.reparsedClones.slice();
|
|
464
|
+
clones.sort(compareNodePositions);
|
|
465
|
+
result.reparsedClones = clones;
|
|
466
|
+
}
|
|
461
467
|
setExternalModuleIndicator(result);
|
|
462
468
|
}
|
|
463
469
|
parseToplevelStatement(index) {
|
|
@@ -1315,7 +1321,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
1315
1321
|
return this.finishWithJSDoc(new ContinueStatement(label), pos, jsdoc);
|
|
1316
1322
|
}
|
|
1317
1323
|
parseIdentifierUnlessAtSemicolon() {
|
|
1318
|
-
return this.canParseSemicolon() ? undefined : this.parseIdentifier();
|
|
1324
|
+
return this.canParseSemicolon() ? undefined : this.parseIdentifier(1 /* IdentifierUse.Name */);
|
|
1319
1325
|
}
|
|
1320
1326
|
parseReturnStatement() {
|
|
1321
1327
|
const pos = this.nodePos();
|
|
@@ -1660,7 +1666,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
1660
1666
|
// named `implements`.
|
|
1661
1667
|
if (this.isBindingIdentifier() && !this.isImplementsClause()) {
|
|
1662
1668
|
const saveHasAwaitIdentifier = this.statementHasAwaitIdentifier;
|
|
1663
|
-
const id = this.createIdentifier(this.isBindingIdentifier());
|
|
1669
|
+
const id = this.createIdentifier(this.isBindingIdentifier(), 1 /* IdentifierUse.Name */);
|
|
1664
1670
|
this.statementHasAwaitIdentifier = saveHasAwaitIdentifier;
|
|
1665
1671
|
return id;
|
|
1666
1672
|
}
|
|
@@ -1888,7 +1894,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
1888
1894
|
}
|
|
1889
1895
|
parseInterfaceDeclaration(pos, jsdoc, modifiers) {
|
|
1890
1896
|
this.parseExpected(119 /* SyntaxKind.InterfaceKeyword */);
|
|
1891
|
-
const name = this.parseIdentifier();
|
|
1897
|
+
const name = this.parseIdentifier(1 /* IdentifierUse.Name */);
|
|
1892
1898
|
const typeParameters = this.parseTypeParameters();
|
|
1893
1899
|
const heritageClauses = this.parseHeritageClauses();
|
|
1894
1900
|
const members = this.parseObjectTypeMembers();
|
|
@@ -1900,7 +1906,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
1900
1906
|
this.parseExpected(156 /* SyntaxKind.TypeKeyword */);
|
|
1901
1907
|
if (this.hasPrecedingLineBreak())
|
|
1902
1908
|
this.parseErrorAtCurrentToken(108 /* Diagnostics.Line_break_not_permitted_here */);
|
|
1903
|
-
const name = this.parseIdentifier();
|
|
1909
|
+
const name = this.parseIdentifier(1 /* IdentifierUse.Name */);
|
|
1904
1910
|
const typeParameters = this.parseTypeParameters();
|
|
1905
1911
|
this.parseExpected(63 /* SyntaxKind.EqualsToken */);
|
|
1906
1912
|
const type = this.token() === 141 /* SyntaxKind.IntrinsicKeyword */ && this.lookAhead(nextIsNotDot)
|
|
@@ -1926,7 +1932,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
1926
1932
|
parseEnumDeclaration(pos, jsdoc, modifiers) {
|
|
1927
1933
|
const saveHasAwaitIdentifier = this.statementHasAwaitIdentifier;
|
|
1928
1934
|
this.parseExpected(93 /* SyntaxKind.EnumKeyword */);
|
|
1929
|
-
const name = this.parseIdentifier();
|
|
1935
|
+
const name = this.parseIdentifier(1 /* IdentifierUse.Name */);
|
|
1930
1936
|
let members;
|
|
1931
1937
|
if (this.parseExpected(18 /* SyntaxKind.OpenBraceToken */)) {
|
|
1932
1938
|
const saveContextFlags = this.contextFlags;
|
|
@@ -1965,7 +1971,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
1965
1971
|
const saveHasAwaitIdentifier = this.statementHasAwaitIdentifier;
|
|
1966
1972
|
if (this.token() === 162 /* SyntaxKind.GlobalKeyword */) {
|
|
1967
1973
|
// `global` names the global scope augmentation.
|
|
1968
|
-
name = this.parseIdentifier();
|
|
1974
|
+
name = this.parseIdentifier(1 /* IdentifierUse.Name */);
|
|
1969
1975
|
keyword = 162 /* SyntaxKind.GlobalKeyword */;
|
|
1970
1976
|
}
|
|
1971
1977
|
else {
|
|
@@ -1994,7 +2000,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
1994
2000
|
}
|
|
1995
2001
|
parseModuleOrNamespaceDeclaration(pos, jsdoc, modifiers, nested, keyword) {
|
|
1996
2002
|
const saveHasAwaitIdentifier = this.statementHasAwaitIdentifier;
|
|
1997
|
-
const name = nested ? this.parseIdentifierName() : this.parseIdentifier();
|
|
2003
|
+
const name = nested ? this.parseIdentifierName(1 /* IdentifierUse.Name */) : this.parseIdentifier(1 /* IdentifierUse.Name */);
|
|
1998
2004
|
let body;
|
|
1999
2005
|
if (this.parseOptional(24 /* SyntaxKind.DotToken */)) {
|
|
2000
2006
|
const implicitExport = new Token(94 /* SyntaxKind.ExportKeyword */);
|
|
@@ -2017,7 +2023,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2017
2023
|
const afterImportPos = this.nodePos();
|
|
2018
2024
|
// The identifier isn't parsed in an await context; the checker reports `await`.
|
|
2019
2025
|
const saveHasAwaitIdentifier = this.statementHasAwaitIdentifier;
|
|
2020
|
-
let identifier = this.isIdentifier() ? this.parseIdentifier() : undefined;
|
|
2026
|
+
let identifier = this.isIdentifier() ? this.parseIdentifier(1 /* IdentifierUse.Name */) : undefined;
|
|
2021
2027
|
let phaseModifier = 0 /* SyntaxKind.Unknown */;
|
|
2022
2028
|
if (identifier !== undefined &&
|
|
2023
2029
|
identifier.text === 'type' &&
|
|
@@ -2025,7 +2031,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2025
2031
|
(this.isIdentifier() && this.lookAhead(nextTokenIsFromKeywordOrEqualsToken))) &&
|
|
2026
2032
|
(this.isIdentifier() || this.tokenAfterImportDefinitelyProducesImportDeclaration())) {
|
|
2027
2033
|
phaseModifier = 156 /* SyntaxKind.TypeKeyword */;
|
|
2028
|
-
identifier = this.isIdentifier() ? this.parseIdentifier() : undefined;
|
|
2034
|
+
identifier = this.isIdentifier() ? this.parseIdentifier(1 /* IdentifierUse.Name */) : undefined;
|
|
2029
2035
|
}
|
|
2030
2036
|
else if (identifier !== undefined && identifier.text === 'defer') {
|
|
2031
2037
|
const shouldParseAsDeferModifier = this.token() === 161 /* SyntaxKind.FromKeyword */
|
|
@@ -2033,7 +2039,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2033
2039
|
: this.token() !== 27 /* SyntaxKind.CommaToken */ && this.token() !== 63 /* SyntaxKind.EqualsToken */;
|
|
2034
2040
|
if (shouldParseAsDeferModifier) {
|
|
2035
2041
|
phaseModifier = 166 /* SyntaxKind.DeferKeyword */;
|
|
2036
|
-
identifier = this.isIdentifier() ? this.parseIdentifier() : undefined;
|
|
2042
|
+
identifier = this.isIdentifier() ? this.parseIdentifier(1 /* IdentifierUse.Name */) : undefined;
|
|
2037
2043
|
}
|
|
2038
2044
|
}
|
|
2039
2045
|
if (identifier !== undefined &&
|
|
@@ -2124,7 +2130,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2124
2130
|
const pos = this.nodePos();
|
|
2125
2131
|
this.parseExpected(41 /* SyntaxKind.AsteriskToken */);
|
|
2126
2132
|
this.parseExpected(129 /* SyntaxKind.AsKeyword */);
|
|
2127
|
-
const name = this.parseIdentifier();
|
|
2133
|
+
const name = this.parseIdentifier(1 /* IdentifierUse.Name */);
|
|
2128
2134
|
return this.finishNode(new NamespaceImport(name), pos);
|
|
2129
2135
|
}
|
|
2130
2136
|
parseNamedImports() {
|
|
@@ -2156,9 +2162,9 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2156
2162
|
// import { type as as } from "mod"; - isTypeOnly: false, name: as, propertyName: type
|
|
2157
2163
|
// import { type as as as } from "mod"; - isTypeOnly: true, name: as, propertyName: as
|
|
2158
2164
|
if (this.token() === 129 /* SyntaxKind.AsKeyword */) {
|
|
2159
|
-
const firstAs = this.parseIdentifierName();
|
|
2165
|
+
const firstAs = this.parseIdentifierName(1 /* IdentifierUse.Name */);
|
|
2160
2166
|
if (this.token() === 129 /* SyntaxKind.AsKeyword */) {
|
|
2161
|
-
const secondAs = this.parseIdentifierName();
|
|
2167
|
+
const secondAs = this.parseIdentifierName(1 /* IdentifierUse.Name */);
|
|
2162
2168
|
if (this.canParseModuleExportName()) {
|
|
2163
2169
|
// { type as as something }
|
|
2164
2170
|
isTypeOnly = true;
|
|
@@ -2229,7 +2235,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2229
2235
|
parseModuleExportName() {
|
|
2230
2236
|
if (this.token() === 10 /* SyntaxKind.StringLiteral */)
|
|
2231
2237
|
return this.parseLiteralExpression(false);
|
|
2232
|
-
return this.parseIdentifierName();
|
|
2238
|
+
return this.parseIdentifierName(1 /* IdentifierUse.Name */);
|
|
2233
2239
|
}
|
|
2234
2240
|
tryParseImportAttributes() {
|
|
2235
2241
|
if (this.token() === 117 /* SyntaxKind.WithKeyword */ ||
|
|
@@ -2261,7 +2267,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2261
2267
|
this.parseExpected(129 /* SyntaxKind.AsKeyword */);
|
|
2262
2268
|
this.parseExpected(145 /* SyntaxKind.NamespaceKeyword */);
|
|
2263
2269
|
const saveHasAwaitIdentifier = this.statementHasAwaitIdentifier;
|
|
2264
|
-
const name = this.parseIdentifier();
|
|
2270
|
+
const name = this.parseIdentifier(1 /* IdentifierUse.Name */);
|
|
2265
2271
|
this.statementHasAwaitIdentifier = saveHasAwaitIdentifier;
|
|
2266
2272
|
this.parseSemicolon();
|
|
2267
2273
|
// Modifiers are kept so the grammar checker can report them.
|
|
@@ -2404,7 +2410,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2404
2410
|
}
|
|
2405
2411
|
parseTypeParameterOfInferType() {
|
|
2406
2412
|
const pos = this.nodePos();
|
|
2407
|
-
const name = this.parseIdentifier();
|
|
2413
|
+
const name = this.parseIdentifier(1 /* IdentifierUse.Name */);
|
|
2408
2414
|
const constraint = this.tryParseConstraintOfInferType();
|
|
2409
2415
|
const result = new TypeParameterDeclaration(undefined, name, constraint, undefined, undefined);
|
|
2410
2416
|
this.finishNode(result, pos);
|
|
@@ -2602,11 +2608,12 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2602
2608
|
parseEntityNameOfTypeReference() {
|
|
2603
2609
|
return this.parseEntityName(true, 79 /* Diagnostics.Type_expected */);
|
|
2604
2610
|
}
|
|
2605
|
-
|
|
2611
|
+
/** An entity name; `use` is for its first identifier, the qualified names' right sides are names. */
|
|
2612
|
+
parseEntityName(allowReservedWords, diagnosticMessage, use = 1 /* IdentifierUse.Name */) {
|
|
2606
2613
|
const pos = this.nodePos();
|
|
2607
2614
|
let entity = allowReservedWords
|
|
2608
|
-
? this.parseIdentifierNameWithDiagnostic(diagnosticMessage)
|
|
2609
|
-
: this.parseIdentifierWithDiagnostic(diagnosticMessage, undefined);
|
|
2615
|
+
? this.parseIdentifierNameWithDiagnostic(diagnosticMessage, use)
|
|
2616
|
+
: this.parseIdentifierWithDiagnostic(diagnosticMessage, undefined, use);
|
|
2610
2617
|
while (this.parseOptional(24 /* SyntaxKind.DotToken */)) {
|
|
2611
2618
|
// A JSDoc-style generic; the checker reports the gap between the name and the type arguments.
|
|
2612
2619
|
if (this.token() === 29 /* SyntaxKind.LessThanToken */)
|
|
@@ -2631,20 +2638,20 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2631
2638
|
// after it). Report a missing identifier right after the dot rather than on the next token.
|
|
2632
2639
|
if (this.isKeywordStartingNextLine()) {
|
|
2633
2640
|
this.parseErrorAt(this.nodePos(), this.nodePos(), 1 /* Diagnostics.Identifier_expected */);
|
|
2634
|
-
return this.createMissingIdentifier();
|
|
2641
|
+
return this.createMissingIdentifier(1 /* IdentifierUse.Name */);
|
|
2635
2642
|
}
|
|
2636
2643
|
if (this.token() === 80 /* SyntaxKind.PrivateIdentifier */) {
|
|
2637
2644
|
this.parsePrivateIdentifier();
|
|
2638
2645
|
this.parseErrorAt(this.nodePos(), this.nodePos(), 1 /* Diagnostics.Identifier_expected */);
|
|
2639
|
-
return this.createMissingIdentifier();
|
|
2646
|
+
return this.createMissingIdentifier(1 /* IdentifierUse.Name */);
|
|
2640
2647
|
}
|
|
2641
2648
|
if (allowIdentifierNames) {
|
|
2642
2649
|
if (allowUnicodeEscapeSequenceInIdentifierName)
|
|
2643
|
-
return this.parseIdentifierName();
|
|
2644
|
-
return this.parseIdentifierNameErrorOnUnicodeEscapeSequence();
|
|
2650
|
+
return this.parseIdentifierName(1 /* IdentifierUse.Name */);
|
|
2651
|
+
return this.parseIdentifierNameErrorOnUnicodeEscapeSequence(1 /* IdentifierUse.Name */);
|
|
2645
2652
|
}
|
|
2646
2653
|
const saveHasAwaitIdentifier = this.statementHasAwaitIdentifier;
|
|
2647
|
-
const id = this.parseIdentifier();
|
|
2654
|
+
const id = this.parseIdentifier(1 /* IdentifierUse.Name */);
|
|
2648
2655
|
this.statementHasAwaitIdentifier = saveHasAwaitIdentifier;
|
|
2649
2656
|
return id;
|
|
2650
2657
|
}
|
|
@@ -2654,14 +2661,25 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2654
2661
|
tokenIsIdentifierOrKeyword(this.token()) &&
|
|
2655
2662
|
this.lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine));
|
|
2656
2663
|
}
|
|
2657
|
-
|
|
2664
|
+
/**
|
|
2665
|
+
* A new identifier of the class `use` calls for. Callers create it after the identifier's token, so
|
|
2666
|
+
* for an element name the current token tells a shorthand property from an assignment or a method.
|
|
2667
|
+
*/
|
|
2668
|
+
newIdentifier(text, use = 0 /* IdentifierUse.Reference */) {
|
|
2658
2669
|
this.identifierCount++;
|
|
2659
2670
|
if (text === 'await')
|
|
2660
2671
|
this.statementHasAwaitIdentifier = true;
|
|
2661
|
-
|
|
2672
|
+
if (use === 1 /* IdentifierUse.Name */ || (use === 2 /* IdentifierUse.ElementName */ && this.isElementNameEnd()))
|
|
2673
|
+
return new Identifier(text);
|
|
2674
|
+
return new ReferenceIdentifier(text);
|
|
2662
2675
|
}
|
|
2663
|
-
|
|
2664
|
-
|
|
2676
|
+
/** Whether the current token ends an object literal element name that is not a shorthand property. */
|
|
2677
|
+
isElementNameEnd() {
|
|
2678
|
+
const token = this.token();
|
|
2679
|
+
return token === 58 /* SyntaxKind.ColonToken */ || token === 20 /* SyntaxKind.OpenParenToken */ || token === 29 /* SyntaxKind.LessThanToken */;
|
|
2680
|
+
}
|
|
2681
|
+
createMissingIdentifier(use = 0 /* IdentifierUse.Reference */) {
|
|
2682
|
+
const result = this.newIdentifier('', use);
|
|
2665
2683
|
this.finishNode(result, this.nodePos());
|
|
2666
2684
|
return result;
|
|
2667
2685
|
}
|
|
@@ -2741,7 +2759,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2741
2759
|
const pos = this.nodePos();
|
|
2742
2760
|
let name;
|
|
2743
2761
|
if (tokenIsIdentifierOrKeyword(this.token()))
|
|
2744
|
-
name = this.parseIdentifierName();
|
|
2762
|
+
name = this.parseIdentifierName(1 /* IdentifierUse.Name */);
|
|
2745
2763
|
else if (this.token() === 10 /* SyntaxKind.StringLiteral */)
|
|
2746
2764
|
name = this.parseLiteralExpression(false);
|
|
2747
2765
|
if (name !== undefined)
|
|
@@ -2774,7 +2792,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2774
2792
|
parseTypeQuery() {
|
|
2775
2793
|
const pos = this.nodePos();
|
|
2776
2794
|
this.parseExpected(113 /* SyntaxKind.TypeOfKeyword */);
|
|
2777
|
-
const entityName = this.parseEntityName(true, undefined);
|
|
2795
|
+
const entityName = this.parseEntityName(true, undefined, 0 /* IdentifierUse.Reference */);
|
|
2778
2796
|
// ASI: don't parse the next line's type arguments as part of an instantiation expression.
|
|
2779
2797
|
const typeArguments = this.hasPrecedingLineBreak() ? undefined : this.parseTypeArguments();
|
|
2780
2798
|
return this.finishNode(new TypeQueryNode(entityName, typeArguments), pos);
|
|
@@ -2810,7 +2828,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2810
2828
|
}
|
|
2811
2829
|
parseMappedTypeParameter() {
|
|
2812
2830
|
const pos = this.nodePos();
|
|
2813
|
-
const name = this.parseIdentifierName();
|
|
2831
|
+
const name = this.parseIdentifierName(1 /* IdentifierUse.Name */);
|
|
2814
2832
|
this.parseExpected(102 /* SyntaxKind.InKeyword */);
|
|
2815
2833
|
const type = this.parseType();
|
|
2816
2834
|
const result = new TypeParameterDeclaration(undefined, name, type, undefined, undefined);
|
|
@@ -2855,7 +2873,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2855
2873
|
parseTypeParameter() {
|
|
2856
2874
|
const pos = this.nodePos();
|
|
2857
2875
|
const modifiers = this.parseModifiersEx(false, true, false);
|
|
2858
|
-
const name = this.parseIdentifier();
|
|
2876
|
+
const name = this.parseIdentifier(1 /* IdentifierUse.Name */);
|
|
2859
2877
|
let constraint;
|
|
2860
2878
|
let expression;
|
|
2861
2879
|
if (this.parseOptional(95 /* SyntaxKind.ExtendsKeyword */)) {
|
|
@@ -2909,7 +2927,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2909
2927
|
const modifiers = this.parseModifiersEx(true, false, false);
|
|
2910
2928
|
this.contextFlags = saveContextFlags;
|
|
2911
2929
|
if (this.token() === 109 /* SyntaxKind.ThisKeyword */) {
|
|
2912
|
-
const result = new ParameterDeclaration(modifiers, undefined, this.createIdentifier(true), undefined, this.parseTypeAnnotation(), undefined);
|
|
2930
|
+
const result = new ParameterDeclaration(modifiers, undefined, this.createIdentifier(true, 1 /* IdentifierUse.Name */), undefined, this.parseTypeAnnotation(), undefined);
|
|
2913
2931
|
if (modifiers !== undefined) {
|
|
2914
2932
|
const first = modifiers.nodes[0];
|
|
2915
2933
|
this.parseErrorAt(first.pos, first.end, 359 /* Diagnostics.Neither_decorators_nor_modifiers_may_be_applied_to_this_parameters */);
|
|
@@ -2970,7 +2988,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2970
2988
|
if (this.isIdentifier()) {
|
|
2971
2989
|
const state = this.beginSpeculation();
|
|
2972
2990
|
const pos = this.nodePos();
|
|
2973
|
-
const id = this.parseIdentifier();
|
|
2991
|
+
const id = this.parseIdentifier(1 /* IdentifierUse.Name */);
|
|
2974
2992
|
if (this.token() === 142 /* SyntaxKind.IsKeyword */ && !this.hasPrecedingLineBreak()) {
|
|
2975
2993
|
this.endSpeculation(state);
|
|
2976
2994
|
this.nextToken();
|
|
@@ -3000,13 +3018,13 @@ export class Parser extends ScannerErrorReporter {
|
|
|
3000
3018
|
this.checkJSSyntax(result);
|
|
3001
3019
|
return result;
|
|
3002
3020
|
}
|
|
3003
|
-
parsePropertyName() {
|
|
3021
|
+
parsePropertyName(use = 1 /* IdentifierUse.Name */) {
|
|
3004
3022
|
const saveHasAwaitIdentifier = this.statementHasAwaitIdentifier;
|
|
3005
|
-
const prop = this.parsePropertyNameWorker(true);
|
|
3023
|
+
const prop = this.parsePropertyNameWorker(true, use);
|
|
3006
3024
|
this.statementHasAwaitIdentifier = saveHasAwaitIdentifier;
|
|
3007
3025
|
return prop;
|
|
3008
3026
|
}
|
|
3009
|
-
parsePropertyNameWorker(allowComputedPropertyNames) {
|
|
3027
|
+
parsePropertyNameWorker(allowComputedPropertyNames, use = 1 /* IdentifierUse.Name */) {
|
|
3010
3028
|
const token = this.token();
|
|
3011
3029
|
if (token === 10 /* SyntaxKind.StringLiteral */ || token === 8 /* SyntaxKind.NumericLiteral */ || token === 9 /* SyntaxKind.BigIntLiteral */)
|
|
3012
3030
|
return this.parseLiteralExpression(true);
|
|
@@ -3014,7 +3032,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
3014
3032
|
return this.parseComputedPropertyName();
|
|
3015
3033
|
if (token === 80 /* SyntaxKind.PrivateIdentifier */)
|
|
3016
3034
|
return this.parsePrivateIdentifier();
|
|
3017
|
-
return this.parseIdentifierName();
|
|
3035
|
+
return this.parseIdentifierName(use);
|
|
3018
3036
|
}
|
|
3019
3037
|
parseComputedPropertyName() {
|
|
3020
3038
|
const pos = this.nodePos();
|
|
@@ -3099,7 +3117,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
3099
3117
|
const pos = this.nodePos();
|
|
3100
3118
|
const jsdoc = this.jsdocScannerInfo();
|
|
3101
3119
|
const dotDotDotToken = this.parseOptionalToken(25 /* SyntaxKind.DotDotDotToken */);
|
|
3102
|
-
const name = this.parseIdentifierName();
|
|
3120
|
+
const name = this.parseIdentifierName(1 /* IdentifierUse.Name */);
|
|
3103
3121
|
const questionToken = this.parseOptionalToken(57 /* SyntaxKind.QuestionToken */);
|
|
3104
3122
|
this.parseExpected(58 /* SyntaxKind.ColonToken */);
|
|
3105
3123
|
const type = this.parseTupleElementType();
|
|
@@ -3132,7 +3150,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
3132
3150
|
parseAssertsTypePredicate() {
|
|
3133
3151
|
const pos = this.nodePos();
|
|
3134
3152
|
const assertsModifier = this.parseExpectedToken(130 /* SyntaxKind.AssertsKeyword */);
|
|
3135
|
-
const parameterName = this.token() === 109 /* SyntaxKind.ThisKeyword */ ? this.parseThisTypeNode() : this.parseIdentifier();
|
|
3153
|
+
const parameterName = this.token() === 109 /* SyntaxKind.ThisKeyword */ ? this.parseThisTypeNode() : this.parseIdentifier(1 /* IdentifierUse.Name */);
|
|
3136
3154
|
const type = this.parseOptional(142 /* SyntaxKind.IsKeyword */) ? this.parseType() : undefined;
|
|
3137
3155
|
return this.finishNode(new TypePredicateNode(assertsModifier, parameterName, type), pos);
|
|
3138
3156
|
}
|
|
@@ -4101,10 +4119,10 @@ export class Parser extends ScannerErrorReporter {
|
|
|
4101
4119
|
parseJsxAttributeName() {
|
|
4102
4120
|
const pos = this.nodePos();
|
|
4103
4121
|
this.scanJsxIdentifier();
|
|
4104
|
-
const attrName = this.parseIdentifierNameErrorOnUnicodeEscapeSequence();
|
|
4122
|
+
const attrName = this.parseIdentifierNameErrorOnUnicodeEscapeSequence(1 /* IdentifierUse.Name */);
|
|
4105
4123
|
if (this.parseOptional(58 /* SyntaxKind.ColonToken */)) {
|
|
4106
4124
|
this.scanJsxIdentifier();
|
|
4107
|
-
return this.finishNode(new JsxNamespacedName(attrName, this.parseIdentifierNameErrorOnUnicodeEscapeSequence()), pos);
|
|
4125
|
+
return this.finishNode(new JsxNamespacedName(attrName, this.parseIdentifierNameErrorOnUnicodeEscapeSequence(1 /* IdentifierUse.Name */)), pos);
|
|
4108
4126
|
}
|
|
4109
4127
|
return attrName;
|
|
4110
4128
|
}
|
|
@@ -4222,7 +4240,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
4222
4240
|
// An `import.*` meta property, such as `import.meta`.
|
|
4223
4241
|
this.nextToken();
|
|
4224
4242
|
this.nextToken();
|
|
4225
|
-
const name = this.parseIdentifierName();
|
|
4243
|
+
const name = this.parseIdentifierName(1 /* IdentifierUse.Name */);
|
|
4226
4244
|
expression = this.finishNode(new MetaProperty(101 /* SyntaxKind.ImportKeyword */, name), pos);
|
|
4227
4245
|
if (name.text === 'defer') {
|
|
4228
4246
|
if (this.token() === 20 /* SyntaxKind.OpenParenToken */ || this.token() === 29 /* SyntaxKind.LessThanToken */)
|
|
@@ -4440,7 +4458,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
4440
4458
|
const inner = expression;
|
|
4441
4459
|
const argumentList = this.parseArgumentList();
|
|
4442
4460
|
const isOptionalChain = questionDotToken !== undefined || this.tryReparseOptionalChain(expression);
|
|
4443
|
-
expression = this.checkJSSyntax(this.finishNode(
|
|
4461
|
+
expression = this.checkJSSyntax(this.finishNode(newCallExpression(expression, questionDotToken, typeArguments, argumentList, isOptionalChain ? 32 /* NodeFlags.OptionalChain */ : 0 /* NodeFlags.None */, (this.contextFlags & 65536 /* NodeFlags.JavaScriptFile */) !== 0), pos));
|
|
4444
4462
|
this.unparseExpressionWithTypeArguments(inner, typeArguments, expression);
|
|
4445
4463
|
continue;
|
|
4446
4464
|
}
|
|
@@ -4606,7 +4624,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
4606
4624
|
return this.parseAccessorDeclaration(pos, jsdoc, modifiers, 179 /* SyntaxKind.SetAccessor */, 0 /* ParseFlags.None */);
|
|
4607
4625
|
const asteriskToken = this.parseOptionalToken(41 /* SyntaxKind.AsteriskToken */);
|
|
4608
4626
|
const tokenIsIdentifier = this.isIdentifier();
|
|
4609
|
-
const name = this.parsePropertyName();
|
|
4627
|
+
const name = this.parsePropertyName(2 /* IdentifierUse.ElementName */);
|
|
4610
4628
|
// The grammar checker reports optional property assignments, definite assignment assertions,
|
|
4611
4629
|
// decorators and modifiers.
|
|
4612
4630
|
let postfixToken = this.parseOptionalToken(57 /* SyntaxKind.QuestionToken */);
|
|
@@ -4627,7 +4645,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
4627
4645
|
else {
|
|
4628
4646
|
this.parseExpected(58 /* SyntaxKind.ColonToken */);
|
|
4629
4647
|
const initializer = this.parseAssignmentExpressionOrHigherAllowIn();
|
|
4630
|
-
node =
|
|
4648
|
+
node = newPropertyAssignment(modifiers, name, postfixToken, undefined, initializer, (this.contextFlags & 65536 /* NodeFlags.JavaScriptFile */) !== 0);
|
|
4631
4649
|
}
|
|
4632
4650
|
return this.finishWithJSDoc(node, pos, jsdoc);
|
|
4633
4651
|
}
|
|
@@ -4683,7 +4701,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
4683
4701
|
const pos = this.nodePos();
|
|
4684
4702
|
this.parseExpected(104 /* SyntaxKind.NewKeyword */);
|
|
4685
4703
|
if (this.parseOptional(24 /* SyntaxKind.DotToken */)) {
|
|
4686
|
-
const name = this.parseIdentifierName();
|
|
4704
|
+
const name = this.parseIdentifierName(1 /* IdentifierUse.Name */);
|
|
4687
4705
|
return this.finishNode(new MetaProperty(104 /* SyntaxKind.NewKeyword */, name), pos);
|
|
4688
4706
|
}
|
|
4689
4707
|
const expressionPos = this.nodePos();
|
|
@@ -4739,36 +4757,36 @@ export class Parser extends ScannerErrorReporter {
|
|
|
4739
4757
|
return this.finishNode(result, pos);
|
|
4740
4758
|
}
|
|
4741
4759
|
// Identifiers
|
|
4742
|
-
parseIdentifierNameErrorOnUnicodeEscapeSequence() {
|
|
4760
|
+
parseIdentifierNameErrorOnUnicodeEscapeSequence(use = 0 /* IdentifierUse.Reference */) {
|
|
4743
4761
|
if (this.scanner.hasUnicodeEscape() || this.scanner.hasExtendedUnicodeEscape())
|
|
4744
4762
|
this.parseErrorAtCurrentToken(1824 /* Diagnostics.Unicode_escape_sequence_cannot_appear_here */);
|
|
4745
|
-
return this.createIdentifier(tokenIsIdentifierOrKeyword(this.token()));
|
|
4763
|
+
return this.createIdentifier(tokenIsIdentifierOrKeyword(this.token()), use);
|
|
4746
4764
|
}
|
|
4747
4765
|
parseBindingIdentifier() {
|
|
4748
4766
|
return this.parseBindingIdentifierWithDiagnostic(undefined);
|
|
4749
4767
|
}
|
|
4750
4768
|
parseBindingIdentifierWithDiagnostic(privateIdentifierDiagnosticMessage) {
|
|
4751
4769
|
const saveHasAwaitIdentifier = this.statementHasAwaitIdentifier;
|
|
4752
|
-
const id = this.createIdentifierWithDiagnostic(this.isBindingIdentifier(), undefined, privateIdentifierDiagnosticMessage);
|
|
4770
|
+
const id = this.createIdentifierWithDiagnostic(this.isBindingIdentifier(), undefined, privateIdentifierDiagnosticMessage, 1 /* IdentifierUse.Name */);
|
|
4753
4771
|
this.statementHasAwaitIdentifier = saveHasAwaitIdentifier;
|
|
4754
4772
|
return id;
|
|
4755
4773
|
}
|
|
4756
|
-
parseIdentifierName() {
|
|
4757
|
-
return this.parseIdentifierNameWithDiagnostic(undefined);
|
|
4774
|
+
parseIdentifierName(use = 0 /* IdentifierUse.Reference */) {
|
|
4775
|
+
return this.parseIdentifierNameWithDiagnostic(undefined, use);
|
|
4758
4776
|
}
|
|
4759
|
-
parseIdentifierNameWithDiagnostic(diagnosticMessage) {
|
|
4760
|
-
return this.createIdentifierWithDiagnostic(tokenIsIdentifierOrKeyword(this.token()), diagnosticMessage, undefined);
|
|
4777
|
+
parseIdentifierNameWithDiagnostic(diagnosticMessage, use = 0 /* IdentifierUse.Reference */) {
|
|
4778
|
+
return this.createIdentifierWithDiagnostic(tokenIsIdentifierOrKeyword(this.token()), diagnosticMessage, undefined, use);
|
|
4761
4779
|
}
|
|
4762
|
-
parseIdentifier() {
|
|
4763
|
-
return this.parseIdentifierWithDiagnostic(undefined, undefined);
|
|
4780
|
+
parseIdentifier(use = 0 /* IdentifierUse.Reference */) {
|
|
4781
|
+
return this.parseIdentifierWithDiagnostic(undefined, undefined, use);
|
|
4764
4782
|
}
|
|
4765
|
-
parseIdentifierWithDiagnostic(diagnosticMessage, privateIdentifierDiagnosticMessage) {
|
|
4766
|
-
return this.createIdentifierWithDiagnostic(this.isIdentifier(), diagnosticMessage, privateIdentifierDiagnosticMessage);
|
|
4783
|
+
parseIdentifierWithDiagnostic(diagnosticMessage, privateIdentifierDiagnosticMessage, use = 0 /* IdentifierUse.Reference */) {
|
|
4784
|
+
return this.createIdentifierWithDiagnostic(this.isIdentifier(), diagnosticMessage, privateIdentifierDiagnosticMessage, use);
|
|
4767
4785
|
}
|
|
4768
|
-
createIdentifier(isIdentifier) {
|
|
4769
|
-
return this.createIdentifierWithDiagnostic(isIdentifier, undefined, undefined);
|
|
4786
|
+
createIdentifier(isIdentifier, use = 0 /* IdentifierUse.Reference */) {
|
|
4787
|
+
return this.createIdentifierWithDiagnostic(isIdentifier, undefined, undefined, use);
|
|
4770
4788
|
}
|
|
4771
|
-
createIdentifierWithDiagnostic(isIdentifier, diagnosticMessage, privateIdentifierDiagnosticMessage) {
|
|
4789
|
+
createIdentifierWithDiagnostic(isIdentifier, diagnosticMessage, privateIdentifierDiagnosticMessage, use = 0 /* IdentifierUse.Reference */) {
|
|
4772
4790
|
if (isIdentifier) {
|
|
4773
4791
|
const pos = this.scanner.hasPrecedingJSDocLeadingAsterisks() ? this.scanner.getTokenStart() : this.nodePos();
|
|
4774
4792
|
const text = this.scanner.getIdentifierValue();
|
|
@@ -4776,7 +4794,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
4776
4794
|
this.nextTokenWithoutCheck();
|
|
4777
4795
|
if (record)
|
|
4778
4796
|
this.identifierTexts.push(text);
|
|
4779
|
-
const result = this.newIdentifier(text);
|
|
4797
|
+
const result = this.newIdentifier(text, use);
|
|
4780
4798
|
this.finishNode(result, pos);
|
|
4781
4799
|
return result;
|
|
4782
4800
|
}
|
|
@@ -4784,7 +4802,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
4784
4802
|
this.parseErrorAtCurrentToken(privateIdentifierDiagnosticMessage !== undefined
|
|
4785
4803
|
? privateIdentifierDiagnosticMessage
|
|
4786
4804
|
: 1838 /* Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies */);
|
|
4787
|
-
return this.createIdentifier(true);
|
|
4805
|
+
return this.createIdentifier(true, use);
|
|
4788
4806
|
}
|
|
4789
4807
|
// Report at the current position only at the end of the file: elsewhere the error would land
|
|
4790
4808
|
// incorrectly on embedded script tags.
|
|
@@ -4809,7 +4827,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
4809
4827
|
else {
|
|
4810
4828
|
this.parseErrorAtCurrentToken(1 /* Diagnostics.Identifier_expected */);
|
|
4811
4829
|
}
|
|
4812
|
-
return this.createMissingIdentifier();
|
|
4830
|
+
return this.createMissingIdentifier(use);
|
|
4813
4831
|
}
|
|
4814
4832
|
internIdentifier(text) {
|
|
4815
4833
|
this.identifierTexts.push(text);
|
|
@@ -5531,9 +5549,9 @@ export class Parser extends ScannerErrorReporter {
|
|
|
5531
5549
|
// Pragmas
|
|
5532
5550
|
processPragmasIntoFields(file) {
|
|
5533
5551
|
file.checkJsDirective = undefined;
|
|
5534
|
-
file.referencedFiles =
|
|
5535
|
-
file.typeReferenceDirectives =
|
|
5536
|
-
file.libReferenceDirectives =
|
|
5552
|
+
file.referencedFiles = emptyFileReferences;
|
|
5553
|
+
file.typeReferenceDirectives = emptyFileReferences;
|
|
5554
|
+
file.libReferenceDirectives = emptyFileReferences;
|
|
5537
5555
|
for (const pragma of file.pragmas) {
|
|
5538
5556
|
switch (pragma.name) {
|
|
5539
5557
|
case 'reference': {
|
|
@@ -5552,13 +5570,13 @@ export class Parser extends ScannerErrorReporter {
|
|
|
5552
5570
|
const parsed = resolutionMode !== undefined
|
|
5553
5571
|
? this.parseResolutionMode(resolutionMode.value, resolutionMode.pos, resolutionMode.end)
|
|
5554
5572
|
: ModuleKind.None;
|
|
5555
|
-
file.typeReferenceDirectives.
|
|
5573
|
+
file.typeReferenceDirectives = appendToList(file.typeReferenceDirectives, new FileReference(types.pos, types.end, types.value, parsed, isPreserved));
|
|
5556
5574
|
}
|
|
5557
5575
|
else if (lib !== undefined) {
|
|
5558
|
-
file.libReferenceDirectives.
|
|
5576
|
+
file.libReferenceDirectives = appendToList(file.libReferenceDirectives, new FileReference(lib.pos, lib.end, lib.value, ModuleKind.None, isPreserved));
|
|
5559
5577
|
}
|
|
5560
5578
|
else if (path !== undefined) {
|
|
5561
|
-
file.referencedFiles.
|
|
5579
|
+
file.referencedFiles = appendToList(file.referencedFiles, new FileReference(path.pos, path.end, path.value, ModuleKind.None, isPreserved));
|
|
5562
5580
|
}
|
|
5563
5581
|
else {
|
|
5564
5582
|
this.parseErrorAt(pragma.range.pos, pragma.range.end, 57 /* Diagnostics.Invalid_reference_directive_syntax */);
|
|
@@ -5698,6 +5716,16 @@ export function forgetLazyJSDocFile() {
|
|
|
5698
5716
|
lazyJSDocFile = undefined;
|
|
5699
5717
|
}
|
|
5700
5718
|
const viableKeywordSuggestions = getViableKeywordSuggestions();
|
|
5719
|
+
// A parser whose JSDoc parser released parsers keep (`Parser.release`), created on first use.
|
|
5720
|
+
let releasedParserValue;
|
|
5721
|
+
function releasedParser() {
|
|
5722
|
+
let parser = releasedParserValue;
|
|
5723
|
+
if (parser === undefined) {
|
|
5724
|
+
parser = new Parser('/', '/', '', 3 /* ScriptKind.TS */, new ExternalModuleIndicatorOptions(false, false));
|
|
5725
|
+
releasedParserValue = parser;
|
|
5726
|
+
}
|
|
5727
|
+
return parser;
|
|
5728
|
+
}
|
|
5701
5729
|
function getSpaceSuggestion(expressionText) {
|
|
5702
5730
|
for (const keyword of viableKeywordSuggestions)
|
|
5703
5731
|
if (expressionText.length > keyword.length + 2 && expressionText.startsWith(keyword))
|
|
@@ -5757,7 +5785,7 @@ function typeHasBlockingError(node) {
|
|
|
5757
5785
|
}
|
|
5758
5786
|
function attachFileToDiagnostics(diagnostics, file) {
|
|
5759
5787
|
if (diagnostics.length === 0)
|
|
5760
|
-
return
|
|
5788
|
+
return emptyDiagnostics;
|
|
5761
5789
|
const diagnosticFile = file.diagnosticFile();
|
|
5762
5790
|
for (const d of diagnostics) {
|
|
5763
5791
|
d.file = diagnosticFile;
|
|
@@ -6015,12 +6043,13 @@ function nextTokenIsNotColon(p) {
|
|
|
6015
6043
|
}
|
|
6016
6044
|
// Pragmas
|
|
6017
6045
|
function getCommentPragmas(sourceText) {
|
|
6018
|
-
const pragmas = [];
|
|
6019
6046
|
const ranges = getLeadingCommentRanges(sourceText, 0);
|
|
6020
|
-
if (ranges
|
|
6021
|
-
|
|
6022
|
-
|
|
6023
|
-
|
|
6047
|
+
if (ranges === undefined)
|
|
6048
|
+
return emptyPragmas;
|
|
6049
|
+
const pragmas = [];
|
|
6050
|
+
for (const range of ranges)
|
|
6051
|
+
extractPragmas(range, sourceText.substring(range.pos, range.end), pragmas);
|
|
6052
|
+
return pragmas.length === 0 ? emptyPragmas : pragmas;
|
|
6024
6053
|
}
|
|
6025
6054
|
function extractPragmas(range, text, pragmas) {
|
|
6026
6055
|
if (range.kind === 2 /* SyntaxKind.SingleLineCommentTrivia */) {
|
|
@@ -6181,10 +6210,10 @@ function collectModuleReferences(file, node, inAmbientModule) {
|
|
|
6181
6210
|
(inAmbientModule || hasModifierFlag(node, 128 /* ModifierFlags.Ambient */) || file.isDeclarationFile)) {
|
|
6182
6211
|
const nameText = getText(node.name);
|
|
6183
6212
|
if (file.externalModuleIndicator !== undefined || (inAmbientModule && !isExternalModuleNameRelative(nameText))) {
|
|
6184
|
-
file.moduleAugmentations.
|
|
6213
|
+
file.moduleAugmentations = appendToList(file.moduleAugmentations, node.name);
|
|
6185
6214
|
}
|
|
6186
6215
|
else if (!inAmbientModule) {
|
|
6187
|
-
file.ambientModuleNames.
|
|
6216
|
+
file.ambientModuleNames = appendToList(file.ambientModuleNames, nameText);
|
|
6188
6217
|
const body = node.body;
|
|
6189
6218
|
if (body !== undefined) {
|
|
6190
6219
|
const statements = getStatements(body);
|