tsc-ts 0.0.4 → 0.0.5
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 +33 -1
- package/dist/api/compiler/ast-utilities.d.ts +82 -0
- package/dist/api/compiler/ast-utilities.js +462 -0
- package/dist/api/compiler/ast.d.ts +2350 -0
- package/dist/api/compiler/ast.js +11206 -0
- package/dist/api/compiler/astnav.d.ts +37 -0
- package/dist/api/compiler/astnav.js +767 -0
- package/dist/api/compiler/binder-utilities.d.ts +182 -0
- package/dist/api/compiler/binder-utilities.js +1240 -0
- package/dist/api/compiler/binder.d.ts +33 -0
- package/dist/api/compiler/binder.js +2358 -0
- package/dist/api/compiler/character-codes.d.ts +161 -0
- package/dist/api/compiler/character-codes.js +160 -0
- package/dist/api/compiler/checker-calls.d.ts +46 -0
- package/dist/api/compiler/checker-calls.js +1640 -0
- package/dist/api/compiler/checker-classes.d.ts +30 -0
- package/dist/api/compiler/checker-classes.js +582 -0
- package/dist/api/compiler/checker-contextual.d.ts +77 -0
- package/dist/api/compiler/checker-contextual.js +1136 -0
- package/dist/api/compiler/checker-declaration-order.d.ts +12 -0
- package/dist/api/compiler/checker-declaration-order.js +356 -0
- package/dist/api/compiler/checker-declarations.d.ts +33 -0
- package/dist/api/compiler/checker-declarations.js +888 -0
- package/dist/api/compiler/checker-declared-types.d.ts +48 -0
- package/dist/api/compiler/checker-declared-types.js +787 -0
- package/dist/api/compiler/checker-decorators.d.ts +26 -0
- package/dist/api/compiler/checker-decorators.js +562 -0
- package/dist/api/compiler/checker-deprecation.d.ts +33 -0
- package/dist/api/compiler/checker-deprecation.js +315 -0
- package/dist/api/compiler/checker-destructuring.d.ts +34 -0
- package/dist/api/compiler/checker-destructuring.js +584 -0
- package/dist/api/compiler/checker-elaboration.d.ts +15 -0
- package/dist/api/compiler/checker-elaboration.js +290 -0
- package/dist/api/compiler/checker-emit-helpers.d.ts +58 -0
- package/dist/api/compiler/checker-emit-helpers.js +154 -0
- package/dist/api/compiler/checker-emit-resolver.d.ts +75 -0
- package/dist/api/compiler/checker-emit-resolver.js +579 -0
- package/dist/api/compiler/checker-evaluator.d.ts +27 -0
- package/dist/api/compiler/checker-evaluator.js +188 -0
- package/dist/api/compiler/checker-expressions.d.ts +67 -0
- package/dist/api/compiler/checker-expressions.js +1351 -0
- package/dist/api/compiler/checker-features.d.ts +6 -0
- package/dist/api/compiler/checker-features.js +354 -0
- package/dist/api/compiler/checker-flow.d.ts +86 -0
- package/dist/api/compiler/checker-flow.js +169 -0
- package/dist/api/compiler/checker-functions.d.ts +43 -0
- package/dist/api/compiler/checker-functions.js +1002 -0
- package/dist/api/compiler/checker-generated-code.d.ts +25 -0
- package/dist/api/compiler/checker-generated-code.js +168 -0
- package/dist/api/compiler/checker-globals.d.ts +14 -0
- package/dist/api/compiler/checker-globals.js +37 -0
- package/dist/api/compiler/checker-grammar.d.ts +35 -0
- package/dist/api/compiler/checker-grammar.js +2573 -0
- package/dist/api/compiler/checker-heritage.d.ts +28 -0
- package/dist/api/compiler/checker-heritage.js +900 -0
- package/dist/api/compiler/checker-inference.d.ts +179 -0
- package/dist/api/compiler/checker-inference.js +2105 -0
- package/dist/api/compiler/checker-iteration.d.ts +115 -0
- package/dist/api/compiler/checker-iteration.js +857 -0
- package/dist/api/compiler/checker-javascript.d.ts +42 -0
- package/dist/api/compiler/checker-javascript.js +441 -0
- package/dist/api/compiler/checker-jsdoc.d.ts +30 -0
- package/dist/api/compiler/checker-jsdoc.js +320 -0
- package/dist/api/compiler/checker-jsx.d.ts +94 -0
- package/dist/api/compiler/checker-jsx.js +1433 -0
- package/dist/api/compiler/checker-literals.d.ts +6 -0
- package/dist/api/compiler/checker-literals.js +43 -0
- package/dist/api/compiler/checker-members.d.ts +198 -0
- package/dist/api/compiler/checker-members.js +2126 -0
- package/dist/api/compiler/checker-modules.d.ts +85 -0
- package/dist/api/compiler/checker-modules.js +2141 -0
- package/dist/api/compiler/checker-narrowing.d.ts +120 -0
- package/dist/api/compiler/checker-narrowing.js +2797 -0
- package/dist/api/compiler/checker-object-literals.d.ts +14 -0
- package/dist/api/compiler/checker-object-literals.js +479 -0
- package/dist/api/compiler/checker-operators.d.ts +33 -0
- package/dist/api/compiler/checker-operators.js +1040 -0
- package/dist/api/compiler/checker-overloads.d.ts +7 -0
- package/dist/api/compiler/checker-overloads.js +270 -0
- package/dist/api/compiler/checker-property-access.d.ts +34 -0
- package/dist/api/compiler/checker-property-access.js +672 -0
- package/dist/api/compiler/checker-services.d.ts +49 -0
- package/dist/api/compiler/checker-services.js +995 -0
- package/dist/api/compiler/checker-signatures.d.ts +55 -0
- package/dist/api/compiler/checker-signatures.js +788 -0
- package/dist/api/compiler/checker-source-file.d.ts +27 -0
- package/dist/api/compiler/checker-source-file.js +619 -0
- package/dist/api/compiler/checker-statements.d.ts +18 -0
- package/dist/api/compiler/checker-statements.js +226 -0
- package/dist/api/compiler/checker-super.d.ts +13 -0
- package/dist/api/compiler/checker-super.js +241 -0
- package/dist/api/compiler/checker-symbol-types.d.ts +67 -0
- package/dist/api/compiler/checker-symbol-types.js +1885 -0
- package/dist/api/compiler/checker-symbols.d.ts +181 -0
- package/dist/api/compiler/checker-symbols.js +1782 -0
- package/dist/api/compiler/checker-type-factory.d.ts +142 -0
- package/dist/api/compiler/checker-type-factory.js +2501 -0
- package/dist/api/compiler/checker-type-nodes.d.ts +26 -0
- package/dist/api/compiler/checker-type-nodes.js +828 -0
- package/dist/api/compiler/checker-type-operators.d.ts +109 -0
- package/dist/api/compiler/checker-type-operators.js +1842 -0
- package/dist/api/compiler/checker-types.d.ts +1027 -0
- package/dist/api/compiler/checker-types.js +1697 -0
- package/dist/api/compiler/checker-unused.d.ts +19 -0
- package/dist/api/compiler/checker-unused.js +524 -0
- package/dist/api/compiler/checker-utilities.d.ts +33 -0
- package/dist/api/compiler/checker-utilities.js +141 -0
- package/dist/api/compiler/checker.d.ts +491 -0
- package/dist/api/compiler/checker.js +912 -0
- package/dist/api/compiler/command-line.d.ts +32 -0
- package/dist/api/compiler/command-line.js +383 -0
- package/dist/api/compiler/compile-program.d.ts +118 -0
- package/dist/api/compiler/compile-program.js +384 -0
- package/dist/api/compiler/diagnostic-locales.d.ts +22 -0
- package/dist/api/compiler/diagnostic-locales.js +64 -0
- package/dist/api/compiler/diagnostic-messages.d.ts +2166 -0
- package/dist/api/compiler/diagnostic-messages.js +184 -0
- package/dist/api/compiler/diagnostics.d.ts +167 -0
- package/dist/api/compiler/diagnostics.js +820 -0
- package/dist/api/compiler/emitter.d.ts +71 -0
- package/dist/api/compiler/emitter.js +327 -0
- package/dist/api/compiler/file-include.d.ts +117 -0
- package/dist/api/compiler/file-include.js +536 -0
- package/dist/api/compiler/file-loader.d.ts +261 -0
- package/dist/api/compiler/file-loader.js +1257 -0
- package/dist/api/compiler/file-system.d.ts +51 -0
- package/dist/api/compiler/file-system.js +132 -0
- package/dist/api/compiler/flow.d.ts +60 -0
- package/dist/api/compiler/flow.js +45 -0
- package/dist/api/compiler/instantiation.d.ts +74 -0
- package/dist/api/compiler/instantiation.js +799 -0
- package/dist/api/compiler/jsdoc.d.ts +75 -0
- package/dist/api/compiler/jsdoc.js +1229 -0
- package/dist/api/compiler/link-tables.d.ts +36 -0
- package/dist/api/compiler/link-tables.js +83 -0
- package/dist/api/compiler/locale-data.d.ts +24 -0
- package/dist/api/compiler/locale-data.js +183 -0
- package/dist/api/compiler/locale.d.ts +4 -0
- package/dist/api/compiler/locale.js +317 -0
- package/dist/api/compiler/locales/cs-CZ.d.ts +2 -0
- package/dist/api/compiler/locales/cs-CZ.js +3 -0
- package/dist/api/compiler/locales/de-DE.d.ts +2 -0
- package/dist/api/compiler/locales/de-DE.js +3 -0
- package/dist/api/compiler/locales/es-ES.d.ts +2 -0
- package/dist/api/compiler/locales/es-ES.js +3 -0
- package/dist/api/compiler/locales/fr-FR.d.ts +2 -0
- package/dist/api/compiler/locales/fr-FR.js +3 -0
- package/dist/api/compiler/locales/it-IT.d.ts +2 -0
- package/dist/api/compiler/locales/it-IT.js +3 -0
- package/dist/api/compiler/locales/ja-JP.d.ts +2 -0
- package/dist/api/compiler/locales/ja-JP.js +3 -0
- package/dist/api/compiler/locales/ko-KR.d.ts +2 -0
- package/dist/api/compiler/locales/ko-KR.js +3 -0
- package/dist/api/compiler/locales/pl-PL.d.ts +2 -0
- package/dist/api/compiler/locales/pl-PL.js +3 -0
- package/dist/api/compiler/locales/pt-BR.d.ts +2 -0
- package/dist/api/compiler/locales/pt-BR.js +3 -0
- package/dist/api/compiler/locales/ru-RU.d.ts +2 -0
- package/dist/api/compiler/locales/ru-RU.js +3 -0
- package/dist/api/compiler/locales/tr-TR.d.ts +2 -0
- package/dist/api/compiler/locales/tr-TR.js +3 -0
- package/dist/api/compiler/locales/zh-CN.d.ts +2 -0
- package/dist/api/compiler/locales/zh-CN.js +3 -0
- package/dist/api/compiler/locales/zh-TW.d.ts +2 -0
- package/dist/api/compiler/locales/zh-TW.js +3 -0
- package/dist/api/compiler/module-resolution-types.d.ts +83 -0
- package/dist/api/compiler/module-resolution-types.js +176 -0
- package/dist/api/compiler/module-resolution.d.ts +71 -0
- package/dist/api/compiler/module-resolution.js +1598 -0
- package/dist/api/compiler/module-specifiers.d.ts +64 -0
- package/dist/api/compiler/module-specifiers.js +1101 -0
- package/dist/api/compiler/name-resolver.d.ts +43 -0
- package/dist/api/compiler/name-resolver.js +509 -0
- package/dist/api/compiler/node-builder-names.d.ts +32 -0
- package/dist/api/compiler/node-builder-names.js +854 -0
- package/dist/api/compiler/node-builder-pseudo.d.ts +36 -0
- package/dist/api/compiler/node-builder-pseudo.js +744 -0
- package/dist/api/compiler/node-builder-reuse.d.ts +4 -0
- package/dist/api/compiler/node-builder-reuse.js +647 -0
- package/dist/api/compiler/node-builder.d.ts +270 -0
- package/dist/api/compiler/node-builder.js +2645 -0
- package/dist/api/compiler/option-declarations.d.ts +90 -0
- package/dist/api/compiler/option-declarations.js +1460 -0
- package/dist/api/compiler/options.d.ts +289 -0
- package/dist/api/compiler/options.js +1197 -0
- package/dist/api/compiler/output-paths.d.ts +42 -0
- package/dist/api/compiler/output-paths.js +195 -0
- package/dist/api/compiler/package-json.d.ts +175 -0
- package/dist/api/compiler/package-json.js +1015 -0
- package/dist/api/compiler/parallel-parse.d.ts +219 -0
- package/dist/api/compiler/parallel-parse.js +537 -0
- package/dist/api/compiler/parser.d.ts +587 -0
- package/dist/api/compiler/parser.js +6407 -0
- package/dist/api/compiler/path.d.ts +91 -0
- package/dist/api/compiler/path.js +705 -0
- package/dist/api/compiler/printer/async-helpers.d.ts +22 -0
- package/dist/api/compiler/printer/async-helpers.js +91 -0
- package/dist/api/compiler/printer/auto-generate.d.ts +13 -0
- package/dist/api/compiler/printer/auto-generate.js +20 -0
- package/dist/api/compiler/printer/decorator-helpers.d.ts +24 -0
- package/dist/api/compiler/printer/decorator-helpers.js +118 -0
- package/dist/api/compiler/printer/emit-context.d.ts +154 -0
- package/dist/api/compiler/printer/emit-context.js +576 -0
- package/dist/api/compiler/printer/emit-flags.d.ts +60 -0
- package/dist/api/compiler/printer/emit-flags.js +2 -0
- package/dist/api/compiler/printer/factory-base.d.ts +171 -0
- package/dist/api/compiler/printer/factory-base.js +1505 -0
- package/dist/api/compiler/printer/factory.d.ts +147 -0
- package/dist/api/compiler/printer/factory.js +542 -0
- package/dist/api/compiler/printer/helpers.d.ts +27 -0
- package/dist/api/compiler/printer/helpers.js +164 -0
- package/dist/api/compiler/printer/name-generator.d.ts +41 -0
- package/dist/api/compiler/printer/name-generator.js +283 -0
- package/dist/api/compiler/printer/printer.d.ts +411 -0
- package/dist/api/compiler/printer/printer.js +4517 -0
- package/dist/api/compiler/printer/text-writer.d.ts +46 -0
- package/dist/api/compiler/printer/text-writer.js +172 -0
- package/dist/api/compiler/printer/utilities.d.ts +82 -0
- package/dist/api/compiler/printer/utilities.js +817 -0
- package/dist/api/compiler/program-checker.d.ts +156 -0
- package/dist/api/compiler/program-checker.js +526 -0
- package/dist/api/compiler/program-utilities.d.ts +52 -0
- package/dist/api/compiler/program-utilities.js +365 -0
- package/dist/api/compiler/program.d.ts +180 -0
- package/dist/api/compiler/program.js +1011 -0
- package/dist/api/compiler/pseudo-bigint.d.ts +5 -0
- package/dist/api/compiler/pseudo-bigint.js +61 -0
- package/dist/api/compiler/regexp-checker.d.ts +38 -0
- package/dist/api/compiler/regexp-checker.js +942 -0
- package/dist/api/compiler/relations.d.ts +263 -0
- package/dist/api/compiler/relations.js +4002 -0
- package/dist/api/compiler/reparser.d.ts +48 -0
- package/dist/api/compiler/reparser.js +1323 -0
- package/dist/api/compiler/scanner.d.ts +256 -0
- package/dist/api/compiler/scanner.js +2853 -0
- package/dist/api/compiler/side-state.d.ts +16 -0
- package/dist/api/compiler/side-state.js +89 -0
- package/dist/api/compiler/sourcemap.d.ts +55 -0
- package/dist/api/compiler/sourcemap.js +340 -0
- package/dist/api/compiler/spelling.d.ts +14 -0
- package/dist/api/compiler/spelling.js +128 -0
- package/dist/api/compiler/symbol-accessibility.d.ts +57 -0
- package/dist/api/compiler/symbol-accessibility.js +894 -0
- package/dist/api/compiler/symbol.d.ts +240 -0
- package/dist/api/compiler/symbol.js +228 -0
- package/dist/api/compiler/symlinks.d.ts +32 -0
- package/dist/api/compiler/symlinks.js +114 -0
- package/dist/api/compiler/syntax-kind.d.ts +389 -0
- package/dist/api/compiler/syntax-kind.js +2 -0
- package/dist/api/compiler/timeline.d.ts +9 -0
- package/dist/api/compiler/timeline.js +54 -0
- package/dist/api/compiler/transformers/alias-references.d.ts +39 -0
- package/dist/api/compiler/transformers/alias-references.js +676 -0
- package/dist/api/compiler/transformers/async-utilities.d.ts +51 -0
- package/dist/api/compiler/transformers/async-utilities.js +260 -0
- package/dist/api/compiler/transformers/async.d.ts +53 -0
- package/dist/api/compiler/transformers/async.js +645 -0
- package/dist/api/compiler/transformers/class-fields.d.ts +206 -0
- package/dist/api/compiler/transformers/class-fields.js +2418 -0
- package/dist/api/compiler/transformers/class-utilities.d.ts +46 -0
- package/dist/api/compiler/transformers/class-utilities.js +261 -0
- package/dist/api/compiler/transformers/commonjs-module.d.ts +103 -0
- package/dist/api/compiler/transformers/commonjs-module.js +1180 -0
- package/dist/api/compiler/transformers/const-enum-inliner.d.ts +11 -0
- package/dist/api/compiler/transformers/const-enum-inliner.js +36 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.d.ts +52 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.js +538 -0
- package/dist/api/compiler/transformers/declarations-pseudo.d.ts +160 -0
- package/dist/api/compiler/transformers/declarations-pseudo.js +797 -0
- package/dist/api/compiler/transformers/declarations-resolver.d.ts +152 -0
- package/dist/api/compiler/transformers/declarations-resolver.js +35 -0
- package/dist/api/compiler/transformers/declarations-syntactic.d.ts +119 -0
- package/dist/api/compiler/transformers/declarations-syntactic.js +1582 -0
- package/dist/api/compiler/transformers/declarations-tracker.d.ts +46 -0
- package/dist/api/compiler/transformers/declarations-tracker.js +197 -0
- package/dist/api/compiler/transformers/declarations.d.ts +175 -0
- package/dist/api/compiler/transformers/declarations.js +2380 -0
- package/dist/api/compiler/transformers/decorator-metadata.d.ts +54 -0
- package/dist/api/compiler/transformers/decorator-metadata.js +554 -0
- package/dist/api/compiler/transformers/decorator-utilities.d.ts +38 -0
- package/dist/api/compiler/transformers/decorator-utilities.js +238 -0
- package/dist/api/compiler/transformers/destructuring.d.ts +25 -0
- package/dist/api/compiler/transformers/destructuring.js +626 -0
- package/dist/api/compiler/transformers/downlevel.d.ts +6 -0
- package/dist/api/compiler/transformers/downlevel.js +45 -0
- package/dist/api/compiler/transformers/emit-resolver.d.ts +61 -0
- package/dist/api/compiler/transformers/emit-resolver.js +197 -0
- package/dist/api/compiler/transformers/es-decorators.d.ts +118 -0
- package/dist/api/compiler/transformers/es-decorators.js +1901 -0
- package/dist/api/compiler/transformers/exponentiation.d.ts +11 -0
- package/dist/api/compiler/transformers/exponentiation.js +76 -0
- package/dist/api/compiler/transformers/external-module-info.d.ts +35 -0
- package/dist/api/compiler/transformers/external-module-info.js +351 -0
- package/dist/api/compiler/transformers/for-await.d.ts +43 -0
- package/dist/api/compiler/transformers/for-await.js +469 -0
- package/dist/api/compiler/transformers/import-elision.d.ts +16 -0
- package/dist/api/compiler/transformers/import-elision.js +124 -0
- package/dist/api/compiler/transformers/jsx-entities.d.ts +1 -0
- package/dist/api/compiler/transformers/jsx-entities.js +256 -0
- package/dist/api/compiler/transformers/jsx.d.ts +71 -0
- package/dist/api/compiler/transformers/jsx.js +700 -0
- package/dist/api/compiler/transformers/legacy-decorators.d.ts +56 -0
- package/dist/api/compiler/transformers/legacy-decorators.js +564 -0
- package/dist/api/compiler/transformers/logical-assignment.d.ts +14 -0
- package/dist/api/compiler/transformers/logical-assignment.js +62 -0
- package/dist/api/compiler/transformers/module-utilities.d.ts +9 -0
- package/dist/api/compiler/transformers/module-utilities.js +36 -0
- package/dist/api/compiler/transformers/module.d.ts +49 -0
- package/dist/api/compiler/transformers/module.js +296 -0
- package/dist/api/compiler/transformers/named-evaluation.d.ts +26 -0
- package/dist/api/compiler/transformers/named-evaluation.js +266 -0
- package/dist/api/compiler/transformers/nullish-coalescing.d.ts +9 -0
- package/dist/api/compiler/transformers/nullish-coalescing.js +26 -0
- package/dist/api/compiler/transformers/object-rest-spread.d.ts +34 -0
- package/dist/api/compiler/transformers/object-rest-spread.js +411 -0
- package/dist/api/compiler/transformers/optional-catch.d.ts +9 -0
- package/dist/api/compiler/transformers/optional-catch.js +20 -0
- package/dist/api/compiler/transformers/optional-chain.d.ts +14 -0
- package/dist/api/compiler/transformers/optional-chain.js +188 -0
- package/dist/api/compiler/transformers/reference-resolver.d.ts +128 -0
- package/dist/api/compiler/transformers/reference-resolver.js +1155 -0
- package/dist/api/compiler/transformers/runtime-syntax.d.ts +71 -0
- package/dist/api/compiler/transformers/runtime-syntax.js +753 -0
- package/dist/api/compiler/transformers/subtree-facts.d.ts +9 -0
- package/dist/api/compiler/transformers/subtree-facts.js +203 -0
- package/dist/api/compiler/transformers/syntax-facts.d.ts +51 -0
- package/dist/api/compiler/transformers/syntax-facts.js +254 -0
- package/dist/api/compiler/transformers/tagged-template.d.ts +17 -0
- package/dist/api/compiler/transformers/tagged-template.js +148 -0
- package/dist/api/compiler/transformers/transformer.d.ts +17 -0
- package/dist/api/compiler/transformers/transformer.js +54 -0
- package/dist/api/compiler/transformers/type-eraser.d.ts +21 -0
- package/dist/api/compiler/transformers/type-eraser.js +346 -0
- package/dist/api/compiler/transformers/type-serialization.d.ts +20 -0
- package/dist/api/compiler/transformers/type-serialization.js +347 -0
- package/dist/api/compiler/transformers/using.d.ts +56 -0
- package/dist/api/compiler/transformers/using.js +453 -0
- package/dist/api/compiler/transformers/utilities.d.ts +50 -0
- package/dist/api/compiler/transformers/utilities.js +347 -0
- package/dist/api/compiler/transformers/visitor-base.d.ts +6 -0
- package/dist/api/compiler/transformers/visitor-base.js +817 -0
- package/dist/api/compiler/transformers/visitor-hooks.d.ts +29 -0
- package/dist/api/compiler/transformers/visitor-hooks.js +189 -0
- package/dist/api/compiler/tsconfig.d.ts +177 -0
- package/dist/api/compiler/tsconfig.js +1311 -0
- package/dist/api/compiler/type-printer.d.ts +15 -0
- package/dist/api/compiler/type-printer.js +74 -0
- package/dist/api/compiler/types.d.ts +87 -0
- package/dist/api/compiler/types.js +23 -0
- package/dist/api/compiler/unicode-identifiers.d.ts +2 -0
- package/dist/api/compiler/unicode-identifiers.js +209 -0
- package/dist/api/compiler/unicode-properties.d.ts +8 -0
- package/dist/api/compiler/unicode-properties.js +531 -0
- package/dist/api/compiler/vfs-match.d.ts +24 -0
- package/dist/api/compiler/vfs-match.js +587 -0
- package/dist/api/library/ast.d.ts +3 -2
- package/dist/api/library/ast.generated.d.ts +127 -139
- package/dist/api/library/checker.d.ts +51 -0
- package/dist/api/library/checker.js +318 -0
- package/dist/api/library/diagnostics.d.ts +13 -0
- package/dist/api/library/diagnostics.js +50 -0
- package/dist/api/library/disk.d.ts +13 -0
- package/dist/api/library/disk.js +66 -0
- package/dist/api/library/errors.d.ts +13 -0
- package/dist/api/library/errors.js +24 -0
- package/dist/api/library/host.d.ts +24 -0
- package/dist/api/library/host.js +52 -0
- package/dist/api/library/index.d.ts +5 -1
- package/dist/api/library/index.js +4 -0
- package/dist/api/library/nodes.d.ts +51 -0
- package/dist/api/library/nodes.js +196 -0
- package/dist/api/library/options.d.ts +144 -0
- package/dist/api/library/options.js +308 -0
- package/dist/api/library/parse.d.ts +19 -0
- package/dist/api/library/parse.js +41 -0
- package/dist/api/library/program.d.ts +21 -0
- package/dist/api/library/program.js +234 -0
- package/dist/api/library/types.d.ts +14 -1
- package/package.json +12 -8
- package/src/compiler/ast-utilities.ts +548 -0
- package/src/compiler/ast.ts +12862 -0
- package/src/compiler/astnav.ts +799 -0
- package/src/compiler/binder-utilities.ts +1392 -0
- package/src/compiler/binder.ts +2703 -0
- package/src/compiler/build-info.ts +1197 -0
- package/src/compiler/character-codes.ts +323 -0
- package/src/compiler/checker-calls.ts +2155 -0
- package/src/compiler/checker-classes.ts +706 -0
- package/src/compiler/checker-contextual.ts +1457 -0
- package/src/compiler/checker-declaration-order.ts +438 -0
- package/src/compiler/checker-declarations.ts +1194 -0
- package/src/compiler/checker-declared-types.ts +919 -0
- package/src/compiler/checker-decorators.ts +694 -0
- package/src/compiler/checker-deprecation.ts +359 -0
- package/src/compiler/checker-destructuring.ts +805 -0
- package/src/compiler/checker-elaboration.ts +477 -0
- package/src/compiler/checker-emit-helpers.ts +224 -0
- package/src/compiler/checker-emit-resolver.ts +769 -0
- package/src/compiler/checker-evaluator.ts +243 -0
- package/src/compiler/checker-expressions.ts +1831 -0
- package/src/compiler/checker-features.ts +361 -0
- package/src/compiler/checker-flow.ts +394 -0
- package/src/compiler/checker-functions.ts +1296 -0
- package/src/compiler/checker-generated-code.ts +227 -0
- package/src/compiler/checker-globals.ts +52 -0
- package/src/compiler/checker-grammar.ts +3584 -0
- package/src/compiler/checker-heritage.ts +1233 -0
- package/src/compiler/checker-inference.ts +2576 -0
- package/src/compiler/checker-iteration.ts +1206 -0
- package/src/compiler/checker-javascript.ts +502 -0
- package/src/compiler/checker-jsdoc.ts +360 -0
- package/src/compiler/checker-jsx.ts +1924 -0
- package/src/compiler/checker-literals.ts +61 -0
- package/src/compiler/checker-members.ts +2436 -0
- package/src/compiler/checker-modules.ts +2886 -0
- package/src/compiler/checker-narrowing.ts +3230 -0
- package/src/compiler/checker-object-literals.ts +575 -0
- package/src/compiler/checker-operators.ts +1422 -0
- package/src/compiler/checker-overloads.ts +328 -0
- package/src/compiler/checker-property-access.ts +906 -0
- package/src/compiler/checker-services.ts +1149 -0
- package/src/compiler/checker-signatures.ts +1032 -0
- package/src/compiler/checker-source-file.ts +732 -0
- package/src/compiler/checker-statements.ts +292 -0
- package/src/compiler/checker-super.ts +261 -0
- package/src/compiler/checker-symbol-types.ts +2107 -0
- package/src/compiler/checker-symbols.ts +2150 -0
- package/src/compiler/checker-type-factory.ts +2579 -0
- package/src/compiler/checker-type-nodes.ts +1033 -0
- package/src/compiler/checker-type-operators.ts +2502 -0
- package/src/compiler/checker-types.ts +2340 -0
- package/src/compiler/checker-unused.ts +642 -0
- package/src/compiler/checker-utilities.ts +161 -0
- package/src/compiler/checker.ts +1116 -0
- package/src/compiler/command-line.ts +436 -0
- package/src/compiler/compile-program.ts +439 -0
- package/src/compiler/decoder.ts +1209 -0
- package/src/compiler/diagnostic-locales.ts +86 -0
- package/src/compiler/diagnostic-messages.ts +2349 -0
- package/src/compiler/diagnostics.ts +897 -0
- package/src/compiler/emitter.ts +434 -0
- package/src/compiler/encoder.ts +1945 -0
- package/src/compiler/file-include.ts +673 -0
- package/src/compiler/file-loader.ts +1528 -0
- package/src/compiler/file-system.ts +143 -0
- package/src/compiler/flow.ts +89 -0
- package/src/compiler/help.ts +473 -0
- package/src/compiler/incremental.ts +2784 -0
- package/src/compiler/init.ts +141 -0
- package/src/compiler/instantiation.ts +894 -0
- package/src/compiler/jsdoc.ts +1386 -0
- package/src/compiler/link-tables.ts +98 -0
- package/src/compiler/locale-data.ts +203 -0
- package/src/compiler/locale.ts +307 -0
- package/src/compiler/locales/cs-CZ.ts +5 -0
- package/src/compiler/locales/de-DE.ts +5 -0
- package/src/compiler/locales/es-ES.ts +5 -0
- package/src/compiler/locales/fr-FR.ts +5 -0
- package/src/compiler/locales/it-IT.ts +5 -0
- package/src/compiler/locales/ja-JP.ts +5 -0
- package/src/compiler/locales/ko-KR.ts +5 -0
- package/src/compiler/locales/pl-PL.ts +5 -0
- package/src/compiler/locales/pt-BR.ts +5 -0
- package/src/compiler/locales/ru-RU.ts +5 -0
- package/src/compiler/locales/tr-TR.ts +5 -0
- package/src/compiler/locales/zh-CN.ts +5 -0
- package/src/compiler/locales/zh-TW.ts +5 -0
- package/src/compiler/module-resolution-types.ts +243 -0
- package/src/compiler/module-resolution.ts +2072 -0
- package/src/compiler/module-specifiers.ts +1491 -0
- package/src/compiler/name-resolver.ts +646 -0
- package/src/compiler/node-builder-names.ts +1069 -0
- package/src/compiler/node-builder-pseudo.ts +892 -0
- package/src/compiler/node-builder-reuse.ts +764 -0
- package/src/compiler/node-builder.ts +3425 -0
- package/src/compiler/option-declarations.ts +1560 -0
- package/src/compiler/options.ts +1576 -0
- package/src/compiler/output-paths.ts +334 -0
- package/src/compiler/package-json.ts +1083 -0
- package/src/compiler/parallel-check.ts +1951 -0
- package/src/compiler/parallel-parse.ts +590 -0
- package/src/compiler/parse-thread.ts +140 -0
- package/src/compiler/parser.ts +7716 -0
- package/src/compiler/path.ts +717 -0
- package/src/compiler/printer/async-helpers.ts +183 -0
- package/src/compiler/printer/auto-generate.ts +27 -0
- package/src/compiler/printer/decorator-helpers.ts +218 -0
- package/src/compiler/printer/emit-context.ts +679 -0
- package/src/compiler/printer/emit-flags.ts +64 -0
- package/src/compiler/printer/factory-base.ts +2577 -0
- package/src/compiler/printer/factory.ts +764 -0
- package/src/compiler/printer/helpers.ts +291 -0
- package/src/compiler/printer/name-generator.ts +372 -0
- package/src/compiler/printer/printer.ts +5072 -0
- package/src/compiler/printer/text-writer.ts +183 -0
- package/src/compiler/printer/utilities.ts +884 -0
- package/src/compiler/program-checker.ts +592 -0
- package/src/compiler/program-utilities.ts +435 -0
- package/src/compiler/program.ts +1419 -0
- package/src/compiler/pseudo-bigint.ts +62 -0
- package/src/compiler/regexp-checker.ts +1142 -0
- package/src/compiler/relations.ts +5149 -0
- package/src/compiler/reparser.ts +1566 -0
- package/src/compiler/scanner.ts +2951 -0
- package/src/compiler/show-config.ts +239 -0
- package/src/compiler/side-state.ts +125 -0
- package/src/compiler/sourcemap.ts +366 -0
- package/src/compiler/spelling.ts +122 -0
- package/src/compiler/symbol-accessibility.ts +1071 -0
- package/src/compiler/symbol.ts +439 -0
- package/src/compiler/symlinks.ts +137 -0
- package/src/compiler/syntax-kind.ts +391 -0
- package/src/compiler/thread-entry.ts +191 -0
- package/src/compiler/timeline.ts +53 -0
- package/src/compiler/transformers/alias-references.ts +757 -0
- package/src/compiler/transformers/async-utilities.ts +335 -0
- package/src/compiler/transformers/async.ts +838 -0
- package/src/compiler/transformers/class-fields.ts +2967 -0
- package/src/compiler/transformers/class-utilities.ts +324 -0
- package/src/compiler/transformers/commonjs-module.ts +1621 -0
- package/src/compiler/transformers/const-enum-inliner.ts +50 -0
- package/src/compiler/transformers/declarations-diagnostics.ts +832 -0
- package/src/compiler/transformers/declarations-pseudo.ts +966 -0
- package/src/compiler/transformers/declarations-resolver.ts +249 -0
- package/src/compiler/transformers/declarations-syntactic.ts +1859 -0
- package/src/compiler/transformers/declarations-tracker.ts +269 -0
- package/src/compiler/transformers/declarations.ts +3120 -0
- package/src/compiler/transformers/decorator-metadata.ts +697 -0
- package/src/compiler/transformers/decorator-utilities.ts +283 -0
- package/src/compiler/transformers/destructuring.ts +708 -0
- package/src/compiler/transformers/downlevel.ts +50 -0
- package/src/compiler/transformers/emit-resolver.ts +258 -0
- package/src/compiler/transformers/es-decorators.ts +2682 -0
- package/src/compiler/transformers/exponentiation.ts +80 -0
- package/src/compiler/transformers/external-module-info.ts +412 -0
- package/src/compiler/transformers/for-await.ts +687 -0
- package/src/compiler/transformers/import-elision.ts +152 -0
- package/src/compiler/transformers/jsx-entities.ts +256 -0
- package/src/compiler/transformers/jsx.ts +824 -0
- package/src/compiler/transformers/legacy-decorators.ts +726 -0
- package/src/compiler/transformers/logical-assignment.ts +75 -0
- package/src/compiler/transformers/module-utilities.ts +42 -0
- package/src/compiler/transformers/module.ts +474 -0
- package/src/compiler/transformers/named-evaluation.ts +389 -0
- package/src/compiler/transformers/nullish-coalescing.ts +35 -0
- package/src/compiler/transformers/object-rest-spread.ts +577 -0
- package/src/compiler/transformers/optional-catch.ts +29 -0
- package/src/compiler/transformers/optional-chain.ts +246 -0
- package/src/compiler/transformers/reference-resolver.ts +1201 -0
- package/src/compiler/transformers/runtime-syntax.ts +942 -0
- package/src/compiler/transformers/subtree-facts.ts +245 -0
- package/src/compiler/transformers/syntax-facts.ts +353 -0
- package/src/compiler/transformers/tagged-template.ts +167 -0
- package/src/compiler/transformers/transformer.ts +56 -0
- package/src/compiler/transformers/type-eraser.ts +520 -0
- package/src/compiler/transformers/type-serialization.ts +374 -0
- package/src/compiler/transformers/using.ts +613 -0
- package/src/compiler/transformers/utilities.ts +419 -0
- package/src/compiler/transformers/visitor-base.ts +1601 -0
- package/src/compiler/transformers/visitor-hooks.ts +252 -0
- package/src/compiler/tsc-build.ts +1418 -0
- package/src/compiler/tsc-cli.ts +666 -0
- package/src/compiler/tsc-compile.ts +437 -0
- package/src/compiler/tsc-watch.ts +854 -0
- package/src/compiler/tsconfig.ts +1574 -0
- package/src/compiler/type-printer.ts +110 -0
- package/src/compiler/types.ts +115 -0
- package/src/compiler/unicode-identifiers.ts +212 -0
- package/src/compiler/unicode-properties.ts +537 -0
- package/src/compiler/vfs-match.ts +597 -0
- package/src/compiler/xxh3.ts +650 -0
- package/src/library/ast.generated.ts +141 -167
- package/src/library/ast.ts +4 -1
- package/src/library/checker.ts +384 -0
- package/src/library/diagnostics.ts +72 -0
- package/src/library/disk.ts +73 -0
- package/src/library/errors.ts +26 -0
- package/src/library/host.ts +63 -0
- package/src/library/index.ts +21 -0
- package/src/library/nodes.ts +232 -0
- package/src/library/options.ts +449 -0
- package/src/library/parse.ts +63 -0
- package/src/library/program.ts +293 -0
- package/src/library/types.ts +14 -1
|
@@ -0,0 +1,2853 @@
|
|
|
1
|
+
import { charSize, codePointAt, isASCIILetter, isDigit, isHexDigit, isIdentifierPart, isIdentifierStart, isLineBreak, isOctalDigit, isWhiteSpaceLike, isWhiteSpaceSingleLine, } from './character-codes.js';
|
|
2
|
+
import { parsePseudoBigInt } from './pseudo-bigint.js';
|
|
3
|
+
import { checkRegularExpression, regularExpressionFlag, } from './regexp-checker.js';
|
|
4
|
+
import { CommentDirective, CommentRange, } from './types.js';
|
|
5
|
+
export { isIdentifierPart, isIdentifierStart } from './character-codes.js';
|
|
6
|
+
const textToKeyword = new Map([
|
|
7
|
+
['abstract', 127 /* SyntaxKind.AbstractKeyword */],
|
|
8
|
+
['accessor', 128 /* SyntaxKind.AccessorKeyword */],
|
|
9
|
+
['any', 132 /* SyntaxKind.AnyKeyword */],
|
|
10
|
+
['as', 129 /* SyntaxKind.AsKeyword */],
|
|
11
|
+
['asserts', 130 /* SyntaxKind.AssertsKeyword */],
|
|
12
|
+
['assert', 131 /* SyntaxKind.AssertKeyword */],
|
|
13
|
+
['bigint', 163 /* SyntaxKind.BigIntKeyword */],
|
|
14
|
+
['boolean', 135 /* SyntaxKind.BooleanKeyword */],
|
|
15
|
+
['break', 82 /* SyntaxKind.BreakKeyword */],
|
|
16
|
+
['case', 83 /* SyntaxKind.CaseKeyword */],
|
|
17
|
+
['catch', 84 /* SyntaxKind.CatchKeyword */],
|
|
18
|
+
['class', 85 /* SyntaxKind.ClassKeyword */],
|
|
19
|
+
['continue', 87 /* SyntaxKind.ContinueKeyword */],
|
|
20
|
+
['const', 86 /* SyntaxKind.ConstKeyword */],
|
|
21
|
+
['constructor', 136 /* SyntaxKind.ConstructorKeyword */],
|
|
22
|
+
['debugger', 88 /* SyntaxKind.DebuggerKeyword */],
|
|
23
|
+
['declare', 137 /* SyntaxKind.DeclareKeyword */],
|
|
24
|
+
['default', 89 /* SyntaxKind.DefaultKeyword */],
|
|
25
|
+
['defer', 166 /* SyntaxKind.DeferKeyword */],
|
|
26
|
+
['delete', 90 /* SyntaxKind.DeleteKeyword */],
|
|
27
|
+
['do', 91 /* SyntaxKind.DoKeyword */],
|
|
28
|
+
['else', 92 /* SyntaxKind.ElseKeyword */],
|
|
29
|
+
['enum', 93 /* SyntaxKind.EnumKeyword */],
|
|
30
|
+
['export', 94 /* SyntaxKind.ExportKeyword */],
|
|
31
|
+
['extends', 95 /* SyntaxKind.ExtendsKeyword */],
|
|
32
|
+
['false', 96 /* SyntaxKind.FalseKeyword */],
|
|
33
|
+
['finally', 97 /* SyntaxKind.FinallyKeyword */],
|
|
34
|
+
['for', 98 /* SyntaxKind.ForKeyword */],
|
|
35
|
+
['from', 161 /* SyntaxKind.FromKeyword */],
|
|
36
|
+
['function', 99 /* SyntaxKind.FunctionKeyword */],
|
|
37
|
+
['get', 138 /* SyntaxKind.GetKeyword */],
|
|
38
|
+
['if', 100 /* SyntaxKind.IfKeyword */],
|
|
39
|
+
['immediate', 139 /* SyntaxKind.ImmediateKeyword */],
|
|
40
|
+
['implements', 118 /* SyntaxKind.ImplementsKeyword */],
|
|
41
|
+
['import', 101 /* SyntaxKind.ImportKeyword */],
|
|
42
|
+
['in', 102 /* SyntaxKind.InKeyword */],
|
|
43
|
+
['infer', 140 /* SyntaxKind.InferKeyword */],
|
|
44
|
+
['instanceof', 103 /* SyntaxKind.InstanceOfKeyword */],
|
|
45
|
+
['interface', 119 /* SyntaxKind.InterfaceKeyword */],
|
|
46
|
+
['intrinsic', 141 /* SyntaxKind.IntrinsicKeyword */],
|
|
47
|
+
['is', 142 /* SyntaxKind.IsKeyword */],
|
|
48
|
+
['keyof', 143 /* SyntaxKind.KeyOfKeyword */],
|
|
49
|
+
['let', 120 /* SyntaxKind.LetKeyword */],
|
|
50
|
+
['module', 144 /* SyntaxKind.ModuleKeyword */],
|
|
51
|
+
['namespace', 145 /* SyntaxKind.NamespaceKeyword */],
|
|
52
|
+
['never', 146 /* SyntaxKind.NeverKeyword */],
|
|
53
|
+
['new', 104 /* SyntaxKind.NewKeyword */],
|
|
54
|
+
['null', 105 /* SyntaxKind.NullKeyword */],
|
|
55
|
+
['number', 150 /* SyntaxKind.NumberKeyword */],
|
|
56
|
+
['object', 151 /* SyntaxKind.ObjectKeyword */],
|
|
57
|
+
['package', 121 /* SyntaxKind.PackageKeyword */],
|
|
58
|
+
['private', 122 /* SyntaxKind.PrivateKeyword */],
|
|
59
|
+
['protected', 123 /* SyntaxKind.ProtectedKeyword */],
|
|
60
|
+
['public', 124 /* SyntaxKind.PublicKeyword */],
|
|
61
|
+
['override', 164 /* SyntaxKind.OverrideKeyword */],
|
|
62
|
+
['out', 147 /* SyntaxKind.OutKeyword */],
|
|
63
|
+
['readonly', 148 /* SyntaxKind.ReadonlyKeyword */],
|
|
64
|
+
['require', 149 /* SyntaxKind.RequireKeyword */],
|
|
65
|
+
['global', 162 /* SyntaxKind.GlobalKeyword */],
|
|
66
|
+
['return', 106 /* SyntaxKind.ReturnKeyword */],
|
|
67
|
+
['satisfies', 152 /* SyntaxKind.SatisfiesKeyword */],
|
|
68
|
+
['set', 153 /* SyntaxKind.SetKeyword */],
|
|
69
|
+
['static', 125 /* SyntaxKind.StaticKeyword */],
|
|
70
|
+
['string', 154 /* SyntaxKind.StringKeyword */],
|
|
71
|
+
['super', 107 /* SyntaxKind.SuperKeyword */],
|
|
72
|
+
['switch', 108 /* SyntaxKind.SwitchKeyword */],
|
|
73
|
+
['symbol', 155 /* SyntaxKind.SymbolKeyword */],
|
|
74
|
+
['this', 109 /* SyntaxKind.ThisKeyword */],
|
|
75
|
+
['throw', 110 /* SyntaxKind.ThrowKeyword */],
|
|
76
|
+
['true', 111 /* SyntaxKind.TrueKeyword */],
|
|
77
|
+
['try', 112 /* SyntaxKind.TryKeyword */],
|
|
78
|
+
['type', 156 /* SyntaxKind.TypeKeyword */],
|
|
79
|
+
['typeof', 113 /* SyntaxKind.TypeOfKeyword */],
|
|
80
|
+
['undefined', 157 /* SyntaxKind.UndefinedKeyword */],
|
|
81
|
+
['unique', 158 /* SyntaxKind.UniqueKeyword */],
|
|
82
|
+
['unknown', 159 /* SyntaxKind.UnknownKeyword */],
|
|
83
|
+
['using', 160 /* SyntaxKind.UsingKeyword */],
|
|
84
|
+
['var', 114 /* SyntaxKind.VarKeyword */],
|
|
85
|
+
['void', 115 /* SyntaxKind.VoidKeyword */],
|
|
86
|
+
['while', 116 /* SyntaxKind.WhileKeyword */],
|
|
87
|
+
['with', 117 /* SyntaxKind.WithKeyword */],
|
|
88
|
+
['yield', 126 /* SyntaxKind.YieldKeyword */],
|
|
89
|
+
['async', 133 /* SyntaxKind.AsyncKeyword */],
|
|
90
|
+
['await', 134 /* SyntaxKind.AwaitKeyword */],
|
|
91
|
+
['of', 165 /* SyntaxKind.OfKeyword */],
|
|
92
|
+
]);
|
|
93
|
+
const textToToken = new Map([
|
|
94
|
+
['{', 18 /* SyntaxKind.OpenBraceToken */],
|
|
95
|
+
['}', 19 /* SyntaxKind.CloseBraceToken */],
|
|
96
|
+
['(', 20 /* SyntaxKind.OpenParenToken */],
|
|
97
|
+
[')', 21 /* SyntaxKind.CloseParenToken */],
|
|
98
|
+
['[', 22 /* SyntaxKind.OpenBracketToken */],
|
|
99
|
+
[']', 23 /* SyntaxKind.CloseBracketToken */],
|
|
100
|
+
['.', 24 /* SyntaxKind.DotToken */],
|
|
101
|
+
['...', 25 /* SyntaxKind.DotDotDotToken */],
|
|
102
|
+
[';', 26 /* SyntaxKind.SemicolonToken */],
|
|
103
|
+
[',', 27 /* SyntaxKind.CommaToken */],
|
|
104
|
+
['<', 29 /* SyntaxKind.LessThanToken */],
|
|
105
|
+
['>', 31 /* SyntaxKind.GreaterThanToken */],
|
|
106
|
+
['<=', 32 /* SyntaxKind.LessThanEqualsToken */],
|
|
107
|
+
['>=', 33 /* SyntaxKind.GreaterThanEqualsToken */],
|
|
108
|
+
['==', 34 /* SyntaxKind.EqualsEqualsToken */],
|
|
109
|
+
['!=', 35 /* SyntaxKind.ExclamationEqualsToken */],
|
|
110
|
+
['===', 36 /* SyntaxKind.EqualsEqualsEqualsToken */],
|
|
111
|
+
['!==', 37 /* SyntaxKind.ExclamationEqualsEqualsToken */],
|
|
112
|
+
['=>', 38 /* SyntaxKind.EqualsGreaterThanToken */],
|
|
113
|
+
['+', 39 /* SyntaxKind.PlusToken */],
|
|
114
|
+
['-', 40 /* SyntaxKind.MinusToken */],
|
|
115
|
+
['**', 42 /* SyntaxKind.AsteriskAsteriskToken */],
|
|
116
|
+
['*', 41 /* SyntaxKind.AsteriskToken */],
|
|
117
|
+
['/', 43 /* SyntaxKind.SlashToken */],
|
|
118
|
+
['%', 44 /* SyntaxKind.PercentToken */],
|
|
119
|
+
['++', 45 /* SyntaxKind.PlusPlusToken */],
|
|
120
|
+
['--', 46 /* SyntaxKind.MinusMinusToken */],
|
|
121
|
+
['<<', 47 /* SyntaxKind.LessThanLessThanToken */],
|
|
122
|
+
['</', 30 /* SyntaxKind.LessThanSlashToken */],
|
|
123
|
+
['>>', 48 /* SyntaxKind.GreaterThanGreaterThanToken */],
|
|
124
|
+
['>>>', 49 /* SyntaxKind.GreaterThanGreaterThanGreaterThanToken */],
|
|
125
|
+
['&', 50 /* SyntaxKind.AmpersandToken */],
|
|
126
|
+
['|', 51 /* SyntaxKind.BarToken */],
|
|
127
|
+
['^', 52 /* SyntaxKind.CaretToken */],
|
|
128
|
+
['!', 53 /* SyntaxKind.ExclamationToken */],
|
|
129
|
+
['~', 54 /* SyntaxKind.TildeToken */],
|
|
130
|
+
['&&', 55 /* SyntaxKind.AmpersandAmpersandToken */],
|
|
131
|
+
['||', 56 /* SyntaxKind.BarBarToken */],
|
|
132
|
+
['?', 57 /* SyntaxKind.QuestionToken */],
|
|
133
|
+
['??', 60 /* SyntaxKind.QuestionQuestionToken */],
|
|
134
|
+
['?.', 28 /* SyntaxKind.QuestionDotToken */],
|
|
135
|
+
[':', 58 /* SyntaxKind.ColonToken */],
|
|
136
|
+
['=', 63 /* SyntaxKind.EqualsToken */],
|
|
137
|
+
['+=', 64 /* SyntaxKind.PlusEqualsToken */],
|
|
138
|
+
['-=', 65 /* SyntaxKind.MinusEqualsToken */],
|
|
139
|
+
['*=', 66 /* SyntaxKind.AsteriskEqualsToken */],
|
|
140
|
+
['**=', 67 /* SyntaxKind.AsteriskAsteriskEqualsToken */],
|
|
141
|
+
['/=', 68 /* SyntaxKind.SlashEqualsToken */],
|
|
142
|
+
['%=', 69 /* SyntaxKind.PercentEqualsToken */],
|
|
143
|
+
['<<=', 70 /* SyntaxKind.LessThanLessThanEqualsToken */],
|
|
144
|
+
['>>=', 71 /* SyntaxKind.GreaterThanGreaterThanEqualsToken */],
|
|
145
|
+
['>>>=', 72 /* SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken */],
|
|
146
|
+
['&=', 73 /* SyntaxKind.AmpersandEqualsToken */],
|
|
147
|
+
['|=', 74 /* SyntaxKind.BarEqualsToken */],
|
|
148
|
+
['^=', 78 /* SyntaxKind.CaretEqualsToken */],
|
|
149
|
+
['||=', 75 /* SyntaxKind.BarBarEqualsToken */],
|
|
150
|
+
['&&=', 76 /* SyntaxKind.AmpersandAmpersandEqualsToken */],
|
|
151
|
+
['??=', 77 /* SyntaxKind.QuestionQuestionEqualsToken */],
|
|
152
|
+
['@', 59 /* SyntaxKind.AtToken */],
|
|
153
|
+
['#', 62 /* SyntaxKind.HashToken */],
|
|
154
|
+
['`', 61 /* SyntaxKind.BacktickToken */],
|
|
155
|
+
]);
|
|
156
|
+
const tokenToText = [];
|
|
157
|
+
for (let kind = 0; kind <= 166 /* SyntaxKind.LastToken */; kind++)
|
|
158
|
+
tokenToText.push('');
|
|
159
|
+
for (const [text, kind] of textToToken)
|
|
160
|
+
tokenToText[kind] = text;
|
|
161
|
+
for (const [text, kind] of textToKeyword)
|
|
162
|
+
tokenToText[kind] = text;
|
|
163
|
+
// Keywords bucketed by first letter and length, so identifiers are classified
|
|
164
|
+
// without allocating their text.
|
|
165
|
+
const keywordBucketStart = new Int32Array(26 * 13 + 2);
|
|
166
|
+
const keywordKinds = new Uint16Array(textToKeyword.size);
|
|
167
|
+
// The code units of every keyword, 12 slots each, in bucket order.
|
|
168
|
+
const keywordCodeUnits = new Uint16Array(textToKeyword.size * 12);
|
|
169
|
+
{
|
|
170
|
+
for (const text of textToKeyword.keys())
|
|
171
|
+
keywordBucketStart[keywordBucket(text) + 2]++;
|
|
172
|
+
for (let i = 2; i < keywordBucketStart.length; i++)
|
|
173
|
+
keywordBucketStart[i] += keywordBucketStart[i - 1];
|
|
174
|
+
for (const [text, kind] of textToKeyword) {
|
|
175
|
+
const slot = keywordBucketStart[keywordBucket(text) + 1]++;
|
|
176
|
+
keywordKinds[slot] = kind;
|
|
177
|
+
for (let j = 0; j < text.length; j++)
|
|
178
|
+
keywordCodeUnits[slot * 12 + j] = text.charCodeAt(j);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function keywordBucket(text) {
|
|
182
|
+
return (text.charCodeAt(0) - 97 /* CharacterCodes.a */) * 13 + text.length;
|
|
183
|
+
}
|
|
184
|
+
/** The keyword kind of the code units `chars[start, end)`, or `Identifier`. */
|
|
185
|
+
function keywordKindAt(chars, start, end) {
|
|
186
|
+
const length = (end - start) | 0;
|
|
187
|
+
if (length < 2 || length > 12)
|
|
188
|
+
return 79 /* SyntaxKind.Identifier */;
|
|
189
|
+
const first = chars[start] | 0;
|
|
190
|
+
if (first < 97 /* CharacterCodes.a */ || first > 122 /* CharacterCodes.z */)
|
|
191
|
+
return 79 /* SyntaxKind.Identifier */;
|
|
192
|
+
const bucket = ((first - 97 /* CharacterCodes.a */) * 13 + length) | 0;
|
|
193
|
+
const last = keywordBucketStart[bucket + 1] | 0;
|
|
194
|
+
for (let i = keywordBucketStart[bucket] | 0; i < last; i = (i + 1) | 0) {
|
|
195
|
+
const base = (i * 12) | 0;
|
|
196
|
+
let j = 1;
|
|
197
|
+
while (j < length && (keywordCodeUnits[(base + j) | 0] | 0) === (chars[(start + j) | 0] | 0))
|
|
198
|
+
j = (j + 1) | 0;
|
|
199
|
+
if (j === length)
|
|
200
|
+
return (keywordKinds[i] | 0);
|
|
201
|
+
}
|
|
202
|
+
return 79 /* SyntaxKind.Identifier */;
|
|
203
|
+
}
|
|
204
|
+
/** The keyword kind of `text`, or `Identifier`. */
|
|
205
|
+
export function getIdentifierToken(text) {
|
|
206
|
+
if (text.length < 2 || text.length > 12)
|
|
207
|
+
return 79 /* SyntaxKind.Identifier */;
|
|
208
|
+
const first = text.charCodeAt(0);
|
|
209
|
+
if (first < 97 /* CharacterCodes.a */ || first > 122 /* CharacterCodes.z */)
|
|
210
|
+
return 79 /* SyntaxKind.Identifier */;
|
|
211
|
+
// `| 0`: a SyntaxKind is an int32, which lets its storage stay int32.
|
|
212
|
+
return (textToKeyword.get(text) ?? 79 /* SyntaxKind.Identifier */) | 0;
|
|
213
|
+
}
|
|
214
|
+
/** The keyword kind of an identifier's text, or `Unknown`. */
|
|
215
|
+
export function identifierToKeywordKind(text) {
|
|
216
|
+
return (textToKeyword.get(text) ?? 0 /* SyntaxKind.Unknown */) | 0;
|
|
217
|
+
}
|
|
218
|
+
export function tokenToString(kind) {
|
|
219
|
+
return kind >= 0 && kind < tokenToText.length ? tokenToText[kind] : '';
|
|
220
|
+
}
|
|
221
|
+
export function stringToToken(text) {
|
|
222
|
+
return (textToToken.get(text) ?? textToKeyword.get(text) ?? 0 /* SyntaxKind.Unknown */) | 0;
|
|
223
|
+
}
|
|
224
|
+
/** Keywords longer than two characters, for spelling suggestions. */
|
|
225
|
+
export function getViableKeywordSuggestions() {
|
|
226
|
+
const result = [];
|
|
227
|
+
for (const text of textToKeyword.keys())
|
|
228
|
+
if (text.length > 2)
|
|
229
|
+
result.push(text);
|
|
230
|
+
return result;
|
|
231
|
+
}
|
|
232
|
+
export function tokenIsIdentifierOrKeyword(token) {
|
|
233
|
+
return token >= 79 /* SyntaxKind.Identifier */;
|
|
234
|
+
}
|
|
235
|
+
/** Whether `name` is a valid identifier (JSX names may contain `-` and `:`). */
|
|
236
|
+
export function isIdentifierText(name, languageVariant = 0 /* LanguageVariant.Standard */) {
|
|
237
|
+
let ch = codePointAt(name, 0, name.length);
|
|
238
|
+
if (!isIdentifierStart(ch))
|
|
239
|
+
return false;
|
|
240
|
+
for (let i = charSize(ch); i < name.length; i += charSize(ch)) {
|
|
241
|
+
ch = codePointAt(name, i, name.length);
|
|
242
|
+
if (!isIdentifierPart(ch, languageVariant))
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
/** Receives scanner diagnostics. An abstract class rather than a function so native builds dispatch statically. */
|
|
248
|
+
export class ScannerErrorReporter {
|
|
249
|
+
}
|
|
250
|
+
const noArgs = [];
|
|
251
|
+
/** A snapshot of the scanner's token state for `Scanner.rewind`. */
|
|
252
|
+
export class ScannerState {
|
|
253
|
+
pos;
|
|
254
|
+
fullStartPos;
|
|
255
|
+
tokenStart;
|
|
256
|
+
token;
|
|
257
|
+
tokenFlags;
|
|
258
|
+
tokenValue;
|
|
259
|
+
valueStart;
|
|
260
|
+
valueEnd;
|
|
261
|
+
commentDirectiveCount;
|
|
262
|
+
skipJSDocLeadingAsterisks;
|
|
263
|
+
constructor(pos, fullStartPos, tokenStart, token, tokenFlags, tokenValue, valueStart, valueEnd, commentDirectiveCount, skipJSDocLeadingAsterisks) {
|
|
264
|
+
this.pos = pos | 0;
|
|
265
|
+
this.fullStartPos = fullStartPos | 0;
|
|
266
|
+
this.tokenStart = tokenStart | 0;
|
|
267
|
+
this.token = token;
|
|
268
|
+
this.tokenFlags = tokenFlags;
|
|
269
|
+
this.tokenValue = tokenValue;
|
|
270
|
+
this.valueStart = valueStart | 0;
|
|
271
|
+
this.valueEnd = valueEnd | 0;
|
|
272
|
+
this.commentDirectiveCount = commentDirectiveCount;
|
|
273
|
+
this.skipJSDocLeadingAsterisks = skipJSDocLeadingAsterisks;
|
|
274
|
+
}
|
|
275
|
+
/** @internal Overwrites this snapshot with the scanner's current state, like `Scanner.mark`. */
|
|
276
|
+
assign(scanner) {
|
|
277
|
+
this.pos = scanner.pos | 0;
|
|
278
|
+
this.fullStartPos = scanner.fullStartPos;
|
|
279
|
+
this.tokenStart = scanner.tokenStart;
|
|
280
|
+
this.token = scanner.token;
|
|
281
|
+
this.tokenFlags = scanner.tokenFlags;
|
|
282
|
+
this.tokenValue = scanner.tokenValue;
|
|
283
|
+
this.valueStart = scanner.valueStart;
|
|
284
|
+
this.valueEnd = scanner.valueEnd;
|
|
285
|
+
this.commentDirectiveCount = scanner.commentDirectives.length;
|
|
286
|
+
this.skipJSDocLeadingAsterisks = scanner.skipJSDocLeadingAsterisks;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* `[A-Za-z0-9_$]`, for an int32 code unit. The scanner's hot loops test this inline rather than
|
|
291
|
+
* calling `isWordCharacter`, whose parameter native builds keep as a double.
|
|
292
|
+
*/
|
|
293
|
+
function isASCIIIdentifierPart(c) {
|
|
294
|
+
return ((c >= 97 /* CharacterCodes.a */ && c <= 122 /* CharacterCodes.z */) ||
|
|
295
|
+
(c >= 65 /* CharacterCodes.A */ && c <= 90 /* CharacterCodes.Z */) ||
|
|
296
|
+
(c >= 48 /* CharacterCodes._0 */ && c <= 57 /* CharacterCodes._9 */) ||
|
|
297
|
+
c === 95 /* CharacterCodes._ */ ||
|
|
298
|
+
c === 36 /* CharacterCodes.$ */);
|
|
299
|
+
}
|
|
300
|
+
/** FNV-1a over a range's code units. The identifier scan computes the same hash as it goes. */
|
|
301
|
+
function rangeHash(chars, start, end) {
|
|
302
|
+
let hash = 0x811c9dc5 | 0;
|
|
303
|
+
for (let i = start | 0; i < end; i = (i + 1) | 0)
|
|
304
|
+
hash = Math.imul(hash ^ (chars[i] | 0), 0x01000193);
|
|
305
|
+
return finishHash(hash);
|
|
306
|
+
}
|
|
307
|
+
function finishHash(hash) {
|
|
308
|
+
return hash ^ (hash >>> 15);
|
|
309
|
+
}
|
|
310
|
+
/** Strings for ranges of one text, keyed by their code units: equal identifiers share one string. */
|
|
311
|
+
class IdentifierTable {
|
|
312
|
+
text;
|
|
313
|
+
// Pairs of (entry index + 1, hash) per slot, (0, 0) when empty; linear probing.
|
|
314
|
+
slots;
|
|
315
|
+
// Each entry's length in code units.
|
|
316
|
+
lengths;
|
|
317
|
+
texts;
|
|
318
|
+
count;
|
|
319
|
+
// Per entry: 1 once its text was recorded among the file's identifier texts (`markRecorded`).
|
|
320
|
+
recorded;
|
|
321
|
+
// The entry the last `intern` returned.
|
|
322
|
+
lastEntry;
|
|
323
|
+
constructor(text) {
|
|
324
|
+
this.text = text;
|
|
325
|
+
this.slots = new Int32Array(512);
|
|
326
|
+
this.lengths = new Int32Array(128);
|
|
327
|
+
this.texts = [];
|
|
328
|
+
this.count = 0;
|
|
329
|
+
this.recorded = new Uint8Array(128);
|
|
330
|
+
this.lastEntry = -1;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Whether `text`, just returned by `intern`, still needs recording among the file's identifier
|
|
334
|
+
* texts; marks it recorded. Texts the table doesn't know are always recorded.
|
|
335
|
+
*/
|
|
336
|
+
markRecorded(text) {
|
|
337
|
+
const entry = this.lastEntry;
|
|
338
|
+
if (entry < 0 || this.texts[entry] !== text)
|
|
339
|
+
return true;
|
|
340
|
+
if (this.recorded[entry] !== 0)
|
|
341
|
+
return false;
|
|
342
|
+
this.recorded[entry] = 1;
|
|
343
|
+
return true;
|
|
344
|
+
}
|
|
345
|
+
/** Empties the table for a new text. */
|
|
346
|
+
setText(text) {
|
|
347
|
+
this.text = text;
|
|
348
|
+
if (this.count === 0)
|
|
349
|
+
return;
|
|
350
|
+
this.slots.fill(0);
|
|
351
|
+
this.recorded.fill(0, 0, this.count);
|
|
352
|
+
this.texts.length = 0;
|
|
353
|
+
this.count = 0;
|
|
354
|
+
this.lastEntry = -1;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* `text.substring(start, end)`, or the string interned for an equal range; `hash` is its `rangeHash`.
|
|
358
|
+
* A candidate of the same hash and length is compared with `startsWith`, which natively compares
|
|
359
|
+
* the bytes of both strings at once.
|
|
360
|
+
*/
|
|
361
|
+
intern(start, end, hash) {
|
|
362
|
+
start = start | 0;
|
|
363
|
+
end = end | 0;
|
|
364
|
+
hash = hash | 0;
|
|
365
|
+
const length = (end - start) | 0;
|
|
366
|
+
const slots = this.slots;
|
|
367
|
+
const mask = ((slots.length >> 1) - 1) | 0;
|
|
368
|
+
let slot = hash & mask;
|
|
369
|
+
for (;;) {
|
|
370
|
+
const entry = slots[(slot * 2) | 0] | 0;
|
|
371
|
+
if (entry === 0)
|
|
372
|
+
break;
|
|
373
|
+
if ((slots[(slot * 2 + 1) | 0] | 0) === hash && (this.lengths[(entry - 1) | 0] | 0) === length) {
|
|
374
|
+
const candidate = this.texts[(entry - 1) | 0];
|
|
375
|
+
if (this.text.startsWith(candidate, start)) {
|
|
376
|
+
this.lastEntry = (entry - 1) | 0;
|
|
377
|
+
return candidate;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
slot = (slot + 1) & mask;
|
|
381
|
+
}
|
|
382
|
+
const value = this.text.substring(start, end);
|
|
383
|
+
const index = this.count | 0;
|
|
384
|
+
if (index === this.lengths.length) {
|
|
385
|
+
const lengths = new Int32Array(index * 2);
|
|
386
|
+
lengths.set(this.lengths);
|
|
387
|
+
this.lengths = lengths;
|
|
388
|
+
const recorded = new Uint8Array(index * 2);
|
|
389
|
+
recorded.set(this.recorded);
|
|
390
|
+
this.recorded = recorded;
|
|
391
|
+
}
|
|
392
|
+
this.lengths[index] = length;
|
|
393
|
+
this.texts.push(value);
|
|
394
|
+
this.count = (index + 1) | 0;
|
|
395
|
+
this.lastEntry = index;
|
|
396
|
+
slots[(slot * 2) | 0] = (index + 1) | 0;
|
|
397
|
+
slots[(slot * 2 + 1) | 0] = hash;
|
|
398
|
+
if (this.count * 2 > mask + 1)
|
|
399
|
+
this.slots = rehash(slots);
|
|
400
|
+
return value;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
/** `IdentifierTable` slots in a table twice the size. */
|
|
404
|
+
function rehash(old) {
|
|
405
|
+
const slots = new Int32Array(old.length * 2);
|
|
406
|
+
const mask = slots.length / 2 - 1;
|
|
407
|
+
for (let i = 0; i < old.length; i += 2) {
|
|
408
|
+
const entry = old[i];
|
|
409
|
+
if (entry === 0)
|
|
410
|
+
continue;
|
|
411
|
+
const hash = old[i + 1];
|
|
412
|
+
let slot = hash & mask;
|
|
413
|
+
while (slots[slot * 2] !== 0)
|
|
414
|
+
slot = (slot + 1) & mask;
|
|
415
|
+
slots[slot * 2] = entry;
|
|
416
|
+
slots[slot * 2 + 1] = hash;
|
|
417
|
+
}
|
|
418
|
+
return slots;
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* The code units a scanner with code units on demand copies at a time: few enough that the comments
|
|
422
|
+
* of a large declaration file copy a small part of it, enough that a file whose comments are all
|
|
423
|
+
* parsed is copied in a few hundred writes.
|
|
424
|
+
*/
|
|
425
|
+
const unitBlockSize = 1024;
|
|
426
|
+
function isLowSurrogate(ch) {
|
|
427
|
+
return ch >= 0xdc00 && ch <= 0xdfff;
|
|
428
|
+
}
|
|
429
|
+
/** The UTF-16 code units of `text`, followed by zeros so the scanner can peek past the end. */
|
|
430
|
+
function toCodeUnits(text) {
|
|
431
|
+
const chars = new Uint16Array(text.length + 4);
|
|
432
|
+
Buffer.from(chars.buffer).write(text, 'utf16le');
|
|
433
|
+
return chars;
|
|
434
|
+
}
|
|
435
|
+
// The two loops below scan long runs. They index `chars` from `pos` on an int32 counter, which
|
|
436
|
+
// native builds compile to an integer loop without allocating a view.
|
|
437
|
+
/** The position of the next `` ` ``, `$`, `\\` or CR at or after `pos`, or `end`. */
|
|
438
|
+
function skipTemplateText(chars, pos, end) {
|
|
439
|
+
for (let i = pos | 0; i < end; i = (i + 1) | 0) {
|
|
440
|
+
const c = chars[i] | 0;
|
|
441
|
+
if (c === 96 /* CharacterCodes.backtick */ ||
|
|
442
|
+
c === 36 /* CharacterCodes.$ */ ||
|
|
443
|
+
c === 92 /* CharacterCodes.backslash */ ||
|
|
444
|
+
c === 13 /* CharacterCodes.carriageReturn */)
|
|
445
|
+
return i;
|
|
446
|
+
}
|
|
447
|
+
return end;
|
|
448
|
+
}
|
|
449
|
+
/** The position of the next `*`, `@`, line break or non-ASCII unit at or after `pos`, or `end`. */
|
|
450
|
+
function skipCommentText(chars, pos, end) {
|
|
451
|
+
for (let i = pos | 0; i < end; i = (i + 1) | 0) {
|
|
452
|
+
const c = chars[i] | 0;
|
|
453
|
+
if (c === 42 /* CharacterCodes.asterisk */ ||
|
|
454
|
+
c === 64 /* CharacterCodes.at */ ||
|
|
455
|
+
c === 10 /* CharacterCodes.lineFeed */ ||
|
|
456
|
+
c === 13 /* CharacterCodes.carriageReturn */ ||
|
|
457
|
+
c > 127 /* CharacterCodes.maxAsciiCharacter */)
|
|
458
|
+
return i;
|
|
459
|
+
}
|
|
460
|
+
return end;
|
|
461
|
+
}
|
|
462
|
+
function hasPrefixAt(text, pos, prefix) {
|
|
463
|
+
if (pos + prefix.length > text.length)
|
|
464
|
+
return false;
|
|
465
|
+
for (let i = 0; i < prefix.length; i++)
|
|
466
|
+
if (text.charCodeAt(pos + i) !== prefix.charCodeAt(i))
|
|
467
|
+
return false;
|
|
468
|
+
return true;
|
|
469
|
+
}
|
|
470
|
+
/** Whether `chars[pos, end)` starts with `tag` followed by whitespace, `}`, `*` or `end`. */
|
|
471
|
+
function hasJSDocTag(chars, pos, end, tag) {
|
|
472
|
+
const tagEnd = pos + tag.length;
|
|
473
|
+
if (tagEnd > end)
|
|
474
|
+
return false;
|
|
475
|
+
for (let i = 0; i < tag.length; i++)
|
|
476
|
+
if (chars[pos + i] !== tag.charCodeAt(i))
|
|
477
|
+
return false;
|
|
478
|
+
if (tagEnd === end)
|
|
479
|
+
return true;
|
|
480
|
+
const ch = chars[tagEnd];
|
|
481
|
+
return (ch === 32 /* CharacterCodes.space */ ||
|
|
482
|
+
ch === 9 /* CharacterCodes.tab */ ||
|
|
483
|
+
ch === 10 /* CharacterCodes.lineFeed */ ||
|
|
484
|
+
ch === 13 /* CharacterCodes.carriageReturn */ ||
|
|
485
|
+
ch === 125 /* CharacterCodes.closeBrace */ ||
|
|
486
|
+
ch === 42 /* CharacterCodes.asterisk */);
|
|
487
|
+
}
|
|
488
|
+
/** Adds the `@deprecated` and `@see`/`@link` flags for a JSDoc tag name at `pos`. */
|
|
489
|
+
function jsDocTagFlags(chars, pos, end, flags) {
|
|
490
|
+
if ((flags & 131072 /* TokenFlags.PrecedingJSDocWithDeprecated */) === 0 && hasJSDocTag(chars, pos, end, 'deprecated'))
|
|
491
|
+
flags |= 131072 /* TokenFlags.PrecedingJSDocWithDeprecated */;
|
|
492
|
+
if ((flags & 262144 /* TokenFlags.PrecedingJSDocWithSeeOrLink */) === 0 &&
|
|
493
|
+
(hasJSDocTag(chars, pos, end, 'see') ||
|
|
494
|
+
hasJSDocTag(chars, pos, end, 'link') ||
|
|
495
|
+
hasJSDocTag(chars, pos, end, 'linkcode') ||
|
|
496
|
+
hasJSDocTag(chars, pos, end, 'linkplain')))
|
|
497
|
+
flags |= 262144 /* TokenFlags.PrecedingJSDocWithSeeOrLink */;
|
|
498
|
+
return flags;
|
|
499
|
+
}
|
|
500
|
+
function hexByte(value) {
|
|
501
|
+
const hex = value.toString(16);
|
|
502
|
+
return hex.length < 2 ? '\\x0' + hex : '\\x' + hex;
|
|
503
|
+
}
|
|
504
|
+
function regularExpressionFlagName(target) {
|
|
505
|
+
switch (target) {
|
|
506
|
+
case 5 /* ScriptTarget.ES2018 */:
|
|
507
|
+
return 'es2018';
|
|
508
|
+
case 9 /* ScriptTarget.ES2022 */:
|
|
509
|
+
return 'es2022';
|
|
510
|
+
default:
|
|
511
|
+
return 'es2024';
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Tokenizes TypeScript and JavaScript source text. Positions are UTF-16 offsets.
|
|
516
|
+
*
|
|
517
|
+
* ```ts
|
|
518
|
+
* const scanner = new Scanner();
|
|
519
|
+
* scanner.setText(text);
|
|
520
|
+
* while (scanner.scan() !== SyntaxKind.EndOfFile) console.log(scanner.getTokenText());
|
|
521
|
+
* ```
|
|
522
|
+
*/
|
|
523
|
+
export class Scanner {
|
|
524
|
+
/** @internal */ text;
|
|
525
|
+
// The text's UTF-16 code units: indexing a typed array is much cheaper than
|
|
526
|
+
// `charCodeAt` on large native strings.
|
|
527
|
+
/** @internal */ chars;
|
|
528
|
+
/** @internal */ end;
|
|
529
|
+
languageVariant;
|
|
530
|
+
scriptTarget;
|
|
531
|
+
onError;
|
|
532
|
+
skipTrivia;
|
|
533
|
+
// Writes of the token offsets below are coerced with `| 0` where the compiler can't bound the
|
|
534
|
+
// value, so native builds store them as 32-bit integers. `pos` too: every write (also in the
|
|
535
|
+
// regular expression checker) is `(pos + n) | 0` or an int32 value, never `++` or `+=`, and hot
|
|
536
|
+
// loops copy it into an int32 local and read code units as `chars[i] | 0`, so they run on
|
|
537
|
+
// integers instead of doubles. Positions stay far below 2^31, so `| 0` never changes a value.
|
|
538
|
+
/** @internal Current position; the end of the current token. */
|
|
539
|
+
pos;
|
|
540
|
+
/** @internal */ fullStartPos;
|
|
541
|
+
/** @internal */ tokenStart;
|
|
542
|
+
/** @internal */ token;
|
|
543
|
+
/** @internal */ tokenFlags;
|
|
544
|
+
// The token value is `text[valueStart, valueEnd)` while `valueStart >= 0`,
|
|
545
|
+
// so identifiers and keywords don't allocate until their value is read.
|
|
546
|
+
/** @internal */ tokenValue;
|
|
547
|
+
/** @internal */ valueStart;
|
|
548
|
+
/** @internal */ valueEnd;
|
|
549
|
+
// `rangeHash` of `chars[hashStart, hashEnd)`, which the ASCII identifier scan computes as it goes.
|
|
550
|
+
valueHash;
|
|
551
|
+
hashStart;
|
|
552
|
+
hashEnd;
|
|
553
|
+
/** @internal */ commentDirectives;
|
|
554
|
+
/** @internal */ skipJSDocLeadingAsterisks;
|
|
555
|
+
// The code units zeroed by `setTextEnd`.
|
|
556
|
+
cutUnits;
|
|
557
|
+
identifiers;
|
|
558
|
+
// With code units on demand: per block of `unitBlockSize` code units, 1 once `chars` holds them
|
|
559
|
+
// (`loadUnits`); `chars` is zero elsewhere.
|
|
560
|
+
loadedBlocks;
|
|
561
|
+
// The line breaks the text holds, computed on first use.
|
|
562
|
+
textKind;
|
|
563
|
+
// The first LF and CR at or after `lineFeedFrom` and `carriageReturnFrom`: `lineFeedAt` and
|
|
564
|
+
// `carriageReturnAt` (the text length where there is none), found by `nextLineFeed` and
|
|
565
|
+
// `nextCarriageReturn`. -1 for none found yet.
|
|
566
|
+
lineFeedFrom;
|
|
567
|
+
lineFeedAt;
|
|
568
|
+
carriageReturnFrom;
|
|
569
|
+
carriageReturnAt;
|
|
570
|
+
/**
|
|
571
|
+
* With `unitsOnDemand`, the code units of the text are copied only for the ranges passed to
|
|
572
|
+
* `loadUnits`, for scanning a few ranges of a large text.
|
|
573
|
+
*/
|
|
574
|
+
constructor(text = '', unitsOnDemand = false) {
|
|
575
|
+
this.text = text;
|
|
576
|
+
if (unitsOnDemand) {
|
|
577
|
+
this.chars = new Uint16Array(text.length + 4);
|
|
578
|
+
this.loadedBlocks = new Uint8Array(((text.length + unitBlockSize - 1) / unitBlockSize) | 0);
|
|
579
|
+
}
|
|
580
|
+
else {
|
|
581
|
+
this.chars = toCodeUnits(text);
|
|
582
|
+
this.loadedBlocks = undefined;
|
|
583
|
+
}
|
|
584
|
+
this.end = text.length | 0;
|
|
585
|
+
this.languageVariant = 0 /* LanguageVariant.Standard */;
|
|
586
|
+
this.scriptTarget = 0 /* ScriptTarget.None */;
|
|
587
|
+
this.onError = undefined;
|
|
588
|
+
this.skipTrivia = true;
|
|
589
|
+
this.pos = 0;
|
|
590
|
+
this.fullStartPos = 0;
|
|
591
|
+
this.tokenStart = 0;
|
|
592
|
+
this.token = 0 /* SyntaxKind.Unknown */;
|
|
593
|
+
this.tokenFlags = 0 /* TokenFlags.None */;
|
|
594
|
+
this.tokenValue = '';
|
|
595
|
+
this.valueStart = -1;
|
|
596
|
+
this.valueEnd = -1;
|
|
597
|
+
this.valueHash = 0;
|
|
598
|
+
this.hashStart = -1;
|
|
599
|
+
this.hashEnd = -1;
|
|
600
|
+
this.commentDirectives = [];
|
|
601
|
+
this.skipJSDocLeadingAsterisks = 0;
|
|
602
|
+
this.cutUnits = new Uint16Array(4);
|
|
603
|
+
this.identifiers = new IdentifierTable(text);
|
|
604
|
+
this.textKind = 0 /* TextKind.Unknown */;
|
|
605
|
+
this.lineFeedFrom = -1;
|
|
606
|
+
this.lineFeedAt = -1;
|
|
607
|
+
this.carriageReturnFrom = -1;
|
|
608
|
+
this.carriageReturnAt = -1;
|
|
609
|
+
}
|
|
610
|
+
/** Sets the text to scan and resets the token state. */
|
|
611
|
+
setText(text) {
|
|
612
|
+
this.text = text;
|
|
613
|
+
this.chars = toCodeUnits(text);
|
|
614
|
+
this.loadedBlocks = undefined;
|
|
615
|
+
this.identifiers.setText(text);
|
|
616
|
+
this.textKind = 0 /* TextKind.Unknown */;
|
|
617
|
+
this.lineFeedFrom = -1;
|
|
618
|
+
this.lineFeedAt = -1;
|
|
619
|
+
this.carriageReturnFrom = -1;
|
|
620
|
+
this.carriageReturnAt = -1;
|
|
621
|
+
this.end = text.length | 0;
|
|
622
|
+
this.pos = 0;
|
|
623
|
+
this.fullStartPos = 0;
|
|
624
|
+
this.tokenStart = 0;
|
|
625
|
+
this.token = 0 /* SyntaxKind.Unknown */;
|
|
626
|
+
this.tokenFlags = 0 /* TokenFlags.None */;
|
|
627
|
+
this.tokenValue = '';
|
|
628
|
+
this.valueStart = -1;
|
|
629
|
+
this.hashStart = -1;
|
|
630
|
+
this.commentDirectives = [];
|
|
631
|
+
this.skipJSDocLeadingAsterisks = 0;
|
|
632
|
+
}
|
|
633
|
+
/** @internal Like `setText(text.substring(0, end))` without copying, but keeps comment directives; pass the text length to undo. */
|
|
634
|
+
setTextEnd(end) {
|
|
635
|
+
const chars = this.chars;
|
|
636
|
+
const cut = this.cutUnits;
|
|
637
|
+
// Restore the units zeroed by the previous call, then zero the units past `end`.
|
|
638
|
+
if (this.end < this.text.length)
|
|
639
|
+
for (let i = 0; i < 4; i++)
|
|
640
|
+
chars[this.end + i] = cut[i];
|
|
641
|
+
if (end < this.text.length)
|
|
642
|
+
for (let i = 0; i < 4; i++) {
|
|
643
|
+
cut[i] = chars[end + i];
|
|
644
|
+
chars[end + i] = 0;
|
|
645
|
+
}
|
|
646
|
+
this.end = end | 0;
|
|
647
|
+
this.pos = 0;
|
|
648
|
+
this.fullStartPos = 0;
|
|
649
|
+
this.tokenStart = 0;
|
|
650
|
+
this.token = 0 /* SyntaxKind.Unknown */;
|
|
651
|
+
this.tokenFlags = 0 /* TokenFlags.None */;
|
|
652
|
+
this.tokenValue = '';
|
|
653
|
+
this.valueStart = -1;
|
|
654
|
+
this.hashStart = -1;
|
|
655
|
+
this.skipJSDocLeadingAsterisks = 0;
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* @internal Where the scanner copies code units on demand, copies those of `text[start, end)`
|
|
659
|
+
* and the four around each end, a block of `unitBlockSize` units at a time (and whole surrogate
|
|
660
|
+
* pairs); otherwise does nothing.
|
|
661
|
+
*/
|
|
662
|
+
loadUnits(start, end) {
|
|
663
|
+
const blocks = this.loadedBlocks;
|
|
664
|
+
if (blocks === undefined)
|
|
665
|
+
return;
|
|
666
|
+
const text = this.text;
|
|
667
|
+
const length = text.length;
|
|
668
|
+
const last = Math.min(blocks.length - 1, ((end + 4) / unitBlockSize) | 0);
|
|
669
|
+
for (let block = (Math.max(0, start - 4) / unitBlockSize) | 0; block <= last; block++) {
|
|
670
|
+
if (blocks[block] !== 0)
|
|
671
|
+
continue;
|
|
672
|
+
// The run of blocks not copied yet.
|
|
673
|
+
let runEnd = block;
|
|
674
|
+
while (runEnd < last && blocks[runEnd + 1] === 0)
|
|
675
|
+
runEnd++;
|
|
676
|
+
let from = block * unitBlockSize;
|
|
677
|
+
let to = Math.min(length, (runEnd + 1) * unitBlockSize);
|
|
678
|
+
if (from > 0 && isLowSurrogate(text.charCodeAt(from)))
|
|
679
|
+
from--;
|
|
680
|
+
if (to < length && isLowSurrogate(text.charCodeAt(to)))
|
|
681
|
+
to++;
|
|
682
|
+
Buffer.from(this.chars.buffer, from * 2, (to - from) * 2).write(text.substring(from, to), 'utf16le');
|
|
683
|
+
blocks.fill(1, block, runEnd + 1);
|
|
684
|
+
block = runEnd;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
setOnError(reporter) {
|
|
688
|
+
this.onError = reporter;
|
|
689
|
+
}
|
|
690
|
+
setLanguageVariant(languageVariant) {
|
|
691
|
+
this.languageVariant = languageVariant;
|
|
692
|
+
}
|
|
693
|
+
setScriptTarget(scriptTarget) {
|
|
694
|
+
this.scriptTarget = scriptTarget;
|
|
695
|
+
}
|
|
696
|
+
/** When false, `scan` returns whitespace, newline and comment trivia tokens. */
|
|
697
|
+
setSkipTrivia(skip) {
|
|
698
|
+
this.skipTrivia = skip;
|
|
699
|
+
}
|
|
700
|
+
/** Nests skipping of JSDoc leading `*` after line breaks; balance every `true` with a `false`. */
|
|
701
|
+
setSkipJSDocLeadingAsterisks(skip) {
|
|
702
|
+
this.skipJSDocLeadingAsterisks += skip ? 1 : -1;
|
|
703
|
+
}
|
|
704
|
+
getText() {
|
|
705
|
+
return this.text;
|
|
706
|
+
}
|
|
707
|
+
getToken() {
|
|
708
|
+
return this.token;
|
|
709
|
+
}
|
|
710
|
+
getTokenFlags() {
|
|
711
|
+
return this.tokenFlags;
|
|
712
|
+
}
|
|
713
|
+
/** Start of the token including leading trivia. */
|
|
714
|
+
getTokenFullStart() {
|
|
715
|
+
return this.fullStartPos;
|
|
716
|
+
}
|
|
717
|
+
getTokenStart() {
|
|
718
|
+
return this.tokenStart;
|
|
719
|
+
}
|
|
720
|
+
getTokenEnd() {
|
|
721
|
+
return this.pos;
|
|
722
|
+
}
|
|
723
|
+
getTokenText() {
|
|
724
|
+
return this.text.substring(this.tokenStart, this.pos);
|
|
725
|
+
}
|
|
726
|
+
/** The cooked value: identifier text, string contents, normalized number, etc. */
|
|
727
|
+
getTokenValue() {
|
|
728
|
+
if (this.valueStart >= 0) {
|
|
729
|
+
this.tokenValue = this.text.substring(this.valueStart, this.valueEnd);
|
|
730
|
+
this.valueStart = -1;
|
|
731
|
+
}
|
|
732
|
+
return this.tokenValue;
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* Whether `text`, the identifier value just returned by `getIdentifierValue`, is the first of its
|
|
736
|
+
* file to be recorded; files record each identifier text once.
|
|
737
|
+
*/
|
|
738
|
+
recordIdentifierValue(text) {
|
|
739
|
+
return this.identifiers.markRecorded(text);
|
|
740
|
+
}
|
|
741
|
+
/** @internal Like `getTokenValue`, but identifiers with the same text share one string. */
|
|
742
|
+
getIdentifierValue() {
|
|
743
|
+
const start = this.valueStart;
|
|
744
|
+
if (start >= 0) {
|
|
745
|
+
const end = this.valueEnd;
|
|
746
|
+
const hash = start === this.hashStart && end === this.hashEnd ? this.valueHash : rangeHash(this.chars, start, end);
|
|
747
|
+
this.tokenValue = this.identifiers.intern(start, end, hash);
|
|
748
|
+
this.valueStart = -1;
|
|
749
|
+
}
|
|
750
|
+
return this.tokenValue;
|
|
751
|
+
}
|
|
752
|
+
getCommentDirectives() {
|
|
753
|
+
return this.commentDirectives;
|
|
754
|
+
}
|
|
755
|
+
hasUnicodeEscape() {
|
|
756
|
+
return (this.tokenFlags & 1024 /* TokenFlags.UnicodeEscape */) !== 0;
|
|
757
|
+
}
|
|
758
|
+
hasExtendedUnicodeEscape() {
|
|
759
|
+
return (this.tokenFlags & 8 /* TokenFlags.ExtendedUnicodeEscape */) !== 0;
|
|
760
|
+
}
|
|
761
|
+
hasPrecedingLineBreak() {
|
|
762
|
+
return (this.tokenFlags & 1 /* TokenFlags.PrecedingLineBreak */) !== 0;
|
|
763
|
+
}
|
|
764
|
+
hasPrecedingJSDocComment() {
|
|
765
|
+
return (this.tokenFlags & 2 /* TokenFlags.PrecedingJSDocComment */) !== 0;
|
|
766
|
+
}
|
|
767
|
+
hasPrecedingJSDocLeadingAsterisks() {
|
|
768
|
+
return (this.tokenFlags & 32768 /* TokenFlags.PrecedingJSDocLeadingAsterisks */) !== 0;
|
|
769
|
+
}
|
|
770
|
+
hasPrecedingJSDocWithDeprecatedTag() {
|
|
771
|
+
return (this.tokenFlags & 131072 /* TokenFlags.PrecedingJSDocWithDeprecated */) !== 0;
|
|
772
|
+
}
|
|
773
|
+
hasPrecedingJSDocWithSeeOrLink() {
|
|
774
|
+
return (this.tokenFlags & 262144 /* TokenFlags.PrecedingJSDocWithSeeOrLink */) !== 0;
|
|
775
|
+
}
|
|
776
|
+
isUnterminated() {
|
|
777
|
+
return (this.tokenFlags & 4 /* TokenFlags.Unterminated */) !== 0;
|
|
778
|
+
}
|
|
779
|
+
mark() {
|
|
780
|
+
return new ScannerState(this.pos, this.fullStartPos, this.tokenStart, this.token, this.tokenFlags, this.tokenValue, this.valueStart, this.valueEnd, this.commentDirectives.length, this.skipJSDocLeadingAsterisks);
|
|
781
|
+
}
|
|
782
|
+
rewind(state) {
|
|
783
|
+
this.pos = state.pos;
|
|
784
|
+
this.fullStartPos = state.fullStartPos;
|
|
785
|
+
this.tokenStart = state.tokenStart;
|
|
786
|
+
this.token = state.token;
|
|
787
|
+
this.tokenFlags = state.tokenFlags;
|
|
788
|
+
this.tokenValue = state.tokenValue;
|
|
789
|
+
this.valueStart = state.valueStart;
|
|
790
|
+
this.valueEnd = state.valueEnd;
|
|
791
|
+
while (this.commentDirectives.length > state.commentDirectiveCount)
|
|
792
|
+
this.commentDirectives.pop();
|
|
793
|
+
this.skipJSDocLeadingAsterisks = state.skipJSDocLeadingAsterisks;
|
|
794
|
+
}
|
|
795
|
+
/** Runs `callback` and restores the scanner state afterwards. */
|
|
796
|
+
lookAhead(callback) {
|
|
797
|
+
const state = this.mark();
|
|
798
|
+
const result = callback();
|
|
799
|
+
this.rewind(state);
|
|
800
|
+
return result;
|
|
801
|
+
}
|
|
802
|
+
/** Runs `callback` and restores the scanner state if it returns `undefined`. */
|
|
803
|
+
tryScan(callback) {
|
|
804
|
+
const state = this.mark();
|
|
805
|
+
const result = callback();
|
|
806
|
+
if (result === undefined)
|
|
807
|
+
this.rewind(state);
|
|
808
|
+
return result;
|
|
809
|
+
}
|
|
810
|
+
/** Moves to `pos` without changing the current token. */
|
|
811
|
+
resetPos(pos) {
|
|
812
|
+
if (pos < 0)
|
|
813
|
+
throw new Error('Cannot reset token state to negative position');
|
|
814
|
+
this.pos = pos | 0;
|
|
815
|
+
this.fullStartPos = pos | 0;
|
|
816
|
+
this.tokenStart = pos | 0;
|
|
817
|
+
}
|
|
818
|
+
resetTokenState(pos) {
|
|
819
|
+
this.resetPos(pos);
|
|
820
|
+
this.token = 0 /* SyntaxKind.Unknown */;
|
|
821
|
+
this.tokenValue = '';
|
|
822
|
+
this.valueStart = -1;
|
|
823
|
+
this.tokenFlags = 0 /* TokenFlags.None */;
|
|
824
|
+
}
|
|
825
|
+
/** @internal */
|
|
826
|
+
languageVersion() {
|
|
827
|
+
return this.scriptTarget === 0 /* ScriptTarget.None */ ? 99 /* ScriptTarget.Latest */ : this.scriptTarget;
|
|
828
|
+
}
|
|
829
|
+
error(message) {
|
|
830
|
+
this.errorAt(message, this.pos, 0, noArgs);
|
|
831
|
+
}
|
|
832
|
+
/** @internal */
|
|
833
|
+
errorAt(message, start, length, args) {
|
|
834
|
+
if (this.onError !== undefined)
|
|
835
|
+
this.onError.onError(message, start, length, args);
|
|
836
|
+
}
|
|
837
|
+
/** @internal The code unit at `pos`, or -1 at the end. */
|
|
838
|
+
char() {
|
|
839
|
+
return this.pos < this.end ? this.chars[this.pos] | 0 : -1 /* CharacterCodes.EOF */;
|
|
840
|
+
}
|
|
841
|
+
/** @internal The code unit at `pos + offset`, or -1 past the end. */
|
|
842
|
+
peek(offset) {
|
|
843
|
+
const at = (this.pos + offset) | 0;
|
|
844
|
+
return at < this.end ? this.chars[at] | 0 : -1 /* CharacterCodes.EOF */;
|
|
845
|
+
}
|
|
846
|
+
/** @internal The code point at `pos`, or -1 at the end. */
|
|
847
|
+
codePoint() {
|
|
848
|
+
return this.codePointAt(this.pos, this.end);
|
|
849
|
+
}
|
|
850
|
+
/** @internal The code point at `pos`, combining a surrogate pair; -1 at or past `end`. */
|
|
851
|
+
codePointAt(pos, end) {
|
|
852
|
+
if (pos >= end)
|
|
853
|
+
return -1 /* CharacterCodes.EOF */;
|
|
854
|
+
const chars = this.chars;
|
|
855
|
+
const ch = chars[pos] | 0;
|
|
856
|
+
if (ch >= 0xd800 && ch <= 0xdbff && pos + 1 < end) {
|
|
857
|
+
const low = chars[pos + 1] | 0;
|
|
858
|
+
if (low >= 0xdc00 && low <= 0xdfff)
|
|
859
|
+
return (ch - 0xd800) * 0x400 + (low - 0xdc00) + 0x10000;
|
|
860
|
+
}
|
|
861
|
+
return ch;
|
|
862
|
+
}
|
|
863
|
+
/** The code point ending just before `pos`; -1 at the start. */
|
|
864
|
+
codePointBefore(pos) {
|
|
865
|
+
if (pos <= 0)
|
|
866
|
+
return -1 /* CharacterCodes.EOF */;
|
|
867
|
+
const ch = this.chars[pos - 1] | 0;
|
|
868
|
+
if (ch >= 0xdc00 && ch <= 0xdfff && pos >= 2) {
|
|
869
|
+
const high = this.chars[pos - 2] | 0;
|
|
870
|
+
if (high >= 0xd800 && high <= 0xdbff)
|
|
871
|
+
return (high - 0xd800) * 0x400 + (ch - 0xdc00) + 0x10000;
|
|
872
|
+
}
|
|
873
|
+
return ch;
|
|
874
|
+
}
|
|
875
|
+
setValue(value) {
|
|
876
|
+
this.tokenValue = value;
|
|
877
|
+
this.valueStart = -1;
|
|
878
|
+
}
|
|
879
|
+
setValueSlice(start, end) {
|
|
880
|
+
this.valueStart = start | 0;
|
|
881
|
+
this.valueEnd = end | 0;
|
|
882
|
+
}
|
|
883
|
+
scan() {
|
|
884
|
+
// `chars` is zero-padded, so peeking a few units past the end is safe.
|
|
885
|
+
const chars = this.chars;
|
|
886
|
+
this.fullStartPos = this.pos | 0;
|
|
887
|
+
this.tokenFlags = 0 /* TokenFlags.None */;
|
|
888
|
+
for (;;) {
|
|
889
|
+
const ch = this.pos < this.end ? chars[this.pos] | 0 : -1 /* CharacterCodes.EOF */;
|
|
890
|
+
this.tokenStart = this.pos | 0;
|
|
891
|
+
switch (ch) {
|
|
892
|
+
case 9 /* CharacterCodes.tab */:
|
|
893
|
+
case 11 /* CharacterCodes.verticalTab */:
|
|
894
|
+
case 12 /* CharacterCodes.formFeed */:
|
|
895
|
+
case 32 /* CharacterCodes.space */:
|
|
896
|
+
if (this.skipTrivia) {
|
|
897
|
+
let pos = (this.pos + 1) | 0;
|
|
898
|
+
const end = this.end;
|
|
899
|
+
while (pos < end) {
|
|
900
|
+
const c = chars[pos] | 0;
|
|
901
|
+
if (c !== 32 /* CharacterCodes.space */ && c !== 9 /* CharacterCodes.tab */)
|
|
902
|
+
break;
|
|
903
|
+
pos = (pos + 1) | 0;
|
|
904
|
+
}
|
|
905
|
+
this.pos = pos;
|
|
906
|
+
continue;
|
|
907
|
+
}
|
|
908
|
+
this.pos = (this.pos + 1) | 0;
|
|
909
|
+
while (this.pos < this.end && isWhiteSpaceSingleLine(chars[this.pos] | 0))
|
|
910
|
+
this.pos = (this.pos + 1) | 0;
|
|
911
|
+
return (this.token = 5 /* SyntaxKind.WhitespaceTrivia */);
|
|
912
|
+
case 10 /* CharacterCodes.lineFeed */:
|
|
913
|
+
case 13 /* CharacterCodes.carriageReturn */:
|
|
914
|
+
this.tokenFlags |= 1 /* TokenFlags.PrecedingLineBreak */;
|
|
915
|
+
if (this.skipTrivia) {
|
|
916
|
+
let pos = (this.pos + 1) | 0;
|
|
917
|
+
const end = this.end;
|
|
918
|
+
while (pos < end) {
|
|
919
|
+
const c = chars[pos] | 0;
|
|
920
|
+
if (c !== 32 /* CharacterCodes.space */ && (c < 9 /* CharacterCodes.tab */ || c > 13 /* CharacterCodes.carriageReturn */))
|
|
921
|
+
break;
|
|
922
|
+
pos = (pos + 1) | 0;
|
|
923
|
+
}
|
|
924
|
+
this.pos = pos;
|
|
925
|
+
continue;
|
|
926
|
+
}
|
|
927
|
+
this.pos =
|
|
928
|
+
(this.pos +
|
|
929
|
+
(ch === 13 /* CharacterCodes.carriageReturn */ && (chars[this.pos + 1] | 0) === 10 /* CharacterCodes.lineFeed */ ? 2 : 1)) |
|
|
930
|
+
0;
|
|
931
|
+
return (this.token = 4 /* SyntaxKind.NewLineTrivia */);
|
|
932
|
+
case 33 /* CharacterCodes.exclamation */:
|
|
933
|
+
if ((chars[this.pos + 1] | 0) === 61 /* CharacterCodes.equals */) {
|
|
934
|
+
if ((chars[this.pos + 2] | 0) === 61 /* CharacterCodes.equals */) {
|
|
935
|
+
this.pos = (this.pos + 3) | 0;
|
|
936
|
+
return (this.token = 37 /* SyntaxKind.ExclamationEqualsEqualsToken */);
|
|
937
|
+
}
|
|
938
|
+
this.pos = (this.pos + 2) | 0;
|
|
939
|
+
return (this.token = 35 /* SyntaxKind.ExclamationEqualsToken */);
|
|
940
|
+
}
|
|
941
|
+
this.pos = (this.pos + 1) | 0;
|
|
942
|
+
return (this.token = 53 /* SyntaxKind.ExclamationToken */);
|
|
943
|
+
case 34 /* CharacterCodes.doubleQuote */:
|
|
944
|
+
case 39 /* CharacterCodes.singleQuote */:
|
|
945
|
+
this.scanString(false);
|
|
946
|
+
return (this.token = 10 /* SyntaxKind.StringLiteral */);
|
|
947
|
+
case 96 /* CharacterCodes.backtick */:
|
|
948
|
+
return (this.token = this.scanTemplateAndSetTokenValue(false));
|
|
949
|
+
case 37 /* CharacterCodes.percent */:
|
|
950
|
+
if ((chars[this.pos + 1] | 0) === 61 /* CharacterCodes.equals */) {
|
|
951
|
+
this.pos = (this.pos + 2) | 0;
|
|
952
|
+
return (this.token = 69 /* SyntaxKind.PercentEqualsToken */);
|
|
953
|
+
}
|
|
954
|
+
this.pos = (this.pos + 1) | 0;
|
|
955
|
+
return (this.token = 44 /* SyntaxKind.PercentToken */);
|
|
956
|
+
case 38 /* CharacterCodes.ampersand */: {
|
|
957
|
+
const next = chars[this.pos + 1] | 0;
|
|
958
|
+
if (next === 38 /* CharacterCodes.ampersand */) {
|
|
959
|
+
if ((chars[this.pos + 2] | 0) === 61 /* CharacterCodes.equals */) {
|
|
960
|
+
this.pos = (this.pos + 3) | 0;
|
|
961
|
+
return (this.token = 76 /* SyntaxKind.AmpersandAmpersandEqualsToken */);
|
|
962
|
+
}
|
|
963
|
+
this.pos = (this.pos + 2) | 0;
|
|
964
|
+
return (this.token = 55 /* SyntaxKind.AmpersandAmpersandToken */);
|
|
965
|
+
}
|
|
966
|
+
if (next === 61 /* CharacterCodes.equals */) {
|
|
967
|
+
this.pos = (this.pos + 2) | 0;
|
|
968
|
+
return (this.token = 73 /* SyntaxKind.AmpersandEqualsToken */);
|
|
969
|
+
}
|
|
970
|
+
this.pos = (this.pos + 1) | 0;
|
|
971
|
+
return (this.token = 50 /* SyntaxKind.AmpersandToken */);
|
|
972
|
+
}
|
|
973
|
+
case 40 /* CharacterCodes.openParen */:
|
|
974
|
+
this.pos = (this.pos + 1) | 0;
|
|
975
|
+
return (this.token = 20 /* SyntaxKind.OpenParenToken */);
|
|
976
|
+
case 41 /* CharacterCodes.closeParen */:
|
|
977
|
+
this.pos = (this.pos + 1) | 0;
|
|
978
|
+
return (this.token = 21 /* SyntaxKind.CloseParenToken */);
|
|
979
|
+
case 42 /* CharacterCodes.asterisk */: {
|
|
980
|
+
const next = chars[this.pos + 1] | 0;
|
|
981
|
+
if (next === 61 /* CharacterCodes.equals */) {
|
|
982
|
+
this.pos = (this.pos + 2) | 0;
|
|
983
|
+
return (this.token = 66 /* SyntaxKind.AsteriskEqualsToken */);
|
|
984
|
+
}
|
|
985
|
+
if (next === 42 /* CharacterCodes.asterisk */) {
|
|
986
|
+
if ((chars[this.pos + 2] | 0) === 61 /* CharacterCodes.equals */) {
|
|
987
|
+
this.pos = (this.pos + 3) | 0;
|
|
988
|
+
return (this.token = 67 /* SyntaxKind.AsteriskAsteriskEqualsToken */);
|
|
989
|
+
}
|
|
990
|
+
this.pos = (this.pos + 2) | 0;
|
|
991
|
+
return (this.token = 42 /* SyntaxKind.AsteriskAsteriskToken */);
|
|
992
|
+
}
|
|
993
|
+
this.pos = (this.pos + 1) | 0;
|
|
994
|
+
if (this.skipJSDocLeadingAsterisks !== 0 &&
|
|
995
|
+
(this.tokenFlags & 32768 /* TokenFlags.PrecedingJSDocLeadingAsterisks */) === 0 &&
|
|
996
|
+
(this.tokenFlags & 1 /* TokenFlags.PrecedingLineBreak */) !== 0) {
|
|
997
|
+
this.tokenFlags |= 32768 /* TokenFlags.PrecedingJSDocLeadingAsterisks */;
|
|
998
|
+
continue;
|
|
999
|
+
}
|
|
1000
|
+
return (this.token = 41 /* SyntaxKind.AsteriskToken */);
|
|
1001
|
+
}
|
|
1002
|
+
case 43 /* CharacterCodes.plus */: {
|
|
1003
|
+
const next = chars[this.pos + 1] | 0;
|
|
1004
|
+
if (next === 61 /* CharacterCodes.equals */) {
|
|
1005
|
+
this.pos = (this.pos + 2) | 0;
|
|
1006
|
+
return (this.token = 64 /* SyntaxKind.PlusEqualsToken */);
|
|
1007
|
+
}
|
|
1008
|
+
if (next === 43 /* CharacterCodes.plus */) {
|
|
1009
|
+
this.pos = (this.pos + 2) | 0;
|
|
1010
|
+
return (this.token = 45 /* SyntaxKind.PlusPlusToken */);
|
|
1011
|
+
}
|
|
1012
|
+
this.pos = (this.pos + 1) | 0;
|
|
1013
|
+
return (this.token = 39 /* SyntaxKind.PlusToken */);
|
|
1014
|
+
}
|
|
1015
|
+
case 44 /* CharacterCodes.comma */:
|
|
1016
|
+
this.pos = (this.pos + 1) | 0;
|
|
1017
|
+
return (this.token = 27 /* SyntaxKind.CommaToken */);
|
|
1018
|
+
case 45 /* CharacterCodes.minus */: {
|
|
1019
|
+
const next = chars[this.pos + 1] | 0;
|
|
1020
|
+
if (next === 61 /* CharacterCodes.equals */) {
|
|
1021
|
+
this.pos = (this.pos + 2) | 0;
|
|
1022
|
+
return (this.token = 65 /* SyntaxKind.MinusEqualsToken */);
|
|
1023
|
+
}
|
|
1024
|
+
if (next === 45 /* CharacterCodes.minus */) {
|
|
1025
|
+
this.pos = (this.pos + 2) | 0;
|
|
1026
|
+
return (this.token = 46 /* SyntaxKind.MinusMinusToken */);
|
|
1027
|
+
}
|
|
1028
|
+
this.pos = (this.pos + 1) | 0;
|
|
1029
|
+
return (this.token = 40 /* SyntaxKind.MinusToken */);
|
|
1030
|
+
}
|
|
1031
|
+
case 46 /* CharacterCodes.dot */: {
|
|
1032
|
+
const next = chars[this.pos + 1] | 0;
|
|
1033
|
+
if (isDigit(next))
|
|
1034
|
+
return (this.token = this.scanNumber());
|
|
1035
|
+
if (next === 46 /* CharacterCodes.dot */ && (chars[this.pos + 2] | 0) === 46 /* CharacterCodes.dot */) {
|
|
1036
|
+
this.pos = (this.pos + 3) | 0;
|
|
1037
|
+
return (this.token = 25 /* SyntaxKind.DotDotDotToken */);
|
|
1038
|
+
}
|
|
1039
|
+
this.pos = (this.pos + 1) | 0;
|
|
1040
|
+
return (this.token = 24 /* SyntaxKind.DotToken */);
|
|
1041
|
+
}
|
|
1042
|
+
case 47 /* CharacterCodes.slash */: {
|
|
1043
|
+
const next = chars[this.pos + 1] | 0;
|
|
1044
|
+
if (next === 47 /* CharacterCodes.slash */) {
|
|
1045
|
+
const pos = this.lineCommentEnd((this.pos + 2) | 0);
|
|
1046
|
+
this.pos = pos;
|
|
1047
|
+
this.processCommentDirective(this.tokenStart, pos, false);
|
|
1048
|
+
if (this.skipTrivia)
|
|
1049
|
+
continue;
|
|
1050
|
+
return (this.token = 2 /* SyntaxKind.SingleLineCommentTrivia */);
|
|
1051
|
+
}
|
|
1052
|
+
if (next === 42 /* CharacterCodes.asterisk */) {
|
|
1053
|
+
if (this.scanMultiLineComment())
|
|
1054
|
+
continue;
|
|
1055
|
+
return (this.token = 3 /* SyntaxKind.MultiLineCommentTrivia */);
|
|
1056
|
+
}
|
|
1057
|
+
if (next === 61 /* CharacterCodes.equals */) {
|
|
1058
|
+
this.pos = (this.pos + 2) | 0;
|
|
1059
|
+
return (this.token = 68 /* SyntaxKind.SlashEqualsToken */);
|
|
1060
|
+
}
|
|
1061
|
+
this.pos = (this.pos + 1) | 0;
|
|
1062
|
+
return (this.token = 43 /* SyntaxKind.SlashToken */);
|
|
1063
|
+
}
|
|
1064
|
+
case 48 /* CharacterCodes._0 */: {
|
|
1065
|
+
const next = chars[this.pos + 1] | 0;
|
|
1066
|
+
if (next === 88 /* CharacterCodes.X */ || next === 120 /* CharacterCodes.x */)
|
|
1067
|
+
return (this.token = this.scanHexNumber());
|
|
1068
|
+
if (next === 66 /* CharacterCodes.B */ || next === 98 /* CharacterCodes.b */)
|
|
1069
|
+
return (this.token = this.scanBinaryOrOctalNumber(2));
|
|
1070
|
+
if (next === 79 /* CharacterCodes.O */ || next === 111 /* CharacterCodes.o */)
|
|
1071
|
+
return (this.token = this.scanBinaryOrOctalNumber(8));
|
|
1072
|
+
return (this.token = this.scanNumber());
|
|
1073
|
+
}
|
|
1074
|
+
case 49 /* CharacterCodes._1 */:
|
|
1075
|
+
case 50 /* CharacterCodes._2 */:
|
|
1076
|
+
case 51 /* CharacterCodes._3 */:
|
|
1077
|
+
case 52 /* CharacterCodes._4 */:
|
|
1078
|
+
case 53 /* CharacterCodes._5 */:
|
|
1079
|
+
case 54 /* CharacterCodes._6 */:
|
|
1080
|
+
case 55 /* CharacterCodes._7 */:
|
|
1081
|
+
case 56 /* CharacterCodes._8 */:
|
|
1082
|
+
case 57 /* CharacterCodes._9 */:
|
|
1083
|
+
return (this.token = this.scanNumber());
|
|
1084
|
+
case 58 /* CharacterCodes.colon */:
|
|
1085
|
+
this.pos = (this.pos + 1) | 0;
|
|
1086
|
+
return (this.token = 58 /* SyntaxKind.ColonToken */);
|
|
1087
|
+
case 59 /* CharacterCodes.semicolon */:
|
|
1088
|
+
this.pos = (this.pos + 1) | 0;
|
|
1089
|
+
return (this.token = 26 /* SyntaxKind.SemicolonToken */);
|
|
1090
|
+
case 60 /* CharacterCodes.lessThan */: {
|
|
1091
|
+
const next = chars[this.pos + 1] | 0;
|
|
1092
|
+
if (next === 60 /* CharacterCodes.lessThan */ && isConflictMarkerTrivia(this.text, this.pos)) {
|
|
1093
|
+
if (this.scanConflictMarker())
|
|
1094
|
+
continue;
|
|
1095
|
+
return (this.token = 6 /* SyntaxKind.ConflictMarkerTrivia */);
|
|
1096
|
+
}
|
|
1097
|
+
if (next === 60 /* CharacterCodes.lessThan */) {
|
|
1098
|
+
if ((chars[this.pos + 2] | 0) === 61 /* CharacterCodes.equals */) {
|
|
1099
|
+
this.pos = (this.pos + 3) | 0;
|
|
1100
|
+
return (this.token = 70 /* SyntaxKind.LessThanLessThanEqualsToken */);
|
|
1101
|
+
}
|
|
1102
|
+
this.pos = (this.pos + 2) | 0;
|
|
1103
|
+
return (this.token = 47 /* SyntaxKind.LessThanLessThanToken */);
|
|
1104
|
+
}
|
|
1105
|
+
if (next === 61 /* CharacterCodes.equals */) {
|
|
1106
|
+
this.pos = (this.pos + 2) | 0;
|
|
1107
|
+
return (this.token = 32 /* SyntaxKind.LessThanEqualsToken */);
|
|
1108
|
+
}
|
|
1109
|
+
if (this.languageVariant === 1 /* LanguageVariant.JSX */ &&
|
|
1110
|
+
next === 47 /* CharacterCodes.slash */ &&
|
|
1111
|
+
(chars[this.pos + 2] | 0) !== 42 /* CharacterCodes.asterisk */) {
|
|
1112
|
+
this.pos = (this.pos + 2) | 0;
|
|
1113
|
+
return (this.token = 30 /* SyntaxKind.LessThanSlashToken */);
|
|
1114
|
+
}
|
|
1115
|
+
this.pos = (this.pos + 1) | 0;
|
|
1116
|
+
return (this.token = 29 /* SyntaxKind.LessThanToken */);
|
|
1117
|
+
}
|
|
1118
|
+
case 61 /* CharacterCodes.equals */: {
|
|
1119
|
+
const next = chars[this.pos + 1] | 0;
|
|
1120
|
+
if (next === 61 /* CharacterCodes.equals */ && isConflictMarkerTrivia(this.text, this.pos)) {
|
|
1121
|
+
if (this.scanConflictMarker())
|
|
1122
|
+
continue;
|
|
1123
|
+
return (this.token = 6 /* SyntaxKind.ConflictMarkerTrivia */);
|
|
1124
|
+
}
|
|
1125
|
+
if (next === 61 /* CharacterCodes.equals */) {
|
|
1126
|
+
if ((chars[this.pos + 2] | 0) === 61 /* CharacterCodes.equals */) {
|
|
1127
|
+
this.pos = (this.pos + 3) | 0;
|
|
1128
|
+
return (this.token = 36 /* SyntaxKind.EqualsEqualsEqualsToken */);
|
|
1129
|
+
}
|
|
1130
|
+
this.pos = (this.pos + 2) | 0;
|
|
1131
|
+
return (this.token = 34 /* SyntaxKind.EqualsEqualsToken */);
|
|
1132
|
+
}
|
|
1133
|
+
if (next === 62 /* CharacterCodes.greaterThan */) {
|
|
1134
|
+
this.pos = (this.pos + 2) | 0;
|
|
1135
|
+
return (this.token = 38 /* SyntaxKind.EqualsGreaterThanToken */);
|
|
1136
|
+
}
|
|
1137
|
+
this.pos = (this.pos + 1) | 0;
|
|
1138
|
+
return (this.token = 63 /* SyntaxKind.EqualsToken */);
|
|
1139
|
+
}
|
|
1140
|
+
case 62 /* CharacterCodes.greaterThan */:
|
|
1141
|
+
if ((chars[this.pos + 1] | 0) === 62 /* CharacterCodes.greaterThan */ && isConflictMarkerTrivia(this.text, this.pos)) {
|
|
1142
|
+
if (this.scanConflictMarker())
|
|
1143
|
+
continue;
|
|
1144
|
+
return (this.token = 6 /* SyntaxKind.ConflictMarkerTrivia */);
|
|
1145
|
+
}
|
|
1146
|
+
this.pos = (this.pos + 1) | 0;
|
|
1147
|
+
return (this.token = 31 /* SyntaxKind.GreaterThanToken */);
|
|
1148
|
+
case 63 /* CharacterCodes.question */: {
|
|
1149
|
+
const next = chars[this.pos + 1] | 0;
|
|
1150
|
+
if (next === 46 /* CharacterCodes.dot */ && !isDigit(chars[this.pos + 2] | 0)) {
|
|
1151
|
+
this.pos = (this.pos + 2) | 0;
|
|
1152
|
+
return (this.token = 28 /* SyntaxKind.QuestionDotToken */);
|
|
1153
|
+
}
|
|
1154
|
+
if (next === 63 /* CharacterCodes.question */) {
|
|
1155
|
+
if ((chars[this.pos + 2] | 0) === 61 /* CharacterCodes.equals */) {
|
|
1156
|
+
this.pos = (this.pos + 3) | 0;
|
|
1157
|
+
return (this.token = 77 /* SyntaxKind.QuestionQuestionEqualsToken */);
|
|
1158
|
+
}
|
|
1159
|
+
this.pos = (this.pos + 2) | 0;
|
|
1160
|
+
return (this.token = 60 /* SyntaxKind.QuestionQuestionToken */);
|
|
1161
|
+
}
|
|
1162
|
+
this.pos = (this.pos + 1) | 0;
|
|
1163
|
+
return (this.token = 57 /* SyntaxKind.QuestionToken */);
|
|
1164
|
+
}
|
|
1165
|
+
case 91 /* CharacterCodes.openBracket */:
|
|
1166
|
+
this.pos = (this.pos + 1) | 0;
|
|
1167
|
+
return (this.token = 22 /* SyntaxKind.OpenBracketToken */);
|
|
1168
|
+
case 93 /* CharacterCodes.closeBracket */:
|
|
1169
|
+
this.pos = (this.pos + 1) | 0;
|
|
1170
|
+
return (this.token = 23 /* SyntaxKind.CloseBracketToken */);
|
|
1171
|
+
case 94 /* CharacterCodes.caret */:
|
|
1172
|
+
if ((chars[this.pos + 1] | 0) === 61 /* CharacterCodes.equals */) {
|
|
1173
|
+
this.pos = (this.pos + 2) | 0;
|
|
1174
|
+
return (this.token = 78 /* SyntaxKind.CaretEqualsToken */);
|
|
1175
|
+
}
|
|
1176
|
+
this.pos = (this.pos + 1) | 0;
|
|
1177
|
+
return (this.token = 52 /* SyntaxKind.CaretToken */);
|
|
1178
|
+
case 123 /* CharacterCodes.openBrace */:
|
|
1179
|
+
this.pos = (this.pos + 1) | 0;
|
|
1180
|
+
return (this.token = 18 /* SyntaxKind.OpenBraceToken */);
|
|
1181
|
+
case 124 /* CharacterCodes.bar */: {
|
|
1182
|
+
const next = chars[this.pos + 1] | 0;
|
|
1183
|
+
if (next === 124 /* CharacterCodes.bar */ && isConflictMarkerTrivia(this.text, this.pos)) {
|
|
1184
|
+
if (this.scanConflictMarker())
|
|
1185
|
+
continue;
|
|
1186
|
+
return (this.token = 6 /* SyntaxKind.ConflictMarkerTrivia */);
|
|
1187
|
+
}
|
|
1188
|
+
if (next === 124 /* CharacterCodes.bar */) {
|
|
1189
|
+
if ((chars[this.pos + 2] | 0) === 61 /* CharacterCodes.equals */) {
|
|
1190
|
+
this.pos = (this.pos + 3) | 0;
|
|
1191
|
+
return (this.token = 75 /* SyntaxKind.BarBarEqualsToken */);
|
|
1192
|
+
}
|
|
1193
|
+
this.pos = (this.pos + 2) | 0;
|
|
1194
|
+
return (this.token = 56 /* SyntaxKind.BarBarToken */);
|
|
1195
|
+
}
|
|
1196
|
+
if (next === 61 /* CharacterCodes.equals */) {
|
|
1197
|
+
this.pos = (this.pos + 2) | 0;
|
|
1198
|
+
return (this.token = 74 /* SyntaxKind.BarEqualsToken */);
|
|
1199
|
+
}
|
|
1200
|
+
this.pos = (this.pos + 1) | 0;
|
|
1201
|
+
return (this.token = 51 /* SyntaxKind.BarToken */);
|
|
1202
|
+
}
|
|
1203
|
+
case 125 /* CharacterCodes.closeBrace */:
|
|
1204
|
+
this.pos = (this.pos + 1) | 0;
|
|
1205
|
+
return (this.token = 19 /* SyntaxKind.CloseBraceToken */);
|
|
1206
|
+
case 126 /* CharacterCodes.tilde */:
|
|
1207
|
+
this.pos = (this.pos + 1) | 0;
|
|
1208
|
+
return (this.token = 54 /* SyntaxKind.TildeToken */);
|
|
1209
|
+
case 64 /* CharacterCodes.at */:
|
|
1210
|
+
this.pos = (this.pos + 1) | 0;
|
|
1211
|
+
return (this.token = 59 /* SyntaxKind.AtToken */);
|
|
1212
|
+
case 92 /* CharacterCodes.backslash */: {
|
|
1213
|
+
const codePoint = this.peekUnicodeEscape();
|
|
1214
|
+
if (codePoint >= 0 && isIdentifierStart(codePoint)) {
|
|
1215
|
+
const head = String.fromCodePoint(this.scanUnicodeEscape(true));
|
|
1216
|
+
this.setValue(head + this.scanIdentifierParts());
|
|
1217
|
+
return (this.token = getIdentifierToken(this.tokenValue));
|
|
1218
|
+
}
|
|
1219
|
+
return this.scanInvalidCharacter();
|
|
1220
|
+
}
|
|
1221
|
+
case 35 /* CharacterCodes.hash */:
|
|
1222
|
+
if ((chars[this.pos + 1] | 0) === 33 /* CharacterCodes.exclamation */) {
|
|
1223
|
+
if (this.pos === 0) {
|
|
1224
|
+
this.pos = scanShebangTrivia(this.text, 0) | 0;
|
|
1225
|
+
continue;
|
|
1226
|
+
}
|
|
1227
|
+
this.errorAt(1843 /* Diagnostics.X_can_only_be_used_at_the_start_of_a_file */, this.pos, 2, noArgs);
|
|
1228
|
+
this.pos = (this.pos + 1) | 0;
|
|
1229
|
+
return (this.token = 0 /* SyntaxKind.Unknown */);
|
|
1230
|
+
}
|
|
1231
|
+
if ((chars[this.pos + 1] | 0) === 92 /* CharacterCodes.backslash */) {
|
|
1232
|
+
this.pos = (this.pos + 1) | 0;
|
|
1233
|
+
const codePoint = this.peekUnicodeEscape();
|
|
1234
|
+
if (codePoint >= 0 && isIdentifierStart(codePoint)) {
|
|
1235
|
+
const head = '#' + String.fromCodePoint(this.scanUnicodeEscape(true));
|
|
1236
|
+
this.setValue(head + this.scanIdentifierParts());
|
|
1237
|
+
return (this.token = 80 /* SyntaxKind.PrivateIdentifier */);
|
|
1238
|
+
}
|
|
1239
|
+
this.pos = (this.pos - 1) | 0;
|
|
1240
|
+
}
|
|
1241
|
+
if (!this.scanIdentifier(1)) {
|
|
1242
|
+
this.errorAt(94 /* Diagnostics.Invalid_character */, this.pos - 1, 1, noArgs);
|
|
1243
|
+
this.setValue('#');
|
|
1244
|
+
}
|
|
1245
|
+
return (this.token = 80 /* SyntaxKind.PrivateIdentifier */);
|
|
1246
|
+
default: {
|
|
1247
|
+
if (ch < 0)
|
|
1248
|
+
return (this.token = 1 /* SyntaxKind.EndOfFile */);
|
|
1249
|
+
if (this.scanIdentifier(0))
|
|
1250
|
+
return (this.token = this.identifierKind());
|
|
1251
|
+
const codePoint = this.codePoint();
|
|
1252
|
+
if (codePoint === 65533 /* CharacterCodes.replacementCharacter */) {
|
|
1253
|
+
this.errorAt(405 /* Diagnostics.File_appears_to_be_binary */, 0, 0, noArgs);
|
|
1254
|
+
this.pos = this.end;
|
|
1255
|
+
return (this.token = 7 /* SyntaxKind.NonTextFileMarkerTrivia */);
|
|
1256
|
+
}
|
|
1257
|
+
if (isWhiteSpaceSingleLine(codePoint)) {
|
|
1258
|
+
this.pos = (this.pos + 1) | 0;
|
|
1259
|
+
if (codePoint === 133 /* CharacterCodes.nextLine */ || this.skipTrivia)
|
|
1260
|
+
continue;
|
|
1261
|
+
while (this.pos < this.end && isWhiteSpaceSingleLine(chars[this.pos] | 0))
|
|
1262
|
+
this.pos = (this.pos + 1) | 0;
|
|
1263
|
+
return (this.token = 5 /* SyntaxKind.WhitespaceTrivia */);
|
|
1264
|
+
}
|
|
1265
|
+
if (isLineBreak(codePoint)) {
|
|
1266
|
+
this.tokenFlags |= 1 /* TokenFlags.PrecedingLineBreak */;
|
|
1267
|
+
this.pos = (this.pos + 1) | 0;
|
|
1268
|
+
continue;
|
|
1269
|
+
}
|
|
1270
|
+
return this.scanInvalidCharacter();
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
/** The kind of the identifier just scanned by `scanIdentifier`. */
|
|
1276
|
+
identifierKind() {
|
|
1277
|
+
return this.valueStart >= 0
|
|
1278
|
+
? keywordKindAt(this.chars, this.valueStart, this.valueEnd)
|
|
1279
|
+
: getIdentifierToken(this.tokenValue);
|
|
1280
|
+
}
|
|
1281
|
+
/** The line breaks the text holds, found once per text. */
|
|
1282
|
+
getTextKind() {
|
|
1283
|
+
let kind = this.textKind;
|
|
1284
|
+
if (kind === 0 /* TextKind.Unknown */) {
|
|
1285
|
+
const text = this.text;
|
|
1286
|
+
// Natively, the UTF-8 length is known without a search, and ASCII texts hold no separators.
|
|
1287
|
+
if (Buffer.byteLength(text, 'utf8') !== text.length &&
|
|
1288
|
+
(text.indexOf('\u2028') >= 0 || text.indexOf('\u2029') >= 0))
|
|
1289
|
+
kind = 3 /* TextKind.Separators */;
|
|
1290
|
+
else
|
|
1291
|
+
kind = text.indexOf('\r') >= 0 ? 2 /* TextKind.LFAndCR */ : 1 /* TextKind.LF */;
|
|
1292
|
+
this.textKind = kind;
|
|
1293
|
+
}
|
|
1294
|
+
return kind;
|
|
1295
|
+
}
|
|
1296
|
+
/**
|
|
1297
|
+
* The end of the line comment whose text starts at `pos`: the next line break, or `end`. Found with
|
|
1298
|
+
* string searches (natively, byte searches) instead of a loop over code units, except in texts with
|
|
1299
|
+
* line or paragraph separators.
|
|
1300
|
+
*/
|
|
1301
|
+
lineCommentEnd(pos) {
|
|
1302
|
+
const end = this.end;
|
|
1303
|
+
const kind = this.getTextKind();
|
|
1304
|
+
if (kind !== 3 /* TextKind.Separators */) {
|
|
1305
|
+
let at = this.nextLineFeed(pos);
|
|
1306
|
+
if (kind === 2 /* TextKind.LFAndCR */)
|
|
1307
|
+
at = Math.min(at, this.nextCarriageReturn(pos));
|
|
1308
|
+
return at > end ? end : at | 0;
|
|
1309
|
+
}
|
|
1310
|
+
const chars = this.chars;
|
|
1311
|
+
while (pos < end && !isLineBreak(chars[pos] | 0))
|
|
1312
|
+
pos = (pos + 1) | 0;
|
|
1313
|
+
return pos;
|
|
1314
|
+
}
|
|
1315
|
+
/**
|
|
1316
|
+
* The position of the first LF at or after `pos`, or the text length. The last result is kept: as
|
|
1317
|
+
* the scanner moves forward each search starts where the previous one ended, so a text with few
|
|
1318
|
+
* LFs (CR line breaks) is not searched to its end once per line comment.
|
|
1319
|
+
*/
|
|
1320
|
+
nextLineFeed(pos) {
|
|
1321
|
+
if (pos >= this.lineFeedFrom && pos <= this.lineFeedAt)
|
|
1322
|
+
return this.lineFeedAt;
|
|
1323
|
+
const text = this.text;
|
|
1324
|
+
const at = text.indexOf('\n', pos);
|
|
1325
|
+
this.lineFeedFrom = pos;
|
|
1326
|
+
this.lineFeedAt = at < 0 ? text.length : at;
|
|
1327
|
+
return this.lineFeedAt;
|
|
1328
|
+
}
|
|
1329
|
+
/** Like `nextLineFeed`, for CR: a text with LF line breaks and few CRs is searched once. */
|
|
1330
|
+
nextCarriageReturn(pos) {
|
|
1331
|
+
if (pos >= this.carriageReturnFrom && pos <= this.carriageReturnAt)
|
|
1332
|
+
return this.carriageReturnAt;
|
|
1333
|
+
const text = this.text;
|
|
1334
|
+
const at = text.indexOf('\r', pos);
|
|
1335
|
+
this.carriageReturnFrom = pos;
|
|
1336
|
+
this.carriageReturnAt = at < 0 ? text.length : at;
|
|
1337
|
+
return this.carriageReturnAt;
|
|
1338
|
+
}
|
|
1339
|
+
/** Scans `/* … *\/`; returns true if the comment is skipped as trivia. */
|
|
1340
|
+
scanMultiLineComment() {
|
|
1341
|
+
const chars = this.chars;
|
|
1342
|
+
const end = this.end;
|
|
1343
|
+
let pos = (this.pos + 2) | 0;
|
|
1344
|
+
const isJSDoc = pos < end && (chars[pos] | 0) === 42 /* CharacterCodes.asterisk */ && (chars[pos + 1] | 0) !== 47 /* CharacterCodes.slash */;
|
|
1345
|
+
let closed = false;
|
|
1346
|
+
let lastLineStart = this.tokenStart;
|
|
1347
|
+
let flags = this.tokenFlags;
|
|
1348
|
+
if (isJSDoc)
|
|
1349
|
+
flags |= 2 /* TokenFlags.PrecedingJSDocComment */;
|
|
1350
|
+
const kind = this.getTextKind();
|
|
1351
|
+
if (kind !== 3 /* TextKind.Separators */) {
|
|
1352
|
+
// String searches for the closing `*/`, then for the line breaks and JSDoc tags in the comment,
|
|
1353
|
+
// instead of a loop over code units; not in texts with line or paragraph separators.
|
|
1354
|
+
const text = this.text;
|
|
1355
|
+
const close = text.indexOf('*/', pos);
|
|
1356
|
+
closed = close >= 0 && close + 2 <= end;
|
|
1357
|
+
const bodyEnd = closed ? close : end;
|
|
1358
|
+
if (pos < bodyEnd) {
|
|
1359
|
+
const body = text.substring(pos, bodyEnd);
|
|
1360
|
+
// A forward search first: most comments have no line break, and searching back is slower.
|
|
1361
|
+
let lastBreak = body.indexOf('\n') >= 0 ? body.lastIndexOf('\n') : -1;
|
|
1362
|
+
if (kind === 2 /* TextKind.LFAndCR */ && body.indexOf('\r') >= 0)
|
|
1363
|
+
lastBreak = Math.max(lastBreak, body.lastIndexOf('\r'));
|
|
1364
|
+
if (lastBreak >= 0) {
|
|
1365
|
+
lastLineStart = (pos + lastBreak + 1) | 0;
|
|
1366
|
+
flags |= 1 /* TokenFlags.PrecedingLineBreak */;
|
|
1367
|
+
}
|
|
1368
|
+
if (isJSDoc)
|
|
1369
|
+
for (let at = body.indexOf('@'); at >= 0; at = body.indexOf('@', at + 1))
|
|
1370
|
+
flags = jsDocTagFlags(chars, pos + at + 1, end, flags);
|
|
1371
|
+
}
|
|
1372
|
+
pos = closed ? (close + 2) | 0 : end;
|
|
1373
|
+
}
|
|
1374
|
+
else {
|
|
1375
|
+
while (pos < end) {
|
|
1376
|
+
pos = skipCommentText(chars, pos, end) | 0;
|
|
1377
|
+
if (pos >= end)
|
|
1378
|
+
break;
|
|
1379
|
+
const c = chars[pos] | 0;
|
|
1380
|
+
pos = (pos + 1) | 0;
|
|
1381
|
+
if (c === 42 /* CharacterCodes.asterisk */) {
|
|
1382
|
+
if ((chars[pos] | 0) === 47 /* CharacterCodes.slash */) {
|
|
1383
|
+
pos = (pos + 1) | 0;
|
|
1384
|
+
closed = true;
|
|
1385
|
+
break;
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
else if (c === 10 /* CharacterCodes.lineFeed */ || c === 13 /* CharacterCodes.carriageReturn */ || c >= 0x2028) {
|
|
1389
|
+
if (isLineBreak(c)) {
|
|
1390
|
+
lastLineStart = pos;
|
|
1391
|
+
flags |= 1 /* TokenFlags.PrecedingLineBreak */;
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
else if (c === 64 /* CharacterCodes.at */ && isJSDoc) {
|
|
1395
|
+
flags = jsDocTagFlags(chars, pos, end, flags);
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
this.pos = pos;
|
|
1400
|
+
this.tokenFlags = flags;
|
|
1401
|
+
this.processCommentDirective(lastLineStart, pos, true);
|
|
1402
|
+
if (!closed)
|
|
1403
|
+
this.error(6 /* Diagnostics.Asterisk_Slash_expected */);
|
|
1404
|
+
if (this.skipTrivia)
|
|
1405
|
+
return true;
|
|
1406
|
+
if (!closed)
|
|
1407
|
+
this.tokenFlags |= 4 /* TokenFlags.Unterminated */;
|
|
1408
|
+
return false;
|
|
1409
|
+
}
|
|
1410
|
+
/** Scans a merge conflict marker; returns true if it is skipped as trivia. */
|
|
1411
|
+
scanConflictMarker() {
|
|
1412
|
+
this.pos = scanConflictMarkerTrivia(this.text, this.pos, this) | 0;
|
|
1413
|
+
return this.skipTrivia;
|
|
1414
|
+
}
|
|
1415
|
+
processCommentDirective(start, end, multiline) {
|
|
1416
|
+
const text = this.text;
|
|
1417
|
+
const chars = this.chars;
|
|
1418
|
+
let pos = start;
|
|
1419
|
+
if (multiline) {
|
|
1420
|
+
while (pos < end && (chars[pos] === 32 /* CharacterCodes.space */ || chars[pos] === 9 /* CharacterCodes.tab */))
|
|
1421
|
+
pos++;
|
|
1422
|
+
while (pos < end && (chars[pos] === 47 /* CharacterCodes.slash */ || chars[pos] === 42 /* CharacterCodes.asterisk */))
|
|
1423
|
+
pos++;
|
|
1424
|
+
}
|
|
1425
|
+
else {
|
|
1426
|
+
pos += 2;
|
|
1427
|
+
while (pos < end && chars[pos] === 47 /* CharacterCodes.slash */)
|
|
1428
|
+
pos++;
|
|
1429
|
+
}
|
|
1430
|
+
while (pos < end && (chars[pos] === 32 /* CharacterCodes.space */ || chars[pos] === 9 /* CharacterCodes.tab */))
|
|
1431
|
+
pos++;
|
|
1432
|
+
if (!(pos < end && chars[pos] === 64 /* CharacterCodes.at */))
|
|
1433
|
+
return;
|
|
1434
|
+
pos++;
|
|
1435
|
+
let kind;
|
|
1436
|
+
if (hasPrefixAt(text, pos, 'ts-expect-error'))
|
|
1437
|
+
kind = 1 /* CommentDirectiveKind.ExpectError */;
|
|
1438
|
+
else if (hasPrefixAt(text, pos, 'ts-ignore'))
|
|
1439
|
+
kind = 2 /* CommentDirectiveKind.Ignore */;
|
|
1440
|
+
else
|
|
1441
|
+
return;
|
|
1442
|
+
this.commentDirectives.push(new CommentDirective(start, end, kind));
|
|
1443
|
+
}
|
|
1444
|
+
/** @internal Scans an identifier after `prefixLength` units; sets the token value. */
|
|
1445
|
+
scanIdentifier(prefixLength) {
|
|
1446
|
+
const text = this.text;
|
|
1447
|
+
const chars = this.chars;
|
|
1448
|
+
const start = this.pos;
|
|
1449
|
+
this.pos = (this.pos + prefixLength) | 0;
|
|
1450
|
+
let ch = this.char();
|
|
1451
|
+
if (isASCIILetter(ch) || ch === 95 /* CharacterCodes._ */ || ch === 36 /* CharacterCodes.$ */) {
|
|
1452
|
+
// Fast path for ASCII identifiers, which also hashes the units for interning.
|
|
1453
|
+
let pos = (this.pos + 1) | 0;
|
|
1454
|
+
const end = this.end;
|
|
1455
|
+
// The FNV-1a offset basis, as in `rangeHash` (a literal: native builds load module constants).
|
|
1456
|
+
let hash = 0x811c9dc5 | 0;
|
|
1457
|
+
for (let i = start; i < pos; i = (i + 1) | 0)
|
|
1458
|
+
hash = Math.imul(hash ^ (chars[i] | 0), 0x01000193);
|
|
1459
|
+
while (pos < end) {
|
|
1460
|
+
const c = chars[pos] | 0;
|
|
1461
|
+
if (!isASCIIIdentifierPart(c))
|
|
1462
|
+
break;
|
|
1463
|
+
hash = Math.imul(hash ^ c, 0x01000193);
|
|
1464
|
+
pos = (pos + 1) | 0;
|
|
1465
|
+
}
|
|
1466
|
+
this.pos = pos;
|
|
1467
|
+
ch = pos < end ? chars[pos] | 0 : -1 /* CharacterCodes.EOF */;
|
|
1468
|
+
if (ch <= 127 /* CharacterCodes.maxAsciiCharacter */ && ch !== 92 /* CharacterCodes.backslash */) {
|
|
1469
|
+
this.setValueSlice(start, pos);
|
|
1470
|
+
this.valueHash = finishHash(hash);
|
|
1471
|
+
this.hashStart = start;
|
|
1472
|
+
this.hashEnd = pos;
|
|
1473
|
+
return true;
|
|
1474
|
+
}
|
|
1475
|
+
this.pos = (start + prefixLength) | 0;
|
|
1476
|
+
}
|
|
1477
|
+
ch = this.codePoint();
|
|
1478
|
+
if (!isIdentifierStart(ch))
|
|
1479
|
+
return false;
|
|
1480
|
+
do {
|
|
1481
|
+
this.pos = (this.pos + charSize(ch)) | 0;
|
|
1482
|
+
ch = this.codePoint();
|
|
1483
|
+
} while (isIdentifierPart(ch));
|
|
1484
|
+
if (ch === 92 /* CharacterCodes.backslash */)
|
|
1485
|
+
this.setValue(text.substring(start, this.pos) + this.scanIdentifierParts());
|
|
1486
|
+
else
|
|
1487
|
+
this.setValueSlice(start, this.pos);
|
|
1488
|
+
return true;
|
|
1489
|
+
}
|
|
1490
|
+
/** Scans identifier parts including `\u` escapes and returns their cooked text. */
|
|
1491
|
+
scanIdentifierParts() {
|
|
1492
|
+
let result = '';
|
|
1493
|
+
let start = this.pos;
|
|
1494
|
+
for (;;) {
|
|
1495
|
+
const ch = this.codePoint();
|
|
1496
|
+
if (isIdentifierPart(ch)) {
|
|
1497
|
+
this.pos = (this.pos + charSize(ch)) | 0;
|
|
1498
|
+
continue;
|
|
1499
|
+
}
|
|
1500
|
+
if (ch === 92 /* CharacterCodes.backslash */) {
|
|
1501
|
+
const escaped = this.peekUnicodeEscape();
|
|
1502
|
+
if (escaped >= 0 && isIdentifierPart(escaped)) {
|
|
1503
|
+
result += this.text.substring(start, this.pos) + String.fromCodePoint(this.scanUnicodeEscape(true));
|
|
1504
|
+
start = this.pos;
|
|
1505
|
+
continue;
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
break;
|
|
1509
|
+
}
|
|
1510
|
+
return start === this.pos ? result : result + this.text.substring(start, this.pos);
|
|
1511
|
+
}
|
|
1512
|
+
scanInvalidCharacter() {
|
|
1513
|
+
const size = charSize(this.codePoint());
|
|
1514
|
+
this.errorAt(94 /* Diagnostics.Invalid_character */, this.pos, size, noArgs);
|
|
1515
|
+
this.pos = (this.pos + size) | 0;
|
|
1516
|
+
return (this.token = 0 /* SyntaxKind.Unknown */);
|
|
1517
|
+
}
|
|
1518
|
+
/** Scans a quoted string and sets its cooked value. */
|
|
1519
|
+
scanString(jsxAttributeString) {
|
|
1520
|
+
const text = this.text;
|
|
1521
|
+
const chars = this.chars;
|
|
1522
|
+
const quote = this.char();
|
|
1523
|
+
if (quote === 39 /* CharacterCodes.singleQuote */)
|
|
1524
|
+
this.tokenFlags |= 65536 /* TokenFlags.SingleQuote */;
|
|
1525
|
+
let start = (this.pos + 1) | 0;
|
|
1526
|
+
// Fast path: no escapes or line breaks before the closing quote.
|
|
1527
|
+
let pos = start;
|
|
1528
|
+
const end = this.end;
|
|
1529
|
+
while (pos < end) {
|
|
1530
|
+
const ch = chars[pos] | 0;
|
|
1531
|
+
if (ch === quote) {
|
|
1532
|
+
this.setValueSlice(start, pos);
|
|
1533
|
+
this.pos = (pos + 1) | 0;
|
|
1534
|
+
return;
|
|
1535
|
+
}
|
|
1536
|
+
if (!jsxAttributeString &&
|
|
1537
|
+
(ch === 92 /* CharacterCodes.backslash */ || ch === 10 /* CharacterCodes.lineFeed */ || ch === 13 /* CharacterCodes.carriageReturn */))
|
|
1538
|
+
break;
|
|
1539
|
+
pos = (pos + 1) | 0;
|
|
1540
|
+
}
|
|
1541
|
+
this.pos = pos;
|
|
1542
|
+
let result = '';
|
|
1543
|
+
for (;;) {
|
|
1544
|
+
const ch = this.char();
|
|
1545
|
+
if (ch < 0) {
|
|
1546
|
+
result += text.substring(start, this.pos);
|
|
1547
|
+
this.tokenFlags |= 4 /* TokenFlags.Unterminated */;
|
|
1548
|
+
this.error(0 /* Diagnostics.Unterminated_string_literal */);
|
|
1549
|
+
break;
|
|
1550
|
+
}
|
|
1551
|
+
if (ch === quote) {
|
|
1552
|
+
result += text.substring(start, this.pos);
|
|
1553
|
+
this.pos = (this.pos + 1) | 0;
|
|
1554
|
+
break;
|
|
1555
|
+
}
|
|
1556
|
+
if (ch === 92 /* CharacterCodes.backslash */ && !jsxAttributeString) {
|
|
1557
|
+
result += text.substring(start, this.pos);
|
|
1558
|
+
result += this.scanEscapeSequence(1 /* EscapeSequenceScanningFlags.String */ | 2 /* EscapeSequenceScanningFlags.ReportErrors */);
|
|
1559
|
+
start = this.pos;
|
|
1560
|
+
continue;
|
|
1561
|
+
}
|
|
1562
|
+
if ((ch === 10 /* CharacterCodes.lineFeed */ || ch === 13 /* CharacterCodes.carriageReturn */) && !jsxAttributeString) {
|
|
1563
|
+
result += text.substring(start, this.pos);
|
|
1564
|
+
this.tokenFlags |= 4 /* TokenFlags.Unterminated */;
|
|
1565
|
+
this.error(0 /* Diagnostics.Unterminated_string_literal */);
|
|
1566
|
+
break;
|
|
1567
|
+
}
|
|
1568
|
+
this.pos = (this.pos + 1) | 0;
|
|
1569
|
+
}
|
|
1570
|
+
this.setValue(result);
|
|
1571
|
+
}
|
|
1572
|
+
/** Scans a template literal part starting at `` ` `` or `}`. */
|
|
1573
|
+
scanTemplateAndSetTokenValue(shouldEmitInvalidEscapeError) {
|
|
1574
|
+
const text = this.text;
|
|
1575
|
+
const chars = this.chars;
|
|
1576
|
+
const end = this.end;
|
|
1577
|
+
const startedWithBacktick = this.char() === 96 /* CharacterCodes.backtick */;
|
|
1578
|
+
let start = this.pos + 1;
|
|
1579
|
+
let pos = start;
|
|
1580
|
+
// The value is `text[start, pos)` unless escapes or CRs make it `cooked`.
|
|
1581
|
+
let cooked = false;
|
|
1582
|
+
let result = '';
|
|
1583
|
+
let token = 0 /* SyntaxKind.Unknown */;
|
|
1584
|
+
for (;;) {
|
|
1585
|
+
pos = skipTemplateText(chars, pos, end);
|
|
1586
|
+
const ch = pos < end ? chars[pos] : -1 /* CharacterCodes.EOF */;
|
|
1587
|
+
if (ch < 0 || ch === 96 /* CharacterCodes.backtick */) {
|
|
1588
|
+
this.pos = pos | 0;
|
|
1589
|
+
if (ch === 96 /* CharacterCodes.backtick */) {
|
|
1590
|
+
this.pos = (this.pos + 1) | 0;
|
|
1591
|
+
}
|
|
1592
|
+
else {
|
|
1593
|
+
this.tokenFlags |= 4 /* TokenFlags.Unterminated */;
|
|
1594
|
+
this.error(117 /* Diagnostics.Unterminated_template_literal */);
|
|
1595
|
+
}
|
|
1596
|
+
token = startedWithBacktick ? 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */ : 17 /* SyntaxKind.TemplateTail */;
|
|
1597
|
+
break;
|
|
1598
|
+
}
|
|
1599
|
+
if (ch === 36 /* CharacterCodes.$ */) {
|
|
1600
|
+
if (chars[pos + 1] !== 123 /* CharacterCodes.openBrace */) {
|
|
1601
|
+
pos++;
|
|
1602
|
+
continue;
|
|
1603
|
+
}
|
|
1604
|
+
this.pos = (pos + 2) | 0;
|
|
1605
|
+
token = startedWithBacktick ? 15 /* SyntaxKind.TemplateHead */ : 16 /* SyntaxKind.TemplateMiddle */;
|
|
1606
|
+
break;
|
|
1607
|
+
}
|
|
1608
|
+
result += text.substring(start, pos);
|
|
1609
|
+
cooked = true;
|
|
1610
|
+
if (ch === 92 /* CharacterCodes.backslash */) {
|
|
1611
|
+
this.pos = pos | 0;
|
|
1612
|
+
result += this.scanEscapeSequence(shouldEmitInvalidEscapeError
|
|
1613
|
+
? 1 /* EscapeSequenceScanningFlags.String */ | 2 /* EscapeSequenceScanningFlags.ReportErrors */
|
|
1614
|
+
: 1 /* EscapeSequenceScanningFlags.String */);
|
|
1615
|
+
pos = this.pos;
|
|
1616
|
+
}
|
|
1617
|
+
else {
|
|
1618
|
+
// <CR><LF> and <CR> are normalized to <LF> in template values.
|
|
1619
|
+
result += '\n';
|
|
1620
|
+
pos++;
|
|
1621
|
+
if (pos < end && chars[pos] === 10 /* CharacterCodes.lineFeed */)
|
|
1622
|
+
pos++;
|
|
1623
|
+
}
|
|
1624
|
+
start = pos;
|
|
1625
|
+
}
|
|
1626
|
+
if (cooked)
|
|
1627
|
+
this.setValue(result + text.substring(start, pos));
|
|
1628
|
+
else
|
|
1629
|
+
this.setValueSlice(start, pos);
|
|
1630
|
+
return token;
|
|
1631
|
+
}
|
|
1632
|
+
/** Scans an escape sequence at `\` and returns its cooked value. */
|
|
1633
|
+
scanEscapeSequence(flags) {
|
|
1634
|
+
const start = this.pos;
|
|
1635
|
+
const value = this.scanEscapeCodePoint(flags);
|
|
1636
|
+
if (value >= 0)
|
|
1637
|
+
return String.fromCodePoint(value);
|
|
1638
|
+
return value === -1 /* EscapeValue.Empty */ ? '' : this.text.substring(start, this.pos);
|
|
1639
|
+
}
|
|
1640
|
+
/**
|
|
1641
|
+
* @internal Scans an escape sequence at `\`. Returns its code point, `EscapeValue.Empty`
|
|
1642
|
+
* for a line continuation, or `EscapeValue.Raw` when the value is the escape's own text.
|
|
1643
|
+
*/
|
|
1644
|
+
scanEscapeCodePoint(flags) {
|
|
1645
|
+
const start = this.pos;
|
|
1646
|
+
this.pos = (this.pos + 1) | 0;
|
|
1647
|
+
let ch = this.char();
|
|
1648
|
+
if (ch < 0) {
|
|
1649
|
+
this.error(93 /* Diagnostics.Unexpected_end_of_text */);
|
|
1650
|
+
return -1 /* EscapeValue.Empty */;
|
|
1651
|
+
}
|
|
1652
|
+
this.pos = (this.pos + 1) | 0;
|
|
1653
|
+
switch (ch) {
|
|
1654
|
+
case 48 /* CharacterCodes._0 */:
|
|
1655
|
+
case 49 /* CharacterCodes._1 */:
|
|
1656
|
+
case 50 /* CharacterCodes._2 */:
|
|
1657
|
+
case 51 /* CharacterCodes._3 */:
|
|
1658
|
+
case 52 /* CharacterCodes._4 */:
|
|
1659
|
+
case 53 /* CharacterCodes._5 */:
|
|
1660
|
+
case 54 /* CharacterCodes._6 */:
|
|
1661
|
+
case 55 /* CharacterCodes._7 */: {
|
|
1662
|
+
// '\0' not followed by a digit is the null character; '\08' is '\0' + '8'.
|
|
1663
|
+
if (ch === 48 /* CharacterCodes._0 */ && !isDigit(this.char()))
|
|
1664
|
+
return 0;
|
|
1665
|
+
// '\1', '\17', '\177', but '\4', '\47' and not '\477'.
|
|
1666
|
+
if (ch <= 51 /* CharacterCodes._3 */ && isOctalDigit(this.char()))
|
|
1667
|
+
this.pos = (this.pos + 1) | 0;
|
|
1668
|
+
if (isOctalDigit(this.char()))
|
|
1669
|
+
this.pos = (this.pos + 1) | 0;
|
|
1670
|
+
this.tokenFlags |= 2048 /* TokenFlags.ContainsInvalidEscape */;
|
|
1671
|
+
if ((flags & 6 /* EscapeSequenceScanningFlags.ReportInvalidEscapeErrors */) !== 0) {
|
|
1672
|
+
const code = parseInt(this.text.substring(start + 1, this.pos), 8);
|
|
1673
|
+
const args = [hexByte(code)];
|
|
1674
|
+
if ((flags & 4 /* EscapeSequenceScanningFlags.RegularExpression */) !== 0 &&
|
|
1675
|
+
(flags & 32 /* EscapeSequenceScanningFlags.AtomEscape */) === 0 &&
|
|
1676
|
+
ch !== 48 /* CharacterCodes._0 */)
|
|
1677
|
+
this.errorAt(451 /* Diagnostics.Octal_escape_sequences_and_backreferences_are_not_allowed_in_a_character_class_If_this_was_intended_as_an_escape_sequence_use_the_syntax_0_instead */, start, this.pos - start, args);
|
|
1678
|
+
else
|
|
1679
|
+
this.errorAt(402 /* Diagnostics.Octal_escape_sequences_are_not_allowed_Use_the_syntax_0 */, start, this.pos - start, args);
|
|
1680
|
+
return code;
|
|
1681
|
+
}
|
|
1682
|
+
return -2 /* EscapeValue.Raw */;
|
|
1683
|
+
}
|
|
1684
|
+
case 56 /* CharacterCodes._8 */:
|
|
1685
|
+
case 57 /* CharacterCodes._9 */:
|
|
1686
|
+
this.tokenFlags |= 2048 /* TokenFlags.ContainsInvalidEscape */;
|
|
1687
|
+
if ((flags & 6 /* EscapeSequenceScanningFlags.ReportInvalidEscapeErrors */) !== 0) {
|
|
1688
|
+
if ((flags & 4 /* EscapeSequenceScanningFlags.RegularExpression */) !== 0 &&
|
|
1689
|
+
(flags & 32 /* EscapeSequenceScanningFlags.AtomEscape */) === 0)
|
|
1690
|
+
this.errorAt(452 /* Diagnostics.Decimal_escape_sequences_and_backreferences_are_not_allowed_in_a_character_class */, start, this.pos - start, noArgs);
|
|
1691
|
+
else
|
|
1692
|
+
this.errorAt(403 /* Diagnostics.Escape_sequence_0_is_not_allowed */, start, this.pos - start, [
|
|
1693
|
+
this.text.substring(start, this.pos),
|
|
1694
|
+
]);
|
|
1695
|
+
return ch;
|
|
1696
|
+
}
|
|
1697
|
+
return -2 /* EscapeValue.Raw */;
|
|
1698
|
+
case 98 /* CharacterCodes.b */:
|
|
1699
|
+
return 8 /* CharacterCodes.backspace */;
|
|
1700
|
+
case 116 /* CharacterCodes.t */:
|
|
1701
|
+
return 9 /* CharacterCodes.tab */;
|
|
1702
|
+
case 110 /* CharacterCodes.n */:
|
|
1703
|
+
return 10 /* CharacterCodes.lineFeed */;
|
|
1704
|
+
case 118 /* CharacterCodes.v */:
|
|
1705
|
+
return 11 /* CharacterCodes.verticalTab */;
|
|
1706
|
+
case 102 /* CharacterCodes.f */:
|
|
1707
|
+
return 12 /* CharacterCodes.formFeed */;
|
|
1708
|
+
case 114 /* CharacterCodes.r */:
|
|
1709
|
+
return 13 /* CharacterCodes.carriageReturn */;
|
|
1710
|
+
case 39 /* CharacterCodes.singleQuote */:
|
|
1711
|
+
return 39 /* CharacterCodes.singleQuote */;
|
|
1712
|
+
case 34 /* CharacterCodes.doubleQuote */:
|
|
1713
|
+
return 34 /* CharacterCodes.doubleQuote */;
|
|
1714
|
+
case 117 /* CharacterCodes.u */: {
|
|
1715
|
+
// '\uDDDD' and '\u{DDDDDD}'
|
|
1716
|
+
const extended = this.char() === 123 /* CharacterCodes.openBrace */;
|
|
1717
|
+
this.pos = (this.pos - 2) | 0;
|
|
1718
|
+
const reportErrors = (flags & 6 /* EscapeSequenceScanningFlags.ReportInvalidEscapeErrors */) !== 0;
|
|
1719
|
+
const codePoint = this.scanUnicodeEscape(reportErrors);
|
|
1720
|
+
if (extended && (flags & 17 /* EscapeSequenceScanningFlags.AllowExtendedUnicodeEscape */) === 0) {
|
|
1721
|
+
this.tokenFlags |= 2048 /* TokenFlags.ContainsInvalidEscape */;
|
|
1722
|
+
if (reportErrors)
|
|
1723
|
+
this.errorAt(453 /* Diagnostics.Unicode_escape_sequences_are_only_available_when_the_Unicode_u_flag_or_the_Unicode_Sets_v_flag_is_set */, start, this.pos - start, noArgs);
|
|
1724
|
+
}
|
|
1725
|
+
if (codePoint < 0)
|
|
1726
|
+
return -2 /* EscapeValue.Raw */;
|
|
1727
|
+
// In any-Unicode regular expressions, '\uHigh\uLow' is one code point.
|
|
1728
|
+
if (!extended &&
|
|
1729
|
+
(flags & 4 /* EscapeSequenceScanningFlags.RegularExpression */) !== 0 &&
|
|
1730
|
+
(flags & 16 /* EscapeSequenceScanningFlags.AnyUnicodeMode */) !== 0 &&
|
|
1731
|
+
codePoint >= 0xd800 &&
|
|
1732
|
+
codePoint <= 0xdbff &&
|
|
1733
|
+
this.char() === 92 /* CharacterCodes.backslash */ &&
|
|
1734
|
+
this.peek(1) === 117 /* CharacterCodes.u */ &&
|
|
1735
|
+
this.peek(2) !== 123 /* CharacterCodes.openBrace */) {
|
|
1736
|
+
const savedPos = this.pos;
|
|
1737
|
+
const low = this.scanUnicodeEscape(reportErrors);
|
|
1738
|
+
if (low >= 0xdc00 && low <= 0xdfff)
|
|
1739
|
+
return (codePoint - 0xd800) * 0x400 + (low - 0xdc00) + 0x10000;
|
|
1740
|
+
this.pos = savedPos | 0;
|
|
1741
|
+
}
|
|
1742
|
+
// In strings, a high surrogate escape joins a following low surrogate escape.
|
|
1743
|
+
if ((flags & 4 /* EscapeSequenceScanningFlags.RegularExpression */) === 0 &&
|
|
1744
|
+
codePoint >= 0xd800 &&
|
|
1745
|
+
codePoint <= 0xdbff) {
|
|
1746
|
+
const low = this.scanLowSurrogateEscape();
|
|
1747
|
+
if (low >= 0)
|
|
1748
|
+
return (codePoint - 0xd800) * 0x400 + (low - 0xdc00) + 0x10000;
|
|
1749
|
+
}
|
|
1750
|
+
return codePoint;
|
|
1751
|
+
}
|
|
1752
|
+
case 120 /* CharacterCodes.x */:
|
|
1753
|
+
// '\xDD'
|
|
1754
|
+
for (; this.pos < start + 4; this.pos = (this.pos + 1) | 0) {
|
|
1755
|
+
if (!isHexDigit(this.char())) {
|
|
1756
|
+
this.tokenFlags |= 2048 /* TokenFlags.ContainsInvalidEscape */;
|
|
1757
|
+
if ((flags & 6 /* EscapeSequenceScanningFlags.ReportInvalidEscapeErrors */) !== 0)
|
|
1758
|
+
this.error(92 /* Diagnostics.Hexadecimal_digit_expected */);
|
|
1759
|
+
return -2 /* EscapeValue.Raw */;
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
this.tokenFlags |= 4096 /* TokenFlags.HexEscape */;
|
|
1763
|
+
return parseInt(this.text.substring(start + 2, this.pos), 16);
|
|
1764
|
+
case 13 /* CharacterCodes.carriageReturn */:
|
|
1765
|
+
// A line continuation is the empty code unit sequence.
|
|
1766
|
+
if (this.char() === 10 /* CharacterCodes.lineFeed */)
|
|
1767
|
+
this.pos = (this.pos + 1) | 0;
|
|
1768
|
+
return -1 /* EscapeValue.Empty */;
|
|
1769
|
+
case 10 /* CharacterCodes.lineFeed */:
|
|
1770
|
+
case 8232 /* CharacterCodes.lineSeparator */:
|
|
1771
|
+
case 8233 /* CharacterCodes.paragraphSeparator */:
|
|
1772
|
+
return -1 /* EscapeValue.Empty */;
|
|
1773
|
+
default:
|
|
1774
|
+
if (ch >= 0xd800 && ch <= 0xdbff) {
|
|
1775
|
+
this.pos = (this.pos - 1) | 0;
|
|
1776
|
+
ch = this.codePoint();
|
|
1777
|
+
this.pos = (this.pos + charSize(ch)) | 0;
|
|
1778
|
+
}
|
|
1779
|
+
if ((flags & 16 /* EscapeSequenceScanningFlags.AnyUnicodeMode */) !== 0 ||
|
|
1780
|
+
((flags & 4 /* EscapeSequenceScanningFlags.RegularExpression */) !== 0 &&
|
|
1781
|
+
(flags & 8 /* EscapeSequenceScanningFlags.AnnexB */) === 0 &&
|
|
1782
|
+
isIdentifierPart(ch)))
|
|
1783
|
+
this.errorAt(450 /* Diagnostics.This_character_cannot_be_escaped_in_a_regular_expression */, start, this.pos - start, noArgs);
|
|
1784
|
+
return ch;
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
/** After a high surrogate escape: the low surrogate of a following `\u` escape, or -1. */
|
|
1788
|
+
scanLowSurrogateEscape() {
|
|
1789
|
+
if (this.char() !== 92 /* CharacterCodes.backslash */ || this.peek(1) !== 117 /* CharacterCodes.u */)
|
|
1790
|
+
return -1;
|
|
1791
|
+
const pos = this.pos;
|
|
1792
|
+
const flags = this.tokenFlags;
|
|
1793
|
+
// Errors are reported when the escape is scanned again on its own.
|
|
1794
|
+
const low = this.scanUnicodeEscape(false);
|
|
1795
|
+
if (low >= 0xdc00 && low <= 0xdfff)
|
|
1796
|
+
return low;
|
|
1797
|
+
this.pos = pos | 0;
|
|
1798
|
+
this.tokenFlags = flags;
|
|
1799
|
+
return -1;
|
|
1800
|
+
}
|
|
1801
|
+
/** Scans `\uXXXX` or `\u{X…}` at `pos`; returns the code point or -1 if invalid. */
|
|
1802
|
+
scanUnicodeEscape(shouldEmitInvalidEscapeError) {
|
|
1803
|
+
this.pos = (this.pos + 2) | 0;
|
|
1804
|
+
const start = this.pos;
|
|
1805
|
+
const extended = this.char() === 123 /* CharacterCodes.openBrace */;
|
|
1806
|
+
let value;
|
|
1807
|
+
if (extended) {
|
|
1808
|
+
this.pos = (this.pos + 1) | 0;
|
|
1809
|
+
value = this.scanHexValue(1, true);
|
|
1810
|
+
}
|
|
1811
|
+
else {
|
|
1812
|
+
this.tokenFlags |= 1024 /* TokenFlags.UnicodeEscape */;
|
|
1813
|
+
value = this.scanHexValue(4, false);
|
|
1814
|
+
}
|
|
1815
|
+
if (value < 0) {
|
|
1816
|
+
this.tokenFlags |= 2048 /* TokenFlags.ContainsInvalidEscape */;
|
|
1817
|
+
if (shouldEmitInvalidEscapeError)
|
|
1818
|
+
this.error(92 /* Diagnostics.Hexadecimal_digit_expected */);
|
|
1819
|
+
return -1;
|
|
1820
|
+
}
|
|
1821
|
+
if (extended) {
|
|
1822
|
+
let invalid = false;
|
|
1823
|
+
if (value > 0x10ffff) {
|
|
1824
|
+
if (shouldEmitInvalidEscapeError)
|
|
1825
|
+
this.errorAt(154 /* Diagnostics.An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive */, start + 1, this.pos - start - 1, noArgs);
|
|
1826
|
+
invalid = true;
|
|
1827
|
+
}
|
|
1828
|
+
if (this.pos >= this.end) {
|
|
1829
|
+
if (shouldEmitInvalidEscapeError)
|
|
1830
|
+
this.error(93 /* Diagnostics.Unexpected_end_of_text */);
|
|
1831
|
+
invalid = true;
|
|
1832
|
+
}
|
|
1833
|
+
else if (this.char() === 125 /* CharacterCodes.closeBrace */) {
|
|
1834
|
+
this.pos = (this.pos + 1) | 0;
|
|
1835
|
+
}
|
|
1836
|
+
else {
|
|
1837
|
+
if (shouldEmitInvalidEscapeError)
|
|
1838
|
+
this.error(155 /* Diagnostics.Unterminated_Unicode_escape_sequence */);
|
|
1839
|
+
invalid = true;
|
|
1840
|
+
}
|
|
1841
|
+
if (invalid) {
|
|
1842
|
+
this.tokenFlags |= 2048 /* TokenFlags.ContainsInvalidEscape */;
|
|
1843
|
+
return -1;
|
|
1844
|
+
}
|
|
1845
|
+
this.tokenFlags |= 8 /* TokenFlags.ExtendedUnicodeEscape */;
|
|
1846
|
+
}
|
|
1847
|
+
return value;
|
|
1848
|
+
}
|
|
1849
|
+
/** At `\`: the code point of a following `\u` escape, or -1. Leaves the scanner unchanged. */
|
|
1850
|
+
peekUnicodeEscape() {
|
|
1851
|
+
if (this.peek(1) !== 117 /* CharacterCodes.u */)
|
|
1852
|
+
return -1;
|
|
1853
|
+
const pos = this.pos;
|
|
1854
|
+
const flags = this.tokenFlags;
|
|
1855
|
+
const codePoint = this.scanUnicodeEscape(false);
|
|
1856
|
+
this.pos = pos | 0;
|
|
1857
|
+
this.tokenFlags = flags;
|
|
1858
|
+
return codePoint;
|
|
1859
|
+
}
|
|
1860
|
+
/** Scans hex digits (no separators) and returns their value, or -1 if fewer than `minCount`. */
|
|
1861
|
+
scanHexValue(minCount, scanAsManyAsPossible) {
|
|
1862
|
+
let count = 0;
|
|
1863
|
+
let value = 0;
|
|
1864
|
+
while (count < minCount || scanAsManyAsPossible) {
|
|
1865
|
+
const ch = this.char();
|
|
1866
|
+
let digit;
|
|
1867
|
+
if (ch >= 48 /* CharacterCodes._0 */ && ch <= 57 /* CharacterCodes._9 */)
|
|
1868
|
+
digit = ch - 48 /* CharacterCodes._0 */;
|
|
1869
|
+
else if (ch >= 65 /* CharacterCodes.A */ && ch <= 70 /* CharacterCodes.F */)
|
|
1870
|
+
digit = ch - 65 /* CharacterCodes.A */ + 10;
|
|
1871
|
+
else if (ch >= 97 /* CharacterCodes.a */ && ch <= 102 /* CharacterCodes.f */)
|
|
1872
|
+
digit = ch - 97 /* CharacterCodes.a */ + 10;
|
|
1873
|
+
else
|
|
1874
|
+
break;
|
|
1875
|
+
value = value * 16 + digit;
|
|
1876
|
+
count++;
|
|
1877
|
+
this.pos = (this.pos + 1) | 0;
|
|
1878
|
+
}
|
|
1879
|
+
return count < minCount ? -1 : value;
|
|
1880
|
+
}
|
|
1881
|
+
/** `text[start, end)` without numeric separators. */
|
|
1882
|
+
withoutSeparators(start, end) {
|
|
1883
|
+
if ((this.tokenFlags & 512 /* TokenFlags.ContainsSeparator */) === 0)
|
|
1884
|
+
return this.text.substring(start, end);
|
|
1885
|
+
let result = '';
|
|
1886
|
+
let from = start;
|
|
1887
|
+
for (let i = start; i < end; i++) {
|
|
1888
|
+
if (this.chars[i] !== 95 /* CharacterCodes._ */)
|
|
1889
|
+
continue;
|
|
1890
|
+
result += this.text.substring(from, i);
|
|
1891
|
+
from = i + 1;
|
|
1892
|
+
}
|
|
1893
|
+
return result + this.text.substring(from, end);
|
|
1894
|
+
}
|
|
1895
|
+
scanNumber() {
|
|
1896
|
+
let start = this.pos;
|
|
1897
|
+
if (this.char() === 48 /* CharacterCodes._0 */) {
|
|
1898
|
+
this.pos = (this.pos + 1) | 0;
|
|
1899
|
+
if (this.char() === 95 /* CharacterCodes._ */) {
|
|
1900
|
+
this.tokenFlags |= 512 /* TokenFlags.ContainsSeparator */ | 16384 /* TokenFlags.ContainsInvalidSeparator */;
|
|
1901
|
+
this.errorAt(1342 /* Diagnostics.Numeric_separators_are_not_allowed_here */, this.pos, 1, noArgs);
|
|
1902
|
+
this.pos = start | 0;
|
|
1903
|
+
this.scanNumberFragment();
|
|
1904
|
+
}
|
|
1905
|
+
else {
|
|
1906
|
+
const digitsStart = this.pos;
|
|
1907
|
+
let isOctal = true;
|
|
1908
|
+
while (isDigit(this.char())) {
|
|
1909
|
+
if (!isOctalDigit(this.char()))
|
|
1910
|
+
isOctal = false;
|
|
1911
|
+
this.pos = (this.pos + 1) | 0;
|
|
1912
|
+
}
|
|
1913
|
+
if (this.pos > digitsStart && isOctal) {
|
|
1914
|
+
// Legacy octal literal, e.g. `0777`.
|
|
1915
|
+
const value = parseInt(this.text.substring(digitsStart, this.pos), 8);
|
|
1916
|
+
this.setValue(String(value));
|
|
1917
|
+
this.tokenFlags |= 32 /* TokenFlags.Octal */;
|
|
1918
|
+
const withMinus = this.token === 40 /* SyntaxKind.MinusToken */;
|
|
1919
|
+
const literal = (withMinus ? '-0o' : '0o') + value.toString(8);
|
|
1920
|
+
if (withMinus)
|
|
1921
|
+
start--;
|
|
1922
|
+
this.errorAt(89 /* Diagnostics.Octal_literals_are_not_allowed_Use_the_syntax_0 */, start, this.pos - start, [literal]);
|
|
1923
|
+
return 8 /* SyntaxKind.NumericLiteral */;
|
|
1924
|
+
}
|
|
1925
|
+
if (this.pos > digitsStart)
|
|
1926
|
+
this.tokenFlags |= 8192 /* TokenFlags.ContainsLeadingZero */;
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
else {
|
|
1930
|
+
this.scanNumberFragment();
|
|
1931
|
+
}
|
|
1932
|
+
const fixedPartEnd = this.pos;
|
|
1933
|
+
if (this.char() === 46 /* CharacterCodes.dot */) {
|
|
1934
|
+
this.pos = (this.pos + 1) | 0;
|
|
1935
|
+
this.scanNumberFragment();
|
|
1936
|
+
}
|
|
1937
|
+
let end = this.pos;
|
|
1938
|
+
if (this.char() === 69 /* CharacterCodes.E */ || this.char() === 101 /* CharacterCodes.e */) {
|
|
1939
|
+
this.pos = (this.pos + 1) | 0;
|
|
1940
|
+
this.tokenFlags |= 16 /* TokenFlags.Scientific */;
|
|
1941
|
+
if (this.char() === 43 /* CharacterCodes.plus */ || this.char() === 45 /* CharacterCodes.minus */)
|
|
1942
|
+
this.pos = (this.pos + 1) | 0;
|
|
1943
|
+
if (this.scanNumberFragment() === 0)
|
|
1944
|
+
this.error(91 /* Diagnostics.Digit_expected */);
|
|
1945
|
+
else
|
|
1946
|
+
end = this.pos;
|
|
1947
|
+
}
|
|
1948
|
+
// Integers of up to 15 digits without separators are already canonical.
|
|
1949
|
+
if (fixedPartEnd === this.pos &&
|
|
1950
|
+
this.pos - start <= 15 &&
|
|
1951
|
+
(this.tokenFlags & (512 /* TokenFlags.ContainsSeparator */ | 8192 /* TokenFlags.ContainsLeadingZero */)) === 0 &&
|
|
1952
|
+
this.chars[this.pos] !== 110 /* CharacterCodes.n */) {
|
|
1953
|
+
this.setValueSlice(start, this.pos);
|
|
1954
|
+
if (!isIdentifierStart(this.codePoint()))
|
|
1955
|
+
return 8 /* SyntaxKind.NumericLiteral */;
|
|
1956
|
+
}
|
|
1957
|
+
const raw = this.withoutSeparators(start, end);
|
|
1958
|
+
if ((this.tokenFlags & 8192 /* TokenFlags.ContainsLeadingZero */) !== 0) {
|
|
1959
|
+
this.errorAt(404 /* Diagnostics.Decimals_with_leading_zeros_are_not_allowed */, start, this.pos - start, noArgs);
|
|
1960
|
+
this.setValue(String(Number(raw)));
|
|
1961
|
+
return 8 /* SyntaxKind.NumericLiteral */;
|
|
1962
|
+
}
|
|
1963
|
+
let result;
|
|
1964
|
+
if (fixedPartEnd === this.pos) {
|
|
1965
|
+
this.setValue(raw);
|
|
1966
|
+
result = this.scanBigIntSuffix();
|
|
1967
|
+
}
|
|
1968
|
+
else {
|
|
1969
|
+
this.setValue(String(Number(raw)));
|
|
1970
|
+
result = 8 /* SyntaxKind.NumericLiteral */;
|
|
1971
|
+
}
|
|
1972
|
+
if (isIdentifierStart(this.codePoint())) {
|
|
1973
|
+
const idStart = this.pos;
|
|
1974
|
+
const id = this.scanIdentifierParts();
|
|
1975
|
+
if (result !== 9 /* SyntaxKind.BigIntLiteral */ && id.length === 1 && this.chars[idStart] === 110 /* CharacterCodes.n */) {
|
|
1976
|
+
if ((this.tokenFlags & 16 /* TokenFlags.Scientific */) !== 0) {
|
|
1977
|
+
this.errorAt(286 /* Diagnostics.A_bigint_literal_cannot_use_exponential_notation */, start, this.pos - start, noArgs);
|
|
1978
|
+
return result;
|
|
1979
|
+
}
|
|
1980
|
+
if (fixedPartEnd < idStart) {
|
|
1981
|
+
this.errorAt(287 /* Diagnostics.A_bigint_literal_must_be_an_integer */, start, this.pos - start, noArgs);
|
|
1982
|
+
return result;
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
this.errorAt(285 /* Diagnostics.An_identifier_or_keyword_cannot_immediately_follow_a_numeric_literal */, idStart, this.pos - idStart, noArgs);
|
|
1986
|
+
this.pos = idStart | 0;
|
|
1987
|
+
}
|
|
1988
|
+
return result;
|
|
1989
|
+
}
|
|
1990
|
+
/** Scans decimal digits with numeric separators; returns how many digits. */
|
|
1991
|
+
scanNumberFragment() {
|
|
1992
|
+
let count = 0;
|
|
1993
|
+
let allowSeparator = false;
|
|
1994
|
+
let isPreviousTokenSeparator = false;
|
|
1995
|
+
for (;;) {
|
|
1996
|
+
const ch = this.char();
|
|
1997
|
+
if (isDigit(ch)) {
|
|
1998
|
+
allowSeparator = true;
|
|
1999
|
+
isPreviousTokenSeparator = false;
|
|
2000
|
+
count++;
|
|
2001
|
+
}
|
|
2002
|
+
else if (ch === 95 /* CharacterCodes._ */) {
|
|
2003
|
+
this.tokenFlags |= 512 /* TokenFlags.ContainsSeparator */;
|
|
2004
|
+
if (allowSeparator) {
|
|
2005
|
+
allowSeparator = false;
|
|
2006
|
+
isPreviousTokenSeparator = true;
|
|
2007
|
+
}
|
|
2008
|
+
else {
|
|
2009
|
+
this.tokenFlags |= 16384 /* TokenFlags.ContainsInvalidSeparator */;
|
|
2010
|
+
if (isPreviousTokenSeparator)
|
|
2011
|
+
this.errorAt(1343 /* Diagnostics.Multiple_consecutive_numeric_separators_are_not_permitted */, this.pos, 1, noArgs);
|
|
2012
|
+
else
|
|
2013
|
+
this.errorAt(1342 /* Diagnostics.Numeric_separators_are_not_allowed_here */, this.pos, 1, noArgs);
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
else {
|
|
2017
|
+
break;
|
|
2018
|
+
}
|
|
2019
|
+
this.pos = (this.pos + 1) | 0;
|
|
2020
|
+
}
|
|
2021
|
+
if (isPreviousTokenSeparator) {
|
|
2022
|
+
this.tokenFlags |= 16384 /* TokenFlags.ContainsInvalidSeparator */;
|
|
2023
|
+
this.errorAt(1342 /* Diagnostics.Numeric_separators_are_not_allowed_here */, this.pos - 1, 1, noArgs);
|
|
2024
|
+
}
|
|
2025
|
+
return count;
|
|
2026
|
+
}
|
|
2027
|
+
/** Scans digits of a `0x`, `0b` or `0o` literal (allowing separators); returns how many. */
|
|
2028
|
+
scanSpecifierDigits(base) {
|
|
2029
|
+
let count = 0;
|
|
2030
|
+
let allowSeparator = false;
|
|
2031
|
+
let isPreviousTokenSeparator = false;
|
|
2032
|
+
for (;;) {
|
|
2033
|
+
const ch = this.char();
|
|
2034
|
+
if (base === 16 ? isHexDigit(ch) : isDigit(ch) && ch - 48 /* CharacterCodes._0 */ < base) {
|
|
2035
|
+
allowSeparator = true;
|
|
2036
|
+
isPreviousTokenSeparator = false;
|
|
2037
|
+
count++;
|
|
2038
|
+
}
|
|
2039
|
+
else if (ch === 95 /* CharacterCodes._ */) {
|
|
2040
|
+
this.tokenFlags |= 512 /* TokenFlags.ContainsSeparator */;
|
|
2041
|
+
if (allowSeparator) {
|
|
2042
|
+
allowSeparator = false;
|
|
2043
|
+
isPreviousTokenSeparator = true;
|
|
2044
|
+
}
|
|
2045
|
+
else if (isPreviousTokenSeparator) {
|
|
2046
|
+
this.errorAt(1343 /* Diagnostics.Multiple_consecutive_numeric_separators_are_not_permitted */, this.pos, 1, noArgs);
|
|
2047
|
+
}
|
|
2048
|
+
else {
|
|
2049
|
+
this.errorAt(1342 /* Diagnostics.Numeric_separators_are_not_allowed_here */, this.pos, 1, noArgs);
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
2052
|
+
else {
|
|
2053
|
+
break;
|
|
2054
|
+
}
|
|
2055
|
+
this.pos = (this.pos + 1) | 0;
|
|
2056
|
+
}
|
|
2057
|
+
if (isPreviousTokenSeparator)
|
|
2058
|
+
this.errorAt(1342 /* Diagnostics.Numeric_separators_are_not_allowed_here */, this.pos - 1, 1, noArgs);
|
|
2059
|
+
return count;
|
|
2060
|
+
}
|
|
2061
|
+
scanHexNumber() {
|
|
2062
|
+
this.pos = (this.pos + 2) | 0;
|
|
2063
|
+
const digitsStart = this.pos;
|
|
2064
|
+
let digits;
|
|
2065
|
+
if (this.scanSpecifierDigits(16) === 0) {
|
|
2066
|
+
this.error(92 /* Diagnostics.Hexadecimal_digit_expected */);
|
|
2067
|
+
digits = '0';
|
|
2068
|
+
}
|
|
2069
|
+
else {
|
|
2070
|
+
digits = this.withoutSeparators(digitsStart, this.pos).toLowerCase();
|
|
2071
|
+
}
|
|
2072
|
+
this.setValue('0x' + digits);
|
|
2073
|
+
this.tokenFlags |= 64 /* TokenFlags.HexSpecifier */;
|
|
2074
|
+
return this.scanBigIntSuffix();
|
|
2075
|
+
}
|
|
2076
|
+
scanBinaryOrOctalNumber(base) {
|
|
2077
|
+
this.pos = (this.pos + 2) | 0;
|
|
2078
|
+
const digitsStart = this.pos;
|
|
2079
|
+
let digits;
|
|
2080
|
+
if (this.scanSpecifierDigits(base) === 0) {
|
|
2081
|
+
this.error(base === 2 ? 133 /* Diagnostics.Binary_digit_expected */ : 134 /* Diagnostics.Octal_digit_expected */);
|
|
2082
|
+
digits = '0';
|
|
2083
|
+
}
|
|
2084
|
+
else {
|
|
2085
|
+
digits = this.withoutSeparators(digitsStart, this.pos);
|
|
2086
|
+
}
|
|
2087
|
+
this.setValue((base === 2 ? '0b' : '0o') + digits);
|
|
2088
|
+
this.tokenFlags |= base === 2 ? 128 /* TokenFlags.BinarySpecifier */ : 256 /* TokenFlags.OctalSpecifier */;
|
|
2089
|
+
return this.scanBigIntSuffix();
|
|
2090
|
+
}
|
|
2091
|
+
/** Completes a numeric literal whose value is set: a `n` suffix makes it a bigint. */
|
|
2092
|
+
scanBigIntSuffix() {
|
|
2093
|
+
if (this.char() === 110 /* CharacterCodes.n */) {
|
|
2094
|
+
if ((this.tokenFlags & 384 /* TokenFlags.BinaryOrOctalSpecifier */) !== 0)
|
|
2095
|
+
this.setValue(parsePseudoBigInt(this.tokenValue) + 'n');
|
|
2096
|
+
else
|
|
2097
|
+
this.setValue(this.tokenValue + 'n');
|
|
2098
|
+
this.pos = (this.pos + 1) | 0;
|
|
2099
|
+
return 9 /* SyntaxKind.BigIntLiteral */;
|
|
2100
|
+
}
|
|
2101
|
+
this.setValue(String(Number(this.tokenValue)));
|
|
2102
|
+
return 8 /* SyntaxKind.NumericLiteral */;
|
|
2103
|
+
}
|
|
2104
|
+
/** Splits `<<` into `<`. */
|
|
2105
|
+
reScanLessThanToken() {
|
|
2106
|
+
if (this.token === 47 /* SyntaxKind.LessThanLessThanToken */) {
|
|
2107
|
+
this.pos = (this.tokenStart + 1) | 0;
|
|
2108
|
+
this.token = 29 /* SyntaxKind.LessThanToken */;
|
|
2109
|
+
}
|
|
2110
|
+
return this.token;
|
|
2111
|
+
}
|
|
2112
|
+
/** Joins `>` with following `>`, `>=`, `>>`, `>>=` or `=`. */
|
|
2113
|
+
reScanGreaterThanToken() {
|
|
2114
|
+
if (this.token !== 31 /* SyntaxKind.GreaterThanToken */)
|
|
2115
|
+
return this.token;
|
|
2116
|
+
this.pos = (this.tokenStart + 1) | 0;
|
|
2117
|
+
if (this.char() === 62 /* CharacterCodes.greaterThan */) {
|
|
2118
|
+
if (this.peek(1) === 62 /* CharacterCodes.greaterThan */) {
|
|
2119
|
+
if (this.peek(2) === 61 /* CharacterCodes.equals */) {
|
|
2120
|
+
this.pos = (this.pos + 3) | 0;
|
|
2121
|
+
return (this.token = 72 /* SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken */);
|
|
2122
|
+
}
|
|
2123
|
+
this.pos = (this.pos + 2) | 0;
|
|
2124
|
+
return (this.token = 49 /* SyntaxKind.GreaterThanGreaterThanGreaterThanToken */);
|
|
2125
|
+
}
|
|
2126
|
+
if (this.peek(1) === 61 /* CharacterCodes.equals */) {
|
|
2127
|
+
this.pos = (this.pos + 2) | 0;
|
|
2128
|
+
return (this.token = 71 /* SyntaxKind.GreaterThanGreaterThanEqualsToken */);
|
|
2129
|
+
}
|
|
2130
|
+
this.pos = (this.pos + 1) | 0;
|
|
2131
|
+
return (this.token = 48 /* SyntaxKind.GreaterThanGreaterThanToken */);
|
|
2132
|
+
}
|
|
2133
|
+
if (this.char() === 61 /* CharacterCodes.equals */) {
|
|
2134
|
+
this.pos = (this.pos + 1) | 0;
|
|
2135
|
+
return (this.token = 33 /* SyntaxKind.GreaterThanEqualsToken */);
|
|
2136
|
+
}
|
|
2137
|
+
return this.token;
|
|
2138
|
+
}
|
|
2139
|
+
/** Rescans a `}` as a template middle or tail. */
|
|
2140
|
+
reScanTemplateToken(isTaggedTemplate) {
|
|
2141
|
+
this.pos = this.tokenStart;
|
|
2142
|
+
return (this.token = this.scanTemplateAndSetTokenValue(!isTaggedTemplate));
|
|
2143
|
+
}
|
|
2144
|
+
/** Splits `*=` into `*` and `=`, returning `=`. */
|
|
2145
|
+
reScanAsteriskEqualsToken() {
|
|
2146
|
+
if (this.token !== 66 /* SyntaxKind.AsteriskEqualsToken */)
|
|
2147
|
+
throw new Error("'reScanAsteriskEqualsToken' should only be called on a '*='");
|
|
2148
|
+
this.pos = (this.tokenStart + 1) | 0;
|
|
2149
|
+
return (this.token = 63 /* SyntaxKind.EqualsToken */);
|
|
2150
|
+
}
|
|
2151
|
+
/** Rescans `/` or `/=` as a regular expression literal, optionally checking its syntax. */
|
|
2152
|
+
reScanSlashToken(reportErrors = false) {
|
|
2153
|
+
if (this.token !== 43 /* SyntaxKind.SlashToken */ && this.token !== 68 /* SyntaxKind.SlashEqualsToken */)
|
|
2154
|
+
return this.token;
|
|
2155
|
+
const chars = this.chars;
|
|
2156
|
+
// Find the end of the body quickly so the flags are known before checking it.
|
|
2157
|
+
const bodyStart = this.tokenStart + 1;
|
|
2158
|
+
let p = bodyStart;
|
|
2159
|
+
let inEscape = false;
|
|
2160
|
+
let namedCaptureGroups = false;
|
|
2161
|
+
// A `[` inside a class does not nest here, even in Unicode Sets mode: `/[[]/` is terminated.
|
|
2162
|
+
let inCharacterClass = false;
|
|
2163
|
+
for (;;) {
|
|
2164
|
+
if (p >= this.end) {
|
|
2165
|
+
this.tokenFlags |= 4 /* TokenFlags.Unterminated */;
|
|
2166
|
+
break;
|
|
2167
|
+
}
|
|
2168
|
+
const ch = chars[p];
|
|
2169
|
+
if (isLineBreak(ch)) {
|
|
2170
|
+
this.tokenFlags |= 4 /* TokenFlags.Unterminated */;
|
|
2171
|
+
break;
|
|
2172
|
+
}
|
|
2173
|
+
if (inEscape) {
|
|
2174
|
+
inEscape = false;
|
|
2175
|
+
}
|
|
2176
|
+
else if (ch === 47 /* CharacterCodes.slash */ && !inCharacterClass) {
|
|
2177
|
+
break;
|
|
2178
|
+
}
|
|
2179
|
+
else if (ch === 91 /* CharacterCodes.openBracket */) {
|
|
2180
|
+
inCharacterClass = true;
|
|
2181
|
+
}
|
|
2182
|
+
else if (ch === 92 /* CharacterCodes.backslash */) {
|
|
2183
|
+
inEscape = true;
|
|
2184
|
+
}
|
|
2185
|
+
else if (ch === 93 /* CharacterCodes.closeBracket */) {
|
|
2186
|
+
inCharacterClass = false;
|
|
2187
|
+
}
|
|
2188
|
+
else if (!inCharacterClass &&
|
|
2189
|
+
ch === 40 /* CharacterCodes.openParen */ &&
|
|
2190
|
+
p + 2 < this.end &&
|
|
2191
|
+
chars[p + 1] === 63 /* CharacterCodes.question */ &&
|
|
2192
|
+
chars[p + 2] === 60 /* CharacterCodes.lessThan */ &&
|
|
2193
|
+
(p + 3 >= this.end || (chars[p + 3] !== 61 /* CharacterCodes.equals */ && chars[p + 3] !== 33 /* CharacterCodes.exclamation */))) {
|
|
2194
|
+
namedCaptureGroups = true;
|
|
2195
|
+
}
|
|
2196
|
+
p++;
|
|
2197
|
+
}
|
|
2198
|
+
const bodyEnd = p;
|
|
2199
|
+
if ((this.tokenFlags & 4 /* TokenFlags.Unterminated */) !== 0) {
|
|
2200
|
+
// Recover at the nearest unbalanced bracket, counting nested classes.
|
|
2201
|
+
p = bodyStart;
|
|
2202
|
+
inEscape = false;
|
|
2203
|
+
let classDepth = 0;
|
|
2204
|
+
let inDecimalQuantifier = false;
|
|
2205
|
+
let groupDepth = 0;
|
|
2206
|
+
while (p < bodyEnd) {
|
|
2207
|
+
const ch = chars[p];
|
|
2208
|
+
if (inEscape) {
|
|
2209
|
+
inEscape = false;
|
|
2210
|
+
}
|
|
2211
|
+
else if (ch === 92 /* CharacterCodes.backslash */) {
|
|
2212
|
+
inEscape = true;
|
|
2213
|
+
}
|
|
2214
|
+
else if (ch === 91 /* CharacterCodes.openBracket */) {
|
|
2215
|
+
classDepth++;
|
|
2216
|
+
}
|
|
2217
|
+
else if (ch === 93 /* CharacterCodes.closeBracket */ && classDepth !== 0) {
|
|
2218
|
+
classDepth--;
|
|
2219
|
+
}
|
|
2220
|
+
else if (classDepth === 0) {
|
|
2221
|
+
if (ch === 123 /* CharacterCodes.openBrace */) {
|
|
2222
|
+
inDecimalQuantifier = true;
|
|
2223
|
+
}
|
|
2224
|
+
else if (ch === 125 /* CharacterCodes.closeBrace */ && inDecimalQuantifier) {
|
|
2225
|
+
inDecimalQuantifier = false;
|
|
2226
|
+
}
|
|
2227
|
+
else if (!inDecimalQuantifier) {
|
|
2228
|
+
if (ch === 40 /* CharacterCodes.openParen */)
|
|
2229
|
+
groupDepth++;
|
|
2230
|
+
else if (ch === 41 /* CharacterCodes.closeParen */ && groupDepth !== 0)
|
|
2231
|
+
groupDepth--;
|
|
2232
|
+
else if (ch === 41 /* CharacterCodes.closeParen */ ||
|
|
2233
|
+
ch === 93 /* CharacterCodes.closeBracket */ ||
|
|
2234
|
+
ch === 125 /* CharacterCodes.closeBrace */)
|
|
2235
|
+
break;
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
p++;
|
|
2239
|
+
}
|
|
2240
|
+
// Trailing whitespace and semicolons are unlikely to belong to the regex.
|
|
2241
|
+
while (p > bodyStart) {
|
|
2242
|
+
const ch = chars[p - 1];
|
|
2243
|
+
if (!isWhiteSpaceLike(ch) && ch !== 59 /* CharacterCodes.semicolon */)
|
|
2244
|
+
break;
|
|
2245
|
+
p--;
|
|
2246
|
+
}
|
|
2247
|
+
this.errorAt(118 /* Diagnostics.Unterminated_regular_expression_literal */, this.tokenStart, p - this.tokenStart, noArgs);
|
|
2248
|
+
}
|
|
2249
|
+
else {
|
|
2250
|
+
p++; // the closing slash
|
|
2251
|
+
let flags = 0 /* RegularExpressionFlags.None */;
|
|
2252
|
+
while (p < this.end) {
|
|
2253
|
+
const ch = this.codePointAt(p, this.end);
|
|
2254
|
+
if (ch === 65533 /* CharacterCodes.replacementCharacter */ || !isIdentifierPart(ch))
|
|
2255
|
+
break;
|
|
2256
|
+
const size = charSize(ch);
|
|
2257
|
+
if (reportErrors) {
|
|
2258
|
+
const flag = regularExpressionFlag(ch);
|
|
2259
|
+
if (flag === 0 /* RegularExpressionFlags.None */)
|
|
2260
|
+
this.errorAt(414 /* Diagnostics.Unknown_regular_expression_flag */, p, size, noArgs);
|
|
2261
|
+
else if ((flags & flag) !== 0)
|
|
2262
|
+
this.errorAt(415 /* Diagnostics.Duplicate_regular_expression_flag */, p, size, noArgs);
|
|
2263
|
+
else if (((flags | flag) & 96 /* RegularExpressionFlags.AnyUnicodeMode */) === 96 /* RegularExpressionFlags.AnyUnicodeMode */)
|
|
2264
|
+
this.errorAt(417 /* Diagnostics.The_Unicode_u_flag_and_the_Unicode_Sets_v_flag_cannot_be_set_simultaneously */, p, size, noArgs);
|
|
2265
|
+
else {
|
|
2266
|
+
flags |= flag;
|
|
2267
|
+
this.checkRegularExpressionFlagAvailability(flag, p, size);
|
|
2268
|
+
}
|
|
2269
|
+
}
|
|
2270
|
+
p += size;
|
|
2271
|
+
}
|
|
2272
|
+
if (reportErrors) {
|
|
2273
|
+
const savedEnd = this.end;
|
|
2274
|
+
const savedTokenStart = this.tokenStart;
|
|
2275
|
+
const savedTokenFlags = this.tokenFlags;
|
|
2276
|
+
this.pos = bodyStart | 0;
|
|
2277
|
+
this.end = bodyEnd | 0;
|
|
2278
|
+
checkRegularExpression(this, bodyEnd, flags, namedCaptureGroups);
|
|
2279
|
+
this.end = savedEnd;
|
|
2280
|
+
this.tokenStart = savedTokenStart;
|
|
2281
|
+
this.tokenFlags = savedTokenFlags;
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
this.pos = p | 0;
|
|
2285
|
+
this.setValueSlice(this.tokenStart, p);
|
|
2286
|
+
return (this.token = 13 /* SyntaxKind.RegularExpressionLiteral */);
|
|
2287
|
+
}
|
|
2288
|
+
/** @internal Reports a regular expression flag unavailable at the current target. */
|
|
2289
|
+
checkRegularExpressionFlagAvailability(flag, pos, size) {
|
|
2290
|
+
let availableFrom;
|
|
2291
|
+
if (flag === 1 /* RegularExpressionFlags.HasIndices */)
|
|
2292
|
+
availableFrom = 9 /* ScriptTarget.ES2022 */;
|
|
2293
|
+
else if (flag === 16 /* RegularExpressionFlags.DotAll */)
|
|
2294
|
+
availableFrom = 5 /* ScriptTarget.ES2018 */;
|
|
2295
|
+
else if (flag === 64 /* RegularExpressionFlags.UnicodeSets */)
|
|
2296
|
+
availableFrom = 11 /* ScriptTarget.ES2024 */;
|
|
2297
|
+
else
|
|
2298
|
+
return;
|
|
2299
|
+
if (this.languageVersion() < availableFrom)
|
|
2300
|
+
this.errorAt(416 /* Diagnostics.This_regular_expression_flag_is_only_available_when_targeting_0_or_later */, pos, size, [
|
|
2301
|
+
regularExpressionFlagName(availableFrom),
|
|
2302
|
+
]);
|
|
2303
|
+
}
|
|
2304
|
+
/** Rescans from the token's full start as JSX text or a JSX token. */
|
|
2305
|
+
reScanJsxToken(allowMultilineJsxText = true) {
|
|
2306
|
+
this.pos = this.fullStartPos;
|
|
2307
|
+
this.tokenStart = this.fullStartPos;
|
|
2308
|
+
return (this.token = this.scanJsxToken(allowMultilineJsxText));
|
|
2309
|
+
}
|
|
2310
|
+
/** Splits a private identifier into `#` and the name. */
|
|
2311
|
+
reScanHashToken() {
|
|
2312
|
+
if (this.token === 80 /* SyntaxKind.PrivateIdentifier */) {
|
|
2313
|
+
this.pos = (this.tokenStart + 1) | 0;
|
|
2314
|
+
this.token = 62 /* SyntaxKind.HashToken */;
|
|
2315
|
+
}
|
|
2316
|
+
return this.token;
|
|
2317
|
+
}
|
|
2318
|
+
/** Splits `??` into `?`. */
|
|
2319
|
+
reScanQuestionToken() {
|
|
2320
|
+
if (this.token !== 60 /* SyntaxKind.QuestionQuestionToken */)
|
|
2321
|
+
throw new Error("'reScanQuestionToken' should only be called on a '??'");
|
|
2322
|
+
this.pos = (this.tokenStart + 1) | 0;
|
|
2323
|
+
return (this.token = 57 /* SyntaxKind.QuestionToken */);
|
|
2324
|
+
}
|
|
2325
|
+
/** Scans JSX children: text, `<`, `</` or `{`. */
|
|
2326
|
+
scanJsxToken(allowMultilineJsxText = true) {
|
|
2327
|
+
this.fullStartPos = this.pos | 0;
|
|
2328
|
+
this.tokenStart = this.pos | 0;
|
|
2329
|
+
const ch = this.char();
|
|
2330
|
+
if (ch < 0)
|
|
2331
|
+
return (this.token = 1 /* SyntaxKind.EndOfFile */);
|
|
2332
|
+
if (ch === 60 /* CharacterCodes.lessThan */) {
|
|
2333
|
+
if (this.peek(1) === 47 /* CharacterCodes.slash */) {
|
|
2334
|
+
this.pos = (this.pos + 2) | 0;
|
|
2335
|
+
return (this.token = 30 /* SyntaxKind.LessThanSlashToken */);
|
|
2336
|
+
}
|
|
2337
|
+
this.pos = (this.pos + 1) | 0;
|
|
2338
|
+
return (this.token = 29 /* SyntaxKind.LessThanToken */);
|
|
2339
|
+
}
|
|
2340
|
+
if (ch === 123 /* CharacterCodes.openBrace */) {
|
|
2341
|
+
this.pos = (this.pos + 1) | 0;
|
|
2342
|
+
return (this.token = 18 /* SyntaxKind.OpenBraceToken */);
|
|
2343
|
+
}
|
|
2344
|
+
// 0: only whitespace so far; -1: only whitespace and a line break, which is ignored.
|
|
2345
|
+
let firstNonWhitespace = 0;
|
|
2346
|
+
while (this.pos < this.end) {
|
|
2347
|
+
const c = this.chars[this.pos] | 0;
|
|
2348
|
+
if (c === 123 /* CharacterCodes.openBrace */)
|
|
2349
|
+
break;
|
|
2350
|
+
if (c === 60 /* CharacterCodes.lessThan */) {
|
|
2351
|
+
if (isConflictMarkerTrivia(this.text, this.pos)) {
|
|
2352
|
+
this.pos = scanConflictMarkerTrivia(this.text, this.pos, this) | 0;
|
|
2353
|
+
return (this.token = 6 /* SyntaxKind.ConflictMarkerTrivia */);
|
|
2354
|
+
}
|
|
2355
|
+
break;
|
|
2356
|
+
}
|
|
2357
|
+
if (c === 62 /* CharacterCodes.greaterThan */)
|
|
2358
|
+
this.errorAt(311 /* Diagnostics.Unexpected_token_Did_you_mean_or_gt */, this.pos, 1, noArgs);
|
|
2359
|
+
else if (c === 125 /* CharacterCodes.closeBrace */)
|
|
2360
|
+
this.errorAt(310 /* Diagnostics.Unexpected_token_Did_you_mean_or_rbrace */, this.pos, 1, noArgs);
|
|
2361
|
+
if (isLineBreak(c) && firstNonWhitespace === 0)
|
|
2362
|
+
firstNonWhitespace = -1;
|
|
2363
|
+
else if (!allowMultilineJsxText && isLineBreak(c) && firstNonWhitespace > 0)
|
|
2364
|
+
break;
|
|
2365
|
+
else if (!isWhiteSpaceLike(c))
|
|
2366
|
+
firstNonWhitespace = this.pos;
|
|
2367
|
+
this.pos = (this.pos + 1) | 0;
|
|
2368
|
+
}
|
|
2369
|
+
this.setValueSlice(this.fullStartPos, this.pos);
|
|
2370
|
+
return (this.token = firstNonWhitespace === -1 ? 12 /* SyntaxKind.JsxTextAllWhiteSpaces */ : 11 /* SyntaxKind.JsxText */);
|
|
2371
|
+
}
|
|
2372
|
+
/** Extends an identifier or keyword with `-` and further parts, as JSX names allow. */
|
|
2373
|
+
scanJsxIdentifier() {
|
|
2374
|
+
if (!tokenIsIdentifierOrKeyword(this.token))
|
|
2375
|
+
return this.token;
|
|
2376
|
+
let value = this.getTokenValue();
|
|
2377
|
+
while (this.pos < this.end) {
|
|
2378
|
+
if (this.char() === 45 /* CharacterCodes.minus */) {
|
|
2379
|
+
value += '-';
|
|
2380
|
+
this.pos = (this.pos + 1) | 0;
|
|
2381
|
+
continue;
|
|
2382
|
+
}
|
|
2383
|
+
const pos = this.pos;
|
|
2384
|
+
value += this.scanIdentifierParts();
|
|
2385
|
+
if (this.pos === pos)
|
|
2386
|
+
break;
|
|
2387
|
+
}
|
|
2388
|
+
this.setValue(value);
|
|
2389
|
+
return (this.token = getIdentifierToken(value));
|
|
2390
|
+
}
|
|
2391
|
+
/** Scans a JSX attribute value after `=`: a string, or any other token. */
|
|
2392
|
+
scanJsxAttributeValue() {
|
|
2393
|
+
this.fullStartPos = this.pos | 0;
|
|
2394
|
+
while (this.pos < this.end && isWhiteSpaceLike(this.chars[this.pos] | 0))
|
|
2395
|
+
this.pos = (this.pos + 1) | 0;
|
|
2396
|
+
this.tokenStart = this.pos | 0;
|
|
2397
|
+
const ch = this.char();
|
|
2398
|
+
if (ch === 34 /* CharacterCodes.doubleQuote */ || ch === 39 /* CharacterCodes.singleQuote */) {
|
|
2399
|
+
this.scanString(true);
|
|
2400
|
+
return (this.token = 10 /* SyntaxKind.StringLiteral */);
|
|
2401
|
+
}
|
|
2402
|
+
return this.scan();
|
|
2403
|
+
}
|
|
2404
|
+
reScanJsxAttributeValue() {
|
|
2405
|
+
this.pos = this.fullStartPos;
|
|
2406
|
+
this.tokenStart = this.fullStartPos;
|
|
2407
|
+
return this.scanJsxAttributeValue();
|
|
2408
|
+
}
|
|
2409
|
+
/** Scans JSDoc comment text up to a line break, backtick, `{` or tag; falls back to `scanJSDocToken`. */
|
|
2410
|
+
scanJSDocCommentTextToken(inBackticks) {
|
|
2411
|
+
this.fullStartPos = this.pos | 0;
|
|
2412
|
+
this.tokenFlags = 0 /* TokenFlags.None */;
|
|
2413
|
+
if (this.pos >= this.end)
|
|
2414
|
+
return (this.token = 1 /* SyntaxKind.EndOfFile */);
|
|
2415
|
+
this.tokenStart = this.pos | 0;
|
|
2416
|
+
while (this.pos < this.end) {
|
|
2417
|
+
// Fast path: an ASCII unit that ends no text run.
|
|
2418
|
+
const unit = this.chars[this.pos] | 0;
|
|
2419
|
+
if (unit < 0x80 &&
|
|
2420
|
+
unit !== 10 /* CharacterCodes.lineFeed */ &&
|
|
2421
|
+
unit !== 13 /* CharacterCodes.carriageReturn */ &&
|
|
2422
|
+
unit !== 96 /* CharacterCodes.backtick */ &&
|
|
2423
|
+
unit !== 123 /* CharacterCodes.openBrace */ &&
|
|
2424
|
+
unit !== 64 /* CharacterCodes.at */) {
|
|
2425
|
+
this.pos = (this.pos + 1) | 0;
|
|
2426
|
+
continue;
|
|
2427
|
+
}
|
|
2428
|
+
const ch = this.codePointAt(this.pos, this.end);
|
|
2429
|
+
if (isLineBreak(ch) || ch === 96 /* CharacterCodes.backtick */)
|
|
2430
|
+
break;
|
|
2431
|
+
const size = charSize(ch);
|
|
2432
|
+
if (!inBackticks) {
|
|
2433
|
+
if (ch === 123 /* CharacterCodes.openBrace */)
|
|
2434
|
+
break;
|
|
2435
|
+
// Outside backticks, `@` starts a tag after whitespace and before an identifier.
|
|
2436
|
+
if (ch === 64 /* CharacterCodes.at */ &&
|
|
2437
|
+
isWhiteSpaceSingleLine(this.codePointBefore(this.pos)) &&
|
|
2438
|
+
isIdentifierStart(this.codePointAt((this.pos + size) | 0, this.end)))
|
|
2439
|
+
break;
|
|
2440
|
+
}
|
|
2441
|
+
this.pos = (this.pos + size) | 0;
|
|
2442
|
+
}
|
|
2443
|
+
if (this.pos === this.tokenStart)
|
|
2444
|
+
return this.scanJSDocToken();
|
|
2445
|
+
this.setValueSlice(this.tokenStart, this.pos);
|
|
2446
|
+
return (this.token = 81 /* SyntaxKind.JSDocCommentTextToken */);
|
|
2447
|
+
}
|
|
2448
|
+
/** After `@`: whether a tag name (or an incomplete tag) can follow. */
|
|
2449
|
+
canFollowJSDocAt() {
|
|
2450
|
+
if (this.pos >= this.end)
|
|
2451
|
+
return true;
|
|
2452
|
+
const ch = this.codePointAt(this.pos, this.end);
|
|
2453
|
+
return isIdentifierStart(ch) || isWhiteSpaceSingleLine(ch) || isLineBreak(ch);
|
|
2454
|
+
}
|
|
2455
|
+
scanJSDocToken() {
|
|
2456
|
+
this.fullStartPos = this.pos | 0;
|
|
2457
|
+
this.tokenFlags = 0 /* TokenFlags.None */;
|
|
2458
|
+
const text = this.text;
|
|
2459
|
+
const chars = this.chars;
|
|
2460
|
+
if (this.pos >= this.end)
|
|
2461
|
+
return (this.token = 1 /* SyntaxKind.EndOfFile */);
|
|
2462
|
+
this.tokenStart = this.pos | 0;
|
|
2463
|
+
const ch = this.codePointAt(this.pos, this.end);
|
|
2464
|
+
this.pos = (this.pos + charSize(ch)) | 0;
|
|
2465
|
+
switch (ch) {
|
|
2466
|
+
case 9 /* CharacterCodes.tab */:
|
|
2467
|
+
case 11 /* CharacterCodes.verticalTab */:
|
|
2468
|
+
case 12 /* CharacterCodes.formFeed */:
|
|
2469
|
+
case 32 /* CharacterCodes.space */:
|
|
2470
|
+
while (this.pos < this.end && isWhiteSpaceSingleLine(chars[this.pos] | 0))
|
|
2471
|
+
this.pos = (this.pos + 1) | 0;
|
|
2472
|
+
return (this.token = 5 /* SyntaxKind.WhitespaceTrivia */);
|
|
2473
|
+
case 64 /* CharacterCodes.at */:
|
|
2474
|
+
return (this.token = 59 /* SyntaxKind.AtToken */);
|
|
2475
|
+
case 13 /* CharacterCodes.carriageReturn */:
|
|
2476
|
+
case 10 /* CharacterCodes.lineFeed */:
|
|
2477
|
+
if (ch === 13 /* CharacterCodes.carriageReturn */ && this.char() === 10 /* CharacterCodes.lineFeed */)
|
|
2478
|
+
this.pos = (this.pos + 1) | 0;
|
|
2479
|
+
this.tokenFlags |= 1 /* TokenFlags.PrecedingLineBreak */;
|
|
2480
|
+
return (this.token = 4 /* SyntaxKind.NewLineTrivia */);
|
|
2481
|
+
case 42 /* CharacterCodes.asterisk */:
|
|
2482
|
+
return (this.token = 41 /* SyntaxKind.AsteriskToken */);
|
|
2483
|
+
case 123 /* CharacterCodes.openBrace */:
|
|
2484
|
+
return (this.token = 18 /* SyntaxKind.OpenBraceToken */);
|
|
2485
|
+
case 125 /* CharacterCodes.closeBrace */:
|
|
2486
|
+
return (this.token = 19 /* SyntaxKind.CloseBraceToken */);
|
|
2487
|
+
case 91 /* CharacterCodes.openBracket */:
|
|
2488
|
+
return (this.token = 22 /* SyntaxKind.OpenBracketToken */);
|
|
2489
|
+
case 93 /* CharacterCodes.closeBracket */:
|
|
2490
|
+
return (this.token = 23 /* SyntaxKind.CloseBracketToken */);
|
|
2491
|
+
case 40 /* CharacterCodes.openParen */:
|
|
2492
|
+
return (this.token = 20 /* SyntaxKind.OpenParenToken */);
|
|
2493
|
+
case 41 /* CharacterCodes.closeParen */:
|
|
2494
|
+
return (this.token = 21 /* SyntaxKind.CloseParenToken */);
|
|
2495
|
+
case 60 /* CharacterCodes.lessThan */:
|
|
2496
|
+
return (this.token = 29 /* SyntaxKind.LessThanToken */);
|
|
2497
|
+
case 62 /* CharacterCodes.greaterThan */:
|
|
2498
|
+
return (this.token = 31 /* SyntaxKind.GreaterThanToken */);
|
|
2499
|
+
case 61 /* CharacterCodes.equals */:
|
|
2500
|
+
return (this.token = 63 /* SyntaxKind.EqualsToken */);
|
|
2501
|
+
case 44 /* CharacterCodes.comma */:
|
|
2502
|
+
return (this.token = 27 /* SyntaxKind.CommaToken */);
|
|
2503
|
+
case 46 /* CharacterCodes.dot */:
|
|
2504
|
+
return (this.token = 24 /* SyntaxKind.DotToken */);
|
|
2505
|
+
case 96 /* CharacterCodes.backtick */:
|
|
2506
|
+
return (this.token = 61 /* SyntaxKind.BacktickToken */);
|
|
2507
|
+
case 35 /* CharacterCodes.hash */:
|
|
2508
|
+
return (this.token = 62 /* SyntaxKind.HashToken */);
|
|
2509
|
+
case 92 /* CharacterCodes.backslash */: {
|
|
2510
|
+
this.pos = (this.pos - 1) | 0;
|
|
2511
|
+
const codePoint = this.peekUnicodeEscape();
|
|
2512
|
+
if (codePoint >= 0 && isIdentifierStart(codePoint)) {
|
|
2513
|
+
const head = String.fromCodePoint(this.scanUnicodeEscape(true));
|
|
2514
|
+
this.setValue(head + this.scanIdentifierParts());
|
|
2515
|
+
return (this.token = getIdentifierToken(this.tokenValue));
|
|
2516
|
+
}
|
|
2517
|
+
this.pos = (this.pos + 1) | 0;
|
|
2518
|
+
return (this.token = 0 /* SyntaxKind.Unknown */);
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
if (!isIdentifierStart(ch))
|
|
2522
|
+
return (this.token = 0 /* SyntaxKind.Unknown */);
|
|
2523
|
+
let last = ch;
|
|
2524
|
+
while (this.pos < this.end) {
|
|
2525
|
+
const unit = this.chars[this.pos] | 0;
|
|
2526
|
+
if (unit < 0x80) {
|
|
2527
|
+
last = unit;
|
|
2528
|
+
if (!isASCIIIdentifierPart(unit) && unit !== 45 /* CharacterCodes.minus */)
|
|
2529
|
+
break;
|
|
2530
|
+
this.pos = (this.pos + 1) | 0;
|
|
2531
|
+
continue;
|
|
2532
|
+
}
|
|
2533
|
+
last = this.codePointAt(this.pos, this.end);
|
|
2534
|
+
if (!isIdentifierPart(last) && last !== 45 /* CharacterCodes.minus */)
|
|
2535
|
+
break;
|
|
2536
|
+
this.pos = (this.pos + charSize(last)) | 0;
|
|
2537
|
+
}
|
|
2538
|
+
if (last === 92 /* CharacterCodes.backslash */)
|
|
2539
|
+
this.setValue(text.substring(this.tokenStart, this.pos) + this.scanIdentifierParts());
|
|
2540
|
+
else
|
|
2541
|
+
this.setValueSlice(this.tokenStart, this.pos);
|
|
2542
|
+
return (this.token = this.identifierKind());
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
const mergeConflictMarkerLength = 7;
|
|
2546
|
+
function utf8Length(ch) {
|
|
2547
|
+
return ch < 0x80 ? 1 : ch < 0x800 ? 2 : ch >= 0xd800 && ch <= 0xdfff ? 4 : 3;
|
|
2548
|
+
}
|
|
2549
|
+
// Whether a conflict marker at `pos` is at a line start, as TypeScript 7 decides it:
|
|
2550
|
+
// after a CR or LF, or after a line terminator followed by two bytes of UTF-8
|
|
2551
|
+
// (two ASCII characters or one two-byte character).
|
|
2552
|
+
function isConflictMarkerLineStart(text, pos) {
|
|
2553
|
+
if (pos === 0)
|
|
2554
|
+
return true;
|
|
2555
|
+
const previous = text.charCodeAt(pos - 1);
|
|
2556
|
+
if (previous === 10 /* CharacterCodes.lineFeed */ || previous === 13 /* CharacterCodes.carriageReturn */)
|
|
2557
|
+
return true;
|
|
2558
|
+
const length = utf8Length(previous);
|
|
2559
|
+
if (length === 2)
|
|
2560
|
+
return pos >= 2 && isLineBreak(text.charCodeAt(pos - 2));
|
|
2561
|
+
if (length === 1 && pos >= 3 && text.charCodeAt(pos - 2) < 0x80)
|
|
2562
|
+
return isLineBreak(text.charCodeAt(pos - 3));
|
|
2563
|
+
return false;
|
|
2564
|
+
}
|
|
2565
|
+
/** Whether `text` has a `<<<<<<<`, `|||||||`, `=======` or `>>>>>>>` marker at `pos`. */
|
|
2566
|
+
export function isConflictMarkerTrivia(text, pos) {
|
|
2567
|
+
if (pos + 1 >= text.length || text.charCodeAt(pos + 1) !== text.charCodeAt(pos))
|
|
2568
|
+
return false;
|
|
2569
|
+
if (!isConflictMarkerLineStart(text, pos) || pos + mergeConflictMarkerLength >= text.length)
|
|
2570
|
+
return false;
|
|
2571
|
+
const ch = text.charCodeAt(pos);
|
|
2572
|
+
for (let i = 2; i < mergeConflictMarkerLength; i++)
|
|
2573
|
+
if (text.charCodeAt(pos + i) !== ch)
|
|
2574
|
+
return false;
|
|
2575
|
+
return ch === 61 /* CharacterCodes.equals */ || text.charCodeAt(pos + mergeConflictMarkerLength) === 32 /* CharacterCodes.space */;
|
|
2576
|
+
}
|
|
2577
|
+
/** Skips a conflict marker and returns the position after it; reports it if `scanner` is given. */
|
|
2578
|
+
function scanConflictMarkerTrivia(text, pos, scanner) {
|
|
2579
|
+
if (scanner !== undefined)
|
|
2580
|
+
scanner.errorAt(141 /* Diagnostics.Merge_conflict_marker_encountered */, pos, mergeConflictMarkerLength, noArgs);
|
|
2581
|
+
const ch = text.charCodeAt(pos);
|
|
2582
|
+
const length = text.length;
|
|
2583
|
+
if (ch === 60 /* CharacterCodes.lessThan */ || ch === 62 /* CharacterCodes.greaterThan */) {
|
|
2584
|
+
while (pos < length && !isLineBreak(text.charCodeAt(pos)))
|
|
2585
|
+
pos++;
|
|
2586
|
+
return pos;
|
|
2587
|
+
}
|
|
2588
|
+
// Consume from a ||||||| or ======= marker to the next ======= or >>>>>>> marker.
|
|
2589
|
+
while (pos < length) {
|
|
2590
|
+
const current = text.charCodeAt(pos);
|
|
2591
|
+
if ((current === 61 /* CharacterCodes.equals */ || current === 62 /* CharacterCodes.greaterThan */) &&
|
|
2592
|
+
current !== ch &&
|
|
2593
|
+
isConflictMarkerTrivia(text, pos))
|
|
2594
|
+
break;
|
|
2595
|
+
pos++;
|
|
2596
|
+
}
|
|
2597
|
+
return pos;
|
|
2598
|
+
}
|
|
2599
|
+
function scanShebangTrivia(text, pos) {
|
|
2600
|
+
pos += 2;
|
|
2601
|
+
while (pos < text.length && !isLineBreak(text.charCodeAt(pos)))
|
|
2602
|
+
pos++;
|
|
2603
|
+
return pos;
|
|
2604
|
+
}
|
|
2605
|
+
function isShebangTrivia(text) {
|
|
2606
|
+
return (text.length >= 2 && text.charCodeAt(0) === 35 /* CharacterCodes.hash */ && text.charCodeAt(1) === 33 /* CharacterCodes.exclamation */);
|
|
2607
|
+
}
|
|
2608
|
+
/** The `#!` line at the start of `text`, or `''`. */
|
|
2609
|
+
export function getShebang(text) {
|
|
2610
|
+
return isShebangTrivia(text) ? text.substring(0, scanShebangTrivia(text, 0)) : '';
|
|
2611
|
+
}
|
|
2612
|
+
/** Whether trivia could start at `pos`; a fast pre-check for `skipTrivia`. */
|
|
2613
|
+
export function couldStartTrivia(text, pos) {
|
|
2614
|
+
const ch = text.charCodeAt(pos);
|
|
2615
|
+
switch (ch) {
|
|
2616
|
+
case 13 /* CharacterCodes.carriageReturn */:
|
|
2617
|
+
case 10 /* CharacterCodes.lineFeed */:
|
|
2618
|
+
case 9 /* CharacterCodes.tab */:
|
|
2619
|
+
case 11 /* CharacterCodes.verticalTab */:
|
|
2620
|
+
case 12 /* CharacterCodes.formFeed */:
|
|
2621
|
+
case 32 /* CharacterCodes.space */:
|
|
2622
|
+
case 47 /* CharacterCodes.slash */:
|
|
2623
|
+
case 60 /* CharacterCodes.lessThan */:
|
|
2624
|
+
case 124 /* CharacterCodes.bar */:
|
|
2625
|
+
case 61 /* CharacterCodes.equals */:
|
|
2626
|
+
case 62 /* CharacterCodes.greaterThan */:
|
|
2627
|
+
return true;
|
|
2628
|
+
case 35 /* CharacterCodes.hash */:
|
|
2629
|
+
return pos === 0;
|
|
2630
|
+
default:
|
|
2631
|
+
return ch > 127 /* CharacterCodes.maxAsciiCharacter */;
|
|
2632
|
+
}
|
|
2633
|
+
}
|
|
2634
|
+
/** Returns the position after whitespace, comments, conflict markers and a leading shebang. */
|
|
2635
|
+
export function skipTrivia(text, pos, stopAfterLineBreak = false, stopAtComments = false, inJSDoc = false) {
|
|
2636
|
+
if (pos < 0)
|
|
2637
|
+
return pos;
|
|
2638
|
+
const length = text.length;
|
|
2639
|
+
let canConsumeStar = false;
|
|
2640
|
+
for (;;) {
|
|
2641
|
+
if (pos >= length)
|
|
2642
|
+
return pos;
|
|
2643
|
+
const ch = text.charCodeAt(pos);
|
|
2644
|
+
switch (ch) {
|
|
2645
|
+
case 13 /* CharacterCodes.carriageReturn */:
|
|
2646
|
+
case 10 /* CharacterCodes.lineFeed */:
|
|
2647
|
+
if (ch === 13 /* CharacterCodes.carriageReturn */ &&
|
|
2648
|
+
pos + 1 < length &&
|
|
2649
|
+
text.charCodeAt(pos + 1) === 10 /* CharacterCodes.lineFeed */)
|
|
2650
|
+
pos++;
|
|
2651
|
+
pos++;
|
|
2652
|
+
if (stopAfterLineBreak)
|
|
2653
|
+
return pos;
|
|
2654
|
+
canConsumeStar = inJSDoc;
|
|
2655
|
+
continue;
|
|
2656
|
+
case 9 /* CharacterCodes.tab */:
|
|
2657
|
+
case 11 /* CharacterCodes.verticalTab */:
|
|
2658
|
+
case 12 /* CharacterCodes.formFeed */:
|
|
2659
|
+
case 32 /* CharacterCodes.space */:
|
|
2660
|
+
pos++;
|
|
2661
|
+
continue;
|
|
2662
|
+
case 47 /* CharacterCodes.slash */:
|
|
2663
|
+
if (stopAtComments || pos + 1 >= length)
|
|
2664
|
+
return pos;
|
|
2665
|
+
if (text.charCodeAt(pos + 1) === 47 /* CharacterCodes.slash */) {
|
|
2666
|
+
pos += 2;
|
|
2667
|
+
while (pos < length && !isLineBreak(text.charCodeAt(pos)))
|
|
2668
|
+
pos++;
|
|
2669
|
+
canConsumeStar = false;
|
|
2670
|
+
continue;
|
|
2671
|
+
}
|
|
2672
|
+
if (text.charCodeAt(pos + 1) === 42 /* CharacterCodes.asterisk */) {
|
|
2673
|
+
const close = text.indexOf('*/', pos + 2);
|
|
2674
|
+
pos = close < 0 ? length : close + 2;
|
|
2675
|
+
canConsumeStar = false;
|
|
2676
|
+
continue;
|
|
2677
|
+
}
|
|
2678
|
+
return pos;
|
|
2679
|
+
case 60 /* CharacterCodes.lessThan */:
|
|
2680
|
+
case 124 /* CharacterCodes.bar */:
|
|
2681
|
+
case 61 /* CharacterCodes.equals */:
|
|
2682
|
+
case 62 /* CharacterCodes.greaterThan */:
|
|
2683
|
+
if (isConflictMarkerTrivia(text, pos)) {
|
|
2684
|
+
pos = scanConflictMarkerTrivia(text, pos, undefined);
|
|
2685
|
+
canConsumeStar = false;
|
|
2686
|
+
continue;
|
|
2687
|
+
}
|
|
2688
|
+
return pos;
|
|
2689
|
+
case 35 /* CharacterCodes.hash */:
|
|
2690
|
+
if (pos === 0 && isShebangTrivia(text)) {
|
|
2691
|
+
pos = scanShebangTrivia(text, pos);
|
|
2692
|
+
canConsumeStar = false;
|
|
2693
|
+
continue;
|
|
2694
|
+
}
|
|
2695
|
+
return pos;
|
|
2696
|
+
case 42 /* CharacterCodes.asterisk */:
|
|
2697
|
+
if (canConsumeStar) {
|
|
2698
|
+
pos++;
|
|
2699
|
+
canConsumeStar = false;
|
|
2700
|
+
continue;
|
|
2701
|
+
}
|
|
2702
|
+
return pos;
|
|
2703
|
+
default:
|
|
2704
|
+
if (ch > 127 /* CharacterCodes.maxAsciiCharacter */ && isWhiteSpaceLike(ch)) {
|
|
2705
|
+
pos++;
|
|
2706
|
+
continue;
|
|
2707
|
+
}
|
|
2708
|
+
return pos;
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
}
|
|
2712
|
+
/** Comments before the next token at `pos`; those on the first line are skipped unless `pos` is 0. */
|
|
2713
|
+
export function getLeadingCommentRanges(text, pos) {
|
|
2714
|
+
return collectCommentRanges(text, pos, false);
|
|
2715
|
+
}
|
|
2716
|
+
/** Comments after `pos` up to the next line break. */
|
|
2717
|
+
export function getTrailingCommentRanges(text, pos) {
|
|
2718
|
+
return collectCommentRanges(text, pos, true);
|
|
2719
|
+
}
|
|
2720
|
+
function collectCommentRanges(text, pos, trailing) {
|
|
2721
|
+
let result;
|
|
2722
|
+
let pendingPos = 0;
|
|
2723
|
+
let pendingEnd = 0;
|
|
2724
|
+
let pendingKind = 0 /* SyntaxKind.Unknown */;
|
|
2725
|
+
let pendingHasTrailingNewLine = false;
|
|
2726
|
+
let hasPending = false;
|
|
2727
|
+
let collecting = trailing;
|
|
2728
|
+
if (pos === 0) {
|
|
2729
|
+
collecting = true;
|
|
2730
|
+
if (isShebangTrivia(text))
|
|
2731
|
+
pos = scanShebangTrivia(text, pos);
|
|
2732
|
+
}
|
|
2733
|
+
const length = text.length;
|
|
2734
|
+
scan: while (pos >= 0 && pos < length) {
|
|
2735
|
+
const ch = text.charCodeAt(pos);
|
|
2736
|
+
switch (ch) {
|
|
2737
|
+
case 13 /* CharacterCodes.carriageReturn */:
|
|
2738
|
+
case 10 /* CharacterCodes.lineFeed */:
|
|
2739
|
+
if (ch === 13 /* CharacterCodes.carriageReturn */ &&
|
|
2740
|
+
pos + 1 < length &&
|
|
2741
|
+
text.charCodeAt(pos + 1) === 10 /* CharacterCodes.lineFeed */)
|
|
2742
|
+
pos++;
|
|
2743
|
+
pos++;
|
|
2744
|
+
if (trailing)
|
|
2745
|
+
break scan;
|
|
2746
|
+
collecting = true;
|
|
2747
|
+
if (hasPending)
|
|
2748
|
+
pendingHasTrailingNewLine = true;
|
|
2749
|
+
continue;
|
|
2750
|
+
case 9 /* CharacterCodes.tab */:
|
|
2751
|
+
case 11 /* CharacterCodes.verticalTab */:
|
|
2752
|
+
case 12 /* CharacterCodes.formFeed */:
|
|
2753
|
+
case 32 /* CharacterCodes.space */:
|
|
2754
|
+
pos++;
|
|
2755
|
+
continue;
|
|
2756
|
+
case 47 /* CharacterCodes.slash */: {
|
|
2757
|
+
const next = pos + 1 < length ? text.charCodeAt(pos + 1) : 0;
|
|
2758
|
+
if (next !== 47 /* CharacterCodes.slash */ && next !== 42 /* CharacterCodes.asterisk */)
|
|
2759
|
+
break scan;
|
|
2760
|
+
const kind = next === 47 /* CharacterCodes.slash */ ? 2 /* SyntaxKind.SingleLineCommentTrivia */ : 3 /* SyntaxKind.MultiLineCommentTrivia */;
|
|
2761
|
+
const start = pos;
|
|
2762
|
+
let hasTrailingNewLine = false;
|
|
2763
|
+
pos += 2;
|
|
2764
|
+
if (next === 47 /* CharacterCodes.slash */) {
|
|
2765
|
+
while (pos < length) {
|
|
2766
|
+
if (isLineBreak(text.charCodeAt(pos))) {
|
|
2767
|
+
hasTrailingNewLine = true;
|
|
2768
|
+
break;
|
|
2769
|
+
}
|
|
2770
|
+
pos++;
|
|
2771
|
+
}
|
|
2772
|
+
}
|
|
2773
|
+
else {
|
|
2774
|
+
const close = text.indexOf('*/', pos);
|
|
2775
|
+
pos = close < 0 ? length : close + 2;
|
|
2776
|
+
}
|
|
2777
|
+
if (collecting) {
|
|
2778
|
+
if (hasPending) {
|
|
2779
|
+
if (result === undefined)
|
|
2780
|
+
result = [];
|
|
2781
|
+
result.push(new CommentRange(pendingPos, pendingEnd, pendingKind, pendingHasTrailingNewLine));
|
|
2782
|
+
}
|
|
2783
|
+
pendingPos = start;
|
|
2784
|
+
pendingEnd = pos;
|
|
2785
|
+
pendingKind = kind;
|
|
2786
|
+
pendingHasTrailingNewLine = hasTrailingNewLine;
|
|
2787
|
+
hasPending = true;
|
|
2788
|
+
}
|
|
2789
|
+
continue;
|
|
2790
|
+
}
|
|
2791
|
+
default:
|
|
2792
|
+
if (ch > 127 /* CharacterCodes.maxAsciiCharacter */ && isWhiteSpaceLike(ch)) {
|
|
2793
|
+
if (hasPending && isLineBreak(ch))
|
|
2794
|
+
pendingHasTrailingNewLine = true;
|
|
2795
|
+
pos++;
|
|
2796
|
+
continue;
|
|
2797
|
+
}
|
|
2798
|
+
break scan;
|
|
2799
|
+
}
|
|
2800
|
+
}
|
|
2801
|
+
if (hasPending) {
|
|
2802
|
+
if (result === undefined)
|
|
2803
|
+
result = [];
|
|
2804
|
+
result.push(new CommentRange(pendingPos, pendingEnd, pendingKind, pendingHasTrailingNewLine));
|
|
2805
|
+
}
|
|
2806
|
+
return result;
|
|
2807
|
+
}
|
|
2808
|
+
/** Start positions of each line, split at CR, LF, CRLF, LS and PS. */
|
|
2809
|
+
export function computeLineStarts(text) {
|
|
2810
|
+
// Most texts break lines at LF only, which a search finds fastest.
|
|
2811
|
+
if (text.indexOf('\r') < 0 && text.indexOf('\u2028') < 0 && text.indexOf('\u2029') < 0) {
|
|
2812
|
+
const starts = [0];
|
|
2813
|
+
for (let i = text.indexOf('\n'); i >= 0; i = text.indexOf('\n', i + 1))
|
|
2814
|
+
starts.push(i + 1);
|
|
2815
|
+
return starts;
|
|
2816
|
+
}
|
|
2817
|
+
const result = [];
|
|
2818
|
+
let lineStart = 0;
|
|
2819
|
+
let pos = 0;
|
|
2820
|
+
while (pos < text.length) {
|
|
2821
|
+
const ch = text.charCodeAt(pos);
|
|
2822
|
+
pos++;
|
|
2823
|
+
if (ch === 13 /* CharacterCodes.carriageReturn */) {
|
|
2824
|
+
if (pos < text.length && text.charCodeAt(pos) === 10 /* CharacterCodes.lineFeed */)
|
|
2825
|
+
pos++;
|
|
2826
|
+
}
|
|
2827
|
+
else if (ch !== 10 /* CharacterCodes.lineFeed */ &&
|
|
2828
|
+
ch !== 8232 /* CharacterCodes.lineSeparator */ &&
|
|
2829
|
+
ch !== 8233 /* CharacterCodes.paragraphSeparator */) {
|
|
2830
|
+
continue;
|
|
2831
|
+
}
|
|
2832
|
+
result.push(lineStart);
|
|
2833
|
+
lineStart = pos;
|
|
2834
|
+
}
|
|
2835
|
+
result.push(lineStart);
|
|
2836
|
+
return result;
|
|
2837
|
+
}
|
|
2838
|
+
/** The zero-based line containing `pos`. */
|
|
2839
|
+
export function computeLineOfPosition(lineStarts, pos) {
|
|
2840
|
+
let low = 0;
|
|
2841
|
+
let high = lineStarts.length - 1;
|
|
2842
|
+
while (low <= high) {
|
|
2843
|
+
const middle = low + ((high - low) >> 1);
|
|
2844
|
+
const value = lineStarts[middle];
|
|
2845
|
+
if (value < pos)
|
|
2846
|
+
low = middle + 1;
|
|
2847
|
+
else if (value > pos)
|
|
2848
|
+
high = middle - 1;
|
|
2849
|
+
else
|
|
2850
|
+
return middle;
|
|
2851
|
+
}
|
|
2852
|
+
return low - 1;
|
|
2853
|
+
}
|