From 873c1df74b7c7dcba59eaccc1bb4bd4b0da18a35 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Sat, 11 Oct 2014 12:52:42 -0700 Subject: [PATCH 01/63] Add es6 target --- src/compiler/commandLineParser.ts | 6 +- .../diagnosticInformationMap.generated.ts | 4 +- src/compiler/diagnosticMessages.json | 4 +- src/compiler/types.ts | 2 + src/harness/fourslash.ts | 2 +- src/harness/harness.ts | 4 +- src/harness/harnessLanguageService.ts | 2 +- src/services/compiler/precompile.ts | 2 +- src/services/services.ts | 12 +- src/services/shims.ts | 3 + src/services/syntax/scanner.ts | 2 +- src/services/syntax/unicode.ts | 4 +- tests/baselines/reference/es6-amd.js | 31 +++++ tests/baselines/reference/es6-amd.js.map | 2 + .../baselines/reference/es6-amd.sourcemap.txt | 128 ++++++++++++++++++ tests/baselines/reference/es6-amd.types | 16 +++ .../reference/es6-declaration-amd.js | 31 +++++ .../reference/es6-declaration-amd.js.map | 2 + .../es6-declaration-amd.sourcemap.txt | 128 ++++++++++++++++++ .../reference/es6-declaration-amd.types | 16 +++ .../baselines/reference/es6-sourcemap-amd.js | 25 ++++ .../reference/es6-sourcemap-amd.js.map | 2 + .../reference/es6-sourcemap-amd.sourcemap.txt | 128 ++++++++++++++++++ .../reference/es6-sourcemap-amd.types | 16 +++ tests/cases/compiler/es6-amd.ts | 17 +++ tests/cases/compiler/es6-declaration-amd.ts | 17 +++ tests/cases/compiler/es6-sourcemap-amd.ts | 16 +++ 27 files changed, 602 insertions(+), 20 deletions(-) create mode 100644 tests/baselines/reference/es6-amd.js create mode 100644 tests/baselines/reference/es6-amd.js.map create mode 100644 tests/baselines/reference/es6-amd.sourcemap.txt create mode 100644 tests/baselines/reference/es6-amd.types create mode 100644 tests/baselines/reference/es6-declaration-amd.js create mode 100644 tests/baselines/reference/es6-declaration-amd.js.map create mode 100644 tests/baselines/reference/es6-declaration-amd.sourcemap.txt create mode 100644 tests/baselines/reference/es6-declaration-amd.types create mode 100644 tests/baselines/reference/es6-sourcemap-amd.js create mode 100644 tests/baselines/reference/es6-sourcemap-amd.js.map create mode 100644 tests/baselines/reference/es6-sourcemap-amd.sourcemap.txt create mode 100644 tests/baselines/reference/es6-sourcemap-amd.types create mode 100644 tests/cases/compiler/es6-amd.ts create mode 100644 tests/cases/compiler/es6-declaration-amd.ts create mode 100644 tests/cases/compiler/es6-sourcemap-amd.ts diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 0e48953eaa7..a7993484c64 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -102,10 +102,10 @@ module ts { { name: "target", shortName: "t", - type: { "es3": ScriptTarget.ES3, "es5": ScriptTarget.ES5 }, - description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_or_ES5, + type: { "es3": ScriptTarget.ES3, "es5": ScriptTarget.ES5 , "es6": ScriptTarget.ES6 }, + description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental, paramType: Diagnostics.VERSION, - error: Diagnostics.Argument_for_target_option_must_be_es3_or_es5 + error: Diagnostics.Argument_for_target_option_must_be_es3_es5_or_es6 }, { name: "version", diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index f6e8275786d..627fb202c18 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -357,7 +357,7 @@ module ts { Watch_input_files: { code: 6005, category: DiagnosticCategory.Message, key: "Watch input files." }, Redirect_output_structure_to_the_directory: { code: 6006, category: DiagnosticCategory.Message, key: "Redirect output structure to the directory." }, Do_not_emit_comments_to_output: { code: 6009, category: DiagnosticCategory.Message, key: "Do not emit comments to output." }, - Specify_ECMAScript_target_version_Colon_ES3_default_or_ES5: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), or 'ES5'" }, + Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" }, Specify_module_code_generation_Colon_commonjs_or_amd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs' or 'amd'" }, Print_this_message: { code: 6017, category: DiagnosticCategory.Message, key: "Print this message." }, Print_the_compiler_s_version: { code: 6019, category: DiagnosticCategory.Message, key: "Print the compiler's version." }, @@ -379,7 +379,7 @@ module ts { Compiler_option_0_expects_an_argument: { code: 6044, category: DiagnosticCategory.Error, key: "Compiler option '{0}' expects an argument." }, Unterminated_quoted_string_in_response_file_0: { code: 6045, category: DiagnosticCategory.Error, key: "Unterminated quoted string in response file '{0}'." }, Argument_for_module_option_must_be_commonjs_or_amd: { code: 6046, category: DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs' or 'amd'." }, - Argument_for_target_option_must_be_es3_or_es5: { code: 6047, category: DiagnosticCategory.Error, key: "Argument for '--target' option must be 'es3' or 'es5'." }, + Argument_for_target_option_must_be_es3_es5_or_es6: { code: 6047, category: DiagnosticCategory.Error, key: "Argument for '--target' option must be 'es3', 'es5', or 'es6'." }, Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1: { code: 6048, category: DiagnosticCategory.Error, key: "Locale must be of the form or -. For example '{0}' or '{1}'." }, Unsupported_locale_0: { code: 6049, category: DiagnosticCategory.Error, key: "Unsupported locale '{0}'." }, Unable_to_open_file_0: { code: 6050, category: DiagnosticCategory.Error, key: "Unable to open file '{0}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 97c82a0a718..26a8c51cccc 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1424,7 +1424,7 @@ "category": "Message", "code": 6009 }, - "Specify ECMAScript target version: 'ES3' (default), or 'ES5'": { + "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)": { "category": "Message", "code": 6015 }, @@ -1512,7 +1512,7 @@ "category": "Error", "code": 6046 }, - "Argument for '--target' option must be 'es3' or 'es5'.": { + "Argument for '--target' option must be 'es3', 'es5', or 'es6'.": { "category": "Error", "code": 6047 }, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 2a291c828cd..38b69e23dee 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1062,6 +1062,8 @@ module ts { export enum ScriptTarget { ES3, ES5, + ES6, + Latest = ES6, } export interface ParsedCommandLine { diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 6a4e13b22e3..0e605a854e2 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2139,7 +2139,7 @@ module FourSlash { var host = Harness.Compiler.createCompilerHost([{ unitName: Harness.Compiler.fourslashFilename, content: undefined }, { unitName: fileName, content: content }], (fn, contents) => result = contents, - ts.ScriptTarget.ES5, + ts.ScriptTarget.Latest, sys.useCaseSensitiveFileNames); var program = ts.createProgram([Harness.Compiler.fourslashFilename, fileName], { out: "fourslashTestOutput.js" }, host); var checker = ts.createTypeChecker(program, /*fullTypeCheckMode*/ true); diff --git a/src/harness/harness.ts b/src/harness/harness.ts index e35fe83f9b2..728c4cc08e0 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -532,7 +532,7 @@ module Harness { } export var defaultLibFileName = 'lib.d.ts'; - export var defaultLibSourceFile = ts.createSourceFile(defaultLibFileName, IO.readFile(libFolder + 'lib.core.d.ts'), /*languageVersion*/ ts.ScriptTarget.ES5, /*version:*/ "0"); + export var defaultLibSourceFile = ts.createSourceFile(defaultLibFileName, IO.readFile(libFolder + 'lib.core.d.ts'), /*languageVersion*/ ts.ScriptTarget.Latest, /*version:*/ "0"); // Cache these between executions so we don't have to re-parse them for every test export var fourslashFilename = 'fourslash.ts'; @@ -685,6 +685,8 @@ module Harness { options.target = ts.ScriptTarget.ES3; } else if (setting.value.toLowerCase() === 'es5') { options.target = ts.ScriptTarget.ES5; + } else if (setting.value.toLowerCase() === 'es6') { + options.target = ts.ScriptTarget.ES6; } else { throw new Error('Unknown compile target ' + setting.value); } diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 647d0729cbb..6307c4d1e78 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -260,7 +260,7 @@ module Harness.LanguageService { /** Parse file given its source text */ public parseSourceText(fileName: string, sourceText: TypeScript.IScriptSnapshot): TypeScript.SourceUnitSyntax { - return TypeScript.Parser.parse(fileName, TypeScript.SimpleText.fromScriptSnapshot(sourceText), ts.ScriptTarget.ES5, TypeScript.isDTSFile(fileName)).sourceUnit(); + return TypeScript.Parser.parse(fileName, TypeScript.SimpleText.fromScriptSnapshot(sourceText), ts.ScriptTarget.Latest, TypeScript.isDTSFile(fileName)).sourceUnit(); } /** Parse a file on disk given its fileName */ diff --git a/src/services/compiler/precompile.ts b/src/services/compiler/precompile.ts index 3ff23d85bea..08a919a65b5 100644 --- a/src/services/compiler/precompile.ts +++ b/src/services/compiler/precompile.ts @@ -184,7 +184,7 @@ module TypeScript { export function preProcessFile(fileName: string, sourceText: IScriptSnapshot, readImportFiles = true): IPreProcessedFileInfo { var text = SimpleText.fromScriptSnapshot(sourceText); - var scanner = Scanner.createScanner(ts.ScriptTarget.ES5, text, reportDiagnostic); + var scanner = Scanner.createScanner(ts.ScriptTarget.Latest, text, reportDiagnostic); var firstToken = scanner.scan(/*allowRegularExpression:*/ false); diff --git a/src/services/services.ts b/src/services/services.ts index 42f6160bd3e..d7c5dc2d897 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -77,7 +77,7 @@ module ts { update(scriptSnapshot: TypeScript.IScriptSnapshot, version: string, isOpen: boolean, textChangeRange: TypeScript.TextChangeRange): SourceFile; } - var scanner: Scanner = createScanner(ScriptTarget.ES5, /*skipTrivia*/ true); + var scanner: Scanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ true); var emptyArray: any[] = []; @@ -1456,9 +1456,9 @@ module ts { } export function getDefaultCompilerOptions(): CompilerOptions { - // Set "ES5" target by default for language service + // Set "ScriptTarget.Latest" target by default for language service return { - target: ScriptTarget.ES5, + target: ScriptTarget.Latest, module: ModuleKind.None, }; } @@ -3794,8 +3794,8 @@ module ts { // before and after it have to be a non-identifier char). var endPosition = position + symbolNameLength; - if ((position === 0 || !isIdentifierPart(text.charCodeAt(position - 1), ScriptTarget.ES5)) && - (endPosition === sourceLength || !isIdentifierPart(text.charCodeAt(endPosition), ScriptTarget.ES5))) { + if ((position === 0 || !isIdentifierPart(text.charCodeAt(position - 1), ScriptTarget.Latest)) && + (endPosition === sourceLength || !isIdentifierPart(text.charCodeAt(endPosition), ScriptTarget.Latest))) { // Found a real match. Keep searching. positions.push(position); } @@ -5217,7 +5217,7 @@ module ts { /// Classifier export function createClassifier(host: Logger): Classifier { - var scanner = createScanner(ScriptTarget.ES5, /*skipTrivia*/ false); + var scanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ false); /// We do not have a full parser support to know when we should parse a regex or not /// If we consider every slash token to be a regex, we could be missing cases like "1/2/3", where diff --git a/src/services/shims.ts b/src/services/shims.ts index fdea0202323..a6bf421b095 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -174,6 +174,7 @@ module ts { export enum LanguageVersion { EcmaScript3 = 0, EcmaScript5 = 1, + EcmaScript6 = 2, } export enum ModuleGenTarget { @@ -213,6 +214,7 @@ module ts { switch (languageVersion) { case LanguageVersion.EcmaScript3: return ScriptTarget.ES3 case LanguageVersion.EcmaScript5: return ScriptTarget.ES5; + case LanguageVersion.EcmaScript6: return ScriptTarget.ES6; default: throw Error("unsupported LanguageVersion value: " + languageVersion); } } @@ -234,6 +236,7 @@ module ts { switch (scriptTarget) { case ScriptTarget.ES3: return LanguageVersion.EcmaScript3; case ScriptTarget.ES5: return LanguageVersion.EcmaScript5; + case ScriptTarget.ES6: return LanguageVersion.EcmaScript6; default: throw Error("unsupported ScriptTarget value: " + scriptTarget); } } diff --git a/src/services/syntax/scanner.ts b/src/services/syntax/scanner.ts index 45cc151e2d5..29ced029f1c 100644 --- a/src/services/syntax/scanner.ts +++ b/src/services/syntax/scanner.ts @@ -186,7 +186,7 @@ module TypeScript.Scanner { var lastTokenInfo = { leadingTriviaWidth: -1, width: -1 }; var lastTokenInfoTokenID: number = -1; - var triviaScanner = createScannerInternal(ts.ScriptTarget.ES5, SimpleText.fromString(""), () => { }); + var triviaScanner = createScannerInternal(ts.ScriptTarget.Latest, SimpleText.fromString(""), () => { }); interface IScannerToken extends ISyntaxToken { } diff --git a/src/services/syntax/unicode.ts b/src/services/syntax/unicode.ts index df2f88b74c5..b1e94090de7 100644 --- a/src/services/syntax/unicode.ts +++ b/src/services/syntax/unicode.ts @@ -84,7 +84,7 @@ module TypeScript { if (languageVersion === ts.ScriptTarget.ES3) { return Unicode.lookupInUnicodeMap(code, Unicode.unicodeES3IdentifierStart); } - else if (languageVersion === ts.ScriptTarget.ES5) { + else if (languageVersion >= ts.ScriptTarget.ES5) { return Unicode.lookupInUnicodeMap(code, Unicode.unicodeES5IdentifierStart); } else { @@ -96,7 +96,7 @@ module TypeScript { if (languageVersion === ts.ScriptTarget.ES3) { return Unicode.lookupInUnicodeMap(code, Unicode.unicodeES3IdentifierPart); } - else if (languageVersion === ts.ScriptTarget.ES5) { + else if (languageVersion >= ts.ScriptTarget.ES5) { return Unicode.lookupInUnicodeMap(code, Unicode.unicodeES5IdentifierPart); } else { diff --git a/tests/baselines/reference/es6-amd.js b/tests/baselines/reference/es6-amd.js new file mode 100644 index 00000000000..0cce3af0446 --- /dev/null +++ b/tests/baselines/reference/es6-amd.js @@ -0,0 +1,31 @@ +//// [es6-amd.ts] + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + +//// [es6-amd.js] +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +//# sourceMappingURL=es6-amd.js.map + +//// [es6-amd.d.ts] +declare class A { + constructor(); + B(): number; +} diff --git a/tests/baselines/reference/es6-amd.js.map b/tests/baselines/reference/es6-amd.js.map new file mode 100644 index 00000000000..7371ba578bd --- /dev/null +++ b/tests/baselines/reference/es6-amd.js.map @@ -0,0 +1,2 @@ +//// [es6-amd.js.map] +{"version":3,"file":"es6-amd.js","sourceRoot":"","sources":["es6-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA,IAAM,CAAC;IAEHA,SAFEA,CAACA;IAKHC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-amd.sourcemap.txt b/tests/baselines/reference/es6-amd.sourcemap.txt new file mode 100644 index 00000000000..070a35703e1 --- /dev/null +++ b/tests/baselines/reference/es6-amd.sourcemap.txt @@ -0,0 +1,128 @@ +=================================================================== +JsFile: es6-amd.js +mapUrl: es6-amd.js.map +sourceRoot: +sources: es6-amd.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/es6-amd.js +sourceFile:es6-amd.ts +------------------------------------------------------------------- +>>>var A = (function () { +1 > +2 >^^^^ +3 > ^ +4 > ^^^^^^^^^^^^^^-> +1 > + > +2 >class +3 > A +1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) +2 >Emitted(1, 5) Source(2, 7) + SourceIndex(0) +3 >Emitted(1, 6) Source(2, 8) + SourceIndex(0) +--- +>>> function A() { +1->^^^^ +2 > ^^^^^^^^^ +3 > ^ +1-> + >{ + > +2 > +3 > A +1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) +2 >Emitted(2, 14) Source(2, 7) + SourceIndex(0) name (A) +3 >Emitted(2, 15) Source(2, 8) + SourceIndex(0) name (A) +--- +>>> } +1 >^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + >{ + > constructor () + > { + > + > +2 > } +1 >Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) +2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) +--- +>>> A.prototype.B = function () { +1->^^^^ +2 > ^^^^^^^^^^^^^ +3 > ^^^ +1-> + > + > public +2 > B +3 > +1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) +2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) +3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) +--- +>>> return 42; +1 >^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +1 >public B() + > { + > +2 > return +3 > +4 > 42 +5 > ; +1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) +2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) +3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) +4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) +5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) +--- +>>> }; +1 >^^^^ +2 > ^ +3 > ^^^^^^^^^-> +1 > + > +2 > } +1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) +2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) +--- +>>> return A; +1->^^^^ +2 > ^^^^^^^^ +1-> + > +2 > } +1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) +--- +>>>})(); +1 > +2 >^ +3 > +4 > ^^^^ +5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > +2 >} +3 > +4 > class A + > { + > constructor () + > { + > + > } + > + > public B() + > { + > return 42; + > } + > } +1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) +3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) +4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) +--- +>>>//# sourceMappingURL=es6-amd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es6-amd.types b/tests/baselines/reference/es6-amd.types new file mode 100644 index 00000000000..62815911f7f --- /dev/null +++ b/tests/baselines/reference/es6-amd.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/es6-amd.ts === + +class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; + } +} diff --git a/tests/baselines/reference/es6-declaration-amd.js b/tests/baselines/reference/es6-declaration-amd.js new file mode 100644 index 00000000000..471f96b223d --- /dev/null +++ b/tests/baselines/reference/es6-declaration-amd.js @@ -0,0 +1,31 @@ +//// [es6-declaration-amd.ts] + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + +//// [es6-declaration-amd.js] +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +//# sourceMappingURL=es6-declaration-amd.js.map + +//// [es6-declaration-amd.d.ts] +declare class A { + constructor(); + B(): number; +} diff --git a/tests/baselines/reference/es6-declaration-amd.js.map b/tests/baselines/reference/es6-declaration-amd.js.map new file mode 100644 index 00000000000..0987f9478e9 --- /dev/null +++ b/tests/baselines/reference/es6-declaration-amd.js.map @@ -0,0 +1,2 @@ +//// [es6-declaration-amd.js.map] +{"version":3,"file":"es6-declaration-amd.js","sourceRoot":"","sources":["es6-declaration-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA,IAAM,CAAC;IAEHA,SAFEA,CAACA;IAKHC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-declaration-amd.sourcemap.txt b/tests/baselines/reference/es6-declaration-amd.sourcemap.txt new file mode 100644 index 00000000000..1fc0b5f05fe --- /dev/null +++ b/tests/baselines/reference/es6-declaration-amd.sourcemap.txt @@ -0,0 +1,128 @@ +=================================================================== +JsFile: es6-declaration-amd.js +mapUrl: es6-declaration-amd.js.map +sourceRoot: +sources: es6-declaration-amd.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/es6-declaration-amd.js +sourceFile:es6-declaration-amd.ts +------------------------------------------------------------------- +>>>var A = (function () { +1 > +2 >^^^^ +3 > ^ +4 > ^^^^^^^^^^^^^^-> +1 > + > +2 >class +3 > A +1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) +2 >Emitted(1, 5) Source(2, 7) + SourceIndex(0) +3 >Emitted(1, 6) Source(2, 8) + SourceIndex(0) +--- +>>> function A() { +1->^^^^ +2 > ^^^^^^^^^ +3 > ^ +1-> + >{ + > +2 > +3 > A +1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) +2 >Emitted(2, 14) Source(2, 7) + SourceIndex(0) name (A) +3 >Emitted(2, 15) Source(2, 8) + SourceIndex(0) name (A) +--- +>>> } +1 >^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + >{ + > constructor () + > { + > + > +2 > } +1 >Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) +2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) +--- +>>> A.prototype.B = function () { +1->^^^^ +2 > ^^^^^^^^^^^^^ +3 > ^^^ +1-> + > + > public +2 > B +3 > +1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) +2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) +3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) +--- +>>> return 42; +1 >^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +1 >public B() + > { + > +2 > return +3 > +4 > 42 +5 > ; +1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) +2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) +3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) +4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) +5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) +--- +>>> }; +1 >^^^^ +2 > ^ +3 > ^^^^^^^^^-> +1 > + > +2 > } +1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) +2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) +--- +>>> return A; +1->^^^^ +2 > ^^^^^^^^ +1-> + > +2 > } +1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) +--- +>>>})(); +1 > +2 >^ +3 > +4 > ^^^^ +5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > +2 >} +3 > +4 > class A + > { + > constructor () + > { + > + > } + > + > public B() + > { + > return 42; + > } + > } +1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) +3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) +4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) +--- +>>>//# sourceMappingURL=es6-declaration-amd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es6-declaration-amd.types b/tests/baselines/reference/es6-declaration-amd.types new file mode 100644 index 00000000000..e275fc52439 --- /dev/null +++ b/tests/baselines/reference/es6-declaration-amd.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/es6-declaration-amd.ts === + +class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; + } +} diff --git a/tests/baselines/reference/es6-sourcemap-amd.js b/tests/baselines/reference/es6-sourcemap-amd.js new file mode 100644 index 00000000000..805e56cf830 --- /dev/null +++ b/tests/baselines/reference/es6-sourcemap-amd.js @@ -0,0 +1,25 @@ +//// [es6-sourcemap-amd.ts] + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + +//// [es6-sourcemap-amd.js] +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +//# sourceMappingURL=es6-sourcemap-amd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es6-sourcemap-amd.js.map b/tests/baselines/reference/es6-sourcemap-amd.js.map new file mode 100644 index 00000000000..689f0447fa8 --- /dev/null +++ b/tests/baselines/reference/es6-sourcemap-amd.js.map @@ -0,0 +1,2 @@ +//// [es6-sourcemap-amd.js.map] +{"version":3,"file":"es6-sourcemap-amd.js","sourceRoot":"","sources":["es6-sourcemap-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA,IAAM,CAAC;IAEHA,SAFEA,CAACA;IAKHC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-sourcemap-amd.sourcemap.txt b/tests/baselines/reference/es6-sourcemap-amd.sourcemap.txt new file mode 100644 index 00000000000..09abb195987 --- /dev/null +++ b/tests/baselines/reference/es6-sourcemap-amd.sourcemap.txt @@ -0,0 +1,128 @@ +=================================================================== +JsFile: es6-sourcemap-amd.js +mapUrl: es6-sourcemap-amd.js.map +sourceRoot: +sources: es6-sourcemap-amd.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/es6-sourcemap-amd.js +sourceFile:es6-sourcemap-amd.ts +------------------------------------------------------------------- +>>>var A = (function () { +1 > +2 >^^^^ +3 > ^ +4 > ^^^^^^^^^^^^^^-> +1 > + > +2 >class +3 > A +1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) +2 >Emitted(1, 5) Source(2, 7) + SourceIndex(0) +3 >Emitted(1, 6) Source(2, 8) + SourceIndex(0) +--- +>>> function A() { +1->^^^^ +2 > ^^^^^^^^^ +3 > ^ +1-> + >{ + > +2 > +3 > A +1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) +2 >Emitted(2, 14) Source(2, 7) + SourceIndex(0) name (A) +3 >Emitted(2, 15) Source(2, 8) + SourceIndex(0) name (A) +--- +>>> } +1 >^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + >{ + > constructor () + > { + > + > +2 > } +1 >Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) +2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) +--- +>>> A.prototype.B = function () { +1->^^^^ +2 > ^^^^^^^^^^^^^ +3 > ^^^ +1-> + > + > public +2 > B +3 > +1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) +2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) +3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) +--- +>>> return 42; +1 >^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +1 >public B() + > { + > +2 > return +3 > +4 > 42 +5 > ; +1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) +2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) +3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) +4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) +5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) +--- +>>> }; +1 >^^^^ +2 > ^ +3 > ^^^^^^^^^-> +1 > + > +2 > } +1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) +2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) +--- +>>> return A; +1->^^^^ +2 > ^^^^^^^^ +1-> + > +2 > } +1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) +--- +>>>})(); +1 > +2 >^ +3 > +4 > ^^^^ +5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > +2 >} +3 > +4 > class A + > { + > constructor () + > { + > + > } + > + > public B() + > { + > return 42; + > } + > } +1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) +3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) +4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) +--- +>>>//# sourceMappingURL=es6-sourcemap-amd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es6-sourcemap-amd.types b/tests/baselines/reference/es6-sourcemap-amd.types new file mode 100644 index 00000000000..661ab2e7cdd --- /dev/null +++ b/tests/baselines/reference/es6-sourcemap-amd.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/es6-sourcemap-amd.ts === + +class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; + } +} diff --git a/tests/cases/compiler/es6-amd.ts b/tests/cases/compiler/es6-amd.ts new file mode 100644 index 00000000000..a5fb99a8605 --- /dev/null +++ b/tests/cases/compiler/es6-amd.ts @@ -0,0 +1,17 @@ +// @target: ES6 +// @sourcemap: false +// @declaration: false +// @module: amd + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/es6-declaration-amd.ts b/tests/cases/compiler/es6-declaration-amd.ts new file mode 100644 index 00000000000..1dcfeca8497 --- /dev/null +++ b/tests/cases/compiler/es6-declaration-amd.ts @@ -0,0 +1,17 @@ +// @target: ES6 +// @sourcemap: false +// @declaration: true +// @module: amd + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/es6-sourcemap-amd.ts b/tests/cases/compiler/es6-sourcemap-amd.ts new file mode 100644 index 00000000000..c00a697de94 --- /dev/null +++ b/tests/cases/compiler/es6-sourcemap-amd.ts @@ -0,0 +1,16 @@ +// @target: ES6 +// @sourcemap: true +// @module: amd + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} \ No newline at end of file From 778f101dea279a97349261a802158bd1055b77f9 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Sun, 12 Oct 2014 21:10:04 -0700 Subject: [PATCH 02/63] Add basic parsing support for let and const --- .../diagnosticInformationMap.generated.ts | 4 ++ src/compiler/diagnosticMessages.json | 16 +++++ src/compiler/emitter.ts | 46 ++++++++++++-- src/compiler/parser.ts | 41 +++++++++++- src/compiler/types.ts | 2 + ...onstDeclarations-ambient-errors.errors.txt | 34 ++++++++++ .../reference/constDeclarations-ambient.js | 13 ++++ .../reference/constDeclarations-ambient.types | 23 +++++++ .../constDeclarations-errors.errors.txt | 62 +++++++++++++++++++ .../constDeclarations-es5.errors.txt | 17 +++++ .../baselines/reference/constDeclarations.js | 19 ++++++ .../reference/constDeclarations.types | 14 +++++ .../baselines/reference/constDeclarations2.js | 26 ++++++++ .../reference/constDeclarations2.types | 18 ++++++ .../reference/letDeclarations-es5.errors.txt | 40 ++++++++++++ tests/baselines/reference/letDeclarations.js | 35 +++++++++++ .../baselines/reference/letDeclarations.types | 36 +++++++++++ tests/baselines/reference/letDeclarations2.js | 19 ++++++ .../reference/letDeclarations2.types | 11 ++++ .../constDeclarations-ambient-errors.ts | 11 ++++ .../compiler/constDeclarations-ambient.ts | 11 ++++ .../compiler/constDeclarations-errors.ts | 11 ++++ tests/cases/compiler/constDeclarations-es5.ts | 5 ++ tests/cases/compiler/constDeclarations.ts | 7 +++ tests/cases/compiler/constDeclarations2.ts | 9 +++ tests/cases/compiler/letDeclarations-es5.ts | 13 ++++ tests/cases/compiler/letDeclarations.ts | 14 +++++ tests/cases/compiler/letDeclarations2.ts | 7 +++ 28 files changed, 557 insertions(+), 7 deletions(-) create mode 100644 tests/baselines/reference/constDeclarations-ambient-errors.errors.txt create mode 100644 tests/baselines/reference/constDeclarations-ambient.js create mode 100644 tests/baselines/reference/constDeclarations-ambient.types create mode 100644 tests/baselines/reference/constDeclarations-errors.errors.txt create mode 100644 tests/baselines/reference/constDeclarations-es5.errors.txt create mode 100644 tests/baselines/reference/constDeclarations.js create mode 100644 tests/baselines/reference/constDeclarations.types create mode 100644 tests/baselines/reference/constDeclarations2.js create mode 100644 tests/baselines/reference/constDeclarations2.types create mode 100644 tests/baselines/reference/letDeclarations-es5.errors.txt create mode 100644 tests/baselines/reference/letDeclarations.js create mode 100644 tests/baselines/reference/letDeclarations.types create mode 100644 tests/baselines/reference/letDeclarations2.js create mode 100644 tests/baselines/reference/letDeclarations2.types create mode 100644 tests/cases/compiler/constDeclarations-ambient-errors.ts create mode 100644 tests/cases/compiler/constDeclarations-ambient.ts create mode 100644 tests/cases/compiler/constDeclarations-errors.ts create mode 100644 tests/cases/compiler/constDeclarations-es5.ts create mode 100644 tests/cases/compiler/constDeclarations.ts create mode 100644 tests/cases/compiler/constDeclarations2.ts create mode 100644 tests/cases/compiler/letDeclarations-es5.ts create mode 100644 tests/cases/compiler/letDeclarations.ts create mode 100644 tests/cases/compiler/letDeclarations2.ts diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 627fb202c18..fe0071c1302 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -115,6 +115,10 @@ module ts { Filename_0_differs_from_already_included_filename_1_only_in_casing: { code: 1149, category: DiagnosticCategory.Error, key: "Filename '{0}' differs from already included filename '{1}' only in casing" }, new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: DiagnosticCategory.Error, key: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, An_enum_member_cannot_have_a_numeric_name: { code: 1151, category: DiagnosticCategory.Error, key: "An enum member cannot have a numeric name." }, + var_let_or_const_expected: { code: 1152, category: DiagnosticCategory.Error, key: "'var', 'let' or 'const' expected." }, + let_variable_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1153, category: DiagnosticCategory.Error, key: "'let' variable declarations are only available when targeting ECMAScript 6 and higher." }, + const_variable_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1154, category: DiagnosticCategory.Error, key: "'const' variable declarations are only available when targeting ECMAScript 6 and higher." }, + Const_must_be_intialized: { code: 1155, category: DiagnosticCategory.Error, key: "Const must be intialized." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 26a8c51cccc..39c38b06938 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -451,6 +451,22 @@ "category": "Error", "code": 1151 }, + "'var', 'let' or 'const' expected.": { + "category": "Error", + "code": 1152 + }, + "'let' variable declarations are only available when targeting ECMAScript 6 and higher.": { + "category": "Error", + "code": 1153 + }, + "'const' variable declarations are only available when targeting ECMAScript 6 and higher.": { + "category": "Error", + "code": 1154 + }, + "Const must be intialized.": { + "category": "Error", + "code": 1155 + }, "Duplicate identifier '{0}'.": { "category": "Error", diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index c038cf39868..81022d04e31 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1149,7 +1149,12 @@ module ts { write(" "); endPos = emitToken(SyntaxKind.OpenParenToken, endPos); if (node.declarations) { - emitToken(SyntaxKind.VarKeyword, endPos); + if (node.declarations[0] && node.declarations[0].flags & NodeFlags.Let) { + emitToken(SyntaxKind.LetKeyword, endPos); + } + else { + emitToken(SyntaxKind.VarKeyword, endPos); + } write(" "); emitCommaList(node.declarations, /*includeTrailingComma*/ false); } @@ -1169,7 +1174,12 @@ module ts { write(" "); endPos = emitToken(SyntaxKind.OpenParenToken, endPos); if (node.declaration) { - emitToken(SyntaxKind.VarKeyword, endPos); + if (node.declaration.flags & NodeFlags.Let) { + emitToken(SyntaxKind.LetKeyword, endPos); + } + else { + emitToken(SyntaxKind.VarKeyword, endPos); + } write(" "); emit(node.declaration); } @@ -1298,7 +1308,17 @@ module ts { function emitVariableStatement(node: VariableStatement) { emitLeadingComments(node); - if (!(node.flags & NodeFlags.Export)) write("var "); + if (!(node.flags & NodeFlags.Export)) { + if (node.flags & NodeFlags.Let) { + write("let "); + } + else if (node.flags & NodeFlags.Const) { + write("const "); + } + else { + write("var "); + } + } emitCommaList(node.declarations, /*includeTrailingComma*/ false); write(";"); emitTrailingComments(node); @@ -1774,7 +1794,15 @@ module ts { if (node.flags & NodeFlags.Export) { writeLine(); emitStart(node); - write("var "); + if (node.flags & NodeFlags.Let) { + write("let "); + } + else if (node.flags & NodeFlags.Const) { + write("const "); + } + else { + write("var "); + } emit(node.name); write(" = "); emitModuleMemberName(node); @@ -2822,7 +2850,15 @@ module ts { if (hasDeclarationWithEmit) { emitJsDocComments(node); emitDeclarationFlags(node); - write("var "); + if (node.flags & NodeFlags.Let) { + write("let "); + } + else if (node.flags & NodeFlags.Const) { + write("const "); + } + else { + write("var "); + } emitCommaList(node.declarations, emitVariableDeclaration); write(";"); writeLine(); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 8a78500db8d..c39780087f2 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2645,6 +2645,15 @@ module ts { error(Diagnostics.Variable_declaration_list_cannot_be_empty); } } + else if (parseOptional(SyntaxKind.LetKeyword)) { + var declarations = parseVariableDeclarationList(NodeFlags.Let, true); + if (!declarations.length) { + error(Diagnostics.Variable_declaration_list_cannot_be_empty); + } + if (languageVersion < ScriptTarget.ES6) { + grammarErrorAtPos(declarations.pos, declarations.end - declarations.pos, Diagnostics.let_variable_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); + } + } else { var varOrInit = parseExpression(true); } @@ -2970,6 +2979,8 @@ module ts { return !inErrorRecovery; case SyntaxKind.OpenBraceToken: case SyntaxKind.VarKeyword: + case SyntaxKind.LetKeyword: + case SyntaxKind.ConstKeyword: case SyntaxKind.FunctionKeyword: case SyntaxKind.IfKeyword: case SyntaxKind.DoKeyword: @@ -3016,6 +3027,8 @@ module ts { case SyntaxKind.OpenBraceToken: return parseBlock(/* ignoreMissingOpenBrace */ false, /*checkForStrictMode*/ false); case SyntaxKind.VarKeyword: + case SyntaxKind.LetKeyword: + case SyntaxKind.ConstKeyword: return parseVariableStatement(); case SyntaxKind.FunctionKeyword: return parseFunctionDeclaration(); @@ -3095,6 +3108,9 @@ module ts { if (inAmbientContext && node.initializer && errorCountBeforeVariableDeclaration === file.syntacticErrors.length) { grammarErrorAtPos(initializerStart, initializerFirstTokenLength, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); } + if (!inAmbientContext && !node.initializer && flags & NodeFlags.Const) { + grammarErrorOnNode(node, Diagnostics.Const_must_be_intialized); + } if (isInStrictMode && isEvalOrArgumentsIdentifier(node.name)) { // It is a SyntaxError if a VariableDeclaration or VariableDeclarationNoIn occurs within strict code // and its Identifier is eval or arguments @@ -3112,13 +3128,30 @@ module ts { var node = createNode(SyntaxKind.VariableStatement, pos); if (flags) node.flags = flags; var errorCountBeforeVarStatement = file.syntacticErrors.length; - parseExpected(SyntaxKind.VarKeyword); - node.declarations = parseVariableDeclarationList(flags, /*noIn*/false); + if (token === SyntaxKind.LetKeyword) { + node.flags |= NodeFlags.Let; + } + else if (token === SyntaxKind.ConstKeyword) { + node.flags |= NodeFlags.Const; + } + else if (token !== SyntaxKind.VarKeyword) { + error(Diagnostics.var_let_or_const_expected); + } + nextToken(); + node.declarations = parseVariableDeclarationList(node.flags, /*noIn*/false); parseSemicolon(); finishNode(node); if (!node.declarations.length && file.syntacticErrors.length === errorCountBeforeVarStatement) { grammarErrorOnNode(node, Diagnostics.Variable_declaration_list_cannot_be_empty); } + if (languageVersion < ScriptTarget.ES6) { + if (node.flags & NodeFlags.Let) { + grammarErrorOnNode(node, Diagnostics.let_variable_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); + } + else if (node.flags & NodeFlags.Const) { + grammarErrorOnNode(node, Diagnostics.const_variable_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); + } + } return node; } @@ -3697,6 +3730,8 @@ module ts { function isDeclaration(): boolean { switch (token) { case SyntaxKind.VarKeyword: + case SyntaxKind.LetKeyword: + case SyntaxKind.ConstKeyword: case SyntaxKind.FunctionKeyword: return true; case SyntaxKind.ClassKeyword: @@ -3747,6 +3782,8 @@ module ts { var result: Declaration; switch (token) { case SyntaxKind.VarKeyword: + case SyntaxKind.LetKeyword: + case SyntaxKind.ConstKeyword: result = parseVariableStatement(pos, flags); break; case SyntaxKind.FunctionKeyword: diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 38b69e23dee..4218d4f4011 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -245,6 +245,8 @@ module ts { MultiLine = 0x00000100, // Multi-line array or object literal Synthetic = 0x00000200, // Synthetic node (for full fidelity) DeclarationFile = 0x00000400, // Node is a .d.ts file + Let = 0x00000800, + Const = 0x00001000, Modifier = Export | Ambient | Public | Private | Protected | Static, AccessibilityModifier = Public | Private | Protected diff --git a/tests/baselines/reference/constDeclarations-ambient-errors.errors.txt b/tests/baselines/reference/constDeclarations-ambient-errors.errors.txt new file mode 100644 index 00000000000..6e2d00dc4c4 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-ambient-errors.errors.txt @@ -0,0 +1,34 @@ +tests/cases/compiler/constDeclarations-ambient-errors.ts(3,27): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/compiler/constDeclarations-ambient-errors.ts(4,26): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/compiler/constDeclarations-ambient-errors.ts(5,18): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/compiler/constDeclarations-ambient-errors.ts(5,37): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/compiler/constDeclarations-ambient-errors.ts(5,51): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/compiler/constDeclarations-ambient-errors.ts(8,14): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/compiler/constDeclarations-ambient-errors.ts(9,22): error TS1039: Initializers are not allowed in ambient contexts. + + +==== tests/cases/compiler/constDeclarations-ambient-errors.ts (7 errors) ==== + + // error: no intialization expected in ambient declarations + declare const c1: boolean = true; + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. + declare const c2: number = 0; + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. + declare const c3 = null, c4 :string = "", c5: any = 0; + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. + + declare module M { + const c6 = 0; + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. + const c7: number = 7; + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. + } \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-ambient.js b/tests/baselines/reference/constDeclarations-ambient.js new file mode 100644 index 00000000000..dd78f73051a --- /dev/null +++ b/tests/baselines/reference/constDeclarations-ambient.js @@ -0,0 +1,13 @@ +//// [constDeclarations-ambient.ts] + +// No error +declare const c1: boolean; +declare const c2: number; +declare const c3, c4 :string, c5: any; + +declare module M { + const c6; + const c7: number; +} + +//// [constDeclarations-ambient.js] diff --git a/tests/baselines/reference/constDeclarations-ambient.types b/tests/baselines/reference/constDeclarations-ambient.types new file mode 100644 index 00000000000..0ab2d4b700a --- /dev/null +++ b/tests/baselines/reference/constDeclarations-ambient.types @@ -0,0 +1,23 @@ +=== tests/cases/compiler/constDeclarations-ambient.ts === + +// No error +declare const c1: boolean; +>c1 : boolean + +declare const c2: number; +>c2 : number + +declare const c3, c4 :string, c5: any; +>c3 : any +>c4 : string +>c5 : any + +declare module M { +>M : typeof M + + const c6; +>c6 : any + + const c7: number; +>c7 : number +} diff --git a/tests/baselines/reference/constDeclarations-errors.errors.txt b/tests/baselines/reference/constDeclarations-errors.errors.txt new file mode 100644 index 00000000000..79d56ade878 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-errors.errors.txt @@ -0,0 +1,62 @@ +tests/cases/compiler/constDeclarations-errors.ts(3,7): error TS1155: const must be intialized. +tests/cases/compiler/constDeclarations-errors.ts(4,7): error TS1155: const must be intialized. +tests/cases/compiler/constDeclarations-errors.ts(5,7): error TS1155: const must be intialized. +tests/cases/compiler/constDeclarations-errors.ts(5,11): error TS1155: const must be intialized. +tests/cases/compiler/constDeclarations-errors.ts(5,15): error TS1155: const must be intialized. +tests/cases/compiler/constDeclarations-errors.ts(5,27): error TS1155: const must be intialized. +tests/cases/compiler/constDeclarations-errors.ts(8,5): error TS1109: Expression expected. +tests/cases/compiler/constDeclarations-errors.ts(8,5): error TS1156: const must be declared inside a block. +tests/cases/compiler/constDeclarations-errors.ts(8,11): error TS1155: const must be intialized. +tests/cases/compiler/constDeclarations-errors.ts(8,13): error TS1005: ';' expected. +tests/cases/compiler/constDeclarations-errors.ts(8,13): error TS1128: Declaration or statement expected. +tests/cases/compiler/constDeclarations-errors.ts(8,18): error TS1128: Declaration or statement expected. +tests/cases/compiler/constDeclarations-errors.ts(10,5): error TS1109: Expression expected. +tests/cases/compiler/constDeclarations-errors.ts(10,5): error TS1156: const must be declared inside a block. +tests/cases/compiler/constDeclarations-errors.ts(10,28): error TS1005: ';' expected. +tests/cases/compiler/constDeclarations-errors.ts(10,11): error TS2403: Subsequent variable declarations must have the same type. Variable 'c' must be of type 'any', but here has type 'number'. + + +==== tests/cases/compiler/constDeclarations-errors.ts (16 errors) ==== + + // error, missing intialicer + const c1; + ~~ +!!! error TS1155: const must be intialized. + const c2: number; + ~~ +!!! error TS1155: const must be intialized. + const c3, c4, c5 :string, c6; // error, missing initialicer + ~~ +!!! error TS1155: const must be intialized. + ~~ +!!! error TS1155: const must be intialized. + ~~ +!!! error TS1155: const must be intialized. + ~~ +!!! error TS1155: const must be intialized. + + // error, wrong context + for(const c in {}) { } + ~~~~~ +!!! error TS1109: Expression expected. + ~~~~~~~ +!!! error TS1156: const must be declared inside a block. + ~ +!!! error TS1155: const must be intialized. + ~~ +!!! error TS1005: ';' expected. + ~~ +!!! error TS1128: Declaration or statement expected. + ~ +!!! error TS1128: Declaration or statement expected. + + for(const c = 0; c < 9; c++) { } + ~~~~~ +!!! error TS1109: Expression expected. + ~~~~~~~~~~~~ +!!! error TS1156: const must be declared inside a block. + ~ +!!! error TS1005: ';' expected. + ~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'c' must be of type 'any', but here has type 'number'. + \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-es5.errors.txt b/tests/baselines/reference/constDeclarations-es5.errors.txt new file mode 100644 index 00000000000..a941b826ed0 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-es5.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/constDeclarations-es5.ts(2,1): error TS1154: 'const' variable declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/constDeclarations-es5.ts(3,1): error TS1154: 'const' variable declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/constDeclarations-es5.ts(4,1): error TS1154: 'const' variable declarations are only available when targeting ECMAScript 6 and higher. + + +==== tests/cases/compiler/constDeclarations-es5.ts (3 errors) ==== + + const z7 = false; + ~~~~~~~~~~~~~~~~~ +!!! error TS1154: 'const' variable declarations are only available when targeting ECMAScript 6 and higher. + const z8: number = 23; + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1154: 'const' variable declarations are only available when targeting ECMAScript 6 and higher. + const z9 = 0, z10 :string = "", z11 = null; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1154: 'const' variable declarations are only available when targeting ECMAScript 6 and higher. + \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations.js b/tests/baselines/reference/constDeclarations.js new file mode 100644 index 00000000000..23d87d2c2a7 --- /dev/null +++ b/tests/baselines/reference/constDeclarations.js @@ -0,0 +1,19 @@ +//// [constDeclarations.ts] + +// No error +const c1 = false; +const c2: number = 23; +const c3 = 0, c4 :string = "", c5 = null; + + +//// [constDeclarations.js] +// No error +const c1 = false; +const c2 = 23; +const c3 = 0, c4 = "", c5 = null; + + +//// [constDeclarations.d.ts] +declare const c1: boolean; +declare const c2: number; +declare const c3: number, c4: string, c5: any; diff --git a/tests/baselines/reference/constDeclarations.types b/tests/baselines/reference/constDeclarations.types new file mode 100644 index 00000000000..7faa37f85bc --- /dev/null +++ b/tests/baselines/reference/constDeclarations.types @@ -0,0 +1,14 @@ +=== tests/cases/compiler/constDeclarations.ts === + +// No error +const c1 = false; +>c1 : boolean + +const c2: number = 23; +>c2 : number + +const c3 = 0, c4 :string = "", c5 = null; +>c3 : number +>c4 : string +>c5 : any + diff --git a/tests/baselines/reference/constDeclarations2.js b/tests/baselines/reference/constDeclarations2.js new file mode 100644 index 00000000000..e4ee67ebdcd --- /dev/null +++ b/tests/baselines/reference/constDeclarations2.js @@ -0,0 +1,26 @@ +//// [constDeclarations2.ts] + +// No error +module M { + export const c1 = false; + export const c2: number = 23; + export const c3 = 0, c4 :string = "", c5 = null; +} + + +//// [constDeclarations2.js] +// No error +var M; +(function (M) { + M.c1 = false; + M.c2 = 23; + M.c3 = 0, M.c4 = "", M.c5 = null; +})(M || (M = {})); + + +//// [constDeclarations2.d.ts] +declare module M { + const c1: boolean; + const c2: number; + const c3: number, c4: string, c5: any; +} diff --git a/tests/baselines/reference/constDeclarations2.types b/tests/baselines/reference/constDeclarations2.types new file mode 100644 index 00000000000..c81eca96b0d --- /dev/null +++ b/tests/baselines/reference/constDeclarations2.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/constDeclarations2.ts === + +// No error +module M { +>M : typeof M + + export const c1 = false; +>c1 : boolean + + export const c2: number = 23; +>c2 : number + + export const c3 = 0, c4 :string = "", c5 = null; +>c3 : number +>c4 : string +>c5 : any +} + diff --git a/tests/baselines/reference/letDeclarations-es5.errors.txt b/tests/baselines/reference/letDeclarations-es5.errors.txt new file mode 100644 index 00000000000..2a5858350cd --- /dev/null +++ b/tests/baselines/reference/letDeclarations-es5.errors.txt @@ -0,0 +1,40 @@ +tests/cases/compiler/letDeclarations-es5.ts(2,1): error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(3,1): error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(4,1): error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(6,1): error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(7,1): error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(8,1): error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(10,8): error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(12,8): error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. + + +==== tests/cases/compiler/letDeclarations-es5.ts (8 errors) ==== + + let l1; + ~~~~~~~ +!!! error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. + let l2: number; + ~~~~~~~~~~~~~~~ +!!! error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. + let l3, l4, l5 :string, l6; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. + + let l7 = false; + ~~~~~~~~~~~~~~~ +!!! error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. + let l8: number = 23; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. + let l9 = 0, l10 :string = "", l11 = null; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. + + for(let l11 in {}) { } + ~~~~ +!!! error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. + + for(let l12 = 0; l12 < 9; l12++) { } + ~~~~~~~~ +!!! error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. + \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations.js b/tests/baselines/reference/letDeclarations.js new file mode 100644 index 00000000000..bc186b732f5 --- /dev/null +++ b/tests/baselines/reference/letDeclarations.js @@ -0,0 +1,35 @@ +//// [letDeclarations.ts] + +let l1; +let l2: number; +let l3, l4, l5 :string, l6; + +let l7 = false; +let l8: number = 23; +let l9 = 0, l10 :string = "", l11 = null; + +for(let l11 in {}) { } + +for(let l12 = 0; l12 < 9; l12++) { } + + +//// [letDeclarations.js] +let l1; +let l2; +let l3, l4, l5, l6; +let l7 = false; +let l8 = 23; +let l9 = 0, l10 = "", l11 = null; +for (let l11 in {}) { +} +for (let l12 = 0; l12 < 9; l12++) { +} + + +//// [letDeclarations.d.ts] +declare let l1: any; +declare let l2: number; +declare let l3: any, l4: any, l5: string, l6: any; +declare let l7: boolean; +declare let l8: number; +declare let l9: number, l10: string, l11: any; diff --git a/tests/baselines/reference/letDeclarations.types b/tests/baselines/reference/letDeclarations.types new file mode 100644 index 00000000000..aa47a7f0006 --- /dev/null +++ b/tests/baselines/reference/letDeclarations.types @@ -0,0 +1,36 @@ +=== tests/cases/compiler/letDeclarations.ts === + +let l1; +>l1 : any + +let l2: number; +>l2 : number + +let l3, l4, l5 :string, l6; +>l3 : any +>l4 : any +>l5 : string +>l6 : any + +let l7 = false; +>l7 : boolean + +let l8: number = 23; +>l8 : number + +let l9 = 0, l10 :string = "", l11 = null; +>l9 : number +>l10 : string +>l11 : any + +for(let l11 in {}) { } +>l11 : any +>{} : {} + +for(let l12 = 0; l12 < 9; l12++) { } +>l12 : number +>l12 < 9 : boolean +>l12 : number +>l12++ : number +>l12 : number + diff --git a/tests/baselines/reference/letDeclarations2.js b/tests/baselines/reference/letDeclarations2.js new file mode 100644 index 00000000000..8a6f039f2ca --- /dev/null +++ b/tests/baselines/reference/letDeclarations2.js @@ -0,0 +1,19 @@ +//// [letDeclarations2.ts] + +module M { + let l1 = "s"; + export let l2 = 0; +} + +//// [letDeclarations2.js] +var M; +(function (M) { + let l1 = "s"; + M.l2 = 0; +})(M || (M = {})); + + +//// [letDeclarations2.d.ts] +declare module M { + let l2: number; +} diff --git a/tests/baselines/reference/letDeclarations2.types b/tests/baselines/reference/letDeclarations2.types new file mode 100644 index 00000000000..2fa08b6d940 --- /dev/null +++ b/tests/baselines/reference/letDeclarations2.types @@ -0,0 +1,11 @@ +=== tests/cases/compiler/letDeclarations2.ts === + +module M { +>M : typeof M + + let l1 = "s"; +>l1 : string + + export let l2 = 0; +>l2 : number +} diff --git a/tests/cases/compiler/constDeclarations-ambient-errors.ts b/tests/cases/compiler/constDeclarations-ambient-errors.ts new file mode 100644 index 00000000000..c07bfb01810 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-ambient-errors.ts @@ -0,0 +1,11 @@ +// @target: ES6 + +// error: no intialization expected in ambient declarations +declare const c1: boolean = true; +declare const c2: number = 0; +declare const c3 = null, c4 :string = "", c5: any = 0; + +declare module M { + const c6 = 0; + const c7: number = 7; +} \ No newline at end of file diff --git a/tests/cases/compiler/constDeclarations-ambient.ts b/tests/cases/compiler/constDeclarations-ambient.ts new file mode 100644 index 00000000000..dcd4cb9fc72 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-ambient.ts @@ -0,0 +1,11 @@ +// @target: ES6 + +// No error +declare const c1: boolean; +declare const c2: number; +declare const c3, c4 :string, c5: any; + +declare module M { + const c6; + const c7: number; +} \ No newline at end of file diff --git a/tests/cases/compiler/constDeclarations-errors.ts b/tests/cases/compiler/constDeclarations-errors.ts new file mode 100644 index 00000000000..08ccaf7fe18 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-errors.ts @@ -0,0 +1,11 @@ +// @target: ES6 + +// error, missing intialicer +const c1; +const c2: number; +const c3, c4, c5 :string, c6; // error, missing initialicer + +// error, wrong context +for(const c in {}) { } + +for(const c = 0; c < 9; c++) { } diff --git a/tests/cases/compiler/constDeclarations-es5.ts b/tests/cases/compiler/constDeclarations-es5.ts new file mode 100644 index 00000000000..0da824a7396 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-es5.ts @@ -0,0 +1,5 @@ +// @target: ES5 + +const z7 = false; +const z8: number = 23; +const z9 = 0, z10 :string = "", z11 = null; diff --git a/tests/cases/compiler/constDeclarations.ts b/tests/cases/compiler/constDeclarations.ts new file mode 100644 index 00000000000..36e01551a66 --- /dev/null +++ b/tests/cases/compiler/constDeclarations.ts @@ -0,0 +1,7 @@ +// @target: ES6 +// @declaration: true + +// No error +const c1 = false; +const c2: number = 23; +const c3 = 0, c4 :string = "", c5 = null; diff --git a/tests/cases/compiler/constDeclarations2.ts b/tests/cases/compiler/constDeclarations2.ts new file mode 100644 index 00000000000..a221c3563ba --- /dev/null +++ b/tests/cases/compiler/constDeclarations2.ts @@ -0,0 +1,9 @@ +// @target: ES6 +// @declaration: true + +// No error +module M { + export const c1 = false; + export const c2: number = 23; + export const c3 = 0, c4 :string = "", c5 = null; +} diff --git a/tests/cases/compiler/letDeclarations-es5.ts b/tests/cases/compiler/letDeclarations-es5.ts new file mode 100644 index 00000000000..b115c260a91 --- /dev/null +++ b/tests/cases/compiler/letDeclarations-es5.ts @@ -0,0 +1,13 @@ +// @target: ES5 + +let l1; +let l2: number; +let l3, l4, l5 :string, l6; + +let l7 = false; +let l8: number = 23; +let l9 = 0, l10 :string = "", l11 = null; + +for(let l11 in {}) { } + +for(let l12 = 0; l12 < 9; l12++) { } diff --git a/tests/cases/compiler/letDeclarations.ts b/tests/cases/compiler/letDeclarations.ts new file mode 100644 index 00000000000..e90e355ba68 --- /dev/null +++ b/tests/cases/compiler/letDeclarations.ts @@ -0,0 +1,14 @@ +// @target: ES6 +// @declaration: true + +let l1; +let l2: number; +let l3, l4, l5 :string, l6; + +let l7 = false; +let l8: number = 23; +let l9 = 0, l10 :string = "", l11 = null; + +for(let l11 in {}) { } + +for(let l12 = 0; l12 < 9; l12++) { } diff --git a/tests/cases/compiler/letDeclarations2.ts b/tests/cases/compiler/letDeclarations2.ts new file mode 100644 index 00000000000..e7e09f0849a --- /dev/null +++ b/tests/cases/compiler/letDeclarations2.ts @@ -0,0 +1,7 @@ +// @target: ES6 +// @declaration: true + +module M { + let l1 = "s"; + export let l2 = 0; +} \ No newline at end of file From 979d45eb670ebc1e68f4029e1d055c28c73430f6 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Sun, 12 Oct 2014 21:43:09 -0700 Subject: [PATCH 03/63] Disallow let and const declarations outside blocks --- .../diagnosticInformationMap.generated.ts | 4 +- src/compiler/diagnosticMessages.json | 10 +- src/compiler/parser.ts | 55 +++-- ...nstDeclarations-invalidContexts.errors.txt | 66 +++++ ...constDeclarations-validContexts.errors.txt | 129 ++++++++++ .../constDeclarations-validContexts.js | 229 ++++++++++++++++++ ...letDeclarations-invalidContexts.errors.txt | 66 +++++ .../letDeclarations-validContexts.errors.txt | 129 ++++++++++ .../letDeclarations-validContexts.js | 229 ++++++++++++++++++ .../constDeclarations-invalidContexts.ts | 33 +++ .../constDeclarations-validContexts.ts | 124 ++++++++++ .../letDeclarations-invalidContexts.ts | 33 +++ .../compiler/letDeclarations-validContexts.ts | 124 ++++++++++ 13 files changed, 1205 insertions(+), 26 deletions(-) create mode 100644 tests/baselines/reference/constDeclarations-invalidContexts.errors.txt create mode 100644 tests/baselines/reference/constDeclarations-validContexts.errors.txt create mode 100644 tests/baselines/reference/constDeclarations-validContexts.js create mode 100644 tests/baselines/reference/letDeclarations-invalidContexts.errors.txt create mode 100644 tests/baselines/reference/letDeclarations-validContexts.errors.txt create mode 100644 tests/baselines/reference/letDeclarations-validContexts.js create mode 100644 tests/cases/compiler/constDeclarations-invalidContexts.ts create mode 100644 tests/cases/compiler/constDeclarations-validContexts.ts create mode 100644 tests/cases/compiler/letDeclarations-invalidContexts.ts create mode 100644 tests/cases/compiler/letDeclarations-validContexts.ts diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index fe0071c1302..84e10cfec58 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -118,7 +118,9 @@ module ts { var_let_or_const_expected: { code: 1152, category: DiagnosticCategory.Error, key: "'var', 'let' or 'const' expected." }, let_variable_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1153, category: DiagnosticCategory.Error, key: "'let' variable declarations are only available when targeting ECMAScript 6 and higher." }, const_variable_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1154, category: DiagnosticCategory.Error, key: "'const' variable declarations are only available when targeting ECMAScript 6 and higher." }, - Const_must_be_intialized: { code: 1155, category: DiagnosticCategory.Error, key: "Const must be intialized." }, + const_must_be_intialized: { code: 1155, category: DiagnosticCategory.Error, key: "const must be intialized." }, + const_must_be_declared_inside_a_block: { code: 1156, category: DiagnosticCategory.Error, key: "const must be declared inside a block." }, + let_must_be_declared_inside_a_block: { code: 1157, category: DiagnosticCategory.Error, key: "let must be declared inside a block." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 39c38b06938..fa433e0e772 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -463,10 +463,18 @@ "category": "Error", "code": 1154 }, - "Const must be intialized.": { + "const must be intialized.": { "category": "Error", "code": 1155 }, + "const must be declared inside a block.": { + "category": "Error", + "code": 1156 + }, + "let must be declared inside a block.": { + "category": "Error", + "code": 1157 + }, "Duplicate identifier '{0}'.": { "category": "Error", diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index c39780087f2..d8d1d24a97e 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2542,11 +2542,14 @@ module ts { } // STATEMENTS + function parseStatementAllowingLetDeclaration() { + return parseStatement(/*allowLetDeclarations*/ true); + } function parseBlock(ignoreMissingOpenBrace: boolean, checkForStrictMode: boolean): Block { var node = createNode(SyntaxKind.Block); if (parseExpected(SyntaxKind.OpenBraceToken) || ignoreMissingOpenBrace) { - node.statements = parseList(ParsingContext.BlockStatements,checkForStrictMode, parseStatement); + node.statements = parseList(ParsingContext.BlockStatements, checkForStrictMode, parseStatementAllowingLetDeclaration); parseExpected(SyntaxKind.CloseBraceToken); } else { @@ -2592,8 +2595,8 @@ module ts { parseExpected(SyntaxKind.OpenParenToken); node.expression = parseExpression(); parseExpected(SyntaxKind.CloseParenToken); - node.thenStatement = parseStatement(); - node.elseStatement = parseOptional(SyntaxKind.ElseKeyword) ? parseStatement() : undefined; + node.thenStatement = parseStatement(/*allowLetDeclarations*/ false); + node.elseStatement = parseOptional(SyntaxKind.ElseKeyword) ? parseStatement(/*allowLetDeclarations*/ false) : undefined; return finishNode(node); } @@ -2603,7 +2606,7 @@ module ts { var saveInIterationStatement = inIterationStatement; inIterationStatement = ControlBlockContext.Nested; - node.statement = parseStatement(); + node.statement = parseStatement(/*allowLetDeclarations*/ false); inIterationStatement = saveInIterationStatement; parseExpected(SyntaxKind.WhileKeyword); @@ -2628,7 +2631,7 @@ module ts { var saveInIterationStatement = inIterationStatement; inIterationStatement = ControlBlockContext.Nested; - node.statement = parseStatement(); + node.statement = parseStatement(/*allowLetDeclarations*/ false); inIterationStatement = saveInIterationStatement; return finishNode(node); @@ -2692,7 +2695,7 @@ module ts { var saveInIterationStatement = inIterationStatement; inIterationStatement = ControlBlockContext.Nested; - forOrForInStatement.statement = parseStatement(); + forOrForInStatement.statement = parseStatement(/*allowLetDeclarations*/ false); inIterationStatement = saveInIterationStatement; return finishNode(forOrForInStatement); @@ -2803,7 +2806,7 @@ module ts { parseExpected(SyntaxKind.OpenParenToken); node.expression = parseExpression(); parseExpected(SyntaxKind.CloseParenToken); - node.statement = parseStatement(); + node.statement = parseStatement(/*allowLetDeclarations*/ false); node = finishNode(node); if (isInStrictMode) { // Strict mode code may not include a WithStatement. The occurrence of a WithStatement in such @@ -2818,7 +2821,7 @@ module ts { parseExpected(SyntaxKind.CaseKeyword); node.expression = parseExpression(); parseExpected(SyntaxKind.ColonToken); - node.statements = parseList(ParsingContext.SwitchClauseStatements, /*checkForStrictMode*/ false, parseStatement); + node.statements = parseList(ParsingContext.SwitchClauseStatements, /*checkForStrictMode*/ false, parseStatementAllowingLetDeclaration); return finishNode(node); } @@ -2826,7 +2829,7 @@ module ts { var node = createNode(SyntaxKind.DefaultClause); parseExpected(SyntaxKind.DefaultKeyword); parseExpected(SyntaxKind.ColonToken); - node.statements = parseList(ParsingContext.SwitchClauseStatements, /*checkForStrictMode*/ false, parseStatement); + node.statements = parseList(ParsingContext.SwitchClauseStatements, /*checkForStrictMode*/ false, parseStatementAllowingLetDeclaration); return finishNode(node); } @@ -2933,9 +2936,9 @@ module ts { return token === SyntaxKind.WhileKeyword || token === SyntaxKind.DoKeyword || token === SyntaxKind.ForKeyword; } - function parseStatementWithLabelSet(): Statement { + function parseStatementWithLabelSet(allowLetDeclarations: boolean): Statement { labelledStatementInfo.pushCurrentLabelSet(isIterationStatementStart()); - var statement = parseStatement(); + var statement = parseStatement(allowLetDeclarations); labelledStatementInfo.pop(); return statement; } @@ -2944,7 +2947,7 @@ module ts { return isIdentifier() && lookAhead(() => nextToken() === SyntaxKind.ColonToken); } - function parseLabelledStatement(): LabeledStatement { + function parseLabelledStatement(allowLetDeclarations: boolean): LabeledStatement { var node = createNode(SyntaxKind.LabeledStatement); node.label = parseIdentifier(); parseExpected(SyntaxKind.ColonToken); @@ -2956,7 +2959,7 @@ module ts { // We only want to call parseStatementWithLabelSet when the label set is complete // Therefore, keep parsing labels until we know we're done. - node.statement = isLabel() ? parseLabelledStatement() : parseStatementWithLabelSet(); + node.statement = isLabel() ? parseLabelledStatement(allowLetDeclarations) : parseStatementWithLabelSet(allowLetDeclarations); return finishNode(node); } @@ -3022,14 +3025,14 @@ module ts { } } - function parseStatement(): Statement { + function parseStatement(allowLetDeclarations: boolean): Statement { switch (token) { case SyntaxKind.OpenBraceToken: return parseBlock(/* ignoreMissingOpenBrace */ false, /*checkForStrictMode*/ false); case SyntaxKind.VarKeyword: case SyntaxKind.LetKeyword: case SyntaxKind.ConstKeyword: - return parseVariableStatement(); + return parseVariableStatement(allowLetDeclarations); case SyntaxKind.FunctionKeyword: return parseFunctionDeclaration(); case SyntaxKind.SemicolonToken: @@ -3063,16 +3066,12 @@ module ts { return parseDebuggerStatement(); default: if (isLabel()) { - return parseLabelledStatement(); + return parseLabelledStatement(allowLetDeclarations); } return parseExpressionStatement(); } } - function parseStatementOrFunction(): Statement { - return token === SyntaxKind.FunctionKeyword ? parseFunctionDeclaration() : parseStatement(); - } - function parseAndCheckFunctionBody(isConstructor: boolean): Block { var initialPosition = scanner.getTokenPos(); var errorCountBeforeBody = file.syntacticErrors.length; @@ -3109,7 +3108,7 @@ module ts { grammarErrorAtPos(initializerStart, initializerFirstTokenLength, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); } if (!inAmbientContext && !node.initializer && flags & NodeFlags.Const) { - grammarErrorOnNode(node, Diagnostics.Const_must_be_intialized); + grammarErrorOnNode(node, Diagnostics.const_must_be_intialized); } if (isInStrictMode && isEvalOrArgumentsIdentifier(node.name)) { // It is a SyntaxError if a VariableDeclaration or VariableDeclarationNoIn occurs within strict code @@ -3124,7 +3123,7 @@ module ts { () => parseVariableDeclaration(flags, noIn), /*allowTrailingComma*/ false); } - function parseVariableStatement(pos?: number, flags?: NodeFlags): VariableStatement { + function parseVariableStatement(allowLetDeclarations: boolean, pos?: number, flags?: NodeFlags): VariableStatement { var node = createNode(SyntaxKind.VariableStatement, pos); if (flags) node.flags = flags; var errorCountBeforeVarStatement = file.syntacticErrors.length; @@ -3152,6 +3151,14 @@ module ts { grammarErrorOnNode(node, Diagnostics.const_variable_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); } } + else if (!allowLetDeclarations){ + if (node.flags & NodeFlags.Let) { + grammarErrorOnNode(node, Diagnostics.let_must_be_declared_inside_a_block); + } + else if (node.flags & NodeFlags.Const) { + grammarErrorOnNode(node, Diagnostics.const_must_be_declared_inside_a_block); + } + } return node; } @@ -3784,7 +3791,7 @@ module ts { case SyntaxKind.VarKeyword: case SyntaxKind.LetKeyword: case SyntaxKind.ConstKeyword: - result = parseVariableStatement(pos, flags); + result = parseVariableStatement(/*allowLetDeclarations*/ true, pos, flags); break; case SyntaxKind.FunctionKeyword: result = parseFunctionDeclaration(pos, flags); @@ -3832,7 +3839,7 @@ module ts { var statementStart = scanner.getTokenPos(); var statementFirstTokenLength = scanner.getTextPos() - statementStart; var errorCountBeforeStatement = file.syntacticErrors.length; - var statement = parseStatement(); + var statement = parseStatement(/*allowLetDeclarations*/ false); if (inAmbientContext && file.syntacticErrors.length === errorCountBeforeStatement) { grammarErrorAtPos(statementStart, statementFirstTokenLength, Diagnostics.Statements_are_not_allowed_in_ambient_contexts); diff --git a/tests/baselines/reference/constDeclarations-invalidContexts.errors.txt b/tests/baselines/reference/constDeclarations-invalidContexts.errors.txt new file mode 100644 index 00000000000..b7aef3dabbe --- /dev/null +++ b/tests/baselines/reference/constDeclarations-invalidContexts.errors.txt @@ -0,0 +1,66 @@ +tests/cases/compiler/constDeclarations-invalidContexts.ts(4,5): error TS1156: const must be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(6,5): error TS1156: const must be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(9,5): error TS1156: const must be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(12,5): error TS1156: const must be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(17,5): error TS1156: const must be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(20,5): error TS1156: const must be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(23,5): error TS1156: const must be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(26,12): error TS1156: const must be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(29,29): error TS1156: const must be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(16,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'. + + +==== tests/cases/compiler/constDeclarations-invalidContexts.ts (10 errors) ==== + + // Errors, const must be defined inside a block + if (true) + const c1 = 0; + ~~~~~~~~~~~~~ +!!! error TS1156: const must be declared inside a block. + else + const c2 = 0; + ~~~~~~~~~~~~~ +!!! error TS1156: const must be declared inside a block. + + while (true) + const c3 = 0; + ~~~~~~~~~~~~~ +!!! error TS1156: const must be declared inside a block. + + do + const c4 = 0; + ~~~~~~~~~~~~~ +!!! error TS1156: const must be declared inside a block. + while (true); + + var obj; + with (obj) + ~~~ +!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'. + const c5 = 0; + ~~~~~~~~~~~~~ +!!! error TS1156: const must be declared inside a block. + + for (var i = 0; i < 10; i++) + const c6 = 0; + ~~~~~~~~~~~~~ +!!! error TS1156: const must be declared inside a block. + + for (var i2 in {}) + const c7 = 0; + ~~~~~~~~~~~~~ +!!! error TS1156: const must be declared inside a block. + + if (true) + label: const c8 = 0; + ~~~~~~~~~~~~~ +!!! error TS1156: const must be declared inside a block. + + while (false) + label2: label3: label4: const c9 = 0; + ~~~~~~~~~~~~~ +!!! error TS1156: const must be declared inside a block. + + + + \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-validContexts.errors.txt b/tests/baselines/reference/constDeclarations-validContexts.errors.txt new file mode 100644 index 00000000000..7af16a53cbe --- /dev/null +++ b/tests/baselines/reference/constDeclarations-validContexts.errors.txt @@ -0,0 +1,129 @@ +tests/cases/compiler/constDeclarations-validContexts.ts(20,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'. + + +==== tests/cases/compiler/constDeclarations-validContexts.ts (1 errors) ==== + + + // Control flow statements with blocks + if (true) { + const c1 = 0; + } + else { + const c2 = 0; + } + + while (true) { + const c3 = 0; + } + + do { + const c4 = 0; + } while (true); + + var obj; + with (obj) { + ~~~ +!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'. + const c5 = 0; + } + + for (var i = 0; i < 10; i++) { + const c6 = 0; + } + + for (var i2 in {}) { + const c7 = 0; + } + + if (true) { + label: const c8 = 0; + } + + while (false) { + label2: label3: label4: const c9 = 0; + } + + // Try/catch/finally + try { + const c10 = 0; + } + catch (e) { + const c11 = 0; + } + finally { + const c12 = 0; + } + + // Switch + switch (0) { + case 0: + const c13 = 0; + break; + default: + const c14 = 0; + break; + } + + // blocks + { + const c15 = 0; + { + const c16 = 0 + label17: const c17 = 0; + } + } + + // global + const c18 = 0; + + // functions + function F() { + const c19 = 0; + } + + var F2 = () => { + const c20 = 0; + }; + + var F3 = function () { + const c21 = 0; + }; + + // modules + module m { + const c22 = 0; + + { + const c23 = 0; + } + } + + // methods + class C { + constructor() { + const c24 = 0; + } + + method() { + const c25 = 0; + } + + get v() { + const c26 = 0; + return c26; + } + + set v(value) { + const c27 = value; + } + } + + // object literals + var o = { + f() { + const c28 = 0; + }, + f2: () => { + const c29 = 0; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-validContexts.js b/tests/baselines/reference/constDeclarations-validContexts.js new file mode 100644 index 00000000000..355f39af2f2 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-validContexts.js @@ -0,0 +1,229 @@ +//// [constDeclarations-validContexts.ts] + + +// Control flow statements with blocks +if (true) { + const c1 = 0; +} +else { + const c2 = 0; +} + +while (true) { + const c3 = 0; +} + +do { + const c4 = 0; +} while (true); + +var obj; +with (obj) { + const c5 = 0; +} + +for (var i = 0; i < 10; i++) { + const c6 = 0; +} + +for (var i2 in {}) { + const c7 = 0; +} + +if (true) { + label: const c8 = 0; +} + +while (false) { + label2: label3: label4: const c9 = 0; +} + +// Try/catch/finally +try { + const c10 = 0; +} +catch (e) { + const c11 = 0; +} +finally { + const c12 = 0; +} + +// Switch +switch (0) { + case 0: + const c13 = 0; + break; + default: + const c14 = 0; + break; +} + +// blocks +{ + const c15 = 0; + { + const c16 = 0 + label17: const c17 = 0; + } +} + +// global +const c18 = 0; + +// functions +function F() { + const c19 = 0; +} + +var F2 = () => { + const c20 = 0; +}; + +var F3 = function () { + const c21 = 0; +}; + +// modules +module m { + const c22 = 0; + + { + const c23 = 0; + } +} + +// methods +class C { + constructor() { + const c24 = 0; + } + + method() { + const c25 = 0; + } + + get v() { + const c26 = 0; + return c26; + } + + set v(value) { + const c27 = value; + } +} + +// object literals +var o = { + f() { + const c28 = 0; + }, + f2: () => { + const c29 = 0; + } +} + +//// [constDeclarations-validContexts.js] +// Control flow statements with blocks +if (true) { + const c1 = 0; +} +else { + const c2 = 0; +} +while (true) { + const c3 = 0; +} +do { + const c4 = 0; +} while (true); +var obj; +with (obj) { + const c5 = 0; +} +for (var i = 0; i < 10; i++) { + const c6 = 0; +} +for (var i2 in {}) { + const c7 = 0; +} +if (true) { + label: const c8 = 0; +} +while (false) { + label2: label3: label4: const c9 = 0; +} +try { + const c10 = 0; +} +catch (e) { + const c11 = 0; +} +finally { + const c12 = 0; +} +switch (0) { + case 0: + const c13 = 0; + break; + default: + const c14 = 0; + break; +} +{ + const c15 = 0; + { + const c16 = 0; + label17: const c17 = 0; + } +} +// global +const c18 = 0; +// functions +function F() { + const c19 = 0; +} +var F2 = function () { + const c20 = 0; +}; +var F3 = function () { + const c21 = 0; +}; +// modules +var m; +(function (m) { + const c22 = 0; + { + const c23 = 0; + } +})(m || (m = {})); +// methods +var C = (function () { + function C() { + const c24 = 0; + } + C.prototype.method = function () { + const c25 = 0; + }; + Object.defineProperty(C.prototype, "v", { + get: function () { + const c26 = 0; + return c26; + }, + set: function (value) { + const c27 = value; + }, + enumerable: true, + configurable: true + }); + return C; +})(); +// object literals +var o = { + f: function () { + const c28 = 0; + }, + f2: function () { + const c29 = 0; + } +}; diff --git a/tests/baselines/reference/letDeclarations-invalidContexts.errors.txt b/tests/baselines/reference/letDeclarations-invalidContexts.errors.txt new file mode 100644 index 00000000000..3877f61641a --- /dev/null +++ b/tests/baselines/reference/letDeclarations-invalidContexts.errors.txt @@ -0,0 +1,66 @@ +tests/cases/compiler/letDeclarations-invalidContexts.ts(4,5): error TS1157: let must be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(6,5): error TS1157: let must be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(9,5): error TS1157: let must be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(12,5): error TS1157: let must be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(17,5): error TS1157: let must be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(20,5): error TS1157: let must be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(23,5): error TS1157: let must be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(26,12): error TS1157: let must be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(29,29): error TS1157: let must be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(16,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'. + + +==== tests/cases/compiler/letDeclarations-invalidContexts.ts (10 errors) ==== + + // Errors, let must be defined inside a block + if (true) + let l1 = 0; + ~~~~~~~~~~~ +!!! error TS1157: let must be declared inside a block. + else + let l2 = 0; + ~~~~~~~~~~~ +!!! error TS1157: let must be declared inside a block. + + while (true) + let l3 = 0; + ~~~~~~~~~~~ +!!! error TS1157: let must be declared inside a block. + + do + let l4 = 0; + ~~~~~~~~~~~ +!!! error TS1157: let must be declared inside a block. + while (true); + + var obj; + with (obj) + ~~~ +!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'. + let l5 = 0; + ~~~~~~~~~~~ +!!! error TS1157: let must be declared inside a block. + + for (var i = 0; i < 10; i++) + let l6 = 0; + ~~~~~~~~~~~ +!!! error TS1157: let must be declared inside a block. + + for (var i2 in {}) + let l7 = 0; + ~~~~~~~~~~~ +!!! error TS1157: let must be declared inside a block. + + if (true) + label: let l8 = 0; + ~~~~~~~~~~~ +!!! error TS1157: let must be declared inside a block. + + while (false) + label2: label3: label4: let l9 = 0; + ~~~~~~~~~~~ +!!! error TS1157: let must be declared inside a block. + + + + \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-validContexts.errors.txt b/tests/baselines/reference/letDeclarations-validContexts.errors.txt new file mode 100644 index 00000000000..de6cf7beef4 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-validContexts.errors.txt @@ -0,0 +1,129 @@ +tests/cases/compiler/letDeclarations-validContexts.ts(20,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'. + + +==== tests/cases/compiler/letDeclarations-validContexts.ts (1 errors) ==== + + + // Control flow statements with blocks + if (true) { + let l1 = 0; + } + else { + let l2 = 0; + } + + while (true) { + let l3 = 0; + } + + do { + let l4 = 0; + } while (true); + + var obj; + with (obj) { + ~~~ +!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'. + let l5 = 0; + } + + for (var i = 0; i < 10; i++) { + let l6 = 0; + } + + for (var i2 in {}) { + let l7 = 0; + } + + if (true) { + label: let l8 = 0; + } + + while (false) { + label2: label3: label4: let l9 = 0; + } + + // Try/catch/finally + try { + let l10 = 0; + } + catch (e) { + let l11 = 0; + } + finally { + let l12 = 0; + } + + // Switch + switch (0) { + case 0: + let l13 = 0; + break; + default: + let l14 = 0; + break; + } + + // blocks + { + let l15 = 0; + { + let l16 = 0 + label17: let l17 = 0; + } + } + + // global + let l18 = 0; + + // functions + function F() { + let l19 = 0; + } + + var F2 = () => { + let l20 = 0; + }; + + var F3 = function () { + let l21 = 0; + }; + + // modules + module m { + let l22 = 0; + + { + let l23 = 0; + } + } + + // methods + class C { + constructor() { + let l24 = 0; + } + + method() { + let l25 = 0; + } + + get v() { + let l26 = 0; + return l26; + } + + set v(value) { + let l27 = value; + } + } + + // object literals + var o = { + f() { + let l28 = 0; + }, + f2: () => { + let l29 = 0; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-validContexts.js b/tests/baselines/reference/letDeclarations-validContexts.js new file mode 100644 index 00000000000..daa25014ab3 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-validContexts.js @@ -0,0 +1,229 @@ +//// [letDeclarations-validContexts.ts] + + +// Control flow statements with blocks +if (true) { + let l1 = 0; +} +else { + let l2 = 0; +} + +while (true) { + let l3 = 0; +} + +do { + let l4 = 0; +} while (true); + +var obj; +with (obj) { + let l5 = 0; +} + +for (var i = 0; i < 10; i++) { + let l6 = 0; +} + +for (var i2 in {}) { + let l7 = 0; +} + +if (true) { + label: let l8 = 0; +} + +while (false) { + label2: label3: label4: let l9 = 0; +} + +// Try/catch/finally +try { + let l10 = 0; +} +catch (e) { + let l11 = 0; +} +finally { + let l12 = 0; +} + +// Switch +switch (0) { + case 0: + let l13 = 0; + break; + default: + let l14 = 0; + break; +} + +// blocks +{ + let l15 = 0; + { + let l16 = 0 + label17: let l17 = 0; + } +} + +// global +let l18 = 0; + +// functions +function F() { + let l19 = 0; +} + +var F2 = () => { + let l20 = 0; +}; + +var F3 = function () { + let l21 = 0; +}; + +// modules +module m { + let l22 = 0; + + { + let l23 = 0; + } +} + +// methods +class C { + constructor() { + let l24 = 0; + } + + method() { + let l25 = 0; + } + + get v() { + let l26 = 0; + return l26; + } + + set v(value) { + let l27 = value; + } +} + +// object literals +var o = { + f() { + let l28 = 0; + }, + f2: () => { + let l29 = 0; + } +} + +//// [letDeclarations-validContexts.js] +// Control flow statements with blocks +if (true) { + let l1 = 0; +} +else { + let l2 = 0; +} +while (true) { + let l3 = 0; +} +do { + let l4 = 0; +} while (true); +var obj; +with (obj) { + let l5 = 0; +} +for (var i = 0; i < 10; i++) { + let l6 = 0; +} +for (var i2 in {}) { + let l7 = 0; +} +if (true) { + label: let l8 = 0; +} +while (false) { + label2: label3: label4: let l9 = 0; +} +try { + let l10 = 0; +} +catch (e) { + let l11 = 0; +} +finally { + let l12 = 0; +} +switch (0) { + case 0: + let l13 = 0; + break; + default: + let l14 = 0; + break; +} +{ + let l15 = 0; + { + let l16 = 0; + label17: let l17 = 0; + } +} +// global +let l18 = 0; +// functions +function F() { + let l19 = 0; +} +var F2 = function () { + let l20 = 0; +}; +var F3 = function () { + let l21 = 0; +}; +// modules +var m; +(function (m) { + let l22 = 0; + { + let l23 = 0; + } +})(m || (m = {})); +// methods +var C = (function () { + function C() { + let l24 = 0; + } + C.prototype.method = function () { + let l25 = 0; + }; + Object.defineProperty(C.prototype, "v", { + get: function () { + let l26 = 0; + return l26; + }, + set: function (value) { + let l27 = value; + }, + enumerable: true, + configurable: true + }); + return C; +})(); +// object literals +var o = { + f: function () { + let l28 = 0; + }, + f2: function () { + let l29 = 0; + } +}; diff --git a/tests/cases/compiler/constDeclarations-invalidContexts.ts b/tests/cases/compiler/constDeclarations-invalidContexts.ts new file mode 100644 index 00000000000..3da91a7d1d7 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-invalidContexts.ts @@ -0,0 +1,33 @@ +// @target: ES6 + +// Errors, const must be defined inside a block +if (true) + const c1 = 0; +else + const c2 = 0; + +while (true) + const c3 = 0; + +do + const c4 = 0; +while (true); + +var obj; +with (obj) + const c5 = 0; + +for (var i = 0; i < 10; i++) + const c6 = 0; + +for (var i2 in {}) + const c7 = 0; + +if (true) + label: const c8 = 0; + +while (false) + label2: label3: label4: const c9 = 0; + + + diff --git a/tests/cases/compiler/constDeclarations-validContexts.ts b/tests/cases/compiler/constDeclarations-validContexts.ts new file mode 100644 index 00000000000..ffde8e45d6f --- /dev/null +++ b/tests/cases/compiler/constDeclarations-validContexts.ts @@ -0,0 +1,124 @@ +// @target: ES6 + + +// Control flow statements with blocks +if (true) { + const c1 = 0; +} +else { + const c2 = 0; +} + +while (true) { + const c3 = 0; +} + +do { + const c4 = 0; +} while (true); + +var obj; +with (obj) { + const c5 = 0; +} + +for (var i = 0; i < 10; i++) { + const c6 = 0; +} + +for (var i2 in {}) { + const c7 = 0; +} + +if (true) { + label: const c8 = 0; +} + +while (false) { + label2: label3: label4: const c9 = 0; +} + +// Try/catch/finally +try { + const c10 = 0; +} +catch (e) { + const c11 = 0; +} +finally { + const c12 = 0; +} + +// Switch +switch (0) { + case 0: + const c13 = 0; + break; + default: + const c14 = 0; + break; +} + +// blocks +{ + const c15 = 0; + { + const c16 = 0 + label17: const c17 = 0; + } +} + +// global +const c18 = 0; + +// functions +function F() { + const c19 = 0; +} + +var F2 = () => { + const c20 = 0; +}; + +var F3 = function () { + const c21 = 0; +}; + +// modules +module m { + const c22 = 0; + + { + const c23 = 0; + } +} + +// methods +class C { + constructor() { + const c24 = 0; + } + + method() { + const c25 = 0; + } + + get v() { + const c26 = 0; + return c26; + } + + set v(value) { + const c27 = value; + } +} + +// object literals +var o = { + f() { + const c28 = 0; + }, + f2: () => { + const c29 = 0; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/letDeclarations-invalidContexts.ts b/tests/cases/compiler/letDeclarations-invalidContexts.ts new file mode 100644 index 00000000000..4d165ba2cda --- /dev/null +++ b/tests/cases/compiler/letDeclarations-invalidContexts.ts @@ -0,0 +1,33 @@ +// @target: ES6 + +// Errors, let must be defined inside a block +if (true) + let l1 = 0; +else + let l2 = 0; + +while (true) + let l3 = 0; + +do + let l4 = 0; +while (true); + +var obj; +with (obj) + let l5 = 0; + +for (var i = 0; i < 10; i++) + let l6 = 0; + +for (var i2 in {}) + let l7 = 0; + +if (true) + label: let l8 = 0; + +while (false) + label2: label3: label4: let l9 = 0; + + + diff --git a/tests/cases/compiler/letDeclarations-validContexts.ts b/tests/cases/compiler/letDeclarations-validContexts.ts new file mode 100644 index 00000000000..32801f2d009 --- /dev/null +++ b/tests/cases/compiler/letDeclarations-validContexts.ts @@ -0,0 +1,124 @@ +// @target: ES6 + + +// Control flow statements with blocks +if (true) { + let l1 = 0; +} +else { + let l2 = 0; +} + +while (true) { + let l3 = 0; +} + +do { + let l4 = 0; +} while (true); + +var obj; +with (obj) { + let l5 = 0; +} + +for (var i = 0; i < 10; i++) { + let l6 = 0; +} + +for (var i2 in {}) { + let l7 = 0; +} + +if (true) { + label: let l8 = 0; +} + +while (false) { + label2: label3: label4: let l9 = 0; +} + +// Try/catch/finally +try { + let l10 = 0; +} +catch (e) { + let l11 = 0; +} +finally { + let l12 = 0; +} + +// Switch +switch (0) { + case 0: + let l13 = 0; + break; + default: + let l14 = 0; + break; +} + +// blocks +{ + let l15 = 0; + { + let l16 = 0 + label17: let l17 = 0; + } +} + +// global +let l18 = 0; + +// functions +function F() { + let l19 = 0; +} + +var F2 = () => { + let l20 = 0; +}; + +var F3 = function () { + let l21 = 0; +}; + +// modules +module m { + let l22 = 0; + + { + let l23 = 0; + } +} + +// methods +class C { + constructor() { + let l24 = 0; + } + + method() { + let l25 = 0; + } + + get v() { + let l26 = 0; + return l26; + } + + set v(value) { + let l27 = value; + } +} + +// object literals +var o = { + f() { + let l28 = 0; + }, + f2: () => { + let l29 = 0; + } +} \ No newline at end of file From 6f6f4afeb1cd0e5be322d8de371e7b5db03bda2a Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Sun, 12 Oct 2014 21:44:29 -0700 Subject: [PATCH 04/63] Fix line endings --- .../decrementOperatorWithEnumType.errors.txt | 46 +++++++++--------- .../enumIdentifierLiterals.errors.txt | 48 +++++++++---------- .../reference/enumIdentifierLiterals.js | 24 +++++----- .../incrementOperatorWithEnumType.errors.txt | 40 ++++++++-------- .../reference/parserEnum7.errors.txt | 28 +++++------ tests/baselines/reference/parserEnum7.js | 20 ++++---- 6 files changed, 103 insertions(+), 103 deletions(-) diff --git a/tests/baselines/reference/decrementOperatorWithEnumType.errors.txt b/tests/baselines/reference/decrementOperatorWithEnumType.errors.txt index d43515e84ef..a0c30e9dc93 100644 --- a/tests/baselines/reference/decrementOperatorWithEnumType.errors.txt +++ b/tests/baselines/reference/decrementOperatorWithEnumType.errors.txt @@ -1,24 +1,24 @@ -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(7,23): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(12,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(12,7): error TS2304: Cannot find name 'A'. - - -==== tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts (3 errors) ==== - // -- operator on enum type - - enum ENUM1 { A, B, "" }; - - // expression - var ResultIsNumber1 = --ENUM1["A"]; - var ResultIsNumber2 = ENUM1.A--; - ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. - - // miss assignment operator - --ENUM1["A"]; - - ENUM1[A]--; - ~~~~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. - ~ +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(7,23): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(12,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(12,7): error TS2304: Cannot find name 'A'. + + +==== tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts (3 errors) ==== + // -- operator on enum type + + enum ENUM1 { A, B, "" }; + + // expression + var ResultIsNumber1 = --ENUM1["A"]; + var ResultIsNumber2 = ENUM1.A--; + ~~~~~~~ +!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. + + // miss assignment operator + --ENUM1["A"]; + + ENUM1[A]--; + ~~~~~~~~ +!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. + ~ !!! error TS2304: Cannot find name 'A'. \ No newline at end of file diff --git a/tests/baselines/reference/enumIdentifierLiterals.errors.txt b/tests/baselines/reference/enumIdentifierLiterals.errors.txt index 721a6bd29ff..6327e40289a 100644 --- a/tests/baselines/reference/enumIdentifierLiterals.errors.txt +++ b/tests/baselines/reference/enumIdentifierLiterals.errors.txt @@ -1,25 +1,25 @@ -tests/cases/compiler/enumIdentifierLiterals.ts(2,5): error TS1151: An enum member cannot have a numeric name. -tests/cases/compiler/enumIdentifierLiterals.ts(3,5): error TS1151: An enum member cannot have a numeric name. -tests/cases/compiler/enumIdentifierLiterals.ts(4,5): error TS1151: An enum member cannot have a numeric name. -tests/cases/compiler/enumIdentifierLiterals.ts(5,5): error TS1151: An enum member cannot have a numeric name. -tests/cases/compiler/enumIdentifierLiterals.ts(6,5): error TS1151: An enum member cannot have a numeric name. - - -==== tests/cases/compiler/enumIdentifierLiterals.ts (5 errors) ==== - enum Nums { - 1.0, - ~~~ -!!! error TS1151: An enum member cannot have a numeric name. - 11e-1, - ~~~~~ -!!! error TS1151: An enum member cannot have a numeric name. - 0.12e1, - ~~~~~~ -!!! error TS1151: An enum member cannot have a numeric name. - "13e-1", - ~~~~~~~ -!!! error TS1151: An enum member cannot have a numeric name. - 0xF00D - ~~~~~~ -!!! error TS1151: An enum member cannot have a numeric name. +tests/cases/compiler/enumIdentifierLiterals.ts(2,5): error TS1151: An enum member cannot have a numeric name. +tests/cases/compiler/enumIdentifierLiterals.ts(3,5): error TS1151: An enum member cannot have a numeric name. +tests/cases/compiler/enumIdentifierLiterals.ts(4,5): error TS1151: An enum member cannot have a numeric name. +tests/cases/compiler/enumIdentifierLiterals.ts(5,5): error TS1151: An enum member cannot have a numeric name. +tests/cases/compiler/enumIdentifierLiterals.ts(6,5): error TS1151: An enum member cannot have a numeric name. + + +==== tests/cases/compiler/enumIdentifierLiterals.ts (5 errors) ==== + enum Nums { + 1.0, + ~~~ +!!! error TS1151: An enum member cannot have a numeric name. + 11e-1, + ~~~~~ +!!! error TS1151: An enum member cannot have a numeric name. + 0.12e1, + ~~~~~~ +!!! error TS1151: An enum member cannot have a numeric name. + "13e-1", + ~~~~~~~ +!!! error TS1151: An enum member cannot have a numeric name. + 0xF00D + ~~~~~~ +!!! error TS1151: An enum member cannot have a numeric name. } \ No newline at end of file diff --git a/tests/baselines/reference/enumIdentifierLiterals.js b/tests/baselines/reference/enumIdentifierLiterals.js index 06cb76dd21d..72a8a56570c 100644 --- a/tests/baselines/reference/enumIdentifierLiterals.js +++ b/tests/baselines/reference/enumIdentifierLiterals.js @@ -1,18 +1,18 @@ -//// [enumIdentifierLiterals.ts] +//// [enumIdentifierLiterals.ts] enum Nums { 1.0, 11e-1, 0.12e1, "13e-1", 0xF00D -} - -//// [enumIdentifierLiterals.js] -var Nums; -(function (Nums) { - Nums[Nums["1"] = 0] = "1"; - Nums[Nums["1.1"] = 1] = "1.1"; - Nums[Nums["1.2"] = 2] = "1.2"; - Nums[Nums["13e-1"] = 3] = "13e-1"; - Nums[Nums["61453"] = 4] = "61453"; -})(Nums || (Nums = {})); +} + +//// [enumIdentifierLiterals.js] +var Nums; +(function (Nums) { + Nums[Nums["1"] = 0] = "1"; + Nums[Nums["1.1"] = 1] = "1.1"; + Nums[Nums["1.2"] = 2] = "1.2"; + Nums[Nums["13e-1"] = 3] = "13e-1"; + Nums[Nums["61453"] = 4] = "61453"; +})(Nums || (Nums = {})); diff --git a/tests/baselines/reference/incrementOperatorWithEnumType.errors.txt b/tests/baselines/reference/incrementOperatorWithEnumType.errors.txt index 7617dbba379..9bcf6c7612f 100644 --- a/tests/baselines/reference/incrementOperatorWithEnumType.errors.txt +++ b/tests/baselines/reference/incrementOperatorWithEnumType.errors.txt @@ -1,21 +1,21 @@ -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(7,23): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(12,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. - - -==== tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts (2 errors) ==== - // ++ operator on enum type - - enum ENUM1 { A, B, "" }; - - // expression - var ResultIsNumber1 = ++ENUM1["B"]; - var ResultIsNumber2 = ENUM1.B++; - ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. - - // miss assignment operator - ++ENUM1["B"]; - - ENUM1.B++; - ~~~~~~~ +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(7,23): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(12,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. + + +==== tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts (2 errors) ==== + // ++ operator on enum type + + enum ENUM1 { A, B, "" }; + + // expression + var ResultIsNumber1 = ++ENUM1["B"]; + var ResultIsNumber2 = ENUM1.B++; + ~~~~~~~ +!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. + + // miss assignment operator + ++ENUM1["B"]; + + ENUM1.B++; + ~~~~~~~ !!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. \ No newline at end of file diff --git a/tests/baselines/reference/parserEnum7.errors.txt b/tests/baselines/reference/parserEnum7.errors.txt index 48c938e02de..a4a2326546a 100644 --- a/tests/baselines/reference/parserEnum7.errors.txt +++ b/tests/baselines/reference/parserEnum7.errors.txt @@ -1,15 +1,15 @@ -tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts(2,3): error TS1151: An enum member cannot have a numeric name. -tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts(2,6): error TS1151: An enum member cannot have a numeric name. -tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts(2,9): error TS1151: An enum member cannot have a numeric name. - - -==== tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts (3 errors) ==== - enum E { - 1, 2, 3 - ~ -!!! error TS1151: An enum member cannot have a numeric name. - ~ -!!! error TS1151: An enum member cannot have a numeric name. - ~ -!!! error TS1151: An enum member cannot have a numeric name. +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts(2,3): error TS1151: An enum member cannot have a numeric name. +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts(2,6): error TS1151: An enum member cannot have a numeric name. +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts(2,9): error TS1151: An enum member cannot have a numeric name. + + +==== tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts (3 errors) ==== + enum E { + 1, 2, 3 + ~ +!!! error TS1151: An enum member cannot have a numeric name. + ~ +!!! error TS1151: An enum member cannot have a numeric name. + ~ +!!! error TS1151: An enum member cannot have a numeric name. } \ No newline at end of file diff --git a/tests/baselines/reference/parserEnum7.js b/tests/baselines/reference/parserEnum7.js index 831090f4ce7..3781167bbba 100644 --- a/tests/baselines/reference/parserEnum7.js +++ b/tests/baselines/reference/parserEnum7.js @@ -1,12 +1,12 @@ -//// [parserEnum7.ts] +//// [parserEnum7.ts] enum E { 1, 2, 3 -} - -//// [parserEnum7.js] -var E; -(function (E) { - E[E["1"] = 0] = "1"; - E[E["2"] = 1] = "2"; - E[E["3"] = 2] = "3"; -})(E || (E = {})); +} + +//// [parserEnum7.js] +var E; +(function (E) { + E[E["1"] = 0] = "1"; + E[E["2"] = 1] = "2"; + E[E["3"] = 2] = "3"; +})(E || (E = {})); From cf89f5cf589213510ab9b30f67050592118b60be Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 13 Oct 2014 20:54:26 -0700 Subject: [PATCH 05/63] Add binder support for block scoped variable declarations --- src/compiler/binder.ts | 112 +++++-- src/compiler/types.ts | 12 +- .../constDeclarations-errors.errors.txt | 11 +- .../constDeclarations-scopes.errors.txt | 153 +++++++++ .../reference/constDeclarations-scopes.js | 276 +++++++++++++++++ ...tDeclarations-scopes-duplicates.errors.txt | 152 +++++++++ .../letDeclarations-scopes-duplicates.js | 140 +++++++++ .../letDeclarations-scopes.errors.txt | 161 ++++++++++ .../reference/letDeclarations-scopes.js | 290 ++++++++++++++++++ .../letDeclarations-scopes2.errors.txt | 42 +++ .../reference/letDeclarations-scopes2.js | 49 +++ .../compiler/constDeclarations-scopes.ts | 148 +++++++++ .../letDeclarations-scopes-duplicates.ts | 77 +++++ .../cases/compiler/letDeclarations-scopes.ts | 156 ++++++++++ .../cases/compiler/letDeclarations-scopes2.ts | 27 ++ 15 files changed, 1766 insertions(+), 40 deletions(-) create mode 100644 tests/baselines/reference/constDeclarations-scopes.errors.txt create mode 100644 tests/baselines/reference/constDeclarations-scopes.js create mode 100644 tests/baselines/reference/letDeclarations-scopes-duplicates.errors.txt create mode 100644 tests/baselines/reference/letDeclarations-scopes-duplicates.js create mode 100644 tests/baselines/reference/letDeclarations-scopes.errors.txt create mode 100644 tests/baselines/reference/letDeclarations-scopes.js create mode 100644 tests/baselines/reference/letDeclarations-scopes2.errors.txt create mode 100644 tests/baselines/reference/letDeclarations-scopes2.js create mode 100644 tests/cases/compiler/constDeclarations-scopes.ts create mode 100644 tests/cases/compiler/letDeclarations-scopes-duplicates.ts create mode 100644 tests/cases/compiler/letDeclarations-scopes.ts create mode 100644 tests/cases/compiler/letDeclarations-scopes2.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index c9f9d6bf6e3..0760f33ce67 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -31,13 +31,14 @@ module ts { var parent: Node; var container: Declaration; + var blockScopeContainer: Node; var lastContainer: Declaration; var symbolCount = 0; var Symbol = objectAllocator.getSymbolConstructor(); if (!file.locals) { file.locals = {}; - container = file; + container = blockScopeContainer = file; bind(file); file.symbolCount = symbolCount; } @@ -167,12 +168,13 @@ module ts { // All container nodes are kept on a linked list in declaration order. This list is used by the getLocalNameOfContainer function // in the type checker to validate that the local name used for a container is unique. - function bindChildren(node: Declaration, symbolKind: SymbolFlags) { + function bindChildren(node: Declaration, symbolKind: SymbolFlags, isBlockScopeContainer: boolean) { if (symbolKind & SymbolFlags.HasLocals) { node.locals = {}; } var saveParent = parent; var saveContainer = container; + var savedBlockScopeContainer = blockScopeContainer; parent = node; if (symbolKind & SymbolFlags.IsContainer) { container = node; @@ -184,12 +186,16 @@ module ts { lastContainer = container; } } + if (isBlockScopeContainer) { + blockScopeContainer = node; + } forEachChild(node, bind); container = saveContainer; parent = saveParent; + blockScopeContainer = savedBlockScopeContainer; } - function bindDeclaration(node: Declaration, symbolKind: SymbolFlags, symbolExcludes: SymbolFlags) { + function bindDeclaration(node: Declaration, symbolKind: SymbolFlags, symbolExcludes: SymbolFlags, isBlockScopeContainer: boolean) { switch (container.kind) { case SyntaxKind.ModuleDeclaration: declareModuleMember(node, symbolKind, symbolExcludes); @@ -225,126 +231,168 @@ module ts { declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); break; } - bindChildren(node, symbolKind); + bindChildren(node, symbolKind, isBlockScopeContainer); } function bindConstructorDeclaration(node: ConstructorDeclaration) { - bindDeclaration(node, SymbolFlags.Constructor, 0); + bindDeclaration(node, SymbolFlags.Constructor, 0, /*isBlockScopeContainer*/ true); forEach(node.parameters, p => { if (p.flags & (NodeFlags.Public | NodeFlags.Private | NodeFlags.Protected)) { - bindDeclaration(p, SymbolFlags.Property, SymbolFlags.PropertyExcludes); + bindDeclaration(p, SymbolFlags.Property, SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false); } }); } function bindModuleDeclaration(node: ModuleDeclaration) { if (node.name.kind === SyntaxKind.StringLiteral) { - bindDeclaration(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes); + bindDeclaration(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes, /*isBlockScopeContainer*/ true); } else if (isInstantiated(node)) { - bindDeclaration(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes); + bindDeclaration(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes, /*isBlockScopeContainer*/ true); } else { - bindDeclaration(node, SymbolFlags.NamespaceModule, SymbolFlags.NamespaceModuleExcludes); + bindDeclaration(node, SymbolFlags.NamespaceModule, SymbolFlags.NamespaceModuleExcludes, /*isBlockScopeContainer*/ true); } } - function bindAnonymousDeclaration(node: Node, symbolKind: SymbolFlags, name: string) { + function bindAnonymousDeclaration(node: Node, symbolKind: SymbolFlags, name: string, isBlockScopeContainer: boolean) { var symbol = createSymbol(symbolKind, name); addDeclarationToSymbol(symbol, node, symbolKind); - bindChildren(node, symbolKind); + bindChildren(node, symbolKind, isBlockScopeContainer); } function bindCatchVariableDeclaration(node: CatchBlock) { var symbol = createSymbol(SymbolFlags.Variable, node.variable.text || "__missing"); addDeclarationToSymbol(symbol, node, SymbolFlags.Variable); var saveParent = parent; - parent = node; + var savedBlockScopeContainer = blockScopeContainer; + parent = blockScopeContainer = node; forEachChild(node, bind); parent = saveParent; + blockScopeContainer = savedBlockScopeContainer; + } + + function bindBlockScopedVariableDeclaration(node: Declaration) { + var symbolKind = SymbolFlags.Variable | SymbolFlags.BlockScoped; + switch (blockScopeContainer.kind) { + case SyntaxKind.ModuleDeclaration: + declareModuleMember(node, symbolKind, SymbolFlags.BlockScopedExcludes); + break; + case SyntaxKind.SourceFile: + if (isExternalModule(container)) { + declareModuleMember(node, symbolKind, SymbolFlags.BlockScopedExcludes); + break; + } + default: + if (!blockScopeContainer.locals) { + blockScopeContainer.locals = {}; + } + declareSymbol(blockScopeContainer.locals, undefined, node, symbolKind, SymbolFlags.BlockScopedExcludes); + } + + bindChildren(node, symbolKind, /*isBlockScopeContainer*/ false); } function bind(node: Node) { + var isBlockScopeContainer: boolean; node.parent = parent; switch (node.kind) { case SyntaxKind.TypeParameter: - bindDeclaration(node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes); + bindDeclaration(node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.Parameter: - bindDeclaration(node, SymbolFlags.Variable, SymbolFlags.ParameterExcludes); + bindDeclaration(node, SymbolFlags.Variable, SymbolFlags.ParameterExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.VariableDeclaration: - bindDeclaration(node, SymbolFlags.Variable, SymbolFlags.VariableExcludes); + if (node.flags & NodeFlags.BlockScoped) { + bindBlockScopedVariableDeclaration(node); + } + else { + bindDeclaration(node, SymbolFlags.Variable, SymbolFlags.VariableExcludes, /*isBlockScopeContainer*/ false); + } break; case SyntaxKind.Property: case SyntaxKind.PropertyAssignment: - bindDeclaration(node, SymbolFlags.Property, SymbolFlags.PropertyExcludes); + bindDeclaration(node, SymbolFlags.Property, SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.EnumMember: - bindDeclaration(node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes); + bindDeclaration(node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.CallSignature: - bindDeclaration(node, SymbolFlags.CallSignature, 0); + bindDeclaration(node, SymbolFlags.CallSignature, 0, /*isBlockScopeContainer*/ false); break; case SyntaxKind.Method: - bindDeclaration(node, SymbolFlags.Method, SymbolFlags.MethodExcludes); + bindDeclaration(node, SymbolFlags.Method, SymbolFlags.MethodExcludes, /*isBlockScopeContainer*/ true); break; case SyntaxKind.ConstructSignature: - bindDeclaration(node, SymbolFlags.ConstructSignature, 0); + bindDeclaration(node, SymbolFlags.ConstructSignature, 0, /*isBlockScopeContainer*/ true); break; case SyntaxKind.IndexSignature: - bindDeclaration(node, SymbolFlags.IndexSignature, 0); + bindDeclaration(node, SymbolFlags.IndexSignature, 0, /*isBlockScopeContainer*/ false); break; case SyntaxKind.FunctionDeclaration: - bindDeclaration(node, SymbolFlags.Function, SymbolFlags.FunctionExcludes); + bindDeclaration(node, SymbolFlags.Function, SymbolFlags.FunctionExcludes, /*isBlockScopeContainer*/ true); break; case SyntaxKind.Constructor: bindConstructorDeclaration(node); break; case SyntaxKind.GetAccessor: - bindDeclaration(node, SymbolFlags.GetAccessor, SymbolFlags.GetAccessorExcludes); + bindDeclaration(node, SymbolFlags.GetAccessor, SymbolFlags.GetAccessorExcludes, /*isBlockScopeContainer*/ true); break; case SyntaxKind.SetAccessor: - bindDeclaration(node, SymbolFlags.SetAccessor, SymbolFlags.SetAccessorExcludes); + bindDeclaration(node, SymbolFlags.SetAccessor, SymbolFlags.SetAccessorExcludes, /*isBlockScopeContainer*/ true); break; case SyntaxKind.TypeLiteral: - bindAnonymousDeclaration(node, SymbolFlags.TypeLiteral, "__type"); + bindAnonymousDeclaration(node, SymbolFlags.TypeLiteral, "__type", /*isBlockScopeContainer*/ false); break; case SyntaxKind.ObjectLiteral: - bindAnonymousDeclaration(node, SymbolFlags.ObjectLiteral, "__object"); + bindAnonymousDeclaration(node, SymbolFlags.ObjectLiteral, "__object", /*isBlockScopeContainer*/ false); break; case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: - bindAnonymousDeclaration(node, SymbolFlags.Function, "__function"); + bindAnonymousDeclaration(node, SymbolFlags.Function, "__function", /*isBlockScopeContainer*/ true); break; case SyntaxKind.CatchBlock: bindCatchVariableDeclaration(node); break; case SyntaxKind.ClassDeclaration: - bindDeclaration(node, SymbolFlags.Class, SymbolFlags.ClassExcludes); + bindDeclaration(node, SymbolFlags.Class, SymbolFlags.ClassExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.InterfaceDeclaration: - bindDeclaration(node, SymbolFlags.Interface, SymbolFlags.InterfaceExcludes); + bindDeclaration(node, SymbolFlags.Interface, SymbolFlags.InterfaceExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.EnumDeclaration: - bindDeclaration(node, SymbolFlags.Enum, SymbolFlags.EnumExcludes); + bindDeclaration(node, SymbolFlags.Enum, SymbolFlags.EnumExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.ModuleDeclaration: bindModuleDeclaration(node); break; case SyntaxKind.ImportDeclaration: - bindDeclaration(node, SymbolFlags.Import, SymbolFlags.ImportExcludes); + bindDeclaration(node, SymbolFlags.Import, SymbolFlags.ImportExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.SourceFile: if (isExternalModule(node)) { - bindAnonymousDeclaration(node, SymbolFlags.ValueModule, '"' + removeFileExtension((node).filename) + '"'); + bindAnonymousDeclaration(node, SymbolFlags.ValueModule, '"' + removeFileExtension((node).filename) + '"', /*isBlockScopeContainer*/ true); break; } + + case SyntaxKind.Block: + case SyntaxKind.TryBlock: + case SyntaxKind.CatchBlock: + case SyntaxKind.FinallyBlock: + case SyntaxKind.ForStatement: + case SyntaxKind.ForInStatement: + case SyntaxKind.SwitchStatement: + isBlockScopeContainer = true; + default: var saveParent = parent; + var savedBlockScopeContainer = blockScopeContainer; parent = node; + if (isBlockScopeContainer) blockScopeContainer = node; forEachChild(node, bind); parent = saveParent; + blockScopeContainer = savedBlockScopeContainer; } } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 4218d4f4011..09cd613e8f3 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -245,11 +245,12 @@ module ts { MultiLine = 0x00000100, // Multi-line array or object literal Synthetic = 0x00000200, // Synthetic node (for full fidelity) DeclarationFile = 0x00000400, // Node is a .d.ts file - Let = 0x00000800, - Const = 0x00001000, + Let = 0x00000800, // Variable declaration + Const = 0x00001000, // Variable declaration Modifier = Export | Ambient | Public | Private | Protected | Static, - AccessibilityModifier = Public | Private | Protected + AccessibilityModifier = Public | Private | Protected, + BlockScoped = Let | Const } export interface Node extends TextRange { @@ -768,6 +769,8 @@ module ts { Undefined = 0x08000000, // Symbol for the undefined + BlockScoped = 0x10000000, + Value = Variable | Property | EnumMember | Function | Class | Enum | ValueModule | Method | GetAccessor | SetAccessor, Type = Class | Interface | Enum | TypeLiteral | ObjectLiteral | TypeParameter, Namespace = ValueModule | NamespaceModule, @@ -776,7 +779,8 @@ module ts { Signature = CallSignature | ConstructSignature | IndexSignature, ParameterExcludes = Value, - VariableExcludes = Value & ~Variable, + VariableExcludes = (Value | BlockScoped) & ~Variable, + BlockScopedExcludes = Value, PropertyExcludes = Value, EnumMemberExcludes = Value, FunctionExcludes = Value & ~(Function | ValueModule), diff --git a/tests/baselines/reference/constDeclarations-errors.errors.txt b/tests/baselines/reference/constDeclarations-errors.errors.txt index 79d56ade878..9a922ac93a9 100644 --- a/tests/baselines/reference/constDeclarations-errors.errors.txt +++ b/tests/baselines/reference/constDeclarations-errors.errors.txt @@ -13,10 +13,11 @@ tests/cases/compiler/constDeclarations-errors.ts(8,18): error TS1128: Declaratio tests/cases/compiler/constDeclarations-errors.ts(10,5): error TS1109: Expression expected. tests/cases/compiler/constDeclarations-errors.ts(10,5): error TS1156: const must be declared inside a block. tests/cases/compiler/constDeclarations-errors.ts(10,28): error TS1005: ';' expected. -tests/cases/compiler/constDeclarations-errors.ts(10,11): error TS2403: Subsequent variable declarations must have the same type. Variable 'c' must be of type 'any', but here has type 'number'. +tests/cases/compiler/constDeclarations-errors.ts(10,18): error TS2304: Cannot find name 'c'. +tests/cases/compiler/constDeclarations-errors.ts(10,25): error TS2304: Cannot find name 'c'. -==== tests/cases/compiler/constDeclarations-errors.ts (16 errors) ==== +==== tests/cases/compiler/constDeclarations-errors.ts (17 errors) ==== // error, missing intialicer const c1; @@ -57,6 +58,8 @@ tests/cases/compiler/constDeclarations-errors.ts(10,11): error TS2403: Subsequen !!! error TS1156: const must be declared inside a block. ~ !!! error TS1005: ';' expected. - ~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'c' must be of type 'any', but here has type 'number'. + ~ +!!! error TS2304: Cannot find name 'c'. + ~ +!!! error TS2304: Cannot find name 'c'. \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-scopes.errors.txt b/tests/baselines/reference/constDeclarations-scopes.errors.txt new file mode 100644 index 00000000000..138acd9b16d --- /dev/null +++ b/tests/baselines/reference/constDeclarations-scopes.errors.txt @@ -0,0 +1,153 @@ +tests/cases/compiler/constDeclarations-scopes.ts(28,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'. + + +==== tests/cases/compiler/constDeclarations-scopes.ts (1 errors) ==== + + // global + const c = "string"; + + var n: number; + + // Control flow statements with blocks + if (true) { + const c = 0; + n = c; + } + else { + const c = 0; + n = c; + } + + while (true) { + const c = 0; + n = c; + } + + do { + const c = 0; + n = c; + } while (true); + + var obj; + with (obj) { + ~~~ +!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'. + const c = 0; + n = c; + } + + for (var i = 0; i < 10; i++) { + const c = 0; + n = c; + } + + for (var i2 in {}) { + const c = 0; + n = c; + } + + if (true) { + label: const c = 0; + n = c; + } + + while (false) { + label2: label3: label4: const c = 0; + n = c; + } + + // Try/catch/finally + try { + const c = 0; + n = c; + } + catch (e) { + const c = 0; + n = c; + } + finally { + const c = 0; + n = c; + } + + // Switch + switch (0) { + case 0: + const c = 0; + n = c; + break; + } + + // blocks + { + const c = 0; + n = c; + { + const c = false; + var b: boolean = c; + } + } + + // functions + + function F() { + const c = 0; + n = c; + } + + var F2 = () => { + const c = 0; + n = c; + }; + + var F3 = function () { + const c = 0; + n = c; + }; + + // modules + module m { + const c = 0; + n = c; + + { + const c = false; + var b2: boolean = c; + } + } + + // methods + class C { + constructor() { + const c = 0; + n = c; + } + + method() { + const c = 0; + n = c; + } + + get v() { + const c = 0; + n = c; + return n; + } + + set v(value) { + const c = 0; + n = c; + } + } + + // object literals + var o = { + f() { + const c = 0; + n = c; + }, + f2: () => { + const c = 0; + n = c; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-scopes.js b/tests/baselines/reference/constDeclarations-scopes.js new file mode 100644 index 00000000000..800dd856422 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-scopes.js @@ -0,0 +1,276 @@ +//// [constDeclarations-scopes.ts] + +// global +const c = "string"; + +var n: number; + +// Control flow statements with blocks +if (true) { + const c = 0; + n = c; +} +else { + const c = 0; + n = c; +} + +while (true) { + const c = 0; + n = c; +} + +do { + const c = 0; + n = c; +} while (true); + +var obj; +with (obj) { + const c = 0; + n = c; +} + +for (var i = 0; i < 10; i++) { + const c = 0; + n = c; +} + +for (var i2 in {}) { + const c = 0; + n = c; +} + +if (true) { + label: const c = 0; + n = c; +} + +while (false) { + label2: label3: label4: const c = 0; + n = c; +} + +// Try/catch/finally +try { + const c = 0; + n = c; +} +catch (e) { + const c = 0; + n = c; +} +finally { + const c = 0; + n = c; +} + +// Switch +switch (0) { + case 0: + const c = 0; + n = c; + break; +} + +// blocks +{ + const c = 0; + n = c; + { + const c = false; + var b: boolean = c; + } +} + +// functions + +function F() { + const c = 0; + n = c; +} + +var F2 = () => { + const c = 0; + n = c; +}; + +var F3 = function () { + const c = 0; + n = c; +}; + +// modules +module m { + const c = 0; + n = c; + + { + const c = false; + var b2: boolean = c; + } +} + +// methods +class C { + constructor() { + const c = 0; + n = c; + } + + method() { + const c = 0; + n = c; + } + + get v() { + const c = 0; + n = c; + return n; + } + + set v(value) { + const c = 0; + n = c; + } +} + +// object literals +var o = { + f() { + const c = 0; + n = c; + }, + f2: () => { + const c = 0; + n = c; + } +} + +//// [constDeclarations-scopes.js] +// global +const c = "string"; +var n; +// Control flow statements with blocks +if (true) { + const c = 0; + n = c; +} +else { + const c = 0; + n = c; +} +while (true) { + const c = 0; + n = c; +} +do { + const c = 0; + n = c; +} while (true); +var obj; +with (obj) { + const c = 0; + n = c; +} +for (var i = 0; i < 10; i++) { + const c = 0; + n = c; +} +for (var i2 in {}) { + const c = 0; + n = c; +} +if (true) { + label: const c = 0; + n = c; +} +while (false) { + label2: label3: label4: const c = 0; + n = c; +} +try { + const c = 0; + n = c; +} +catch (e) { + const c = 0; + n = c; +} +finally { + const c = 0; + n = c; +} +switch (0) { + case 0: + const c = 0; + n = c; + break; +} +{ + const c = 0; + n = c; + { + const c = false; + var b = c; + } +} +// functions +function F() { + const c = 0; + n = c; +} +var F2 = function () { + const c = 0; + n = c; +}; +var F3 = function () { + const c = 0; + n = c; +}; +// modules +var m; +(function (m) { + const c = 0; + n = c; + { + const c = false; + var b2 = c; + } +})(m || (m = {})); +// methods +var C = (function () { + function C() { + const c = 0; + n = c; + } + C.prototype.method = function () { + const c = 0; + n = c; + }; + Object.defineProperty(C.prototype, "v", { + get: function () { + const c = 0; + n = c; + return n; + }, + set: function (value) { + const c = 0; + n = c; + }, + enumerable: true, + configurable: true + }); + return C; +})(); +// object literals +var o = { + f: function () { + const c = 0; + n = c; + }, + f2: function () { + const c = 0; + n = c; + } +}; diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates.errors.txt new file mode 100644 index 00000000000..41d2813f7c4 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates.errors.txt @@ -0,0 +1,152 @@ +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(3,5): error TS2300: Duplicate identifier 'var1'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(4,5): error TS2300: Duplicate identifier 'var1'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(6,5): error TS2300: Duplicate identifier 'var2'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(7,7): error TS2300: Duplicate identifier 'var2'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(9,7): error TS2300: Duplicate identifier 'var3'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(10,5): error TS2300: Duplicate identifier 'var3'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(12,7): error TS2300: Duplicate identifier 'var4'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(13,7): error TS2300: Duplicate identifier 'var4'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(15,5): error TS2300: Duplicate identifier 'var5'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(16,5): error TS2300: Duplicate identifier 'var5'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(18,5): error TS2300: Duplicate identifier 'var6'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(19,5): error TS2300: Duplicate identifier 'var6'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(22,9): error TS2300: Duplicate identifier 'var7'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(23,9): error TS2300: Duplicate identifier 'var7'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(25,13): error TS2300: Duplicate identifier 'var8'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(26,15): error TS2300: Duplicate identifier 'var8'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(32,13): error TS2300: Duplicate identifier 'var9'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(33,13): error TS2300: Duplicate identifier 'var9'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(37,11): error TS2300: Duplicate identifier 'var10'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(38,11): error TS2300: Duplicate identifier 'var10'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(41,9): error TS2300: Duplicate identifier 'var11'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(42,9): error TS2300: Duplicate identifier 'var11'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(46,9): error TS2300: Duplicate identifier 'var12'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(47,9): error TS2300: Duplicate identifier 'var12'. + + +==== tests/cases/compiler/letDeclarations-scopes-duplicates.ts (24 errors) ==== + + // Errors: redeclaration + let var1 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var1'. + let var1 = 0; // error + ~~~~ +!!! error TS2300: Duplicate identifier 'var1'. + + let var2 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var2'. + const var2 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var2'. + + const var3 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var3'. + let var3 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var3'. + + const var4 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var4'. + const var4 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var4'. + + var var5 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var5'. + let var5 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var5'. + + let var6 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var6'. + var var6 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var6'. + + { + let var7 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var7'. + let var7 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var7'. + { + let var8 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var8'. + const var8 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var8'. + } + } + + switch (0) { + default: + let var9 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var9'. + let var9 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var9'. + } + + try { + const var10 = 0; + ~~~~~ +!!! error TS2300: Duplicate identifier 'var10'. + const var10 = 0; + ~~~~~ +!!! error TS2300: Duplicate identifier 'var10'. + } + catch (e) { + let var11 = 0; + ~~~~~ +!!! error TS2300: Duplicate identifier 'var11'. + let var11 = 0; + ~~~~~ +!!! error TS2300: Duplicate identifier 'var11'. + } + + function F1() { + let var12; + ~~~~~ +!!! error TS2300: Duplicate identifier 'var12'. + let var12; + ~~~~~ +!!! error TS2300: Duplicate identifier 'var12'. + } + + // OK + var var20 = 0; + + var var20 = 0 + { + let var20 = 0; + { + let var20 = 0; + } + } + + switch (0) { + default: + let var20 = 0; + } + + try { + let var20 = 0; + } + catch (e) { + let var20 = 0; + } + + function F() { + let var20; + } + + \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates.js b/tests/baselines/reference/letDeclarations-scopes-duplicates.js new file mode 100644 index 00000000000..c7d2ef9863a --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates.js @@ -0,0 +1,140 @@ +//// [letDeclarations-scopes-duplicates.ts] + +// Errors: redeclaration +let var1 = 0; +let var1 = 0; // error + +let var2 = 0; +const var2 = 0; + +const var3 = 0; +let var3 = 0; + +const var4 = 0; +const var4 = 0; + +var var5 = 0; +let var5 = 0; + +let var6 = 0; +var var6 = 0; + +{ + let var7 = 0; + let var7 = 0; + { + let var8 = 0; + const var8 = 0; + } +} + +switch (0) { + default: + let var9 = 0; + let var9 = 0; +} + +try { + const var10 = 0; + const var10 = 0; +} +catch (e) { + let var11 = 0; + let var11 = 0; +} + +function F1() { + let var12; + let var12; +} + +// OK +var var20 = 0; + +var var20 = 0 +{ + let var20 = 0; + { + let var20 = 0; + } +} + +switch (0) { + default: + let var20 = 0; +} + +try { + let var20 = 0; +} +catch (e) { + let var20 = 0; +} + +function F() { + let var20; +} + + + +//// [letDeclarations-scopes-duplicates.js] +// Errors: redeclaration +let var1 = 0; +let var1 = 0; // error +let var2 = 0; +const var2 = 0; +const var3 = 0; +let var3 = 0; +const var4 = 0; +const var4 = 0; +var var5 = 0; +let var5 = 0; +let var6 = 0; +var var6 = 0; +{ + let var7 = 0; + let var7 = 0; + { + let var8 = 0; + const var8 = 0; + } +} +switch (0) { + default: + let var9 = 0; + let var9 = 0; +} +try { + const var10 = 0; + const var10 = 0; +} +catch (e) { + let var11 = 0; + let var11 = 0; +} +function F1() { + let var12; + let var12; +} +// OK +var var20 = 0; +var var20 = 0; +{ + let var20 = 0; + { + let var20 = 0; + } +} +switch (0) { + default: + let var20 = 0; +} +try { + let var20 = 0; +} +catch (e) { + let var20 = 0; +} +function F() { + let var20; +} diff --git a/tests/baselines/reference/letDeclarations-scopes.errors.txt b/tests/baselines/reference/letDeclarations-scopes.errors.txt new file mode 100644 index 00000000000..df54e0fc3c4 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes.errors.txt @@ -0,0 +1,161 @@ +tests/cases/compiler/letDeclarations-scopes.ts(28,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'. + + +==== tests/cases/compiler/letDeclarations-scopes.ts (1 errors) ==== + + // global + let l = "string"; + + var n: number; + + // Control flow statements with blocks + if (true) { + let l = 0; + n = l; + } + else { + let l = 0; + n = l; + } + + while (true) { + let l = 0; + n = l; + } + + do { + let l = 0; + n = l; + } while (true); + + var obj; + with (obj) { + ~~~ +!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'. + let l = 0; + n = l; + } + + for (var i = 0; i < 10; i++) { + let l = 0; + n = l; + } + + for (var i2 in {}) { + let l = 0; + n = l; + } + + if (true) { + label: let l = 0; + n = l; + } + + while (false) { + label2: label3: label4: let l = 0; + n = l; + } + + for (let l = 0; n = l; l++) { + let l = true; + var b3: boolean = l; + } + + for (let l in {}) { + + } + + // Try/catch/finally + try { + let l = 0; + n = l; + } + catch (e) { + let l = 0; + n = l; + } + finally { + let l = 0; + n = l; + } + + // Switch + switch (0) { + case 0: + let l = 0; + n = l; + break; + } + + // blocks + { + let l = 0; + n = l; + { + let l = false; + var b: boolean = l; + } + } + + // functions + function F() { + let l = 0; + n = l; + } + + var F2 = () => { + let l = 0; + n = l; + }; + + var F3 = function () { + let l = 0; + n = l; + }; + + // modules + module m { + let l = 0; + n = l; + + { + let l = false; + var b2: boolean = l; + } + } + + // methods + class C { + constructor() { + let l = 0; + n = l; + } + + method() { + let l = 0; + n = l; + } + + get v() { + let l = 0; + n = l; + return n; + } + + set v(value) { + let l = 0; + n = l; + } + } + + // object literals + var o = { + f() { + let l = 0; + n = l; + }, + f2: () => { + let l = 0; + n = l; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes.js b/tests/baselines/reference/letDeclarations-scopes.js new file mode 100644 index 00000000000..59d42368b6c --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes.js @@ -0,0 +1,290 @@ +//// [letDeclarations-scopes.ts] + +// global +let l = "string"; + +var n: number; + +// Control flow statements with blocks +if (true) { + let l = 0; + n = l; +} +else { + let l = 0; + n = l; +} + +while (true) { + let l = 0; + n = l; +} + +do { + let l = 0; + n = l; +} while (true); + +var obj; +with (obj) { + let l = 0; + n = l; +} + +for (var i = 0; i < 10; i++) { + let l = 0; + n = l; +} + +for (var i2 in {}) { + let l = 0; + n = l; +} + +if (true) { + label: let l = 0; + n = l; +} + +while (false) { + label2: label3: label4: let l = 0; + n = l; +} + +for (let l = 0; n = l; l++) { + let l = true; + var b3: boolean = l; +} + +for (let l in {}) { + +} + +// Try/catch/finally +try { + let l = 0; + n = l; +} +catch (e) { + let l = 0; + n = l; +} +finally { + let l = 0; + n = l; +} + +// Switch +switch (0) { + case 0: + let l = 0; + n = l; + break; +} + +// blocks +{ + let l = 0; + n = l; + { + let l = false; + var b: boolean = l; + } +} + +// functions +function F() { + let l = 0; + n = l; +} + +var F2 = () => { + let l = 0; +n = l; +}; + +var F3 = function () { + let l = 0; +n = l; +}; + +// modules +module m { + let l = 0; + n = l; + + { + let l = false; + var b2: boolean = l; + } +} + +// methods +class C { + constructor() { + let l = 0; + n = l; + } + + method() { + let l = 0; + n = l; + } + + get v() { + let l = 0; + n = l; + return n; + } + + set v(value) { + let l = 0; + n = l; + } +} + +// object literals +var o = { + f() { + let l = 0; +n = l; + }, +f2: () => { + let l = 0; + n = l; + } +} + +//// [letDeclarations-scopes.js] +// global +let l = "string"; +var n; +// Control flow statements with blocks +if (true) { + let l = 0; + n = l; +} +else { + let l = 0; + n = l; +} +while (true) { + let l = 0; + n = l; +} +do { + let l = 0; + n = l; +} while (true); +var obj; +with (obj) { + let l = 0; + n = l; +} +for (var i = 0; i < 10; i++) { + let l = 0; + n = l; +} +for (var i2 in {}) { + let l = 0; + n = l; +} +if (true) { + label: let l = 0; + n = l; +} +while (false) { + label2: label3: label4: let l = 0; + n = l; +} +for (let l = 0; n = l; l++) { + let l = true; + var b3 = l; +} +for (let l in {}) { +} +try { + let l = 0; + n = l; +} +catch (e) { + let l = 0; + n = l; +} +finally { + let l = 0; + n = l; +} +switch (0) { + case 0: + let l = 0; + n = l; + break; +} +{ + let l = 0; + n = l; + { + let l = false; + var b = l; + } +} +// functions +function F() { + let l = 0; + n = l; +} +var F2 = function () { + let l = 0; + n = l; +}; +var F3 = function () { + let l = 0; + n = l; +}; +// modules +var m; +(function (m) { + let l = 0; + n = l; + { + let l = false; + var b2 = l; + } +})(m || (m = {})); +// methods +var C = (function () { + function C() { + let l = 0; + n = l; + } + C.prototype.method = function () { + let l = 0; + n = l; + }; + Object.defineProperty(C.prototype, "v", { + get: function () { + let l = 0; + n = l; + return n; + }, + set: function (value) { + let l = 0; + n = l; + }, + enumerable: true, + configurable: true + }); + return C; +})(); +// object literals +var o = { + f: function () { + let l = 0; + n = l; + }, + f2: function () { + let l = 0; + n = l; + } +}; diff --git a/tests/baselines/reference/letDeclarations-scopes2.errors.txt b/tests/baselines/reference/letDeclarations-scopes2.errors.txt new file mode 100644 index 00000000000..a786db1104b --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes2.errors.txt @@ -0,0 +1,42 @@ +tests/cases/compiler/letDeclarations-scopes2.ts(9,5): error TS2304: Cannot find name 'local2'. +tests/cases/compiler/letDeclarations-scopes2.ts(21,5): error TS2304: Cannot find name 'local2'. +tests/cases/compiler/letDeclarations-scopes2.ts(24,1): error TS2304: Cannot find name 'local'. +tests/cases/compiler/letDeclarations-scopes2.ts(26,1): error TS2304: Cannot find name 'local2'. + + +==== tests/cases/compiler/letDeclarations-scopes2.ts (4 errors) ==== + + let global = 0; + + { + let local = 0; + + local; // OK + global; // OK + local2; // Error + ~~~~~~ +!!! error TS2304: Cannot find name 'local2'. + + { + let local2 = 0; + + local; // OK + global; // OK + local2; // OK + } + + local; // OK + global; // OK + local2; // Error + ~~~~~~ +!!! error TS2304: Cannot find name 'local2'. + } + + local; // Error + ~~~~~ +!!! error TS2304: Cannot find name 'local'. + global; // OK + local2; // Error + ~~~~~~ +!!! error TS2304: Cannot find name 'local2'. + \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes2.js b/tests/baselines/reference/letDeclarations-scopes2.js new file mode 100644 index 00000000000..98d0e791832 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes2.js @@ -0,0 +1,49 @@ +//// [letDeclarations-scopes2.ts] + +let global = 0; + +{ + let local = 0; + + local; // OK + global; // OK + local2; // Error + + { + let local2 = 0; + + local; // OK + global; // OK + local2; // OK + } + + local; // OK + global; // OK + local2; // Error +} + +local; // Error +global; // OK +local2; // Error + + +//// [letDeclarations-scopes2.js] +let global = 0; +{ + let local = 0; + local; // OK + global; // OK + local2; // Error + { + let local2 = 0; + local; // OK + global; // OK + local2; // OK + } + local; // OK + global; // OK + local2; // Error +} +local; // Error +global; // OK +local2; // Error diff --git a/tests/cases/compiler/constDeclarations-scopes.ts b/tests/cases/compiler/constDeclarations-scopes.ts new file mode 100644 index 00000000000..d0c1df425b6 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-scopes.ts @@ -0,0 +1,148 @@ +// @target: ES6 + +// global +const c = "string"; + +var n: number; + +// Control flow statements with blocks +if (true) { + const c = 0; + n = c; +} +else { + const c = 0; + n = c; +} + +while (true) { + const c = 0; + n = c; +} + +do { + const c = 0; + n = c; +} while (true); + +var obj; +with (obj) { + const c = 0; + n = c; +} + +for (var i = 0; i < 10; i++) { + const c = 0; + n = c; +} + +for (var i2 in {}) { + const c = 0; + n = c; +} + +if (true) { + label: const c = 0; + n = c; +} + +while (false) { + label2: label3: label4: const c = 0; + n = c; +} + +// Try/catch/finally +try { + const c = 0; + n = c; +} +catch (e) { + const c = 0; + n = c; +} +finally { + const c = 0; + n = c; +} + +// Switch +switch (0) { + case 0: + const c = 0; + n = c; + break; +} + +// blocks +{ + const c = 0; + n = c; + { + const c = false; + var b: boolean = c; + } +} + +// functions + +function F() { + const c = 0; + n = c; +} + +var F2 = () => { + const c = 0; + n = c; +}; + +var F3 = function () { + const c = 0; + n = c; +}; + +// modules +module m { + const c = 0; + n = c; + + { + const c = false; + var b2: boolean = c; + } +} + +// methods +class C { + constructor() { + const c = 0; + n = c; + } + + method() { + const c = 0; + n = c; + } + + get v() { + const c = 0; + n = c; + return n; + } + + set v(value) { + const c = 0; + n = c; + } +} + +// object literals +var o = { + f() { + const c = 0; + n = c; + }, + f2: () => { + const c = 0; + n = c; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/letDeclarations-scopes-duplicates.ts b/tests/cases/compiler/letDeclarations-scopes-duplicates.ts new file mode 100644 index 00000000000..841b55af168 --- /dev/null +++ b/tests/cases/compiler/letDeclarations-scopes-duplicates.ts @@ -0,0 +1,77 @@ +// @target: ES6 + +// Errors: redeclaration +let var1 = 0; +let var1 = 0; // error + +let var2 = 0; +const var2 = 0; + +const var3 = 0; +let var3 = 0; + +const var4 = 0; +const var4 = 0; + +var var5 = 0; +let var5 = 0; + +let var6 = 0; +var var6 = 0; + +{ + let var7 = 0; + let var7 = 0; + { + let var8 = 0; + const var8 = 0; + } +} + +switch (0) { + default: + let var9 = 0; + let var9 = 0; +} + +try { + const var10 = 0; + const var10 = 0; +} +catch (e) { + let var11 = 0; + let var11 = 0; +} + +function F1() { + let var12; + let var12; +} + +// OK +var var20 = 0; + +var var20 = 0 +{ + let var20 = 0; + { + let var20 = 0; + } +} + +switch (0) { + default: + let var20 = 0; +} + +try { + let var20 = 0; +} +catch (e) { + let var20 = 0; +} + +function F() { + let var20; +} + diff --git a/tests/cases/compiler/letDeclarations-scopes.ts b/tests/cases/compiler/letDeclarations-scopes.ts new file mode 100644 index 00000000000..0393f0f295b --- /dev/null +++ b/tests/cases/compiler/letDeclarations-scopes.ts @@ -0,0 +1,156 @@ +// @target: ES6 + +// global +let l = "string"; + +var n: number; + +// Control flow statements with blocks +if (true) { + let l = 0; + n = l; +} +else { + let l = 0; + n = l; +} + +while (true) { + let l = 0; + n = l; +} + +do { + let l = 0; + n = l; +} while (true); + +var obj; +with (obj) { + let l = 0; + n = l; +} + +for (var i = 0; i < 10; i++) { + let l = 0; + n = l; +} + +for (var i2 in {}) { + let l = 0; + n = l; +} + +if (true) { + label: let l = 0; + n = l; +} + +while (false) { + label2: label3: label4: let l = 0; + n = l; +} + +for (let l = 0; n = l; l++) { + let l = true; + var b3: boolean = l; +} + +for (let l in {}) { + +} + +// Try/catch/finally +try { + let l = 0; + n = l; +} +catch (e) { + let l = 0; + n = l; +} +finally { + let l = 0; + n = l; +} + +// Switch +switch (0) { + case 0: + let l = 0; + n = l; + break; +} + +// blocks +{ + let l = 0; + n = l; + { + let l = false; + var b: boolean = l; + } +} + +// functions +function F() { + let l = 0; + n = l; +} + +var F2 = () => { + let l = 0; +n = l; +}; + +var F3 = function () { + let l = 0; +n = l; +}; + +// modules +module m { + let l = 0; + n = l; + + { + let l = false; + var b2: boolean = l; + } +} + +// methods +class C { + constructor() { + let l = 0; + n = l; + } + + method() { + let l = 0; + n = l; + } + + get v() { + let l = 0; + n = l; + return n; + } + + set v(value) { + let l = 0; + n = l; + } +} + +// object literals +var o = { + f() { + let l = 0; +n = l; + }, +f2: () => { + let l = 0; + n = l; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/letDeclarations-scopes2.ts b/tests/cases/compiler/letDeclarations-scopes2.ts new file mode 100644 index 00000000000..6f1200a0cb2 --- /dev/null +++ b/tests/cases/compiler/letDeclarations-scopes2.ts @@ -0,0 +1,27 @@ +// @target: ES6 + +let global = 0; + +{ + let local = 0; + + local; // OK + global; // OK + local2; // Error + + { + let local2 = 0; + + local; // OK + global; // OK + local2; // OK + } + + local; // OK + global; // OK + local2; // Error +} + +local; // Error +global; // OK +local2; // Error From 1dde985f1d66459c079ca84271d951b9aa770ec0 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 13 Oct 2014 22:19:19 -0700 Subject: [PATCH 06/63] Do not allow use of block-scoped variable before its definition --- src/compiler/checker.ts | 15 ++++++++++++ .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 16 ++++++++----- ...eclarations-useBeforeDefinition.errors.txt | 21 ++++++++++++++++ .../constDeclarations-useBeforeDefinition.js | 24 +++++++++++++++++++ ...clarations-useBeforeDefinition2.errors.txt | 11 +++++++++ .../constDeclarations-useBeforeDefinition2.js | 12 ++++++++++ ...eclarations-useBeforeDefinition.errors.txt | 21 ++++++++++++++++ .../letDeclarations-useBeforeDefinition.js | 24 +++++++++++++++++++ ...clarations-useBeforeDefinition2.errors.txt | 11 +++++++++ .../letDeclarations-useBeforeDefinition2.js | 12 ++++++++++ .../reference/letDeclarations3.errors.txt | 18 ++++++++++++++ .../constDeclarations-useBeforeDefinition.ts | 12 ++++++++++ .../constDeclarations-useBeforeDefinition2.ts | 8 +++++++ .../letDeclarations-useBeforeDefinition.ts | 12 ++++++++++ .../letDeclarations-useBeforeDefinition2.ts | 8 +++++++ 16 files changed, 220 insertions(+), 6 deletions(-) create mode 100644 tests/baselines/reference/constDeclarations-useBeforeDefinition.errors.txt create mode 100644 tests/baselines/reference/constDeclarations-useBeforeDefinition.js create mode 100644 tests/baselines/reference/constDeclarations-useBeforeDefinition2.errors.txt create mode 100644 tests/baselines/reference/constDeclarations-useBeforeDefinition2.js create mode 100644 tests/baselines/reference/letDeclarations-useBeforeDefinition.errors.txt create mode 100644 tests/baselines/reference/letDeclarations-useBeforeDefinition.js create mode 100644 tests/baselines/reference/letDeclarations-useBeforeDefinition2.errors.txt create mode 100644 tests/baselines/reference/letDeclarations-useBeforeDefinition2.js create mode 100644 tests/baselines/reference/letDeclarations3.errors.txt create mode 100644 tests/cases/compiler/constDeclarations-useBeforeDefinition.ts create mode 100644 tests/cases/compiler/constDeclarations-useBeforeDefinition2.ts create mode 100644 tests/cases/compiler/letDeclarations-useBeforeDefinition.ts create mode 100644 tests/cases/compiler/letDeclarations-useBeforeDefinition2.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 927cc050e20..08f2654d4d2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -314,6 +314,21 @@ module ts { if (!s && nameNotFoundMessage) { error(errorLocation, nameNotFoundMessage, nameArg); } + if (s && s.flags & SymbolFlags.BlockScoped) { + var declaration = forEach(s.declarations, d => d.flags & NodeFlags.BlockScoped ? d : undefined); + Debug.assert(declaration, "Bock-scoped variable declaration is undefined"); + var declarationSourceFile = getSourceFileOfNode(declaration); + var referenceSourceFile = getSourceFileOfNode(errorLocation); + if (declarationSourceFile === referenceSourceFile && declaration.pos > errorLocation.pos) { + error(errorLocation, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, identifierToString(declaration.name)); + } + else if (compilerOptions.out) { + var sourceFiles = program.getSourceFiles(); + if (sourceFiles.indexOf(referenceSourceFile) < sourceFiles.indexOf(declarationSourceFile)) { + error(errorLocation, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, identifierToString(declaration.name)); + } + } + } return s; } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 84e10cfec58..f2a1f6abc03 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -269,6 +269,7 @@ module ts { Property_0_is_protected_and_only_accessible_within_class_1_and_its_subclasses: { code: 2445, category: DiagnosticCategory.Error, key: "Property '{0}' is protected and only accessible within class '{1}' and its subclasses." }, Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1: { code: 2446, category: DiagnosticCategory.Error, key: "Property '{0}' is protected and only accessible through an instance of class '{1}'." }, The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead: { code: 2447, category: DiagnosticCategory.Error, key: "The '{0}' operator is not allowed for boolean types. Consider using '{1}' instead." }, + Block_scoped_variable_0_used_before_its_declaration: { code: 2448, category: DiagnosticCategory.Error, key: "Block-scoped variable '{0}' used before its declaration." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4001, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index fa433e0e772..dddd3ddb3d2 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -451,27 +451,27 @@ "category": "Error", "code": 1151 }, - "'var', 'let' or 'const' expected.": { + "'var', 'let' or 'const' expected.": { "category": "Error", "code": 1152 }, - "'let' variable declarations are only available when targeting ECMAScript 6 and higher.": { + "'let' variable declarations are only available when targeting ECMAScript 6 and higher.": { "category": "Error", "code": 1153 }, - "'const' variable declarations are only available when targeting ECMAScript 6 and higher.": { + "'const' variable declarations are only available when targeting ECMAScript 6 and higher.": { "category": "Error", "code": 1154 }, - "const must be intialized.": { + "const must be intialized.": { "category": "Error", "code": 1155 }, - "const must be declared inside a block.": { + "const must be declared inside a block.": { "category": "Error", "code": 1156 }, - "let must be declared inside a block.": { + "let must be declared inside a block.": { "category": "Error", "code": 1157 }, @@ -1068,6 +1068,10 @@ "category": "Error", "code": 2447 }, + "Block-scoped variable '{0}' used before its declaration.": { + "category": "Error", + "code": 2448 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/tests/baselines/reference/constDeclarations-useBeforeDefinition.errors.txt b/tests/baselines/reference/constDeclarations-useBeforeDefinition.errors.txt new file mode 100644 index 00000000000..97cf58c6e9d --- /dev/null +++ b/tests/baselines/reference/constDeclarations-useBeforeDefinition.errors.txt @@ -0,0 +1,21 @@ +tests/cases/compiler/constDeclarations-useBeforeDefinition.ts(3,5): error TS2448: Block-scoped variable 'c1' used before its declaration. +tests/cases/compiler/constDeclarations-useBeforeDefinition.ts(9,5): error TS2448: Block-scoped variable 'v1' used before its declaration. + + +==== tests/cases/compiler/constDeclarations-useBeforeDefinition.ts (2 errors) ==== + + { + c1; + ~~ +!!! error TS2448: Block-scoped variable 'c1' used before its declaration. + const c1 = 0; + } + + var v1; + { + v1; + ~~ +!!! error TS2448: Block-scoped variable 'v1' used before its declaration. + const v1 = 0; + } + \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-useBeforeDefinition.js b/tests/baselines/reference/constDeclarations-useBeforeDefinition.js new file mode 100644 index 00000000000..4fe0e64f275 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-useBeforeDefinition.js @@ -0,0 +1,24 @@ +//// [constDeclarations-useBeforeDefinition.ts] + +{ + c1; + const c1 = 0; +} + +var v1; +{ + v1; + const v1 = 0; +} + + +//// [constDeclarations-useBeforeDefinition.js] +{ + c1; + const c1 = 0; +} +var v1; +{ + v1; + const v1 = 0; +} diff --git a/tests/baselines/reference/constDeclarations-useBeforeDefinition2.errors.txt b/tests/baselines/reference/constDeclarations-useBeforeDefinition2.errors.txt new file mode 100644 index 00000000000..a4d28f51878 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-useBeforeDefinition2.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/file1.ts(2,1): error TS2448: Block-scoped variable 'c' used before its declaration. + + +==== tests/cases/compiler/file1.ts (1 errors) ==== + + c; + ~ +!!! error TS2448: Block-scoped variable 'c' used before its declaration. + +==== tests/cases/compiler/file2.ts (0 errors) ==== + const c = 0; \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-useBeforeDefinition2.js b/tests/baselines/reference/constDeclarations-useBeforeDefinition2.js new file mode 100644 index 00000000000..7d1f4cf5725 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-useBeforeDefinition2.js @@ -0,0 +1,12 @@ +//// [tests/cases/compiler/constDeclarations-useBeforeDefinition2.ts] //// + +//// [file1.ts] + +c; + +//// [file2.ts] +const c = 0; + +//// [out.js] +c; +const c = 0; diff --git a/tests/baselines/reference/letDeclarations-useBeforeDefinition.errors.txt b/tests/baselines/reference/letDeclarations-useBeforeDefinition.errors.txt new file mode 100644 index 00000000000..74c354f4ff2 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-useBeforeDefinition.errors.txt @@ -0,0 +1,21 @@ +tests/cases/compiler/letDeclarations-useBeforeDefinition.ts(3,5): error TS2448: Block-scoped variable 'l1' used before its declaration. +tests/cases/compiler/letDeclarations-useBeforeDefinition.ts(9,5): error TS2448: Block-scoped variable 'v1' used before its declaration. + + +==== tests/cases/compiler/letDeclarations-useBeforeDefinition.ts (2 errors) ==== + + { + l1; + ~~ +!!! error TS2448: Block-scoped variable 'l1' used before its declaration. + let l1; + } + + var v1; + { + v1; + ~~ +!!! error TS2448: Block-scoped variable 'v1' used before its declaration. + let v1 = 0; + } + \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-useBeforeDefinition.js b/tests/baselines/reference/letDeclarations-useBeforeDefinition.js new file mode 100644 index 00000000000..be1f9a127f4 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-useBeforeDefinition.js @@ -0,0 +1,24 @@ +//// [letDeclarations-useBeforeDefinition.ts] + +{ + l1; + let l1; +} + +var v1; +{ + v1; + let v1 = 0; +} + + +//// [letDeclarations-useBeforeDefinition.js] +{ + l1; + let l1; +} +var v1; +{ + v1; + let v1 = 0; +} diff --git a/tests/baselines/reference/letDeclarations-useBeforeDefinition2.errors.txt b/tests/baselines/reference/letDeclarations-useBeforeDefinition2.errors.txt new file mode 100644 index 00000000000..5b8633312d9 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-useBeforeDefinition2.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/file1.ts(2,1): error TS2448: Block-scoped variable 'l' used before its declaration. + + +==== tests/cases/compiler/file1.ts (1 errors) ==== + + l; + ~ +!!! error TS2448: Block-scoped variable 'l' used before its declaration. + +==== tests/cases/compiler/file2.ts (0 errors) ==== + const l = 0; \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-useBeforeDefinition2.js b/tests/baselines/reference/letDeclarations-useBeforeDefinition2.js new file mode 100644 index 00000000000..35560edd1c8 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-useBeforeDefinition2.js @@ -0,0 +1,12 @@ +//// [tests/cases/compiler/letDeclarations-useBeforeDefinition2.ts] //// + +//// [file1.ts] + +l; + +//// [file2.ts] +const l = 0; + +//// [out.js] +l; +const l = 0; diff --git a/tests/baselines/reference/letDeclarations3.errors.txt b/tests/baselines/reference/letDeclarations3.errors.txt new file mode 100644 index 00000000000..8c4d925ce13 --- /dev/null +++ b/tests/baselines/reference/letDeclarations3.errors.txt @@ -0,0 +1,18 @@ +tests/cases/compiler/letDeclarations3.ts(3,5): error TS2300: Duplicate identifier 'l1'. +tests/cases/compiler/letDeclarations3.ts(3,9): error TS2300: Duplicate identifier 'l1'. +tests/cases/compiler/letDeclarations3.ts(3,13): error TS2300: Duplicate identifier 'l1'. + + +==== tests/cases/compiler/letDeclarations3.ts (3 errors) ==== + + // Duplicate variables + let l1, l1, l1; + ~~ +!!! error TS2300: Duplicate identifier 'l1'. + ~~ +!!! error TS2300: Duplicate identifier 'l1'. + ~~ +!!! error TS2300: Duplicate identifier 'l1'. + + // unexpected 'let' + let l2, let, l3; \ No newline at end of file diff --git a/tests/cases/compiler/constDeclarations-useBeforeDefinition.ts b/tests/cases/compiler/constDeclarations-useBeforeDefinition.ts new file mode 100644 index 00000000000..ec793fda484 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-useBeforeDefinition.ts @@ -0,0 +1,12 @@ +// @target: ES6 + +{ + c1; + const c1 = 0; +} + +var v1; +{ + v1; + const v1 = 0; +} diff --git a/tests/cases/compiler/constDeclarations-useBeforeDefinition2.ts b/tests/cases/compiler/constDeclarations-useBeforeDefinition2.ts new file mode 100644 index 00000000000..c34bb4012bf --- /dev/null +++ b/tests/cases/compiler/constDeclarations-useBeforeDefinition2.ts @@ -0,0 +1,8 @@ +// @target: ES6 +// @out: out.js + +// @Filename: file1.ts +c; + +// @Filename: file2.ts +const c = 0; \ No newline at end of file diff --git a/tests/cases/compiler/letDeclarations-useBeforeDefinition.ts b/tests/cases/compiler/letDeclarations-useBeforeDefinition.ts new file mode 100644 index 00000000000..671762d4a45 --- /dev/null +++ b/tests/cases/compiler/letDeclarations-useBeforeDefinition.ts @@ -0,0 +1,12 @@ +// @target: ES6 + +{ + l1; + let l1; +} + +var v1; +{ + v1; + let v1 = 0; +} diff --git a/tests/cases/compiler/letDeclarations-useBeforeDefinition2.ts b/tests/cases/compiler/letDeclarations-useBeforeDefinition2.ts new file mode 100644 index 00000000000..a6cbc729b94 --- /dev/null +++ b/tests/cases/compiler/letDeclarations-useBeforeDefinition2.ts @@ -0,0 +1,8 @@ +// @target: ES6 +// @out: out.js + +// @Filename: file1.ts +l; + +// @Filename: file2.ts +const l = 0; \ No newline at end of file From 318575ce75c2c10e714336a9326405c63f49affd Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 14 Oct 2014 14:51:28 -0700 Subject: [PATCH 07/63] Ensure duplicate let/const declarations accross files are reported --- src/compiler/checker.ts | 1 + .../letDeclarations-scopes-duplicates2.errors.txt | 11 +++++++++++ .../reference/letDeclarations-scopes-duplicates2.js | 13 +++++++++++++ .../letDeclarations-scopes-duplicates3.errors.txt | 11 +++++++++++ .../reference/letDeclarations-scopes-duplicates3.js | 13 +++++++++++++ .../letDeclarations-scopes-duplicates4.errors.txt | 11 +++++++++++ .../reference/letDeclarations-scopes-duplicates4.js | 13 +++++++++++++ .../letDeclarations-scopes-duplicates5.errors.txt | 11 +++++++++++ .../reference/letDeclarations-scopes-duplicates5.js | 13 +++++++++++++ .../letDeclarations-scopes-duplicates6.errors.txt | 11 +++++++++++ .../reference/letDeclarations-scopes-duplicates6.js | 13 +++++++++++++ .../letDeclarations-scopes-duplicates7.errors.txt | 11 +++++++++++ .../reference/letDeclarations-scopes-duplicates7.js | 13 +++++++++++++ .../compiler/letDeclarations-scopes-duplicates2.ts | 7 +++++++ .../compiler/letDeclarations-scopes-duplicates3.ts | 7 +++++++ .../compiler/letDeclarations-scopes-duplicates4.ts | 7 +++++++ .../compiler/letDeclarations-scopes-duplicates5.ts | 7 +++++++ .../compiler/letDeclarations-scopes-duplicates6.ts | 7 +++++++ .../compiler/letDeclarations-scopes-duplicates7.ts | 7 +++++++ 19 files changed, 187 insertions(+) create mode 100644 tests/baselines/reference/letDeclarations-scopes-duplicates2.errors.txt create mode 100644 tests/baselines/reference/letDeclarations-scopes-duplicates2.js create mode 100644 tests/baselines/reference/letDeclarations-scopes-duplicates3.errors.txt create mode 100644 tests/baselines/reference/letDeclarations-scopes-duplicates3.js create mode 100644 tests/baselines/reference/letDeclarations-scopes-duplicates4.errors.txt create mode 100644 tests/baselines/reference/letDeclarations-scopes-duplicates4.js create mode 100644 tests/baselines/reference/letDeclarations-scopes-duplicates5.errors.txt create mode 100644 tests/baselines/reference/letDeclarations-scopes-duplicates5.js create mode 100644 tests/baselines/reference/letDeclarations-scopes-duplicates6.errors.txt create mode 100644 tests/baselines/reference/letDeclarations-scopes-duplicates6.js create mode 100644 tests/baselines/reference/letDeclarations-scopes-duplicates7.errors.txt create mode 100644 tests/baselines/reference/letDeclarations-scopes-duplicates7.js create mode 100644 tests/cases/compiler/letDeclarations-scopes-duplicates2.ts create mode 100644 tests/cases/compiler/letDeclarations-scopes-duplicates3.ts create mode 100644 tests/cases/compiler/letDeclarations-scopes-duplicates4.ts create mode 100644 tests/cases/compiler/letDeclarations-scopes-duplicates5.ts create mode 100644 tests/cases/compiler/letDeclarations-scopes-duplicates6.ts create mode 100644 tests/cases/compiler/letDeclarations-scopes-duplicates7.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 08f2654d4d2..76533abf50c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -172,6 +172,7 @@ module ts { function getExcludedSymbolFlags(flags: SymbolFlags): SymbolFlags { var result: SymbolFlags = 0; + if (flags & SymbolFlags.BlockScoped) result |= SymbolFlags.BlockScopedExcludes; if (flags & SymbolFlags.Variable) result |= SymbolFlags.VariableExcludes; if (flags & SymbolFlags.Property) result |= SymbolFlags.PropertyExcludes; if (flags & SymbolFlags.EnumMember) result |= SymbolFlags.EnumMemberExcludes; diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates2.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates2.errors.txt new file mode 100644 index 00000000000..324385b406e --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates2.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/file2.ts(1,5): error TS2300: Duplicate identifier 'var1'. + + +==== tests/cases/compiler/file1.ts (0 errors) ==== + + let var1 = 0; + +==== tests/cases/compiler/file2.ts (1 errors) ==== + let var1 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var1'. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates2.js b/tests/baselines/reference/letDeclarations-scopes-duplicates2.js new file mode 100644 index 00000000000..9b35bd81c76 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates2.js @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/letDeclarations-scopes-duplicates2.ts] //// + +//// [file1.ts] + +let var1 = 0; + +//// [file2.ts] +let var1 = 0; + +//// [file1.js] +let var1 = 0; +//// [file2.js] +let var1 = 0; diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates3.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates3.errors.txt new file mode 100644 index 00000000000..a85ca8bad04 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates3.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/file2.ts(1,7): error TS2300: Duplicate identifier 'var1'. + + +==== tests/cases/compiler/file1.ts (0 errors) ==== + + let var1 = 0; + +==== tests/cases/compiler/file2.ts (1 errors) ==== + const var1 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var1'. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates3.js b/tests/baselines/reference/letDeclarations-scopes-duplicates3.js new file mode 100644 index 00000000000..e74caf37219 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates3.js @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/letDeclarations-scopes-duplicates3.ts] //// + +//// [file1.ts] + +let var1 = 0; + +//// [file2.ts] +const var1 = 0; + +//// [file1.js] +let var1 = 0; +//// [file2.js] +const var1 = 0; diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates4.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates4.errors.txt new file mode 100644 index 00000000000..1a43932040f --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates4.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/file2.ts(1,5): error TS2300: Duplicate identifier 'var1'. + + +==== tests/cases/compiler/file1.ts (0 errors) ==== + + const var1 = 0; + +==== tests/cases/compiler/file2.ts (1 errors) ==== + let var1 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var1'. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates4.js b/tests/baselines/reference/letDeclarations-scopes-duplicates4.js new file mode 100644 index 00000000000..ac338e31c72 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates4.js @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/letDeclarations-scopes-duplicates4.ts] //// + +//// [file1.ts] + +const var1 = 0; + +//// [file2.ts] +let var1 = 0; + +//// [file1.js] +const var1 = 0; +//// [file2.js] +let var1 = 0; diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates5.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates5.errors.txt new file mode 100644 index 00000000000..49737b17740 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates5.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/file2.ts(1,7): error TS2300: Duplicate identifier 'var1'. + + +==== tests/cases/compiler/file1.ts (0 errors) ==== + + const var1 = 0; + +==== tests/cases/compiler/file2.ts (1 errors) ==== + const var1 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var1'. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates5.js b/tests/baselines/reference/letDeclarations-scopes-duplicates5.js new file mode 100644 index 00000000000..2424c91ab90 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates5.js @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/letDeclarations-scopes-duplicates5.ts] //// + +//// [file1.ts] + +const var1 = 0; + +//// [file2.ts] +const var1 = 0; + +//// [file1.js] +const var1 = 0; +//// [file2.js] +const var1 = 0; diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates6.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates6.errors.txt new file mode 100644 index 00000000000..2904227c8f8 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates6.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/file2.ts(1,5): error TS2300: Duplicate identifier 'var1'. + + +==== tests/cases/compiler/file1.ts (0 errors) ==== + + var var1 = 0; + +==== tests/cases/compiler/file2.ts (1 errors) ==== + let var1 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var1'. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates6.js b/tests/baselines/reference/letDeclarations-scopes-duplicates6.js new file mode 100644 index 00000000000..24edc0b7bde --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates6.js @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/letDeclarations-scopes-duplicates6.ts] //// + +//// [file1.ts] + +var var1 = 0; + +//// [file2.ts] +let var1 = 0; + +//// [file1.js] +var var1 = 0; +//// [file2.js] +let var1 = 0; diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates7.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates7.errors.txt new file mode 100644 index 00000000000..8dd0418b602 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates7.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/file2.ts(1,5): error TS2300: Duplicate identifier 'var1'. + + +==== tests/cases/compiler/file1.ts (0 errors) ==== + + let var1 = 0; + +==== tests/cases/compiler/file2.ts (1 errors) ==== + var var1 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var1'. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates7.js b/tests/baselines/reference/letDeclarations-scopes-duplicates7.js new file mode 100644 index 00000000000..4cbc359e2c2 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates7.js @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/letDeclarations-scopes-duplicates7.ts] //// + +//// [file1.ts] + +let var1 = 0; + +//// [file2.ts] +var var1 = 0; + +//// [file1.js] +let var1 = 0; +//// [file2.js] +var var1 = 0; diff --git a/tests/cases/compiler/letDeclarations-scopes-duplicates2.ts b/tests/cases/compiler/letDeclarations-scopes-duplicates2.ts new file mode 100644 index 00000000000..40ddc14fc3f --- /dev/null +++ b/tests/cases/compiler/letDeclarations-scopes-duplicates2.ts @@ -0,0 +1,7 @@ +// @target: ES6 + +// @Filename: file1.ts +let var1 = 0; + +// @Filename: file2.ts +let var1 = 0; \ No newline at end of file diff --git a/tests/cases/compiler/letDeclarations-scopes-duplicates3.ts b/tests/cases/compiler/letDeclarations-scopes-duplicates3.ts new file mode 100644 index 00000000000..1f10efa5385 --- /dev/null +++ b/tests/cases/compiler/letDeclarations-scopes-duplicates3.ts @@ -0,0 +1,7 @@ +// @target: ES6 + +// @Filename: file1.ts +let var1 = 0; + +// @Filename: file2.ts +const var1 = 0; \ No newline at end of file diff --git a/tests/cases/compiler/letDeclarations-scopes-duplicates4.ts b/tests/cases/compiler/letDeclarations-scopes-duplicates4.ts new file mode 100644 index 00000000000..150d434a2bc --- /dev/null +++ b/tests/cases/compiler/letDeclarations-scopes-duplicates4.ts @@ -0,0 +1,7 @@ +// @target: ES6 + +// @Filename: file1.ts +const var1 = 0; + +// @Filename: file2.ts +let var1 = 0; \ No newline at end of file diff --git a/tests/cases/compiler/letDeclarations-scopes-duplicates5.ts b/tests/cases/compiler/letDeclarations-scopes-duplicates5.ts new file mode 100644 index 00000000000..da249853499 --- /dev/null +++ b/tests/cases/compiler/letDeclarations-scopes-duplicates5.ts @@ -0,0 +1,7 @@ +// @target: ES6 + +// @Filename: file1.ts +const var1 = 0; + +// @Filename: file2.ts +const var1 = 0; \ No newline at end of file diff --git a/tests/cases/compiler/letDeclarations-scopes-duplicates6.ts b/tests/cases/compiler/letDeclarations-scopes-duplicates6.ts new file mode 100644 index 00000000000..f71b7623790 --- /dev/null +++ b/tests/cases/compiler/letDeclarations-scopes-duplicates6.ts @@ -0,0 +1,7 @@ +// @target: ES6 + +// @Filename: file1.ts +var var1 = 0; + +// @Filename: file2.ts +let var1 = 0; \ No newline at end of file diff --git a/tests/cases/compiler/letDeclarations-scopes-duplicates7.ts b/tests/cases/compiler/letDeclarations-scopes-duplicates7.ts new file mode 100644 index 00000000000..829fda0c927 --- /dev/null +++ b/tests/cases/compiler/letDeclarations-scopes-duplicates7.ts @@ -0,0 +1,7 @@ +// @target: ES6 + +// @Filename: file1.ts +let var1 = 0; + +// @Filename: file2.ts +var var1 = 0; \ No newline at end of file From cffc62aa1bc9b1282707365475e18bd6af200775 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 14 Oct 2014 15:18:44 -0700 Subject: [PATCH 08/63] Report duplicate identifier errors on all locations for merged declarations to align with local declarations --- src/compiler/checker.ts | 3 + ...tionTypeArgumentArrayAssignment.errors.txt | 15 ----- .../functionTypeArgumentArrayAssignment.js | 23 +++++--- .../functionTypeArgumentArrayAssignment.types | 27 +++++++++ .../reference/instanceofOperator.errors.txt | 47 ++++++++-------- .../baselines/reference/instanceofOperator.js | 53 ++++++++++-------- ...Declarations-scopes-duplicates2.errors.txt | 5 +- ...Declarations-scopes-duplicates3.errors.txt | 5 +- ...Declarations-scopes-duplicates4.errors.txt | 5 +- ...Declarations-scopes-duplicates5.errors.txt | 5 +- ...Declarations-scopes-duplicates6.errors.txt | 5 +- ...Declarations-scopes-duplicates7.errors.txt | 5 +- .../reference/letDeclarations3.errors.txt | 18 ------ .../parserOptionalTypeMembers1.errors.txt | 23 -------- .../reference/parserOptionalTypeMembers1.js | 2 +- .../parserOptionalTypeMembers1.types | 23 ++++++++ .../amd/declareVariableCollision.errors.txt | 5 +- .../node/declareVariableCollision.errors.txt | 5 +- .../functionTypeArgumentArrayAssignment.ts | 14 +++-- tests/cases/compiler/instanceofOperator.ts | Bin 1006 -> 1120 bytes .../ecmascript5/parserOptionalTypeMembers1.ts | 2 +- 21 files changed, 161 insertions(+), 129 deletions(-) delete mode 100644 tests/baselines/reference/functionTypeArgumentArrayAssignment.errors.txt create mode 100644 tests/baselines/reference/functionTypeArgumentArrayAssignment.types delete mode 100644 tests/baselines/reference/letDeclarations3.errors.txt delete mode 100644 tests/baselines/reference/parserOptionalTypeMembers1.errors.txt create mode 100644 tests/baselines/reference/parserOptionalTypeMembers1.types diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 76533abf50c..f7d20733aa9 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -226,6 +226,9 @@ module ts { forEach(source.declarations, node => { error(node.name ? node.name : node, Diagnostics.Duplicate_identifier_0, symbolToString(source)); }); + forEach(target.declarations, node => { + error(node.name ? node.name : node, Diagnostics.Duplicate_identifier_0, symbolToString(source)); + }); } } diff --git a/tests/baselines/reference/functionTypeArgumentArrayAssignment.errors.txt b/tests/baselines/reference/functionTypeArgumentArrayAssignment.errors.txt deleted file mode 100644 index 9897286a624..00000000000 --- a/tests/baselines/reference/functionTypeArgumentArrayAssignment.errors.txt +++ /dev/null @@ -1,15 +0,0 @@ -tests/cases/compiler/functionTypeArgumentArrayAssignment.ts(3,2): error TS2300: Duplicate identifier 'length'. - - -==== tests/cases/compiler/functionTypeArgumentArrayAssignment.ts (1 errors) ==== - interface Array { - foo: T; - length: number; - ~~~~~~ -!!! error TS2300: Duplicate identifier 'length'. - } - - function map() { - var ys: U[] = []; - } - \ No newline at end of file diff --git a/tests/baselines/reference/functionTypeArgumentArrayAssignment.js b/tests/baselines/reference/functionTypeArgumentArrayAssignment.js index 9569c4566d8..38188c3505a 100644 --- a/tests/baselines/reference/functionTypeArgumentArrayAssignment.js +++ b/tests/baselines/reference/functionTypeArgumentArrayAssignment.js @@ -1,15 +1,20 @@ //// [functionTypeArgumentArrayAssignment.ts] -interface Array { - foo: T; - length: number; -} +module test { + interface Array { + foo: T; + length: number; + } -function map() { -var ys: U[] = []; + function map() { + var ys: U[] = []; + } } //// [functionTypeArgumentArrayAssignment.js] -function map() { - var ys = []; -} +var test; +(function (test) { + function map() { + var ys = []; + } +})(test || (test = {})); diff --git a/tests/baselines/reference/functionTypeArgumentArrayAssignment.types b/tests/baselines/reference/functionTypeArgumentArrayAssignment.types new file mode 100644 index 00000000000..73375ac5e21 --- /dev/null +++ b/tests/baselines/reference/functionTypeArgumentArrayAssignment.types @@ -0,0 +1,27 @@ +=== tests/cases/compiler/functionTypeArgumentArrayAssignment.ts === +module test { +>test : typeof test + + interface Array { +>Array : Array +>T : T + + foo: T; +>foo : T +>T : T + + length: number; +>length : number + } + + function map() { +>map : () => void +>U : U + + var ys: U[] = []; +>ys : U[] +>U : U +>[] : U[] + } +} + diff --git a/tests/baselines/reference/instanceofOperator.errors.txt b/tests/baselines/reference/instanceofOperator.errors.txt index 15d55188741..2fa517c53be 100644 --- a/tests/baselines/reference/instanceofOperator.errors.txt +++ b/tests/baselines/reference/instanceofOperator.errors.txt @@ -1,43 +1,42 @@ -tests/cases/compiler/instanceofOperator.ts(6,7): error TS2300: Duplicate identifier 'Object'. -tests/cases/compiler/instanceofOperator.ts(11,1): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. -tests/cases/compiler/instanceofOperator.ts(14,16): error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type. -tests/cases/compiler/instanceofOperator.ts(15,19): error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type. -tests/cases/compiler/instanceofOperator.ts(18,1): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. -tests/cases/compiler/instanceofOperator.ts(20,1): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. +tests/cases/compiler/instanceofOperator.ts(12,5): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. +tests/cases/compiler/instanceofOperator.ts(15,20): error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type. +tests/cases/compiler/instanceofOperator.ts(16,23): error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type. +tests/cases/compiler/instanceofOperator.ts(19,5): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. +tests/cases/compiler/instanceofOperator.ts(21,5): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. -==== tests/cases/compiler/instanceofOperator.ts (6 errors) ==== +==== tests/cases/compiler/instanceofOperator.ts (5 errors) ==== // Spec: // The instanceof operator requires the left operand to be of type Any or an object type, and the right // operand to be of type Any or a subtype of the ‘Function’ interface type. The result is always of the // Boolean primitive type. - class Object { } - ~~~~~~ -!!! error TS2300: Duplicate identifier 'Object'. - var obj: Object; + module test { + class Object { } + var obj: Object; - 4 instanceof null; - ~ + 4 instanceof null; + ~ !!! error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. - // Error and should be error - obj instanceof 4; - ~ + // Error and should be error + obj instanceof 4; + ~ !!! error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type. - Object instanceof obj; - ~~~ + Object instanceof obj; + ~~~ !!! error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type. - // Error on left hand side - null instanceof null; - ~~~~ + // Error on left hand side + null instanceof null; + ~~~~ !!! error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. - obj instanceof Object; - undefined instanceof undefined; - ~~~~~~~~~ + obj instanceof Object; + undefined instanceof undefined; + ~~~~~~~~~ !!! error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. + } \ No newline at end of file diff --git a/tests/baselines/reference/instanceofOperator.js b/tests/baselines/reference/instanceofOperator.js index 7620c3e83f4..3c6970b66a4 100644 --- a/tests/baselines/reference/instanceofOperator.js +++ b/tests/baselines/reference/instanceofOperator.js @@ -4,21 +4,23 @@ // operand to be of type Any or a subtype of the ‘Function’ interface type. The result is always of the // Boolean primitive type. -class Object { } -var obj: Object; +module test { + class Object { } + var obj: Object; -4 instanceof null; + 4 instanceof null; -// Error and should be error -obj instanceof 4; -Object instanceof obj; + // Error and should be error + obj instanceof 4; + Object instanceof obj; -// Error on left hand side -null instanceof null; -obj instanceof Object; -undefined instanceof undefined; + // Error on left hand side + null instanceof null; + obj instanceof Object; + undefined instanceof undefined; +} @@ -27,17 +29,20 @@ undefined instanceof undefined; // The instanceof operator requires the left operand to be of type Any or an object type, and the right // operand to be of type Any or a subtype of the ‘Function’ interface type. The result is always of the // Boolean primitive type. -var Object = (function () { - function Object() { - } - return Object; -})(); -var obj; -4 instanceof null; -// Error and should be error -obj instanceof 4; -Object instanceof obj; -// Error on left hand side -null instanceof null; -obj instanceof Object; -undefined instanceof undefined; +var test; +(function (test) { + var Object = (function () { + function Object() { + } + return Object; + })(); + var obj; + 4 instanceof null; + // Error and should be error + obj instanceof 4; + Object instanceof obj; + // Error on left hand side + null instanceof null; + obj instanceof Object; + undefined instanceof undefined; +})(test || (test = {})); diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates2.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates2.errors.txt index 324385b406e..b948b1b7a14 100644 --- a/tests/baselines/reference/letDeclarations-scopes-duplicates2.errors.txt +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates2.errors.txt @@ -1,9 +1,12 @@ +tests/cases/compiler/file1.ts(2,5): error TS2300: Duplicate identifier 'var1'. tests/cases/compiler/file2.ts(1,5): error TS2300: Duplicate identifier 'var1'. -==== tests/cases/compiler/file1.ts (0 errors) ==== +==== tests/cases/compiler/file1.ts (1 errors) ==== let var1 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var1'. ==== tests/cases/compiler/file2.ts (1 errors) ==== let var1 = 0; diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates3.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates3.errors.txt index a85ca8bad04..7222fb9bf22 100644 --- a/tests/baselines/reference/letDeclarations-scopes-duplicates3.errors.txt +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates3.errors.txt @@ -1,9 +1,12 @@ +tests/cases/compiler/file1.ts(2,5): error TS2300: Duplicate identifier 'var1'. tests/cases/compiler/file2.ts(1,7): error TS2300: Duplicate identifier 'var1'. -==== tests/cases/compiler/file1.ts (0 errors) ==== +==== tests/cases/compiler/file1.ts (1 errors) ==== let var1 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var1'. ==== tests/cases/compiler/file2.ts (1 errors) ==== const var1 = 0; diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates4.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates4.errors.txt index 1a43932040f..e626af7e52a 100644 --- a/tests/baselines/reference/letDeclarations-scopes-duplicates4.errors.txt +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates4.errors.txt @@ -1,9 +1,12 @@ +tests/cases/compiler/file1.ts(2,7): error TS2300: Duplicate identifier 'var1'. tests/cases/compiler/file2.ts(1,5): error TS2300: Duplicate identifier 'var1'. -==== tests/cases/compiler/file1.ts (0 errors) ==== +==== tests/cases/compiler/file1.ts (1 errors) ==== const var1 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var1'. ==== tests/cases/compiler/file2.ts (1 errors) ==== let var1 = 0; diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates5.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates5.errors.txt index 49737b17740..ac5f79dd5a8 100644 --- a/tests/baselines/reference/letDeclarations-scopes-duplicates5.errors.txt +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates5.errors.txt @@ -1,9 +1,12 @@ +tests/cases/compiler/file1.ts(2,7): error TS2300: Duplicate identifier 'var1'. tests/cases/compiler/file2.ts(1,7): error TS2300: Duplicate identifier 'var1'. -==== tests/cases/compiler/file1.ts (0 errors) ==== +==== tests/cases/compiler/file1.ts (1 errors) ==== const var1 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var1'. ==== tests/cases/compiler/file2.ts (1 errors) ==== const var1 = 0; diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates6.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates6.errors.txt index 2904227c8f8..0d3a4726bd3 100644 --- a/tests/baselines/reference/letDeclarations-scopes-duplicates6.errors.txt +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates6.errors.txt @@ -1,9 +1,12 @@ +tests/cases/compiler/file1.ts(2,5): error TS2300: Duplicate identifier 'var1'. tests/cases/compiler/file2.ts(1,5): error TS2300: Duplicate identifier 'var1'. -==== tests/cases/compiler/file1.ts (0 errors) ==== +==== tests/cases/compiler/file1.ts (1 errors) ==== var var1 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var1'. ==== tests/cases/compiler/file2.ts (1 errors) ==== let var1 = 0; diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates7.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates7.errors.txt index 8dd0418b602..dafbae97080 100644 --- a/tests/baselines/reference/letDeclarations-scopes-duplicates7.errors.txt +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates7.errors.txt @@ -1,9 +1,12 @@ +tests/cases/compiler/file1.ts(2,5): error TS2300: Duplicate identifier 'var1'. tests/cases/compiler/file2.ts(1,5): error TS2300: Duplicate identifier 'var1'. -==== tests/cases/compiler/file1.ts (0 errors) ==== +==== tests/cases/compiler/file1.ts (1 errors) ==== let var1 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var1'. ==== tests/cases/compiler/file2.ts (1 errors) ==== var var1 = 0; diff --git a/tests/baselines/reference/letDeclarations3.errors.txt b/tests/baselines/reference/letDeclarations3.errors.txt deleted file mode 100644 index 8c4d925ce13..00000000000 --- a/tests/baselines/reference/letDeclarations3.errors.txt +++ /dev/null @@ -1,18 +0,0 @@ -tests/cases/compiler/letDeclarations3.ts(3,5): error TS2300: Duplicate identifier 'l1'. -tests/cases/compiler/letDeclarations3.ts(3,9): error TS2300: Duplicate identifier 'l1'. -tests/cases/compiler/letDeclarations3.ts(3,13): error TS2300: Duplicate identifier 'l1'. - - -==== tests/cases/compiler/letDeclarations3.ts (3 errors) ==== - - // Duplicate variables - let l1, l1, l1; - ~~ -!!! error TS2300: Duplicate identifier 'l1'. - ~~ -!!! error TS2300: Duplicate identifier 'l1'. - ~~ -!!! error TS2300: Duplicate identifier 'l1'. - - // unexpected 'let' - let l2, let, l3; \ No newline at end of file diff --git a/tests/baselines/reference/parserOptionalTypeMembers1.errors.txt b/tests/baselines/reference/parserOptionalTypeMembers1.errors.txt deleted file mode 100644 index 0279ad37777..00000000000 --- a/tests/baselines/reference/parserOptionalTypeMembers1.errors.txt +++ /dev/null @@ -1,23 +0,0 @@ -tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts(2,5): error TS2300: Duplicate identifier 'configurable'. -tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts(3,5): error TS2300: Duplicate identifier 'enumerable'. -tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts(4,5): error TS2300: Duplicate identifier 'value'. -tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts(5,5): error TS2300: Duplicate identifier 'writable'. - - -==== tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts (4 errors) ==== - interface PropertyDescriptor { - configurable?: boolean; - ~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'configurable'. - enumerable?: boolean; - ~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'enumerable'. - value?: any; - ~~~~~ -!!! error TS2300: Duplicate identifier 'value'. - writable?: boolean; - ~~~~~~~~ -!!! error TS2300: Duplicate identifier 'writable'. - get?(): any; - set?(v: any): void; - } \ No newline at end of file diff --git a/tests/baselines/reference/parserOptionalTypeMembers1.js b/tests/baselines/reference/parserOptionalTypeMembers1.js index 5dfb0adfe82..757887e5409 100644 --- a/tests/baselines/reference/parserOptionalTypeMembers1.js +++ b/tests/baselines/reference/parserOptionalTypeMembers1.js @@ -1,5 +1,5 @@ //// [parserOptionalTypeMembers1.ts] -interface PropertyDescriptor { +interface PropertyDescriptor2 { configurable?: boolean; enumerable?: boolean; value?: any; diff --git a/tests/baselines/reference/parserOptionalTypeMembers1.types b/tests/baselines/reference/parserOptionalTypeMembers1.types new file mode 100644 index 00000000000..7ede18a1d92 --- /dev/null +++ b/tests/baselines/reference/parserOptionalTypeMembers1.types @@ -0,0 +1,23 @@ +=== tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts === +interface PropertyDescriptor2 { +>PropertyDescriptor2 : PropertyDescriptor2 + + configurable?: boolean; +>configurable : boolean + + enumerable?: boolean; +>enumerable : boolean + + value?: any; +>value : any + + writable?: boolean; +>writable : boolean + + get?(): any; +>get : () => any + + set?(v: any): void; +>set : (v: any) => void +>v : any +} diff --git a/tests/baselines/reference/project/declareVariableCollision/amd/declareVariableCollision.errors.txt b/tests/baselines/reference/project/declareVariableCollision/amd/declareVariableCollision.errors.txt index 5dc0a63d7eb..64ec399fabf 100644 --- a/tests/baselines/reference/project/declareVariableCollision/amd/declareVariableCollision.errors.txt +++ b/tests/baselines/reference/project/declareVariableCollision/amd/declareVariableCollision.errors.txt @@ -1,3 +1,4 @@ +in1.d.ts(1,8): error TS2300: Duplicate identifier 'a'. in2.d.ts(1,8): error TS2300: Duplicate identifier 'a'. @@ -14,8 +15,10 @@ in2.d.ts(1,8): error TS2300: Duplicate identifier 'a'. class MyClass{ } } } -==== in1.d.ts (0 errors) ==== +==== in1.d.ts (1 errors) ==== import a = A; + ~ +!!! error TS2300: Duplicate identifier 'a'. ==== in2.d.ts (1 errors) ==== import a = A; ~ diff --git a/tests/baselines/reference/project/declareVariableCollision/node/declareVariableCollision.errors.txt b/tests/baselines/reference/project/declareVariableCollision/node/declareVariableCollision.errors.txt index 5dc0a63d7eb..64ec399fabf 100644 --- a/tests/baselines/reference/project/declareVariableCollision/node/declareVariableCollision.errors.txt +++ b/tests/baselines/reference/project/declareVariableCollision/node/declareVariableCollision.errors.txt @@ -1,3 +1,4 @@ +in1.d.ts(1,8): error TS2300: Duplicate identifier 'a'. in2.d.ts(1,8): error TS2300: Duplicate identifier 'a'. @@ -14,8 +15,10 @@ in2.d.ts(1,8): error TS2300: Duplicate identifier 'a'. class MyClass{ } } } -==== in1.d.ts (0 errors) ==== +==== in1.d.ts (1 errors) ==== import a = A; + ~ +!!! error TS2300: Duplicate identifier 'a'. ==== in2.d.ts (1 errors) ==== import a = A; ~ diff --git a/tests/cases/compiler/functionTypeArgumentArrayAssignment.ts b/tests/cases/compiler/functionTypeArgumentArrayAssignment.ts index 77fbb74d7ad..91cf2d551b9 100644 --- a/tests/cases/compiler/functionTypeArgumentArrayAssignment.ts +++ b/tests/cases/compiler/functionTypeArgumentArrayAssignment.ts @@ -1,8 +1,10 @@ -interface Array { - foo: T; - length: number; -} +module test { + interface Array { + foo: T; + length: number; + } -function map() { -var ys: U[] = []; + function map() { + var ys: U[] = []; + } } diff --git a/tests/cases/compiler/instanceofOperator.ts b/tests/cases/compiler/instanceofOperator.ts index 60b724149ce5d8769df19128b9542a359313f421..f9b304de1136787f2307ea99fe8feebba1f74b1a 100644 GIT binary patch delta 202 zcmaFI{(xh{FGkf|hJ1z;hEj$chExUxh7urI3?vm8su_40xPUYmPX5WL$_``8G8uA0 z*$gI=1DVyikyQ#Z3s3H2(&B}w$Y)4m$eO4q$#247jbh|oCR4bPg3Ok1wkNYbhUUrB Xn1xs&E;-LEI(Zkf0aq>9Fp$jv^I#zc delta 78 zcmaFB@s54NFUH9VOe&Lom<$+ACMrr!p2x(+sldR?zy-pSw=>yJ{==j;S&P|ZavHM* admck6Lk>d@L?PegJIn@?MOd6zK*|AE%@gMU diff --git a/tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts b/tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts index fb3b96952fe..331d0faed9e 100644 --- a/tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts +++ b/tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts @@ -1,4 +1,4 @@ -interface PropertyDescriptor { +interface PropertyDescriptor2 { configurable?: boolean; enumerable?: boolean; value?: any; From f5c27400939ee5584a2f18575ad7d6c9f75ef2a3 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 14 Oct 2014 16:52:12 -0700 Subject: [PATCH 09/63] Flag assignments to a const --- src/compiler/checker.ts | 30 ++++- .../diagnosticInformationMap.generated.ts | 2 + src/compiler/diagnosticMessages.json | 8 ++ .../constDeclarations-access.errors.txt | 11 ++ .../reference/constDeclarations-access.js | 13 +++ .../constDeclarations-access2.errors.txt | 89 ++++++++++++++ .../reference/constDeclarations-access2.js | 71 ++++++++++++ .../reference/letDeclarations-access.js | 70 +++++++++++ .../reference/letDeclarations-access.types | 109 ++++++++++++++++++ .../compiler/constDeclarations-access.ts | 7 ++ .../compiler/constDeclarations-access2.ts | 38 ++++++ .../cases/compiler/letDeclarations-access.ts | 38 ++++++ 12 files changed, 480 insertions(+), 6 deletions(-) create mode 100644 tests/baselines/reference/constDeclarations-access.errors.txt create mode 100644 tests/baselines/reference/constDeclarations-access.js create mode 100644 tests/baselines/reference/constDeclarations-access2.errors.txt create mode 100644 tests/baselines/reference/constDeclarations-access2.js create mode 100644 tests/baselines/reference/letDeclarations-access.js create mode 100644 tests/baselines/reference/letDeclarations-access.types create mode 100644 tests/cases/compiler/constDeclarations-access.ts create mode 100644 tests/cases/compiler/constDeclarations-access2.ts create mode 100644 tests/cases/compiler/letDeclarations-access.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f7d20733aa9..5bba99c6d43 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -318,7 +318,9 @@ module ts { if (!s && nameNotFoundMessage) { error(errorLocation, nameNotFoundMessage, nameArg); } + if (s && s.flags & SymbolFlags.BlockScoped) { + // Block-scoped variables can not be used before thier definition var declaration = forEach(s.declarations, d => d.flags & NodeFlags.BlockScoped ? d : undefined); Debug.assert(declaration, "Bock-scoped variable declaration is undefined"); var declarationSourceFile = getSourceFileOfNode(declaration); @@ -4923,7 +4925,7 @@ module ts { return true; } - function checkReferenceExpression(n: Node, message: DiagnosticMessage): boolean { + function checkReferenceExpression(n: Node, invalidReferenceMessage: DiagnosticMessage, constantVarianleMessage: DiagnosticMessage): boolean { function findSymbol(n: Node): Symbol { var symbol = getNodeLinks(n).resolvedSymbol; // Because we got the symbol from the resolvedSymbol property, it might be of kind @@ -4962,8 +4964,20 @@ module ts { } } + function isConstVariableReference(n: Node) { + if (n.kind === SyntaxKind.Identifier) { + var symbol = findSymbol(n); + return symbol && (symbol.flags & SymbolFlags.Variable) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & NodeFlags.Const) !== 0; + } + return false; + } + if (!isReferenceOrErrorExpression(n)) { - error(n, message); + error(n, invalidReferenceMessage); + return false; + } + if (isConstVariableReference(n)) { + error(n, constantVarianleMessage); return false; } return true; @@ -4988,7 +5002,9 @@ module ts { var ok = checkArithmeticOperandType(node.operand, operandType, Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type); if (ok) { // run check only if former checks succeeded to avoid reporting cascading errors - checkReferenceExpression(node.operand, Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer); + checkReferenceExpression(node.operand, + Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer, + Diagnostics.The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant); } return numberType; } @@ -5000,7 +5016,9 @@ module ts { var ok = checkArithmeticOperandType(node.operand, operandType, Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type); if (ok) { // run check only if former checks succeeded to avoid reporting cascading errors - checkReferenceExpression(node.operand, Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer); + checkReferenceExpression(node.operand, + Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer, + Diagnostics.The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant); } return numberType; } @@ -5177,7 +5195,7 @@ module ts { // requires VarExpr to be classified as a reference // A compound assignment furthermore requires VarExpr to be classified as a reference (section 4.1) // and the type of the non - compound operation to be assignable to the type of VarExpr. - var ok = checkReferenceExpression(node.left, Diagnostics.Invalid_left_hand_side_of_assignment_expression); + var ok = checkReferenceExpression(node.left, Diagnostics.Invalid_left_hand_side_of_assignment_expression, Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); // Use default messages if (ok) { // to avoid cascading errors check assignability only if 'isReference' check succeeded and no errors were reported @@ -6252,7 +6270,7 @@ module ts { } else { // run check only former check succeeded to avoid cascading errors - checkReferenceExpression(node.variable, Diagnostics.Invalid_left_hand_side_in_for_in_statement); + checkReferenceExpression(node.variable, Diagnostics.Invalid_left_hand_side_in_for_in_statement, Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); } } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index f2a1f6abc03..5d4acbbc67b 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -270,6 +270,8 @@ module ts { Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1: { code: 2446, category: DiagnosticCategory.Error, key: "Property '{0}' is protected and only accessible through an instance of class '{1}'." }, The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead: { code: 2447, category: DiagnosticCategory.Error, key: "The '{0}' operator is not allowed for boolean types. Consider using '{1}' instead." }, Block_scoped_variable_0_used_before_its_declaration: { code: 2448, category: DiagnosticCategory.Error, key: "Block-scoped variable '{0}' used before its declaration." }, + The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant: { code: 2449, category: DiagnosticCategory.Error, key: "The operand of an increment or decrement operator cannot be a constant." }, + Left_hand_side_of_assignment_expression_cannot_be_a_constant: { code: 2450, category: DiagnosticCategory.Error, key: "Left-hand side of assignment expression cannot be a constant." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4001, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index dddd3ddb3d2..937d6cdd614 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1072,6 +1072,14 @@ "category": "Error", "code": 2448 }, + "The operand of an increment or decrement operator cannot be a constant.": { + "category": "Error", + "code": 2449 + }, + "Left-hand side of assignment expression cannot be a constant.": { + "category": "Error", + "code": 2450 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/tests/baselines/reference/constDeclarations-access.errors.txt b/tests/baselines/reference/constDeclarations-access.errors.txt new file mode 100644 index 00000000000..04b942aec09 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-access.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/file2.ts(1,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. + + +==== tests/cases/compiler/file1.ts (0 errors) ==== + + const x = 0 + +==== tests/cases/compiler/file2.ts (1 errors) ==== + x++; + ~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-access.js b/tests/baselines/reference/constDeclarations-access.js new file mode 100644 index 00000000000..ba913f2d5fc --- /dev/null +++ b/tests/baselines/reference/constDeclarations-access.js @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/constDeclarations-access.ts] //// + +//// [file1.ts] + +const x = 0 + +//// [file2.ts] +x++; + +//// [file1.js] +const x = 0; +//// [file2.js] +x++; diff --git a/tests/baselines/reference/constDeclarations-access2.errors.txt b/tests/baselines/reference/constDeclarations-access2.errors.txt new file mode 100644 index 00000000000..f3bf7d1d750 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-access2.errors.txt @@ -0,0 +1,89 @@ +tests/cases/compiler/constDeclarations-access2.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(6,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(7,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(16,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(18,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(19,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(20,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(21,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. + + +==== tests/cases/compiler/constDeclarations-access2.ts (16 errors) ==== + + const x = 0 + + // Errors + x = 1; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x += 2; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x -= 3; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x *= 4; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x /= 5; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x %= 6; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x <<= 7; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x >>= 8; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x >>>= 9; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x &= 10; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x |= 11; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x ^= 12; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + + x++; + ~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + x--; + ~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + ++x; + ~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + --x; + ~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + + // OK + var a = x + 1; + + function f(v: number) { } + f(x); + + if (x) { } + + x; + (x); + + -x; + +x; + + x.toString(); + \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-access2.js b/tests/baselines/reference/constDeclarations-access2.js new file mode 100644 index 00000000000..e2a1bcd9fa5 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-access2.js @@ -0,0 +1,71 @@ +//// [constDeclarations-access2.ts] + +const x = 0 + +// Errors +x = 1; +x += 2; +x -= 3; +x *= 4; +x /= 5; +x %= 6; +x <<= 7; +x >>= 8; +x >>>= 9; +x &= 10; +x |= 11; +x ^= 12; + +x++; +x--; +++x; +--x; + +// OK +var a = x + 1; + +function f(v: number) { } +f(x); + +if (x) { } + +x; +(x); + +-x; ++x; + +x.toString(); + + +//// [constDeclarations-access2.js] +const x = 0; +// Errors +x = 1; +x += 2; +x -= 3; +x *= 4; +x /= 5; +x %= 6; +x <<= 7; +x >>= 8; +x >>>= 9; +x &= 10; +x |= 11; +x ^= 12; +x++; +x--; +++x; +--x; +// OK +var a = x + 1; +function f(v) { +} +f(x); +if (x) { +} +x; +(x); +-x; ++x; +x.toString(); diff --git a/tests/baselines/reference/letDeclarations-access.js b/tests/baselines/reference/letDeclarations-access.js new file mode 100644 index 00000000000..404c2876310 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-access.js @@ -0,0 +1,70 @@ +//// [letDeclarations-access.ts] + +let x = 0 + +// No errors + +x = 1; +x += 2; +x -= 3; +x *= 4; +x /= 5; +x %= 6; +x <<= 7; +x >>= 8; +x >>>= 9; +x &= 10; +x |= 11; +x ^= 12; + +x++; +x--; +++x; +--x; + +var a = x + 1; + +function f(v: number) { } +f(x); + +if (x) { } + +x; +(x); + +-x; ++x; + +x.toString(); + + +//// [letDeclarations-access.js] +let x = 0; +// No errors +x = 1; +x += 2; +x -= 3; +x *= 4; +x /= 5; +x %= 6; +x <<= 7; +x >>= 8; +x >>>= 9; +x &= 10; +x |= 11; +x ^= 12; +x++; +x--; +++x; +--x; +var a = x + 1; +function f(v) { +} +f(x); +if (x) { +} +x; +(x); +-x; ++x; +x.toString(); diff --git a/tests/baselines/reference/letDeclarations-access.types b/tests/baselines/reference/letDeclarations-access.types new file mode 100644 index 00000000000..f26d07ca5f8 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-access.types @@ -0,0 +1,109 @@ +=== tests/cases/compiler/letDeclarations-access.ts === + +let x = 0 +>x : number + +// No errors + +x = 1; +>x = 1 : number +>x : number + +x += 2; +>x += 2 : number +>x : number + +x -= 3; +>x -= 3 : number +>x : number + +x *= 4; +>x *= 4 : number +>x : number + +x /= 5; +>x /= 5 : number +>x : number + +x %= 6; +>x %= 6 : number +>x : number + +x <<= 7; +>x <<= 7 : number +>x : number + +x >>= 8; +>x >>= 8 : number +>x : number + +x >>>= 9; +>x >>>= 9 : number +>x : number + +x &= 10; +>x &= 10 : number +>x : number + +x |= 11; +>x |= 11 : number +>x : number + +x ^= 12; +>x ^= 12 : number +>x : number + +x++; +>x++ : number +>x : number + +x--; +>x-- : number +>x : number + +++x; +>++x : number +>x : number + +--x; +>--x : number +>x : number + +var a = x + 1; +>a : number +>x + 1 : number +>x : number + +function f(v: number) { } +>f : (v: number) => void +>v : number + +f(x); +>f(x) : void +>f : (v: number) => void +>x : number + +if (x) { } +>x : number + +x; +>x : number + +(x); +>(x) : number +>x : number + +-x; +>-x : number +>x : number + ++x; +>+x : number +>x : number + +x.toString(); +>x.toString() : string +>x.toString : (radix?: number) => string +>x : number +>toString : (radix?: number) => string + diff --git a/tests/cases/compiler/constDeclarations-access.ts b/tests/cases/compiler/constDeclarations-access.ts new file mode 100644 index 00000000000..665d6753a6d --- /dev/null +++ b/tests/cases/compiler/constDeclarations-access.ts @@ -0,0 +1,7 @@ +// @target: ES6 + +// @Filename: file1.ts +const x = 0 + +// @Filename: file2.ts +x++; \ No newline at end of file diff --git a/tests/cases/compiler/constDeclarations-access2.ts b/tests/cases/compiler/constDeclarations-access2.ts new file mode 100644 index 00000000000..e46889c1126 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-access2.ts @@ -0,0 +1,38 @@ +// @target: ES6 + +const x = 0 + +// Errors +x = 1; +x += 2; +x -= 3; +x *= 4; +x /= 5; +x %= 6; +x <<= 7; +x >>= 8; +x >>>= 9; +x &= 10; +x |= 11; +x ^= 12; + +x++; +x--; +++x; +--x; + +// OK +var a = x + 1; + +function f(v: number) { } +f(x); + +if (x) { } + +x; +(x); + +-x; ++x; + +x.toString(); diff --git a/tests/cases/compiler/letDeclarations-access.ts b/tests/cases/compiler/letDeclarations-access.ts new file mode 100644 index 00000000000..6ed655f1cb2 --- /dev/null +++ b/tests/cases/compiler/letDeclarations-access.ts @@ -0,0 +1,38 @@ +// @target: ES6 + +let x = 0 + +// No errors + +x = 1; +x += 2; +x -= 3; +x *= 4; +x /= 5; +x %= 6; +x <<= 7; +x >>= 8; +x >>>= 9; +x &= 10; +x |= 11; +x ^= 12; + +x++; +x--; +++x; +--x; + +var a = x + 1; + +function f(v: number) { } +f(x); + +if (x) { } + +x; +(x); + +-x; ++x; + +x.toString(); From 82f5fb4055c98ded41f6d6d275cc06c2f286ab2b Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 14 Oct 2014 17:15:11 -0700 Subject: [PATCH 10/63] Flag const declarations shodowed by var redeclarations --- src/compiler/checker.ts | 32 ++++++++++++++ .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 ++ ...arationShadowedByVarDeclaration.errors.txt | 35 +++++++++++++++ ...onstDeclarationShadowedByVarDeclaration.js | 43 +++++++++++++++++++ ...onstDeclarationShadowedByVarDeclaration.ts | 24 +++++++++++ 6 files changed, 139 insertions(+) create mode 100644 tests/baselines/reference/constDeclarationShadowedByVarDeclaration.errors.txt create mode 100644 tests/baselines/reference/constDeclarationShadowedByVarDeclaration.js create mode 100644 tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5bba99c6d43..6927be355a8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6174,6 +6174,36 @@ module ts { } } + function checkCollisionsWithConstDeclarations(node: VariableDeclaration) { + // Variable declarations are hoisted to the top of their function scope. They can shadow + // block scoped declarations, which bind tighter. this will not be flagged as duplicate definition + // by the binder as the declaration scope is different. + // A non-initialized declaration is a no-op as the block declaration will resolve before the var + // declaration. the problem is if the declaration has an initializer. this will act as a write to the + // block declared value. this is fine for let, but not const. + // + // Only consider declarations with initializers, uninitialized var declarations will not + // step on a const variable. + // Do not consider let and const declarations, as duplicate block-scoped declarations + // are handled by the binder. + // We are only looking for var declarations that step on const declarations from a + // different scope. e.g.: + // var x = 0; + // { + // const x = 0; + // var x = 0; + // } + if (node.initializer && (node.flags & NodeFlags.BlockScoped) === 0) { + var symbol = getSymbolOfNode(node); + var localDeclarationSymbol = resolveName(node, node.name.text, SymbolFlags.BlockScoped, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined); + if (localDeclarationSymbol && localDeclarationSymbol !== symbol) { + if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & NodeFlags.Const) { + error(node, Diagnostics.Cannot_redeclare_constant_0, symbolToString(localDeclarationSymbol)); + } + } + } + } + function checkVariableDeclaration(node: VariableDeclaration) { checkSourceElement(node.type); checkExportsOnMergedDeclarations(node); @@ -6197,6 +6227,8 @@ module ts { // Use default messages checkTypeAssignableTo(checkAndMarkExpression(node.initializer), type, node, /*chainedMessage*/ undefined, /*terminalMessage*/ undefined); } + + checkCollisionsWithConstDeclarations(node); } checkCollisionWithCapturedSuperVariable(node, node.name); diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 5d4acbbc67b..86a66c468ab 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -272,6 +272,7 @@ module ts { Block_scoped_variable_0_used_before_its_declaration: { code: 2448, category: DiagnosticCategory.Error, key: "Block-scoped variable '{0}' used before its declaration." }, The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant: { code: 2449, category: DiagnosticCategory.Error, key: "The operand of an increment or decrement operator cannot be a constant." }, Left_hand_side_of_assignment_expression_cannot_be_a_constant: { code: 2450, category: DiagnosticCategory.Error, key: "Left-hand side of assignment expression cannot be a constant." }, + Cannot_redeclare_constant_0: { code: 2451, category: DiagnosticCategory.Error, key: "Cannot redeclare constant '{0}'." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4001, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 937d6cdd614..ebe9a815b50 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1080,6 +1080,10 @@ "category": "Error", "code": 2450 }, + "Cannot redeclare constant '{0}'.": { + "category": "Error", + "code": 2451 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/tests/baselines/reference/constDeclarationShadowedByVarDeclaration.errors.txt b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration.errors.txt new file mode 100644 index 00000000000..662628e0692 --- /dev/null +++ b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration.errors.txt @@ -0,0 +1,35 @@ +tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts(7,9): error TS2451: Cannot redeclare constant 'x'. +tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts(15,13): error TS2451: Cannot redeclare constant 'y'. +tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts(22,7): error TS2451: Cannot redeclare constant 'z'. + + +==== tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts (3 errors) ==== + + // Error as declaration of var would cause a write to the const value + var x = 0; + { + const x = 0; + + var x = 0; + ~ +!!! error TS2451: Cannot redeclare constant 'x'. + } + + + var y = 0; + { + const y = 0; + { + var y = 0; + ~ +!!! error TS2451: Cannot redeclare constant 'y'. + } + } + + + { + const z = 0; + var z = 0 + ~ +!!! error TS2451: Cannot redeclare constant 'z'. + } \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarationShadowedByVarDeclaration.js b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration.js new file mode 100644 index 00000000000..9fcc9f8f568 --- /dev/null +++ b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration.js @@ -0,0 +1,43 @@ +//// [constDeclarationShadowedByVarDeclaration.ts] + +// Error as declaration of var would cause a write to the const value +var x = 0; +{ + const x = 0; + + var x = 0; +} + + +var y = 0; +{ + const y = 0; + { + var y = 0; + } +} + + +{ + const z = 0; + var z = 0 +} + +//// [constDeclarationShadowedByVarDeclaration.js] +// Error as declaration of var would cause a write to the const value +var x = 0; +{ + const x = 0; + var x = 0; +} +var y = 0; +{ + const y = 0; + { + var y = 0; + } +} +{ + const z = 0; + var z = 0; +} diff --git a/tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts b/tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts new file mode 100644 index 00000000000..a4d39233847 --- /dev/null +++ b/tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts @@ -0,0 +1,24 @@ +// @target: ES6 + +// Error as declaration of var would cause a write to the const value +var x = 0; +{ + const x = 0; + + var x = 0; +} + + +var y = 0; +{ + const y = 0; + { + var y = 0; + } +} + + +{ + const z = 0; + var z = 0 +} \ No newline at end of file From 3e4560147bb03a7ad471ebc8487a11d8adcfe66c Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 14 Oct 2014 17:37:46 -0700 Subject: [PATCH 11/63] Allow const in for statements --- .../diagnosticInformationMap.generated.ts | 4 +- src/compiler/diagnosticMessages.json | 4 +- src/compiler/parser.ts | 15 ++++-- .../constDeclarations-errors.errors.txt | 53 +++++++------------ .../constDeclarations-es5.errors.txt | 12 ++--- .../reference/constDeclarations-scopes2.js | 27 ++++++++++ .../reference/constDeclarations-scopes2.types | 32 +++++++++++ .../baselines/reference/constDeclarations.js | 13 ++++- .../reference/constDeclarations.types | 14 +++++ .../compiler/constDeclarations-errors.ts | 11 +++- .../compiler/constDeclarations-scopes2.ts | 15 ++++++ tests/cases/compiler/constDeclarations.ts | 6 +++ 12 files changed, 156 insertions(+), 50 deletions(-) create mode 100644 tests/baselines/reference/constDeclarations-scopes2.js create mode 100644 tests/baselines/reference/constDeclarations-scopes2.types create mode 100644 tests/cases/compiler/constDeclarations-scopes2.ts diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 86a66c468ab..2fde444dff2 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -116,8 +116,8 @@ module ts { new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: DiagnosticCategory.Error, key: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, An_enum_member_cannot_have_a_numeric_name: { code: 1151, category: DiagnosticCategory.Error, key: "An enum member cannot have a numeric name." }, var_let_or_const_expected: { code: 1152, category: DiagnosticCategory.Error, key: "'var', 'let' or 'const' expected." }, - let_variable_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1153, category: DiagnosticCategory.Error, key: "'let' variable declarations are only available when targeting ECMAScript 6 and higher." }, - const_variable_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1154, category: DiagnosticCategory.Error, key: "'const' variable declarations are only available when targeting ECMAScript 6 and higher." }, + let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1153, category: DiagnosticCategory.Error, key: "'let' declarations are only available when targeting ECMAScript 6 and higher." }, + const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1154, category: DiagnosticCategory.Error, key: "'const' declarations are only available when targeting ECMAScript 6 and higher." }, const_must_be_intialized: { code: 1155, category: DiagnosticCategory.Error, key: "const must be intialized." }, const_must_be_declared_inside_a_block: { code: 1156, category: DiagnosticCategory.Error, key: "const must be declared inside a block." }, let_must_be_declared_inside_a_block: { code: 1157, category: DiagnosticCategory.Error, key: "let must be declared inside a block." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index ebe9a815b50..b2f98559ed8 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -455,11 +455,11 @@ "category": "Error", "code": 1152 }, - "'let' variable declarations are only available when targeting ECMAScript 6 and higher.": { + "'let' declarations are only available when targeting ECMAScript 6 and higher.": { "category": "Error", "code": 1153 }, - "'const' variable declarations are only available when targeting ECMAScript 6 and higher.": { + "'const' declarations are only available when targeting ECMAScript 6 and higher.": { "category": "Error", "code": 1154 }, diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index d8d1d24a97e..ad514adebed 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2654,7 +2654,16 @@ module ts { error(Diagnostics.Variable_declaration_list_cannot_be_empty); } if (languageVersion < ScriptTarget.ES6) { - grammarErrorAtPos(declarations.pos, declarations.end - declarations.pos, Diagnostics.let_variable_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); + grammarErrorAtPos(declarations.pos, declarations.end - declarations.pos, Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); + } + } + else if (parseOptional(SyntaxKind.ConstKeyword)) { + var declarations = parseVariableDeclarationList(NodeFlags.Const, true); + if (!declarations.length) { + error(Diagnostics.Variable_declaration_list_cannot_be_empty); + } + if (languageVersion < ScriptTarget.ES6) { + grammarErrorAtPos(declarations.pos, declarations.end - declarations.pos, Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); } } else { @@ -3145,10 +3154,10 @@ module ts { } if (languageVersion < ScriptTarget.ES6) { if (node.flags & NodeFlags.Let) { - grammarErrorOnNode(node, Diagnostics.let_variable_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); + grammarErrorOnNode(node, Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); } else if (node.flags & NodeFlags.Const) { - grammarErrorOnNode(node, Diagnostics.const_variable_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); + grammarErrorOnNode(node, Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); } } else if (!allowLetDeclarations){ diff --git a/tests/baselines/reference/constDeclarations-errors.errors.txt b/tests/baselines/reference/constDeclarations-errors.errors.txt index 9a922ac93a9..1766fb49374 100644 --- a/tests/baselines/reference/constDeclarations-errors.errors.txt +++ b/tests/baselines/reference/constDeclarations-errors.errors.txt @@ -4,20 +4,13 @@ tests/cases/compiler/constDeclarations-errors.ts(5,7): error TS1155: const must tests/cases/compiler/constDeclarations-errors.ts(5,11): error TS1155: const must be intialized. tests/cases/compiler/constDeclarations-errors.ts(5,15): error TS1155: const must be intialized. tests/cases/compiler/constDeclarations-errors.ts(5,27): error TS1155: const must be intialized. -tests/cases/compiler/constDeclarations-errors.ts(8,5): error TS1109: Expression expected. -tests/cases/compiler/constDeclarations-errors.ts(8,5): error TS1156: const must be declared inside a block. tests/cases/compiler/constDeclarations-errors.ts(8,11): error TS1155: const must be intialized. -tests/cases/compiler/constDeclarations-errors.ts(8,13): error TS1005: ';' expected. -tests/cases/compiler/constDeclarations-errors.ts(8,13): error TS1128: Declaration or statement expected. -tests/cases/compiler/constDeclarations-errors.ts(8,18): error TS1128: Declaration or statement expected. -tests/cases/compiler/constDeclarations-errors.ts(10,5): error TS1109: Expression expected. -tests/cases/compiler/constDeclarations-errors.ts(10,5): error TS1156: const must be declared inside a block. -tests/cases/compiler/constDeclarations-errors.ts(10,28): error TS1005: ';' expected. -tests/cases/compiler/constDeclarations-errors.ts(10,18): error TS2304: Cannot find name 'c'. -tests/cases/compiler/constDeclarations-errors.ts(10,25): error TS2304: Cannot find name 'c'. +tests/cases/compiler/constDeclarations-errors.ts(14,11): error TS1155: const must be intialized. +tests/cases/compiler/constDeclarations-errors.ts(17,20): error TS1155: const must be intialized. +tests/cases/compiler/constDeclarations-errors.ts(11,27): error TS2449: The operand of an increment or decrement operator cannot be a constant. -==== tests/cases/compiler/constDeclarations-errors.ts (17 errors) ==== +==== tests/cases/compiler/constDeclarations-errors.ts (10 errors) ==== // error, missing intialicer const c1; @@ -36,30 +29,22 @@ tests/cases/compiler/constDeclarations-errors.ts(10,25): error TS2304: Cannot fi ~~ !!! error TS1155: const must be intialized. - // error, wrong context + // error, can not be unintalized for(const c in {}) { } - ~~~~~ -!!! error TS1109: Expression expected. - ~~~~~~~ -!!! error TS1156: const must be declared inside a block. ~ !!! error TS1155: const must be intialized. - ~~ -!!! error TS1005: ';' expected. - ~~ -!!! error TS1128: Declaration or statement expected. - ~ -!!! error TS1128: Declaration or statement expected. - for(const c = 0; c < 9; c++) { } - ~~~~~ -!!! error TS1109: Expression expected. - ~~~~~~~~~~~~ -!!! error TS1156: const must be declared inside a block. - ~ -!!! error TS1005: ';' expected. - ~ -!!! error TS2304: Cannot find name 'c'. - ~ -!!! error TS2304: Cannot find name 'c'. - \ No newline at end of file + // error, assigning to a const + for(const c8 = 0; c8 < 1; c8++) { } + ~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + + // error, can not be unintalized + for(const c9; c9 < 1;) { } + ~~ +!!! error TS1155: const must be intialized. + + // error, can not be unintalized + for(const c10 = 0, c11; c10 < 1;) { } + ~~~ +!!! error TS1155: const must be intialized. \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-es5.errors.txt b/tests/baselines/reference/constDeclarations-es5.errors.txt index a941b826ed0..0b830eab05a 100644 --- a/tests/baselines/reference/constDeclarations-es5.errors.txt +++ b/tests/baselines/reference/constDeclarations-es5.errors.txt @@ -1,17 +1,17 @@ -tests/cases/compiler/constDeclarations-es5.ts(2,1): error TS1154: 'const' variable declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/constDeclarations-es5.ts(3,1): error TS1154: 'const' variable declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/constDeclarations-es5.ts(4,1): error TS1154: 'const' variable declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/constDeclarations-es5.ts(2,1): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/constDeclarations-es5.ts(3,1): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/constDeclarations-es5.ts(4,1): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. ==== tests/cases/compiler/constDeclarations-es5.ts (3 errors) ==== const z7 = false; ~~~~~~~~~~~~~~~~~ -!!! error TS1154: 'const' variable declarations are only available when targeting ECMAScript 6 and higher. +!!! error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. const z8: number = 23; ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1154: 'const' variable declarations are only available when targeting ECMAScript 6 and higher. +!!! error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. const z9 = 0, z10 :string = "", z11 = null; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1154: 'const' variable declarations are only available when targeting ECMAScript 6 and higher. +!!! error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-scopes2.js b/tests/baselines/reference/constDeclarations-scopes2.js new file mode 100644 index 00000000000..be9514e18a7 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-scopes2.js @@ -0,0 +1,27 @@ +//// [constDeclarations-scopes2.ts] + +// global +const c = "string"; + +var n: number; +var b: boolean; + +// for scope +for (const c = 0; c < 10; n = c ) { + // for block + const c = false; + b = c; +} + + + +//// [constDeclarations-scopes2.js] +// global +const c = "string"; +var n; +var b; +for (var c = 0; c < 10; n = c) { + // for block + const c = false; + b = c; +} diff --git a/tests/baselines/reference/constDeclarations-scopes2.types b/tests/baselines/reference/constDeclarations-scopes2.types new file mode 100644 index 00000000000..9609ef8f44b --- /dev/null +++ b/tests/baselines/reference/constDeclarations-scopes2.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/constDeclarations-scopes2.ts === + +// global +const c = "string"; +>c : string + +var n: number; +>n : number + +var b: boolean; +>b : boolean + +// for scope +for (const c = 0; c < 10; n = c ) { +>c : number +>c < 10 : boolean +>c : number +>n = c : number +>n : number +>c : number + + // for block + const c = false; +>c : boolean + + b = c; +>b = c : boolean +>b : boolean +>c : boolean +} + + diff --git a/tests/baselines/reference/constDeclarations.js b/tests/baselines/reference/constDeclarations.js index 23d87d2c2a7..d6371da863e 100644 --- a/tests/baselines/reference/constDeclarations.js +++ b/tests/baselines/reference/constDeclarations.js @@ -4,13 +4,24 @@ const c1 = false; const c2: number = 23; const c3 = 0, c4 :string = "", c5 = null; - + + +for(const c4 = 0; c4 < 9; ) { break; } + + +for(const c5 = 0, c6 = 0; c5 < c6; ) { break; } //// [constDeclarations.js] // No error const c1 = false; const c2 = 23; const c3 = 0, c4 = "", c5 = null; +for (var c4 = 0; c4 < 9;) { + break; +} +for (var c5 = 0, c6 = 0; c5 < c6;) { + break; +} //// [constDeclarations.d.ts] diff --git a/tests/baselines/reference/constDeclarations.types b/tests/baselines/reference/constDeclarations.types index 7faa37f85bc..e82a2f0035f 100644 --- a/tests/baselines/reference/constDeclarations.types +++ b/tests/baselines/reference/constDeclarations.types @@ -12,3 +12,17 @@ const c3 = 0, c4 :string = "", c5 = null; >c4 : string >c5 : any + +for(const c4 = 0; c4 < 9; ) { break; } +>c4 : number +>c4 < 9 : boolean +>c4 : number + + +for(const c5 = 0, c6 = 0; c5 < c6; ) { break; } +>c5 : number +>c6 : number +>c5 < c6 : boolean +>c5 : number +>c6 : number + diff --git a/tests/cases/compiler/constDeclarations-errors.ts b/tests/cases/compiler/constDeclarations-errors.ts index 08ccaf7fe18..09dc0e96790 100644 --- a/tests/cases/compiler/constDeclarations-errors.ts +++ b/tests/cases/compiler/constDeclarations-errors.ts @@ -5,7 +5,14 @@ const c1; const c2: number; const c3, c4, c5 :string, c6; // error, missing initialicer -// error, wrong context +// error, can not be unintalized for(const c in {}) { } -for(const c = 0; c < 9; c++) { } +// error, assigning to a const +for(const c8 = 0; c8 < 1; c8++) { } + +// error, can not be unintalized +for(const c9; c9 < 1;) { } + +// error, can not be unintalized +for(const c10 = 0, c11; c10 < 1;) { } \ No newline at end of file diff --git a/tests/cases/compiler/constDeclarations-scopes2.ts b/tests/cases/compiler/constDeclarations-scopes2.ts new file mode 100644 index 00000000000..fe0ab16409a --- /dev/null +++ b/tests/cases/compiler/constDeclarations-scopes2.ts @@ -0,0 +1,15 @@ +// @target: ES6 + +// global +const c = "string"; + +var n: number; +var b: boolean; + +// for scope +for (const c = 0; c < 10; n = c ) { + // for block + const c = false; + b = c; +} + diff --git a/tests/cases/compiler/constDeclarations.ts b/tests/cases/compiler/constDeclarations.ts index 36e01551a66..2b8563b340a 100644 --- a/tests/cases/compiler/constDeclarations.ts +++ b/tests/cases/compiler/constDeclarations.ts @@ -5,3 +5,9 @@ const c1 = false; const c2: number = 23; const c3 = 0, c4 :string = "", c5 = null; + + +for(const c4 = 0; c4 < 9; ) { break; } + + +for(const c5 = 0, c6 = 0; c5 < c6; ) { break; } \ No newline at end of file From 03a100d03921b659b2c6b6eeaf284d0685c57d46 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 15 Oct 2014 09:15:00 -0700 Subject: [PATCH 12/63] Do not allow let and const declarations to be exported from a module --- .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 +++ src/compiler/parser.ts | 5 ++- .../reference/constDeclarations2.errors.txt | 20 ++++++++++++ .../baselines/reference/constDeclarations2.js | 26 --------------- .../reference/constDeclarations2.types | 18 ----------- .../reference/letDeclarations-es5.errors.txt | 32 +++++++++---------- .../reference/letDeclarations2.errors.txt | 11 +++++++ tests/baselines/reference/letDeclarations2.js | 19 ----------- .../reference/letDeclarations2.types | 11 ------- 10 files changed, 56 insertions(+), 91 deletions(-) create mode 100644 tests/baselines/reference/constDeclarations2.errors.txt delete mode 100644 tests/baselines/reference/constDeclarations2.js delete mode 100644 tests/baselines/reference/constDeclarations2.types create mode 100644 tests/baselines/reference/letDeclarations2.errors.txt delete mode 100644 tests/baselines/reference/letDeclarations2.js delete mode 100644 tests/baselines/reference/letDeclarations2.types diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 2fde444dff2..c9d296d8bcc 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -121,6 +121,7 @@ module ts { const_must_be_intialized: { code: 1155, category: DiagnosticCategory.Error, key: "const must be intialized." }, const_must_be_declared_inside_a_block: { code: 1156, category: DiagnosticCategory.Error, key: "const must be declared inside a block." }, let_must_be_declared_inside_a_block: { code: 1157, category: DiagnosticCategory.Error, key: "let must be declared inside a block." }, + Only_var_declarations_can_be_exported: { code: 1158, category: DiagnosticCategory.Error, key: "Only var declarations can be exported." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b2f98559ed8..68b5395224a 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -475,6 +475,10 @@ "category": "Error", "code": 1157 }, + "Only var declarations can be exported.": { + "category": "Error", + "code": 1158 + }, "Duplicate identifier '{0}'.": { "category": "Error", diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index ad514adebed..b011220095c 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3160,7 +3160,7 @@ module ts { grammarErrorOnNode(node, Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); } } - else if (!allowLetDeclarations){ + else if (!allowLetDeclarations) { if (node.flags & NodeFlags.Let) { grammarErrorOnNode(node, Diagnostics.let_must_be_declared_inside_a_block); } @@ -3168,6 +3168,9 @@ module ts { grammarErrorOnNode(node, Diagnostics.const_must_be_declared_inside_a_block); } } + else if (node.flags & NodeFlags.Export && node.flags & NodeFlags.BlockScoped) { + grammarErrorOnNode(node, Diagnostics.Only_var_declarations_can_be_exported); + } return node; } diff --git a/tests/baselines/reference/constDeclarations2.errors.txt b/tests/baselines/reference/constDeclarations2.errors.txt new file mode 100644 index 00000000000..39317b599f9 --- /dev/null +++ b/tests/baselines/reference/constDeclarations2.errors.txt @@ -0,0 +1,20 @@ +tests/cases/compiler/constDeclarations2.ts(4,5): error TS1158: Only var declarations can be exported. +tests/cases/compiler/constDeclarations2.ts(5,5): error TS1158: Only var declarations can be exported. +tests/cases/compiler/constDeclarations2.ts(6,5): error TS1158: Only var declarations can be exported. + + +==== tests/cases/compiler/constDeclarations2.ts (3 errors) ==== + + // No error + module M { + export const c1 = false; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1158: Only var declarations can be exported. + export const c2: number = 23; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1158: Only var declarations can be exported. + export const c3 = 0, c4 :string = "", c5 = null; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1158: Only var declarations can be exported. + } + \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations2.js b/tests/baselines/reference/constDeclarations2.js deleted file mode 100644 index e4ee67ebdcd..00000000000 --- a/tests/baselines/reference/constDeclarations2.js +++ /dev/null @@ -1,26 +0,0 @@ -//// [constDeclarations2.ts] - -// No error -module M { - export const c1 = false; - export const c2: number = 23; - export const c3 = 0, c4 :string = "", c5 = null; -} - - -//// [constDeclarations2.js] -// No error -var M; -(function (M) { - M.c1 = false; - M.c2 = 23; - M.c3 = 0, M.c4 = "", M.c5 = null; -})(M || (M = {})); - - -//// [constDeclarations2.d.ts] -declare module M { - const c1: boolean; - const c2: number; - const c3: number, c4: string, c5: any; -} diff --git a/tests/baselines/reference/constDeclarations2.types b/tests/baselines/reference/constDeclarations2.types deleted file mode 100644 index c81eca96b0d..00000000000 --- a/tests/baselines/reference/constDeclarations2.types +++ /dev/null @@ -1,18 +0,0 @@ -=== tests/cases/compiler/constDeclarations2.ts === - -// No error -module M { ->M : typeof M - - export const c1 = false; ->c1 : boolean - - export const c2: number = 23; ->c2 : number - - export const c3 = 0, c4 :string = "", c5 = null; ->c3 : number ->c4 : string ->c5 : any -} - diff --git a/tests/baselines/reference/letDeclarations-es5.errors.txt b/tests/baselines/reference/letDeclarations-es5.errors.txt index 2a5858350cd..be1a56a8b7f 100644 --- a/tests/baselines/reference/letDeclarations-es5.errors.txt +++ b/tests/baselines/reference/letDeclarations-es5.errors.txt @@ -1,40 +1,40 @@ -tests/cases/compiler/letDeclarations-es5.ts(2,1): error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5.ts(3,1): error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5.ts(4,1): error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5.ts(6,1): error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5.ts(7,1): error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5.ts(8,1): error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5.ts(10,8): error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5.ts(12,8): error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(2,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(3,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(4,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(6,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(7,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(8,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(10,8): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(12,8): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. ==== tests/cases/compiler/letDeclarations-es5.ts (8 errors) ==== let l1; ~~~~~~~ -!!! error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. let l2: number; ~~~~~~~~~~~~~~~ -!!! error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. let l3, l4, l5 :string, l6; ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. let l7 = false; ~~~~~~~~~~~~~~~ -!!! error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. let l8: number = 23; ~~~~~~~~~~~~~~~~~~~~ -!!! error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. let l9 = 0, l10 :string = "", l11 = null; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. for(let l11 in {}) { } ~~~~ -!!! error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. for(let l12 = 0; l12 < 9; l12++) { } ~~~~~~~~ -!!! error TS1153: 'let' variable declarations are only available when targeting ECMAScript 6 and higher. +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations2.errors.txt b/tests/baselines/reference/letDeclarations2.errors.txt new file mode 100644 index 00000000000..384912a2bb4 --- /dev/null +++ b/tests/baselines/reference/letDeclarations2.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/letDeclarations2.ts(4,5): error TS1158: Only var declarations can be exported. + + +==== tests/cases/compiler/letDeclarations2.ts (1 errors) ==== + + module M { + let l1 = "s"; + export let l2 = 0; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1158: Only var declarations can be exported. + } \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations2.js b/tests/baselines/reference/letDeclarations2.js deleted file mode 100644 index 8a6f039f2ca..00000000000 --- a/tests/baselines/reference/letDeclarations2.js +++ /dev/null @@ -1,19 +0,0 @@ -//// [letDeclarations2.ts] - -module M { - let l1 = "s"; - export let l2 = 0; -} - -//// [letDeclarations2.js] -var M; -(function (M) { - let l1 = "s"; - M.l2 = 0; -})(M || (M = {})); - - -//// [letDeclarations2.d.ts] -declare module M { - let l2: number; -} diff --git a/tests/baselines/reference/letDeclarations2.types b/tests/baselines/reference/letDeclarations2.types deleted file mode 100644 index 2fa08b6d940..00000000000 --- a/tests/baselines/reference/letDeclarations2.types +++ /dev/null @@ -1,11 +0,0 @@ -=== tests/cases/compiler/letDeclarations2.ts === - -module M { ->M : typeof M - - let l1 = "s"; ->l1 : string - - export let l2 = 0; ->l2 : number -} From 61549239d85e554d36eb85050fbae5d4edc3f0f8 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 15 Oct 2014 09:20:46 -0700 Subject: [PATCH 13/63] Fix emitting for const in for loops --- src/compiler/emitter.ts | 13 ++++--------- .../reference/constDeclarations-scopes2.js | 2 +- tests/baselines/reference/constDeclarations.js | 4 ++-- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 81022d04e31..8c0dd818d32 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1152,6 +1152,9 @@ module ts { if (node.declarations[0] && node.declarations[0].flags & NodeFlags.Let) { emitToken(SyntaxKind.LetKeyword, endPos); } + else if (node.declarations[0] && node.declarations[0].flags & NodeFlags.Const) { + emitToken(SyntaxKind.ConstKeyword, endPos); + } else { emitToken(SyntaxKind.VarKeyword, endPos); } @@ -1794,15 +1797,7 @@ module ts { if (node.flags & NodeFlags.Export) { writeLine(); emitStart(node); - if (node.flags & NodeFlags.Let) { - write("let "); - } - else if (node.flags & NodeFlags.Const) { - write("const "); - } - else { - write("var "); - } + write("var "); emit(node.name); write(" = "); emitModuleMemberName(node); diff --git a/tests/baselines/reference/constDeclarations-scopes2.js b/tests/baselines/reference/constDeclarations-scopes2.js index be9514e18a7..1d0f252ab4f 100644 --- a/tests/baselines/reference/constDeclarations-scopes2.js +++ b/tests/baselines/reference/constDeclarations-scopes2.js @@ -20,7 +20,7 @@ for (const c = 0; c < 10; n = c ) { const c = "string"; var n; var b; -for (var c = 0; c < 10; n = c) { +for (const c = 0; c < 10; n = c) { // for block const c = false; b = c; diff --git a/tests/baselines/reference/constDeclarations.js b/tests/baselines/reference/constDeclarations.js index d6371da863e..060c0aba61c 100644 --- a/tests/baselines/reference/constDeclarations.js +++ b/tests/baselines/reference/constDeclarations.js @@ -16,10 +16,10 @@ for(const c5 = 0, c6 = 0; c5 < c6; ) { break; } const c1 = false; const c2 = 23; const c3 = 0, c4 = "", c5 = null; -for (var c4 = 0; c4 < 9;) { +for (const c4 = 0; c4 < 9;) { break; } -for (var c5 = 0, c6 = 0; c5 < c6;) { +for (const c5 = 0, c6 = 0; c5 < c6;) { break; } From d33aa4335ff753d4721033dad1ad34cde3955d44 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 15 Oct 2014 14:45:33 -0700 Subject: [PATCH 14/63] Switched syntactic classifier to use new tree. Also added tests. --- src/harness/fourslash.ts | 24 +++- src/services/services.ts | 133 ++++++++---------- src/services/utilities.ts | 26 +++- tests/cases/fourslash/fourslash.ts | 24 ++-- ...cticClassificationsFunctionWithComments.ts | 25 ++++ .../syntacticClassificationsObjectLiteral.ts | 25 ++++ 6 files changed, 159 insertions(+), 98 deletions(-) create mode 100644 tests/cases/fourslash/syntacticClassificationsFunctionWithComments.ts create mode 100644 tests/cases/fourslash/syntacticClassificationsObjectLiteral.ts diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 9dad3dddf60..ea35bd069eb 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1612,7 +1612,9 @@ module FourSlash { private verifyClassifications(expected: { classificationType: string; text: string; textSpan?: TextSpan }[], actual: ts.ClassifiedSpan[]) { if (actual.length !== expected.length) { - this.raiseError('verifyClassifications failed - expected total classifications to be ' + expected.length + ', but was ' + actual.length); + this.raiseError('verifyClassifications failed - expected total classifications to be ' + expected.length + + ', but was ' + actual.length + + jsonMismatchString()); } for (var i = 0; i < expected.length; i++) { @@ -1623,7 +1625,8 @@ module FourSlash { if (expectedType !== actualClassification.classificationType) { this.raiseError('verifyClassifications failed - expected classifications type to be ' + expectedType + ', but was ' + - actualClassification.classificationType); + actualClassification.classificationType + + jsonMismatchString()); } var expectedSpan = expectedClassification.textSpan; @@ -1635,17 +1638,25 @@ module FourSlash { if (expectedSpan.start !== actualSpan.start() || expectedLength !== actualSpan.length()) { this.raiseError("verifyClassifications failed - expected span of text to be " + "{start=" + expectedSpan.start + ", length=" + expectedLength + "}, but was " + - "{start=" + actualSpan.start() + ", length=" + actualSpan.length() + "}"); + "{start=" + actualSpan.start() + ", length=" + actualSpan.length() + "}" + + jsonMismatchString()); } } var actualText = this.activeFile.content.substr(actualSpan.start(), actualSpan.length()); if (expectedClassification.text !== actualText) { - this.raiseError('verifyClassifications failed - expected classificatied text to be ' + + this.raiseError('verifyClassifications failed - expected classified text to be ' + expectedClassification.text + ', but was ' + - actualText); + actualText + + jsonMismatchString()); } } + + function jsonMismatchString() { + return sys.newLine + + "expected: '" + sys.newLine + JSON.stringify(expected, (k,v) => v, 2) + "'" + sys.newLine + + "actual: '" + sys.newLine + JSON.stringify(actual, (k, v) => v, 2) + "'"; + } } public verifySemanticClassifications(expected: { classificationType: string; text: string }[]) { @@ -1996,7 +2007,8 @@ module FourSlash { var newlinePos = text.indexOf('\n'); if (newlinePos === -1) { return text; - } else { + } + else { if (text.charAt(newlinePos - 1) === '\r') { newlinePos--; } diff --git a/src/services/services.ts b/src/services/services.ts index b07d12919cd..6afbe11c554 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4782,115 +4782,99 @@ module ts { var sourceFile = getCurrentSourceFile(fileName); var result: ClassifiedSpan[] = []; - processElement(sourceFile.getSourceUnit()); + processElement(sourceFile, sourceFile); return result; - function classifyTrivia(trivia: TypeScript.ISyntaxTrivia) { - if (trivia.isComment() && span.intersectsWith(trivia.fullStart(), trivia.fullWidth())) { + function classifyComment(comment: CommentRange) { + var width = comment.end - comment.pos; + if (span.intersectsWith(comment.pos, width)) { result.push({ - textSpan: new TypeScript.TextSpan(trivia.fullStart(), trivia.fullWidth()), + textSpan: new TypeScript.TextSpan(comment.pos, width), classificationType: ClassificationTypeNames.comment }); } } - function classifyTriviaList(trivia: TypeScript.ISyntaxTriviaList) { - for (var i = 0, n = trivia.count(); i < n; i++) { - classifyTrivia(trivia.syntaxTriviaAt(i)); - } - } + function classifyToken(token: Node, tokenOwner: Node, sourceFile: SourceFile): void { + forEach(getLeadingCommentRanges(sourceFile.text, token.getFullStart()), classifyComment); - function classifyToken(token: TypeScript.ISyntaxToken) { - if (token.hasLeadingComment()) { - classifyTriviaList(token.leadingTrivia()); - } - - if (TypeScript.width(token) > 0) { - var type = classifyTokenType(token); + if (token.getWidth() > 0) { + var type = classifyTokenType(token, tokenOwner); if (type) { result.push({ - textSpan: new TypeScript.TextSpan(TypeScript.start(token), TypeScript.width(token)), + textSpan: new TypeScript.TextSpan(token.getStart(), token.getWidth()), classificationType: type }); } } - if (token.hasTrailingComment()) { - classifyTriviaList(token.trailingTrivia()); - } + forEach(getTrailingCommentRanges(sourceFile.text, token.getEnd()), classifyComment); } - function classifyTokenType(token: TypeScript.ISyntaxToken): string { - var tokenKind = token.kind(); - if (TypeScript.SyntaxFacts.isAnyKeyword(token.kind())) { + function classifyTokenType(token: Node, tokenOwner: Node): string { + var tokenKind = token.kind; + if (isKeyword(tokenKind)) { return ClassificationTypeNames.keyword; } - // Special case < and > If they appear in a generic context they are punctation, + // Special case < and > If they appear in a generic context they are punctuation, // not operators. - if (tokenKind === TypeScript.SyntaxKind.LessThanToken || tokenKind === TypeScript.SyntaxKind.GreaterThanToken) { - var tokenParentKind = token.parent.kind(); - if (tokenParentKind === TypeScript.SyntaxKind.TypeArgumentList || - tokenParentKind === TypeScript.SyntaxKind.TypeParameterList) { - + if (tokenKind === SyntaxKind.LessThanToken || tokenKind === SyntaxKind.GreaterThanToken) { + var tokenParentKind = token.parent.kind; + // If the node owning the token has a type argument list or type parameter list, then + // we can effectively assume that a '<' and '>' belong to those lists. + if (getTypeArgumentOrTypeParameterList(tokenOwner)) { return ClassificationTypeNames.punctuation; } } - if (TypeScript.SyntaxFacts.isBinaryExpressionOperatorToken(tokenKind) || - TypeScript.SyntaxFacts.isPrefixUnaryExpressionOperatorToken(tokenKind)) { - return ClassificationTypeNames.operator; + if (isPunctuation(token)) { + if (tokenOwner.kind === SyntaxKind.BinaryExpression || + tokenOwner.kind === SyntaxKind.VariableDeclaration || // the '=' in a variable declaration is special cased here. + tokenOwner.kind === SyntaxKind.PrefixOperator || + tokenOwner.kind === SyntaxKind.PostfixOperator || + tokenOwner.kind === SyntaxKind.ConditionalExpression) { + return ClassificationTypeNames.operator; + } + else { + return ClassificationTypeNames.punctuation; + } } - else if (TypeScript.SyntaxFacts.isAnyPunctuation(tokenKind)) { - return ClassificationTypeNames.punctuation; - } - else if (tokenKind === TypeScript.SyntaxKind.NumericLiteral) { + else if (tokenKind === SyntaxKind.NumericLiteral) { return ClassificationTypeNames.numericLiteral; } - else if (tokenKind === TypeScript.SyntaxKind.StringLiteral) { + else if (tokenKind === SyntaxKind.StringLiteral) { return ClassificationTypeNames.stringLiteral; } - else if (tokenKind === TypeScript.SyntaxKind.RegularExpressionLiteral) { - // TODO: we shoudl get another classification type for these literals. + else if (tokenKind === SyntaxKind.RegularExpressionLiteral) { + // TODO: we should get another classification type for these literals. return ClassificationTypeNames.stringLiteral; } - else if (tokenKind === TypeScript.SyntaxKind.IdentifierName) { - var current: TypeScript.ISyntaxNodeOrToken = token; - var parent = token.parent; - while (parent.kind() === TypeScript.SyntaxKind.QualifiedName) { - current = parent; - parent = parent.parent; - } - - switch (parent.kind()) { - case TypeScript.SyntaxKind.SimplePropertyAssignment: - if ((parent).propertyName === token) { - return ClassificationTypeNames.identifier; - } - return; - case TypeScript.SyntaxKind.ClassDeclaration: - if ((parent).identifier === token) { + else if (tokenKind === SyntaxKind.Identifier) { + switch (tokenOwner.kind) { + case SyntaxKind.ClassDeclaration: + if ((tokenOwner).name === token) { return ClassificationTypeNames.className; } return; - case TypeScript.SyntaxKind.TypeParameter: - if ((parent).identifier === token) { + case SyntaxKind.TypeParameter: + if ((tokenOwner).name === token) { return ClassificationTypeNames.typeParameterName; } return; - case TypeScript.SyntaxKind.InterfaceDeclaration: - if ((parent).identifier === token) { + case SyntaxKind.InterfaceDeclaration: + if ((tokenOwner).name === token) { return ClassificationTypeNames.interfaceName; } return; - case TypeScript.SyntaxKind.EnumDeclaration: - if ((parent).identifier === token) { + case SyntaxKind.EnumDeclaration: + if ((tokenOwner).name === token) { return ClassificationTypeNames.enumName; } return; - case TypeScript.SyntaxKind.ModuleDeclaration: - if ((parent).name === current) { + case SyntaxKind.ModuleDeclaration: + if ((tokenOwner).name === token) { return ClassificationTypeNames.moduleName; } return; @@ -4900,19 +4884,18 @@ module ts { } } - function processElement(element: TypeScript.ISyntaxElement) { + function processElement(element: Node, sourceFile: SourceFile) { // Ignore nodes that don't intersect the original span to classify. - if (!TypeScript.isShared(element) && span.intersectsWith(TypeScript.fullStart(element), TypeScript.fullWidth(element))) { - for (var i = 0, n = TypeScript.childCount(element); i < n; i++) { - var child = TypeScript.childAt(element, i); - if (child) { - if (TypeScript.isToken(child)) { - classifyToken(child); - } - else { - // Recurse into our child nodes. - processElement(child); - } + if (span.intersectsWith(element.getFullStart(), element.getFullWidth())) { + var children = element.getChildren(); + for (var i = 0, n = children.length; i < n; i++) { + var child = children[i]; + if (isToken(child)) { + classifyToken(child, element, sourceFile); + } + else { + // Recurse into our child nodes. + processElement(child, sourceFile); } } } diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 4ceb20fdcee..ca17b704d05 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -229,19 +229,35 @@ module ts { return n.kind !== SyntaxKind.SyntaxList || n.getChildCount() !== 0; } + export function getTypeArgumentOrTypeParameterList(node: Node): NodeArray { + if (node.kind === SyntaxKind.TypeReference || node.kind === SyntaxKind.CallExpression) { + return (node).typeArguments; + } + + if (isAnyFunction(node) || node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.InterfaceDeclaration) { + return (node).typeParameters; + } + + return undefined; + } + export function isToken(n: Node): boolean { return n.kind >= SyntaxKind.FirstToken && n.kind <= SyntaxKind.LastToken; } - function isKeyword(n: Node): boolean { - return n.kind >= SyntaxKind.FirstKeyword && n.kind <= SyntaxKind.LastKeyword; - } - function isWord(n: Node): boolean { - return n.kind === SyntaxKind.Identifier || isKeyword(n); + return n.kind === SyntaxKind.Identifier || isKeyword(n.kind); } function isPropertyName(n: Node): boolean { return n.kind === SyntaxKind.StringLiteral || n.kind === SyntaxKind.NumericLiteral || isWord(n); } + + export function isComment(n: Node): boolean { + return n.kind === SyntaxKind.SingleLineCommentTrivia || n.kind === SyntaxKind.MultiLineCommentTrivia; + } + + export function isPunctuation(n: Node): boolean { + return SyntaxKind.FirstPunctuation <= n.kind && n.kind <= SyntaxKind.LastPunctuation; + } } \ No newline at end of file diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index d184be57712..c71f8987bdf 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -575,51 +575,51 @@ module FourSlashInterface { export module classification { export function comment(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { - return getClassification("comment", text, position); + return getClassification("comment", text, position); } export function identifier(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { - return getClassification("identifier", text, position); + return getClassification("identifier", text, position); } export function keyword(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { - return getClassification("keyword", text, position); + return getClassification("keyword", text, position); } export function numericLiteral(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { - return getClassification("numericLiteral", text, position); + return getClassification("numericLiteral", text, position); } export function operator(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { - return getClassification("operator", text, position); + return getClassification("operator", text, position); } export function stringLiteral(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { - return getClassification("stringLiteral", text, position); + return getClassification("stringLiteral", text, position); } export function whiteSpace(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { - return getClassification("whiteSpace", text, position); + return getClassification("whiteSpace", text, position); } export function text(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { - return getClassification("text", text, position); + return getClassification("text", text, position); } export function punctuation(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { - return getClassification("punctuation", text, position); + return getClassification("punctuation", text, position); } export function className(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { - return getClassification("className", text, position); + return getClassification("className", text, position); } export function enumName(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { - return getClassification("enumName", text, position); + return getClassification("enumName", text, position); } export function interfaceName(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { - return getClassification("interfaceName", text, position); + return getClassification("interfaceName", text, position); } export function moduleName(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { diff --git a/tests/cases/fourslash/syntacticClassificationsFunctionWithComments.ts b/tests/cases/fourslash/syntacticClassificationsFunctionWithComments.ts new file mode 100644 index 00000000000..eeaf4a7033f --- /dev/null +++ b/tests/cases/fourslash/syntacticClassificationsFunctionWithComments.ts @@ -0,0 +1,25 @@ +/// + +/////** +//// * This is my function. +//// * There are many like it, but this one is mine. +//// */ +////function myFunction(/* x */ x: any) { +//// var y = x ? x++ : ++x; +////} +////// end of file + +var firstCommentText = +"\ +/**\n\ + * This is my function.\n\ + * There are many like it, but this one is mine.\n\ + */"; + +var c = classification; +verify.syntacticClassificationsAre( + c.comment(firstCommentText), + c.keyword("function"), c.text("myFunction"), c.punctuation("("), c.comment("/* x */"), c.text("x"), c.punctuation(":"), c.keyword("any"), c.punctuation(")"), c.punctuation("{"), + c.keyword("var"), c.text("y"), c.operator("="), c.text("x"), c.operator("?"), c.text("x"), c.operator("++"), c.operator(":"), c.operator("++"), c.text("x"), c.punctuation(";"), + c.punctuation("}"), + c.comment("// end of file")); \ No newline at end of file diff --git a/tests/cases/fourslash/syntacticClassificationsObjectLiteral.ts b/tests/cases/fourslash/syntacticClassificationsObjectLiteral.ts new file mode 100644 index 00000000000..a7e8f7b7b07 --- /dev/null +++ b/tests/cases/fourslash/syntacticClassificationsObjectLiteral.ts @@ -0,0 +1,25 @@ +/// + +////var v = 10e0; +////var x = { +//// p1: 1, +//// p2: 2, +//// any: 3, +//// function: 4, +//// var: 5, +//// void: void 0, +//// v: v += v, +////}; + +var c = classification; +verify.syntacticClassificationsAre( + c.keyword("var"), c.text("v"), c.operator("="), c.numericLiteral("10e0"), c.punctuation(";"), + c.keyword("var"), c.text("x"), c.operator("="), c.punctuation("{"), + c.text("p1"), c.punctuation(":"), c.numericLiteral("1"), c.punctuation(","), + c.text("p2"), c.punctuation(":"), c.numericLiteral("2"), c.punctuation(","), + c.text("any"), c.punctuation(":"), c.numericLiteral("3"), c.punctuation(","), + c.text("function"), c.punctuation(":"), c.numericLiteral("4"), c.punctuation(","), + c.text("var"), c.punctuation(":"), c.numericLiteral("5"), c.punctuation(","), + c.text("void"), c.punctuation(":"), c.keyword("void"), c.numericLiteral("0"), c.punctuation(","), + c.text("v"), c.punctuation(":"), c.text("v"), c.operator("+="), c.text("v"), c.punctuation(","), + c.punctuation("}"), c.punctuation(";")); \ No newline at end of file From 60bb37be60c6e7388ca1e346def14ce281a023f0 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 16 Oct 2014 10:28:00 -0700 Subject: [PATCH 15/63] Add language service support for const --- src/services/navigationBar.ts | 7 ++++++- src/services/services.ts | 10 ++++++++-- tests/cases/fourslash/completionEntryForConst.ts | 7 +++++++ tests/cases/fourslash/navbar_const.ts | 13 +++++++++++++ .../cases/fourslash/quickInfoForConstDeclaration.ts | 6 ++++++ 5 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 tests/cases/fourslash/completionEntryForConst.ts create mode 100644 tests/cases/fourslash/navbar_const.ts create mode 100644 tests/cases/fourslash/quickInfoForConstDeclaration.ts diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 9f16fa57741..69180974120 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -233,7 +233,12 @@ module ts.NavigationBar { return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.functionElement); case SyntaxKind.VariableDeclaration: - return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.variableElement); + if (node.flags & NodeFlags.Const) { + return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.constantElement); + } + else { + return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.variableElement); + } case SyntaxKind.Constructor: return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); diff --git a/src/services/services.ts b/src/services/services.ts index 0222a448aeb..c52bdb34771 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1235,7 +1235,9 @@ module ts { static label = "label"; - static alias = "alias" + static alias = "alias"; + + static constantElement = "constant"; } export class ScriptElementKindModifier { @@ -2720,6 +2722,9 @@ module ts { if (isFirstDeclarationOfSymbolParameter(symbol)) { return ScriptElementKind.parameterElement; } + else if(forEach(symbol.declarations, d => d.flags & NodeFlags.Const)) { + return ScriptElementKind.constantElement; + } return isLocalVariableOrFunction(symbol) ? ScriptElementKind.localVariableElement : ScriptElementKind.variableElement; } if (flags & SymbolFlags.Function) return isLocalVariableOrFunction(symbol) ? ScriptElementKind.localFunctionElement : ScriptElementKind.functionElement; @@ -2751,7 +2756,7 @@ module ts { case SyntaxKind.ClassDeclaration: return ScriptElementKind.classElement; case SyntaxKind.InterfaceDeclaration: return ScriptElementKind.interfaceElement; case SyntaxKind.EnumDeclaration: return ScriptElementKind.enumElement; - case SyntaxKind.VariableDeclaration: return ScriptElementKind.variableElement; + case SyntaxKind.VariableDeclaration: return node.flags & NodeFlags.Const ? ScriptElementKind.constantElement: ScriptElementKind.variableElement; case SyntaxKind.FunctionDeclaration: return ScriptElementKind.functionElement; case SyntaxKind.GetAccessor: return ScriptElementKind.memberGetAccessorElement; case SyntaxKind.SetAccessor: return ScriptElementKind.memberSetAccessorElement; @@ -2840,6 +2845,7 @@ module ts { switch (symbolKind) { case ScriptElementKind.memberVariableElement: case ScriptElementKind.variableElement: + case ScriptElementKind.constantElement: case ScriptElementKind.parameterElement: case ScriptElementKind.localVariableElement: // If it is call or construct signature of lambda's write type name diff --git a/tests/cases/fourslash/completionEntryForConst.ts b/tests/cases/fourslash/completionEntryForConst.ts new file mode 100644 index 00000000000..f6b7cc42d63 --- /dev/null +++ b/tests/cases/fourslash/completionEntryForConst.ts @@ -0,0 +1,7 @@ +/// + +////const c = "s"; +/////**/ + +goTo.marker(); +verify.completionListContains("c", /*text*/ undefined, /*documentation*/ undefined, "constant"); \ No newline at end of file diff --git a/tests/cases/fourslash/navbar_const.ts b/tests/cases/fourslash/navbar_const.ts new file mode 100644 index 00000000000..ede2a9cd1d8 --- /dev/null +++ b/tests/cases/fourslash/navbar_const.ts @@ -0,0 +1,13 @@ +/// + +//// {| "itemName": "c", "kind": "constant", "parentName": "" |}const c = 0; + +test.markers().forEach(marker => { + verify.getScriptLexicalStructureListContains( + marker.data.itemName, + marker.data.kind, + marker.fileName, + marker.data.parentName, + marker.data.isAdditionalRange, + marker.position); +}); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoForConstDeclaration.ts b/tests/cases/fourslash/quickInfoForConstDeclaration.ts new file mode 100644 index 00000000000..dc234b04050 --- /dev/null +++ b/tests/cases/fourslash/quickInfoForConstDeclaration.ts @@ -0,0 +1,6 @@ +/// + +////const /**/c = 0 ; + +goTo.marker(); +verify.quickInfoIs("(constant) c: number"); \ No newline at end of file From fd469d63b1e0e42a435343152e11d972d17adead Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 17 Oct 2014 09:28:42 -0700 Subject: [PATCH 16/63] Fix search for shadowed const declarations by a var declarations to search for any variable instead of only a blockScoped one to ensure we are not picking it up from a wrong scope. --- src/compiler/checker.ts | 4 ++-- ...onstDeclarationShadowedByVarDeclaration2.js | 18 ++++++++++++++++++ ...tDeclarationShadowedByVarDeclaration2.types | 16 ++++++++++++++++ ...onstDeclarationShadowedByVarDeclaration2.ts | 9 +++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/constDeclarationShadowedByVarDeclaration2.js create mode 100644 tests/baselines/reference/constDeclarationShadowedByVarDeclaration2.types create mode 100644 tests/cases/compiler/constDeclarationShadowedByVarDeclaration2.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5b99e2b2dd9..0065d138e9e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6776,8 +6776,8 @@ module ts { // } if (node.initializer && (node.flags & NodeFlags.BlockScoped) === 0) { var symbol = getSymbolOfNode(node); - var localDeclarationSymbol = resolveName(node, node.name.text, SymbolFlags.BlockScoped, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined); - if (localDeclarationSymbol && localDeclarationSymbol !== symbol) { + var localDeclarationSymbol = resolveName(node, node.name.text, SymbolFlags.Variable, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined); + if (localDeclarationSymbol && localDeclarationSymbol !== symbol && localDeclarationSymbol.flags & SymbolFlags.BlockScoped) { if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & NodeFlags.Const) { error(node, Diagnostics.Cannot_redeclare_constant_0, symbolToString(localDeclarationSymbol)); } diff --git a/tests/baselines/reference/constDeclarationShadowedByVarDeclaration2.js b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration2.js new file mode 100644 index 00000000000..67d3e688075 --- /dev/null +++ b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration2.js @@ -0,0 +1,18 @@ +//// [constDeclarationShadowedByVarDeclaration2.ts] + +// No errors, const declaration is not shadowed +function outer() { + const x = 0; + function inner() { + var x = "inner"; + } +} + +//// [constDeclarationShadowedByVarDeclaration2.js] +// No errors, const declaration is not shadowed +function outer() { + const x = 0; + function inner() { + var x = "inner"; + } +} diff --git a/tests/baselines/reference/constDeclarationShadowedByVarDeclaration2.types b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration2.types new file mode 100644 index 00000000000..4217db45509 --- /dev/null +++ b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration2.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/constDeclarationShadowedByVarDeclaration2.ts === + +// No errors, const declaration is not shadowed +function outer() { +>outer : () => void + + const x = 0; +>x : number + + function inner() { +>inner : () => void + + var x = "inner"; +>x : string + } +} diff --git a/tests/cases/compiler/constDeclarationShadowedByVarDeclaration2.ts b/tests/cases/compiler/constDeclarationShadowedByVarDeclaration2.ts new file mode 100644 index 00000000000..98930953996 --- /dev/null +++ b/tests/cases/compiler/constDeclarationShadowedByVarDeclaration2.ts @@ -0,0 +1,9 @@ +// @target: ES6 + +// No errors, const declaration is not shadowed +function outer() { + const x = 0; + function inner() { + var x = "inner"; + } +} \ No newline at end of file From 4ef68b9fb03c21e55d47230ac97b63ebd43bd42e Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 17 Oct 2014 10:09:21 -0700 Subject: [PATCH 17/63] Respond to code review comments --- src/compiler/parser.ts | 36 ++++++++++++++++++------------------ src/compiler/types.ts | 9 ++++++--- src/harness/harness.ts | 2 +- src/services/services.ts | 2 +- 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 112096615b2..305ef595041 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2561,7 +2561,7 @@ module ts { // STATEMENTS function parseStatementAllowingLetDeclaration() { - return parseStatement(/*allowLetDeclarations*/ true); + return parseStatement(/*allowLetAndConstDeclarations*/ true); } function parseBlock(ignoreMissingOpenBrace: boolean, checkForStrictMode: boolean): Block { @@ -2613,8 +2613,8 @@ module ts { parseExpected(SyntaxKind.OpenParenToken); node.expression = parseExpression(); parseExpected(SyntaxKind.CloseParenToken); - node.thenStatement = parseStatement(/*allowLetDeclarations*/ false); - node.elseStatement = parseOptional(SyntaxKind.ElseKeyword) ? parseStatement(/*allowLetDeclarations*/ false) : undefined; + node.thenStatement = parseStatement(/*allowLetAndConstDeclarations*/ false); + node.elseStatement = parseOptional(SyntaxKind.ElseKeyword) ? parseStatement(/*allowLetAndConstDeclarations*/ false) : undefined; return finishNode(node); } @@ -2624,7 +2624,7 @@ module ts { var saveInIterationStatement = inIterationStatement; inIterationStatement = ControlBlockContext.Nested; - node.statement = parseStatement(/*allowLetDeclarations*/ false); + node.statement = parseStatement(/*allowLetAndConstDeclarations*/ false); inIterationStatement = saveInIterationStatement; parseExpected(SyntaxKind.WhileKeyword); @@ -2649,7 +2649,7 @@ module ts { var saveInIterationStatement = inIterationStatement; inIterationStatement = ControlBlockContext.Nested; - node.statement = parseStatement(/*allowLetDeclarations*/ false); + node.statement = parseStatement(/*allowLetAndConstDeclarations*/ false); inIterationStatement = saveInIterationStatement; return finishNode(node); @@ -2722,7 +2722,7 @@ module ts { var saveInIterationStatement = inIterationStatement; inIterationStatement = ControlBlockContext.Nested; - forOrForInStatement.statement = parseStatement(/*allowLetDeclarations*/ false); + forOrForInStatement.statement = parseStatement(/*allowLetAndConstDeclarations*/ false); inIterationStatement = saveInIterationStatement; return finishNode(forOrForInStatement); @@ -2833,7 +2833,7 @@ module ts { parseExpected(SyntaxKind.OpenParenToken); node.expression = parseExpression(); parseExpected(SyntaxKind.CloseParenToken); - node.statement = parseStatement(/*allowLetDeclarations*/ false); + node.statement = parseStatement(/*allowLetAndConstDeclarations*/ false); node = finishNode(node); if (isInStrictMode) { // Strict mode code may not include a WithStatement. The occurrence of a WithStatement in such @@ -2963,9 +2963,9 @@ module ts { return token === SyntaxKind.WhileKeyword || token === SyntaxKind.DoKeyword || token === SyntaxKind.ForKeyword; } - function parseStatementWithLabelSet(allowLetDeclarations: boolean): Statement { + function parseStatementWithLabelSet(allowLetAndConstDeclarations: boolean): Statement { labelledStatementInfo.pushCurrentLabelSet(isIterationStatementStart()); - var statement = parseStatement(allowLetDeclarations); + var statement = parseStatement(allowLetAndConstDeclarations); labelledStatementInfo.pop(); return statement; } @@ -2974,7 +2974,7 @@ module ts { return isIdentifier() && lookAhead(() => nextToken() === SyntaxKind.ColonToken); } - function parseLabelledStatement(allowLetDeclarations: boolean): LabeledStatement { + function parseLabeledStatement(allowLetAndConstDeclarations: boolean): LabeledStatement { var node = createNode(SyntaxKind.LabeledStatement); node.label = parseIdentifier(); parseExpected(SyntaxKind.ColonToken); @@ -2986,7 +2986,7 @@ module ts { // We only want to call parseStatementWithLabelSet when the label set is complete // Therefore, keep parsing labels until we know we're done. - node.statement = isLabel() ? parseLabelledStatement(allowLetDeclarations) : parseStatementWithLabelSet(allowLetDeclarations); + node.statement = isLabel() ? parseLabeledStatement(allowLetAndConstDeclarations) : parseStatementWithLabelSet(allowLetAndConstDeclarations); return finishNode(node); } @@ -3052,14 +3052,14 @@ module ts { } } - function parseStatement(allowLetDeclarations: boolean): Statement { + function parseStatement(allowLetAndConstDeclarations: boolean): Statement { switch (token) { case SyntaxKind.OpenBraceToken: return parseBlock(/* ignoreMissingOpenBrace */ false, /*checkForStrictMode*/ false); case SyntaxKind.VarKeyword: case SyntaxKind.LetKeyword: case SyntaxKind.ConstKeyword: - return parseVariableStatement(allowLetDeclarations); + return parseVariableStatement(allowLetAndConstDeclarations); case SyntaxKind.FunctionKeyword: return parseFunctionDeclaration(); case SyntaxKind.SemicolonToken: @@ -3093,7 +3093,7 @@ module ts { return parseDebuggerStatement(); default: if (isLabel()) { - return parseLabelledStatement(allowLetDeclarations); + return parseLabeledStatement(allowLetAndConstDeclarations); } return parseExpressionStatement(); } @@ -3150,7 +3150,7 @@ module ts { () => parseVariableDeclaration(flags, noIn), /*allowTrailingComma*/ false); } - function parseVariableStatement(allowLetDeclarations: boolean, pos?: number, flags?: NodeFlags): VariableStatement { + function parseVariableStatement(allowLetAndConstDeclarations: boolean, pos?: number, flags?: NodeFlags): VariableStatement { var node = createNode(SyntaxKind.VariableStatement, pos); if (flags) node.flags = flags; var errorCountBeforeVarStatement = file.syntacticErrors.length; @@ -3178,7 +3178,7 @@ module ts { grammarErrorOnNode(node, Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); } } - else if (!allowLetDeclarations) { + else if (!allowLetAndConstDeclarations) { if (node.flags & NodeFlags.Let) { grammarErrorOnNode(node, Diagnostics.let_must_be_declared_inside_a_block); } @@ -3821,7 +3821,7 @@ module ts { case SyntaxKind.VarKeyword: case SyntaxKind.LetKeyword: case SyntaxKind.ConstKeyword: - result = parseVariableStatement(/*allowLetDeclarations*/ true, pos, flags); + result = parseVariableStatement(/*allowLetAndConstDeclarations*/ true, pos, flags); break; case SyntaxKind.FunctionKeyword: result = parseFunctionDeclaration(pos, flags); @@ -3869,7 +3869,7 @@ module ts { var statementStart = scanner.getTokenPos(); var statementFirstTokenLength = scanner.getTextPos() - statementStart; var errorCountBeforeStatement = file.syntacticErrors.length; - var statement = parseStatement(/*allowLetDeclarations*/ false); + var statement = parseStatement(/*allowLetAndConstDeclarations*/ false); if (inAmbientContext && file.syntacticErrors.length === errorCountBeforeStatement) { grammarErrorAtPos(statementStart, statementFirstTokenLength, Diagnostics.Statements_are_not_allowed_in_ambient_contexts); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 5eb567e406e..5a5a5989dab 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -783,7 +783,7 @@ module ts { Transient = 0x04000000, // Transient symbol (created during type check) Prototype = 0x08000000, // Prototype property (no source representation) - BlockScoped = 0x10000000, + BlockScoped = 0x10000000, // A block-scoped declaration Value = Variable | Property | EnumMember | Function | Class | Enum | ValueModule | Method | GetAccessor | SetAccessor | UnionProperty, Type = Class | Interface | Enum | TypeLiteral | ObjectLiteral | TypeParameter, @@ -793,8 +793,11 @@ module ts { Signature = CallSignature | ConstructSignature | IndexSignature, ParameterExcludes = Value, - VariableExcludes = (Value | BlockScoped) & ~Variable, - BlockScopedExcludes = Value, + VariableExcludes = (Value | BlockScoped) & ~Variable, // Variables can be redeclared, but can not redeclare a block-scoped + // declaration with the same name, or any other value that is not a + // variable, e.g. ValueModule or Class + BlockScopedExcludes = Value, // Block-scoped declarations are not allowed to be re-declared + // they can not merge with anything in the value space PropertyExcludes = Value, EnumMemberExcludes = Value, FunctionExcludes = Value & ~(Function | ValueModule), diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 728c4cc08e0..bbabd0462c1 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -686,7 +686,7 @@ module Harness { } else if (setting.value.toLowerCase() === 'es5') { options.target = ts.ScriptTarget.ES5; } else if (setting.value.toLowerCase() === 'es6') { - options.target = ts.ScriptTarget.ES6; + options.target = ts.ScriptTarget.ES6; } else { throw new Error('Unknown compile target ' + setting.value); } diff --git a/src/services/services.ts b/src/services/services.ts index c52bdb34771..fb984c9da87 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2722,7 +2722,7 @@ module ts { if (isFirstDeclarationOfSymbolParameter(symbol)) { return ScriptElementKind.parameterElement; } - else if(forEach(symbol.declarations, d => d.flags & NodeFlags.Const)) { + else if(symbol.valueDeclaration && symbol.valueDeclaration.flags & NodeFlags.Const) { return ScriptElementKind.constantElement; } return isLocalVariableOrFunction(symbol) ? ScriptElementKind.localVariableElement : ScriptElementKind.variableElement; From a5a6c6f2423870d61504d344ef1080795cebda14 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 17 Oct 2014 15:15:22 -0700 Subject: [PATCH 18/63] Allow const and let declarations to be exported in modules. Also ensure that const module elements are not used as references. --- src/compiler/checker.ts | 25 ++++- .../diagnosticInformationMap.generated.ts | 5 +- src/compiler/diagnosticMessages.json | 8 +- src/compiler/parser.ts | 7 +- .../constDeclarations-access2.errors.txt | 7 +- .../reference/constDeclarations-access2.js | 3 + .../constDeclarations-access3.errors.txt | 102 +++++++++++++++++ .../reference/constDeclarations-access3.js | 83 ++++++++++++++ .../constDeclarations-access4.errors.txt | 102 +++++++++++++++++ .../reference/constDeclarations-access4.js | 79 ++++++++++++++ .../constDeclarations-access5.errors.txt | 103 ++++++++++++++++++ .../reference/constDeclarations-access5.js | 89 +++++++++++++++ ...nstDeclarations-invalidContexts.errors.txt | 36 +++--- .../reference/constDeclarations2.errors.txt | 20 ---- .../baselines/reference/constDeclarations2.js | 26 +++++ .../reference/constDeclarations2.types | 18 +++ ...letDeclarations-invalidContexts.errors.txt | 36 +++--- .../reference/letDeclarations2.errors.txt | 11 -- tests/baselines/reference/letDeclarations2.js | 19 ++++ .../reference/letDeclarations2.types | 11 ++ .../compiler/constDeclarations-access2.ts | 2 + .../compiler/constDeclarations-access3.ts | 45 ++++++++ .../compiler/constDeclarations-access4.ts | 45 ++++++++ .../compiler/constDeclarations-access5.ts | 48 ++++++++ 24 files changed, 843 insertions(+), 87 deletions(-) create mode 100644 tests/baselines/reference/constDeclarations-access3.errors.txt create mode 100644 tests/baselines/reference/constDeclarations-access3.js create mode 100644 tests/baselines/reference/constDeclarations-access4.errors.txt create mode 100644 tests/baselines/reference/constDeclarations-access4.js create mode 100644 tests/baselines/reference/constDeclarations-access5.errors.txt create mode 100644 tests/baselines/reference/constDeclarations-access5.js delete mode 100644 tests/baselines/reference/constDeclarations2.errors.txt create mode 100644 tests/baselines/reference/constDeclarations2.js create mode 100644 tests/baselines/reference/constDeclarations2.types delete mode 100644 tests/baselines/reference/letDeclarations2.errors.txt create mode 100644 tests/baselines/reference/letDeclarations2.js create mode 100644 tests/baselines/reference/letDeclarations2.types create mode 100644 tests/cases/compiler/constDeclarations-access3.ts create mode 100644 tests/cases/compiler/constDeclarations-access4.ts create mode 100644 tests/cases/compiler/constDeclarations-access5.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0065d138e9e..bb96151997a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5550,12 +5550,27 @@ module ts { } } - function isConstVariableReference(n: Node) { - if (n.kind === SyntaxKind.Identifier) { - var symbol = findSymbol(n); - return symbol && (symbol.flags & SymbolFlags.Variable) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & NodeFlags.Const) !== 0; + function isConstVariableReference(n: Node): boolean { + switch (n.kind) { + case SyntaxKind.Identifier: + case SyntaxKind.PropertyAccess: + var symbol = findSymbol(n); + return symbol && (symbol.flags & SymbolFlags.Variable) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & NodeFlags.Const) !== 0; + case SyntaxKind.IndexedAccess: + var index = (n).index; + var symbol = findSymbol((n).object); + if (symbol && index.kind === SyntaxKind.StringLiteral) { + var name = (index).text; + var apparentType = getApparentType(getTypeOfSymbol(symbol)); + var prop = getPropertyOfApparentType(apparentType, name); + return prop && (prop.flags & SymbolFlags.Variable) !== 0 && (getDeclarationFlagsFromSymbol(prop) & NodeFlags.Const) !== 0; + } + return false; + case SyntaxKind.ParenExpression: + return isConstVariableReference((n).expression); + default: + return false; } - return false; } if (!isReferenceOrErrorExpression(n)) { diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index d96214ae1d9..ef0ab4327a1 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -119,9 +119,8 @@ module ts { let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1153, category: DiagnosticCategory.Error, key: "'let' declarations are only available when targeting ECMAScript 6 and higher." }, const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1154, category: DiagnosticCategory.Error, key: "'const' declarations are only available when targeting ECMAScript 6 and higher." }, const_must_be_intialized: { code: 1155, category: DiagnosticCategory.Error, key: "const must be intialized." }, - const_must_be_declared_inside_a_block: { code: 1156, category: DiagnosticCategory.Error, key: "const must be declared inside a block." }, - let_must_be_declared_inside_a_block: { code: 1157, category: DiagnosticCategory.Error, key: "let must be declared inside a block." }, - Only_var_declarations_can_be_exported: { code: 1158, category: DiagnosticCategory.Error, key: "Only var declarations can be exported." }, + const_declarations_must_be_declared_inside_a_block: { code: 1156, category: DiagnosticCategory.Error, key: "'const' declarations must be declared inside a block." }, + let_declarations_must_be_declared_inside_a_block: { code: 1157, category: DiagnosticCategory.Error, key: "'let' declarations must be declared inside a block." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index ee1a82b9c13..34ecabe31ae 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -467,18 +467,14 @@ "category": "Error", "code": 1155 }, - "const must be declared inside a block.": { + "'const' declarations must be declared inside a block.": { "category": "Error", "code": 1156 }, - "let must be declared inside a block.": { + "'let' declarations must be declared inside a block.": { "category": "Error", "code": 1157 }, - "Only var declarations can be exported.": { - "category": "Error", - "code": 1158 - }, "Duplicate identifier '{0}'.": { "category": "Error", diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 305ef595041..2ee564c7302 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3180,15 +3180,12 @@ module ts { } else if (!allowLetAndConstDeclarations) { if (node.flags & NodeFlags.Let) { - grammarErrorOnNode(node, Diagnostics.let_must_be_declared_inside_a_block); + grammarErrorOnNode(node, Diagnostics.let_declarations_must_be_declared_inside_a_block); } else if (node.flags & NodeFlags.Const) { - grammarErrorOnNode(node, Diagnostics.const_must_be_declared_inside_a_block); + grammarErrorOnNode(node, Diagnostics.const_declarations_must_be_declared_inside_a_block); } } - else if (node.flags & NodeFlags.Export && node.flags & NodeFlags.BlockScoped) { - grammarErrorOnNode(node, Diagnostics.Only_var_declarations_can_be_exported); - } return node; } diff --git a/tests/baselines/reference/constDeclarations-access2.errors.txt b/tests/baselines/reference/constDeclarations-access2.errors.txt index f3bf7d1d750..6a360e11014 100644 --- a/tests/baselines/reference/constDeclarations-access2.errors.txt +++ b/tests/baselines/reference/constDeclarations-access2.errors.txt @@ -14,9 +14,10 @@ tests/cases/compiler/constDeclarations-access2.ts(18,1): error TS2449: The opera tests/cases/compiler/constDeclarations-access2.ts(19,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. tests/cases/compiler/constDeclarations-access2.ts(20,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. tests/cases/compiler/constDeclarations-access2.ts(21,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(23,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. -==== tests/cases/compiler/constDeclarations-access2.ts (16 errors) ==== +==== tests/cases/compiler/constDeclarations-access2.ts (17 errors) ==== const x = 0 @@ -71,6 +72,10 @@ tests/cases/compiler/constDeclarations-access2.ts(21,3): error TS2449: The opera ~ !!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + ++((x)); + ~~~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + // OK var a = x + 1; diff --git a/tests/baselines/reference/constDeclarations-access2.js b/tests/baselines/reference/constDeclarations-access2.js index e2a1bcd9fa5..fd51c932636 100644 --- a/tests/baselines/reference/constDeclarations-access2.js +++ b/tests/baselines/reference/constDeclarations-access2.js @@ -21,6 +21,8 @@ x--; ++x; --x; +++((x)); + // OK var a = x + 1; @@ -57,6 +59,7 @@ x++; x--; ++x; --x; +++((x)); // OK var a = x + 1; function f(v) { diff --git a/tests/baselines/reference/constDeclarations-access3.errors.txt b/tests/baselines/reference/constDeclarations-access3.errors.txt new file mode 100644 index 00000000000..577b087dff0 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-access3.errors.txt @@ -0,0 +1,102 @@ +tests/cases/compiler/constDeclarations-access3.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(16,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(17,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(21,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(22,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(23,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(24,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(26,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(28,1): error TS2450: Left-hand side of assignment expression cannot be a constant. + + +==== tests/cases/compiler/constDeclarations-access3.ts (18 errors) ==== + + + module M { + export const x = 0; + } + + // Errors + M.x = 1; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x += 2; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x -= 3; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x *= 4; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x /= 5; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x %= 6; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x <<= 7; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x >>= 8; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x >>>= 9; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x &= 10; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x |= 11; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x ^= 12; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + + M.x++; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + M.x--; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + ++M.x; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + --M.x; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + + ++((M.x)); + ~~~~~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + + M["x"] = 0; + ~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + + // OK + var a = M.x + 1; + + function f(v: number) { } + f(M.x); + + if (M.x) { } + + M.x; + (M.x); + + -M.x; + +M.x; + + M.x.toString(); + \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-access3.js b/tests/baselines/reference/constDeclarations-access3.js new file mode 100644 index 00000000000..9ac4880bdd1 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-access3.js @@ -0,0 +1,83 @@ +//// [constDeclarations-access3.ts] + + +module M { + export const x = 0; +} + +// Errors +M.x = 1; +M.x += 2; +M.x -= 3; +M.x *= 4; +M.x /= 5; +M.x %= 6; +M.x <<= 7; +M.x >>= 8; +M.x >>>= 9; +M.x &= 10; +M.x |= 11; +M.x ^= 12; + +M.x++; +M.x--; +++M.x; +--M.x; + +++((M.x)); + +M["x"] = 0; + +// OK +var a = M.x + 1; + +function f(v: number) { } +f(M.x); + +if (M.x) { } + +M.x; +(M.x); + +-M.x; ++M.x; + +M.x.toString(); + + +//// [constDeclarations-access3.js] +var M; +(function (M) { + M.x = 0; +})(M || (M = {})); +// Errors +M.x = 1; +M.x += 2; +M.x -= 3; +M.x *= 4; +M.x /= 5; +M.x %= 6; +M.x <<= 7; +M.x >>= 8; +M.x >>>= 9; +M.x &= 10; +M.x |= 11; +M.x ^= 12; +M.x++; +M.x--; +++M.x; +--M.x; +++((M.x)); +M["x"] = 0; +// OK +var a = M.x + 1; +function f(v) { +} +f(M.x); +if (M.x) { +} +M.x; +(M.x); +-M.x; ++M.x; +M.x.toString(); diff --git a/tests/baselines/reference/constDeclarations-access4.errors.txt b/tests/baselines/reference/constDeclarations-access4.errors.txt new file mode 100644 index 00000000000..9745c0d2624 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-access4.errors.txt @@ -0,0 +1,102 @@ +tests/cases/compiler/constDeclarations-access4.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(16,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(17,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(21,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(22,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(23,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(24,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(26,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(28,1): error TS2450: Left-hand side of assignment expression cannot be a constant. + + +==== tests/cases/compiler/constDeclarations-access4.ts (18 errors) ==== + + + declare module M { + const x: number; + } + + // Errors + M.x = 1; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x += 2; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x -= 3; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x *= 4; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x /= 5; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x %= 6; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x <<= 7; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x >>= 8; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x >>>= 9; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x &= 10; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x |= 11; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x ^= 12; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + + M.x++; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + M.x--; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + ++M.x; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + --M.x; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + + ++((M.x)); + ~~~~~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + + M["x"] = 0; + ~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + + // OK + var a = M.x + 1; + + function f(v: number) { } + f(M.x); + + if (M.x) { } + + M.x; + (M.x); + + -M.x; + +M.x; + + M.x.toString(); + \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-access4.js b/tests/baselines/reference/constDeclarations-access4.js new file mode 100644 index 00000000000..b226e746bba --- /dev/null +++ b/tests/baselines/reference/constDeclarations-access4.js @@ -0,0 +1,79 @@ +//// [constDeclarations-access4.ts] + + +declare module M { + const x: number; +} + +// Errors +M.x = 1; +M.x += 2; +M.x -= 3; +M.x *= 4; +M.x /= 5; +M.x %= 6; +M.x <<= 7; +M.x >>= 8; +M.x >>>= 9; +M.x &= 10; +M.x |= 11; +M.x ^= 12; + +M.x++; +M.x--; +++M.x; +--M.x; + +++((M.x)); + +M["x"] = 0; + +// OK +var a = M.x + 1; + +function f(v: number) { } +f(M.x); + +if (M.x) { } + +M.x; +(M.x); + +-M.x; ++M.x; + +M.x.toString(); + + +//// [constDeclarations-access4.js] +// Errors +M.x = 1; +M.x += 2; +M.x -= 3; +M.x *= 4; +M.x /= 5; +M.x %= 6; +M.x <<= 7; +M.x >>= 8; +M.x >>>= 9; +M.x &= 10; +M.x |= 11; +M.x ^= 12; +M.x++; +M.x--; +++M.x; +--M.x; +++((M.x)); +M["x"] = 0; +// OK +var a = M.x + 1; +function f(v) { +} +f(M.x); +if (M.x) { +} +M.x; +(M.x); +-M.x; ++M.x; +M.x.toString(); diff --git a/tests/baselines/reference/constDeclarations-access5.errors.txt b/tests/baselines/reference/constDeclarations-access5.errors.txt new file mode 100644 index 00000000000..23200e50ee4 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-access5.errors.txt @@ -0,0 +1,103 @@ +tests/cases/compiler/constDeclarations_access_2.ts(4,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(6,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(7,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(17,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(18,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(19,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(20,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(22,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(24,1): error TS2450: Left-hand side of assignment expression cannot be a constant. + + +==== tests/cases/compiler/constDeclarations_access_2.ts (18 errors) ==== + /// + import m = require('constDeclarations_access_1'); + // Errors + m.x = 1; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x += 2; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x -= 3; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x *= 4; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x /= 5; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x %= 6; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x <<= 7; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x >>= 8; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x >>>= 9; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x &= 10; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x |= 11; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x ^= 12; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m + m.x++; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + m.x--; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + ++m.x; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + --m.x; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + + ++((m.x)); + ~~~~~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + + m["x"] = 0; + ~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + + // OK + var a = m.x + 1; + + function f(v: number) { } + f(m.x); + + if (m.x) { } + + m.x; + (m.x); + + -m.x; + +m.x; + + m.x.toString(); + +==== tests/cases/compiler/constDeclarations_access_1.ts (0 errors) ==== + + + export const x = 0; + \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-access5.js b/tests/baselines/reference/constDeclarations-access5.js new file mode 100644 index 00000000000..7acc95ad055 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-access5.js @@ -0,0 +1,89 @@ +//// [tests/cases/compiler/constDeclarations-access5.ts] //// + +//// [constDeclarations_access_1.ts] + + +export const x = 0; + +//// [constDeclarations_access_2.ts] +/// +import m = require('constDeclarations_access_1'); +// Errors +m.x = 1; +m.x += 2; +m.x -= 3; +m.x *= 4; +m.x /= 5; +m.x %= 6; +m.x <<= 7; +m.x >>= 8; +m.x >>>= 9; +m.x &= 10; +m.x |= 11; +m.x ^= 12; +m +m.x++; +m.x--; +++m.x; +--m.x; + +++((m.x)); + +m["x"] = 0; + +// OK +var a = m.x + 1; + +function f(v: number) { } +f(m.x); + +if (m.x) { } + +m.x; +(m.x); + +-m.x; ++m.x; + +m.x.toString(); + + +//// [constDeclarations_access_1.js] +define(["require", "exports"], function (require, exports) { + exports.x = 0; +}); +//// [constDeclarations_access_2.js] +define(["require", "exports", 'constDeclarations_access_1'], function (require, exports, m) { + // Errors + m.x = 1; + m.x += 2; + m.x -= 3; + m.x *= 4; + m.x /= 5; + m.x %= 6; + m.x <<= 7; + m.x >>= 8; + m.x >>>= 9; + m.x &= 10; + m.x |= 11; + m.x ^= 12; + m; + m.x++; + m.x--; + ++m.x; + --m.x; + ++((m.x)); + m["x"] = 0; + // OK + var a = m.x + 1; + function f(v) { + } + f(m.x); + if (m.x) { + } + m.x; + (m.x); + -m.x; + +m.x; + m.x.toString(); +}); diff --git a/tests/baselines/reference/constDeclarations-invalidContexts.errors.txt b/tests/baselines/reference/constDeclarations-invalidContexts.errors.txt index b7aef3dabbe..bc229185e83 100644 --- a/tests/baselines/reference/constDeclarations-invalidContexts.errors.txt +++ b/tests/baselines/reference/constDeclarations-invalidContexts.errors.txt @@ -1,12 +1,12 @@ -tests/cases/compiler/constDeclarations-invalidContexts.ts(4,5): error TS1156: const must be declared inside a block. -tests/cases/compiler/constDeclarations-invalidContexts.ts(6,5): error TS1156: const must be declared inside a block. -tests/cases/compiler/constDeclarations-invalidContexts.ts(9,5): error TS1156: const must be declared inside a block. -tests/cases/compiler/constDeclarations-invalidContexts.ts(12,5): error TS1156: const must be declared inside a block. -tests/cases/compiler/constDeclarations-invalidContexts.ts(17,5): error TS1156: const must be declared inside a block. -tests/cases/compiler/constDeclarations-invalidContexts.ts(20,5): error TS1156: const must be declared inside a block. -tests/cases/compiler/constDeclarations-invalidContexts.ts(23,5): error TS1156: const must be declared inside a block. -tests/cases/compiler/constDeclarations-invalidContexts.ts(26,12): error TS1156: const must be declared inside a block. -tests/cases/compiler/constDeclarations-invalidContexts.ts(29,29): error TS1156: const must be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(4,5): error TS1156: 'const' declarations must be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(6,5): error TS1156: 'const' declarations must be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(9,5): error TS1156: 'const' declarations must be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(12,5): error TS1156: 'const' declarations must be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(17,5): error TS1156: 'const' declarations must be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(20,5): error TS1156: 'const' declarations must be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(23,5): error TS1156: 'const' declarations must be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(26,12): error TS1156: 'const' declarations must be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(29,29): error TS1156: 'const' declarations must be declared inside a block. tests/cases/compiler/constDeclarations-invalidContexts.ts(16,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'. @@ -16,21 +16,21 @@ tests/cases/compiler/constDeclarations-invalidContexts.ts(16,7): error TS2410: A if (true) const c1 = 0; ~~~~~~~~~~~~~ -!!! error TS1156: const must be declared inside a block. +!!! error TS1156: 'const' declarations must be declared inside a block. else const c2 = 0; ~~~~~~~~~~~~~ -!!! error TS1156: const must be declared inside a block. +!!! error TS1156: 'const' declarations must be declared inside a block. while (true) const c3 = 0; ~~~~~~~~~~~~~ -!!! error TS1156: const must be declared inside a block. +!!! error TS1156: 'const' declarations must be declared inside a block. do const c4 = 0; ~~~~~~~~~~~~~ -!!! error TS1156: const must be declared inside a block. +!!! error TS1156: 'const' declarations must be declared inside a block. while (true); var obj; @@ -39,27 +39,27 @@ tests/cases/compiler/constDeclarations-invalidContexts.ts(16,7): error TS2410: A !!! error TS2410: All symbols within a 'with' block will be resolved to 'any'. const c5 = 0; ~~~~~~~~~~~~~ -!!! error TS1156: const must be declared inside a block. +!!! error TS1156: 'const' declarations must be declared inside a block. for (var i = 0; i < 10; i++) const c6 = 0; ~~~~~~~~~~~~~ -!!! error TS1156: const must be declared inside a block. +!!! error TS1156: 'const' declarations must be declared inside a block. for (var i2 in {}) const c7 = 0; ~~~~~~~~~~~~~ -!!! error TS1156: const must be declared inside a block. +!!! error TS1156: 'const' declarations must be declared inside a block. if (true) label: const c8 = 0; ~~~~~~~~~~~~~ -!!! error TS1156: const must be declared inside a block. +!!! error TS1156: 'const' declarations must be declared inside a block. while (false) label2: label3: label4: const c9 = 0; ~~~~~~~~~~~~~ -!!! error TS1156: const must be declared inside a block. +!!! error TS1156: 'const' declarations must be declared inside a block. diff --git a/tests/baselines/reference/constDeclarations2.errors.txt b/tests/baselines/reference/constDeclarations2.errors.txt deleted file mode 100644 index 39317b599f9..00000000000 --- a/tests/baselines/reference/constDeclarations2.errors.txt +++ /dev/null @@ -1,20 +0,0 @@ -tests/cases/compiler/constDeclarations2.ts(4,5): error TS1158: Only var declarations can be exported. -tests/cases/compiler/constDeclarations2.ts(5,5): error TS1158: Only var declarations can be exported. -tests/cases/compiler/constDeclarations2.ts(6,5): error TS1158: Only var declarations can be exported. - - -==== tests/cases/compiler/constDeclarations2.ts (3 errors) ==== - - // No error - module M { - export const c1 = false; - ~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1158: Only var declarations can be exported. - export const c2: number = 23; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1158: Only var declarations can be exported. - export const c3 = 0, c4 :string = "", c5 = null; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1158: Only var declarations can be exported. - } - \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations2.js b/tests/baselines/reference/constDeclarations2.js new file mode 100644 index 00000000000..e4ee67ebdcd --- /dev/null +++ b/tests/baselines/reference/constDeclarations2.js @@ -0,0 +1,26 @@ +//// [constDeclarations2.ts] + +// No error +module M { + export const c1 = false; + export const c2: number = 23; + export const c3 = 0, c4 :string = "", c5 = null; +} + + +//// [constDeclarations2.js] +// No error +var M; +(function (M) { + M.c1 = false; + M.c2 = 23; + M.c3 = 0, M.c4 = "", M.c5 = null; +})(M || (M = {})); + + +//// [constDeclarations2.d.ts] +declare module M { + const c1: boolean; + const c2: number; + const c3: number, c4: string, c5: any; +} diff --git a/tests/baselines/reference/constDeclarations2.types b/tests/baselines/reference/constDeclarations2.types new file mode 100644 index 00000000000..c81eca96b0d --- /dev/null +++ b/tests/baselines/reference/constDeclarations2.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/constDeclarations2.ts === + +// No error +module M { +>M : typeof M + + export const c1 = false; +>c1 : boolean + + export const c2: number = 23; +>c2 : number + + export const c3 = 0, c4 :string = "", c5 = null; +>c3 : number +>c4 : string +>c5 : any +} + diff --git a/tests/baselines/reference/letDeclarations-invalidContexts.errors.txt b/tests/baselines/reference/letDeclarations-invalidContexts.errors.txt index 3877f61641a..0e86e84e784 100644 --- a/tests/baselines/reference/letDeclarations-invalidContexts.errors.txt +++ b/tests/baselines/reference/letDeclarations-invalidContexts.errors.txt @@ -1,12 +1,12 @@ -tests/cases/compiler/letDeclarations-invalidContexts.ts(4,5): error TS1157: let must be declared inside a block. -tests/cases/compiler/letDeclarations-invalidContexts.ts(6,5): error TS1157: let must be declared inside a block. -tests/cases/compiler/letDeclarations-invalidContexts.ts(9,5): error TS1157: let must be declared inside a block. -tests/cases/compiler/letDeclarations-invalidContexts.ts(12,5): error TS1157: let must be declared inside a block. -tests/cases/compiler/letDeclarations-invalidContexts.ts(17,5): error TS1157: let must be declared inside a block. -tests/cases/compiler/letDeclarations-invalidContexts.ts(20,5): error TS1157: let must be declared inside a block. -tests/cases/compiler/letDeclarations-invalidContexts.ts(23,5): error TS1157: let must be declared inside a block. -tests/cases/compiler/letDeclarations-invalidContexts.ts(26,12): error TS1157: let must be declared inside a block. -tests/cases/compiler/letDeclarations-invalidContexts.ts(29,29): error TS1157: let must be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(4,5): error TS1157: 'let' declarations must be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(6,5): error TS1157: 'let' declarations must be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(9,5): error TS1157: 'let' declarations must be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(12,5): error TS1157: 'let' declarations must be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(17,5): error TS1157: 'let' declarations must be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(20,5): error TS1157: 'let' declarations must be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(23,5): error TS1157: 'let' declarations must be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(26,12): error TS1157: 'let' declarations must be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(29,29): error TS1157: 'let' declarations must be declared inside a block. tests/cases/compiler/letDeclarations-invalidContexts.ts(16,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'. @@ -16,21 +16,21 @@ tests/cases/compiler/letDeclarations-invalidContexts.ts(16,7): error TS2410: All if (true) let l1 = 0; ~~~~~~~~~~~ -!!! error TS1157: let must be declared inside a block. +!!! error TS1157: 'let' declarations must be declared inside a block. else let l2 = 0; ~~~~~~~~~~~ -!!! error TS1157: let must be declared inside a block. +!!! error TS1157: 'let' declarations must be declared inside a block. while (true) let l3 = 0; ~~~~~~~~~~~ -!!! error TS1157: let must be declared inside a block. +!!! error TS1157: 'let' declarations must be declared inside a block. do let l4 = 0; ~~~~~~~~~~~ -!!! error TS1157: let must be declared inside a block. +!!! error TS1157: 'let' declarations must be declared inside a block. while (true); var obj; @@ -39,27 +39,27 @@ tests/cases/compiler/letDeclarations-invalidContexts.ts(16,7): error TS2410: All !!! error TS2410: All symbols within a 'with' block will be resolved to 'any'. let l5 = 0; ~~~~~~~~~~~ -!!! error TS1157: let must be declared inside a block. +!!! error TS1157: 'let' declarations must be declared inside a block. for (var i = 0; i < 10; i++) let l6 = 0; ~~~~~~~~~~~ -!!! error TS1157: let must be declared inside a block. +!!! error TS1157: 'let' declarations must be declared inside a block. for (var i2 in {}) let l7 = 0; ~~~~~~~~~~~ -!!! error TS1157: let must be declared inside a block. +!!! error TS1157: 'let' declarations must be declared inside a block. if (true) label: let l8 = 0; ~~~~~~~~~~~ -!!! error TS1157: let must be declared inside a block. +!!! error TS1157: 'let' declarations must be declared inside a block. while (false) label2: label3: label4: let l9 = 0; ~~~~~~~~~~~ -!!! error TS1157: let must be declared inside a block. +!!! error TS1157: 'let' declarations must be declared inside a block. diff --git a/tests/baselines/reference/letDeclarations2.errors.txt b/tests/baselines/reference/letDeclarations2.errors.txt deleted file mode 100644 index 384912a2bb4..00000000000 --- a/tests/baselines/reference/letDeclarations2.errors.txt +++ /dev/null @@ -1,11 +0,0 @@ -tests/cases/compiler/letDeclarations2.ts(4,5): error TS1158: Only var declarations can be exported. - - -==== tests/cases/compiler/letDeclarations2.ts (1 errors) ==== - - module M { - let l1 = "s"; - export let l2 = 0; - ~~~~~~~~~~~~~~~~~~ -!!! error TS1158: Only var declarations can be exported. - } \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations2.js b/tests/baselines/reference/letDeclarations2.js new file mode 100644 index 00000000000..8a6f039f2ca --- /dev/null +++ b/tests/baselines/reference/letDeclarations2.js @@ -0,0 +1,19 @@ +//// [letDeclarations2.ts] + +module M { + let l1 = "s"; + export let l2 = 0; +} + +//// [letDeclarations2.js] +var M; +(function (M) { + let l1 = "s"; + M.l2 = 0; +})(M || (M = {})); + + +//// [letDeclarations2.d.ts] +declare module M { + let l2: number; +} diff --git a/tests/baselines/reference/letDeclarations2.types b/tests/baselines/reference/letDeclarations2.types new file mode 100644 index 00000000000..2fa08b6d940 --- /dev/null +++ b/tests/baselines/reference/letDeclarations2.types @@ -0,0 +1,11 @@ +=== tests/cases/compiler/letDeclarations2.ts === + +module M { +>M : typeof M + + let l1 = "s"; +>l1 : string + + export let l2 = 0; +>l2 : number +} diff --git a/tests/cases/compiler/constDeclarations-access2.ts b/tests/cases/compiler/constDeclarations-access2.ts index e46889c1126..e3f83940d1d 100644 --- a/tests/cases/compiler/constDeclarations-access2.ts +++ b/tests/cases/compiler/constDeclarations-access2.ts @@ -21,6 +21,8 @@ x--; ++x; --x; +++((x)); + // OK var a = x + 1; diff --git a/tests/cases/compiler/constDeclarations-access3.ts b/tests/cases/compiler/constDeclarations-access3.ts new file mode 100644 index 00000000000..370288dab97 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-access3.ts @@ -0,0 +1,45 @@ +// @target: ES6 + + +module M { + export const x = 0; +} + +// Errors +M.x = 1; +M.x += 2; +M.x -= 3; +M.x *= 4; +M.x /= 5; +M.x %= 6; +M.x <<= 7; +M.x >>= 8; +M.x >>>= 9; +M.x &= 10; +M.x |= 11; +M.x ^= 12; + +M.x++; +M.x--; +++M.x; +--M.x; + +++((M.x)); + +M["x"] = 0; + +// OK +var a = M.x + 1; + +function f(v: number) { } +f(M.x); + +if (M.x) { } + +M.x; +(M.x); + +-M.x; ++M.x; + +M.x.toString(); diff --git a/tests/cases/compiler/constDeclarations-access4.ts b/tests/cases/compiler/constDeclarations-access4.ts new file mode 100644 index 00000000000..492f6a31d6d --- /dev/null +++ b/tests/cases/compiler/constDeclarations-access4.ts @@ -0,0 +1,45 @@ +// @target: ES6 + + +declare module M { + const x: number; +} + +// Errors +M.x = 1; +M.x += 2; +M.x -= 3; +M.x *= 4; +M.x /= 5; +M.x %= 6; +M.x <<= 7; +M.x >>= 8; +M.x >>>= 9; +M.x &= 10; +M.x |= 11; +M.x ^= 12; + +M.x++; +M.x--; +++M.x; +--M.x; + +++((M.x)); + +M["x"] = 0; + +// OK +var a = M.x + 1; + +function f(v: number) { } +f(M.x); + +if (M.x) { } + +M.x; +(M.x); + +-M.x; ++M.x; + +M.x.toString(); diff --git a/tests/cases/compiler/constDeclarations-access5.ts b/tests/cases/compiler/constDeclarations-access5.ts new file mode 100644 index 00000000000..1590d9289ef --- /dev/null +++ b/tests/cases/compiler/constDeclarations-access5.ts @@ -0,0 +1,48 @@ +// @target: ES6 +// @module: amd + + +// @Filename: constDeclarations_access_1.ts +export const x = 0; + +// @Filename: constDeclarations_access_2.ts +/// +import m = require('constDeclarations_access_1'); +// Errors +m.x = 1; +m.x += 2; +m.x -= 3; +m.x *= 4; +m.x /= 5; +m.x %= 6; +m.x <<= 7; +m.x >>= 8; +m.x >>>= 9; +m.x &= 10; +m.x |= 11; +m.x ^= 12; +m +m.x++; +m.x--; +++m.x; +--m.x; + +++((m.x)); + +m["x"] = 0; + +// OK +var a = m.x + 1; + +function f(v: number) { } +f(m.x); + +if (m.x) { } + +m.x; +(m.x); + +-m.x; ++m.x; + +m.x.toString(); From 0a59cdd5a0dc58853c2b89df23ba73965b1a7f2e Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 17 Oct 2014 16:18:18 -0700 Subject: [PATCH 19/63] Treat blockScoped variable declarations as a separate category when it comes to symbol flags, instead of compining BlockScoped and Variable --- src/compiler/binder.ts | 17 +++--- src/compiler/checker.ts | 10 ++-- src/compiler/types.ts | 112 +++++++++++++++++++++------------------- 3 files changed, 71 insertions(+), 68 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 0760f33ce67..4441d017802 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -262,8 +262,8 @@ module ts { } function bindCatchVariableDeclaration(node: CatchBlock) { - var symbol = createSymbol(SymbolFlags.Variable, node.variable.text || "__missing"); - addDeclarationToSymbol(symbol, node, SymbolFlags.Variable); + var symbol = createSymbol(SymbolFlags.FunctionScopedVariable, node.variable.text || "__missing"); + addDeclarationToSymbol(symbol, node, SymbolFlags.FunctionScopedVariable); var saveParent = parent; var savedBlockScopeContainer = blockScopeContainer; parent = blockScopeContainer = node; @@ -273,24 +273,23 @@ module ts { } function bindBlockScopedVariableDeclaration(node: Declaration) { - var symbolKind = SymbolFlags.Variable | SymbolFlags.BlockScoped; switch (blockScopeContainer.kind) { case SyntaxKind.ModuleDeclaration: - declareModuleMember(node, symbolKind, SymbolFlags.BlockScopedExcludes); + declareModuleMember(node, SymbolFlags.BlockScopedVariable, SymbolFlags.BlockScopedVariableExcludes); break; case SyntaxKind.SourceFile: if (isExternalModule(container)) { - declareModuleMember(node, symbolKind, SymbolFlags.BlockScopedExcludes); + declareModuleMember(node, SymbolFlags.BlockScopedVariable, SymbolFlags.BlockScopedVariableExcludes); break; } default: if (!blockScopeContainer.locals) { blockScopeContainer.locals = {}; } - declareSymbol(blockScopeContainer.locals, undefined, node, symbolKind, SymbolFlags.BlockScopedExcludes); + declareSymbol(blockScopeContainer.locals, undefined, node, SymbolFlags.BlockScopedVariable, SymbolFlags.BlockScopedVariableExcludes); } - bindChildren(node, symbolKind, /*isBlockScopeContainer*/ false); + bindChildren(node, SymbolFlags.BlockScopedVariable, /*isBlockScopeContainer*/ false); } function bind(node: Node) { @@ -301,14 +300,14 @@ module ts { bindDeclaration(node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.Parameter: - bindDeclaration(node, SymbolFlags.Variable, SymbolFlags.ParameterExcludes, /*isBlockScopeContainer*/ false); + bindDeclaration(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.ParameterExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.VariableDeclaration: if (node.flags & NodeFlags.BlockScoped) { bindBlockScopedVariableDeclaration(node); } else { - bindDeclaration(node, SymbolFlags.Variable, SymbolFlags.VariableExcludes, /*isBlockScopeContainer*/ false); + bindDeclaration(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.FunctionScopedVariableExcludes, /*isBlockScopeContainer*/ false); } break; case SyntaxKind.Property: diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bb96151997a..5caf4acd02e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -181,8 +181,8 @@ module ts { function getExcludedSymbolFlags(flags: SymbolFlags): SymbolFlags { var result: SymbolFlags = 0; - if (flags & SymbolFlags.BlockScoped) result |= SymbolFlags.BlockScopedExcludes; - if (flags & SymbolFlags.Variable) result |= SymbolFlags.VariableExcludes; + if (flags & SymbolFlags.BlockScopedVariable) result |= SymbolFlags.BlockScopedVariableExcludes; + if (flags & SymbolFlags.FunctionScopedVariable) result |= SymbolFlags.FunctionScopedVariableExcludes; if (flags & SymbolFlags.Property) result |= SymbolFlags.PropertyExcludes; if (flags & SymbolFlags.EnumMember) result |= SymbolFlags.EnumMemberExcludes; if (flags & SymbolFlags.Function) result |= SymbolFlags.FunctionExcludes; @@ -328,8 +328,8 @@ module ts { error(errorLocation, nameNotFoundMessage, nameArg); } - if (s && s.flags & SymbolFlags.BlockScoped) { - // Block-scoped variables can not be used before thier definition + if (s && s.flags & SymbolFlags.BlockScopedVariable) { + // Block-scoped variables can not be used before their definition var declaration = forEach(s.declarations, d => d.flags & NodeFlags.BlockScoped ? d : undefined); Debug.assert(declaration, "Bock-scoped variable declaration is undefined"); var declarationSourceFile = getSourceFileOfNode(declaration); @@ -6792,7 +6792,7 @@ module ts { if (node.initializer && (node.flags & NodeFlags.BlockScoped) === 0) { var symbol = getSymbolOfNode(node); var localDeclarationSymbol = resolveName(node, node.name.text, SymbolFlags.Variable, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined); - if (localDeclarationSymbol && localDeclarationSymbol !== symbol && localDeclarationSymbol.flags & SymbolFlags.BlockScoped) { + if (localDeclarationSymbol && localDeclarationSymbol !== symbol && localDeclarationSymbol.flags & SymbolFlags.BlockScopedVariable) { if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & NodeFlags.Const) { error(node, Diagnostics.Cannot_redeclare_constant_0, symbolToString(localDeclarationSymbol)); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 5a5a5989dab..32675c554cd 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -751,68 +751,72 @@ module ts { } export enum SymbolFlags { - Variable = 0x00000001, // Variable or parameter - Property = 0x00000002, // Property or enum member - EnumMember = 0x00000004, // Enum member - Function = 0x00000008, // Function - Class = 0x00000010, // Class - Interface = 0x00000020, // Interface - Enum = 0x00000040, // Enum - ValueModule = 0x00000080, // Instantiated module - NamespaceModule = 0x00000100, // Uninstantiated module - TypeLiteral = 0x00000200, // Type Literal - ObjectLiteral = 0x00000400, // Object Literal - Method = 0x00000800, // Method - Constructor = 0x00001000, // Constructor - GetAccessor = 0x00002000, // Get accessor - SetAccessor = 0x00004000, // Set accessor - CallSignature = 0x00008000, // Call signature - ConstructSignature = 0x00010000, // Construct signature - IndexSignature = 0x00020000, // Index signature - TypeParameter = 0x00040000, // Type parameter - UnionProperty = 0x00080000, // Property in union type + FunctionScopedVariable = 0x00000001, // Variable (var) or parameter + Property = 0x00000002, // Property or enum member + EnumMember = 0x00000004, // Enum member + Function = 0x00000008, // Function + Class = 0x00000010, // Class + Interface = 0x00000020, // Interface + Enum = 0x00000040, // Enum + ValueModule = 0x00000080, // Instantiated module + NamespaceModule = 0x00000100, // Uninstantiated module + TypeLiteral = 0x00000200, // Type Literal + ObjectLiteral = 0x00000400, // Object Literal + Method = 0x00000800, // Method + Constructor = 0x00001000, // Constructor + GetAccessor = 0x00002000, // Get accessor + SetAccessor = 0x00004000, // Set accessor + CallSignature = 0x00008000, // Call signature + ConstructSignature = 0x00010000, // Construct signature + IndexSignature = 0x00020000, // Index signature + TypeParameter = 0x00040000, // Type parameter + UnionProperty = 0x00080000, // Property in union type // Export markers (see comment in declareModuleMember in binder) - ExportValue = 0x00100000, // Exported value marker - ExportType = 0x00200000, // Exported type marker - ExportNamespace = 0x00400000, // Exported namespace marker + ExportValue = 0x00100000, // Exported value marker + ExportType = 0x00200000, // Exported type marker + ExportNamespace = 0x00400000, // Exported namespace marker - Import = 0x00800000, // Import - Instantiated = 0x01000000, // Instantiated symbol - Merged = 0x02000000, // Merged symbol (created during program binding) - Transient = 0x04000000, // Transient symbol (created during type check) - Prototype = 0x08000000, // Prototype property (no source representation) + Import = 0x00800000, // Import + Instantiated = 0x01000000, // Instantiated symbol + Merged = 0x02000000, // Merged symbol (created during program binding) + Transient = 0x04000000, // Transient symbol (created during type check) + Prototype = 0x08000000, // Prototype property (no source representation) - BlockScoped = 0x10000000, // A block-scoped declaration + BlockScopedVariable = 0x10000000, // A block-scoped variable (let ot const) - Value = Variable | Property | EnumMember | Function | Class | Enum | ValueModule | Method | GetAccessor | SetAccessor | UnionProperty, - Type = Class | Interface | Enum | TypeLiteral | ObjectLiteral | TypeParameter, - Namespace = ValueModule | NamespaceModule, - Module = ValueModule | NamespaceModule, - Accessor = GetAccessor | SetAccessor, - Signature = CallSignature | ConstructSignature | IndexSignature, + Variable = FunctionScopedVariable | BlockScopedVariable, + Value = Variable | Property | EnumMember | Function | Class | Enum | ValueModule | Method | GetAccessor | SetAccessor | UnionProperty, + Type = Class | Interface | Enum | TypeLiteral | ObjectLiteral | TypeParameter, + Namespace = ValueModule | NamespaceModule, + Module = ValueModule | NamespaceModule, + Accessor = GetAccessor | SetAccessor, + Signature = CallSignature | ConstructSignature | IndexSignature, - ParameterExcludes = Value, - VariableExcludes = (Value | BlockScoped) & ~Variable, // Variables can be redeclared, but can not redeclare a block-scoped - // declaration with the same name, or any other value that is not a - // variable, e.g. ValueModule or Class - BlockScopedExcludes = Value, // Block-scoped declarations are not allowed to be re-declared - // they can not merge with anything in the value space - PropertyExcludes = Value, - EnumMemberExcludes = Value, - FunctionExcludes = Value & ~(Function | ValueModule), - ClassExcludes = (Value | Type) & ~ValueModule, - InterfaceExcludes = Type & ~Interface, - EnumExcludes = (Value | Type) & ~(Enum | ValueModule), - ValueModuleExcludes = Value & ~(Function | Class | Enum | ValueModule), - NamespaceModuleExcludes = 0, - MethodExcludes = Value & ~Method, - GetAccessorExcludes = Value & ~SetAccessor, - SetAccessorExcludes = Value & ~GetAccessor, - TypeParameterExcludes = Type & ~TypeParameter, + ParameterExcludes = Value, + + // Variables can be redeclared, but can not redeclare a block-scoped declaration with the + // same name, or any other value that is not a variable, e.g. ValueModule or Class + FunctionScopedVariableExcludes = Value & ~FunctionScopedVariable, + + // Block-scoped declarations are not allowed to be re-declared + // they can not merge with anything in the value space + BlockScopedVariableExcludes = Value, + PropertyExcludes = Value, + EnumMemberExcludes = Value, + FunctionExcludes = Value & ~(Function | ValueModule), + ClassExcludes = (Value | Type) & ~ValueModule, + InterfaceExcludes = Type & ~Interface, + EnumExcludes = (Value | Type) & ~(Enum | ValueModule), + ValueModuleExcludes = Value & ~(Function | Class | Enum | ValueModule), + NamespaceModuleExcludes = 0, + MethodExcludes = Value & ~Method, + GetAccessorExcludes = Value & ~SetAccessor, + SetAccessorExcludes = Value & ~GetAccessor, + TypeParameterExcludes = Type & ~TypeParameter, // Imports collide with all other imports with the same name. - ImportExcludes = Import, + ImportExcludes = Import, ModuleMember = Variable | Function | Class | Interface | Enum | Module | Import, From dd5c89d5cfb89e682e48c257c0fbae9d4bd010a4 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 20 Oct 2014 13:48:22 -0700 Subject: [PATCH 20/63] Update error messages --- .../diagnosticInformationMap.generated.ts | 6 ++-- src/compiler/diagnosticMessages.json | 6 ++-- src/compiler/parser.ts | 12 +++---- .../constDeclarations-errors.errors.txt | 36 +++++++++---------- ...nstDeclarations-invalidContexts.errors.txt | 36 +++++++++---------- ...letDeclarations-invalidContexts.errors.txt | 36 +++++++++---------- 6 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index ef0ab4327a1..467797747be 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -118,9 +118,9 @@ module ts { var_let_or_const_expected: { code: 1152, category: DiagnosticCategory.Error, key: "'var', 'let' or 'const' expected." }, let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1153, category: DiagnosticCategory.Error, key: "'let' declarations are only available when targeting ECMAScript 6 and higher." }, const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1154, category: DiagnosticCategory.Error, key: "'const' declarations are only available when targeting ECMAScript 6 and higher." }, - const_must_be_intialized: { code: 1155, category: DiagnosticCategory.Error, key: "const must be intialized." }, - const_declarations_must_be_declared_inside_a_block: { code: 1156, category: DiagnosticCategory.Error, key: "'const' declarations must be declared inside a block." }, - let_declarations_must_be_declared_inside_a_block: { code: 1157, category: DiagnosticCategory.Error, key: "'let' declarations must be declared inside a block." }, + const_declarations_must_be_initialized: { code: 1155, category: DiagnosticCategory.Error, key: "'const' declarations must be initialized" }, + const_declarations_can_only_be_declared_inside_a_block: { code: 1156, category: DiagnosticCategory.Error, key: "'const' declarations can only be declared inside a block." }, + let_declarations_can_only_be_declared_inside_a_block: { code: 1157, category: DiagnosticCategory.Error, key: "'let' declarations can only be declared inside a block." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 34ecabe31ae..0f7788eae6e 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -463,15 +463,15 @@ "category": "Error", "code": 1154 }, - "const must be intialized.": { + "'const' declarations must be initialized": { "category": "Error", "code": 1155 }, - "'const' declarations must be declared inside a block.": { + "'const' declarations can only be declared inside a block.": { "category": "Error", "code": 1156 }, - "'let' declarations must be declared inside a block.": { + "'let' declarations can only be declared inside a block.": { "category": "Error", "code": 1157 }, diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 1cc667c5cb9..a0e992098f7 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2726,13 +2726,13 @@ module ts { parseExpected(SyntaxKind.OpenParenToken); if (token !== SyntaxKind.SemicolonToken) { if (parseOptional(SyntaxKind.VarKeyword)) { - var declarations = parseVariableDeclarationList(0, true); + var declarations = parseVariableDeclarationList(0, /*noIn*/ true); if (!declarations.length) { error(Diagnostics.Variable_declaration_list_cannot_be_empty); } } else if (parseOptional(SyntaxKind.LetKeyword)) { - var declarations = parseVariableDeclarationList(NodeFlags.Let, true); + var declarations = parseVariableDeclarationList(NodeFlags.Let, /*noIn*/ true); if (!declarations.length) { error(Diagnostics.Variable_declaration_list_cannot_be_empty); } @@ -2741,7 +2741,7 @@ module ts { } } else if (parseOptional(SyntaxKind.ConstKeyword)) { - var declarations = parseVariableDeclarationList(NodeFlags.Const, true); + var declarations = parseVariableDeclarationList(NodeFlags.Const, /*noIn*/ true); if (!declarations.length) { error(Diagnostics.Variable_declaration_list_cannot_be_empty); } @@ -3200,7 +3200,7 @@ module ts { grammarErrorAtPos(initializerStart, initializerFirstTokenLength, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); } if (!inAmbientContext && !node.initializer && flags & NodeFlags.Const) { - grammarErrorOnNode(node, Diagnostics.const_must_be_intialized); + grammarErrorOnNode(node, Diagnostics.const_declarations_must_be_initialized); } if (isInStrictMode && isEvalOrArgumentsIdentifier(node.name)) { // It is a SyntaxError if a VariableDeclaration or VariableDeclarationNoIn occurs within strict code @@ -3245,10 +3245,10 @@ module ts { } else if (!allowLetAndConstDeclarations) { if (node.flags & NodeFlags.Let) { - grammarErrorOnNode(node, Diagnostics.let_declarations_must_be_declared_inside_a_block); + grammarErrorOnNode(node, Diagnostics.let_declarations_can_only_be_declared_inside_a_block); } else if (node.flags & NodeFlags.Const) { - grammarErrorOnNode(node, Diagnostics.const_declarations_must_be_declared_inside_a_block); + grammarErrorOnNode(node, Diagnostics.const_declarations_can_only_be_declared_inside_a_block); } } return node; diff --git a/tests/baselines/reference/constDeclarations-errors.errors.txt b/tests/baselines/reference/constDeclarations-errors.errors.txt index 1766fb49374..d87007474a1 100644 --- a/tests/baselines/reference/constDeclarations-errors.errors.txt +++ b/tests/baselines/reference/constDeclarations-errors.errors.txt @@ -1,12 +1,12 @@ -tests/cases/compiler/constDeclarations-errors.ts(3,7): error TS1155: const must be intialized. -tests/cases/compiler/constDeclarations-errors.ts(4,7): error TS1155: const must be intialized. -tests/cases/compiler/constDeclarations-errors.ts(5,7): error TS1155: const must be intialized. -tests/cases/compiler/constDeclarations-errors.ts(5,11): error TS1155: const must be intialized. -tests/cases/compiler/constDeclarations-errors.ts(5,15): error TS1155: const must be intialized. -tests/cases/compiler/constDeclarations-errors.ts(5,27): error TS1155: const must be intialized. -tests/cases/compiler/constDeclarations-errors.ts(8,11): error TS1155: const must be intialized. -tests/cases/compiler/constDeclarations-errors.ts(14,11): error TS1155: const must be intialized. -tests/cases/compiler/constDeclarations-errors.ts(17,20): error TS1155: const must be intialized. +tests/cases/compiler/constDeclarations-errors.ts(3,7): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(4,7): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(5,7): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(5,11): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(5,15): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(5,27): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(8,11): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(14,11): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(17,20): error TS1155: 'const' declarations must be initialized tests/cases/compiler/constDeclarations-errors.ts(11,27): error TS2449: The operand of an increment or decrement operator cannot be a constant. @@ -15,24 +15,24 @@ tests/cases/compiler/constDeclarations-errors.ts(11,27): error TS2449: The opera // error, missing intialicer const c1; ~~ -!!! error TS1155: const must be intialized. +!!! error TS1155: 'const' declarations must be initialized const c2: number; ~~ -!!! error TS1155: const must be intialized. +!!! error TS1155: 'const' declarations must be initialized const c3, c4, c5 :string, c6; // error, missing initialicer ~~ -!!! error TS1155: const must be intialized. +!!! error TS1155: 'const' declarations must be initialized ~~ -!!! error TS1155: const must be intialized. +!!! error TS1155: 'const' declarations must be initialized ~~ -!!! error TS1155: const must be intialized. +!!! error TS1155: 'const' declarations must be initialized ~~ -!!! error TS1155: const must be intialized. +!!! error TS1155: 'const' declarations must be initialized // error, can not be unintalized for(const c in {}) { } ~ -!!! error TS1155: const must be intialized. +!!! error TS1155: 'const' declarations must be initialized // error, assigning to a const for(const c8 = 0; c8 < 1; c8++) { } @@ -42,9 +42,9 @@ tests/cases/compiler/constDeclarations-errors.ts(11,27): error TS2449: The opera // error, can not be unintalized for(const c9; c9 < 1;) { } ~~ -!!! error TS1155: const must be intialized. +!!! error TS1155: 'const' declarations must be initialized // error, can not be unintalized for(const c10 = 0, c11; c10 < 1;) { } ~~~ -!!! error TS1155: const must be intialized. \ No newline at end of file +!!! error TS1155: 'const' declarations must be initialized \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-invalidContexts.errors.txt b/tests/baselines/reference/constDeclarations-invalidContexts.errors.txt index bc229185e83..745ef305ac6 100644 --- a/tests/baselines/reference/constDeclarations-invalidContexts.errors.txt +++ b/tests/baselines/reference/constDeclarations-invalidContexts.errors.txt @@ -1,12 +1,12 @@ -tests/cases/compiler/constDeclarations-invalidContexts.ts(4,5): error TS1156: 'const' declarations must be declared inside a block. -tests/cases/compiler/constDeclarations-invalidContexts.ts(6,5): error TS1156: 'const' declarations must be declared inside a block. -tests/cases/compiler/constDeclarations-invalidContexts.ts(9,5): error TS1156: 'const' declarations must be declared inside a block. -tests/cases/compiler/constDeclarations-invalidContexts.ts(12,5): error TS1156: 'const' declarations must be declared inside a block. -tests/cases/compiler/constDeclarations-invalidContexts.ts(17,5): error TS1156: 'const' declarations must be declared inside a block. -tests/cases/compiler/constDeclarations-invalidContexts.ts(20,5): error TS1156: 'const' declarations must be declared inside a block. -tests/cases/compiler/constDeclarations-invalidContexts.ts(23,5): error TS1156: 'const' declarations must be declared inside a block. -tests/cases/compiler/constDeclarations-invalidContexts.ts(26,12): error TS1156: 'const' declarations must be declared inside a block. -tests/cases/compiler/constDeclarations-invalidContexts.ts(29,29): error TS1156: 'const' declarations must be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(4,5): error TS1156: 'const' declarations can only be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(6,5): error TS1156: 'const' declarations can only be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(9,5): error TS1156: 'const' declarations can only be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(12,5): error TS1156: 'const' declarations can only be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(17,5): error TS1156: 'const' declarations can only be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(20,5): error TS1156: 'const' declarations can only be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(23,5): error TS1156: 'const' declarations can only be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(26,12): error TS1156: 'const' declarations can only be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(29,29): error TS1156: 'const' declarations can only be declared inside a block. tests/cases/compiler/constDeclarations-invalidContexts.ts(16,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'. @@ -16,21 +16,21 @@ tests/cases/compiler/constDeclarations-invalidContexts.ts(16,7): error TS2410: A if (true) const c1 = 0; ~~~~~~~~~~~~~ -!!! error TS1156: 'const' declarations must be declared inside a block. +!!! error TS1156: 'const' declarations can only be declared inside a block. else const c2 = 0; ~~~~~~~~~~~~~ -!!! error TS1156: 'const' declarations must be declared inside a block. +!!! error TS1156: 'const' declarations can only be declared inside a block. while (true) const c3 = 0; ~~~~~~~~~~~~~ -!!! error TS1156: 'const' declarations must be declared inside a block. +!!! error TS1156: 'const' declarations can only be declared inside a block. do const c4 = 0; ~~~~~~~~~~~~~ -!!! error TS1156: 'const' declarations must be declared inside a block. +!!! error TS1156: 'const' declarations can only be declared inside a block. while (true); var obj; @@ -39,27 +39,27 @@ tests/cases/compiler/constDeclarations-invalidContexts.ts(16,7): error TS2410: A !!! error TS2410: All symbols within a 'with' block will be resolved to 'any'. const c5 = 0; ~~~~~~~~~~~~~ -!!! error TS1156: 'const' declarations must be declared inside a block. +!!! error TS1156: 'const' declarations can only be declared inside a block. for (var i = 0; i < 10; i++) const c6 = 0; ~~~~~~~~~~~~~ -!!! error TS1156: 'const' declarations must be declared inside a block. +!!! error TS1156: 'const' declarations can only be declared inside a block. for (var i2 in {}) const c7 = 0; ~~~~~~~~~~~~~ -!!! error TS1156: 'const' declarations must be declared inside a block. +!!! error TS1156: 'const' declarations can only be declared inside a block. if (true) label: const c8 = 0; ~~~~~~~~~~~~~ -!!! error TS1156: 'const' declarations must be declared inside a block. +!!! error TS1156: 'const' declarations can only be declared inside a block. while (false) label2: label3: label4: const c9 = 0; ~~~~~~~~~~~~~ -!!! error TS1156: 'const' declarations must be declared inside a block. +!!! error TS1156: 'const' declarations can only be declared inside a block. diff --git a/tests/baselines/reference/letDeclarations-invalidContexts.errors.txt b/tests/baselines/reference/letDeclarations-invalidContexts.errors.txt index 0e86e84e784..ad0c0f741b5 100644 --- a/tests/baselines/reference/letDeclarations-invalidContexts.errors.txt +++ b/tests/baselines/reference/letDeclarations-invalidContexts.errors.txt @@ -1,12 +1,12 @@ -tests/cases/compiler/letDeclarations-invalidContexts.ts(4,5): error TS1157: 'let' declarations must be declared inside a block. -tests/cases/compiler/letDeclarations-invalidContexts.ts(6,5): error TS1157: 'let' declarations must be declared inside a block. -tests/cases/compiler/letDeclarations-invalidContexts.ts(9,5): error TS1157: 'let' declarations must be declared inside a block. -tests/cases/compiler/letDeclarations-invalidContexts.ts(12,5): error TS1157: 'let' declarations must be declared inside a block. -tests/cases/compiler/letDeclarations-invalidContexts.ts(17,5): error TS1157: 'let' declarations must be declared inside a block. -tests/cases/compiler/letDeclarations-invalidContexts.ts(20,5): error TS1157: 'let' declarations must be declared inside a block. -tests/cases/compiler/letDeclarations-invalidContexts.ts(23,5): error TS1157: 'let' declarations must be declared inside a block. -tests/cases/compiler/letDeclarations-invalidContexts.ts(26,12): error TS1157: 'let' declarations must be declared inside a block. -tests/cases/compiler/letDeclarations-invalidContexts.ts(29,29): error TS1157: 'let' declarations must be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(4,5): error TS1157: 'let' declarations can only be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(6,5): error TS1157: 'let' declarations can only be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(9,5): error TS1157: 'let' declarations can only be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(12,5): error TS1157: 'let' declarations can only be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(17,5): error TS1157: 'let' declarations can only be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(20,5): error TS1157: 'let' declarations can only be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(23,5): error TS1157: 'let' declarations can only be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(26,12): error TS1157: 'let' declarations can only be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(29,29): error TS1157: 'let' declarations can only be declared inside a block. tests/cases/compiler/letDeclarations-invalidContexts.ts(16,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'. @@ -16,21 +16,21 @@ tests/cases/compiler/letDeclarations-invalidContexts.ts(16,7): error TS2410: All if (true) let l1 = 0; ~~~~~~~~~~~ -!!! error TS1157: 'let' declarations must be declared inside a block. +!!! error TS1157: 'let' declarations can only be declared inside a block. else let l2 = 0; ~~~~~~~~~~~ -!!! error TS1157: 'let' declarations must be declared inside a block. +!!! error TS1157: 'let' declarations can only be declared inside a block. while (true) let l3 = 0; ~~~~~~~~~~~ -!!! error TS1157: 'let' declarations must be declared inside a block. +!!! error TS1157: 'let' declarations can only be declared inside a block. do let l4 = 0; ~~~~~~~~~~~ -!!! error TS1157: 'let' declarations must be declared inside a block. +!!! error TS1157: 'let' declarations can only be declared inside a block. while (true); var obj; @@ -39,27 +39,27 @@ tests/cases/compiler/letDeclarations-invalidContexts.ts(16,7): error TS2410: All !!! error TS2410: All symbols within a 'with' block will be resolved to 'any'. let l5 = 0; ~~~~~~~~~~~ -!!! error TS1157: 'let' declarations must be declared inside a block. +!!! error TS1157: 'let' declarations can only be declared inside a block. for (var i = 0; i < 10; i++) let l6 = 0; ~~~~~~~~~~~ -!!! error TS1157: 'let' declarations must be declared inside a block. +!!! error TS1157: 'let' declarations can only be declared inside a block. for (var i2 in {}) let l7 = 0; ~~~~~~~~~~~ -!!! error TS1157: 'let' declarations must be declared inside a block. +!!! error TS1157: 'let' declarations can only be declared inside a block. if (true) label: let l8 = 0; ~~~~~~~~~~~ -!!! error TS1157: 'let' declarations must be declared inside a block. +!!! error TS1157: 'let' declarations can only be declared inside a block. while (false) label2: label3: label4: let l9 = 0; ~~~~~~~~~~~ -!!! error TS1157: 'let' declarations must be declared inside a block. +!!! error TS1157: 'let' declarations can only be declared inside a block. From 91f40988f113e46f8a1dd9193c3f78715f6e4527 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 20 Oct 2014 15:30:06 -0700 Subject: [PATCH 21/63] Simplify the binder logic for managing blockScopeContainer --- src/compiler/binder.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 4441d017802..993c8c39143 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -293,7 +293,6 @@ module ts { } function bind(node: Node) { - var isBlockScopeContainer: boolean; node.parent = parent; switch (node.kind) { case SyntaxKind.TypeParameter: @@ -382,16 +381,14 @@ module ts { case SyntaxKind.ForStatement: case SyntaxKind.ForInStatement: case SyntaxKind.SwitchStatement: - isBlockScopeContainer = true; + bindChildren(node, 0 , true); + break; default: var saveParent = parent; - var savedBlockScopeContainer = blockScopeContainer; parent = node; - if (isBlockScopeContainer) blockScopeContainer = node; forEachChild(node, bind); parent = saveParent; - blockScopeContainer = savedBlockScopeContainer; } } } From d5fe43b53ed4a48e3e13ce277032cefe95c4e11d Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 20 Oct 2014 15:31:33 -0700 Subject: [PATCH 22/63] allow let and const declarations in module bodies under labels --- src/compiler/parser.ts | 8 ++++---- .../reference/letDeclarations-scopes.errors.txt | 14 ++++++++------ .../baselines/reference/letDeclarations-scopes.js | 15 +++++++++------ tests/cases/compiler/letDeclarations-scopes.ts | 14 ++++++++------ 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index a0e992098f7..caa62b7ae9e 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3916,14 +3916,14 @@ module ts { } function parseSourceElement() { - return parseSourceElementOrModuleElement(ModifierContext.SourceElements); + return parseSourceElementOrModuleElement(ModifierContext.SourceElements, /*allowLetAndConstDeclarations*/ false); } function parseModuleElement() { - return parseSourceElementOrModuleElement(ModifierContext.ModuleElements); + return parseSourceElementOrModuleElement(ModifierContext.ModuleElements, /*allowLetAndConstDeclarations*/ true); } - function parseSourceElementOrModuleElement(modifierContext: ModifierContext): Statement { + function parseSourceElementOrModuleElement(modifierContext: ModifierContext, allowLetAndConstDeclarations: boolean): Statement { if (isDeclaration()) { return parseDeclaration(modifierContext); } @@ -3931,7 +3931,7 @@ module ts { var statementStart = scanner.getTokenPos(); var statementFirstTokenLength = scanner.getTextPos() - statementStart; var errorCountBeforeStatement = file.syntacticErrors.length; - var statement = parseStatement(/*allowLetAndConstDeclarations*/ false); + var statement = parseStatement(allowLetAndConstDeclarations); if (inAmbientContext && file.syntacticErrors.length === errorCountBeforeStatement) { grammarErrorAtPos(statementStart, statementFirstTokenLength, Diagnostics.Statements_are_not_allowed_in_ambient_contexts); diff --git a/tests/baselines/reference/letDeclarations-scopes.errors.txt b/tests/baselines/reference/letDeclarations-scopes.errors.txt index df54e0fc3c4..5c89ea98049 100644 --- a/tests/baselines/reference/letDeclarations-scopes.errors.txt +++ b/tests/baselines/reference/letDeclarations-scopes.errors.txt @@ -105,12 +105,12 @@ tests/cases/compiler/letDeclarations-scopes.ts(28,7): error TS2410: All symbols var F2 = () => { let l = 0; - n = l; + n = l; }; var F3 = function () { let l = 0; - n = l; + n = l; }; // modules @@ -120,8 +120,10 @@ tests/cases/compiler/letDeclarations-scopes.ts(28,7): error TS2410: All symbols { let l = false; - var b2: boolean = l; + var b2: boolean = l; } + + lable: let l2 = 0; } // methods @@ -152,10 +154,10 @@ tests/cases/compiler/letDeclarations-scopes.ts(28,7): error TS2410: All symbols var o = { f() { let l = 0; - n = l; + n = l; }, - f2: () => { + f2: () => { let l = 0; - n = l; + n = l; } } \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes.js b/tests/baselines/reference/letDeclarations-scopes.js index 59d42368b6c..fb16a03f569 100644 --- a/tests/baselines/reference/letDeclarations-scopes.js +++ b/tests/baselines/reference/letDeclarations-scopes.js @@ -100,12 +100,12 @@ function F() { var F2 = () => { let l = 0; -n = l; + n = l; }; var F3 = function () { let l = 0; -n = l; + n = l; }; // modules @@ -115,8 +115,10 @@ module m { { let l = false; - var b2: boolean = l; + var b2: boolean = l; } + + lable: let l2 = 0; } // methods @@ -147,11 +149,11 @@ class C { var o = { f() { let l = 0; -n = l; + n = l; }, -f2: () => { + f2: () => { let l = 0; - n = l; + n = l; } } @@ -251,6 +253,7 @@ var m; let l = false; var b2 = l; } + lable: let l2 = 0; })(m || (m = {})); // methods var C = (function () { diff --git a/tests/cases/compiler/letDeclarations-scopes.ts b/tests/cases/compiler/letDeclarations-scopes.ts index 0393f0f295b..93f4ce5b4ed 100644 --- a/tests/cases/compiler/letDeclarations-scopes.ts +++ b/tests/cases/compiler/letDeclarations-scopes.ts @@ -100,12 +100,12 @@ function F() { var F2 = () => { let l = 0; -n = l; + n = l; }; var F3 = function () { let l = 0; -n = l; + n = l; }; // modules @@ -115,8 +115,10 @@ module m { { let l = false; - var b2: boolean = l; + var b2: boolean = l; } + + lable: let l2 = 0; } // methods @@ -147,10 +149,10 @@ class C { var o = { f() { let l = 0; -n = l; + n = l; }, -f2: () => { + f2: () => { let l = 0; - n = l; + n = l; } } \ No newline at end of file From dd7ca69866a17ff86dd477578c1178f6407e94a4 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 20 Oct 2014 17:38:50 -0700 Subject: [PATCH 23/63] Create a new flag for diagnostics 'isEarly' and disable emit if this flag is set. Set the flag by default on all let and const errors to ensure we are not emitting invalid JS code. --- scripts/processDiagnosticMessages.ts | 6 +- src/compiler/binder.ts | 5 +- src/compiler/checker.ts | 18 ++- src/compiler/core.ts | 6 +- .../diagnosticInformationMap.generated.ts | 10 +- src/compiler/diagnosticMessages.json | 22 +-- src/compiler/emitter.ts | 13 +- src/compiler/tsc.ts | 19 ++- src/compiler/types.ts | 4 + src/harness/harness.ts | 4 +- ...arationShadowedByVarDeclaration.errors.txt | 12 +- ...onstDeclarationShadowedByVarDeclaration.js | 43 ------ .../reference/constDeclarations-access.js | 13 -- .../reference/constDeclarations-access2.js | 74 --------- .../reference/constDeclarations-access3.js | 83 ----------- .../reference/constDeclarations-access4.js | 79 ---------- .../reference/constDeclarations-access5.js | 89 ----------- .../constDeclarations-useBeforeDefinition.js | 24 --- .../constDeclarations-useBeforeDefinition2.js | 12 -- .../enumIdentifierLiterals.errors.txt | 16 +- ...tDeclarations-scopes-duplicates.errors.txt | 88 +++++------ .../letDeclarations-scopes-duplicates.js | 140 ------------------ ...Declarations-scopes-duplicates2.errors.txt | 8 +- .../letDeclarations-scopes-duplicates2.js | 13 -- ...Declarations-scopes-duplicates3.errors.txt | 8 +- .../letDeclarations-scopes-duplicates3.js | 13 -- ...Declarations-scopes-duplicates4.errors.txt | 8 +- .../letDeclarations-scopes-duplicates4.js | 13 -- ...Declarations-scopes-duplicates5.errors.txt | 8 +- .../letDeclarations-scopes-duplicates5.js | 13 -- ...Declarations-scopes-duplicates6.errors.txt | 8 +- .../letDeclarations-scopes-duplicates6.js | 13 -- ...Declarations-scopes-duplicates7.errors.txt | 8 +- .../letDeclarations-scopes-duplicates7.js | 13 -- .../letDeclarations-useBeforeDefinition.js | 24 --- .../letDeclarations-useBeforeDefinition2.js | 12 -- .../reference/parserEnum5.errors.txt | 12 +- .../reference/parserEnum7.errors.txt | 12 +- 38 files changed, 164 insertions(+), 802 deletions(-) delete mode 100644 tests/baselines/reference/constDeclarationShadowedByVarDeclaration.js delete mode 100644 tests/baselines/reference/constDeclarations-access.js delete mode 100644 tests/baselines/reference/constDeclarations-access2.js delete mode 100644 tests/baselines/reference/constDeclarations-access3.js delete mode 100644 tests/baselines/reference/constDeclarations-access4.js delete mode 100644 tests/baselines/reference/constDeclarations-access5.js delete mode 100644 tests/baselines/reference/constDeclarations-useBeforeDefinition.js delete mode 100644 tests/baselines/reference/constDeclarations-useBeforeDefinition2.js delete mode 100644 tests/baselines/reference/letDeclarations-scopes-duplicates.js delete mode 100644 tests/baselines/reference/letDeclarations-scopes-duplicates2.js delete mode 100644 tests/baselines/reference/letDeclarations-scopes-duplicates3.js delete mode 100644 tests/baselines/reference/letDeclarations-scopes-duplicates4.js delete mode 100644 tests/baselines/reference/letDeclarations-scopes-duplicates5.js delete mode 100644 tests/baselines/reference/letDeclarations-scopes-duplicates6.js delete mode 100644 tests/baselines/reference/letDeclarations-scopes-duplicates7.js delete mode 100644 tests/baselines/reference/letDeclarations-useBeforeDefinition.js delete mode 100644 tests/baselines/reference/letDeclarations-useBeforeDefinition2.js diff --git a/scripts/processDiagnosticMessages.ts b/scripts/processDiagnosticMessages.ts index 6a4aaad9f93..eccfb821bb2 100644 --- a/scripts/processDiagnosticMessages.ts +++ b/scripts/processDiagnosticMessages.ts @@ -3,6 +3,7 @@ interface DiagnosticDetails { category: string; code: number; + isEarly?: boolean; } interface InputDiagnosticMessageTable { @@ -63,8 +64,9 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, nameMap: ' ' + convertPropertyName(nameMap[name]) + ': { code: ' + diagnosticDetails.code + ', category: DiagnosticCategory.' + diagnosticDetails.category + - ', key: "' + name.replace('"', '\\"') + - '" },\r\n'; + ', key: "' + name.replace('"', '\\"') + '"' + + (diagnosticDetails.isEarly ? ', isEarly: true' : '') + + ' },\r\n'; } result += ' };\r\n}'; diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 993c8c39143..accb46504dc 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -87,10 +87,11 @@ module ts { } // Report errors every position with duplicate declaration // Report errors on previous encountered declarations + var message = symbol.flags & SymbolFlags.BlockScopedVariable ? Diagnostics.Cannot_redeclare_block_scoped_variable_0 : Diagnostics.Duplicate_identifier_0; forEach(symbol.declarations, (declaration) => { - file.semanticErrors.push(createDiagnosticForNode(declaration.name, Diagnostics.Duplicate_identifier_0, getDisplayName(declaration))); + file.semanticErrors.push(createDiagnosticForNode(declaration.name, message, getDisplayName(declaration))); }); - file.semanticErrors.push(createDiagnosticForNode(node.name, Diagnostics.Duplicate_identifier_0, getDisplayName(node))); + file.semanticErrors.push(createDiagnosticForNode(node.name, message, getDisplayName(node))); symbol = createSymbol(0, name); } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d9225269145..ca250fb7e53 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -109,7 +109,8 @@ module ts { isImplementationOfOverload: isImplementationOfOverload, getAliasedSymbol: resolveImport, isUndefinedSymbol: symbol => symbol === undefinedSymbol, - isArgumentsSymbol: symbol => symbol === argumentsSymbol + isArgumentsSymbol: symbol => symbol === argumentsSymbol, + hasEarlyErrors: hasEarlyErrors }; var undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined"); @@ -228,11 +229,13 @@ module ts { recordMergedSymbol(target, source); } else { + var message = target.flags & SymbolFlags.BlockScopedVariable || source.flags & SymbolFlags.BlockScopedVariable + ? Diagnostics.Cannot_redeclare_block_scoped_variable_0 : Diagnostics.Duplicate_identifier_0; forEach(source.declarations, node => { - error(node.name ? node.name : node, Diagnostics.Duplicate_identifier_0, symbolToString(source)); + error(node.name ? node.name : node, message, symbolToString(source)); }); forEach(target.declarations, node => { - error(node.name ? node.name : node, Diagnostics.Duplicate_identifier_0, symbolToString(source)); + error(node.name ? node.name : node, message, symbolToString(source)); }); } } @@ -327,7 +330,7 @@ module ts { if (s && s.flags & SymbolFlags.BlockScopedVariable) { // Block-scoped variables can not be used before their definition var declaration = forEach(s.declarations, d => d.flags & NodeFlags.BlockScoped ? d : undefined); - Debug.assert(declaration, "Bock-scoped variable declaration is undefined"); + Debug.assert(declaration, "Block-scoped variable declaration is undefined"); var declarationSourceFile = getSourceFileOfNode(declaration); var referenceSourceFile = getSourceFileOfNode(errorLocation); if (declarationSourceFile === referenceSourceFile && declaration.pos > errorLocation.pos) { @@ -6864,7 +6867,7 @@ module ts { var localDeclarationSymbol = resolveName(node, node.name.text, SymbolFlags.Variable, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined); if (localDeclarationSymbol && localDeclarationSymbol !== symbol && localDeclarationSymbol.flags & SymbolFlags.BlockScopedVariable) { if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & NodeFlags.Const) { - error(node, Diagnostics.Cannot_redeclare_constant_0, symbolToString(localDeclarationSymbol)); + error(node, Diagnostics.Cannot_redeclare_block_scoped_variable_0, symbolToString(localDeclarationSymbol)); } } } @@ -8363,6 +8366,10 @@ module ts { return getDiagnostics().length > 0 || getGlobalDiagnostics().length > 0; } + function hasEarlyErrors(sourceFile?: SourceFile): boolean { + return forEach(getDiagnostics(sourceFile), d => d.isEarly); + } + function isReferencedImportDeclaration(node: ImportDeclaration): boolean { var symbol = getSymbolOfNode(node); if (getSymbolLinks(symbol).referenced) { @@ -8446,6 +8453,7 @@ module ts { getEnumMemberValue: getEnumMemberValue, isTopLevelValueImportedViaEntityName: isTopLevelValueImportedViaEntityName, hasSemanticErrors: hasSemanticErrors, + hasEarlyErrors: hasEarlyErrors, isDeclarationVisible: isDeclarationVisible, isImplementationOfOverload: isImplementationOfOverload, writeTypeAtLocation: writeTypeAtLocation, diff --git a/src/compiler/core.ts b/src/compiler/core.ts index ee7f4701d19..ae2cf053123 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -232,7 +232,8 @@ module ts { messageText: text, category: message.category, - code: message.code + code: message.code, + isEarly: message.isEarly }; } @@ -251,7 +252,8 @@ module ts { messageText: text, category: message.category, - code: message.code + code: message.code, + isEarly: message.isEarly }; } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 467797747be..a5dda0b1f4b 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -114,7 +114,6 @@ module ts { Cannot_compile_external_modules_unless_the_module_flag_is_provided: { code: 1148, category: DiagnosticCategory.Error, key: "Cannot compile external modules unless the '--module' flag is provided." }, Filename_0_differs_from_already_included_filename_1_only_in_casing: { code: 1149, category: DiagnosticCategory.Error, key: "Filename '{0}' differs from already included filename '{1}' only in casing" }, new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: DiagnosticCategory.Error, key: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, - An_enum_member_cannot_have_a_numeric_name: { code: 1151, category: DiagnosticCategory.Error, key: "An enum member cannot have a numeric name." }, var_let_or_const_expected: { code: 1152, category: DiagnosticCategory.Error, key: "'var', 'let' or 'const' expected." }, let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1153, category: DiagnosticCategory.Error, key: "'let' declarations are only available when targeting ECMAScript 6 and higher." }, const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1154, category: DiagnosticCategory.Error, key: "'const' declarations are only available when targeting ECMAScript 6 and higher." }, @@ -267,10 +266,11 @@ module ts { Property_0_is_protected_and_only_accessible_within_class_1_and_its_subclasses: { code: 2445, category: DiagnosticCategory.Error, key: "Property '{0}' is protected and only accessible within class '{1}' and its subclasses." }, Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1: { code: 2446, category: DiagnosticCategory.Error, key: "Property '{0}' is protected and only accessible through an instance of class '{1}'." }, The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead: { code: 2447, category: DiagnosticCategory.Error, key: "The '{0}' operator is not allowed for boolean types. Consider using '{1}' instead." }, - Block_scoped_variable_0_used_before_its_declaration: { code: 2448, category: DiagnosticCategory.Error, key: "Block-scoped variable '{0}' used before its declaration." }, - The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant: { code: 2449, category: DiagnosticCategory.Error, key: "The operand of an increment or decrement operator cannot be a constant." }, - Left_hand_side_of_assignment_expression_cannot_be_a_constant: { code: 2450, category: DiagnosticCategory.Error, key: "Left-hand side of assignment expression cannot be a constant." }, - Cannot_redeclare_constant_0: { code: 2451, category: DiagnosticCategory.Error, key: "Cannot redeclare constant '{0}'." }, + Block_scoped_variable_0_used_before_its_declaration: { code: 2448, category: DiagnosticCategory.Error, key: "Block-scoped variable '{0}' used before its declaration.", isEarly: true }, + The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant: { code: 2449, category: DiagnosticCategory.Error, key: "The operand of an increment or decrement operator cannot be a constant.", isEarly: true }, + Left_hand_side_of_assignment_expression_cannot_be_a_constant: { code: 2450, category: DiagnosticCategory.Error, key: "Left-hand side of assignment expression cannot be a constant.", isEarly: true }, + Cannot_redeclare_block_scoped_variable_0: { code: 2451, category: DiagnosticCategory.Error, key: "Cannot redeclare block-scoped variable '{0}'.", isEarly: true }, + An_enum_member_cannot_have_a_numeric_name: { code: 2452, category: DiagnosticCategory.Error, key: "An enum member cannot have a numeric name." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4001, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 0f7788eae6e..1336af21aaf 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -447,10 +447,6 @@ "category": "Error", "code": 1150 }, - "An enum member cannot have a numeric name.": { - "category": "Error", - "code": 1151 - }, "'var', 'let' or 'const' expected.": { "category": "Error", "code": 1152 @@ -1062,19 +1058,27 @@ }, "Block-scoped variable '{0}' used before its declaration.": { "category": "Error", - "code": 2448 + "code": 2448, + "isEarly": true }, "The operand of an increment or decrement operator cannot be a constant.": { "category": "Error", - "code": 2449 + "code": 2449, + "isEarly": true }, "Left-hand side of assignment expression cannot be a constant.": { "category": "Error", - "code": 2450 + "code": 2450, + "isEarly": true }, - "Cannot redeclare constant '{0}'.": { + "Cannot redeclare block-scoped variable '{0}'.": { "category": "Error", - "code": 2451 + "code": 2451, + "isEarly": true + }, + "An enum member cannot have a numeric name.": { + "category": "Error", + "code": 2452 }, "Import declaration '{0}' is using private name '{1}'.": { diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 5c85bfc1e6a..1517584e4c8 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3271,11 +3271,14 @@ module ts { } var hasSemanticErrors = resolver.hasSemanticErrors(); + var hasEarlyErrors = resolver.hasEarlyErrors(targetSourceFile); function emitFile(jsFilePath: string, sourceFile?: SourceFile) { - emitJavaScript(jsFilePath, sourceFile); - if (!hasSemanticErrors && compilerOptions.declaration) { - emitDeclarations(jsFilePath, sourceFile); + if (!hasEarlyErrors) { + emitJavaScript(jsFilePath, sourceFile); + if (!hasSemanticErrors && compilerOptions.declaration) { + emitDeclarations(jsFilePath, sourceFile); + } } } @@ -3315,7 +3318,9 @@ module ts { // Check and update returnCode for syntactic and semantic var returnCode: EmitReturnStatus; - if (hasEmitterError) { + if (hasEarlyErrors) { + returnCode = EmitReturnStatus.AllOutputGenerationSkipped; + } else if (hasEmitterError) { returnCode = EmitReturnStatus.EmitErrorsEncountered; } else if (hasSemanticErrors && compilerOptions.declaration) { returnCode = EmitReturnStatus.DeclarationGenerationSkipped; diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index c8cccd2da1c..1fab013a8a6 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -356,13 +356,18 @@ module ts { else { var checker = program.getTypeChecker(/*fullTypeCheckMode*/ true); var checkStart = new Date().getTime(); - var semanticErrors = checker.getDiagnostics(); - var emitStart = new Date().getTime(); - var emitOutput = checker.emitFiles(); - var emitErrors = emitOutput.errors; - exitStatus = emitOutput.emitResultStatus; - var reportStart = new Date().getTime(); - errors = concatenate(semanticErrors, emitErrors); + errors = checker.getDiagnostics(); + if (!checker.hasEarlyErrors()) { + var emitStart = new Date().getTime(); + var emitOutput = checker.emitFiles(); + var emitErrors = emitOutput.errors; + exitStatus = emitOutput.emitResultStatus; + var reportStart = new Date().getTime(); + errors = concatenate(errors, emitErrors); + } + else { + exitStatus = EmitReturnStatus.AllOutputGenerationSkipped; + } } reportDiagnostics(errors); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 10c9500671e..4ba895cfe1e 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -667,6 +667,7 @@ module ts { isImplementationOfOverload(node: FunctionDeclaration): boolean; isUndefinedSymbol(symbol: Symbol): boolean; isArgumentsSymbol(symbol: Symbol): boolean; + hasEarlyErrors(sourceFile?: SourceFile): boolean; // Returns the constant value of this enum member, or 'undefined' if the enum member has a // computed value. @@ -762,6 +763,7 @@ module ts { // Returns the constant value this property access resolves to, or 'undefined' if it does // resolve to a constant. getConstantValue(node: PropertyAccess): number; + hasEarlyErrors(sourceFile?: SourceFile): boolean; } export enum SymbolFlags { @@ -1041,6 +1043,7 @@ module ts { key: string; category: DiagnosticCategory; code: number; + isEarly?: boolean; } // A linked list of formatted diagnostic messages to be used as part of a multiline message. @@ -1061,6 +1064,7 @@ module ts { messageText: string; category: DiagnosticCategory; code: number; + isEarly?: boolean; } export enum DiagnosticCategory { diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 54a9a5184fe..60c5da5a1a6 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -801,9 +801,11 @@ module Harness { var checker = program.getTypeChecker(/*fullTypeCheckMode*/ true); checker.checkProgram(); + var hasEarlyErrors = checker.hasEarlyErrors(); + // only emit if there weren't parse errors var emitResult: ts.EmitResult; - if (!hadParseErrors) { + if (!hadParseErrors && !hasEarlyErrors) { emitResult = checker.emitFiles(); } diff --git a/tests/baselines/reference/constDeclarationShadowedByVarDeclaration.errors.txt b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration.errors.txt index 662628e0692..629cf7f75af 100644 --- a/tests/baselines/reference/constDeclarationShadowedByVarDeclaration.errors.txt +++ b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration.errors.txt @@ -1,6 +1,6 @@ -tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts(7,9): error TS2451: Cannot redeclare constant 'x'. -tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts(15,13): error TS2451: Cannot redeclare constant 'y'. -tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts(22,7): error TS2451: Cannot redeclare constant 'z'. +tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts(7,9): error TS2451: Cannot redeclare block-scoped variable 'x'. +tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts(15,13): error TS2451: Cannot redeclare block-scoped variable 'y'. +tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts(22,7): error TS2451: Cannot redeclare block-scoped variable 'z'. ==== tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts (3 errors) ==== @@ -12,7 +12,7 @@ tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts(22,7): error TS var x = 0; ~ -!!! error TS2451: Cannot redeclare constant 'x'. +!!! error TS2451: Cannot redeclare block-scoped variable 'x'. } @@ -22,7 +22,7 @@ tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts(22,7): error TS { var y = 0; ~ -!!! error TS2451: Cannot redeclare constant 'y'. +!!! error TS2451: Cannot redeclare block-scoped variable 'y'. } } @@ -31,5 +31,5 @@ tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts(22,7): error TS const z = 0; var z = 0 ~ -!!! error TS2451: Cannot redeclare constant 'z'. +!!! error TS2451: Cannot redeclare block-scoped variable 'z'. } \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarationShadowedByVarDeclaration.js b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration.js deleted file mode 100644 index 9fcc9f8f568..00000000000 --- a/tests/baselines/reference/constDeclarationShadowedByVarDeclaration.js +++ /dev/null @@ -1,43 +0,0 @@ -//// [constDeclarationShadowedByVarDeclaration.ts] - -// Error as declaration of var would cause a write to the const value -var x = 0; -{ - const x = 0; - - var x = 0; -} - - -var y = 0; -{ - const y = 0; - { - var y = 0; - } -} - - -{ - const z = 0; - var z = 0 -} - -//// [constDeclarationShadowedByVarDeclaration.js] -// Error as declaration of var would cause a write to the const value -var x = 0; -{ - const x = 0; - var x = 0; -} -var y = 0; -{ - const y = 0; - { - var y = 0; - } -} -{ - const z = 0; - var z = 0; -} diff --git a/tests/baselines/reference/constDeclarations-access.js b/tests/baselines/reference/constDeclarations-access.js deleted file mode 100644 index ba913f2d5fc..00000000000 --- a/tests/baselines/reference/constDeclarations-access.js +++ /dev/null @@ -1,13 +0,0 @@ -//// [tests/cases/compiler/constDeclarations-access.ts] //// - -//// [file1.ts] - -const x = 0 - -//// [file2.ts] -x++; - -//// [file1.js] -const x = 0; -//// [file2.js] -x++; diff --git a/tests/baselines/reference/constDeclarations-access2.js b/tests/baselines/reference/constDeclarations-access2.js deleted file mode 100644 index fd51c932636..00000000000 --- a/tests/baselines/reference/constDeclarations-access2.js +++ /dev/null @@ -1,74 +0,0 @@ -//// [constDeclarations-access2.ts] - -const x = 0 - -// Errors -x = 1; -x += 2; -x -= 3; -x *= 4; -x /= 5; -x %= 6; -x <<= 7; -x >>= 8; -x >>>= 9; -x &= 10; -x |= 11; -x ^= 12; - -x++; -x--; -++x; ---x; - -++((x)); - -// OK -var a = x + 1; - -function f(v: number) { } -f(x); - -if (x) { } - -x; -(x); - --x; -+x; - -x.toString(); - - -//// [constDeclarations-access2.js] -const x = 0; -// Errors -x = 1; -x += 2; -x -= 3; -x *= 4; -x /= 5; -x %= 6; -x <<= 7; -x >>= 8; -x >>>= 9; -x &= 10; -x |= 11; -x ^= 12; -x++; -x--; -++x; ---x; -++((x)); -// OK -var a = x + 1; -function f(v) { -} -f(x); -if (x) { -} -x; -(x); --x; -+x; -x.toString(); diff --git a/tests/baselines/reference/constDeclarations-access3.js b/tests/baselines/reference/constDeclarations-access3.js deleted file mode 100644 index 9ac4880bdd1..00000000000 --- a/tests/baselines/reference/constDeclarations-access3.js +++ /dev/null @@ -1,83 +0,0 @@ -//// [constDeclarations-access3.ts] - - -module M { - export const x = 0; -} - -// Errors -M.x = 1; -M.x += 2; -M.x -= 3; -M.x *= 4; -M.x /= 5; -M.x %= 6; -M.x <<= 7; -M.x >>= 8; -M.x >>>= 9; -M.x &= 10; -M.x |= 11; -M.x ^= 12; - -M.x++; -M.x--; -++M.x; ---M.x; - -++((M.x)); - -M["x"] = 0; - -// OK -var a = M.x + 1; - -function f(v: number) { } -f(M.x); - -if (M.x) { } - -M.x; -(M.x); - --M.x; -+M.x; - -M.x.toString(); - - -//// [constDeclarations-access3.js] -var M; -(function (M) { - M.x = 0; -})(M || (M = {})); -// Errors -M.x = 1; -M.x += 2; -M.x -= 3; -M.x *= 4; -M.x /= 5; -M.x %= 6; -M.x <<= 7; -M.x >>= 8; -M.x >>>= 9; -M.x &= 10; -M.x |= 11; -M.x ^= 12; -M.x++; -M.x--; -++M.x; ---M.x; -++((M.x)); -M["x"] = 0; -// OK -var a = M.x + 1; -function f(v) { -} -f(M.x); -if (M.x) { -} -M.x; -(M.x); --M.x; -+M.x; -M.x.toString(); diff --git a/tests/baselines/reference/constDeclarations-access4.js b/tests/baselines/reference/constDeclarations-access4.js deleted file mode 100644 index b226e746bba..00000000000 --- a/tests/baselines/reference/constDeclarations-access4.js +++ /dev/null @@ -1,79 +0,0 @@ -//// [constDeclarations-access4.ts] - - -declare module M { - const x: number; -} - -// Errors -M.x = 1; -M.x += 2; -M.x -= 3; -M.x *= 4; -M.x /= 5; -M.x %= 6; -M.x <<= 7; -M.x >>= 8; -M.x >>>= 9; -M.x &= 10; -M.x |= 11; -M.x ^= 12; - -M.x++; -M.x--; -++M.x; ---M.x; - -++((M.x)); - -M["x"] = 0; - -// OK -var a = M.x + 1; - -function f(v: number) { } -f(M.x); - -if (M.x) { } - -M.x; -(M.x); - --M.x; -+M.x; - -M.x.toString(); - - -//// [constDeclarations-access4.js] -// Errors -M.x = 1; -M.x += 2; -M.x -= 3; -M.x *= 4; -M.x /= 5; -M.x %= 6; -M.x <<= 7; -M.x >>= 8; -M.x >>>= 9; -M.x &= 10; -M.x |= 11; -M.x ^= 12; -M.x++; -M.x--; -++M.x; ---M.x; -++((M.x)); -M["x"] = 0; -// OK -var a = M.x + 1; -function f(v) { -} -f(M.x); -if (M.x) { -} -M.x; -(M.x); --M.x; -+M.x; -M.x.toString(); diff --git a/tests/baselines/reference/constDeclarations-access5.js b/tests/baselines/reference/constDeclarations-access5.js deleted file mode 100644 index 7acc95ad055..00000000000 --- a/tests/baselines/reference/constDeclarations-access5.js +++ /dev/null @@ -1,89 +0,0 @@ -//// [tests/cases/compiler/constDeclarations-access5.ts] //// - -//// [constDeclarations_access_1.ts] - - -export const x = 0; - -//// [constDeclarations_access_2.ts] -/// -import m = require('constDeclarations_access_1'); -// Errors -m.x = 1; -m.x += 2; -m.x -= 3; -m.x *= 4; -m.x /= 5; -m.x %= 6; -m.x <<= 7; -m.x >>= 8; -m.x >>>= 9; -m.x &= 10; -m.x |= 11; -m.x ^= 12; -m -m.x++; -m.x--; -++m.x; ---m.x; - -++((m.x)); - -m["x"] = 0; - -// OK -var a = m.x + 1; - -function f(v: number) { } -f(m.x); - -if (m.x) { } - -m.x; -(m.x); - --m.x; -+m.x; - -m.x.toString(); - - -//// [constDeclarations_access_1.js] -define(["require", "exports"], function (require, exports) { - exports.x = 0; -}); -//// [constDeclarations_access_2.js] -define(["require", "exports", 'constDeclarations_access_1'], function (require, exports, m) { - // Errors - m.x = 1; - m.x += 2; - m.x -= 3; - m.x *= 4; - m.x /= 5; - m.x %= 6; - m.x <<= 7; - m.x >>= 8; - m.x >>>= 9; - m.x &= 10; - m.x |= 11; - m.x ^= 12; - m; - m.x++; - m.x--; - ++m.x; - --m.x; - ++((m.x)); - m["x"] = 0; - // OK - var a = m.x + 1; - function f(v) { - } - f(m.x); - if (m.x) { - } - m.x; - (m.x); - -m.x; - +m.x; - m.x.toString(); -}); diff --git a/tests/baselines/reference/constDeclarations-useBeforeDefinition.js b/tests/baselines/reference/constDeclarations-useBeforeDefinition.js deleted file mode 100644 index 4fe0e64f275..00000000000 --- a/tests/baselines/reference/constDeclarations-useBeforeDefinition.js +++ /dev/null @@ -1,24 +0,0 @@ -//// [constDeclarations-useBeforeDefinition.ts] - -{ - c1; - const c1 = 0; -} - -var v1; -{ - v1; - const v1 = 0; -} - - -//// [constDeclarations-useBeforeDefinition.js] -{ - c1; - const c1 = 0; -} -var v1; -{ - v1; - const v1 = 0; -} diff --git a/tests/baselines/reference/constDeclarations-useBeforeDefinition2.js b/tests/baselines/reference/constDeclarations-useBeforeDefinition2.js deleted file mode 100644 index 7d1f4cf5725..00000000000 --- a/tests/baselines/reference/constDeclarations-useBeforeDefinition2.js +++ /dev/null @@ -1,12 +0,0 @@ -//// [tests/cases/compiler/constDeclarations-useBeforeDefinition2.ts] //// - -//// [file1.ts] - -c; - -//// [file2.ts] -const c = 0; - -//// [out.js] -c; -const c = 0; diff --git a/tests/baselines/reference/enumIdentifierLiterals.errors.txt b/tests/baselines/reference/enumIdentifierLiterals.errors.txt index 60d8ed81f84..dbf8734ea73 100644 --- a/tests/baselines/reference/enumIdentifierLiterals.errors.txt +++ b/tests/baselines/reference/enumIdentifierLiterals.errors.txt @@ -1,22 +1,22 @@ -tests/cases/compiler/enumIdentifierLiterals.ts(2,5): error TS1151: An enum member cannot have a numeric name. -tests/cases/compiler/enumIdentifierLiterals.ts(3,5): error TS1151: An enum member cannot have a numeric name. -tests/cases/compiler/enumIdentifierLiterals.ts(4,5): error TS1151: An enum member cannot have a numeric name. -tests/cases/compiler/enumIdentifierLiterals.ts(6,5): error TS1151: An enum member cannot have a numeric name. +tests/cases/compiler/enumIdentifierLiterals.ts(2,5): error TS2452: An enum member cannot have a numeric name. +tests/cases/compiler/enumIdentifierLiterals.ts(3,5): error TS2452: An enum member cannot have a numeric name. +tests/cases/compiler/enumIdentifierLiterals.ts(4,5): error TS2452: An enum member cannot have a numeric name. +tests/cases/compiler/enumIdentifierLiterals.ts(6,5): error TS2452: An enum member cannot have a numeric name. ==== tests/cases/compiler/enumIdentifierLiterals.ts (4 errors) ==== enum Nums { 1.0, ~~~ -!!! error TS1151: An enum member cannot have a numeric name. +!!! error TS2452: An enum member cannot have a numeric name. 11e-1, ~~~~~ -!!! error TS1151: An enum member cannot have a numeric name. +!!! error TS2452: An enum member cannot have a numeric name. 0.12e1, ~~~~~~ -!!! error TS1151: An enum member cannot have a numeric name. +!!! error TS2452: An enum member cannot have a numeric name. "13e-1", 0xF00D ~~~~~~ -!!! error TS1151: An enum member cannot have a numeric name. +!!! error TS2452: An enum member cannot have a numeric name. } \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates.errors.txt index 41d2813f7c4..b3b620a4c9e 100644 --- a/tests/baselines/reference/letDeclarations-scopes-duplicates.errors.txt +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates.errors.txt @@ -1,27 +1,27 @@ -tests/cases/compiler/letDeclarations-scopes-duplicates.ts(3,5): error TS2300: Duplicate identifier 'var1'. -tests/cases/compiler/letDeclarations-scopes-duplicates.ts(4,5): error TS2300: Duplicate identifier 'var1'. -tests/cases/compiler/letDeclarations-scopes-duplicates.ts(6,5): error TS2300: Duplicate identifier 'var2'. -tests/cases/compiler/letDeclarations-scopes-duplicates.ts(7,7): error TS2300: Duplicate identifier 'var2'. -tests/cases/compiler/letDeclarations-scopes-duplicates.ts(9,7): error TS2300: Duplicate identifier 'var3'. -tests/cases/compiler/letDeclarations-scopes-duplicates.ts(10,5): error TS2300: Duplicate identifier 'var3'. -tests/cases/compiler/letDeclarations-scopes-duplicates.ts(12,7): error TS2300: Duplicate identifier 'var4'. -tests/cases/compiler/letDeclarations-scopes-duplicates.ts(13,7): error TS2300: Duplicate identifier 'var4'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(3,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(4,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(6,5): error TS2451: Cannot redeclare block-scoped variable 'var2'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(7,7): error TS2451: Cannot redeclare block-scoped variable 'var2'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(9,7): error TS2451: Cannot redeclare block-scoped variable 'var3'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(10,5): error TS2451: Cannot redeclare block-scoped variable 'var3'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(12,7): error TS2451: Cannot redeclare block-scoped variable 'var4'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(13,7): error TS2451: Cannot redeclare block-scoped variable 'var4'. tests/cases/compiler/letDeclarations-scopes-duplicates.ts(15,5): error TS2300: Duplicate identifier 'var5'. tests/cases/compiler/letDeclarations-scopes-duplicates.ts(16,5): error TS2300: Duplicate identifier 'var5'. -tests/cases/compiler/letDeclarations-scopes-duplicates.ts(18,5): error TS2300: Duplicate identifier 'var6'. -tests/cases/compiler/letDeclarations-scopes-duplicates.ts(19,5): error TS2300: Duplicate identifier 'var6'. -tests/cases/compiler/letDeclarations-scopes-duplicates.ts(22,9): error TS2300: Duplicate identifier 'var7'. -tests/cases/compiler/letDeclarations-scopes-duplicates.ts(23,9): error TS2300: Duplicate identifier 'var7'. -tests/cases/compiler/letDeclarations-scopes-duplicates.ts(25,13): error TS2300: Duplicate identifier 'var8'. -tests/cases/compiler/letDeclarations-scopes-duplicates.ts(26,15): error TS2300: Duplicate identifier 'var8'. -tests/cases/compiler/letDeclarations-scopes-duplicates.ts(32,13): error TS2300: Duplicate identifier 'var9'. -tests/cases/compiler/letDeclarations-scopes-duplicates.ts(33,13): error TS2300: Duplicate identifier 'var9'. -tests/cases/compiler/letDeclarations-scopes-duplicates.ts(37,11): error TS2300: Duplicate identifier 'var10'. -tests/cases/compiler/letDeclarations-scopes-duplicates.ts(38,11): error TS2300: Duplicate identifier 'var10'. -tests/cases/compiler/letDeclarations-scopes-duplicates.ts(41,9): error TS2300: Duplicate identifier 'var11'. -tests/cases/compiler/letDeclarations-scopes-duplicates.ts(42,9): error TS2300: Duplicate identifier 'var11'. -tests/cases/compiler/letDeclarations-scopes-duplicates.ts(46,9): error TS2300: Duplicate identifier 'var12'. -tests/cases/compiler/letDeclarations-scopes-duplicates.ts(47,9): error TS2300: Duplicate identifier 'var12'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(18,5): error TS2451: Cannot redeclare block-scoped variable 'var6'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(19,5): error TS2451: Cannot redeclare block-scoped variable 'var6'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(22,9): error TS2451: Cannot redeclare block-scoped variable 'var7'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(23,9): error TS2451: Cannot redeclare block-scoped variable 'var7'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(25,13): error TS2451: Cannot redeclare block-scoped variable 'var8'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(26,15): error TS2451: Cannot redeclare block-scoped variable 'var8'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(32,13): error TS2451: Cannot redeclare block-scoped variable 'var9'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(33,13): error TS2451: Cannot redeclare block-scoped variable 'var9'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(37,11): error TS2451: Cannot redeclare block-scoped variable 'var10'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(38,11): error TS2451: Cannot redeclare block-scoped variable 'var10'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(41,9): error TS2451: Cannot redeclare block-scoped variable 'var11'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(42,9): error TS2451: Cannot redeclare block-scoped variable 'var11'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(46,9): error TS2451: Cannot redeclare block-scoped variable 'var12'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(47,9): error TS2451: Cannot redeclare block-scoped variable 'var12'. ==== tests/cases/compiler/letDeclarations-scopes-duplicates.ts (24 errors) ==== @@ -29,31 +29,31 @@ tests/cases/compiler/letDeclarations-scopes-duplicates.ts(47,9): error TS2300: D // Errors: redeclaration let var1 = 0; ~~~~ -!!! error TS2300: Duplicate identifier 'var1'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. let var1 = 0; // error ~~~~ -!!! error TS2300: Duplicate identifier 'var1'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. let var2 = 0; ~~~~ -!!! error TS2300: Duplicate identifier 'var2'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var2'. const var2 = 0; ~~~~ -!!! error TS2300: Duplicate identifier 'var2'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var2'. const var3 = 0; ~~~~ -!!! error TS2300: Duplicate identifier 'var3'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var3'. let var3 = 0; ~~~~ -!!! error TS2300: Duplicate identifier 'var3'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var3'. const var4 = 0; ~~~~ -!!! error TS2300: Duplicate identifier 'var4'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var4'. const var4 = 0; ~~~~ -!!! error TS2300: Duplicate identifier 'var4'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var4'. var var5 = 0; ~~~~ @@ -64,25 +64,25 @@ tests/cases/compiler/letDeclarations-scopes-duplicates.ts(47,9): error TS2300: D let var6 = 0; ~~~~ -!!! error TS2300: Duplicate identifier 'var6'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var6'. var var6 = 0; ~~~~ -!!! error TS2300: Duplicate identifier 'var6'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var6'. { let var7 = 0; ~~~~ -!!! error TS2300: Duplicate identifier 'var7'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var7'. let var7 = 0; ~~~~ -!!! error TS2300: Duplicate identifier 'var7'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var7'. { let var8 = 0; ~~~~ -!!! error TS2300: Duplicate identifier 'var8'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var8'. const var8 = 0; ~~~~ -!!! error TS2300: Duplicate identifier 'var8'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var8'. } } @@ -90,36 +90,36 @@ tests/cases/compiler/letDeclarations-scopes-duplicates.ts(47,9): error TS2300: D default: let var9 = 0; ~~~~ -!!! error TS2300: Duplicate identifier 'var9'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var9'. let var9 = 0; ~~~~ -!!! error TS2300: Duplicate identifier 'var9'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var9'. } try { const var10 = 0; ~~~~~ -!!! error TS2300: Duplicate identifier 'var10'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var10'. const var10 = 0; ~~~~~ -!!! error TS2300: Duplicate identifier 'var10'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var10'. } catch (e) { let var11 = 0; ~~~~~ -!!! error TS2300: Duplicate identifier 'var11'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var11'. let var11 = 0; ~~~~~ -!!! error TS2300: Duplicate identifier 'var11'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var11'. } function F1() { let var12; ~~~~~ -!!! error TS2300: Duplicate identifier 'var12'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var12'. let var12; ~~~~~ -!!! error TS2300: Duplicate identifier 'var12'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var12'. } // OK diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates.js b/tests/baselines/reference/letDeclarations-scopes-duplicates.js deleted file mode 100644 index c7d2ef9863a..00000000000 --- a/tests/baselines/reference/letDeclarations-scopes-duplicates.js +++ /dev/null @@ -1,140 +0,0 @@ -//// [letDeclarations-scopes-duplicates.ts] - -// Errors: redeclaration -let var1 = 0; -let var1 = 0; // error - -let var2 = 0; -const var2 = 0; - -const var3 = 0; -let var3 = 0; - -const var4 = 0; -const var4 = 0; - -var var5 = 0; -let var5 = 0; - -let var6 = 0; -var var6 = 0; - -{ - let var7 = 0; - let var7 = 0; - { - let var8 = 0; - const var8 = 0; - } -} - -switch (0) { - default: - let var9 = 0; - let var9 = 0; -} - -try { - const var10 = 0; - const var10 = 0; -} -catch (e) { - let var11 = 0; - let var11 = 0; -} - -function F1() { - let var12; - let var12; -} - -// OK -var var20 = 0; - -var var20 = 0 -{ - let var20 = 0; - { - let var20 = 0; - } -} - -switch (0) { - default: - let var20 = 0; -} - -try { - let var20 = 0; -} -catch (e) { - let var20 = 0; -} - -function F() { - let var20; -} - - - -//// [letDeclarations-scopes-duplicates.js] -// Errors: redeclaration -let var1 = 0; -let var1 = 0; // error -let var2 = 0; -const var2 = 0; -const var3 = 0; -let var3 = 0; -const var4 = 0; -const var4 = 0; -var var5 = 0; -let var5 = 0; -let var6 = 0; -var var6 = 0; -{ - let var7 = 0; - let var7 = 0; - { - let var8 = 0; - const var8 = 0; - } -} -switch (0) { - default: - let var9 = 0; - let var9 = 0; -} -try { - const var10 = 0; - const var10 = 0; -} -catch (e) { - let var11 = 0; - let var11 = 0; -} -function F1() { - let var12; - let var12; -} -// OK -var var20 = 0; -var var20 = 0; -{ - let var20 = 0; - { - let var20 = 0; - } -} -switch (0) { - default: - let var20 = 0; -} -try { - let var20 = 0; -} -catch (e) { - let var20 = 0; -} -function F() { - let var20; -} diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates2.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates2.errors.txt index b948b1b7a14..72b8b5609b6 100644 --- a/tests/baselines/reference/letDeclarations-scopes-duplicates2.errors.txt +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates2.errors.txt @@ -1,14 +1,14 @@ -tests/cases/compiler/file1.ts(2,5): error TS2300: Duplicate identifier 'var1'. -tests/cases/compiler/file2.ts(1,5): error TS2300: Duplicate identifier 'var1'. +tests/cases/compiler/file1.ts(2,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. +tests/cases/compiler/file2.ts(1,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. ==== tests/cases/compiler/file1.ts (1 errors) ==== let var1 = 0; ~~~~ -!!! error TS2300: Duplicate identifier 'var1'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. ==== tests/cases/compiler/file2.ts (1 errors) ==== let var1 = 0; ~~~~ -!!! error TS2300: Duplicate identifier 'var1'. \ No newline at end of file +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates2.js b/tests/baselines/reference/letDeclarations-scopes-duplicates2.js deleted file mode 100644 index 9b35bd81c76..00000000000 --- a/tests/baselines/reference/letDeclarations-scopes-duplicates2.js +++ /dev/null @@ -1,13 +0,0 @@ -//// [tests/cases/compiler/letDeclarations-scopes-duplicates2.ts] //// - -//// [file1.ts] - -let var1 = 0; - -//// [file2.ts] -let var1 = 0; - -//// [file1.js] -let var1 = 0; -//// [file2.js] -let var1 = 0; diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates3.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates3.errors.txt index 7222fb9bf22..6ed2fb66195 100644 --- a/tests/baselines/reference/letDeclarations-scopes-duplicates3.errors.txt +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates3.errors.txt @@ -1,14 +1,14 @@ -tests/cases/compiler/file1.ts(2,5): error TS2300: Duplicate identifier 'var1'. -tests/cases/compiler/file2.ts(1,7): error TS2300: Duplicate identifier 'var1'. +tests/cases/compiler/file1.ts(2,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. +tests/cases/compiler/file2.ts(1,7): error TS2451: Cannot redeclare block-scoped variable 'var1'. ==== tests/cases/compiler/file1.ts (1 errors) ==== let var1 = 0; ~~~~ -!!! error TS2300: Duplicate identifier 'var1'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. ==== tests/cases/compiler/file2.ts (1 errors) ==== const var1 = 0; ~~~~ -!!! error TS2300: Duplicate identifier 'var1'. \ No newline at end of file +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates3.js b/tests/baselines/reference/letDeclarations-scopes-duplicates3.js deleted file mode 100644 index e74caf37219..00000000000 --- a/tests/baselines/reference/letDeclarations-scopes-duplicates3.js +++ /dev/null @@ -1,13 +0,0 @@ -//// [tests/cases/compiler/letDeclarations-scopes-duplicates3.ts] //// - -//// [file1.ts] - -let var1 = 0; - -//// [file2.ts] -const var1 = 0; - -//// [file1.js] -let var1 = 0; -//// [file2.js] -const var1 = 0; diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates4.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates4.errors.txt index e626af7e52a..ec87809b0cd 100644 --- a/tests/baselines/reference/letDeclarations-scopes-duplicates4.errors.txt +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates4.errors.txt @@ -1,14 +1,14 @@ -tests/cases/compiler/file1.ts(2,7): error TS2300: Duplicate identifier 'var1'. -tests/cases/compiler/file2.ts(1,5): error TS2300: Duplicate identifier 'var1'. +tests/cases/compiler/file1.ts(2,7): error TS2451: Cannot redeclare block-scoped variable 'var1'. +tests/cases/compiler/file2.ts(1,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. ==== tests/cases/compiler/file1.ts (1 errors) ==== const var1 = 0; ~~~~ -!!! error TS2300: Duplicate identifier 'var1'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. ==== tests/cases/compiler/file2.ts (1 errors) ==== let var1 = 0; ~~~~ -!!! error TS2300: Duplicate identifier 'var1'. \ No newline at end of file +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates4.js b/tests/baselines/reference/letDeclarations-scopes-duplicates4.js deleted file mode 100644 index ac338e31c72..00000000000 --- a/tests/baselines/reference/letDeclarations-scopes-duplicates4.js +++ /dev/null @@ -1,13 +0,0 @@ -//// [tests/cases/compiler/letDeclarations-scopes-duplicates4.ts] //// - -//// [file1.ts] - -const var1 = 0; - -//// [file2.ts] -let var1 = 0; - -//// [file1.js] -const var1 = 0; -//// [file2.js] -let var1 = 0; diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates5.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates5.errors.txt index ac5f79dd5a8..ce3a9da598a 100644 --- a/tests/baselines/reference/letDeclarations-scopes-duplicates5.errors.txt +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates5.errors.txt @@ -1,14 +1,14 @@ -tests/cases/compiler/file1.ts(2,7): error TS2300: Duplicate identifier 'var1'. -tests/cases/compiler/file2.ts(1,7): error TS2300: Duplicate identifier 'var1'. +tests/cases/compiler/file1.ts(2,7): error TS2451: Cannot redeclare block-scoped variable 'var1'. +tests/cases/compiler/file2.ts(1,7): error TS2451: Cannot redeclare block-scoped variable 'var1'. ==== tests/cases/compiler/file1.ts (1 errors) ==== const var1 = 0; ~~~~ -!!! error TS2300: Duplicate identifier 'var1'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. ==== tests/cases/compiler/file2.ts (1 errors) ==== const var1 = 0; ~~~~ -!!! error TS2300: Duplicate identifier 'var1'. \ No newline at end of file +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates5.js b/tests/baselines/reference/letDeclarations-scopes-duplicates5.js deleted file mode 100644 index 2424c91ab90..00000000000 --- a/tests/baselines/reference/letDeclarations-scopes-duplicates5.js +++ /dev/null @@ -1,13 +0,0 @@ -//// [tests/cases/compiler/letDeclarations-scopes-duplicates5.ts] //// - -//// [file1.ts] - -const var1 = 0; - -//// [file2.ts] -const var1 = 0; - -//// [file1.js] -const var1 = 0; -//// [file2.js] -const var1 = 0; diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates6.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates6.errors.txt index 0d3a4726bd3..d09eda28075 100644 --- a/tests/baselines/reference/letDeclarations-scopes-duplicates6.errors.txt +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates6.errors.txt @@ -1,14 +1,14 @@ -tests/cases/compiler/file1.ts(2,5): error TS2300: Duplicate identifier 'var1'. -tests/cases/compiler/file2.ts(1,5): error TS2300: Duplicate identifier 'var1'. +tests/cases/compiler/file1.ts(2,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. +tests/cases/compiler/file2.ts(1,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. ==== tests/cases/compiler/file1.ts (1 errors) ==== var var1 = 0; ~~~~ -!!! error TS2300: Duplicate identifier 'var1'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. ==== tests/cases/compiler/file2.ts (1 errors) ==== let var1 = 0; ~~~~ -!!! error TS2300: Duplicate identifier 'var1'. \ No newline at end of file +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates6.js b/tests/baselines/reference/letDeclarations-scopes-duplicates6.js deleted file mode 100644 index 24edc0b7bde..00000000000 --- a/tests/baselines/reference/letDeclarations-scopes-duplicates6.js +++ /dev/null @@ -1,13 +0,0 @@ -//// [tests/cases/compiler/letDeclarations-scopes-duplicates6.ts] //// - -//// [file1.ts] - -var var1 = 0; - -//// [file2.ts] -let var1 = 0; - -//// [file1.js] -var var1 = 0; -//// [file2.js] -let var1 = 0; diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates7.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates7.errors.txt index dafbae97080..dad85f9f819 100644 --- a/tests/baselines/reference/letDeclarations-scopes-duplicates7.errors.txt +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates7.errors.txt @@ -1,14 +1,14 @@ -tests/cases/compiler/file1.ts(2,5): error TS2300: Duplicate identifier 'var1'. -tests/cases/compiler/file2.ts(1,5): error TS2300: Duplicate identifier 'var1'. +tests/cases/compiler/file1.ts(2,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. +tests/cases/compiler/file2.ts(1,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. ==== tests/cases/compiler/file1.ts (1 errors) ==== let var1 = 0; ~~~~ -!!! error TS2300: Duplicate identifier 'var1'. +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. ==== tests/cases/compiler/file2.ts (1 errors) ==== var var1 = 0; ~~~~ -!!! error TS2300: Duplicate identifier 'var1'. \ No newline at end of file +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates7.js b/tests/baselines/reference/letDeclarations-scopes-duplicates7.js deleted file mode 100644 index 4cbc359e2c2..00000000000 --- a/tests/baselines/reference/letDeclarations-scopes-duplicates7.js +++ /dev/null @@ -1,13 +0,0 @@ -//// [tests/cases/compiler/letDeclarations-scopes-duplicates7.ts] //// - -//// [file1.ts] - -let var1 = 0; - -//// [file2.ts] -var var1 = 0; - -//// [file1.js] -let var1 = 0; -//// [file2.js] -var var1 = 0; diff --git a/tests/baselines/reference/letDeclarations-useBeforeDefinition.js b/tests/baselines/reference/letDeclarations-useBeforeDefinition.js deleted file mode 100644 index be1f9a127f4..00000000000 --- a/tests/baselines/reference/letDeclarations-useBeforeDefinition.js +++ /dev/null @@ -1,24 +0,0 @@ -//// [letDeclarations-useBeforeDefinition.ts] - -{ - l1; - let l1; -} - -var v1; -{ - v1; - let v1 = 0; -} - - -//// [letDeclarations-useBeforeDefinition.js] -{ - l1; - let l1; -} -var v1; -{ - v1; - let v1 = 0; -} diff --git a/tests/baselines/reference/letDeclarations-useBeforeDefinition2.js b/tests/baselines/reference/letDeclarations-useBeforeDefinition2.js deleted file mode 100644 index 35560edd1c8..00000000000 --- a/tests/baselines/reference/letDeclarations-useBeforeDefinition2.js +++ /dev/null @@ -1,12 +0,0 @@ -//// [tests/cases/compiler/letDeclarations-useBeforeDefinition2.ts] //// - -//// [file1.ts] - -l; - -//// [file2.ts] -const l = 0; - -//// [out.js] -l; -const l = 0; diff --git a/tests/baselines/reference/parserEnum5.errors.txt b/tests/baselines/reference/parserEnum5.errors.txt index 40c2c933955..b98fdfbfba5 100644 --- a/tests/baselines/reference/parserEnum5.errors.txt +++ b/tests/baselines/reference/parserEnum5.errors.txt @@ -1,9 +1,9 @@ tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(2,12): error TS1005: ',' expected. tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(3,15): error TS1005: ',' expected. tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(3,24): error TS1005: ',' expected. -tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(2,14): error TS1151: An enum member cannot have a numeric name. -tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(3,17): error TS1151: An enum member cannot have a numeric name. -tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(3,26): error TS1151: An enum member cannot have a numeric name. +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(2,14): error TS2452: An enum member cannot have a numeric name. +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(3,17): error TS2452: An enum member cannot have a numeric name. +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(3,26): error TS2452: An enum member cannot have a numeric name. ==== tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts (6 errors) ==== @@ -12,13 +12,13 @@ tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(3,26) ~ !!! error TS1005: ',' expected. ~ -!!! error TS1151: An enum member cannot have a numeric name. +!!! error TS2452: An enum member cannot have a numeric name. enum E1 { a, b: 1, c, d: 2 = 3 } ~ !!! error TS1005: ',' expected. ~ !!! error TS1005: ',' expected. ~ -!!! error TS1151: An enum member cannot have a numeric name. +!!! error TS2452: An enum member cannot have a numeric name. ~ -!!! error TS1151: An enum member cannot have a numeric name. \ No newline at end of file +!!! error TS2452: An enum member cannot have a numeric name. \ No newline at end of file diff --git a/tests/baselines/reference/parserEnum7.errors.txt b/tests/baselines/reference/parserEnum7.errors.txt index a4a2326546a..1a7f26df8db 100644 --- a/tests/baselines/reference/parserEnum7.errors.txt +++ b/tests/baselines/reference/parserEnum7.errors.txt @@ -1,15 +1,15 @@ -tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts(2,3): error TS1151: An enum member cannot have a numeric name. -tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts(2,6): error TS1151: An enum member cannot have a numeric name. -tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts(2,9): error TS1151: An enum member cannot have a numeric name. +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts(2,3): error TS2452: An enum member cannot have a numeric name. +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts(2,6): error TS2452: An enum member cannot have a numeric name. +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts(2,9): error TS2452: An enum member cannot have a numeric name. ==== tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts (3 errors) ==== enum E { 1, 2, 3 ~ -!!! error TS1151: An enum member cannot have a numeric name. +!!! error TS2452: An enum member cannot have a numeric name. ~ -!!! error TS1151: An enum member cannot have a numeric name. +!!! error TS2452: An enum member cannot have a numeric name. ~ -!!! error TS1151: An enum member cannot have a numeric name. +!!! error TS2452: An enum member cannot have a numeric name. } \ No newline at end of file From 373dc760bf78c78f6e2752e35e7e0f8f679019de Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 20 Oct 2014 17:41:16 -0700 Subject: [PATCH 24/63] respond to code review comments --- src/compiler/checker.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ca250fb7e53..b56d8e6434d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -333,8 +333,10 @@ module ts { Debug.assert(declaration, "Block-scoped variable declaration is undefined"); var declarationSourceFile = getSourceFileOfNode(declaration); var referenceSourceFile = getSourceFileOfNode(errorLocation); - if (declarationSourceFile === referenceSourceFile && declaration.pos > errorLocation.pos) { - error(errorLocation, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, identifierToString(declaration.name)); + if (declarationSourceFile === referenceSourceFile) { + if (declaration.pos > errorLocation.pos) { + error(errorLocation, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, identifierToString(declaration.name)); + } } else if (compilerOptions.out) { var sourceFiles = program.getSourceFiles(); From 06d29a00f2124e727627d4397ae2ea4a378475d2 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 17 Oct 2014 15:39:31 -0700 Subject: [PATCH 25/63] Breakpoint span in variable declarations in new language service Also updates the fourslash breakpoints baseline to be more readable --- Jakefile | 1 + src/harness/fourslash.ts | 80 ++++++++++++++--- src/services/breakpoints.ts | 89 +++++++++++++++++++ src/services/services.ts | 4 +- .../reference/bpSpan_variables.baseline | 23 +++++ .../breakpointValidationVariables.ts | 0 6 files changed, 183 insertions(+), 14 deletions(-) create mode 100644 tests/baselines/reference/bpSpan_variables.baseline rename tests/cases/{fourslash_old => fourslash}/breakpointValidationVariables.ts (100%) diff --git a/Jakefile b/Jakefile index 34879a56691..64394c2d60e 100644 --- a/Jakefile +++ b/Jakefile @@ -55,6 +55,7 @@ var servicesSources = [ ].map(function (f) { return path.join(compilerDirectory, f); }).concat([ + "breakpoints.ts", "services.ts", "shims.ts", "signatureHelp.ts", diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 9dad3dddf60..ba7c6115812 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -985,13 +985,23 @@ module FourSlash { return item.parameters[currentParam]; } - public getBreakpointStatementLocation(pos: number) { + private alignmentForExtraInfo = 50; + + public getBreakpointStatementLocation(pos: number, prefixString: string) { this.taoInvalidReason = 'getBreakpointStatementLocation NYI'; var spanInfo = this.languageService.getBreakpointStatementAtPosition(this.activeFile.fileName, pos); - var resultString = "\n**Pos: " + pos + " SpanInfo: " + JSON.stringify(spanInfo) + "\n** Statement: "; - if (spanInfo !== null) { - resultString = resultString + this.activeFile.content.substr(spanInfo.start(), spanInfo.length()); + var resultString = "SpanInfo: " + JSON.stringify(spanInfo); + if (spanInfo) { + var spanString = this.activeFile.content.substr(spanInfo.start(), spanInfo.length()); + var spanLineMap = ts.getLineStarts(spanString); + for (var i = 0; i < spanLineMap.length; i++) { + if (!i) { + resultString += "\n"; + } + resultString += prefixString + spanString.substring(spanLineMap[i], spanLineMap[i + 1]); + } + resultString += "\n" + prefixString + ":=> (" + this.getLineColStringAtPosition(spanInfo.start()) + ") to (" + this.getLineColStringAtPosition(spanInfo.end()) + ")"; } return resultString; } @@ -1003,12 +1013,60 @@ module FourSlash { "Breakpoint Locations for " + this.activeFile.fileName, this.testData.globalOptions[testOptMetadataNames.baselineFile], () => { - var fileLength = this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName).getLength(); + var fileLineMap = ts.getLineStarts(this.activeFile.content); + var nextLine = 0; var resultString = ""; - for (var pos = 0; pos < fileLength; pos++) { - resultString = resultString + this.getBreakpointStatementLocation(pos); + var currentLine: string; + var previousSpanInfo: string; + var startColumn: number; + var length: number; + var prefixString = " >"; + + var addSpanInfoString = () => { + if (previousSpanInfo) { + resultString += currentLine; + var thisLineMarker = repeatString(startColumn, " ") + repeatString(length, "~"); + thisLineMarker += repeatString(this.alignmentForExtraInfo - thisLineMarker.length - prefixString.length + 1, " "); + resultString += thisLineMarker; + resultString += "=> Pos: (" + (pos - length) + " to " + (pos - 1) + ") "; + resultString += " " + previousSpanInfo; + previousSpanInfo = undefined; + } + }; + + for (var pos = 0; pos < this.activeFile.content.length; pos++) { + if (pos === 0 || pos === fileLineMap[nextLine]) { + nextLine++; + addSpanInfoString(); + if (resultString.length) { + resultString += "\n--------------------------------"; + } + currentLine = "\n" + nextLine.toString() + repeatString(3 - nextLine.toString().length, " ") + ">" + this.activeFile.content.substring(pos, fileLineMap[nextLine]) + "\n "; + startColumn = 0; + length = 0; + } + var spanInfo = this.getBreakpointStatementLocation(pos, prefixString); + if (previousSpanInfo && previousSpanInfo !== spanInfo) { + addSpanInfoString(); + previousSpanInfo = spanInfo; + startColumn = startColumn + length; + length = 1; + } + else { + previousSpanInfo = spanInfo; + length++; + } } + addSpanInfoString(); return resultString; + + function repeatString(count: number, char: string) { + var result = ""; + for (var i = 0; i < count; i++) { + result += char; + } + return result; + } }, true /* run immediately */); } @@ -1056,7 +1114,7 @@ module FourSlash { } public printBreakpointLocation(pos: number) { - Harness.IO.log(this.getBreakpointStatementLocation(pos)); + Harness.IO.log("\n**Pos: " + pos + " " + this.getBreakpointStatementLocation(pos, " ")); } public printBreakpointAtCurrentLocation() { @@ -1502,7 +1560,7 @@ module FourSlash { throw new Error('verifyCaretAtMarker failed - expected to be in file "' + pos.fileName + '", but was in file "' + this.activeFile.fileName + '"'); } if (pos.position !== this.currentCaretPosition) { - throw new Error('verifyCaretAtMarker failed - expected to be at marker "/*' + markerName + '*/, but was at position ' + this.currentCaretPosition + '(' + this.getLineColStringAtCaret() + ')'); + throw new Error('verifyCaretAtMarker failed - expected to be at marker "/*' + markerName + '*/, but was at position ' + this.currentCaretPosition + '(' + this.getLineColStringAtPosition(this.currentCaretPosition) + ')'); } } @@ -2102,8 +2160,8 @@ module FourSlash { return this.languageServiceShimHost.positionToZeroBasedLineCol(this.activeFile.fileName, this.currentCaretPosition).line + 1; } - private getLineColStringAtCaret() { - var pos = this.languageServiceShimHost.positionToZeroBasedLineCol(this.activeFile.fileName, this.currentCaretPosition); + private getLineColStringAtPosition(position: number) { + var pos = this.languageServiceShimHost.positionToZeroBasedLineCol(this.activeFile.fileName, position); return 'line ' + (pos.line + 1) + ', col ' + pos.character; } diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 923458c144d..7eb44213e02 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -1082,4 +1082,93 @@ module TypeScript.Services.Breakpoints { var breakpointResolver = new BreakpointResolver(posLine, lineMap); return breakpointResolver.breakpointSpanOf(positionedToken); } +} + +module ts.Breakpoints { + /** + * Get the breakpoint span in given sourceFile + */ + export function spanInSourceFileAtLocation(sourceFile: SourceFile, position: number) { + // Cannot set breakpoint in dts file + if (sourceFile.flags & NodeFlags.DeclarationFile) { + return; + } + + var tokenAtLocation = getTokenAtPosition(sourceFile, position); + var lineOfPosition = sourceFile.getLineAndCharacterFromPosition(position).line; + if (sourceFile.getLineAndCharacterFromPosition(tokenAtLocation.getStart()).line > lineOfPosition) { + // Get previous token if the token is returned starts on new line + // eg: var x =10; |--- curser is here + // var y = 10; + // token at position will return var keyword on second line as the token but we would like to use + // token on same line if trailing trivia (comments or white spaces on same line) part of the last token on that line + tokenAtLocation = findPrecedingToken(tokenAtLocation.pos, sourceFile); + } + + // Cannot set breakpoint in ambient declarations + if (isInAmbientContext(tokenAtLocation)) { + return; + } + + // Get the span in the node based on its syntax + return spanInNode(tokenAtLocation); + + function textSpan(startNode: Node, endNode?: Node) { + return TypeScript.TextSpan.fromBounds(startNode.getStart(), (endNode || startNode).getEnd()); + } + + function spanInNodeIfStartsOnSameLine(node: Node): TypeScript.TextSpan { + if (node && sourceFile.getLineAndCharacterFromPosition(position).line === sourceFile.getLineAndCharacterFromPosition(node.getStart()).line) { + return spanInNode(node); + } + } + + function spanInNode(node: Node): TypeScript.TextSpan { + if (node) { + switch (node.kind) { + case SyntaxKind.VariableStatement: + return spanInVariableStatement(node); + + case SyntaxKind.VariableDeclaration: + return spanInVariableDeclaration(node); + + case SyntaxKind.SemicolonToken: + case SyntaxKind.EndOfFileToken: + return spanInNodeIfStartsOnSameLine(findPrecedingToken(node.pos, sourceFile)); + + default: + // Default go to parent to set the breakpoint + return spanInNode(node.parent); + } + } + + function spanInVariableDeclaration(variableDeclaration: VariableDeclaration): TypeScript.TextSpan { + var isParentVariableStatement = variableDeclaration.parent.kind === SyntaxKind.VariableStatement; + var isfirstDeclarationOfVariableStatement = isParentVariableStatement && + (variableDeclaration.parent).declarations[0] === variableDeclaration; + + // Breakpoint is possible in variableDeclaration only if there is initialization + if (variableDeclaration.initializer) { + if (isfirstDeclarationOfVariableStatement) { + // First declaration - include var keyword + return textSpan(variableDeclaration.parent, variableDeclaration); + } + else { + // Span only on this declaration + return textSpan(variableDeclaration); + } + } + else if (!isfirstDeclarationOfVariableStatement && isParentVariableStatement) { + // If we cant set breakpoint on this declaration, set it on previous one + var variableStatement = variableDeclaration.parent; + var indexOfCurrentDeclaration = indexOf(variableStatement.declarations, variableDeclaration); + return spanInVariableDeclaration(variableStatement.declarations[indexOfCurrentDeclaration - 1]); + } + } + + function spanInVariableStatement(variableStatement: VariableStatement): TypeScript.TextSpan { + return spanInVariableDeclaration(variableStatement.declarations[0]); + } + } + } } \ No newline at end of file diff --git a/src/services/services.ts b/src/services/services.ts index 5411cac8d0c..4a22d486219 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4737,9 +4737,7 @@ module ts { function getBreakpointStatementAtPosition(filename: string, position: number) { // doesn't use compiler - no need to synchronize with host filename = TypeScript.switchToForwardSlashes(filename); - - var syntaxtree = getSyntaxTree(filename); - return TypeScript.Services.Breakpoints.getBreakpointLocation(syntaxtree, position); + return Breakpoints.spanInSourceFileAtLocation(getCurrentSourceFile(filename), position); } function getNavigationBarItems(filename: string): NavigationBarItem[] { diff --git a/tests/baselines/reference/bpSpan_variables.baseline b/tests/baselines/reference/bpSpan_variables.baseline new file mode 100644 index 00000000000..1dbb80512f5 --- /dev/null +++ b/tests/baselines/reference/bpSpan_variables.baseline @@ -0,0 +1,23 @@ + +1 >var a = 10; + + ~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":0,"length":10} + >var a = 10 + >:=> (line 1, col 0) to (line 1, col 10) +-------------------------------- +2 >var b; + + ~~~~~~~ => Pos: (12 to 18) SpanInfo: undefined +-------------------------------- +3 >var c = 10, d, e; + + ~~~~~~~~~~~~~~~~~~ => Pos: (19 to 36) SpanInfo: {"start":19,"length":10} + >var c = 10 + >:=> (line 3, col 0) to (line 3, col 10) +-------------------------------- +4 >var c2, d2 = 10; + ~~~~~~~ => Pos: (37 to 43) SpanInfo: undefined +4 >var c2, d2 = 10; + ~~~~~~~~~ => Pos: (44 to 52) SpanInfo: {"start":45,"length":7} + >d2 = 10 + >:=> (line 4, col 8) to (line 4, col 15) \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationVariables.ts b/tests/cases/fourslash/breakpointValidationVariables.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationVariables.ts rename to tests/cases/fourslash/breakpointValidationVariables.ts From fbd78b407edd0427f025231140a8cde049a3d35f Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Sat, 30 Aug 2014 18:36:19 -0700 Subject: [PATCH 26/63] Remove the old implementation of the breakpoint resolver --- src/services/breakpoints.ts | 1083 +---------------------------------- 1 file changed, 1 insertion(+), 1082 deletions(-) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 7eb44213e02..d336bdf4b30 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -1,1088 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. Licensed under the Apache License, Version 2.0. // See LICENSE.txt in the project root for complete license information. -module TypeScript.Services.Breakpoints { - function createBreakpointSpanInfo(parentElement: TypeScript.ISyntaxElement, ...childElements: TypeScript.ISyntaxElement[]): TextSpan { - if (!parentElement) { - return null; - } - - if (childElements.length == 0) { - return TextSpan.fromBounds(TypeScript.start(parentElement), TypeScript.end(parentElement)); - } - - var start: number; - var end: number; - for (var i = 0; i < childElements.length; i++) { - var element = childElements[i]; - if (element && !isShared(element)) { - if (start == undefined) { - start = TypeScript.start(element); - } - end = TypeScript.end(element); - } - } - - return TextSpan.fromBounds(start, end); - } - - function createBreakpointSpanInfoWithLimChar(startElement: TypeScript.ISyntaxElement, limChar: number): TextSpan { - return TextSpan.fromBounds(start(startElement), limChar); - } - - class BreakpointResolver { - constructor(private posLine: number, private lineMap: TypeScript.LineMap) { - } - - private breakpointSpanOfToken(positionedToken: TypeScript.ISyntaxToken): TextSpan { - switch (positionedToken.kind()) { - case TypeScript.SyntaxKind.OpenBraceToken: - return this.breakpointSpanOfOpenBrace(positionedToken); - - case TypeScript.SyntaxKind.CloseBraceToken: - return this.breakpointSpanOfCloseBrace(positionedToken); - - case TypeScript.SyntaxKind.CommaToken: - return this.breakpointSpanOfComma(positionedToken); - - case TypeScript.SyntaxKind.SemicolonToken: - case TypeScript.SyntaxKind.EndOfFileToken: - return this.breakpointSpanIfStartsOnSameLine(previousToken(positionedToken)); - - case TypeScript.SyntaxKind.CloseParenToken: - return this.breakpointSpanOfCloseParen(positionedToken); - - case TypeScript.SyntaxKind.DoKeyword: - var parentElement = positionedToken.parent; - if (parentElement && parentElement.kind() == TypeScript.SyntaxKind.DoStatement) { - return this.breakpointSpanIfStartsOnSameLine(nextToken(positionedToken)); - } - break; - } - - return this.breakpointSpanOfContainingNode(positionedToken); - } - - private breakpointSpanOfOpenBrace(openBraceToken: TypeScript.ISyntaxToken): TextSpan { - var container = Syntax.containingNode(openBraceToken); - if (container) { - var originalContainer = container; - if (container && container.kind() == TypeScript.SyntaxKind.Block) { - // We have to check the parent and decide what to do with the breakpoint - container = Syntax.containingNode(container); - if (!container) { - container = originalContainer; - } - } - - switch (container.kind()) { - case TypeScript.SyntaxKind.Block: - if (!this.canHaveBreakpointInBlock(container)) { - return null; - } - return this.breakpointSpanOfFirstStatementInBlock(container); - break; - - case TypeScript.SyntaxKind.ModuleDeclaration: - case TypeScript.SyntaxKind.ClassDeclaration: - case TypeScript.SyntaxKind.FunctionDeclaration: - case TypeScript.SyntaxKind.ConstructorDeclaration: - case TypeScript.SyntaxKind.MemberFunctionDeclaration: - case TypeScript.SyntaxKind.GetAccessor: - case TypeScript.SyntaxKind.SetAccessor: - case TypeScript.SyntaxKind.FunctionExpression: - case TypeScript.SyntaxKind.ParenthesizedArrowFunctionExpression: - case TypeScript.SyntaxKind.SimpleArrowFunctionExpression: - if (!this.canHaveBreakpointInDeclaration(container)) { - return null; - } - if (this.posLine != this.lineMap.getLineNumberFromPosition(start(container))) { - return this.breakpointSpanOfFirstChildOfSyntaxList(this.getSyntaxListOfDeclarationWithElements(container)); - } - else { - return this.breakpointSpanOf(container); - } - - case TypeScript.SyntaxKind.EnumDeclaration: - if (!this.canHaveBreakpointInDeclaration(container)) { - return null; - } - if (this.posLine != this.lineMap.getLineNumberFromPosition(start(container))) { - return this.breakpointSpanOfFirstEnumElement(container); - } - else { - return this.breakpointSpanOf(container); - } - - case TypeScript.SyntaxKind.IfStatement: - case TypeScript.SyntaxKind.ForInStatement: - case TypeScript.SyntaxKind.WhileStatement: - case TypeScript.SyntaxKind.CatchClause: - if (this.posLine != this.lineMap.getLineNumberFromPosition(start(container))) { - return this.breakpointSpanOfFirstStatementInBlock(originalContainer); - } - else { - return this.breakpointSpanOf(container); - } - - case TypeScript.SyntaxKind.DoStatement: - return this.breakpointSpanOfFirstStatementInBlock(originalContainer); - - case TypeScript.SyntaxKind.ForStatement: - if (this.posLine != this.lineMap.getLineNumberFromPosition(start(container))) { - return this.breakpointSpanOfFirstStatementInBlock(originalContainer); - } - else { - return this.breakpointSpanOf(previousToken(openBraceToken)); - } - - case TypeScript.SyntaxKind.ElseClause: - case TypeScript.SyntaxKind.CaseSwitchClause: - case TypeScript.SyntaxKind.DefaultSwitchClause: - case TypeScript.SyntaxKind.WithStatement: - case TypeScript.SyntaxKind.TryStatement: - case TypeScript.SyntaxKind.FinallyClause: - return this.breakpointSpanOfFirstStatementInBlock(originalContainer); - - case TypeScript.SyntaxKind.SwitchStatement: - if (this.posLine != this.lineMap.getLineNumberFromPosition(start(container))) { - return this.breakpointSpanOfFirstStatementOfFirstCaseClause(container); - } - else { - return this.breakpointSpanOf(container); - } - } - } - - return null; - } - - private breakpointSpanOfCloseBrace(closeBraceToken: TypeScript.ISyntaxToken): TextSpan { - var container = Syntax.containingNode(closeBraceToken); - if (container) { - var originalContainer = container; - if (container.kind() == TypeScript.SyntaxKind.Block) { - // We have to check the parent and decide what to do with the breakpoint - container = Syntax.containingNode(container); - if (!container) { - container = originalContainer; - } - } - - switch (container.kind()) { - case TypeScript.SyntaxKind.Block: - if (!this.canHaveBreakpointInBlock(container)) { - return null; - } - return this.breakpointSpanOfLastStatementInBlock(container); - break; - - case TypeScript.SyntaxKind.ModuleDeclaration: - if (!this.canHaveBreakpointInDeclaration(container)) { - return null; - } - var moduleSyntax = container; - if (moduleSyntax.moduleElements && moduleSyntax.moduleElements.length > 0) { - return createBreakpointSpanInfo(closeBraceToken); - } - else { - return null; - } - - case TypeScript.SyntaxKind.ClassDeclaration: - case TypeScript.SyntaxKind.FunctionDeclaration: - case TypeScript.SyntaxKind.ConstructorDeclaration: - case TypeScript.SyntaxKind.MemberFunctionDeclaration: - case TypeScript.SyntaxKind.GetAccessor: - case TypeScript.SyntaxKind.SetAccessor: - case TypeScript.SyntaxKind.FunctionExpression: - if (!this.canHaveBreakpointInDeclaration(container)) { - return null; - } - return createBreakpointSpanInfo(closeBraceToken); - - case TypeScript.SyntaxKind.EnumDeclaration: - if (!this.canHaveBreakpointInDeclaration(container)) { - return null; - } - return createBreakpointSpanInfo(closeBraceToken); - - case TypeScript.SyntaxKind.IfStatement: - case TypeScript.SyntaxKind.ElseClause: - case TypeScript.SyntaxKind.ForInStatement: - case TypeScript.SyntaxKind.ForStatement: - case TypeScript.SyntaxKind.WhileStatement: - case TypeScript.SyntaxKind.DoStatement: - case TypeScript.SyntaxKind.CaseSwitchClause: - case TypeScript.SyntaxKind.DefaultSwitchClause: - case TypeScript.SyntaxKind.WithStatement: - case TypeScript.SyntaxKind.TryStatement: - case TypeScript.SyntaxKind.CatchClause: - case TypeScript.SyntaxKind.FinallyClause: - case TypeScript.SyntaxKind.ParenthesizedArrowFunctionExpression: - case TypeScript.SyntaxKind.SimpleArrowFunctionExpression: - return this.breakpointSpanOfLastStatementInBlock(originalContainer); - - case TypeScript.SyntaxKind.SwitchStatement: - return this.breakpointSpanOfLastStatementOfLastCaseClause(container); - } - } - - return null; - } - - - private breakpointSpanOfComma(commaToken: TypeScript.ISyntaxToken): TextSpan { - var commaParent = commaToken.parent; - if (isSeparatedList(commaParent)) { - var grandParent = commaParent.parent; - if (grandParent) { - switch (grandParent.kind()) { - case TypeScript.SyntaxKind.VariableDeclaration: - case TypeScript.SyntaxKind.EnumDeclaration: - case TypeScript.SyntaxKind.ParameterList: - var index = Syntax.childIndex(commaParent, commaToken); - // Use the previous child - if (index > 0) { - var child = childAt(commaParent, index - 1); - return this.breakpointSpanOf(child); - } - - // If we cant set breakpoint on enum element, just dont set breakpoint - if (grandParent.kind() == TypeScript.SyntaxKind.EnumDeclaration) { - return null; - } - break; - } - } - } - - return this.breakpointSpanOfContainingNode(commaToken); - } - - private breakpointSpanOfCloseParen(closeParenToken: TypeScript.ISyntaxToken): TextSpan { - var closeParenParent = closeParenToken.parent; - if (closeParenParent) { - switch (closeParenParent.kind()) { - case TypeScript.SyntaxKind.ForStatement: - case TypeScript.SyntaxKind.ParameterList: - return this.breakpointSpanOf(previousToken(closeParenToken)); - } - } - - return this.breakpointSpanOfContainingNode(closeParenToken); - } - - private canHaveBreakpointInBlock(blockNode: TypeScript.ISyntaxNode) { - if (!blockNode || TypeScript.SyntaxUtilities.isAmbientDeclarationSyntax(blockNode)) { - return false; - } - - var blockSyntax = blockNode; - return blockSyntax.statements && blockSyntax.statements.length != 0; - } - - private breakpointSpanOfFirstStatementInBlock(blockNode: TypeScript.ISyntaxNode): TextSpan { - if (!blockNode) { - return null; - } - - var blockSyntax = blockNode; - var statementsNode = blockSyntax.statements; - if (!statementsNode || statementsNode.length == 0) { - return null; - } - - var firstStatement = childAt(statementsNode, 0); - if (firstStatement && firstStatement.kind() == TypeScript.SyntaxKind.Block) { - if (this.canHaveBreakpointInBlock(firstStatement)) { - return this.breakpointSpanOfFirstStatementInBlock(firstStatement); - } - return null; - } - else { - return this.breakpointSpanOf(firstStatement); - } - } - - private breakpointSpanOfLastStatementInBlock(blockNode: TypeScript.ISyntaxNode): TextSpan { - if (!blockNode) { - return null; - } - - var blockSyntax = blockNode; - var statementsNode = blockSyntax.statements; - if (!statementsNode || statementsNode.length == 0) { - return null; - } - - var lastStatement = childAt(statementsNode, statementsNode.length - 1); - if (lastStatement && lastStatement.kind() == TypeScript.SyntaxKind.Block) { - if (this.canHaveBreakpointInBlock(lastStatement)) { - return this.breakpointSpanOfLastStatementInBlock(lastStatement); - } - return null; - } - else { - return this.breakpointSpanOf(lastStatement); - } - } - - private breakpointSpanOfFirstChildOfSyntaxList(positionedList: TypeScript.ISyntaxNodeOrToken[]): TextSpan { - if (!positionedList) { - return null; - } - - // Find the first syntax element - var listSyntax = positionedList; - if (listSyntax.length == 0) { - return null; - } - - var firstStatement = childAt(positionedList, 0); - if (firstStatement && firstStatement.kind() == TypeScript.SyntaxKind.Block) { - if (this.canHaveBreakpointInBlock(firstStatement)) { - return this.breakpointSpanOfFirstStatementInBlock(firstStatement); - } - - return null; - } - else { - return this.breakpointSpanOf(firstStatement); - } - } - - private breakpointSpanOfLastChildOfSyntaxList(positionedList: TypeScript.ISyntaxNodeOrToken[]): TextSpan { - if (!positionedList) { - return null; - } - - // Find the first syntax element - var listSyntax = positionedList; - if (listSyntax.length == 0) { - return null; - } - var lastStatement = childAt(positionedList, 0); - if (lastStatement && lastStatement.kind() == TypeScript.SyntaxKind.Block) { - if (this.canHaveBreakpointInBlock(lastStatement)) { - return this.breakpointSpanOfLastStatementInBlock(lastStatement); - } - return null; - } - else { - return this.breakpointSpanOf(lastStatement); - } - } - - private breakpointSpanOfNode(positionedNode: ISyntaxNode): TextSpan { - var node = positionedNode; - switch (node.kind()) { - // Declarations with elements - case TypeScript.SyntaxKind.ModuleDeclaration: - case TypeScript.SyntaxKind.ClassDeclaration: - case TypeScript.SyntaxKind.FunctionDeclaration: - case TypeScript.SyntaxKind.ConstructorDeclaration: - case TypeScript.SyntaxKind.MemberFunctionDeclaration: - case TypeScript.SyntaxKind.GetAccessor: - case TypeScript.SyntaxKind.SetAccessor: - case TypeScript.SyntaxKind.FunctionExpression: - return this.breakpointSpanOfDeclarationWithElements(positionedNode); - - // Var, parameter and member variable declaration syntax - case TypeScript.SyntaxKind.VariableDeclarator: - return this.breakpointSpanOfVariableDeclarator(positionedNode); - - case TypeScript.SyntaxKind.VariableDeclaration: - return this.breakpointSpanOfVariableDeclaration(positionedNode); - - case TypeScript.SyntaxKind.VariableStatement: - return this.breakpointSpanOfVariableStatement(positionedNode); - - case TypeScript.SyntaxKind.Parameter: - return this.breakpointSpanOfParameter(positionedNode); - - case TypeScript.SyntaxKind.MemberVariableDeclaration: - return this.breakpointSpanOfMemberVariableDeclaration(positionedNode); - - case TypeScript.SyntaxKind.ImportDeclaration: - return this.breakpointSpanOfImportDeclaration(positionedNode); - - case TypeScript.SyntaxKind.EnumDeclaration: - return this.breakpointSpanOfEnumDeclaration(positionedNode); - - case TypeScript.SyntaxKind.EnumElement: - return this.breakpointSpanOfEnumElement(positionedNode); - - // Statements - case TypeScript.SyntaxKind.IfStatement: - return this.breakpointSpanOfIfStatement(positionedNode); - case TypeScript.SyntaxKind.ElseClause: - return this.breakpointSpanOfElseClause(positionedNode); - case TypeScript.SyntaxKind.ForInStatement: - return this.breakpointSpanOfForInStatement(positionedNode); - case TypeScript.SyntaxKind.ForStatement: - return this.breakpointSpanOfForStatement(positionedNode); - case TypeScript.SyntaxKind.WhileStatement: - return this.breakpointSpanOfWhileStatement(positionedNode); - case TypeScript.SyntaxKind.DoStatement: - return this.breakpointSpanOfDoStatement(positionedNode); - case TypeScript.SyntaxKind.SwitchStatement: - return this.breakpointSpanOfSwitchStatement(positionedNode); - case TypeScript.SyntaxKind.CaseSwitchClause: - return this.breakpointSpanOfCaseSwitchClause(positionedNode); - case TypeScript.SyntaxKind.DefaultSwitchClause: - return this.breakpointSpanOfDefaultSwitchClause(positionedNode); - case TypeScript.SyntaxKind.WithStatement: - return this.breakpointSpanOfWithStatement(positionedNode); - case TypeScript.SyntaxKind.TryStatement: - return this.breakpointSpanOfTryStatement(positionedNode); - case TypeScript.SyntaxKind.CatchClause: - return this.breakpointSpanOfCatchClause(positionedNode); - case TypeScript.SyntaxKind.FinallyClause: - return this.breakpointSpanOfFinallyClause(positionedNode); - - // Arrow expressions - case TypeScript.SyntaxKind.ParenthesizedArrowFunctionExpression: - return this.breakpointSpanOfParenthesizedArrowFunctionExpression(positionedNode); - - case TypeScript.SyntaxKind.SimpleArrowFunctionExpression: - return this.breakpointSpanOfSimpleArrowFunctionExpression(positionedNode); - - // Expressions or statements - default: - if (SyntaxUtilities.isStatement(node)) { - return this.breakpointSpanOfStatement(positionedNode); - } - else { - return this.breakpointOfExpression(positionedNode); - } - } - } - - private isExpressionOfArrowExpressions(expression: ISyntaxElement): boolean { - if (!expression) { - return false; - } - - var expressionParent = expression.parent; - if (expressionParent) { - if (expressionParent.kind() == TypeScript.SyntaxKind.ParenthesizedArrowFunctionExpression) { - var parenthesizedArrowExpression = expressionParent; - var expressionOfParenthesizedArrowExpression = parenthesizedArrowExpression.expression; - return expressionOfParenthesizedArrowExpression == expression; - } - else if (expressionParent.kind() == TypeScript.SyntaxKind.SimpleArrowFunctionExpression) { - var simpleArrowExpression = expressionParent; - var expressionOfSimpleArrowExpression = simpleArrowExpression.expression; - return expressionOfSimpleArrowExpression == expression; - } - else if (expressionParent.kind() == TypeScript.SyntaxKind.CommaExpression) { - return this.isExpressionOfArrowExpressions(expressionParent); - } - } - return false; - } - - private isInitializerOfForStatement(expressionNode: TypeScript.ISyntaxNode): boolean { - if (!expressionNode) { - return false; - } - - var expressionParent = expressionNode.parent; - if (expressionParent && expressionParent.kind() == TypeScript.SyntaxKind.ForStatement) { - - var expression = expressionNode; - var forStatement = expressionParent; - var initializer = forStatement.initializer; - return initializer === expression; - } - else if (expressionParent && expressionParent.kind() == TypeScript.SyntaxKind.CommaExpression) { - return this.isInitializerOfForStatement(expressionParent); - } - - return false; - } - - private isConditionOfForStatement(expressionNode: TypeScript.ISyntaxNode): boolean { - if (!expressionNode) { - return false; - } - - var expressionParent = expressionNode.parent; - if (expressionParent && expressionParent.kind() == TypeScript.SyntaxKind.ForStatement) { - var expression = expressionNode; - var forStatement = expressionParent; - var condition = forStatement.condition; - return condition === expression; - } - else if (expressionParent && expressionParent.kind() == TypeScript.SyntaxKind.CommaExpression) { - return this.isConditionOfForStatement(expressionParent); - } - - return false; - } - - private isIncrememtorOfForStatement(expressionNode: TypeScript.ISyntaxNode): boolean { - if (!expressionNode) { - return false; - } - - var expressionParent = expressionNode.parent; - if (expressionParent && expressionParent.kind() == TypeScript.SyntaxKind.ForStatement) { - var expression = expressionNode; - var forStatement = expressionParent; - var incrementor = forStatement.incrementor; - return incrementor === expression; - } - else if (expressionParent && expressionParent.kind() == TypeScript.SyntaxKind.CommaExpression) { - return this.isIncrememtorOfForStatement(expressionParent); - } - - return false; - } - - private breakpointOfLeftOfCommaExpression(commaExpressionNode: TypeScript.ISyntaxNode): TextSpan { - var commaExpression = commaExpressionNode; - return this.breakpointSpanOf(commaExpression.left); - } - - private breakpointOfExpression(expressionNode: TypeScript.ISyntaxNode): TextSpan { - if (this.isInitializerOfForStatement(expressionNode) || - this.isConditionOfForStatement(expressionNode) || - this.isIncrememtorOfForStatement(expressionNode)) { - if (expressionNode.kind() == TypeScript.SyntaxKind.CommaExpression) { - return this.breakpointOfLeftOfCommaExpression(expressionNode); - } - return createBreakpointSpanInfo(expressionNode); - } - - if (this.isExpressionOfArrowExpressions(expressionNode)) { - if (expressionNode.kind() == TypeScript.SyntaxKind.CommaExpression) { - return this.breakpointOfLeftOfCommaExpression(expressionNode); - } - return createBreakpointSpanInfo(expressionNode); - } - - if (expressionNode.kind() == TypeScript.SyntaxKind.ExportAssignment) { - var exportAssignmentSyntax = expressionNode; - return createBreakpointSpanInfo(expressionNode, exportAssignmentSyntax.exportKeyword, exportAssignmentSyntax.equalsToken, exportAssignmentSyntax.identifier); - } - - return this.breakpointSpanOfContainingNode(expressionNode); - } - - private breakpointSpanOfStatement(statementNode: TypeScript.ISyntaxNode): TextSpan { - var statement = statementNode; - if (statement.kind() == TypeScript.SyntaxKind.EmptyStatement) { - return null; - } - - var containingNode = Syntax.containingNode(statementNode); - if (SyntaxUtilities.isStatement(containingNode)) { - // Check if not the declarations and the compound statements - var useNodeForBreakpoint = false; - switch (containingNode.kind()) { - // Declarations - case TypeScript.SyntaxKind.ModuleDeclaration: - case TypeScript.SyntaxKind.ClassDeclaration: - case TypeScript.SyntaxKind.FunctionDeclaration: - case TypeScript.SyntaxKind.ConstructorDeclaration: - case TypeScript.SyntaxKind.MemberFunctionDeclaration: - case TypeScript.SyntaxKind.GetAccessor: - case TypeScript.SyntaxKind.SetAccessor: - case TypeScript.SyntaxKind.Block: - - // Compound Statements - case TypeScript.SyntaxKind.IfStatement: - case TypeScript.SyntaxKind.ElseClause: - case TypeScript.SyntaxKind.ForInStatement: - case TypeScript.SyntaxKind.ForStatement: - case TypeScript.SyntaxKind.WhileStatement: - case TypeScript.SyntaxKind.DoStatement: - case TypeScript.SyntaxKind.SwitchStatement: - case TypeScript.SyntaxKind.CaseSwitchClause: - case TypeScript.SyntaxKind.DefaultSwitchClause: - case TypeScript.SyntaxKind.WithStatement: - case TypeScript.SyntaxKind.TryStatement: - case TypeScript.SyntaxKind.CatchClause: - case TypeScript.SyntaxKind.FinallyClause: - case TypeScript.SyntaxKind.Block: - useNodeForBreakpoint = true; - } - - if (!useNodeForBreakpoint) { - return this.breakpointSpanOfContainingNode(statementNode); - } - } - - switch (statement.kind()) { - case TypeScript.SyntaxKind.ExpressionStatement: - var expressionSyntax = statement; - return createBreakpointSpanInfo(expressionSyntax.expression); - - case TypeScript.SyntaxKind.ReturnStatement: - var returnStatementSyntax = statement; - return createBreakpointSpanInfo(statementNode, returnStatementSyntax.returnKeyword, returnStatementSyntax.expression); - - case TypeScript.SyntaxKind.ThrowStatement: - var throwStatementSyntax = statement; - return createBreakpointSpanInfo(statementNode, throwStatementSyntax.throwKeyword, throwStatementSyntax.expression); - - case TypeScript.SyntaxKind.BreakStatement: - var breakStatementSyntax = statement; - return createBreakpointSpanInfo(statementNode, breakStatementSyntax.breakKeyword, breakStatementSyntax.identifier); - - case TypeScript.SyntaxKind.ContinueStatement: - var continueStatementSyntax = statement; - return createBreakpointSpanInfo(statementNode, continueStatementSyntax.continueKeyword, continueStatementSyntax.identifier); - - case TypeScript.SyntaxKind.DebuggerStatement: - var debuggerStatementSyntax = statement; - return createBreakpointSpanInfo(debuggerStatementSyntax.debuggerKeyword); - - case TypeScript.SyntaxKind.LabeledStatement: - var labeledStatementSyntax = statement; - return this.breakpointSpanOf(labeledStatementSyntax.statement); - } - - return null; - } - - private getSyntaxListOfDeclarationWithElements(positionedNode: TypeScript.ISyntaxNode) { - var node = positionedNode; - var elementsList: TypeScript.ISyntaxNodeOrToken[]; - var block: TypeScript.BlockSyntax; - - switch (node.kind()) { - case TypeScript.SyntaxKind.ModuleDeclaration: - elementsList = (node).moduleElements; - break; - - case TypeScript.SyntaxKind.ClassDeclaration: - elementsList = (node).classElements; - break; - - case TypeScript.SyntaxKind.FunctionDeclaration: - block = (node).block; - break; - - case TypeScript.SyntaxKind.ConstructorDeclaration: - block = (node).block; - break; - - case TypeScript.SyntaxKind.MemberFunctionDeclaration: - block = (node).block; - break; - - case TypeScript.SyntaxKind.GetAccessor: - block = (node).block; - break; - - case TypeScript.SyntaxKind.SetAccessor: - block = (node).block; - break; - - case TypeScript.SyntaxKind.FunctionExpression: - block = (node).block; - break; - - case TypeScript.SyntaxKind.ParenthesizedArrowFunctionExpression: - block = (node).block; - break; - - case TypeScript.SyntaxKind.SimpleArrowFunctionExpression: - block = (node).block; - break; - - default: - throw TypeScript.Errors.argument('positionNode', 'unknown node kind in getSyntaxListOfDeclarationWithElements'); - } - - var parentElement: TypeScript.ISyntaxElement = positionedNode; - if (block) { - parentElement = block; - elementsList = block.statements; - } - - return elementsList; - } - - private canHaveBreakpointInDeclaration(positionedNode: TypeScript.ISyntaxNode) { - return positionedNode && !TypeScript.SyntaxUtilities.isAmbientDeclarationSyntax(positionedNode); - } - - private breakpointSpanOfDeclarationWithElements(positionedNode: TypeScript.ISyntaxNode): TextSpan { - if (!this.canHaveBreakpointInDeclaration(positionedNode)) { - return null; - } - - // If inside another module the whole declaration is debuggable - var node = positionedNode; - var moduleSyntax = positionedNode; - if ((SyntaxUtilities.isModuleElement(node) && Syntax.containingNode(positionedNode).kind() != TypeScript.SyntaxKind.SourceUnit) || - SyntaxUtilities.isClassElement(node) || - (moduleSyntax.kind() == TypeScript.SyntaxKind.ModuleDeclaration && moduleSyntax.name - && moduleSyntax.name.kind() == TypeScript.SyntaxKind.QualifiedName)) { - return createBreakpointSpanInfo(positionedNode); - } - else { - // Try to get the breakpoint in first element declaration - return this.breakpointSpanOfFirstChildOfSyntaxList(this.getSyntaxListOfDeclarationWithElements(positionedNode)); - } - } - - private canHaveBreakpointInVariableDeclarator(varDeclaratorNode: TypeScript.ISyntaxNode) { - if (!varDeclaratorNode || TypeScript.SyntaxUtilities.isAmbientDeclarationSyntax(varDeclaratorNode)) { - return false; - } - - var varDeclaratorSyntax = varDeclaratorNode; - return !!varDeclaratorSyntax.equalsValueClause; - } - - private breakpointSpanOfVariableDeclarator(varDeclaratorNode: TypeScript.ISyntaxNode): TextSpan { - if (!this.canHaveBreakpointInVariableDeclarator(varDeclaratorNode)) { - return null; - } - - var container = Syntax.containingNode(varDeclaratorNode); - if (container && container.kind() == TypeScript.SyntaxKind.VariableDeclaration) { - var parentDeclaratorsList = varDeclaratorNode.parent; - // If this is the first declarator in the list use the declaration instead - if (parentDeclaratorsList && childAt(parentDeclaratorsList, 0) == varDeclaratorNode) { - return this.breakpointSpanOfVariableDeclaration(container); - } - - // Create breakpoint on this var declarator - if (this.canHaveBreakpointInVariableDeclarator(varDeclaratorNode)) { - return createBreakpointSpanInfo(varDeclaratorNode); - } - else { - return null; - } - } - else if (container) { - // Member Variable syntax - return this.breakpointSpanOfMemberVariableDeclaration(container); - } - - return null; - } - - private canHaveBreakpointInVariableDeclaration(varDeclarationNode: TypeScript.ISyntaxNode) { - if (!varDeclarationNode || TypeScript.SyntaxUtilities.isAmbientDeclarationSyntax(varDeclarationNode)) { - return false; - } - - var varDeclarationSyntax = varDeclarationNode; - var containerChildren = varDeclarationSyntax.variableDeclarators; - if (!containerChildren || childCount(containerChildren) == 0) { - return false; - } - - var child = childAt(containerChildren, 0); - if (isNode(child)) { - return this.canHaveBreakpointInVariableDeclarator(child); - } - - return false; - } - - private breakpointSpanOfVariableDeclaration(varDeclarationNode: TypeScript.ISyntaxNode): TextSpan { - if (!this.canHaveBreakpointInDeclaration(varDeclarationNode)) { - return null; - } - - var container = Syntax.containingNode(varDeclarationNode); - var varDeclarationSyntax = varDeclarationNode; - var varDeclarators = varDeclarationSyntax.variableDeclarators; - - if (container && container.kind() == TypeScript.SyntaxKind.VariableStatement) { - return this.breakpointSpanOfVariableStatement(container); - } - - if (this.canHaveBreakpointInVariableDeclaration(varDeclarationNode)) { - return createBreakpointSpanInfoWithLimChar(varDeclarationNode, end(childAt(varDeclarators, 0))); - } - else { - return null; - } - } - - private canHaveBreakpointInVariableStatement(varStatementNode: TypeScript.ISyntaxNode) { - if (!varStatementNode || TypeScript.SyntaxUtilities.isAmbientDeclarationSyntax(varStatementNode)) { - return false; - } - - var variableStatement = varStatementNode; - return this.canHaveBreakpointInVariableDeclaration(variableStatement.variableDeclaration); - } - - private breakpointSpanOfVariableStatement(varStatementNode: TypeScript.ISyntaxNode): TextSpan { - if (!this.canHaveBreakpointInVariableStatement(varStatementNode)) { - return null; - } - - var variableStatement = varStatementNode; - var variableDeclaration = variableStatement.variableDeclaration; - var varDeclarationSyntax = variableDeclaration; - var varDeclarators = varDeclarationSyntax.variableDeclarators; - return createBreakpointSpanInfoWithLimChar(varStatementNode, end(childAt(varDeclarators, 0))); - } - - private breakpointSpanOfParameter(parameterNode: TypeScript.ISyntaxNode): TextSpan { - if (parameterNode.parent.kind() === SyntaxKind.SimpleArrowFunctionExpression) { - return this.breakpointSpanOfNode(parameterNode.parent); - } - - if (TypeScript.SyntaxUtilities.isAmbientDeclarationSyntax(parameterNode)) { - return null; - } - - var parameterSyntax = parameterNode; - if (parameterSyntax.dotDotDotToken || parameterSyntax.equalsValueClause || parameterSyntax.modifiers.length > 0) { - return createBreakpointSpanInfo(parameterNode); - } - else { - return null; - } - } - - private breakpointSpanOfMemberVariableDeclaration(memberVarDeclarationNode: TypeScript.ISyntaxNode): TextSpan { - if (TypeScript.SyntaxUtilities.isAmbientDeclarationSyntax(memberVarDeclarationNode)) { - return null; - } - - var memberVariableDeclaration = memberVarDeclarationNode; - if (this.canHaveBreakpointInVariableDeclarator(memberVariableDeclaration.variableDeclarator)) { - return createBreakpointSpanInfo(memberVarDeclarationNode, memberVariableDeclaration.modifiers, memberVariableDeclaration.variableDeclarator); - } - else { - return null; - } - } - - private breakpointSpanOfImportDeclaration(importDeclarationNode: TypeScript.ISyntaxNode): TextSpan { - if (TypeScript.SyntaxUtilities.isAmbientDeclarationSyntax(importDeclarationNode)) { - return null; - } - - var importSyntax = importDeclarationNode; - return createBreakpointSpanInfo(importDeclarationNode, importSyntax.modifiers, importSyntax.importKeyword, importSyntax.identifier, importSyntax.equalsToken, importSyntax.moduleReference); - } - - private breakpointSpanOfEnumDeclaration(enumDeclarationNode: TypeScript.ISyntaxNode): TextSpan { - if (!this.canHaveBreakpointInDeclaration(enumDeclarationNode)) { - return null; - } - - return createBreakpointSpanInfo(enumDeclarationNode); - } - - private breakpointSpanOfFirstEnumElement(enumDeclarationNode: TypeScript.ISyntaxNode): TextSpan { - var enumDeclarationSyntax = enumDeclarationNode; - var enumElements = enumDeclarationSyntax.enumElements; - if (enumElements && childCount(enumElements)) { - return this.breakpointSpanOf(childAt(enumElements, 0)); - } - - return null; - } - - private breakpointSpanOfEnumElement(enumElementNode: TypeScript.ISyntaxNode): TextSpan { - if (TypeScript.SyntaxUtilities.isAmbientDeclarationSyntax(enumElementNode)) { - return null; - } - - return createBreakpointSpanInfo(enumElementNode); - } - - private breakpointSpanOfIfStatement(ifStatementNode: TypeScript.ISyntaxNode): TextSpan { - var ifStatement = ifStatementNode; - return createBreakpointSpanInfo(ifStatementNode, ifStatement.ifKeyword, ifStatement.openParenToken, ifStatement.condition, ifStatement.closeParenToken); - } - - private breakpointSpanOfElseClause(elseClauseNode: TypeScript.ISyntaxNode): TextSpan { - var elseClause = elseClauseNode; - return this.breakpointSpanOf(elseClause.statement); - } - - private breakpointSpanOfForInStatement(forInStatementNode: TypeScript.ISyntaxNode): TextSpan { - var forInStatement = forInStatementNode; - return createBreakpointSpanInfo(forInStatementNode, forInStatement.forKeyword, forInStatement.openParenToken, forInStatement.variableDeclaration, - forInStatement.left, forInStatement.inKeyword, forInStatement.expression, forInStatement.closeParenToken); - } - - private breakpointSpanOfForStatement(forStatementNode: TypeScript.ISyntaxNode): TextSpan { - var forStatement = forStatementNode; - return this.breakpointSpanOf(forStatement.variableDeclaration - ? forStatement.variableDeclaration - : forStatement.initializer); - } - - private breakpointSpanOfWhileStatement(whileStatementNode: TypeScript.ISyntaxNode): TextSpan { - var whileStatement = whileStatementNode; - return createBreakpointSpanInfo(whileStatementNode, whileStatement.whileKeyword, whileStatement.openParenToken, whileStatement.condition, whileStatement.closeParenToken); - } - - private breakpointSpanOfDoStatement(doStatementNode: TypeScript.ISyntaxNode): TextSpan { - var doStatement = doStatementNode; - return createBreakpointSpanInfo(doStatementNode, doStatement.whileKeyword, doStatement.openParenToken, doStatement.condition, doStatement.closeParenToken); - } - - private breakpointSpanOfSwitchStatement(switchStatementNode: TypeScript.ISyntaxNode): TextSpan { - var switchStatement = switchStatementNode; - return createBreakpointSpanInfo(switchStatementNode, switchStatement.switchKeyword, switchStatement.openParenToken, switchStatement.expression, switchStatement.closeParenToken); - } - - private breakpointSpanOfFirstStatementOfFirstCaseClause(switchStatementNode: TypeScript.ISyntaxNode): TextSpan { - var switchStatement = switchStatementNode; - if (switchStatement.switchClauses && switchStatement.switchClauses.length == 0) { - return null; - } - - var switchClauses = switchStatement.switchClauses; - if (switchClauses.length == 0) { - return null; - } - - var firstCaseClause = switchClauses[0]; - var statements = firstCaseClause.statements; - - return this.breakpointSpanOfFirstChildOfSyntaxList(statements); - } - - private breakpointSpanOfLastStatementOfLastCaseClause(switchStatementNode: TypeScript.ISyntaxNode): TextSpan { - var switchStatement = switchStatementNode; - if (switchStatement.switchClauses && switchStatement.switchClauses.length == 0) { - return null; - } - - var switchClauses = switchStatement.switchClauses; - if (switchClauses.length == 0) { - return null; - } - - var lastClauseNode = switchClauses[switchClauses.length - 1]; - var statements = lastClauseNode.statements; - - return this.breakpointSpanOfLastChildOfSyntaxList(statements); - } - - private breakpointSpanOfCaseSwitchClause(caseClauseNode: TypeScript.ISyntaxNode): TextSpan { - var caseSwitchClause = caseClauseNode; - return this.breakpointSpanOfFirstChildOfSyntaxList(caseSwitchClause.statements); - } - - private breakpointSpanOfDefaultSwitchClause(defaultSwithClauseNode: TypeScript.ISyntaxNode): TextSpan { - var defaultSwitchClause = defaultSwithClauseNode; - return this.breakpointSpanOfFirstChildOfSyntaxList(defaultSwitchClause.statements); - } - - private breakpointSpanOfWithStatement(withStatementNode: TypeScript.ISyntaxNode): TextSpan { - var withStatement = withStatementNode; - return this.breakpointSpanOf(withStatement.statement); - } - - private breakpointSpanOfTryStatement(tryStatementNode: TypeScript.ISyntaxNode): TextSpan { - var tryStatement = tryStatementNode; - return this.breakpointSpanOfFirstStatementInBlock(tryStatement.block); - } - - private breakpointSpanOfCatchClause(catchClauseNode: TypeScript.ISyntaxNode): TextSpan { - var catchClause = catchClauseNode; - return createBreakpointSpanInfo(catchClauseNode, catchClause.catchKeyword, catchClause.openParenToken, catchClause.identifier, catchClause.typeAnnotation, catchClause.closeParenToken); - } - - private breakpointSpanOfFinallyClause(finallyClauseNode: TypeScript.ISyntaxNode): TextSpan { - var finallyClause = finallyClauseNode; - return this.breakpointSpanOfFirstStatementInBlock(finallyClause.block); - } - - private breakpointSpanOfParenthesizedArrowFunctionExpression(arrowFunctionExpression: ParenthesizedArrowFunctionExpressionSyntax): TextSpan { - if (arrowFunctionExpression.block) { - return this.breakpointSpanOfFirstStatementInBlock(arrowFunctionExpression.block); - } - else { - return this.breakpointSpanOf(arrowFunctionExpression.expression); - } - } - - private breakpointSpanOfSimpleArrowFunctionExpression(arrowFunctionExpression: SimpleArrowFunctionExpressionSyntax): TextSpan { - if (arrowFunctionExpression.block) { - return this.breakpointSpanOfFirstStatementInBlock(arrowFunctionExpression.block); - } - else { - return this.breakpointSpanOf(arrowFunctionExpression.expression); - } - } - - private breakpointSpanOfContainingNode(positionedElement: ISyntaxElement): TextSpan { - var current = positionedElement.parent; - while (!isNode(current)) { - current = current.parent; - } - - return this.breakpointSpanOf(current); - } - - private breakpointSpanIfStartsOnSameLine(positionedElement: TypeScript.ISyntaxElement): TextSpan { - if (positionedElement && this.posLine == this.lineMap.getLineNumberFromPosition(start(positionedElement))) { - return this.breakpointSpanOf(positionedElement); - } - - return null; - } - - public breakpointSpanOf(positionedElement: TypeScript.ISyntaxElement): TextSpan { - if (!positionedElement) { - return null; - } - - for (var containingNode = Syntax.containingNode(positionedElement); containingNode != null; containingNode = Syntax.containingNode(containingNode)) { - if (containingNode.kind() == TypeScript.SyntaxKind.TypeAnnotation) { - return this.breakpointSpanIfStartsOnSameLine(containingNode); - } - } - - var element = positionedElement; - - // Syntax node - if (isNode(element)) { - return this.breakpointSpanOfNode(positionedElement); - } - - // Token - if (isToken(element)) { - return this.breakpointSpanOfToken(positionedElement); - } - - // List - // Separated List - return this.breakpointSpanOfContainingNode(positionedElement); - } - } - - export function getBreakpointLocation(syntaxTree: TypeScript.SyntaxTree, askedPos: number): TextSpan { - // Cannot set breakpoint in dts file - if (TypeScript.isDTSFile(syntaxTree.fileName())) { - return null; - } - - var sourceUnit = syntaxTree.sourceUnit(); - var positionedToken = TypeScript.findToken(sourceUnit, askedPos); - - var lineMap = syntaxTree.lineMap(); - var posLine = lineMap.getLineNumberFromPosition(askedPos); - var tokenStartLine = lineMap.getLineNumberFromPosition(start(positionedToken)); - if (posLine < tokenStartLine) { - return null; - } - - var breakpointResolver = new BreakpointResolver(posLine, lineMap); - return breakpointResolver.breakpointSpanOf(positionedToken); - } -} +/// module ts.Breakpoints { /** From cec814689c2a5f44ec235fae164fce410e686196 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Sat, 30 Aug 2014 18:39:46 -0700 Subject: [PATCH 27/63] Changed the namespace from ts.Breakpoints to ts.BreakpointResolver --- src/services/breakpoints.ts | 2 +- src/services/services.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index d336bdf4b30..8106d085b5d 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -3,7 +3,7 @@ /// -module ts.Breakpoints { +module ts.BreakpointResolver { /** * Get the breakpoint span in given sourceFile */ diff --git a/src/services/services.ts b/src/services/services.ts index 4a22d486219..080daa1aa53 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4737,7 +4737,7 @@ module ts { function getBreakpointStatementAtPosition(filename: string, position: number) { // doesn't use compiler - no need to synchronize with host filename = TypeScript.switchToForwardSlashes(filename); - return Breakpoints.spanInSourceFileAtLocation(getCurrentSourceFile(filename), position); + return BreakpointResolver.spanInSourceFileAtLocation(getCurrentSourceFile(filename), position); } function getNavigationBarItems(filename: string): NavigationBarItem[] { From 35cdea1a0e1805c636f3d9726c9de124b734c99a Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 17 Oct 2014 15:41:25 -0700 Subject: [PATCH 28/63] Breakpointspan implementation for function declaration, expression statements and return statements --- src/services/breakpoints.ts | 152 ++++++++++++++++++ .../reference/bpSpan_functions.baseline | 102 ++++++++++++ .../breakpointValidationFunctions.ts | 0 3 files changed, 254 insertions(+) create mode 100644 tests/baselines/reference/bpSpan_functions.baseline rename tests/cases/{fourslash_old => fourslash}/breakpointValidationFunctions.ts (100%) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 8106d085b5d..ea8fd3e0a56 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -42,6 +42,10 @@ module ts.BreakpointResolver { } } + function spanInPreviousNode(node: Node): TypeScript.TextSpan { + return spanInNode(findPrecedingToken(node.pos, sourceFile)); + } + function spanInNode(node: Node): TypeScript.TextSpan { if (node) { switch (node.kind) { @@ -51,10 +55,41 @@ module ts.BreakpointResolver { case SyntaxKind.VariableDeclaration: return spanInVariableDeclaration(node); + case SyntaxKind.Parameter: + return spanInParameterDeclaration(node); + + case SyntaxKind.FunctionDeclaration: + return spanInFunctionDeclaration(node); + + case SyntaxKind.FunctionBlock: + return spanInBlock(node); + + case SyntaxKind.ExpressionStatement: + return spanInExpressionStatement(node); + + case SyntaxKind.ReturnStatement: + return spanInReturnStatement(node); + + // Tokens: case SyntaxKind.SemicolonToken: case SyntaxKind.EndOfFileToken: return spanInNodeIfStartsOnSameLine(findPrecedingToken(node.pos, sourceFile)); + case SyntaxKind.CommaToken: + return spanInCommaToken(node); + + case SyntaxKind.OpenBraceToken: + return spanInOpenBraceToken(node); + + case SyntaxKind.CloseBraceToken: + return spanInCloseBraceToken(node); + + case SyntaxKind.CloseParenToken: + return spanInCloseParenToken(node); + + case SyntaxKind.ColonToken: + return spanInColonToken(node); + default: // Default go to parent to set the breakpoint return spanInNode(node.parent); @@ -88,6 +123,123 @@ module ts.BreakpointResolver { function spanInVariableStatement(variableStatement: VariableStatement): TypeScript.TextSpan { return spanInVariableDeclaration(variableStatement.declarations[0]); } + + function canHaveSpanInParameterDeclaration(parameter: ParameterDeclaration): boolean { + // Breakpoint is possible on parameter only if it has initializer, is a rest parameter, or has public or private modifier + return !!parameter.initializer || !!(parameter.flags & NodeFlags.Rest) || + !!(parameter.flags & NodeFlags.Public) || !!(parameter.flags & NodeFlags.Private); + } + + function spanInParameterDeclaration(parameter: ParameterDeclaration): TypeScript.TextSpan { + if (canHaveSpanInParameterDeclaration(parameter)) { + return textSpan(parameter); + } + else { + var functionDeclaration = parameter.parent; + var indexOfParameter = indexOf(functionDeclaration.parameters, parameter); + if (indexOfParameter) { + // Not a first parameter, go to previous parameter + return spanInParameterDeclaration(functionDeclaration.parameters[indexOfParameter - 1]); + } + else { + // Set breakpoint in the function declaration body + return spanInNode(functionDeclaration.body); + } + } + } + + function spanInFunctionDeclaration(functionDeclaration: FunctionDeclaration): TypeScript.TextSpan { + // No breakpoints in the function signature + if (!functionDeclaration.body) { + return; + } + + // Is this coming because the touchingToken was in typeAnnotation of return type + if (functionDeclaration.type) { + for (var node = tokenAtLocation; node; node = node.parent) { + if (node.parent === functionDeclaration && functionDeclaration.type === node) { + if (functionDeclaration.parameters && functionDeclaration.parameters.length) { + // Set breakpoint in last parameter + return spanInParameterDeclaration(functionDeclaration.parameters[functionDeclaration.parameters.length - 1]); + } + + // Set breakpoint in function body + break; + } + } + } + + // Set span in function body + return spanInNode(functionDeclaration.body); + } + + function spanInBlock(block: Block): TypeScript.TextSpan { + // Set breakpoint in first statement + return spanInNode(block.statements[0]); + } + + function spanInExpressionStatement(expressionStatement: ExpressionStatement): TypeScript.TextSpan { + return textSpan(expressionStatement.expression); + } + + function spanInReturnStatement(returnStatement: ReturnStatement): TypeScript.TextSpan { + return textSpan(returnStatement.getChildAt(0, sourceFile), returnStatement.expression); + } + + // Tokens: + function spanInCommaToken(node: Node): TypeScript.TextSpan { + switch (node.parent.kind) { + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.VariableStatement: + return spanInPreviousNode(node); + + // Default to parent node + default: + return spanInNode(node.parent); + } + } + + function spanInOpenBraceToken(node: Node): TypeScript.TextSpan { + switch (node.parent.kind) { + case SyntaxKind.FunctionBlock: + return spanInBlock(node.parent); + + // Default to parent node + default: + return spanInNode(node.parent); + } + } + + function spanInCloseBraceToken(node: Node): TypeScript.TextSpan { + switch (node.parent.kind) { + case SyntaxKind.FunctionBlock: + // Span on close brace token + return textSpan(node); + + // Default to parent node + default: + return spanInNode(node.parent); + } + } + + function spanInCloseParenToken(node: Node): TypeScript.TextSpan { + // Is this close paren token of parameter list, set span in previous token + if (isAnyFunction(node.parent)) { + return spanInPreviousNode(node); + } + + // Default to parent node + return spanInNode(node.parent); + } + + function spanInColonToken(node: Node): TypeScript.TextSpan { + // Is this : specifying return annotation of the function declaration + if (isAnyFunction(node.parent)) { + return spanInPreviousNode(node); + } + + return spanInNode(node.parent); + } } } } \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_functions.baseline b/tests/baselines/reference/bpSpan_functions.baseline new file mode 100644 index 00000000000..623474ec93b --- /dev/null +++ b/tests/baselines/reference/bpSpan_functions.baseline @@ -0,0 +1,102 @@ + +1 >var greetings = 0; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (0 to 18) SpanInfo: {"start":0,"length":17} + >var greetings = 0 + >:=> (line 1, col 0) to (line 1, col 17) +-------------------------------- +2 >function greet(greeting: string): number { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (19 to 61) SpanInfo: {"start":66,"length":11} + >greetings++ + >:=> (line 3, col 4) to (line 3, col 15) +-------------------------------- +3 > greetings++; + + ~~~~~~~~~~~~~~~~~ => Pos: (62 to 78) SpanInfo: {"start":66,"length":11} + >greetings++ + >:=> (line 3, col 4) to (line 3, col 15) +-------------------------------- +4 > return greetings; + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (79 to 100) SpanInfo: {"start":83,"length":16} + >return greetings + >:=> (line 4, col 4) to (line 4, col 20) +-------------------------------- +5 >} + + ~~ => Pos: (101 to 102) SpanInfo: {"start":101,"length":1} + >} + >:=> (line 5, col 0) to (line 5, col 1) +-------------------------------- +6 >function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (103 to 135) SpanInfo: {"start":196,"length":11} + >greetings++ + >:=> (line 7, col 4) to (line 7, col 15) +6 >function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~~~~~~~~~~~~~~~~~~=> Pos: (136 to 155) SpanInfo: {"start":137,"length":6} + >n = 10 + >:=> (line 6, col 34) to (line 6, col 40) +6 >function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (156 to 188) SpanInfo: {"start":157,"length":23} + >...restParams: string[] + >:=> (line 6, col 54) to (line 6, col 77) +6 >function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~=> Pos: (189 to 191) SpanInfo: {"start":196,"length":11} + >greetings++ + >:=> (line 7, col 4) to (line 7, col 15) +-------------------------------- +7 > greetings++; + + ~~~~~~~~~~~~~~~~~ => Pos: (192 to 208) SpanInfo: {"start":196,"length":11} + >greetings++ + >:=> (line 7, col 4) to (line 7, col 15) +-------------------------------- +8 > return greetings; + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (209 to 230) SpanInfo: {"start":213,"length":16} + >return greetings + >:=> (line 8, col 4) to (line 8, col 20) +-------------------------------- +9 >} + + ~~ => Pos: (231 to 232) SpanInfo: {"start":231,"length":1} + >} + >:=> (line 9, col 0) to (line 9, col 1) +-------------------------------- +10 >function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (233 to 262) SpanInfo: {"start":315,"length":6} + >return + >:=> (line 12, col 4) to (line 12, col 10) +10 >function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + + ~~~~~~~~~~~~~~~~~~~~=> Pos: (263 to 282) SpanInfo: {"start":264,"length":6} + >n = 10 + >:=> (line 10, col 31) to (line 10, col 37) +10 >function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + + ~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (283 to 308) SpanInfo: {"start":284,"length":23} + >...restParams: string[] + >:=> (line 10, col 51) to (line 10, col 74) +-------------------------------- +11 >{ + + ~~ => Pos: (309 to 310) SpanInfo: {"start":315,"length":6} + >return + >:=> (line 12, col 4) to (line 12, col 10) +-------------------------------- +12 > return; + + ~~~~~~~~~~~~ => Pos: (311 to 322) SpanInfo: {"start":315,"length":6} + >return + >:=> (line 12, col 4) to (line 12, col 10) +-------------------------------- +13 >} + ~ => Pos: (323 to 323) SpanInfo: {"start":323,"length":1} + >} + >:=> (line 13, col 0) to (line 13, col 1) \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationFunctions.ts b/tests/cases/fourslash/breakpointValidationFunctions.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationFunctions.ts rename to tests/cases/fourslash/breakpointValidationFunctions.ts From abb0acc639cc62e181610afa4bfdad892debb169 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 17 Oct 2014 15:42:10 -0700 Subject: [PATCH 29/63] Breakpoints for while statement --- src/services/breakpoints.ts | 40 +++++++++-- .../baselines/reference/bpSpan_while.baseline | 70 +++++++++++++++++++ .../breakpointValidationWhile.ts | 3 + 3 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 tests/baselines/reference/bpSpan_while.baseline rename tests/cases/{fourslash_old => fourslash}/breakpointValidationWhile.ts (77%) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index ea8fd3e0a56..ebb37bb97cc 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -36,10 +36,11 @@ module ts.BreakpointResolver { return TypeScript.TextSpan.fromBounds(startNode.getStart(), (endNode || startNode).getEnd()); } - function spanInNodeIfStartsOnSameLine(node: Node): TypeScript.TextSpan { + function spanInNodeIfStartsOnSameLine(node: Node, otherwiseOnNode?: Node): TypeScript.TextSpan { if (node && sourceFile.getLineAndCharacterFromPosition(position).line === sourceFile.getLineAndCharacterFromPosition(node.getStart()).line) { return spanInNode(node); } + return spanInNode(otherwiseOnNode); } function spanInPreviousNode(node: Node): TypeScript.TextSpan { @@ -62,7 +63,7 @@ module ts.BreakpointResolver { return spanInFunctionDeclaration(node); case SyntaxKind.FunctionBlock: - return spanInBlock(node); + return spanInFirstStatementOfBlock(node); case SyntaxKind.ExpressionStatement: return spanInExpressionStatement(node); @@ -70,6 +71,9 @@ module ts.BreakpointResolver { case SyntaxKind.ReturnStatement: return spanInReturnStatement(node); + case SyntaxKind.WhileStatement: + return spanInWhileStatement(node); + // Tokens: case SyntaxKind.SemicolonToken: case SyntaxKind.EndOfFileToken: @@ -173,11 +177,27 @@ module ts.BreakpointResolver { return spanInNode(functionDeclaration.body); } - function spanInBlock(block: Block): TypeScript.TextSpan { + function spanInFirstStatementOfBlock(block: Block): TypeScript.TextSpan { // Set breakpoint in first statement return spanInNode(block.statements[0]); } + function spanInLastStatementOfBlock(block: Block): TypeScript.TextSpan { + // Set breakpoint in first statement + return spanInNode(block.statements[block.statements.length - 1]); + } + + function spanInBlock(block: Block): TypeScript.TextSpan { + switch (block.parent.kind) { + // Set on parent if on same line otherwise on first statement + case SyntaxKind.WhileStatement: + return spanInNodeIfStartsOnSameLine(block.parent, block.statements[0]); + } + + // Default action is to set on first statement + return spanInFirstStatementOfBlock(block); + } + function spanInExpressionStatement(expressionStatement: ExpressionStatement): TypeScript.TextSpan { return textSpan(expressionStatement.expression); } @@ -186,6 +206,10 @@ module ts.BreakpointResolver { return textSpan(returnStatement.getChildAt(0, sourceFile), returnStatement.expression); } + function spanInWhileStatement(whileStatement: WhileStatement): TypeScript.TextSpan { + return textSpan(whileStatement, findNextToken(whileStatement.expression, whileStatement)); + } + // Tokens: function spanInCommaToken(node: Node): TypeScript.TextSpan { switch (node.parent.kind) { @@ -202,6 +226,10 @@ module ts.BreakpointResolver { function spanInOpenBraceToken(node: Node): TypeScript.TextSpan { switch (node.parent.kind) { case SyntaxKind.FunctionBlock: + // Span on first statement + return spanInFirstStatementOfBlock(node.parent); + + case SyntaxKind.Block: return spanInBlock(node.parent); // Default to parent node @@ -216,6 +244,9 @@ module ts.BreakpointResolver { // Span on close brace token return textSpan(node); + case SyntaxKind.Block: + return spanInLastStatementOfBlock(node.parent); + // Default to parent node default: return spanInNode(node.parent); @@ -224,7 +255,8 @@ module ts.BreakpointResolver { function spanInCloseParenToken(node: Node): TypeScript.TextSpan { // Is this close paren token of parameter list, set span in previous token - if (isAnyFunction(node.parent)) { + if (isAnyFunction(node.parent) || + node.parent.kind === SyntaxKind.WhileStatement) { return spanInPreviousNode(node); } diff --git a/tests/baselines/reference/bpSpan_while.baseline b/tests/baselines/reference/bpSpan_while.baseline new file mode 100644 index 00000000000..c48e049fbd7 --- /dev/null +++ b/tests/baselines/reference/bpSpan_while.baseline @@ -0,0 +1,70 @@ + +1 >var a = 10; + + ~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":0,"length":10} + >var a = 10 + >:=> (line 1, col 0) to (line 1, col 10) +-------------------------------- +2 >while (a == 10) { + + ~~~~~~~~~~~~~~~~~~ => Pos: (12 to 29) SpanInfo: {"start":12,"length":15} + >while (a == 10) + >:=> (line 2, col 0) to (line 2, col 15) +-------------------------------- +3 > a++; + + ~~~~~~~~~ => Pos: (30 to 38) SpanInfo: {"start":34,"length":3} + >a++ + >:=> (line 3, col 4) to (line 3, col 7) +-------------------------------- +4 >} + + ~~ => Pos: (39 to 40) SpanInfo: {"start":34,"length":3} + >a++ + >:=> (line 3, col 4) to (line 3, col 7) +-------------------------------- +5 >while (a == 10) + + ~~~~~~~~~~~~~~~~~ => Pos: (41 to 57) SpanInfo: {"start":41,"length":15} + >while (a == 10) + >:=> (line 5, col 0) to (line 5, col 15) +-------------------------------- +6 >{ + + ~~ => Pos: (58 to 59) SpanInfo: {"start":64,"length":3} + >a++ + >:=> (line 7, col 4) to (line 7, col 7) +-------------------------------- +7 > a++; + + ~~~~~~~~~ => Pos: (60 to 68) SpanInfo: {"start":64,"length":3} + >a++ + >:=> (line 7, col 4) to (line 7, col 7) +-------------------------------- +8 >} + + ~~ => Pos: (69 to 70) SpanInfo: {"start":64,"length":3} + >a++ + >:=> (line 7, col 4) to (line 7, col 7) +-------------------------------- +9 >while (a == 10) a++; + + ~~~~~~~~~~~~~~~ => Pos: (71 to 85) SpanInfo: {"start":71,"length":15} + >while (a == 10) + >:=> (line 9, col 0) to (line 9, col 15) +9 >while (a == 10) a++; + + ~~~~~~~ => Pos: (86 to 92) SpanInfo: {"start":88,"length":3} + >a++ + >:=> (line 9, col 17) to (line 9, col 20) +-------------------------------- +10 >while (a == 10) + + ~~~~~~~~~~~~~~~~~ => Pos: (93 to 109) SpanInfo: {"start":93,"length":15} + >while (a == 10) + >:=> (line 10, col 0) to (line 10, col 15) +-------------------------------- +11 > a++; + ~~~~~~~~ => Pos: (110 to 117) SpanInfo: {"start":114,"length":3} + >a++ + >:=> (line 11, col 4) to (line 11, col 7) \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationWhile.ts b/tests/cases/fourslash/breakpointValidationWhile.ts similarity index 77% rename from tests/cases/fourslash_old/breakpointValidationWhile.ts rename to tests/cases/fourslash/breakpointValidationWhile.ts index 59d3c4fda3b..9fc913c702c 100644 --- a/tests/cases/fourslash_old/breakpointValidationWhile.ts +++ b/tests/cases/fourslash/breakpointValidationWhile.ts @@ -10,4 +10,7 @@ ////{ //// a++; ////} +////while (a == 10) a++; +////while (a == 10) +//// a++; verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file From a047d205efb35bdc5d7d1ef04ec72c595ce0f1aa Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 17 Oct 2014 15:42:54 -0700 Subject: [PATCH 30/63] Breakpoint span in the doStatement --- src/services/breakpoints.ts | 63 ++++++++++++++- tests/baselines/reference/bpSpan_do.baseline | 81 +++++++++++++++++++ .../breakpointValidationDo.ts | 5 +- 3 files changed, 145 insertions(+), 4 deletions(-) create mode 100644 tests/baselines/reference/bpSpan_do.baseline rename tests/cases/{fourslash_old => fourslash}/breakpointValidationDo.ts (79%) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index ebb37bb97cc..91e723380ab 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -65,6 +65,9 @@ module ts.BreakpointResolver { case SyntaxKind.FunctionBlock: return spanInFirstStatementOfBlock(node); + case SyntaxKind.Block: + return spanInBlock(node); + case SyntaxKind.ExpressionStatement: return spanInExpressionStatement(node); @@ -74,6 +77,9 @@ module ts.BreakpointResolver { case SyntaxKind.WhileStatement: return spanInWhileStatement(node); + case SyntaxKind.DoStatement: + return spanInDoStatement(node); + // Tokens: case SyntaxKind.SemicolonToken: case SyntaxKind.EndOfFileToken: @@ -88,12 +94,27 @@ module ts.BreakpointResolver { case SyntaxKind.CloseBraceToken: return spanInCloseBraceToken(node); + case SyntaxKind.OpenParenToken: + return spanInOpenParenToken(node); + case SyntaxKind.CloseParenToken: return spanInCloseParenToken(node); case SyntaxKind.ColonToken: return spanInColonToken(node); + // Keywords: + case SyntaxKind.WhileKeyword: + return spanInWhileKeyword(node); + + case SyntaxKind.BinaryExpression: + //TODO (pick this up later) for now lets fix do-while baseline + if (node.parent.kind === SyntaxKind.DoStatement) { + // Set span as if on while keyword + return spanInPreviousNode(node); + } + // Default action for now + default: // Default go to parent to set the breakpoint return spanInNode(node.parent); @@ -210,6 +231,10 @@ module ts.BreakpointResolver { return textSpan(whileStatement, findNextToken(whileStatement.expression, whileStatement)); } + function spanInDoStatement(doStatement: DoStatement): TypeScript.TextSpan { + return spanInNode(doStatement.statement); + } + // Tokens: function spanInCommaToken(node: Node): TypeScript.TextSpan { switch (node.parent.kind) { @@ -253,11 +278,33 @@ module ts.BreakpointResolver { } } + function spanInOpenParenToken(node: Node): TypeScript.TextSpan { + if (node.parent.kind === SyntaxKind.DoStatement) { + // Go to while keyword and do action instead + return spanInPreviousNode(node); + } + + // Default to parent node + return spanInNode(node.parent); + } + function spanInCloseParenToken(node: Node): TypeScript.TextSpan { // Is this close paren token of parameter list, set span in previous token - if (isAnyFunction(node.parent) || - node.parent.kind === SyntaxKind.WhileStatement) { - return spanInPreviousNode(node); + switch (node.parent.kind) { + case SyntaxKind.FunctionExpression: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.ArrowFunction: + case SyntaxKind.Method: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.Constructor: + case SyntaxKind.WhileStatement: + case SyntaxKind.DoStatement: + return spanInPreviousNode(node); + + // Default to parent node + default: + return spanInNode(node.parent); } // Default to parent node @@ -272,6 +319,16 @@ module ts.BreakpointResolver { return spanInNode(node.parent); } + + function spanInWhileKeyword(node: Node): TypeScript.TextSpan { + if (node.parent.kind === SyntaxKind.DoStatement) { + // Set span on while expression + return textSpan(node, findNextToken((node.parent).expression, node.parent)); + } + + // Default to parent node + return spanInNode(node.parent); + } } } } \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_do.baseline b/tests/baselines/reference/bpSpan_do.baseline new file mode 100644 index 00000000000..0e8559ce65f --- /dev/null +++ b/tests/baselines/reference/bpSpan_do.baseline @@ -0,0 +1,81 @@ + +1 >var i = 0; + + ~~~~~~~~~~~ => Pos: (0 to 10) SpanInfo: {"start":0,"length":9} + >var i = 0 + >:=> (line 1, col 0) to (line 1, col 9) +-------------------------------- +2 >do + + ~~~ => Pos: (11 to 13) SpanInfo: {"start":20,"length":3} + >i++ + >:=> (line 4, col 4) to (line 4, col 7) +-------------------------------- +3 >{ + + ~~ => Pos: (14 to 15) SpanInfo: {"start":20,"length":3} + >i++ + >:=> (line 4, col 4) to (line 4, col 7) +-------------------------------- +4 > i++; + + ~~~~~~~~~ => Pos: (16 to 24) SpanInfo: {"start":20,"length":3} + >i++ + >:=> (line 4, col 4) to (line 4, col 7) +-------------------------------- +5 >} while (i < 10); + + ~ => Pos: (25 to 25) SpanInfo: {"start":20,"length":3} + >i++ + >:=> (line 4, col 4) to (line 4, col 7) +5 >} while (i < 10); + + ~~~~~~~~~~~~~~~~~ => Pos: (26 to 42) SpanInfo: {"start":27,"length":14} + >while (i < 10) + >:=> (line 5, col 2) to (line 5, col 16) +-------------------------------- +6 >do { + + ~~~~~ => Pos: (43 to 47) SpanInfo: {"start":52,"length":3} + >i++ + >:=> (line 7, col 4) to (line 7, col 7) +-------------------------------- +7 > i++; + + ~~~~~~~~~ => Pos: (48 to 56) SpanInfo: {"start":52,"length":3} + >i++ + >:=> (line 7, col 4) to (line 7, col 7) +-------------------------------- +8 >} while (i < 20); + + ~ => Pos: (57 to 57) SpanInfo: {"start":52,"length":3} + >i++ + >:=> (line 7, col 4) to (line 7, col 7) +8 >} while (i < 20); + + ~~~~~~~~~~~~~~~~~ => Pos: (58 to 74) SpanInfo: {"start":59,"length":14} + >while (i < 20) + >:=> (line 8, col 2) to (line 8, col 16) +-------------------------------- +9 >do { + + ~~~~~ => Pos: (75 to 79) SpanInfo: {"start":84,"length":3} + >i++ + >:=> (line 10, col 4) to (line 10, col 7) +-------------------------------- +10 > i++; + + ~~~~~~~~~ => Pos: (80 to 88) SpanInfo: {"start":84,"length":3} + >i++ + >:=> (line 10, col 4) to (line 10, col 7) +-------------------------------- +11 >} + + ~~~ => Pos: (89 to 91) SpanInfo: {"start":84,"length":3} + >i++ + >:=> (line 10, col 4) to (line 10, col 7) +-------------------------------- +12 >while (i < 30); + ~~~~~~~~~~~~~~~ => Pos: (92 to 106) SpanInfo: {"start":92,"length":14} + >while (i < 30) + >:=> (line 12, col 0) to (line 12, col 14) \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationDo.ts b/tests/cases/fourslash/breakpointValidationDo.ts similarity index 79% rename from tests/cases/fourslash_old/breakpointValidationDo.ts rename to tests/cases/fourslash/breakpointValidationDo.ts index 0c1c28b4b44..e0d02ad75f6 100644 --- a/tests/cases/fourslash_old/breakpointValidationDo.ts +++ b/tests/cases/fourslash/breakpointValidationDo.ts @@ -10,5 +10,8 @@ ////do { //// i++; ////} while (i < 20); - +////do { +//// i++; +////} +////while (i < 30); verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file From 71e96bea9b5b74aa8b07697e680135fc619741d5 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 17 Oct 2014 15:43:40 -0700 Subject: [PATCH 31/63] Breakpoint span in the debugger statement --- src/services/breakpoints.ts | 8 ++++++++ tests/baselines/reference/bpSpan_debugger.baseline | 5 +++++ .../breakpointValidationDebugger.ts | 0 3 files changed, 13 insertions(+) create mode 100644 tests/baselines/reference/bpSpan_debugger.baseline rename tests/cases/{fourslash_old => fourslash}/breakpointValidationDebugger.ts (100%) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 91e723380ab..56146b9d60d 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -80,6 +80,9 @@ module ts.BreakpointResolver { case SyntaxKind.DoStatement: return spanInDoStatement(node); + case SyntaxKind.DebuggerStatement: + return spanInDebuggerStatement(node); + // Tokens: case SyntaxKind.SemicolonToken: case SyntaxKind.EndOfFileToken: @@ -235,6 +238,11 @@ module ts.BreakpointResolver { return spanInNode(doStatement.statement); } + function spanInDebuggerStatement(node: Node): TypeScript.TextSpan { + // Set breakpoint on debugger keyword + return textSpan(node.getChildAt(0, sourceFile)); + } + // Tokens: function spanInCommaToken(node: Node): TypeScript.TextSpan { switch (node.parent.kind) { diff --git a/tests/baselines/reference/bpSpan_debugger.baseline b/tests/baselines/reference/bpSpan_debugger.baseline new file mode 100644 index 00000000000..700ef7a56a9 --- /dev/null +++ b/tests/baselines/reference/bpSpan_debugger.baseline @@ -0,0 +1,5 @@ + +1 >debugger; + ~~~~~~~~~ => Pos: (0 to 8) SpanInfo: {"start":0,"length":8} + >debugger + >:=> (line 1, col 0) to (line 1, col 8) \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationDebugger.ts b/tests/cases/fourslash/breakpointValidationDebugger.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationDebugger.ts rename to tests/cases/fourslash/breakpointValidationDebugger.ts From 7425aedd592d1dd268a427bf1ac59a0407948fdc Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 17 Oct 2014 15:45:17 -0700 Subject: [PATCH 32/63] Breakpoints for if else construct --- src/services/breakpoints.ts | 16 +++ .../reference/bpSpan_ifElse.baseline | 110 ++++++++++++++++++ .../breakpointValidationIfElse.ts | 0 3 files changed, 126 insertions(+) create mode 100644 tests/baselines/reference/bpSpan_ifElse.baseline rename tests/cases/{fourslash_old => fourslash}/breakpointValidationIfElse.ts (100%) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 56146b9d60d..4398b559f66 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -47,6 +47,10 @@ module ts.BreakpointResolver { return spanInNode(findPrecedingToken(node.pos, sourceFile)); } + function spanInNextNode(node: Node): TypeScript.TextSpan { + return spanInNode(findNextToken(node, node.parent)); + } + function spanInNode(node: Node): TypeScript.TextSpan { if (node) { switch (node.kind) { @@ -83,6 +87,9 @@ module ts.BreakpointResolver { case SyntaxKind.DebuggerStatement: return spanInDebuggerStatement(node); + case SyntaxKind.IfStatement: + return spanInIfStatement(node); + // Tokens: case SyntaxKind.SemicolonToken: case SyntaxKind.EndOfFileToken: @@ -110,6 +117,9 @@ module ts.BreakpointResolver { case SyntaxKind.WhileKeyword: return spanInWhileKeyword(node); + case SyntaxKind.ElseKeyword: + return spanInNextNode(node); + case SyntaxKind.BinaryExpression: //TODO (pick this up later) for now lets fix do-while baseline if (node.parent.kind === SyntaxKind.DoStatement) { @@ -215,6 +225,7 @@ module ts.BreakpointResolver { switch (block.parent.kind) { // Set on parent if on same line otherwise on first statement case SyntaxKind.WhileStatement: + case SyntaxKind.IfStatement: return spanInNodeIfStartsOnSameLine(block.parent, block.statements[0]); } @@ -243,6 +254,11 @@ module ts.BreakpointResolver { return textSpan(node.getChildAt(0, sourceFile)); } + function spanInIfStatement(ifStatement: IfStatement): TypeScript.TextSpan { + // set on if(..) span + return textSpan(ifStatement, findNextToken(ifStatement.expression, ifStatement)); + } + // Tokens: function spanInCommaToken(node: Node): TypeScript.TextSpan { switch (node.parent.kind) { diff --git a/tests/baselines/reference/bpSpan_ifElse.baseline b/tests/baselines/reference/bpSpan_ifElse.baseline new file mode 100644 index 00000000000..c325ade25f0 --- /dev/null +++ b/tests/baselines/reference/bpSpan_ifElse.baseline @@ -0,0 +1,110 @@ + +1 >var i = 10; + + ~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":0,"length":10} + >var i = 10 + >:=> (line 1, col 0) to (line 1, col 10) +-------------------------------- +2 >if (i == 10) { + + ~~~~~~~~~~~~~~~ => Pos: (12 to 26) SpanInfo: {"start":12,"length":12} + >if (i == 10) + >:=> (line 2, col 0) to (line 2, col 12) +-------------------------------- +3 > i++; + + ~~~~~~~~~ => Pos: (27 to 35) SpanInfo: {"start":31,"length":3} + >i++ + >:=> (line 3, col 4) to (line 3, col 7) +-------------------------------- +4 >} else + + ~ => Pos: (36 to 36) SpanInfo: {"start":31,"length":3} + >i++ + >:=> (line 3, col 4) to (line 3, col 7) +4 >} else + + ~~~~~~ => Pos: (37 to 42) SpanInfo: undefined +-------------------------------- +5 >{ + + ~~ => Pos: (43 to 44) SpanInfo: undefined +-------------------------------- +6 >} + + ~~ => Pos: (45 to 46) SpanInfo: undefined +-------------------------------- +7 >if (i == 10) + + ~~~~~~~~~~~~~ => Pos: (47 to 59) SpanInfo: {"start":47,"length":12} + >if (i == 10) + >:=> (line 7, col 0) to (line 7, col 12) +-------------------------------- +8 >{ + + ~~ => Pos: (60 to 61) SpanInfo: {"start":66,"length":3} + >i++ + >:=> (line 9, col 4) to (line 9, col 7) +-------------------------------- +9 > i++; + + ~~~~~~~~~ => Pos: (62 to 70) SpanInfo: {"start":66,"length":3} + >i++ + >:=> (line 9, col 4) to (line 9, col 7) +-------------------------------- +10 >} + + ~~ => Pos: (71 to 72) SpanInfo: {"start":66,"length":3} + >i++ + >:=> (line 9, col 4) to (line 9, col 7) +-------------------------------- +11 >else if (i == 20) { + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (73 to 92) SpanInfo: {"start":78,"length":12} + >if (i == 20) + >:=> (line 11, col 5) to (line 11, col 17) +-------------------------------- +12 > i--; + + ~~~~~~~~~ => Pos: (93 to 101) SpanInfo: {"start":97,"length":3} + >i-- + >:=> (line 12, col 4) to (line 12, col 7) +-------------------------------- +13 >} else if (i == 30) { + + ~ => Pos: (102 to 102) SpanInfo: {"start":97,"length":3} + >i-- + >:=> (line 12, col 4) to (line 12, col 7) +13 >} else if (i == 30) { + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (103 to 123) SpanInfo: {"start":109,"length":12} + >if (i == 30) + >:=> (line 13, col 7) to (line 13, col 19) +-------------------------------- +14 > i += 70; + + ~~~~~~~~~~~~~ => Pos: (124 to 136) SpanInfo: {"start":128,"length":7} + >i += 70 + >:=> (line 14, col 4) to (line 14, col 11) +-------------------------------- +15 >} else { + + ~ => Pos: (137 to 137) SpanInfo: {"start":128,"length":7} + >i += 70 + >:=> (line 14, col 4) to (line 14, col 11) +15 >} else { + + ~~~~~~~~ => Pos: (138 to 145) SpanInfo: {"start":150,"length":3} + >i-- + >:=> (line 16, col 4) to (line 16, col 7) +-------------------------------- +16 > i--; + + ~~~~~~~~~ => Pos: (146 to 154) SpanInfo: {"start":150,"length":3} + >i-- + >:=> (line 16, col 4) to (line 16, col 7) +-------------------------------- +17 >} + ~ => Pos: (155 to 155) SpanInfo: {"start":150,"length":3} + >i-- + >:=> (line 16, col 4) to (line 16, col 7) \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationIfElse.ts b/tests/cases/fourslash/breakpointValidationIfElse.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationIfElse.ts rename to tests/cases/fourslash/breakpointValidationIfElse.ts From 6fbf0d672cd76d14f1ac7b5342a09fa52fcab2de Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 17 Oct 2014 15:46:36 -0700 Subject: [PATCH 33/63] Breakpoints in labeled statements --- src/services/breakpoints.ts | 7 +++++++ tests/baselines/reference/bpSpan_labeled.baseline | 11 +++++++++++ .../breakpointValidationLabeled.ts | 0 3 files changed, 18 insertions(+) create mode 100644 tests/baselines/reference/bpSpan_labeled.baseline rename tests/cases/{fourslash_old => fourslash}/breakpointValidationLabeled.ts (100%) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 4398b559f66..a2a19d89626 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -90,6 +90,9 @@ module ts.BreakpointResolver { case SyntaxKind.IfStatement: return spanInIfStatement(node); + case SyntaxKind.LabeledStatement: + return spanInLabeledStatement(node); + // Tokens: case SyntaxKind.SemicolonToken: case SyntaxKind.EndOfFileToken: @@ -258,6 +261,10 @@ module ts.BreakpointResolver { // set on if(..) span return textSpan(ifStatement, findNextToken(ifStatement.expression, ifStatement)); } + + function spanInLabeledStatement(labeledStatement: LabeledStatement): TypeScript.TextSpan { + return spanInNode(labeledStatement.statement); + } // Tokens: function spanInCommaToken(node: Node): TypeScript.TextSpan { diff --git a/tests/baselines/reference/bpSpan_labeled.baseline b/tests/baselines/reference/bpSpan_labeled.baseline new file mode 100644 index 00000000000..8c2d23adedb --- /dev/null +++ b/tests/baselines/reference/bpSpan_labeled.baseline @@ -0,0 +1,11 @@ + +1 >x: + + ~~~ => Pos: (0 to 2) SpanInfo: {"start":3,"length":10} + >var b = 10 + >:=> (line 2, col 0) to (line 2, col 10) +-------------------------------- +2 >var b = 10; + ~~~~~~~~~~~ => Pos: (3 to 13) SpanInfo: {"start":3,"length":10} + >var b = 10 + >:=> (line 2, col 0) to (line 2, col 10) \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationLabeled.ts b/tests/cases/fourslash/breakpointValidationLabeled.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationLabeled.ts rename to tests/cases/fourslash/breakpointValidationLabeled.ts From c81c0bfdce96e1519db994b6ccff0643d7dfef47 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 17 Oct 2014 15:48:00 -0700 Subject: [PATCH 34/63] Breakpoints in break/continue statements --- src/services/breakpoints.ts | 8 +++ .../reference/bpSpan_breakOrContinue.baseline | 71 +++++++++++++++++++ .../breakpointValidationBreakOrContinue.ts | 17 +++++ 3 files changed, 96 insertions(+) create mode 100644 tests/baselines/reference/bpSpan_breakOrContinue.baseline create mode 100644 tests/cases/fourslash/breakpointValidationBreakOrContinue.ts diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index a2a19d89626..deb0a2275a4 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -93,6 +93,10 @@ module ts.BreakpointResolver { case SyntaxKind.LabeledStatement: return spanInLabeledStatement(node); + case SyntaxKind.BreakStatement: + case SyntaxKind.ContinueStatement: + return spanInBreakOrContinueStatement(node); + // Tokens: case SyntaxKind.SemicolonToken: case SyntaxKind.EndOfFileToken: @@ -265,6 +269,10 @@ module ts.BreakpointResolver { function spanInLabeledStatement(labeledStatement: LabeledStatement): TypeScript.TextSpan { return spanInNode(labeledStatement.statement); } + + function spanInBreakOrContinueStatement(breakOrContinueStatement: BreakOrContinueStatement): TypeScript.TextSpan { + return textSpan(breakOrContinueStatement, breakOrContinueStatement.label || breakOrContinueStatement.getChildAt(0)); + } // Tokens: function spanInCommaToken(node: Node): TypeScript.TextSpan { diff --git a/tests/baselines/reference/bpSpan_breakOrContinue.baseline b/tests/baselines/reference/bpSpan_breakOrContinue.baseline new file mode 100644 index 00000000000..617589b9047 --- /dev/null +++ b/tests/baselines/reference/bpSpan_breakOrContinue.baseline @@ -0,0 +1,71 @@ + +1 >while (true) { + + ~~~~~~~~~~~~~~~ => Pos: (0 to 14) SpanInfo: {"start":0,"length":12} + >while (true) + >:=> (line 1, col 0) to (line 1, col 12) +-------------------------------- +2 > break; + + ~~~~~~~~~~~ => Pos: (15 to 25) SpanInfo: {"start":19,"length":5} + >break + >:=> (line 2, col 4) to (line 2, col 9) +-------------------------------- +3 >} + + ~~ => Pos: (26 to 27) SpanInfo: {"start":19,"length":5} + >break + >:=> (line 2, col 4) to (line 2, col 9) +-------------------------------- +4 >y: while (true) { + + ~~~~~~~~~~~~~~~~~~ => Pos: (28 to 45) SpanInfo: {"start":31,"length":12} + >while (true) + >:=> (line 4, col 3) to (line 4, col 15) +-------------------------------- +5 > break y; + + ~~~~~~~~~~~~~ => Pos: (46 to 58) SpanInfo: {"start":50,"length":7} + >break y + >:=> (line 5, col 4) to (line 5, col 11) +-------------------------------- +6 >} + + ~~ => Pos: (59 to 60) SpanInfo: {"start":50,"length":7} + >break y + >:=> (line 5, col 4) to (line 5, col 11) +-------------------------------- +7 >while (true) { + + ~~~~~~~~~~~~~~~ => Pos: (61 to 75) SpanInfo: {"start":61,"length":12} + >while (true) + >:=> (line 7, col 0) to (line 7, col 12) +-------------------------------- +8 > continue; + + ~~~~~~~~~~~~~~ => Pos: (76 to 89) SpanInfo: {"start":80,"length":8} + >continue + >:=> (line 8, col 4) to (line 8, col 12) +-------------------------------- +9 >} + + ~~ => Pos: (90 to 91) SpanInfo: {"start":80,"length":8} + >continue + >:=> (line 8, col 4) to (line 8, col 12) +-------------------------------- +10 >z: while (true) { + + ~~~~~~~~~~~~~~~~~~ => Pos: (92 to 109) SpanInfo: {"start":95,"length":12} + >while (true) + >:=> (line 10, col 3) to (line 10, col 15) +-------------------------------- +11 > continue z; + + ~~~~~~~~~~~~~~~~ => Pos: (110 to 125) SpanInfo: {"start":114,"length":10} + >continue z + >:=> (line 11, col 4) to (line 11, col 14) +-------------------------------- +12 >} + ~ => Pos: (126 to 126) SpanInfo: {"start":114,"length":10} + >continue z + >:=> (line 11, col 4) to (line 11, col 14) \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationBreakOrContinue.ts b/tests/cases/fourslash/breakpointValidationBreakOrContinue.ts new file mode 100644 index 00000000000..f3e92a88dfb --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationBreakOrContinue.ts @@ -0,0 +1,17 @@ +/// + +// @BaselineFile: bpSpan_breakOrContinue.baseline +// @Filename: bpSpan_breakOrContinue.ts +////while (true) { +//// break; +////} +////y: while (true) { +//// break y; +////} +////while (true) { +//// continue; +////} +////z: while (true) { +//// continue z; +////} +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file From b97f87624eb430f40eac6599352b3be02c80c991 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 17 Oct 2014 15:48:41 -0700 Subject: [PATCH 35/63] Breakpoints in for statement --- src/services/breakpoints.ts | 82 ++++-- tests/baselines/reference/bpSpan_for.baseline | 238 ++++++++++++++++++ .../breakpointValidationFor.ts | 0 3 files changed, 302 insertions(+), 18 deletions(-) create mode 100644 tests/baselines/reference/bpSpan_for.baseline rename tests/cases/{fourslash_old => fourslash}/breakpointValidationFor.ts (100%) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index deb0a2275a4..5235fd2829c 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -37,7 +37,7 @@ module ts.BreakpointResolver { } function spanInNodeIfStartsOnSameLine(node: Node, otherwiseOnNode?: Node): TypeScript.TextSpan { - if (node && sourceFile.getLineAndCharacterFromPosition(position).line === sourceFile.getLineAndCharacterFromPosition(node.getStart()).line) { + if (node && lineOfPosition === sourceFile.getLineAndCharacterFromPosition(node.getStart()).line) { return spanInNode(node); } return spanInNode(otherwiseOnNode); @@ -97,6 +97,14 @@ module ts.BreakpointResolver { case SyntaxKind.ContinueStatement: return spanInBreakOrContinueStatement(node); + case SyntaxKind.ForStatement: + return spanInForStatement(node); + + case SyntaxKind.BinaryExpression: + case SyntaxKind.PostfixOperator: + case SyntaxKind.PrefixOperator: + return spanInExpression(node); + // Tokens: case SyntaxKind.SemicolonToken: case SyntaxKind.EndOfFileToken: @@ -127,14 +135,6 @@ module ts.BreakpointResolver { case SyntaxKind.ElseKeyword: return spanInNextNode(node); - case SyntaxKind.BinaryExpression: - //TODO (pick this up later) for now lets fix do-while baseline - if (node.parent.kind === SyntaxKind.DoStatement) { - // Set span as if on while keyword - return spanInPreviousNode(node); - } - // Default action for now - default: // Default go to parent to set the breakpoint return spanInNode(node.parent); @@ -143,25 +143,35 @@ module ts.BreakpointResolver { function spanInVariableDeclaration(variableDeclaration: VariableDeclaration): TypeScript.TextSpan { var isParentVariableStatement = variableDeclaration.parent.kind === SyntaxKind.VariableStatement; - var isfirstDeclarationOfVariableStatement = isParentVariableStatement && - (variableDeclaration.parent).declarations[0] === variableDeclaration; + var isDeclarationOfForStatement = variableDeclaration.parent.kind === SyntaxKind.ForStatement && contains((variableDeclaration.parent).declarations, variableDeclaration); + var declarations = isParentVariableStatement + ? (variableDeclaration.parent).declarations + : isDeclarationOfForStatement + ? (variableDeclaration.parent).declarations + : undefined; // Breakpoint is possible in variableDeclaration only if there is initialization if (variableDeclaration.initializer) { - if (isfirstDeclarationOfVariableStatement) { - // First declaration - include var keyword - return textSpan(variableDeclaration.parent, variableDeclaration); + if (declarations && declarations[0] === variableDeclaration) { + if (isParentVariableStatement) { + // First declaration - include var keyword + return textSpan(variableDeclaration.parent, variableDeclaration); + } + else { + Debug.assert(isDeclarationOfForStatement); + // Include var keyword from for statement declarations in the span + return textSpan(findPrecedingToken(variableDeclaration.pos, sourceFile, variableDeclaration.parent), variableDeclaration); + } } else { // Span only on this declaration return textSpan(variableDeclaration); } } - else if (!isfirstDeclarationOfVariableStatement && isParentVariableStatement) { + else if (declarations && declarations[0] !== variableDeclaration) { // If we cant set breakpoint on this declaration, set it on previous one - var variableStatement = variableDeclaration.parent; - var indexOfCurrentDeclaration = indexOf(variableStatement.declarations, variableDeclaration); - return spanInVariableDeclaration(variableStatement.declarations[indexOfCurrentDeclaration - 1]); + var indexOfCurrentDeclaration = indexOf(declarations, variableDeclaration); + return spanInVariableDeclaration(declarations[indexOfCurrentDeclaration - 1]); } } @@ -234,6 +244,10 @@ module ts.BreakpointResolver { case SyntaxKind.WhileStatement: case SyntaxKind.IfStatement: return spanInNodeIfStartsOnSameLine(block.parent, block.statements[0]); + + // Set span on previous token if it starts on same line otherwise on the first statement of the block + case SyntaxKind.ForStatement: + return spanInNodeIfStartsOnSameLine(findPrecedingToken(block.pos, sourceFile, block.parent), block.statements[0]); } // Default action is to set on first statement @@ -273,6 +287,37 @@ module ts.BreakpointResolver { function spanInBreakOrContinueStatement(breakOrContinueStatement: BreakOrContinueStatement): TypeScript.TextSpan { return textSpan(breakOrContinueStatement, breakOrContinueStatement.label || breakOrContinueStatement.getChildAt(0)); } + + function spanInForStatement(forStatement: ForStatement): TypeScript.TextSpan { + if (forStatement.declarations) { + return spanInNode(forStatement.declarations[0]); + } + if (forStatement.initializer) { + return spanInNode(forStatement.initializer); + } + if (forStatement.condition) { + return textSpan(forStatement.condition); + } + + if (forStatement.iterator) { + return textSpan(forStatement.iterator); + } + } + + function spanInExpression(expression: Expression): TypeScript.TextSpan { + //TODO (pick this up later) for now lets fix do-while baseline if (node.parent.kind === SyntaxKind.DoStatement) { + // Set span as if on while keyword + return spanInPreviousNode(node); + } + + if (node.parent.kind === SyntaxKind.ForStatement) { + // For now lets set the span on this expression, fix it later + return textSpan(expression); + } + + // Default action for now: + return spanInNode(expression.parent); + } // Tokens: function spanInCommaToken(node: Node): TypeScript.TextSpan { @@ -339,6 +384,7 @@ module ts.BreakpointResolver { case SyntaxKind.Constructor: case SyntaxKind.WhileStatement: case SyntaxKind.DoStatement: + case SyntaxKind.ForStatement: return spanInPreviousNode(node); // Default to parent node diff --git a/tests/baselines/reference/bpSpan_for.baseline b/tests/baselines/reference/bpSpan_for.baseline new file mode 100644 index 00000000000..89580008c67 --- /dev/null +++ b/tests/baselines/reference/bpSpan_for.baseline @@ -0,0 +1,238 @@ + +1 >for (var i = 0; i < 10; i++) { + + ~~~~~~~~~~~~~~~ => Pos: (0 to 14) SpanInfo: {"start":5,"length":9} + >var i = 0 + >:=> (line 1, col 5) to (line 1, col 14) +1 >for (var i = 0; i < 10; i++) { + + ~~~~~~~~ => Pos: (15 to 22) SpanInfo: {"start":16,"length":6} + >i < 10 + >:=> (line 1, col 16) to (line 1, col 22) +1 >for (var i = 0; i < 10; i++) { + + ~~~~~~~~ => Pos: (23 to 30) SpanInfo: {"start":24,"length":3} + >i++ + >:=> (line 1, col 24) to (line 1, col 27) +-------------------------------- +2 > WScript.Echo("i: " + i); + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (31 to 59) SpanInfo: {"start":35,"length":23} + >WScript.Echo("i: " + i) + >:=> (line 2, col 4) to (line 2, col 27) +-------------------------------- +3 >} + + ~~ => Pos: (60 to 61) SpanInfo: {"start":35,"length":23} + >WScript.Echo("i: " + i) + >:=> (line 2, col 4) to (line 2, col 27) +-------------------------------- +4 >for (i = 0; i < 10; i++) + + ~~~~~~~~~~~ => Pos: (62 to 72) SpanInfo: {"start":67,"length":5} + >i = 0 + >:=> (line 4, col 5) to (line 4, col 10) +4 >for (i = 0; i < 10; i++) + + ~~~~~~~~ => Pos: (73 to 80) SpanInfo: {"start":74,"length":6} + >i < 10 + >:=> (line 4, col 12) to (line 4, col 18) +4 >for (i = 0; i < 10; i++) + + ~~~~~~ => Pos: (81 to 86) SpanInfo: {"start":82,"length":3} + >i++ + >:=> (line 4, col 20) to (line 4, col 23) +-------------------------------- +5 >{ + + ~~ => Pos: (87 to 88) SpanInfo: {"start":93,"length":23} + >WScript.Echo("i: " + i) + >:=> (line 6, col 4) to (line 6, col 27) +-------------------------------- +6 > WScript.Echo("i: " + i); + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (89 to 117) SpanInfo: {"start":93,"length":23} + >WScript.Echo("i: " + i) + >:=> (line 6, col 4) to (line 6, col 27) +-------------------------------- +7 >} + + ~~ => Pos: (118 to 119) SpanInfo: {"start":93,"length":23} + >WScript.Echo("i: " + i) + >:=> (line 6, col 4) to (line 6, col 27) +-------------------------------- +8 >for (var j = 0; j < 10; ) { + + ~~~~~~~~~~~~~~~ => Pos: (120 to 134) SpanInfo: {"start":125,"length":9} + >var j = 0 + >:=> (line 8, col 5) to (line 8, col 14) +8 >for (var j = 0; j < 10; ) { + + ~~~~~~~~~~~~~ => Pos: (135 to 147) SpanInfo: {"start":136,"length":6} + >j < 10 + >:=> (line 8, col 16) to (line 8, col 22) +-------------------------------- +9 > j++; + + ~~~~~~~~~ => Pos: (148 to 156) SpanInfo: {"start":152,"length":3} + >j++ + >:=> (line 9, col 4) to (line 9, col 7) +-------------------------------- +10 > if (j == 1) { + + ~~~~~~~~~~~~~~~~~~ => Pos: (157 to 174) SpanInfo: {"start":161,"length":11} + >if (j == 1) + >:=> (line 10, col 4) to (line 10, col 15) +-------------------------------- +11 > continue; + + ~~~~~~~~~~~~~~~~~~ => Pos: (175 to 192) SpanInfo: {"start":183,"length":8} + >continue + >:=> (line 11, col 8) to (line 11, col 16) +-------------------------------- +12 > } + + ~~~~~~ => Pos: (193 to 198) SpanInfo: {"start":183,"length":8} + >continue + >:=> (line 11, col 8) to (line 11, col 16) +-------------------------------- +13 >} + + ~~ => Pos: (199 to 200) SpanInfo: {"start":161,"length":11} + >if (j == 1) + >:=> (line 10, col 4) to (line 10, col 15) +-------------------------------- +14 >for (j = 0; j < 10;) + + ~~~~~~~~~~~ => Pos: (201 to 211) SpanInfo: {"start":206,"length":5} + >j = 0 + >:=> (line 14, col 5) to (line 14, col 10) +14 >for (j = 0; j < 10;) + + ~~~~~~~~~~ => Pos: (212 to 221) SpanInfo: {"start":213,"length":6} + >j < 10 + >:=> (line 14, col 12) to (line 14, col 18) +-------------------------------- +15 >{ + + ~~ => Pos: (222 to 223) SpanInfo: {"start":228,"length":3} + >j++ + >:=> (line 16, col 4) to (line 16, col 7) +-------------------------------- +16 > j++; + + ~~~~~~~~~ => Pos: (224 to 232) SpanInfo: {"start":228,"length":3} + >j++ + >:=> (line 16, col 4) to (line 16, col 7) +-------------------------------- +17 >} + + ~~ => Pos: (233 to 234) SpanInfo: {"start":228,"length":3} + >j++ + >:=> (line 16, col 4) to (line 16, col 7) +-------------------------------- +18 >for (var k = 0;; k++) { + + ~~~~~~~~~~~~~~~~ => Pos: (235 to 250) SpanInfo: {"start":240,"length":9} + >var k = 0 + >:=> (line 18, col 5) to (line 18, col 14) +18 >for (var k = 0;; k++) { + + ~~~~~~~~ => Pos: (251 to 258) SpanInfo: {"start":252,"length":3} + >k++ + >:=> (line 18, col 17) to (line 18, col 20) +-------------------------------- +19 >} + + ~~ => Pos: (259 to 260) SpanInfo: undefined +-------------------------------- +20 >for (k = 0;; k++) + + ~~~~~~~~~~~~ => Pos: (261 to 272) SpanInfo: {"start":266,"length":5} + >k = 0 + >:=> (line 20, col 5) to (line 20, col 10) +20 >for (k = 0;; k++) + + ~~~~~~ => Pos: (273 to 278) SpanInfo: {"start":274,"length":3} + >k++ + >:=> (line 20, col 13) to (line 20, col 16) +-------------------------------- +21 >{ + + ~~ => Pos: (279 to 280) SpanInfo: undefined +-------------------------------- +22 >} + + ~~ => Pos: (281 to 282) SpanInfo: undefined +-------------------------------- +23 >for (; k < 10; k++) { + + ~~~~~~~~~~~~~~ => Pos: (283 to 296) SpanInfo: {"start":290,"length":6} + >k < 10 + >:=> (line 23, col 7) to (line 23, col 13) +23 >for (; k < 10; k++) { + + ~~~~~~~~ => Pos: (297 to 304) SpanInfo: {"start":298,"length":3} + >k++ + >:=> (line 23, col 15) to (line 23, col 18) +-------------------------------- +24 >} + + ~~ => Pos: (305 to 306) SpanInfo: undefined +-------------------------------- +25 >for (;;) { + + ~~~~~~~~~~~ => Pos: (307 to 317) SpanInfo: undefined +-------------------------------- +26 > i++; + + ~~~~~~~~~ => Pos: (318 to 326) SpanInfo: {"start":322,"length":3} + >i++ + >:=> (line 26, col 4) to (line 26, col 7) +-------------------------------- +27 >} + + ~~ => Pos: (327 to 328) SpanInfo: {"start":322,"length":3} + >i++ + >:=> (line 26, col 4) to (line 26, col 7) +-------------------------------- +28 >for (;;) + + ~~~~~~~~~ => Pos: (329 to 337) SpanInfo: undefined +-------------------------------- +29 >{ + + ~~ => Pos: (338 to 339) SpanInfo: {"start":344,"length":3} + >i++ + >:=> (line 30, col 4) to (line 30, col 7) +-------------------------------- +30 > i++; + + ~~~~~~~~~ => Pos: (340 to 348) SpanInfo: {"start":344,"length":3} + >i++ + >:=> (line 30, col 4) to (line 30, col 7) +-------------------------------- +31 >} + + ~~ => Pos: (349 to 350) SpanInfo: {"start":344,"length":3} + >i++ + >:=> (line 30, col 4) to (line 30, col 7) +-------------------------------- +32 >for (i = 0, j = 20; j < 20, i < 20; j++) { + + ~~~~~~~~~~~~~~~~~~~ => Pos: (351 to 369) SpanInfo: {"start":356,"length":13} + >i = 0, j = 20 + >:=> (line 32, col 5) to (line 32, col 18) +32 >for (i = 0, j = 20; j < 20, i < 20; j++) { + + ~~~~~~~~~~~~~~~~ => Pos: (370 to 385) SpanInfo: {"start":371,"length":14} + >j < 20, i < 20 + >:=> (line 32, col 20) to (line 32, col 34) +32 >for (i = 0, j = 20; j < 20, i < 20; j++) { + + ~~~~~~~~ => Pos: (386 to 393) SpanInfo: {"start":387,"length":3} + >j++ + >:=> (line 32, col 36) to (line 32, col 39) +-------------------------------- +33 >} + ~ => Pos: (394 to 394) SpanInfo: undefined \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationFor.ts b/tests/cases/fourslash/breakpointValidationFor.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationFor.ts rename to tests/cases/fourslash/breakpointValidationFor.ts From f5731f3e5850cf2beafe7f7038e039985dbaf38d Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 2 Sep 2014 14:59:01 -0700 Subject: [PATCH 36/63] Breakpoints in the for in statement --- src/services/breakpoints.ts | 13 +++ .../baselines/reference/bpSpan_forIn.baseline | 83 +++++++++++++++++++ .../breakpointValidationForIn.ts | 0 3 files changed, 96 insertions(+) create mode 100644 tests/baselines/reference/bpSpan_forIn.baseline rename tests/cases/{fourslash_old => fourslash}/breakpointValidationForIn.ts (100%) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 5235fd2829c..49483e87546 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -100,6 +100,9 @@ module ts.BreakpointResolver { case SyntaxKind.ForStatement: return spanInForStatement(node); + case SyntaxKind.ForInStatement: + return spanInForInStatement(node); + case SyntaxKind.BinaryExpression: case SyntaxKind.PostfixOperator: case SyntaxKind.PrefixOperator: @@ -142,6 +145,11 @@ module ts.BreakpointResolver { } function spanInVariableDeclaration(variableDeclaration: VariableDeclaration): TypeScript.TextSpan { + // If declaration of for in statement, just set the span in parent + if (variableDeclaration.parent.kind === SyntaxKind.ForInStatement) { + return spanInForInStatement(variableDeclaration.parent); + } + var isParentVariableStatement = variableDeclaration.parent.kind === SyntaxKind.VariableStatement; var isDeclarationOfForStatement = variableDeclaration.parent.kind === SyntaxKind.ForStatement && contains((variableDeclaration.parent).declarations, variableDeclaration); var declarations = isParentVariableStatement @@ -243,6 +251,7 @@ module ts.BreakpointResolver { // Set on parent if on same line otherwise on first statement case SyntaxKind.WhileStatement: case SyntaxKind.IfStatement: + case SyntaxKind.ForInStatement: return spanInNodeIfStartsOnSameLine(block.parent, block.statements[0]); // Set span on previous token if it starts on same line otherwise on the first statement of the block @@ -304,6 +313,10 @@ module ts.BreakpointResolver { } } + function spanInForInStatement(forInStatement: ForInStatement): TypeScript.TextSpan { + return textSpan(forInStatement, findNextToken(forInStatement.expression, forInStatement)); + } + function spanInExpression(expression: Expression): TypeScript.TextSpan { //TODO (pick this up later) for now lets fix do-while baseline if (node.parent.kind === SyntaxKind.DoStatement) { // Set span as if on while keyword diff --git a/tests/baselines/reference/bpSpan_forIn.baseline b/tests/baselines/reference/bpSpan_forIn.baseline new file mode 100644 index 00000000000..5c2e6b6d01e --- /dev/null +++ b/tests/baselines/reference/bpSpan_forIn.baseline @@ -0,0 +1,83 @@ + +1 >for (var x in String) { + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (0 to 23) SpanInfo: {"start":0,"length":21} + >for (var x in String) + >:=> (line 1, col 0) to (line 1, col 21) +-------------------------------- +2 > WScript.Echo(x); + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (24 to 44) SpanInfo: {"start":28,"length":15} + >WScript.Echo(x) + >:=> (line 2, col 4) to (line 2, col 19) +-------------------------------- +3 >} + + ~~ => Pos: (45 to 46) SpanInfo: {"start":28,"length":15} + >WScript.Echo(x) + >:=> (line 2, col 4) to (line 2, col 19) +-------------------------------- +4 >for (x in String) { + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (47 to 66) SpanInfo: {"start":47,"length":17} + >for (x in String) + >:=> (line 4, col 0) to (line 4, col 17) +-------------------------------- +5 > WScript.Echo(x); + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (67 to 87) SpanInfo: {"start":71,"length":15} + >WScript.Echo(x) + >:=> (line 5, col 4) to (line 5, col 19) +-------------------------------- +6 >} + + ~~ => Pos: (88 to 89) SpanInfo: {"start":71,"length":15} + >WScript.Echo(x) + >:=> (line 5, col 4) to (line 5, col 19) +-------------------------------- +7 >for (var x2 in String) + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (90 to 112) SpanInfo: {"start":90,"length":22} + >for (var x2 in String) + >:=> (line 7, col 0) to (line 7, col 22) +-------------------------------- +8 >{ + + ~~ => Pos: (113 to 114) SpanInfo: {"start":119,"length":16} + >WScript.Echo(x2) + >:=> (line 9, col 4) to (line 9, col 20) +-------------------------------- +9 > WScript.Echo(x2); + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (115 to 136) SpanInfo: {"start":119,"length":16} + >WScript.Echo(x2) + >:=> (line 9, col 4) to (line 9, col 20) +-------------------------------- +10 >} + + ~~ => Pos: (137 to 138) SpanInfo: {"start":119,"length":16} + >WScript.Echo(x2) + >:=> (line 9, col 4) to (line 9, col 20) +-------------------------------- +11 >for (x in String) + + ~~~~~~~~~~~~~~~~~~ => Pos: (139 to 156) SpanInfo: {"start":139,"length":17} + >for (x in String) + >:=> (line 11, col 0) to (line 11, col 17) +-------------------------------- +12 >{ + + ~~ => Pos: (157 to 158) SpanInfo: {"start":163,"length":15} + >WScript.Echo(x) + >:=> (line 13, col 4) to (line 13, col 19) +-------------------------------- +13 > WScript.Echo(x); + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (159 to 179) SpanInfo: {"start":163,"length":15} + >WScript.Echo(x) + >:=> (line 13, col 4) to (line 13, col 19) +-------------------------------- +14 >} + ~ => Pos: (180 to 180) SpanInfo: {"start":163,"length":15} + >WScript.Echo(x) + >:=> (line 13, col 4) to (line 13, col 19) \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationForIn.ts b/tests/cases/fourslash/breakpointValidationForIn.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationForIn.ts rename to tests/cases/fourslash/breakpointValidationForIn.ts From 5bdeaa9e6d3a23f753bf016a2231b2edf7b567a4 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 17 Oct 2014 20:13:55 -0700 Subject: [PATCH 37/63] Breakpoints in the switch statement --- src/services/breakpoints.ts | 27 +++ .../reference/bpSpan_switch.baseline | 167 ++++++++++++++++++ .../breakpointValidationSwitch.ts | 0 3 files changed, 194 insertions(+) create mode 100644 tests/baselines/reference/bpSpan_switch.baseline rename tests/cases/{fourslash_old => fourslash}/breakpointValidationSwitch.ts (100%) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 49483e87546..fc62884e333 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -103,6 +103,13 @@ module ts.BreakpointResolver { case SyntaxKind.ForInStatement: return spanInForInStatement(node); + case SyntaxKind.SwitchStatement: + return spanInSwitchStatement(node); + + case SyntaxKind.CaseClause: + case SyntaxKind.DefaultClause: + return spanInCaseOrDefaultClause(node); + case SyntaxKind.BinaryExpression: case SyntaxKind.PostfixOperator: case SyntaxKind.PrefixOperator: @@ -317,6 +324,14 @@ module ts.BreakpointResolver { return textSpan(forInStatement, findNextToken(forInStatement.expression, forInStatement)); } + function spanInSwitchStatement(switchStatement: SwitchStatement): TypeScript.TextSpan { + return textSpan(switchStatement, findNextToken(switchStatement.expression, switchStatement)); + } + + function spanInCaseOrDefaultClause(caseOrDefaultClause: CaseOrDefaultClause): TypeScript.TextSpan { + return spanInNode(caseOrDefaultClause.statements[0]); + } + function spanInExpression(expression: Expression): TypeScript.TextSpan { //TODO (pick this up later) for now lets fix do-while baseline if (node.parent.kind === SyntaxKind.DoStatement) { // Set span as if on while keyword @@ -354,6 +369,9 @@ module ts.BreakpointResolver { case SyntaxKind.Block: return spanInBlock(node.parent); + case SyntaxKind.SwitchStatement: + return spanInNodeIfStartsOnSameLine(node.parent, (node.parent).clauses[0]); + // Default to parent node default: return spanInNode(node.parent); @@ -369,6 +387,15 @@ module ts.BreakpointResolver { case SyntaxKind.Block: return spanInLastStatementOfBlock(node.parent); + case SyntaxKind.SwitchStatement: + // breakpoint in last statement of the last clause + var switchStatement = node.parent; + var lastClause = switchStatement.clauses[switchStatement.clauses.length - 1]; + if (lastClause) { + return spanInNode(lastClause.statements[lastClause.statements.length - 1]); + } + return undefined; + // Default to parent node default: return spanInNode(node.parent); diff --git a/tests/baselines/reference/bpSpan_switch.baseline b/tests/baselines/reference/bpSpan_switch.baseline new file mode 100644 index 00000000000..7629f9a8063 --- /dev/null +++ b/tests/baselines/reference/bpSpan_switch.baseline @@ -0,0 +1,167 @@ + +1 >var x = 10; + + ~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":0,"length":10} + >var x = 10 + >:=> (line 1, col 0) to (line 1, col 10) +-------------------------------- +2 >switch (x) { + + ~~~~~~~~~~~~~ => Pos: (12 to 24) SpanInfo: {"start":12,"length":10} + >switch (x) + >:=> (line 2, col 0) to (line 2, col 10) +-------------------------------- +3 > case 5: + + ~~~~~~~~~~~~ => Pos: (25 to 36) SpanInfo: {"start":45,"length":3} + >x++ + >:=> (line 4, col 8) to (line 4, col 11) +-------------------------------- +4 > x++; + + ~~~~~~~~~~~~~ => Pos: (37 to 49) SpanInfo: {"start":45,"length":3} + >x++ + >:=> (line 4, col 8) to (line 4, col 11) +-------------------------------- +5 > break; + + ~~~~~~~~~~~~~~~ => Pos: (50 to 64) SpanInfo: {"start":58,"length":5} + >break + >:=> (line 5, col 8) to (line 5, col 13) +-------------------------------- +6 > case 10: + + ~~~~~~~~~~~~~ => Pos: (65 to 77) SpanInfo: {"start":100,"length":3} + >x-- + >:=> (line 8, col 12) to (line 8, col 15) +-------------------------------- +7 > { + + ~~~~~~~~~~ => Pos: (78 to 87) SpanInfo: {"start":100,"length":3} + >x-- + >:=> (line 8, col 12) to (line 8, col 15) +-------------------------------- +8 > x--; + + ~~~~~~~~~~~~~~~~~ => Pos: (88 to 104) SpanInfo: {"start":100,"length":3} + >x-- + >:=> (line 8, col 12) to (line 8, col 15) +-------------------------------- +9 > break; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (105 to 123) SpanInfo: {"start":117,"length":5} + >break + >:=> (line 9, col 12) to (line 9, col 17) +-------------------------------- +10 > } + + ~~~~~~~~~~ => Pos: (124 to 133) SpanInfo: {"start":117,"length":5} + >break + >:=> (line 9, col 12) to (line 9, col 17) +-------------------------------- +11 > default: + + ~~~~~~~~~~~~~ => Pos: (134 to 146) SpanInfo: {"start":155,"length":9} + >x = x *10 + >:=> (line 12, col 8) to (line 12, col 17) +-------------------------------- +12 > x = x *10; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (147 to 165) SpanInfo: {"start":155,"length":9} + >x = x *10 + >:=> (line 12, col 8) to (line 12, col 17) +-------------------------------- +13 >} + + ~~ => Pos: (166 to 167) SpanInfo: {"start":155,"length":9} + >x = x *10 + >:=> (line 12, col 8) to (line 12, col 17) +-------------------------------- +14 >switch (x) + + ~~~~~~~~~~~ => Pos: (168 to 178) SpanInfo: {"start":168,"length":10} + >switch (x) + >:=> (line 14, col 0) to (line 14, col 10) +-------------------------------- +15 >{ + + ~~ => Pos: (179 to 180) SpanInfo: {"start":201,"length":3} + >x++ + >:=> (line 17, col 8) to (line 17, col 11) +-------------------------------- +16 > case 5: + + ~~~~~~~~~~~~ => Pos: (181 to 192) SpanInfo: {"start":201,"length":3} + >x++ + >:=> (line 17, col 8) to (line 17, col 11) +-------------------------------- +17 > x++; + + ~~~~~~~~~~~~~ => Pos: (193 to 205) SpanInfo: {"start":201,"length":3} + >x++ + >:=> (line 17, col 8) to (line 17, col 11) +-------------------------------- +18 > break; + + ~~~~~~~~~~~~~~~ => Pos: (206 to 220) SpanInfo: {"start":214,"length":5} + >break + >:=> (line 18, col 8) to (line 18, col 13) +-------------------------------- +19 > case 10: + + ~~~~~~~~~~~~~ => Pos: (221 to 233) SpanInfo: {"start":256,"length":3} + >x-- + >:=> (line 21, col 12) to (line 21, col 15) +-------------------------------- +20 > { + + ~~~~~~~~~~ => Pos: (234 to 243) SpanInfo: {"start":256,"length":3} + >x-- + >:=> (line 21, col 12) to (line 21, col 15) +-------------------------------- +21 > x--; + + ~~~~~~~~~~~~~~~~~ => Pos: (244 to 260) SpanInfo: {"start":256,"length":3} + >x-- + >:=> (line 21, col 12) to (line 21, col 15) +-------------------------------- +22 > break; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (261 to 279) SpanInfo: {"start":273,"length":5} + >break + >:=> (line 22, col 12) to (line 22, col 17) +-------------------------------- +23 > } + + ~~~~~~~~~~ => Pos: (280 to 289) SpanInfo: {"start":273,"length":5} + >break + >:=> (line 22, col 12) to (line 22, col 17) +-------------------------------- +24 > default: + + ~~~~~~~~~~~~~ => Pos: (290 to 302) SpanInfo: {"start":325,"length":10} + >x = x * 10 + >:=> (line 26, col 12) to (line 26, col 22) +-------------------------------- +25 > { + + ~~~~~~~~~~ => Pos: (303 to 312) SpanInfo: {"start":325,"length":10} + >x = x * 10 + >:=> (line 26, col 12) to (line 26, col 22) +-------------------------------- +26 > x = x * 10; + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (313 to 336) SpanInfo: {"start":325,"length":10} + >x = x * 10 + >:=> (line 26, col 12) to (line 26, col 22) +-------------------------------- +27 > } + + ~~~~~~~~~~ => Pos: (337 to 346) SpanInfo: {"start":325,"length":10} + >x = x * 10 + >:=> (line 26, col 12) to (line 26, col 22) +-------------------------------- +28 >} + ~ => Pos: (347 to 347) SpanInfo: {"start":325,"length":10} + >x = x * 10 + >:=> (line 26, col 12) to (line 26, col 22) \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationSwitch.ts b/tests/cases/fourslash/breakpointValidationSwitch.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationSwitch.ts rename to tests/cases/fourslash/breakpointValidationSwitch.ts From 3663550d89fcc5b963685e6bda0fc23911e22ee0 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 17 Oct 2014 20:32:50 -0700 Subject: [PATCH 38/63] Breakpoint spans in try,catch,finally blocks and throw statement --- src/services/breakpoints.ts | 25 ++++ .../reference/bpSpan_tryCatchFinally.baseline | 135 ++++++++++++++++++ .../breakpointValidationTryCatchFinally.ts | 0 3 files changed, 160 insertions(+) create mode 100644 tests/baselines/reference/bpSpan_tryCatchFinally.baseline rename tests/cases/{fourslash_old => fourslash}/breakpointValidationTryCatchFinally.ts (100%) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index fc62884e333..e5dc722d7ea 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -70,6 +70,9 @@ module ts.BreakpointResolver { return spanInFirstStatementOfBlock(node); case SyntaxKind.Block: + case SyntaxKind.TryBlock: + case SyntaxKind.CatchBlock: + case SyntaxKind.FinallyBlock: return spanInBlock(node); case SyntaxKind.ExpressionStatement: @@ -110,6 +113,12 @@ module ts.BreakpointResolver { case SyntaxKind.DefaultClause: return spanInCaseOrDefaultClause(node); + case SyntaxKind.TryStatement: + return spanInTryStatement(node); + + case SyntaxKind.ThrowStatement: + return spanInThrowStatement(node); + case SyntaxKind.BinaryExpression: case SyntaxKind.PostfixOperator: case SyntaxKind.PrefixOperator: @@ -143,6 +152,8 @@ module ts.BreakpointResolver { return spanInWhileKeyword(node); case SyntaxKind.ElseKeyword: + case SyntaxKind.CatchKeyword: + case SyntaxKind.FinallyKeyword: return spanInNextNode(node); default: @@ -332,6 +343,14 @@ module ts.BreakpointResolver { return spanInNode(caseOrDefaultClause.statements[0]); } + function spanInTryStatement(tryStatement: TryStatement): TypeScript.TextSpan { + return spanInBlock(tryStatement.tryBlock); + } + + function spanInThrowStatement(throwStatement: ThrowStatement): TypeScript.TextSpan { + return textSpan(throwStatement, throwStatement.expression); + } + function spanInExpression(expression: Expression): TypeScript.TextSpan { //TODO (pick this up later) for now lets fix do-while baseline if (node.parent.kind === SyntaxKind.DoStatement) { // Set span as if on while keyword @@ -367,6 +386,9 @@ module ts.BreakpointResolver { return spanInFirstStatementOfBlock(node.parent); case SyntaxKind.Block: + case SyntaxKind.TryBlock: + case SyntaxKind.CatchBlock: + case SyntaxKind.FinallyBlock: return spanInBlock(node.parent); case SyntaxKind.SwitchStatement: @@ -385,6 +407,9 @@ module ts.BreakpointResolver { return textSpan(node); case SyntaxKind.Block: + case SyntaxKind.TryBlock: + case SyntaxKind.CatchBlock: + case SyntaxKind.FinallyBlock: return spanInLastStatementOfBlock(node.parent); case SyntaxKind.SwitchStatement: diff --git a/tests/baselines/reference/bpSpan_tryCatchFinally.baseline b/tests/baselines/reference/bpSpan_tryCatchFinally.baseline new file mode 100644 index 00000000000..69e2fb0e136 --- /dev/null +++ b/tests/baselines/reference/bpSpan_tryCatchFinally.baseline @@ -0,0 +1,135 @@ + +1 >var x = 10; + + ~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":0,"length":10} + >var x = 10 + >:=> (line 1, col 0) to (line 1, col 10) +-------------------------------- +2 >try { + + ~~~~~~ => Pos: (12 to 17) SpanInfo: {"start":22,"length":9} + >x = x + 1 + >:=> (line 3, col 4) to (line 3, col 13) +-------------------------------- +3 > x = x + 1; + + ~~~~~~~~~~~~~~~ => Pos: (18 to 32) SpanInfo: {"start":22,"length":9} + >x = x + 1 + >:=> (line 3, col 4) to (line 3, col 13) +-------------------------------- +4 >} catch (e) { + + ~ => Pos: (33 to 33) SpanInfo: {"start":22,"length":9} + >x = x + 1 + >:=> (line 3, col 4) to (line 3, col 13) +4 >} catch (e) { + + ~~~~~~~~~~~~~ => Pos: (34 to 46) SpanInfo: {"start":51,"length":9} + >x = x - 1 + >:=> (line 5, col 4) to (line 5, col 13) +-------------------------------- +5 > x = x - 1; + + ~~~~~~~~~~~~~~~ => Pos: (47 to 61) SpanInfo: {"start":51,"length":9} + >x = x - 1 + >:=> (line 5, col 4) to (line 5, col 13) +-------------------------------- +6 >} finally { + + ~ => Pos: (62 to 62) SpanInfo: {"start":51,"length":9} + >x = x - 1 + >:=> (line 5, col 4) to (line 5, col 13) +6 >} finally { + + ~~~~~~~~~~~ => Pos: (63 to 73) SpanInfo: {"start":78,"length":10} + >x = x * 10 + >:=> (line 7, col 4) to (line 7, col 14) +-------------------------------- +7 > x = x * 10; + + ~~~~~~~~~~~~~~~~ => Pos: (74 to 89) SpanInfo: {"start":78,"length":10} + >x = x * 10 + >:=> (line 7, col 4) to (line 7, col 14) +-------------------------------- +8 >} + + ~~ => Pos: (90 to 91) SpanInfo: {"start":78,"length":10} + >x = x * 10 + >:=> (line 7, col 4) to (line 7, col 14) +-------------------------------- +9 >try + + ~~~~ => Pos: (92 to 95) SpanInfo: {"start":102,"length":9} + >x = x + 1 + >:=> (line 11, col 4) to (line 11, col 13) +-------------------------------- +10 >{ + + ~~ => Pos: (96 to 97) SpanInfo: {"start":102,"length":9} + >x = x + 1 + >:=> (line 11, col 4) to (line 11, col 13) +-------------------------------- +11 > x = x + 1; + + ~~~~~~~~~~~~~~~ => Pos: (98 to 112) SpanInfo: {"start":102,"length":9} + >x = x + 1 + >:=> (line 11, col 4) to (line 11, col 13) +-------------------------------- +12 > throw new Error(); + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (113 to 135) SpanInfo: {"start":117,"length":17} + >throw new Error() + >:=> (line 12, col 4) to (line 12, col 21) +-------------------------------- +13 >} + + ~~ => Pos: (136 to 137) SpanInfo: {"start":117,"length":17} + >throw new Error() + >:=> (line 12, col 4) to (line 12, col 21) +-------------------------------- +14 >catch (e) + + ~~~~~~~~~~ => Pos: (138 to 147) SpanInfo: {"start":154,"length":9} + >x = x - 1 + >:=> (line 16, col 4) to (line 16, col 13) +-------------------------------- +15 >{ + + ~~ => Pos: (148 to 149) SpanInfo: {"start":154,"length":9} + >x = x - 1 + >:=> (line 16, col 4) to (line 16, col 13) +-------------------------------- +16 > x = x - 1; + + ~~~~~~~~~~~~~~~ => Pos: (150 to 164) SpanInfo: {"start":154,"length":9} + >x = x - 1 + >:=> (line 16, col 4) to (line 16, col 13) +-------------------------------- +17 >} + + ~~ => Pos: (165 to 166) SpanInfo: {"start":154,"length":9} + >x = x - 1 + >:=> (line 16, col 4) to (line 16, col 13) +-------------------------------- +18 >finally + + ~~~~~~~~ => Pos: (167 to 174) SpanInfo: {"start":181,"length":10} + >x = x * 10 + >:=> (line 20, col 4) to (line 20, col 14) +-------------------------------- +19 >{ + + ~~ => Pos: (175 to 176) SpanInfo: {"start":181,"length":10} + >x = x * 10 + >:=> (line 20, col 4) to (line 20, col 14) +-------------------------------- +20 > x = x * 10; + + ~~~~~~~~~~~~~~~~ => Pos: (177 to 192) SpanInfo: {"start":181,"length":10} + >x = x * 10 + >:=> (line 20, col 4) to (line 20, col 14) +-------------------------------- +21 >} + ~ => Pos: (193 to 193) SpanInfo: {"start":181,"length":10} + >x = x * 10 + >:=> (line 20, col 4) to (line 20, col 14) \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationTryCatchFinally.ts b/tests/cases/fourslash/breakpointValidationTryCatchFinally.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationTryCatchFinally.ts rename to tests/cases/fourslash/breakpointValidationTryCatchFinally.ts From 2905217d4edaeb3b98675ed1d09d581763c77475 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 17 Oct 2014 20:40:28 -0700 Subject: [PATCH 39/63] Breakpoint validation for export assignment --- src/services/breakpoints.ts | 7 +++++++ .../reference/bpSpan_exportAssignment.baseline | 17 +++++++++++++++++ .../breakpointValidationExportAssignment.ts | 0 3 files changed, 24 insertions(+) create mode 100644 tests/baselines/reference/bpSpan_exportAssignment.baseline rename tests/cases/{fourslash_old => fourslash}/breakpointValidationExportAssignment.ts (100%) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index e5dc722d7ea..a5489b670c1 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -119,6 +119,9 @@ module ts.BreakpointResolver { case SyntaxKind.ThrowStatement: return spanInThrowStatement(node); + case SyntaxKind.ExportAssignment: + return spanInExportAssignment(node); + case SyntaxKind.BinaryExpression: case SyntaxKind.PostfixOperator: case SyntaxKind.PrefixOperator: @@ -351,6 +354,10 @@ module ts.BreakpointResolver { return textSpan(throwStatement, throwStatement.expression); } + function spanInExportAssignment(exportAssignment: ExportAssignment): TypeScript.TextSpan { + return textSpan(exportAssignment, exportAssignment.exportName); + } + function spanInExpression(expression: Expression): TypeScript.TextSpan { //TODO (pick this up later) for now lets fix do-while baseline if (node.parent.kind === SyntaxKind.DoStatement) { // Set span as if on while keyword diff --git a/tests/baselines/reference/bpSpan_exportAssignment.baseline b/tests/baselines/reference/bpSpan_exportAssignment.baseline new file mode 100644 index 00000000000..19e4a4ba9bb --- /dev/null +++ b/tests/baselines/reference/bpSpan_exportAssignment.baseline @@ -0,0 +1,17 @@ + +1 >class a { + + ~~~~~~~~~~ => Pos: (0 to 9) SpanInfo: undefined +-------------------------------- +2 > public c; + + ~~~~~~~~~~~~~~ => Pos: (10 to 23) SpanInfo: undefined +-------------------------------- +3 >} + + ~~ => Pos: (24 to 25) SpanInfo: undefined +-------------------------------- +4 >export = a; + ~~~~~~~~~~~ => Pos: (26 to 36) SpanInfo: {"start":26,"length":10} + >export = a + >:=> (line 4, col 0) to (line 4, col 10) \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationExportAssignment.ts b/tests/cases/fourslash/breakpointValidationExportAssignment.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationExportAssignment.ts rename to tests/cases/fourslash/breakpointValidationExportAssignment.ts From d235caf990b2cd9ead201b79d0c98c8963abe907 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 2 Sep 2014 16:10:08 -0700 Subject: [PATCH 40/63] Breakpoints in import declaration --- src/services/breakpoints.ts | 7 ++++ .../reference/bpSpan_import.baseline | 39 +++++++++++++++++++ .../breakpointValidationImport.ts | 0 3 files changed, 46 insertions(+) create mode 100644 tests/baselines/reference/bpSpan_import.baseline rename tests/cases/{fourslash_old => fourslash}/breakpointValidationImport.ts (100%) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index a5489b670c1..c5b7dd5a150 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -122,6 +122,9 @@ module ts.BreakpointResolver { case SyntaxKind.ExportAssignment: return spanInExportAssignment(node); + case SyntaxKind.ImportDeclaration: + return spanInImportDeclaration(node); + case SyntaxKind.BinaryExpression: case SyntaxKind.PostfixOperator: case SyntaxKind.PrefixOperator: @@ -358,6 +361,10 @@ module ts.BreakpointResolver { return textSpan(exportAssignment, exportAssignment.exportName); } + function spanInImportDeclaration(importDeclaration: ImportDeclaration): TypeScript.TextSpan { + return textSpan(importDeclaration, importDeclaration.entityName || importDeclaration.externalModuleName); + } + function spanInExpression(expression: Expression): TypeScript.TextSpan { //TODO (pick this up later) for now lets fix do-while baseline if (node.parent.kind === SyntaxKind.DoStatement) { // Set span as if on while keyword diff --git a/tests/baselines/reference/bpSpan_import.baseline b/tests/baselines/reference/bpSpan_import.baseline new file mode 100644 index 00000000000..5548368fa76 --- /dev/null +++ b/tests/baselines/reference/bpSpan_import.baseline @@ -0,0 +1,39 @@ + +1 >module m { + + ~~~~~~~~~~~ => Pos: (0 to 10) SpanInfo: undefined +-------------------------------- +2 > class c { + + ~~~~~~~~~~~~~~ => Pos: (11 to 24) SpanInfo: undefined +-------------------------------- +3 > } + + ~~~~~~ => Pos: (25 to 30) SpanInfo: undefined +-------------------------------- +4 >} + + ~~ => Pos: (31 to 32) SpanInfo: undefined +-------------------------------- +5 >import a = m.c; + + ~~~~~~~~~~~~~~~~ => Pos: (33 to 48) SpanInfo: {"start":33,"length":14} + >import a = m.c + >:=> (line 5, col 0) to (line 5, col 14) +-------------------------------- +6 >export import b = m.c; + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (49 to 71) SpanInfo: {"start":49,"length":21} + >export import b = m.c + >:=> (line 6, col 0) to (line 6, col 21) +-------------------------------- +7 >var x = new a(); + + ~~~~~~~~~~~~~~~~~ => Pos: (72 to 88) SpanInfo: {"start":72,"length":15} + >var x = new a() + >:=> (line 7, col 0) to (line 7, col 15) +-------------------------------- +8 >var y = new b(); + ~~~~~~~~~~~~~~~~ => Pos: (89 to 104) SpanInfo: {"start":89,"length":15} + >var y = new b() + >:=> (line 8, col 0) to (line 8, col 15) \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationImport.ts b/tests/cases/fourslash/breakpointValidationImport.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationImport.ts rename to tests/cases/fourslash/breakpointValidationImport.ts From 01d4ce25e2de1df4ff9f94ce2750100114e9bffc Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 2 Sep 2014 16:53:03 -0700 Subject: [PATCH 41/63] Breakpoints in enum declaration --- src/services/breakpoints.ts | 21 ++++ .../baselines/reference/bpSpan_enums.baseline | 101 ++++++++++++++++++ .../breakpointValidationEnums.ts | 6 ++ 3 files changed, 128 insertions(+) create mode 100644 tests/baselines/reference/bpSpan_enums.baseline rename tests/cases/{fourslash_old => fourslash}/breakpointValidationEnums.ts (75%) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index c5b7dd5a150..6a450ca62dc 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -125,6 +125,12 @@ module ts.BreakpointResolver { case SyntaxKind.ImportDeclaration: return spanInImportDeclaration(node); + case SyntaxKind.EnumDeclaration: + return spanInEnumDeclaration(node); + + case SyntaxKind.EnumMember: + return spanInEnumMember(node); + case SyntaxKind.BinaryExpression: case SyntaxKind.PostfixOperator: case SyntaxKind.PrefixOperator: @@ -365,6 +371,19 @@ module ts.BreakpointResolver { return textSpan(importDeclaration, importDeclaration.entityName || importDeclaration.externalModuleName); } + function spanInEnumDeclaration(enumDeclaration: EnumDeclaration): TypeScript.TextSpan { + if (enumDeclaration.members.length) { + return spanInEnumMember(enumDeclaration.members[0]); + } + + // On close brace + return spanInNode(enumDeclaration.getLastToken(sourceFile)); + } + + function spanInEnumMember(enumMember: EnumMember) { + return textSpan(enumMember); + } + function spanInExpression(expression: Expression): TypeScript.TextSpan { //TODO (pick this up later) for now lets fix do-while baseline if (node.parent.kind === SyntaxKind.DoStatement) { // Set span as if on while keyword @@ -385,6 +404,7 @@ module ts.BreakpointResolver { switch (node.parent.kind) { case SyntaxKind.FunctionDeclaration: case SyntaxKind.VariableStatement: + case SyntaxKind.EnumDeclaration: return spanInPreviousNode(node); // Default to parent node @@ -417,6 +437,7 @@ module ts.BreakpointResolver { function spanInCloseBraceToken(node: Node): TypeScript.TextSpan { switch (node.parent.kind) { case SyntaxKind.FunctionBlock: + case SyntaxKind.EnumDeclaration: // Span on close brace token return textSpan(node); diff --git a/tests/baselines/reference/bpSpan_enums.baseline b/tests/baselines/reference/bpSpan_enums.baseline new file mode 100644 index 00000000000..c239d421da5 --- /dev/null +++ b/tests/baselines/reference/bpSpan_enums.baseline @@ -0,0 +1,101 @@ + +1 >enum e { + + ~~~~~~~~~ => Pos: (0 to 8) SpanInfo: {"start":13,"length":1} + >x + >:=> (line 2, col 4) to (line 2, col 5) +-------------------------------- +2 > x, + + ~~~~~~~ => Pos: (9 to 15) SpanInfo: {"start":13,"length":1} + >x + >:=> (line 2, col 4) to (line 2, col 5) +-------------------------------- +3 > y, + + ~~~~~~~ => Pos: (16 to 22) SpanInfo: {"start":20,"length":1} + >y + >:=> (line 3, col 4) to (line 3, col 5) +-------------------------------- +4 > x + + ~~~~~~ => Pos: (23 to 28) SpanInfo: {"start":27,"length":1} + >x + >:=> (line 4, col 4) to (line 4, col 5) +-------------------------------- +5 >} + + ~~ => Pos: (29 to 30) SpanInfo: {"start":29,"length":1} + >} + >:=> (line 5, col 0) to (line 5, col 1) +-------------------------------- +6 >enum e2 { + + ~~~~~~~~~~ => Pos: (31 to 40) SpanInfo: {"start":45,"length":6} + >x = 10 + >:=> (line 7, col 4) to (line 7, col 10) +-------------------------------- +7 > x = 10, + + ~~~~~~~~~~~~ => Pos: (41 to 52) SpanInfo: {"start":45,"length":6} + >x = 10 + >:=> (line 7, col 4) to (line 7, col 10) +-------------------------------- +8 > y = 10, + + ~~~~~~~~~~~~ => Pos: (53 to 64) SpanInfo: {"start":57,"length":6} + >y = 10 + >:=> (line 8, col 4) to (line 8, col 10) +-------------------------------- +9 > z, + + ~~~~~~~ => Pos: (65 to 71) SpanInfo: {"start":69,"length":1} + >z + >:=> (line 9, col 4) to (line 9, col 5) +-------------------------------- +10 > x2 + + ~~~~~~~ => Pos: (72 to 78) SpanInfo: {"start":76,"length":2} + >x2 + >:=> (line 10, col 4) to (line 10, col 6) +-------------------------------- +11 >} + + ~~ => Pos: (79 to 80) SpanInfo: {"start":79,"length":1} + >} + >:=> (line 11, col 0) to (line 11, col 1) +-------------------------------- +12 >enum e3 { + + ~~~~~~~~~~ => Pos: (81 to 90) SpanInfo: {"start":91,"length":1} + >} + >:=> (line 13, col 0) to (line 13, col 1) +-------------------------------- +13 >} + + ~~ => Pos: (91 to 92) SpanInfo: {"start":91,"length":1} + >} + >:=> (line 13, col 0) to (line 13, col 1) +-------------------------------- +14 >declare enum e4 { + + ~~~~~~~~~~~~~~~~~~ => Pos: (93 to 110) SpanInfo: undefined +-------------------------------- +15 > x, + + ~~~~~~~ => Pos: (111 to 117) SpanInfo: undefined +-------------------------------- +16 > y, + + ~~~~~~~ => Pos: (118 to 124) SpanInfo: undefined +-------------------------------- +17 > z, + + ~~~~~~~ => Pos: (125 to 131) SpanInfo: undefined +-------------------------------- +18 > x2 + + ~~~~~~~ => Pos: (132 to 138) SpanInfo: undefined +-------------------------------- +19 >} + ~ => Pos: (139 to 139) SpanInfo: undefined \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationEnums.ts b/tests/cases/fourslash/breakpointValidationEnums.ts similarity index 75% rename from tests/cases/fourslash_old/breakpointValidationEnums.ts rename to tests/cases/fourslash/breakpointValidationEnums.ts index 4423941b1e4..cd0dbbdfb23 100644 --- a/tests/cases/fourslash_old/breakpointValidationEnums.ts +++ b/tests/cases/fourslash/breakpointValidationEnums.ts @@ -15,5 +15,11 @@ ////} ////enum e3 { ////} +////declare enum e4 { +//// x, +//// y, +//// z, +//// x2 +////} verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file From b54d20d52b21a734486c1f57d4ed436c9398275b Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 17 Oct 2014 23:15:21 -0700 Subject: [PATCH 42/63] Breakpoints in module declaration --- src/services/breakpoints.ts | 28 +++++-- .../reference/bpSpan_import.baseline | 4 +- .../reference/bpSpan_module.baseline | 77 +++++++++++++++++++ .../reference/bpSpan_moduleAmbient.baseline | 19 +++++ .../reference/bpSpan_moduleEmpty.baseline | 7 ++ .../breakpointValidationModule.ts | 0 .../breakpointValidationModuleAmbient.ts | 0 .../breakpointValidationModuleEmpty.ts | 0 8 files changed, 128 insertions(+), 7 deletions(-) create mode 100644 tests/baselines/reference/bpSpan_module.baseline create mode 100644 tests/baselines/reference/bpSpan_moduleAmbient.baseline create mode 100644 tests/baselines/reference/bpSpan_moduleEmpty.baseline rename tests/cases/{fourslash_old => fourslash}/breakpointValidationModule.ts (100%) rename tests/cases/{fourslash_old => fourslash}/breakpointValidationModuleAmbient.ts (100%) rename tests/cases/{fourslash_old => fourslash}/breakpointValidationModuleEmpty.ts (100%) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 6a450ca62dc..63701d1645c 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -73,6 +73,7 @@ module ts.BreakpointResolver { case SyntaxKind.TryBlock: case SyntaxKind.CatchBlock: case SyntaxKind.FinallyBlock: + case SyntaxKind.ModuleBlock: return spanInBlock(node); case SyntaxKind.ExpressionStatement: @@ -131,6 +132,13 @@ module ts.BreakpointResolver { case SyntaxKind.EnumMember: return spanInEnumMember(node); + case SyntaxKind.ModuleDeclaration: + return spanInModuleDeclaration(node); + + case SyntaxKind.ClassDeclaration: + // TODO + return; + case SyntaxKind.BinaryExpression: case SyntaxKind.PostfixOperator: case SyntaxKind.PrefixOperator: @@ -384,6 +392,10 @@ module ts.BreakpointResolver { return textSpan(enumMember); } + function spanInModuleDeclaration(moduleDeclaration: ModuleDeclaration): TypeScript.TextSpan { + return spanInNode(moduleDeclaration.body); + } + function spanInExpression(expression: Expression): TypeScript.TextSpan { //TODO (pick this up later) for now lets fix do-while baseline if (node.parent.kind === SyntaxKind.DoStatement) { // Set span as if on while keyword @@ -419,12 +431,6 @@ module ts.BreakpointResolver { // Span on first statement return spanInFirstStatementOfBlock(node.parent); - case SyntaxKind.Block: - case SyntaxKind.TryBlock: - case SyntaxKind.CatchBlock: - case SyntaxKind.FinallyBlock: - return spanInBlock(node.parent); - case SyntaxKind.SwitchStatement: return spanInNodeIfStartsOnSameLine(node.parent, (node.parent).clauses[0]); @@ -441,6 +447,16 @@ module ts.BreakpointResolver { // Span on close brace token return textSpan(node); + case SyntaxKind.ModuleBlock: + var moduleBlock = node.parent; + if (moduleBlock.statements.length || // there are statements in the module block + moduleBlock.parent.parent.kind === SyntaxKind.ModuleDeclaration) { // this is a dotted module body + return textSpan(node); + } + + // No span + return; + case SyntaxKind.Block: case SyntaxKind.TryBlock: case SyntaxKind.CatchBlock: diff --git a/tests/baselines/reference/bpSpan_import.baseline b/tests/baselines/reference/bpSpan_import.baseline index 5548368fa76..ef94afb42f0 100644 --- a/tests/baselines/reference/bpSpan_import.baseline +++ b/tests/baselines/reference/bpSpan_import.baseline @@ -13,7 +13,9 @@ -------------------------------- 4 >} - ~~ => Pos: (31 to 32) SpanInfo: undefined + ~~ => Pos: (31 to 32) SpanInfo: {"start":31,"length":1} + >} + >:=> (line 4, col 0) to (line 4, col 1) -------------------------------- 5 >import a = m.c; diff --git a/tests/baselines/reference/bpSpan_module.baseline b/tests/baselines/reference/bpSpan_module.baseline new file mode 100644 index 00000000000..f00595e2b1e --- /dev/null +++ b/tests/baselines/reference/bpSpan_module.baseline @@ -0,0 +1,77 @@ + +1 >module m2 { + + ~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":16,"length":10} + >var a = 10 + >:=> (line 2, col 4) to (line 2, col 14) +-------------------------------- +2 > var a = 10; + + ~~~~~~~~~~~~~~~~ => Pos: (12 to 27) SpanInfo: {"start":16,"length":10} + >var a = 10 + >:=> (line 2, col 4) to (line 2, col 14) +-------------------------------- +3 > a++; + + ~~~~~~~~~ => Pos: (28 to 36) SpanInfo: {"start":32,"length":3} + >a++ + >:=> (line 3, col 4) to (line 3, col 7) +-------------------------------- +4 >} + + ~~ => Pos: (37 to 38) SpanInfo: {"start":37,"length":1} + >} + >:=> (line 4, col 0) to (line 4, col 1) +-------------------------------- +5 >module m3 { + + ~~~~~~~~~~~~ => Pos: (39 to 50) SpanInfo: {"start":75,"length":17} + >export var x = 30 + >:=> (line 7, col 8) to (line 7, col 25) +-------------------------------- +6 > module m4 { + + ~~~~~~~~~~~~~~~~ => Pos: (51 to 66) SpanInfo: {"start":75,"length":17} + >export var x = 30 + >:=> (line 7, col 8) to (line 7, col 25) +-------------------------------- +7 > export var x = 30; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (67 to 93) SpanInfo: {"start":75,"length":17} + >export var x = 30 + >:=> (line 7, col 8) to (line 7, col 25) +-------------------------------- +8 > } + + ~~~~~~ => Pos: (94 to 99) SpanInfo: {"start":98,"length":1} + >} + >:=> (line 8, col 4) to (line 8, col 5) +-------------------------------- +9 > + + ~ => Pos: (100 to 100) SpanInfo: {"start":98,"length":1} + >} + >:=> (line 8, col 4) to (line 8, col 5) +-------------------------------- +10 > export function foo() { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (101 to 128) SpanInfo: {"start":137,"length":11} + >return m4.x + >:=> (line 11, col 8) to (line 11, col 19) +-------------------------------- +11 > return m4.x; + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (129 to 149) SpanInfo: {"start":137,"length":11} + >return m4.x + >:=> (line 11, col 8) to (line 11, col 19) +-------------------------------- +12 > } + + ~~~~~~ => Pos: (150 to 155) SpanInfo: {"start":154,"length":1} + >} + >:=> (line 12, col 4) to (line 12, col 5) +-------------------------------- +13 >} + ~ => Pos: (156 to 156) SpanInfo: {"start":156,"length":1} + >} + >:=> (line 13, col 0) to (line 13, col 1) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_moduleAmbient.baseline b/tests/baselines/reference/bpSpan_moduleAmbient.baseline new file mode 100644 index 00000000000..8ea705dc09f --- /dev/null +++ b/tests/baselines/reference/bpSpan_moduleAmbient.baseline @@ -0,0 +1,19 @@ + +1 >declare module Bar { + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (0 to 20) SpanInfo: undefined +-------------------------------- +2 >} + + ~~ => Pos: (21 to 22) SpanInfo: undefined +-------------------------------- +3 >declare module Foo { + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (23 to 43) SpanInfo: undefined +-------------------------------- +4 > var x; + + ~~~~~~~~~~~ => Pos: (44 to 54) SpanInfo: undefined +-------------------------------- +5 >} + ~ => Pos: (55 to 55) SpanInfo: undefined \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_moduleEmpty.baseline b/tests/baselines/reference/bpSpan_moduleEmpty.baseline new file mode 100644 index 00000000000..3139d4603d2 --- /dev/null +++ b/tests/baselines/reference/bpSpan_moduleEmpty.baseline @@ -0,0 +1,7 @@ + +1 >module Bar { + + ~~~~~~~~~~~~~ => Pos: (0 to 12) SpanInfo: undefined +-------------------------------- +2 >} + ~ => Pos: (13 to 13) SpanInfo: undefined \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationModule.ts b/tests/cases/fourslash/breakpointValidationModule.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationModule.ts rename to tests/cases/fourslash/breakpointValidationModule.ts diff --git a/tests/cases/fourslash_old/breakpointValidationModuleAmbient.ts b/tests/cases/fourslash/breakpointValidationModuleAmbient.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationModuleAmbient.ts rename to tests/cases/fourslash/breakpointValidationModuleAmbient.ts diff --git a/tests/cases/fourslash_old/breakpointValidationModuleEmpty.ts b/tests/cases/fourslash/breakpointValidationModuleEmpty.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationModuleEmpty.ts rename to tests/cases/fourslash/breakpointValidationModuleEmpty.ts From 330065fdeb9fc4890e6f64b2657144a540a1b47d Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Sat, 18 Oct 2014 00:21:06 -0700 Subject: [PATCH 43/63] Breakpoints in classes --- src/services/breakpoints.ts | 48 +++++-- .../baselines/reference/bpSpan_class.baseline | 120 ++++++++++++++++++ .../reference/bpSpan_classAmbient.baseline | 31 +++++ .../bpSpan_exportAssignment.baseline | 4 +- .../reference/bpSpan_import.baseline | 12 +- .../breakpointValidationClass.ts | 0 .../breakpointValidationClassAmbient.ts | 0 7 files changed, 197 insertions(+), 18 deletions(-) create mode 100644 tests/baselines/reference/bpSpan_class.baseline create mode 100644 tests/baselines/reference/bpSpan_classAmbient.baseline rename tests/cases/{fourslash_old => fourslash}/breakpointValidationClass.ts (100%) rename tests/cases/{fourslash_old => fourslash}/breakpointValidationClassAmbient.ts (100%) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 63701d1645c..23a2189d448 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -58,16 +58,21 @@ module ts.BreakpointResolver { return spanInVariableStatement(node); case SyntaxKind.VariableDeclaration: + case SyntaxKind.Property: return spanInVariableDeclaration(node); case SyntaxKind.Parameter: return spanInParameterDeclaration(node); case SyntaxKind.FunctionDeclaration: + case SyntaxKind.Method: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.Constructor: return spanInFunctionDeclaration(node); case SyntaxKind.FunctionBlock: - return spanInFirstStatementOfBlock(node); + return spanInFunctionBlock(node); case SyntaxKind.Block: case SyntaxKind.TryBlock: @@ -136,8 +141,7 @@ module ts.BreakpointResolver { return spanInModuleDeclaration(node); case SyntaxKind.ClassDeclaration: - // TODO - return; + return spanInClassDeclaration(node); case SyntaxKind.BinaryExpression: case SyntaxKind.PostfixOperator: @@ -274,6 +278,15 @@ module ts.BreakpointResolver { return spanInNode(functionDeclaration.body); } + function spanInFunctionBlock(block: Block): TypeScript.TextSpan { + if (block.statements.length) { + return spanInFirstStatementOfBlock(block); + } + + // On close parenthesis + return spanInNode(block.getLastToken()); + } + function spanInFirstStatementOfBlock(block: Block): TypeScript.TextSpan { // Set breakpoint in first statement return spanInNode(block.statements[0]); @@ -396,6 +409,14 @@ module ts.BreakpointResolver { return spanInNode(moduleDeclaration.body); } + function spanInClassDeclaration(classDeclaration: ClassDeclaration): TypeScript.TextSpan { + if (classDeclaration.members.length) { + return spanInNode(classDeclaration.members[0]); + } + + return spanInNode(classDeclaration.getLastToken()); + } + function spanInExpression(expression: Expression): TypeScript.TextSpan { //TODO (pick this up later) for now lets fix do-while baseline if (node.parent.kind === SyntaxKind.DoStatement) { // Set span as if on while keyword @@ -415,6 +436,10 @@ module ts.BreakpointResolver { function spanInCommaToken(node: Node): TypeScript.TextSpan { switch (node.parent.kind) { case SyntaxKind.FunctionDeclaration: + case SyntaxKind.Method: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.Constructor: case SyntaxKind.VariableStatement: case SyntaxKind.EnumDeclaration: return spanInPreviousNode(node); @@ -426,24 +451,19 @@ module ts.BreakpointResolver { } function spanInOpenBraceToken(node: Node): TypeScript.TextSpan { - switch (node.parent.kind) { - case SyntaxKind.FunctionBlock: - // Span on first statement - return spanInFirstStatementOfBlock(node.parent); - - case SyntaxKind.SwitchStatement: - return spanInNodeIfStartsOnSameLine(node.parent, (node.parent).clauses[0]); - - // Default to parent node - default: - return spanInNode(node.parent); + if (node.parent.kind === SyntaxKind.SwitchStatement) { + return spanInNodeIfStartsOnSameLine(node.parent, (node.parent).clauses[0]); } + + // Default to parent node + return spanInNode(node.parent); } function spanInCloseBraceToken(node: Node): TypeScript.TextSpan { switch (node.parent.kind) { case SyntaxKind.FunctionBlock: case SyntaxKind.EnumDeclaration: + case SyntaxKind.ClassDeclaration: // Span on close brace token return textSpan(node); diff --git a/tests/baselines/reference/bpSpan_class.baseline b/tests/baselines/reference/bpSpan_class.baseline new file mode 100644 index 00000000000..a628510bb9e --- /dev/null +++ b/tests/baselines/reference/bpSpan_class.baseline @@ -0,0 +1,120 @@ + +1 >class Greeter { + + ~~~~~~~~~~~~~~~~ => Pos: (0 to 15) SpanInfo: {"start":79,"length":1} + >} + >:=> (line 3, col 4) to (line 3, col 5) +-------------------------------- +2 > constructor(public greeting: string, ...b: string[]) { + + ~~~~~~~~~~~~~~~~ => Pos: (16 to 31) SpanInfo: {"start":79,"length":1} + >} + >:=> (line 3, col 4) to (line 3, col 5) +2 > constructor(public greeting: string, ...b: string[]) { + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (32 to 55) SpanInfo: {"start":32,"length":23} + >public greeting: string + >:=> (line 2, col 16) to (line 2, col 39) +2 > constructor(public greeting: string, ...b: string[]) { + + ~~~~~~~~~~~~~~~~=> Pos: (56 to 71) SpanInfo: {"start":57,"length":14} + >...b: string[] + >:=> (line 2, col 41) to (line 2, col 55) +2 > constructor(public greeting: string, ...b: string[]) { + + ~~~=> Pos: (72 to 74) SpanInfo: {"start":79,"length":1} + >} + >:=> (line 3, col 4) to (line 3, col 5) +-------------------------------- +3 > } + + ~~~~~~ => Pos: (75 to 80) SpanInfo: {"start":79,"length":1} + >} + >:=> (line 3, col 4) to (line 3, col 5) +-------------------------------- +4 > greet() { + + ~~~~~~~~~~~~~~ => Pos: (81 to 94) SpanInfo: {"start":103,"length":39} + >return "

" + this.greeting + "

" + >:=> (line 5, col 8) to (line 5, col 47) +-------------------------------- +5 > return "

" + this.greeting + "

"; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (95 to 143) SpanInfo: {"start":103,"length":39} + >return "

" + this.greeting + "

" + >:=> (line 5, col 8) to (line 5, col 47) +-------------------------------- +6 > } + + ~~~~~~ => Pos: (144 to 149) SpanInfo: {"start":148,"length":1} + >} + >:=> (line 6, col 4) to (line 6, col 5) +-------------------------------- +7 > private x: string; + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (150 to 172) SpanInfo: undefined +-------------------------------- +8 > private x1: number = 10; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (173 to 201) SpanInfo: {"start":177,"length":24} + >private x1: number = 10; + >:=> (line 8, col 4) to (line 8, col 28) +-------------------------------- +9 > private fn() { + + ~~~~~~~~~~~~~~~~~~~ => Pos: (202 to 220) SpanInfo: {"start":229,"length":20} + >return this.greeting + >:=> (line 10, col 8) to (line 10, col 28) +-------------------------------- +10 > return this.greeting; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (221 to 250) SpanInfo: {"start":229,"length":20} + >return this.greeting + >:=> (line 10, col 8) to (line 10, col 28) +-------------------------------- +11 > } + + ~~~~~~ => Pos: (251 to 256) SpanInfo: {"start":255,"length":1} + >} + >:=> (line 11, col 4) to (line 11, col 5) +-------------------------------- +12 > get greetings() { + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (257 to 278) SpanInfo: {"start":287,"length":20} + >return this.greeting + >:=> (line 13, col 8) to (line 13, col 28) +-------------------------------- +13 > return this.greeting; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (279 to 308) SpanInfo: {"start":287,"length":20} + >return this.greeting + >:=> (line 13, col 8) to (line 13, col 28) +-------------------------------- +14 > } + + ~~~~~~ => Pos: (309 to 314) SpanInfo: {"start":313,"length":1} + >} + >:=> (line 14, col 4) to (line 14, col 5) +-------------------------------- +15 > set greetings(greetings: string) { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (315 to 353) SpanInfo: {"start":362,"length":25} + >this.greeting = greetings + >:=> (line 16, col 8) to (line 16, col 33) +-------------------------------- +16 > this.greeting = greetings; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (354 to 388) SpanInfo: {"start":362,"length":25} + >this.greeting = greetings + >:=> (line 16, col 8) to (line 16, col 33) +-------------------------------- +17 > } + + ~~~~~~ => Pos: (389 to 394) SpanInfo: {"start":393,"length":1} + >} + >:=> (line 17, col 4) to (line 17, col 5) +-------------------------------- +18 >} + ~ => Pos: (395 to 395) SpanInfo: {"start":395,"length":1} + >} + >:=> (line 18, col 0) to (line 18, col 1) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_classAmbient.baseline b/tests/baselines/reference/bpSpan_classAmbient.baseline new file mode 100644 index 00000000000..b168c5416c5 --- /dev/null +++ b/tests/baselines/reference/bpSpan_classAmbient.baseline @@ -0,0 +1,31 @@ + +1 >declare class Greeter { + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (0 to 23) SpanInfo: undefined +-------------------------------- +2 > public greeting: string; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (24 to 52) SpanInfo: undefined +-------------------------------- +3 > constructor(greeting: string, ...b: string[]); + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (53 to 103) SpanInfo: undefined +-------------------------------- +4 > greet(): string; + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (104 to 124) SpanInfo: undefined +-------------------------------- +5 > private val; + + ~~~~~~~~~~~~~~~~~ => Pos: (125 to 141) SpanInfo: undefined +-------------------------------- +6 > static x: number; + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (142 to 163) SpanInfo: undefined +-------------------------------- +7 > static fn(a: number, ...b:string[]); + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (164 to 204) SpanInfo: undefined +-------------------------------- +8 >} + ~ => Pos: (205 to 205) SpanInfo: undefined \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_exportAssignment.baseline b/tests/baselines/reference/bpSpan_exportAssignment.baseline index 19e4a4ba9bb..9086e218329 100644 --- a/tests/baselines/reference/bpSpan_exportAssignment.baseline +++ b/tests/baselines/reference/bpSpan_exportAssignment.baseline @@ -9,7 +9,9 @@ -------------------------------- 3 >} - ~~ => Pos: (24 to 25) SpanInfo: undefined + ~~ => Pos: (24 to 25) SpanInfo: {"start":24,"length":1} + >} + >:=> (line 3, col 0) to (line 3, col 1) -------------------------------- 4 >export = a; ~~~~~~~~~~~ => Pos: (26 to 36) SpanInfo: {"start":26,"length":10} diff --git a/tests/baselines/reference/bpSpan_import.baseline b/tests/baselines/reference/bpSpan_import.baseline index ef94afb42f0..bc729447306 100644 --- a/tests/baselines/reference/bpSpan_import.baseline +++ b/tests/baselines/reference/bpSpan_import.baseline @@ -1,15 +1,21 @@ 1 >module m { - ~~~~~~~~~~~ => Pos: (0 to 10) SpanInfo: undefined + ~~~~~~~~~~~ => Pos: (0 to 10) SpanInfo: {"start":29,"length":1} + >} + >:=> (line 3, col 4) to (line 3, col 5) -------------------------------- 2 > class c { - ~~~~~~~~~~~~~~ => Pos: (11 to 24) SpanInfo: undefined + ~~~~~~~~~~~~~~ => Pos: (11 to 24) SpanInfo: {"start":29,"length":1} + >} + >:=> (line 3, col 4) to (line 3, col 5) -------------------------------- 3 > } - ~~~~~~ => Pos: (25 to 30) SpanInfo: undefined + ~~~~~~ => Pos: (25 to 30) SpanInfo: {"start":29,"length":1} + >} + >:=> (line 3, col 4) to (line 3, col 5) -------------------------------- 4 >} diff --git a/tests/cases/fourslash_old/breakpointValidationClass.ts b/tests/cases/fourslash/breakpointValidationClass.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationClass.ts rename to tests/cases/fourslash/breakpointValidationClass.ts diff --git a/tests/cases/fourslash_old/breakpointValidationClassAmbient.ts b/tests/cases/fourslash/breakpointValidationClassAmbient.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationClassAmbient.ts rename to tests/cases/fourslash/breakpointValidationClassAmbient.ts From 0cb2e983aac0a6c0d117d01c8c25523153c06492 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 20 Oct 2014 19:07:18 -0700 Subject: [PATCH 44/63] Breakpoints in expressions --- src/compiler/checker.ts | 71 --- src/compiler/parser.ts | 71 +++ src/services/breakpoints.ts | 121 ++-- .../bpSpan_arrayLiteralExpressions.baseline | 198 ++++++ .../bpSpan_binaryExpressions.baseline | 119 ++++ .../reference/bpSpan_classes.baseline | 284 +++++++++ .../bpSpan_conditionalExpressions.baseline | 129 ++++ tests/baselines/reference/bpSpan_do.baseline | 65 +- tests/baselines/reference/bpSpan_for.baseline | 23 +- .../baselines/reference/bpSpan_forIn.baseline | 64 +- .../bpSpan_functionExpressions.baseline | 189 ++++++ .../reference/bpSpan_ifElse.baseline | 60 +- .../reference/bpSpan_import.baseline | 15 +- .../bpSpan_objectLiteralExpressions.baseline | 233 +++++++ .../bpSpan_parenCallOrNewExpressions.baseline | 361 +++++++++++ .../baselines/reference/bpSpan_stmts.baseline | 572 ++++++++++++++++++ .../reference/bpSpan_switch.baseline | 109 +++- .../reference/bpSpan_tryCatchFinally.baseline | 94 ++- .../bpSpan_typeAssertionExpressions.baseline | 81 +++ .../bpSpan_unaryExpressions.baseline | 74 +++ .../baselines/reference/bpSpan_while.baseline | 67 +- .../baselines/reference/bpSpan_with.baseline | 21 + ...kpointValidationArrayLiteralExpressions.ts | 23 + .../breakpointValidationBinaryExpressions.ts | 17 + .../breakpointValidationClasses.ts | 0 ...akpointValidationConditionalExpressions.ts | 16 + .../cases/fourslash/breakpointValidationDo.ts | 5 + .../fourslash/breakpointValidationForIn.ts | 6 + ...breakpointValidationFunctionExpressions.ts | 14 +- .../fourslash/breakpointValidationIfElse.ts | 5 + ...pointValidationObjectLiteralExpressions.ts | 33 + ...ointValidationParenCallOrNewExpressions.ts | 35 ++ .../breakpointValidationStatements.ts | 0 .../fourslash/breakpointValidationSwitch.ts | 8 + .../breakpointValidationTryCatchFinally.ts | 8 + ...pointValidationTypeAssertionExpressions.ts | 13 + .../breakpointValidationUnaryExpressions.ts | 15 + .../fourslash/breakpointValidationWhile.ts | 6 + .../fourslash/breakpointValidationWith.ts | 10 + 39 files changed, 3090 insertions(+), 145 deletions(-) create mode 100644 tests/baselines/reference/bpSpan_arrayLiteralExpressions.baseline create mode 100644 tests/baselines/reference/bpSpan_binaryExpressions.baseline create mode 100644 tests/baselines/reference/bpSpan_classes.baseline create mode 100644 tests/baselines/reference/bpSpan_conditionalExpressions.baseline create mode 100644 tests/baselines/reference/bpSpan_functionExpressions.baseline create mode 100644 tests/baselines/reference/bpSpan_objectLiteralExpressions.baseline create mode 100644 tests/baselines/reference/bpSpan_parenCallOrNewExpressions.baseline create mode 100644 tests/baselines/reference/bpSpan_stmts.baseline create mode 100644 tests/baselines/reference/bpSpan_typeAssertionExpressions.baseline create mode 100644 tests/baselines/reference/bpSpan_unaryExpressions.baseline create mode 100644 tests/baselines/reference/bpSpan_with.baseline create mode 100644 tests/cases/fourslash/breakpointValidationArrayLiteralExpressions.ts create mode 100644 tests/cases/fourslash/breakpointValidationBinaryExpressions.ts rename tests/cases/{fourslash_old => fourslash}/breakpointValidationClasses.ts (100%) create mode 100644 tests/cases/fourslash/breakpointValidationConditionalExpressions.ts rename tests/cases/{fourslash_old => fourslash}/breakpointValidationFunctionExpressions.ts (57%) create mode 100644 tests/cases/fourslash/breakpointValidationObjectLiteralExpressions.ts create mode 100644 tests/cases/fourslash/breakpointValidationParenCallOrNewExpressions.ts rename tests/cases/{fourslash_old => fourslash}/breakpointValidationStatements.ts (100%) create mode 100644 tests/cases/fourslash/breakpointValidationTypeAssertionExpressions.ts create mode 100644 tests/cases/fourslash/breakpointValidationUnaryExpressions.ts create mode 100644 tests/cases/fourslash/breakpointValidationWith.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index dd8deecbac1..d50f2524c9c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7815,77 +7815,6 @@ module ts { return node.parent && node.parent.kind === SyntaxKind.TypeReference; } - function isExpression(node: Node): boolean { - switch (node.kind) { - case SyntaxKind.ThisKeyword: - case SyntaxKind.SuperKeyword: - case SyntaxKind.NullKeyword: - case SyntaxKind.TrueKeyword: - case SyntaxKind.FalseKeyword: - case SyntaxKind.RegularExpressionLiteral: - case SyntaxKind.ArrayLiteral: - case SyntaxKind.ObjectLiteral: - case SyntaxKind.PropertyAccess: - case SyntaxKind.IndexedAccess: - case SyntaxKind.CallExpression: - case SyntaxKind.NewExpression: - case SyntaxKind.TypeAssertion: - case SyntaxKind.ParenExpression: - case SyntaxKind.FunctionExpression: - case SyntaxKind.ArrowFunction: - case SyntaxKind.PrefixOperator: - case SyntaxKind.PostfixOperator: - case SyntaxKind.BinaryExpression: - case SyntaxKind.ConditionalExpression: - case SyntaxKind.OmittedExpression: - return true; - case SyntaxKind.QualifiedName: - while (node.parent.kind === SyntaxKind.QualifiedName) node = node.parent; - return node.parent.kind === SyntaxKind.TypeQuery; - case SyntaxKind.Identifier: - if (node.parent.kind === SyntaxKind.TypeQuery) { - return true; - } - // Fall through - case SyntaxKind.NumericLiteral: - case SyntaxKind.StringLiteral: - var parent = node.parent; - switch (parent.kind) { - case SyntaxKind.VariableDeclaration: - case SyntaxKind.Parameter: - case SyntaxKind.Property: - case SyntaxKind.EnumMember: - case SyntaxKind.PropertyAssignment: - return (parent).initializer === node; - case SyntaxKind.ExpressionStatement: - case SyntaxKind.IfStatement: - case SyntaxKind.DoStatement: - case SyntaxKind.WhileStatement: - case SyntaxKind.ReturnStatement: - case SyntaxKind.WithStatement: - case SyntaxKind.SwitchStatement: - case SyntaxKind.CaseClause: - case SyntaxKind.ThrowStatement: - case SyntaxKind.SwitchStatement: - return (parent).expression === node; - case SyntaxKind.ForStatement: - return (parent).initializer === node || - (parent).condition === node || - (parent).iterator === node; - case SyntaxKind.ForInStatement: - return (parent).variable === node || - (parent).expression === node; - case SyntaxKind.TypeAssertion: - return node === (parent).operand; - default: - if (isExpression(parent)) { - return true; - } - } - } - return false; - } - function isTypeNode(node: Node): boolean { if (SyntaxKind.FirstTypeNode <= node.kind && node.kind <= SyntaxKind.LastTypeNode) { return true; diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index c755205ee3a..46717d3df0f 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -67,6 +67,77 @@ module ts { return identifier.kind === SyntaxKind.Missing ? "(Missing)" : getTextOfNode(identifier); } + export function isExpression(node: Node): boolean { + switch (node.kind) { + case SyntaxKind.ThisKeyword: + case SyntaxKind.SuperKeyword: + case SyntaxKind.NullKeyword: + case SyntaxKind.TrueKeyword: + case SyntaxKind.FalseKeyword: + case SyntaxKind.RegularExpressionLiteral: + case SyntaxKind.ArrayLiteral: + case SyntaxKind.ObjectLiteral: + case SyntaxKind.PropertyAccess: + case SyntaxKind.IndexedAccess: + case SyntaxKind.CallExpression: + case SyntaxKind.NewExpression: + case SyntaxKind.TypeAssertion: + case SyntaxKind.ParenExpression: + case SyntaxKind.FunctionExpression: + case SyntaxKind.ArrowFunction: + case SyntaxKind.PrefixOperator: + case SyntaxKind.PostfixOperator: + case SyntaxKind.BinaryExpression: + case SyntaxKind.ConditionalExpression: + case SyntaxKind.OmittedExpression: + return true; + case SyntaxKind.QualifiedName: + while (node.parent.kind === SyntaxKind.QualifiedName) node = node.parent; + return node.parent.kind === SyntaxKind.TypeQuery; + case SyntaxKind.Identifier: + if (node.parent.kind === SyntaxKind.TypeQuery) { + return true; + } + // Fall through + case SyntaxKind.NumericLiteral: + case SyntaxKind.StringLiteral: + var parent = node.parent; + switch (parent.kind) { + case SyntaxKind.VariableDeclaration: + case SyntaxKind.Parameter: + case SyntaxKind.Property: + case SyntaxKind.EnumMember: + case SyntaxKind.PropertyAssignment: + return (parent).initializer === node; + case SyntaxKind.ExpressionStatement: + case SyntaxKind.IfStatement: + case SyntaxKind.DoStatement: + case SyntaxKind.WhileStatement: + case SyntaxKind.ReturnStatement: + case SyntaxKind.WithStatement: + case SyntaxKind.SwitchStatement: + case SyntaxKind.CaseClause: + case SyntaxKind.ThrowStatement: + case SyntaxKind.SwitchStatement: + return (parent).expression === node; + case SyntaxKind.ForStatement: + return (parent).initializer === node || + (parent).condition === node || + (parent).iterator === node; + case SyntaxKind.ForInStatement: + return (parent).variable === node || + (parent).expression === node; + case SyntaxKind.TypeAssertion: + return node === (parent).operand; + default: + if (isExpression(parent)) { + return true; + } + } + } + return false; + } + export function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): Diagnostic { node = getErrorSpanForNode(node); var file = getSourceFileOfNode(node); diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 23a2189d448..a9c9bfaff77 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -53,6 +53,28 @@ module ts.BreakpointResolver { function spanInNode(node: Node): TypeScript.TextSpan { if (node) { + if (isExpression(node)) { + if (node.parent.kind === SyntaxKind.DoStatement) { + // Set span as if on while keyword + return spanInPreviousNode(node); + } + + if (node.parent.kind === SyntaxKind.ForStatement) { + // For now lets set the span on this expression, fix it later + return textSpan(node); + } + + if (node.parent.kind === SyntaxKind.BinaryExpression && (node.parent).operator === SyntaxKind.CommaToken) { + // if this is comma expression, the breakpoint is possible in this expression + return textSpan(node); + } + + if (node.parent.kind == SyntaxKind.ArrowFunction && (node.parent).body == node) { + // If this is body of arrow function, it is allowed to have the breakpoint + return textSpan(node); + } + } + switch (node.kind) { case SyntaxKind.VariableStatement: return spanInVariableStatement(node); @@ -69,6 +91,8 @@ module ts.BreakpointResolver { case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: case SyntaxKind.Constructor: + case SyntaxKind.FunctionExpression: + case SyntaxKind.ArrowFunction: return spanInFunctionDeclaration(node); case SyntaxKind.FunctionBlock: @@ -143,10 +167,12 @@ module ts.BreakpointResolver { case SyntaxKind.ClassDeclaration: return spanInClassDeclaration(node); - case SyntaxKind.BinaryExpression: - case SyntaxKind.PostfixOperator: - case SyntaxKind.PrefixOperator: - return spanInExpression(node); + case SyntaxKind.CallExpression: + case SyntaxKind.NewExpression: + return spanInCallOrNewExpression(node); + + case SyntaxKind.WithStatement: + return spanInWithStatement(node); // Tokens: case SyntaxKind.SemicolonToken: @@ -154,8 +180,8 @@ module ts.BreakpointResolver { return spanInNodeIfStartsOnSameLine(findPrecedingToken(node.pos, sourceFile)); case SyntaxKind.CommaToken: - return spanInCommaToken(node); - + return spanInPreviousNode(node) + case SyntaxKind.OpenBraceToken: return spanInOpenBraceToken(node); @@ -171,6 +197,10 @@ module ts.BreakpointResolver { case SyntaxKind.ColonToken: return spanInColonToken(node); + case SyntaxKind.GreaterThanToken: + case SyntaxKind.LessThanToken: + return spanInGreaterThanOrLessThanToken(node); + // Keywords: case SyntaxKind.WhileKeyword: return spanInWhileKeyword(node); @@ -181,6 +211,21 @@ module ts.BreakpointResolver { return spanInNextNode(node); default: + // If this is name of property assignment, set breakpoint in the initializer + if (node.parent.kind === SyntaxKind.PropertyAssignment && (node.parent).name === node) { + return spanInNode((node.parent).initializer); + } + + // Breakpoint in type assertion goes to its operand + if (node.parent.kind === SyntaxKind.TypeAssertion && (node.parent).type === node) { + return spanInNode((node.parent).operand); + } + + // return type of function go to previous token + if (isAnyFunction(node.parent) && (node.parent).type === node) { + return spanInPreviousNode(node); + } + // Default go to parent to set the breakpoint return spanInNode(node.parent); } @@ -259,21 +304,6 @@ module ts.BreakpointResolver { return; } - // Is this coming because the touchingToken was in typeAnnotation of return type - if (functionDeclaration.type) { - for (var node = tokenAtLocation; node; node = node.parent) { - if (node.parent === functionDeclaration && functionDeclaration.type === node) { - if (functionDeclaration.parameters && functionDeclaration.parameters.length) { - // Set breakpoint in last parameter - return spanInParameterDeclaration(functionDeclaration.parameters[functionDeclaration.parameters.length - 1]); - } - - // Set breakpoint in function body - break; - } - } - } - // Set span in function body return spanInNode(functionDeclaration.body); } @@ -417,39 +447,15 @@ module ts.BreakpointResolver { return spanInNode(classDeclaration.getLastToken()); } - function spanInExpression(expression: Expression): TypeScript.TextSpan { - //TODO (pick this up later) for now lets fix do-while baseline if (node.parent.kind === SyntaxKind.DoStatement) { - // Set span as if on while keyword - return spanInPreviousNode(node); - } - - if (node.parent.kind === SyntaxKind.ForStatement) { - // For now lets set the span on this expression, fix it later - return textSpan(expression); - } - - // Default action for now: - return spanInNode(expression.parent); + function spanInCallOrNewExpression(callOrNewExpression: CallExpression): TypeScript.TextSpan { + return textSpan(callOrNewExpression); } - + + function spanInWithStatement(withStatement: WithStatement): TypeScript.TextSpan { + return spanInNode(withStatement.statement); + } + // Tokens: - function spanInCommaToken(node: Node): TypeScript.TextSpan { - switch (node.parent.kind) { - case SyntaxKind.FunctionDeclaration: - case SyntaxKind.Method: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - case SyntaxKind.Constructor: - case SyntaxKind.VariableStatement: - case SyntaxKind.EnumDeclaration: - return spanInPreviousNode(node); - - // Default to parent node - default: - return spanInNode(node.parent); - } - } - function spanInOpenBraceToken(node: Node): TypeScript.TextSpan { if (node.parent.kind === SyntaxKind.SwitchStatement) { return spanInNodeIfStartsOnSameLine(node.parent, (node.parent).clauses[0]); @@ -534,13 +540,22 @@ module ts.BreakpointResolver { function spanInColonToken(node: Node): TypeScript.TextSpan { // Is this : specifying return annotation of the function declaration - if (isAnyFunction(node.parent)) { + if (isAnyFunction(node.parent) || node.parent.kind === SyntaxKind.PropertyAssignment) { return spanInPreviousNode(node); } return spanInNode(node.parent); } + function spanInGreaterThanOrLessThanToken(node: Node): TypeScript.TextSpan { + if (node.parent.kind === SyntaxKind.TypeAssertion) { + return spanInNode((node.parent).operand); + } + + return spanInNode(node.parent); + } + + function spanInWhileKeyword(node: Node): TypeScript.TextSpan { if (node.parent.kind === SyntaxKind.DoStatement) { // Set span on while expression diff --git a/tests/baselines/reference/bpSpan_arrayLiteralExpressions.baseline b/tests/baselines/reference/bpSpan_arrayLiteralExpressions.baseline new file mode 100644 index 00000000000..d8bfbc84aa0 --- /dev/null +++ b/tests/baselines/reference/bpSpan_arrayLiteralExpressions.baseline @@ -0,0 +1,198 @@ + +1 >var a = [10, 20, 30]; + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (0 to 21) SpanInfo: {"start":0,"length":20} + >var a = [10, 20, 30] + >:=> (line 1, col 0) to (line 1, col 20) +-------------------------------- +2 >function foo(a: number) { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (22 to 47) SpanInfo: {"start":52,"length":8} + >return a + >:=> (line 3, col 4) to (line 3, col 12) +-------------------------------- +3 > return a; + + ~~~~~~~~~~~~~~ => Pos: (48 to 61) SpanInfo: {"start":52,"length":8} + >return a + >:=> (line 3, col 4) to (line 3, col 12) +-------------------------------- +4 >} + + ~~ => Pos: (62 to 63) SpanInfo: {"start":62,"length":1} + >} + >:=> (line 4, col 0) to (line 4, col 1) +-------------------------------- +5 >a = [foo(30), (function () { + + ~~~~~ => Pos: (64 to 68) SpanInfo: {"start":64,"length":49} + >a = [foo(30), (function () { + > return 30; + >})()] + >:=> (line 5, col 0) to (line 7, col 5) +5 >a = [foo(30), (function () { + + ~~~~~~~~ => Pos: (69 to 76) SpanInfo: {"start":69,"length":7} + >foo(30) + >:=> (line 5, col 5) to (line 5, col 12) +5 >a = [foo(30), (function () { + + ~~ => Pos: (77 to 78) SpanInfo: {"start":78,"length":34} + >(function () { + > return 30; + >})() + >:=> (line 5, col 14) to (line 7, col 4) +5 >a = [foo(30), (function () { + + ~~~~~~~~~~~~~~ => Pos: (79 to 92) SpanInfo: {"start":97,"length":9} + >return 30 + >:=> (line 6, col 4) to (line 6, col 13) +-------------------------------- +6 > return 30; + + ~~~~~~~~~~~~~~~ => Pos: (93 to 107) SpanInfo: {"start":97,"length":9} + >return 30 + >:=> (line 6, col 4) to (line 6, col 13) +-------------------------------- +7 >})()]; + + ~ => Pos: (108 to 108) SpanInfo: {"start":108,"length":1} + >} + >:=> (line 7, col 0) to (line 7, col 1) +7 >})()]; + + ~~~ => Pos: (109 to 111) SpanInfo: {"start":78,"length":34} + >(function () { + > return 30; + >})() + >:=> (line 5, col 14) to (line 7, col 4) +7 >})()]; + + ~~~ => Pos: (112 to 114) SpanInfo: {"start":64,"length":49} + >a = [foo(30), (function () { + > return 30; + >})()] + >:=> (line 5, col 0) to (line 7, col 5) +-------------------------------- +8 >function bar() { + + ~~~~~~~~~~~~~~~~~ => Pos: (115 to 131) SpanInfo: {"start":136,"length":8} + >return a + >:=> (line 9, col 4) to (line 9, col 12) +-------------------------------- +9 > return a; + + ~~~~~~~~~~~~~~ => Pos: (132 to 145) SpanInfo: {"start":136,"length":8} + >return a + >:=> (line 9, col 4) to (line 9, col 12) +-------------------------------- +10 >} + + ~~ => Pos: (146 to 147) SpanInfo: {"start":146,"length":1} + >} + >:=> (line 10, col 0) to (line 10, col 1) +-------------------------------- +11 >var x = bar()[0]; + + ~~~~~~~ => Pos: (148 to 154) SpanInfo: {"start":148,"length":16} + >var x = bar()[0] + >:=> (line 11, col 0) to (line 11, col 16) +11 >var x = bar()[0]; + + ~~~~~~ => Pos: (155 to 160) SpanInfo: {"start":156,"length":5} + >bar() + >:=> (line 11, col 8) to (line 11, col 13) +11 >var x = bar()[0]; + + ~~~~~ => Pos: (161 to 165) SpanInfo: {"start":148,"length":16} + >var x = bar()[0] + >:=> (line 11, col 0) to (line 11, col 16) +-------------------------------- +12 >x = (function () { + + ~~~ => Pos: (166 to 168) SpanInfo: {"start":166,"length":40} + >x = (function () { + > return a; + >})()[x] + >:=> (line 12, col 0) to (line 14, col 7) +12 >x = (function () { + + ~~ => Pos: (169 to 170) SpanInfo: {"start":170,"length":33} + >(function () { + > return a; + >})() + >:=> (line 12, col 4) to (line 14, col 4) +12 >x = (function () { + + ~~~~~~~~~~~~~~ => Pos: (171 to 184) SpanInfo: {"start":189,"length":8} + >return a + >:=> (line 13, col 4) to (line 13, col 12) +-------------------------------- +13 > return a; + + ~~~~~~~~~~~~~~ => Pos: (185 to 198) SpanInfo: {"start":189,"length":8} + >return a + >:=> (line 13, col 4) to (line 13, col 12) +-------------------------------- +14 >})()[x]; + + ~ => Pos: (199 to 199) SpanInfo: {"start":199,"length":1} + >} + >:=> (line 14, col 0) to (line 14, col 1) +14 >})()[x]; + + ~~~ => Pos: (200 to 202) SpanInfo: {"start":170,"length":33} + >(function () { + > return a; + >})() + >:=> (line 12, col 4) to (line 14, col 4) +14 >})()[x]; + + ~~~~~ => Pos: (203 to 207) SpanInfo: {"start":166,"length":40} + >x = (function () { + > return a; + >})()[x] + >:=> (line 12, col 0) to (line 14, col 7) +-------------------------------- +15 >a[(function () { + + ~~ => Pos: (208 to 209) SpanInfo: {"start":208,"length":36} + >a[(function () { + > return x; + >})()] + >:=> (line 15, col 0) to (line 17, col 5) +15 >a[(function () { + + ~ => Pos: (210 to 210) SpanInfo: {"start":210,"length":33} + >(function () { + > return x; + >})() + >:=> (line 15, col 2) to (line 17, col 4) +15 >a[(function () { + + ~~~~~~~~~~~~~~ => Pos: (211 to 224) SpanInfo: {"start":229,"length":8} + >return x + >:=> (line 16, col 4) to (line 16, col 12) +-------------------------------- +16 > return x; + + ~~~~~~~~~~~~~~ => Pos: (225 to 238) SpanInfo: {"start":229,"length":8} + >return x + >:=> (line 16, col 4) to (line 16, col 12) +-------------------------------- +17 >})()]; + ~ => Pos: (239 to 239) SpanInfo: {"start":239,"length":1} + >} + >:=> (line 17, col 0) to (line 17, col 1) +17 >})()]; + ~~~ => Pos: (240 to 242) SpanInfo: {"start":210,"length":33} + >(function () { + > return x; + >})() + >:=> (line 15, col 2) to (line 17, col 4) +17 >})()]; + ~~ => Pos: (243 to 244) SpanInfo: {"start":208,"length":36} + >a[(function () { + > return x; + >})()] + >:=> (line 15, col 0) to (line 17, col 5) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_binaryExpressions.baseline b/tests/baselines/reference/bpSpan_binaryExpressions.baseline new file mode 100644 index 00000000000..370fec39a25 --- /dev/null +++ b/tests/baselines/reference/bpSpan_binaryExpressions.baseline @@ -0,0 +1,119 @@ + +1 >var x = 10; + + ~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":0,"length":10} + >var x = 10 + >:=> (line 1, col 0) to (line 1, col 10) +-------------------------------- +2 >var y = 20; + + ~~~~~~~~~~~~ => Pos: (12 to 23) SpanInfo: {"start":12,"length":10} + >var y = 20 + >:=> (line 2, col 0) to (line 2, col 10) +-------------------------------- +3 >x += 30; + + ~~~~~~~~~ => Pos: (24 to 32) SpanInfo: {"start":24,"length":7} + >x += 30 + >:=> (line 3, col 0) to (line 3, col 7) +-------------------------------- +4 >x *= 0; + + ~~~~~~~~ => Pos: (33 to 40) SpanInfo: {"start":33,"length":6} + >x *= 0 + >:=> (line 4, col 0) to (line 4, col 6) +-------------------------------- +5 >x = x + 1; + + ~~~~~~~~~~~ => Pos: (41 to 51) SpanInfo: {"start":41,"length":9} + >x = x + 1 + >:=> (line 5, col 0) to (line 5, col 9) +-------------------------------- +6 >x = (function foo() { + + ~~~ => Pos: (52 to 54) SpanInfo: {"start":52,"length":44} + >x = (function foo() { + > return y; + >})() + y + >:=> (line 6, col 0) to (line 8, col 8) +6 >x = (function foo() { + + ~~ => Pos: (55 to 56) SpanInfo: {"start":56,"length":36} + >(function foo() { + > return y; + >})() + >:=> (line 6, col 4) to (line 8, col 4) +6 >x = (function foo() { + + ~~~~~~~~~~~~~~~~~ => Pos: (57 to 73) SpanInfo: {"start":78,"length":8} + >return y + >:=> (line 7, col 4) to (line 7, col 12) +-------------------------------- +7 > return y; + + ~~~~~~~~~~~~~~ => Pos: (74 to 87) SpanInfo: {"start":78,"length":8} + >return y + >:=> (line 7, col 4) to (line 7, col 12) +-------------------------------- +8 >})() + y; + + ~ => Pos: (88 to 88) SpanInfo: {"start":88,"length":1} + >} + >:=> (line 8, col 0) to (line 8, col 1) +8 >})() + y; + + ~~~ => Pos: (89 to 91) SpanInfo: {"start":56,"length":36} + >(function foo() { + > return y; + >})() + >:=> (line 6, col 4) to (line 8, col 4) +8 >})() + y; + + ~~~~~~ => Pos: (92 to 97) SpanInfo: {"start":52,"length":44} + >x = (function foo() { + > return y; + >})() + y + >:=> (line 6, col 0) to (line 8, col 8) +-------------------------------- +9 >x = y + 30 + (function foo() { + + ~~~~~~~~~~~~ => Pos: (98 to 109) SpanInfo: {"start":98,"length":54} + >x = y + 30 + (function foo() { + > return y; + >})() * 40 + >:=> (line 9, col 0) to (line 11, col 9) +9 >x = y + 30 + (function foo() { + + ~~ => Pos: (110 to 111) SpanInfo: {"start":111,"length":36} + >(function foo() { + > return y; + >})() + >:=> (line 9, col 13) to (line 11, col 4) +9 >x = y + 30 + (function foo() { + + ~~~~~~~~~~~~~~~~~ => Pos: (112 to 128) SpanInfo: {"start":133,"length":8} + >return y + >:=> (line 10, col 4) to (line 10, col 12) +-------------------------------- +10 > return y; + + ~~~~~~~~~~~~~~ => Pos: (129 to 142) SpanInfo: {"start":133,"length":8} + >return y + >:=> (line 10, col 4) to (line 10, col 12) +-------------------------------- +11 >})() * 40; + ~ => Pos: (143 to 143) SpanInfo: {"start":143,"length":1} + >} + >:=> (line 11, col 0) to (line 11, col 1) +11 >})() * 40; + ~~~ => Pos: (144 to 146) SpanInfo: {"start":111,"length":36} + >(function foo() { + > return y; + >})() + >:=> (line 9, col 13) to (line 11, col 4) +11 >})() * 40; + ~~~~~~ => Pos: (147 to 152) SpanInfo: {"start":98,"length":54} + >x = y + 30 + (function foo() { + > return y; + >})() * 40 + >:=> (line 9, col 0) to (line 11, col 9) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_classes.baseline b/tests/baselines/reference/bpSpan_classes.baseline new file mode 100644 index 00000000000..88409460d03 --- /dev/null +++ b/tests/baselines/reference/bpSpan_classes.baseline @@ -0,0 +1,284 @@ + +1 >module Foo.Bar { + + ~~~~~~~~~~~~~~~~~ => Pos: (0 to 16) SpanInfo: {"start":21,"length":12} + >"use strict" + >:=> (line 2, col 4) to (line 2, col 16) +-------------------------------- +2 > "use strict"; + + ~~~~~~~~~~~~~~~~~~ => Pos: (17 to 34) SpanInfo: {"start":21,"length":12} + >"use strict" + >:=> (line 2, col 4) to (line 2, col 16) +-------------------------------- +3 > + + ~ => Pos: (35 to 35) SpanInfo: undefined +-------------------------------- +4 > class Greeter { + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (36 to 55) SpanInfo: {"start":111,"length":1} + >} + >:=> (line 6, col 8) to (line 6, col 9) +-------------------------------- +5 > constructor(public greeting: string) { + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (56 to 75) SpanInfo: {"start":111,"length":1} + >} + >:=> (line 6, col 8) to (line 6, col 9) +5 > constructor(public greeting: string) { + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (76 to 99) SpanInfo: {"start":76,"length":23} + >public greeting: string + >:=> (line 5, col 20) to (line 5, col 43) +5 > constructor(public greeting: string) { + + ~~~=> Pos: (100 to 102) SpanInfo: {"start":111,"length":1} + >} + >:=> (line 6, col 8) to (line 6, col 9) +-------------------------------- +6 > } + + ~~~~~~~~~~ => Pos: (103 to 112) SpanInfo: {"start":111,"length":1} + >} + >:=> (line 6, col 8) to (line 6, col 9) +-------------------------------- +7 > + + ~ => Pos: (113 to 113) SpanInfo: {"start":111,"length":1} + >} + >:=> (line 6, col 8) to (line 6, col 9) +-------------------------------- +8 > greet() { + + ~~~~~~~~~~~~~~~~~~ => Pos: (114 to 131) SpanInfo: {"start":144,"length":39} + >return "

" + this.greeting + "

" + >:=> (line 9, col 12) to (line 9, col 51) +-------------------------------- +9 > return "

" + this.greeting + "

"; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (132 to 184) SpanInfo: {"start":144,"length":39} + >return "

" + this.greeting + "

" + >:=> (line 9, col 12) to (line 9, col 51) +-------------------------------- +10 > } + + ~~~~~~~~~~ => Pos: (185 to 194) SpanInfo: {"start":193,"length":1} + >} + >:=> (line 10, col 8) to (line 10, col 9) +-------------------------------- +11 > } + + ~~~~~~ => Pos: (195 to 200) SpanInfo: {"start":199,"length":1} + >} + >:=> (line 11, col 4) to (line 11, col 5) +-------------------------------- +12 > + + ~ => Pos: (201 to 201) SpanInfo: {"start":199,"length":1} + >} + >:=> (line 11, col 4) to (line 11, col 5) +-------------------------------- +13 > + + ~ => Pos: (202 to 202) SpanInfo: {"start":199,"length":1} + >} + >:=> (line 11, col 4) to (line 11, col 5) +-------------------------------- +14 > function foo(greeting: string): Greeter { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (203 to 248) SpanInfo: {"start":257,"length":28} + >return new Greeter(greeting) + >:=> (line 15, col 8) to (line 15, col 36) +-------------------------------- +15 > return new Greeter(greeting); + + ~~~~~~~~~~~~~~ => Pos: (249 to 262) SpanInfo: {"start":257,"length":28} + >return new Greeter(greeting) + >:=> (line 15, col 8) to (line 15, col 36) +15 > return new Greeter(greeting); + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (263 to 286) SpanInfo: {"start":264,"length":21} + >new Greeter(greeting) + >:=> (line 15, col 15) to (line 15, col 36) +-------------------------------- +16 > } + + ~~~~~~ => Pos: (287 to 292) SpanInfo: {"start":291,"length":1} + >} + >:=> (line 16, col 4) to (line 16, col 5) +-------------------------------- +17 > + + ~ => Pos: (293 to 293) SpanInfo: {"start":291,"length":1} + >} + >:=> (line 16, col 4) to (line 16, col 5) +-------------------------------- +18 > var greeter = new Greeter("Hello, world!"); + + ~~~~~~~~~~~~~~~~~ => Pos: (294 to 310) SpanInfo: {"start":298,"length":42} + >var greeter = new Greeter("Hello, world!") + >:=> (line 18, col 4) to (line 18, col 46) +18 > var greeter = new Greeter("Hello, world!"); + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (311 to 341) SpanInfo: {"start":312,"length":28} + >new Greeter("Hello, world!") + >:=> (line 18, col 18) to (line 18, col 46) +-------------------------------- +19 > var str = greeter.greet(); + + ~~~~~~~~~~~~~ => Pos: (342 to 354) SpanInfo: {"start":346,"length":25} + >var str = greeter.greet() + >:=> (line 19, col 4) to (line 19, col 29) +19 > var str = greeter.greet(); + + ~~~~~~~~~~~~~~~~~~ => Pos: (355 to 372) SpanInfo: {"start":356,"length":15} + >greeter.greet() + >:=> (line 19, col 14) to (line 19, col 29) +-------------------------------- +20 > + + ~ => Pos: (373 to 373) SpanInfo: undefined +-------------------------------- +21 > function foo2(greeting: string, ...restGreetings /* more greeting */: string[]) { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (374 to 408) SpanInfo: {"start":468,"length":28} + >var greeters: Greeter[] = [] + >:=> (line 22, col 8) to (line 22, col 36) +21 > function foo2(greeting: string, ...restGreetings /* more greeting */: string[]) { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (409 to 456) SpanInfo: {"start":410,"length":46} + >...restGreetings /* more greeting */: string[] + >:=> (line 21, col 36) to (line 21, col 82) +21 > function foo2(greeting: string, ...restGreetings /* more greeting */: string[]) { + + ~~~=> Pos: (457 to 459) SpanInfo: {"start":468,"length":28} + >var greeters: Greeter[] = [] + >:=> (line 22, col 8) to (line 22, col 36) +-------------------------------- +22 > var greeters: Greeter[] = []; /* inline block comment */ + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (460 to 524) SpanInfo: {"start":468,"length":28} + >var greeters: Greeter[] = [] + >:=> (line 22, col 8) to (line 22, col 36) +-------------------------------- +23 > greeters[0] = new Greeter(greeting); + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (525 to 545) SpanInfo: {"start":533,"length":35} + >greeters[0] = new Greeter(greeting) + >:=> (line 23, col 8) to (line 23, col 43) +23 > greeters[0] = new Greeter(greeting); + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (546 to 569) SpanInfo: {"start":547,"length":21} + >new Greeter(greeting) + >:=> (line 23, col 22) to (line 23, col 43) +-------------------------------- +24 > for (var i = 0; i < restGreetings.length; i++) { + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (570 to 592) SpanInfo: {"start":583,"length":9} + >var i = 0 + >:=> (line 24, col 13) to (line 24, col 22) +24 > for (var i = 0; i < restGreetings.length; i++) { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (593 to 618) SpanInfo: {"start":594,"length":24} + >i < restGreetings.length + >:=> (line 24, col 24) to (line 24, col 48) +24 > for (var i = 0; i < restGreetings.length; i++) { + + ~~~~~~~~=> Pos: (619 to 626) SpanInfo: {"start":620,"length":3} + >i++ + >:=> (line 24, col 50) to (line 24, col 53) +-------------------------------- +25 > greeters.push(new Greeter(restGreetings[i])); + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (627 to 652) SpanInfo: {"start":639,"length":44} + >greeters.push(new Greeter(restGreetings[i])) + >:=> (line 25, col 12) to (line 25, col 56) +25 > greeters.push(new Greeter(restGreetings[i])); + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (653 to 681) SpanInfo: {"start":653,"length":29} + >new Greeter(restGreetings[i]) + >:=> (line 25, col 26) to (line 25, col 55) +25 > greeters.push(new Greeter(restGreetings[i])); + + ~~~=> Pos: (682 to 684) SpanInfo: {"start":639,"length":44} + >greeters.push(new Greeter(restGreetings[i])) + >:=> (line 25, col 12) to (line 25, col 56) +-------------------------------- +26 > } + + ~~~~~~~~~~ => Pos: (685 to 694) SpanInfo: {"start":639,"length":44} + >greeters.push(new Greeter(restGreetings[i])) + >:=> (line 25, col 12) to (line 25, col 56) +-------------------------------- +27 > + + ~ => Pos: (695 to 695) SpanInfo: {"start":639,"length":44} + >greeters.push(new Greeter(restGreetings[i])) + >:=> (line 25, col 12) to (line 25, col 56) +-------------------------------- +28 > return greeters; + + ~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (696 to 720) SpanInfo: {"start":704,"length":15} + >return greeters + >:=> (line 28, col 8) to (line 28, col 23) +-------------------------------- +29 > } + + ~~~~~~ => Pos: (721 to 726) SpanInfo: {"start":725,"length":1} + >} + >:=> (line 29, col 4) to (line 29, col 5) +-------------------------------- +30 > + + ~ => Pos: (727 to 727) SpanInfo: {"start":725,"length":1} + >} + >:=> (line 29, col 4) to (line 29, col 5) +-------------------------------- +31 > var b = foo2("Hello", "World", "!"); + + ~~~~~~~~~~~ => Pos: (728 to 738) SpanInfo: {"start":732,"length":35} + >var b = foo2("Hello", "World", "!") + >:=> (line 31, col 4) to (line 31, col 39) +31 > var b = foo2("Hello", "World", "!"); + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (739 to 768) SpanInfo: {"start":740,"length":27} + >foo2("Hello", "World", "!") + >:=> (line 31, col 12) to (line 31, col 39) +-------------------------------- +32 > // This is simple signle line comment + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (769 to 810) SpanInfo: undefined +-------------------------------- +33 > for (var j = 0; j < b.length; j++) { + + ~~~~~~~~~~~~~~~~~~~ => Pos: (811 to 829) SpanInfo: {"start":820,"length":9} + >var j = 0 + >:=> (line 33, col 9) to (line 33, col 18) +33 > for (var j = 0; j < b.length; j++) { + + ~~~~~~~~~~~~~~ => Pos: (830 to 843) SpanInfo: {"start":831,"length":12} + >j < b.length + >:=> (line 33, col 20) to (line 33, col 32) +33 > for (var j = 0; j < b.length; j++) { + + ~~~~~~~~ => Pos: (844 to 851) SpanInfo: {"start":845,"length":3} + >j++ + >:=> (line 33, col 34) to (line 33, col 37) +-------------------------------- +34 > b[j].greet(); + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (852 to 873) SpanInfo: {"start":860,"length":12} + >b[j].greet() + >:=> (line 34, col 8) to (line 34, col 20) +-------------------------------- +35 > } + + ~~~~~~ => Pos: (874 to 879) SpanInfo: {"start":860,"length":12} + >b[j].greet() + >:=> (line 34, col 8) to (line 34, col 20) +-------------------------------- +36 >} + ~ => Pos: (880 to 880) SpanInfo: {"start":880,"length":1} + >} + >:=> (line 36, col 0) to (line 36, col 1) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_conditionalExpressions.baseline b/tests/baselines/reference/bpSpan_conditionalExpressions.baseline new file mode 100644 index 00000000000..5abd49d50cf --- /dev/null +++ b/tests/baselines/reference/bpSpan_conditionalExpressions.baseline @@ -0,0 +1,129 @@ + +1 >var x = 10; + + ~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":0,"length":10} + >var x = 10 + >:=> (line 1, col 0) to (line 1, col 10) +-------------------------------- +2 >var y = x ? x + 10 : 30; + + ~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (12 to 36) SpanInfo: {"start":12,"length":23} + >var y = x ? x + 10 : 30 + >:=> (line 2, col 0) to (line 2, col 23) +-------------------------------- +3 >var z = (function foo() { + + ~~~~~~~ => Pos: (37 to 43) SpanInfo: {"start":37,"length":90} + >var z = (function foo() { + > return x; + >})() ? y : function bar() { + > return x; + >} () + >:=> (line 3, col 0) to (line 7, col 4) +3 >var z = (function foo() { + + ~~ => Pos: (44 to 45) SpanInfo: {"start":45,"length":36} + >(function foo() { + > return x; + >})() + >:=> (line 3, col 8) to (line 5, col 4) +3 >var z = (function foo() { + + ~~~~~~~~~~~~~~~~~ => Pos: (46 to 62) SpanInfo: {"start":67,"length":8} + >return x + >:=> (line 4, col 4) to (line 4, col 12) +-------------------------------- +4 > return x; + + ~~~~~~~~~~~~~~ => Pos: (63 to 76) SpanInfo: {"start":67,"length":8} + >return x + >:=> (line 4, col 4) to (line 4, col 12) +-------------------------------- +5 >})() ? y : function bar() { + + ~ => Pos: (77 to 77) SpanInfo: {"start":77,"length":1} + >} + >:=> (line 5, col 0) to (line 5, col 1) +5 >})() ? y : function bar() { + + ~~~ => Pos: (78 to 80) SpanInfo: {"start":45,"length":36} + >(function foo() { + > return x; + >})() + >:=> (line 3, col 8) to (line 5, col 4) +5 >})() ? y : function bar() { + + ~~~~~~ => Pos: (81 to 86) SpanInfo: {"start":37,"length":90} + >var z = (function foo() { + > return x; + >})() ? y : function bar() { + > return x; + >} () + >:=> (line 3, col 0) to (line 7, col 4) +5 >})() ? y : function bar() { + + ~~~~~~~~~~~~~~~~~~ => Pos: (87 to 104) SpanInfo: {"start":113,"length":8} + >return x + >:=> (line 6, col 8) to (line 6, col 16) +-------------------------------- +6 > return x; + + ~~~~~~~~~~~~~~~~~~ => Pos: (105 to 122) SpanInfo: {"start":113,"length":8} + >return x + >:=> (line 6, col 8) to (line 6, col 16) +-------------------------------- +7 >} (); + + ~ => Pos: (123 to 123) SpanInfo: {"start":123,"length":1} + >} + >:=> (line 7, col 0) to (line 7, col 1) +7 >} (); + + ~~~~~ => Pos: (124 to 128) SpanInfo: {"start":88,"length":39} + >function bar() { + > return x; + >} () + >:=> (line 5, col 11) to (line 7, col 4) +-------------------------------- +8 >x = y ? (function () { + + ~~~~~~~ => Pos: (129 to 135) SpanInfo: {"start":129,"length":47} + >x = y ? (function () { + > return z; + >})() : 10 + >:=> (line 8, col 0) to (line 10, col 10) +8 >x = y ? (function () { + + ~~ => Pos: (136 to 137) SpanInfo: {"start":137,"length":33} + >(function () { + > return z; + >})() + >:=> (line 8, col 8) to (line 10, col 4) +8 >x = y ? (function () { + + ~~~~~~~~~~~~~~ => Pos: (138 to 151) SpanInfo: {"start":156,"length":8} + >return z + >:=> (line 9, col 4) to (line 9, col 12) +-------------------------------- +9 > return z; + + ~~~~~~~~~~~~~~ => Pos: (152 to 165) SpanInfo: {"start":156,"length":8} + >return z + >:=> (line 9, col 4) to (line 9, col 12) +-------------------------------- +10 >})() : 10; + ~ => Pos: (166 to 166) SpanInfo: {"start":166,"length":1} + >} + >:=> (line 10, col 0) to (line 10, col 1) +10 >})() : 10; + ~~~ => Pos: (167 to 169) SpanInfo: {"start":137,"length":33} + >(function () { + > return z; + >})() + >:=> (line 8, col 8) to (line 10, col 4) +10 >})() : 10; + ~~~~~~~ => Pos: (170 to 176) SpanInfo: {"start":129,"length":47} + >x = y ? (function () { + > return z; + >})() : 10 + >:=> (line 8, col 0) to (line 10, col 10) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_do.baseline b/tests/baselines/reference/bpSpan_do.baseline index 0e8559ce65f..3ff287c2046 100644 --- a/tests/baselines/reference/bpSpan_do.baseline +++ b/tests/baselines/reference/bpSpan_do.baseline @@ -76,6 +76,67 @@ >:=> (line 10, col 4) to (line 10, col 7) -------------------------------- 12 >while (i < 30); - ~~~~~~~~~~~~~~~ => Pos: (92 to 106) SpanInfo: {"start":92,"length":14} + + ~~~~~~~~~~~~~~~~ => Pos: (92 to 107) SpanInfo: {"start":92,"length":14} >while (i < 30) - >:=> (line 12, col 0) to (line 12, col 14) \ No newline at end of file + >:=> (line 12, col 0) to (line 12, col 14) +-------------------------------- +13 >do { + + ~~~~~ => Pos: (108 to 112) SpanInfo: {"start":117,"length":3} + >i-- + >:=> (line 14, col 4) to (line 14, col 7) +-------------------------------- +14 > i--; + + ~~~~~~~~~ => Pos: (113 to 121) SpanInfo: {"start":117,"length":3} + >i-- + >:=> (line 14, col 4) to (line 14, col 7) +-------------------------------- +15 >} while ((function () { + + ~ => Pos: (122 to 122) SpanInfo: {"start":117,"length":3} + >i-- + >:=> (line 14, col 4) to (line 14, col 7) +15 >} while ((function () { + + ~~~~~~~~ => Pos: (123 to 130) SpanInfo: {"start":124,"length":60} + >while ((function () { + > return 30 * i; + > })() !== i) + >:=> (line 15, col 2) to (line 17, col 15) +15 >} while ((function () { + + ~ => Pos: (131 to 131) SpanInfo: {"start":131,"length":46} + >(function () { + > return 30 * i; + > })() + >:=> (line 15, col 9) to (line 17, col 8) +15 >} while ((function () { + + ~~~~~~~~~~~~~~ => Pos: (132 to 145) SpanInfo: {"start":154,"length":13} + >return 30 * i + >:=> (line 16, col 8) to (line 16, col 21) +-------------------------------- +16 > return 30 * i; + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (146 to 168) SpanInfo: {"start":154,"length":13} + >return 30 * i + >:=> (line 16, col 8) to (line 16, col 21) +-------------------------------- +17 > })() !== i); + ~~~~~ => Pos: (169 to 173) SpanInfo: {"start":173,"length":1} + >} + >:=> (line 17, col 4) to (line 17, col 5) +17 > })() !== i); + ~~~ => Pos: (174 to 176) SpanInfo: {"start":131,"length":46} + >(function () { + > return 30 * i; + > })() + >:=> (line 15, col 9) to (line 17, col 8) +17 > })() !== i); + ~~~~~~~~~ => Pos: (177 to 185) SpanInfo: {"start":124,"length":60} + >while ((function () { + > return 30 * i; + > })() !== i) + >:=> (line 15, col 2) to (line 17, col 15) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_for.baseline b/tests/baselines/reference/bpSpan_for.baseline index 89580008c67..7fd6ba4c858 100644 --- a/tests/baselines/reference/bpSpan_for.baseline +++ b/tests/baselines/reference/bpSpan_for.baseline @@ -220,14 +220,29 @@ -------------------------------- 32 >for (i = 0, j = 20; j < 20, i < 20; j++) { - ~~~~~~~~~~~~~~~~~~~ => Pos: (351 to 369) SpanInfo: {"start":356,"length":13} + ~~~~~ => Pos: (351 to 355) SpanInfo: {"start":356,"length":13} >i = 0, j = 20 >:=> (line 32, col 5) to (line 32, col 18) 32 >for (i = 0, j = 20; j < 20, i < 20; j++) { - ~~~~~~~~~~~~~~~~ => Pos: (370 to 385) SpanInfo: {"start":371,"length":14} - >j < 20, i < 20 - >:=> (line 32, col 20) to (line 32, col 34) + ~~~~~~ => Pos: (356 to 361) SpanInfo: {"start":356,"length":5} + >i = 0 + >:=> (line 32, col 5) to (line 32, col 10) +32 >for (i = 0, j = 20; j < 20, i < 20; j++) { + + ~~~~~~~~ => Pos: (362 to 369) SpanInfo: {"start":363,"length":6} + >j = 20 + >:=> (line 32, col 12) to (line 32, col 18) +32 >for (i = 0, j = 20; j < 20, i < 20; j++) { + + ~~~~~~~~ => Pos: (370 to 377) SpanInfo: {"start":371,"length":6} + >j < 20 + >:=> (line 32, col 20) to (line 32, col 26) +32 >for (i = 0, j = 20; j < 20, i < 20; j++) { + + ~~~~~~~~ => Pos: (378 to 385) SpanInfo: {"start":379,"length":6} + >i < 20 + >:=> (line 32, col 28) to (line 32, col 34) 32 >for (i = 0, j = 20; j < 20, i < 20; j++) { ~~~~~~~~ => Pos: (386 to 393) SpanInfo: {"start":387,"length":3} diff --git a/tests/baselines/reference/bpSpan_forIn.baseline b/tests/baselines/reference/bpSpan_forIn.baseline index 5c2e6b6d01e..c2b72df5b12 100644 --- a/tests/baselines/reference/bpSpan_forIn.baseline +++ b/tests/baselines/reference/bpSpan_forIn.baseline @@ -78,6 +78,66 @@ >:=> (line 13, col 4) to (line 13, col 19) -------------------------------- 14 >} - ~ => Pos: (180 to 180) SpanInfo: {"start":163,"length":15} + + ~~ => Pos: (180 to 181) SpanInfo: {"start":163,"length":15} >WScript.Echo(x) - >:=> (line 13, col 4) to (line 13, col 19) \ No newline at end of file + >:=> (line 13, col 4) to (line 13, col 19) +-------------------------------- +15 >var z = 10; + + ~~~~~~~~~~~~ => Pos: (182 to 193) SpanInfo: {"start":182,"length":10} + >var z = 10 + >:=> (line 15, col 0) to (line 15, col 10) +-------------------------------- +16 >for (x in function foo() { + + ~~~~~~~~~ => Pos: (194 to 202) SpanInfo: {"start":194,"length":54} + >for (x in function foo() { + > return new String(); + >}) + >:=> (line 16, col 0) to (line 18, col 2) +16 >for (x in function foo() { + + ~~~~~~~~~~~~~~~~~~ => Pos: (203 to 220) SpanInfo: {"start":225,"length":19} + >return new String() + >:=> (line 17, col 4) to (line 17, col 23) +-------------------------------- +17 > return new String(); + + ~~~~~~~~~~ => Pos: (221 to 230) SpanInfo: {"start":225,"length":19} + >return new String() + >:=> (line 17, col 4) to (line 17, col 23) +17 > return new String(); + + ~~~~~~~~~~~~~~~ => Pos: (231 to 245) SpanInfo: {"start":232,"length":12} + >new String() + >:=> (line 17, col 11) to (line 17, col 23) +-------------------------------- +18 >}) { + + ~ => Pos: (246 to 246) SpanInfo: {"start":246,"length":1} + >} + >:=> (line 18, col 0) to (line 18, col 1) +18 >}) { + + ~ => Pos: (247 to 247) SpanInfo: {"start":194,"length":54} + >for (x in function foo() { + > return new String(); + >}) + >:=> (line 16, col 0) to (line 18, col 2) +18 >}) { + + ~~~ => Pos: (248 to 250) SpanInfo: {"start":255,"length":3} + >z++ + >:=> (line 19, col 4) to (line 19, col 7) +-------------------------------- +19 > z++; + + ~~~~~~~~~ => Pos: (251 to 259) SpanInfo: {"start":255,"length":3} + >z++ + >:=> (line 19, col 4) to (line 19, col 7) +-------------------------------- +20 >} + ~ => Pos: (260 to 260) SpanInfo: {"start":255,"length":3} + >z++ + >:=> (line 19, col 4) to (line 19, col 7) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_functionExpressions.baseline b/tests/baselines/reference/bpSpan_functionExpressions.baseline new file mode 100644 index 00000000000..135edff9418 --- /dev/null +++ b/tests/baselines/reference/bpSpan_functionExpressions.baseline @@ -0,0 +1,189 @@ + +1 >var greetings = 0; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (0 to 18) SpanInfo: {"start":0,"length":17} + >var greetings = 0 + >:=> (line 1, col 0) to (line 1, col 17) +-------------------------------- +2 >var greet = (greeting: string): number => { + + ~~~~~~~~~~~ => Pos: (19 to 29) SpanInfo: {"start":19,"length":84} + >var greet = (greeting: string): number => { + > greetings++; + > return greetings; + >} + >:=> (line 2, col 0) to (line 5, col 1) +2 >var greet = (greeting: string): number => { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (30 to 62) SpanInfo: {"start":67,"length":11} + >greetings++ + >:=> (line 3, col 4) to (line 3, col 15) +-------------------------------- +3 > greetings++; + + ~~~~~~~~~~~~~~~~~ => Pos: (63 to 79) SpanInfo: {"start":67,"length":11} + >greetings++ + >:=> (line 3, col 4) to (line 3, col 15) +-------------------------------- +4 > return greetings; + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (80 to 101) SpanInfo: {"start":84,"length":16} + >return greetings + >:=> (line 4, col 4) to (line 4, col 20) +-------------------------------- +5 >} + + ~~ => Pos: (102 to 103) SpanInfo: {"start":102,"length":1} + >} + >:=> (line 5, col 0) to (line 5, col 1) +-------------------------------- +6 >greet("Hello"); + + ~~~~~~~~~~~~~~~~ => Pos: (104 to 119) SpanInfo: {"start":104,"length":14} + >greet("Hello") + >:=> (line 6, col 0) to (line 6, col 14) +-------------------------------- +7 >var incrGreetings = () => greetings++; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (120 to 138) SpanInfo: {"start":120,"length":37} + >var incrGreetings = () => greetings++ + >:=> (line 7, col 0) to (line 7, col 37) +7 >var incrGreetings = () => greetings++; + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (139 to 158) SpanInfo: {"start":146,"length":11} + >greetings++ + >:=> (line 7, col 26) to (line 7, col 37) +-------------------------------- +8 >var greetNewMsg = msg => greet(msg); + + ~~~~~~~~~~~~~~~~~ => Pos: (159 to 175) SpanInfo: {"start":159,"length":35} + >var greetNewMsg = msg => greet(msg) + >:=> (line 8, col 0) to (line 8, col 35) +8 >var greetNewMsg = msg => greet(msg); + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (176 to 195) SpanInfo: {"start":184,"length":10} + >greet(msg) + >:=> (line 8, col 25) to (line 8, col 35) +-------------------------------- +9 >greetNewMsg = function (msg: string) { + + ~~~~~~~~~~~~~ => Pos: (196 to 208) SpanInfo: {"start":196,"length":63} + >greetNewMsg = function (msg: string) { + > return greet(msg); + >} + >:=> (line 9, col 0) to (line 11, col 1) +9 >greetNewMsg = function (msg: string) { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (209 to 234) SpanInfo: {"start":239,"length":17} + >return greet(msg) + >:=> (line 10, col 4) to (line 10, col 21) +-------------------------------- +10 > return greet(msg); + + ~~~~~~~~~~ => Pos: (235 to 244) SpanInfo: {"start":239,"length":17} + >return greet(msg) + >:=> (line 10, col 4) to (line 10, col 21) +10 > return greet(msg); + + ~~~~~~~~~~~~~ => Pos: (245 to 257) SpanInfo: {"start":246,"length":10} + >greet(msg) + >:=> (line 10, col 11) to (line 10, col 21) +-------------------------------- +11 >}; + + ~~~ => Pos: (258 to 260) SpanInfo: {"start":258,"length":1} + >} + >:=> (line 11, col 0) to (line 11, col 1) +-------------------------------- +12 >function bar(a = function foo() { + + ~~~~~~~~~~~~~ => Pos: (261 to 273) SpanInfo: {"start":326,"length":9} + >if (!a()) + >:=> (line 15, col 4) to (line 15, col 13) +12 >function bar(a = function foo() { + + ~~~ => Pos: (274 to 276) SpanInfo: {"start":274,"length":44} + >a = function foo() { + > return greetings; + >} + >:=> (line 12, col 13) to (line 14, col 1) +12 >function bar(a = function foo() { + + ~~~~~~~~~~~~~~~~~~ => Pos: (277 to 294) SpanInfo: {"start":299,"length":16} + >return greetings + >:=> (line 13, col 4) to (line 13, col 20) +-------------------------------- +13 > return greetings; + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (295 to 316) SpanInfo: {"start":299,"length":16} + >return greetings + >:=> (line 13, col 4) to (line 13, col 20) +-------------------------------- +14 >}) { + + ~~ => Pos: (317 to 318) SpanInfo: {"start":317,"length":1} + >} + >:=> (line 14, col 0) to (line 14, col 1) +14 >}) { + + ~~~ => Pos: (319 to 321) SpanInfo: {"start":326,"length":9} + >if (!a()) + >:=> (line 15, col 4) to (line 15, col 13) +-------------------------------- +15 > if (!a()) { + + ~~~~~~~~~ => Pos: (322 to 330) SpanInfo: {"start":326,"length":9} + >if (!a()) + >:=> (line 15, col 4) to (line 15, col 13) +15 > if (!a()) { + + ~~~ => Pos: (331 to 333) SpanInfo: {"start":331,"length":3} + >a() + >:=> (line 15, col 9) to (line 15, col 12) +15 > if (!a()) { + + ~~~~ => Pos: (334 to 337) SpanInfo: {"start":326,"length":9} + >if (!a()) + >:=> (line 15, col 4) to (line 15, col 13) +-------------------------------- +16 > return a; + + ~~~~~~~~~~~~~~~~~~ => Pos: (338 to 355) SpanInfo: {"start":346,"length":8} + >return a + >:=> (line 16, col 8) to (line 16, col 16) +-------------------------------- +17 > } + + ~~~~~~ => Pos: (356 to 361) SpanInfo: {"start":346,"length":8} + >return a + >:=> (line 16, col 8) to (line 16, col 16) +-------------------------------- +18 > return function bar() { + + ~~~~~~~~~~ => Pos: (362 to 371) SpanInfo: {"start":366,"length":56} + >return function bar() { + > return -greetings; + > } + >:=> (line 18, col 4) to (line 20, col 5) +18 > return function bar() { + + ~~~~~~~~~~~~~~~~~~ => Pos: (372 to 389) SpanInfo: {"start":398,"length":17} + >return -greetings + >:=> (line 19, col 8) to (line 19, col 25) +-------------------------------- +19 > return -greetings; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (390 to 416) SpanInfo: {"start":398,"length":17} + >return -greetings + >:=> (line 19, col 8) to (line 19, col 25) +-------------------------------- +20 > }; + + ~~~~~~~ => Pos: (417 to 423) SpanInfo: {"start":421,"length":1} + >} + >:=> (line 20, col 4) to (line 20, col 5) +-------------------------------- +21 >} + ~ => Pos: (424 to 424) SpanInfo: {"start":424,"length":1} + >} + >:=> (line 21, col 0) to (line 21, col 1) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_ifElse.baseline b/tests/baselines/reference/bpSpan_ifElse.baseline index c325ade25f0..b66316d3392 100644 --- a/tests/baselines/reference/bpSpan_ifElse.baseline +++ b/tests/baselines/reference/bpSpan_ifElse.baseline @@ -105,6 +105,62 @@ >:=> (line 16, col 4) to (line 16, col 7) -------------------------------- 17 >} - ~ => Pos: (155 to 155) SpanInfo: {"start":150,"length":3} + + ~~ => Pos: (155 to 156) SpanInfo: {"start":150,"length":3} >i-- - >:=> (line 16, col 4) to (line 16, col 7) \ No newline at end of file + >:=> (line 16, col 4) to (line 16, col 7) +-------------------------------- +18 >if (function foo() { + + ~~~~ => Pos: (157 to 160) SpanInfo: {"start":157,"length":41} + >if (function foo() { + > return 30; + >} ()) + >:=> (line 18, col 0) to (line 20, col 5) +18 >if (function foo() { + + ~~~~~~~~~~~~~~~~~ => Pos: (161 to 177) SpanInfo: {"start":182,"length":9} + >return 30 + >:=> (line 19, col 4) to (line 19, col 13) +-------------------------------- +19 > return 30; + + ~~~~~~~~~~~~~~~ => Pos: (178 to 192) SpanInfo: {"start":182,"length":9} + >return 30 + >:=> (line 19, col 4) to (line 19, col 13) +-------------------------------- +20 >} ()) { + + ~ => Pos: (193 to 193) SpanInfo: {"start":193,"length":1} + >} + >:=> (line 20, col 0) to (line 20, col 1) +20 >} ()) { + + ~~~ => Pos: (194 to 196) SpanInfo: {"start":161,"length":36} + >function foo() { + > return 30; + >} () + >:=> (line 18, col 4) to (line 20, col 4) +20 >} ()) { + + ~ => Pos: (197 to 197) SpanInfo: {"start":157,"length":41} + >if (function foo() { + > return 30; + >} ()) + >:=> (line 18, col 0) to (line 20, col 5) +20 >} ()) { + + ~~~ => Pos: (198 to 200) SpanInfo: {"start":205,"length":3} + >i++ + >:=> (line 21, col 4) to (line 21, col 7) +-------------------------------- +21 > i++; + + ~~~~~~~~~ => Pos: (201 to 209) SpanInfo: {"start":205,"length":3} + >i++ + >:=> (line 21, col 4) to (line 21, col 7) +-------------------------------- +22 >} + ~ => Pos: (210 to 210) SpanInfo: {"start":205,"length":3} + >i++ + >:=> (line 21, col 4) to (line 21, col 7) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_import.baseline b/tests/baselines/reference/bpSpan_import.baseline index bc729447306..43e843ebd01 100644 --- a/tests/baselines/reference/bpSpan_import.baseline +++ b/tests/baselines/reference/bpSpan_import.baseline @@ -37,11 +37,20 @@ -------------------------------- 7 >var x = new a(); - ~~~~~~~~~~~~~~~~~ => Pos: (72 to 88) SpanInfo: {"start":72,"length":15} + ~~~~~~~ => Pos: (72 to 78) SpanInfo: {"start":72,"length":15} >var x = new a() >:=> (line 7, col 0) to (line 7, col 15) +7 >var x = new a(); + + ~~~~~~~~~~ => Pos: (79 to 88) SpanInfo: {"start":80,"length":7} + >new a() + >:=> (line 7, col 8) to (line 7, col 15) -------------------------------- 8 >var y = new b(); - ~~~~~~~~~~~~~~~~ => Pos: (89 to 104) SpanInfo: {"start":89,"length":15} + ~~~~~~~ => Pos: (89 to 95) SpanInfo: {"start":89,"length":15} >var y = new b() - >:=> (line 8, col 0) to (line 8, col 15) \ No newline at end of file + >:=> (line 8, col 0) to (line 8, col 15) +8 >var y = new b(); + ~~~~~~~~~ => Pos: (96 to 104) SpanInfo: {"start":97,"length":7} + >new b() + >:=> (line 8, col 8) to (line 8, col 15) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_objectLiteralExpressions.baseline b/tests/baselines/reference/bpSpan_objectLiteralExpressions.baseline new file mode 100644 index 00000000000..0d864a9b1bd --- /dev/null +++ b/tests/baselines/reference/bpSpan_objectLiteralExpressions.baseline @@ -0,0 +1,233 @@ + +1 >var x = { + + ~~~~~~~~~~ => Pos: (0 to 9) SpanInfo: {"start":0,"length":179} + >var x = { + > a: 10, + > b: () => 10, + > someMethod() { + > return "Hello"; + > }, + > get y() { + > return 30; + > }, + > set z(x: number) { + > var bar = x; + > } + >} + >:=> (line 1, col 0) to (line 13, col 1) +-------------------------------- +2 > a: 10, + + ~~~~~~~~~~~ => Pos: (10 to 20) SpanInfo: {"start":0,"length":179} + >var x = { + > a: 10, + > b: () => 10, + > someMethod() { + > return "Hello"; + > }, + > get y() { + > return 30; + > }, + > set z(x: number) { + > var bar = x; + > } + >} + >:=> (line 1, col 0) to (line 13, col 1) +-------------------------------- +3 > b: () => 10, + + ~~~~~~~~~~~~~~~~~ => Pos: (21 to 37) SpanInfo: {"start":34,"length":2} + >10 + >:=> (line 3, col 13) to (line 3, col 15) +-------------------------------- +4 > someMethod() { + + ~~~~~~~~~~~~~~~~~~~ => Pos: (38 to 56) SpanInfo: {"start":65,"length":14} + >return "Hello" + >:=> (line 5, col 8) to (line 5, col 22) +-------------------------------- +5 > return "Hello"; + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (57 to 80) SpanInfo: {"start":65,"length":14} + >return "Hello" + >:=> (line 5, col 8) to (line 5, col 22) +-------------------------------- +6 > }, + + ~~~~~~~ => Pos: (81 to 87) SpanInfo: {"start":85,"length":1} + >} + >:=> (line 6, col 4) to (line 6, col 5) +-------------------------------- +7 > get y() { + + ~~~~~~~~~~~~~~ => Pos: (88 to 101) SpanInfo: {"start":110,"length":9} + >return 30 + >:=> (line 8, col 8) to (line 8, col 17) +-------------------------------- +8 > return 30; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (102 to 120) SpanInfo: {"start":110,"length":9} + >return 30 + >:=> (line 8, col 8) to (line 8, col 17) +-------------------------------- +9 > }, + + ~~~~~~~ => Pos: (121 to 127) SpanInfo: {"start":125,"length":1} + >} + >:=> (line 9, col 4) to (line 9, col 5) +-------------------------------- +10 > set z(x: number) { + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (128 to 150) SpanInfo: {"start":159,"length":11} + >var bar = x + >:=> (line 11, col 8) to (line 11, col 19) +-------------------------------- +11 > var bar = x; + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (151 to 171) SpanInfo: {"start":159,"length":11} + >var bar = x + >:=> (line 11, col 8) to (line 11, col 19) +-------------------------------- +12 > } + + ~~~~~~ => Pos: (172 to 177) SpanInfo: {"start":176,"length":1} + >} + >:=> (line 12, col 4) to (line 12, col 5) +-------------------------------- +13 >}; + + ~~~ => Pos: (178 to 180) SpanInfo: {"start":0,"length":179} + >var x = { + > a: 10, + > b: () => 10, + > someMethod() { + > return "Hello"; + > }, + > get y() { + > return 30; + > }, + > set z(x: number) { + > var bar = x; + > } + >} + >:=> (line 1, col 0) to (line 13, col 1) +-------------------------------- +14 >var a = ({ + + ~~~~~~~~~~~ => Pos: (181 to 191) SpanInfo: {"start":181,"length":192} + >var a = ({ + > a: 10, + > b: () => 10, + > someMethod() { + > return "Hello"; + > }, + > get y() { + > return 30; + > }, + > set z(x: number) { + > var bar = x; + > } + >}).someMethod + >:=> (line 14, col 0) to (line 26, col 13) +-------------------------------- +15 > a: 10, + + ~~~~~~~~~~~ => Pos: (192 to 202) SpanInfo: {"start":181,"length":192} + >var a = ({ + > a: 10, + > b: () => 10, + > someMethod() { + > return "Hello"; + > }, + > get y() { + > return 30; + > }, + > set z(x: number) { + > var bar = x; + > } + >}).someMethod + >:=> (line 14, col 0) to (line 26, col 13) +-------------------------------- +16 > b: () => 10, + + ~~~~~~~~~~~~~~~~~ => Pos: (203 to 219) SpanInfo: {"start":216,"length":2} + >10 + >:=> (line 16, col 13) to (line 16, col 15) +-------------------------------- +17 > someMethod() { + + ~~~~~~~~~~~~~~~~~~~ => Pos: (220 to 238) SpanInfo: {"start":247,"length":14} + >return "Hello" + >:=> (line 18, col 8) to (line 18, col 22) +-------------------------------- +18 > return "Hello"; + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (239 to 262) SpanInfo: {"start":247,"length":14} + >return "Hello" + >:=> (line 18, col 8) to (line 18, col 22) +-------------------------------- +19 > }, + + ~~~~~~~ => Pos: (263 to 269) SpanInfo: {"start":267,"length":1} + >} + >:=> (line 19, col 4) to (line 19, col 5) +-------------------------------- +20 > get y() { + + ~~~~~~~~~~~~~~ => Pos: (270 to 283) SpanInfo: {"start":292,"length":9} + >return 30 + >:=> (line 21, col 8) to (line 21, col 17) +-------------------------------- +21 > return 30; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (284 to 302) SpanInfo: {"start":292,"length":9} + >return 30 + >:=> (line 21, col 8) to (line 21, col 17) +-------------------------------- +22 > }, + + ~~~~~~~ => Pos: (303 to 309) SpanInfo: {"start":307,"length":1} + >} + >:=> (line 22, col 4) to (line 22, col 5) +-------------------------------- +23 > set z(x: number) { + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (310 to 332) SpanInfo: {"start":341,"length":11} + >var bar = x + >:=> (line 24, col 8) to (line 24, col 19) +-------------------------------- +24 > var bar = x; + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (333 to 353) SpanInfo: {"start":341,"length":11} + >var bar = x + >:=> (line 24, col 8) to (line 24, col 19) +-------------------------------- +25 > } + + ~~~~~~ => Pos: (354 to 359) SpanInfo: {"start":358,"length":1} + >} + >:=> (line 25, col 4) to (line 25, col 5) +-------------------------------- +26 >}).someMethod; + + ~~~~~~~~~~~~~~~ => Pos: (360 to 374) SpanInfo: {"start":181,"length":192} + >var a = ({ + > a: 10, + > b: () => 10, + > someMethod() { + > return "Hello"; + > }, + > get y() { + > return 30; + > }, + > set z(x: number) { + > var bar = x; + > } + >}).someMethod + >:=> (line 14, col 0) to (line 26, col 13) +-------------------------------- +27 >a(); + ~~~~ => Pos: (375 to 378) SpanInfo: {"start":375,"length":3} + >a() + >:=> (line 27, col 0) to (line 27, col 3) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_parenCallOrNewExpressions.baseline b/tests/baselines/reference/bpSpan_parenCallOrNewExpressions.baseline new file mode 100644 index 00000000000..80692f05178 --- /dev/null +++ b/tests/baselines/reference/bpSpan_parenCallOrNewExpressions.baseline @@ -0,0 +1,361 @@ + +1 >function foo(a: number) { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (0 to 25) SpanInfo: {"start":30,"length":8} + >return a + >:=> (line 2, col 4) to (line 2, col 12) +-------------------------------- +2 > return a; + + ~~~~~~~~~~~~~~ => Pos: (26 to 39) SpanInfo: {"start":30,"length":8} + >return a + >:=> (line 2, col 4) to (line 2, col 12) +-------------------------------- +3 >} + + ~~ => Pos: (40 to 41) SpanInfo: {"start":40,"length":1} + >} + >:=> (line 3, col 0) to (line 3, col 1) +-------------------------------- +4 >foo((function bar() { + + ~~~~ => Pos: (42 to 45) SpanInfo: {"start":42,"length":47} + >foo((function bar() { + > return foo(40); + >})()) + >:=> (line 4, col 0) to (line 6, col 5) +4 >foo((function bar() { + + ~ => Pos: (46 to 46) SpanInfo: {"start":46,"length":42} + >(function bar() { + > return foo(40); + >})() + >:=> (line 4, col 4) to (line 6, col 4) +4 >foo((function bar() { + + ~~~~~~~~~~~~~~~~~ => Pos: (47 to 63) SpanInfo: {"start":68,"length":14} + >return foo(40) + >:=> (line 5, col 4) to (line 5, col 18) +-------------------------------- +5 > return foo(40); + + ~~~~~~~~~~ => Pos: (64 to 73) SpanInfo: {"start":68,"length":14} + >return foo(40) + >:=> (line 5, col 4) to (line 5, col 18) +5 > return foo(40); + + ~~~~~~~~~~ => Pos: (74 to 83) SpanInfo: {"start":75,"length":7} + >foo(40) + >:=> (line 5, col 11) to (line 5, col 18) +-------------------------------- +6 >})()); + + ~ => Pos: (84 to 84) SpanInfo: {"start":84,"length":1} + >} + >:=> (line 6, col 0) to (line 6, col 1) +6 >})()); + + ~~~ => Pos: (85 to 87) SpanInfo: {"start":46,"length":42} + >(function bar() { + > return foo(40); + >})() + >:=> (line 4, col 4) to (line 6, col 4) +6 >})()); + + ~~~ => Pos: (88 to 90) SpanInfo: {"start":42,"length":47} + >foo((function bar() { + > return foo(40); + >})()) + >:=> (line 4, col 0) to (line 6, col 5) +-------------------------------- +7 >var y = foo((function () { + + ~~~~~~~ => Pos: (91 to 97) SpanInfo: {"start":91,"length":52} + >var y = foo((function () { + > return foo(40); + >})()) + >:=> (line 7, col 0) to (line 9, col 5) +7 >var y = foo((function () { + + ~~~~~ => Pos: (98 to 102) SpanInfo: {"start":99,"length":44} + >foo((function () { + > return foo(40); + >})()) + >:=> (line 7, col 8) to (line 9, col 5) +7 >var y = foo((function () { + + ~ => Pos: (103 to 103) SpanInfo: {"start":103,"length":39} + >(function () { + > return foo(40); + >})() + >:=> (line 7, col 12) to (line 9, col 4) +7 >var y = foo((function () { + + ~~~~~~~~~~~~~~ => Pos: (104 to 117) SpanInfo: {"start":122,"length":14} + >return foo(40) + >:=> (line 8, col 4) to (line 8, col 18) +-------------------------------- +8 > return foo(40); + + ~~~~~~~~~~ => Pos: (118 to 127) SpanInfo: {"start":122,"length":14} + >return foo(40) + >:=> (line 8, col 4) to (line 8, col 18) +8 > return foo(40); + + ~~~~~~~~~~ => Pos: (128 to 137) SpanInfo: {"start":129,"length":7} + >foo(40) + >:=> (line 8, col 11) to (line 8, col 18) +-------------------------------- +9 >})());; + + ~ => Pos: (138 to 138) SpanInfo: {"start":138,"length":1} + >} + >:=> (line 9, col 0) to (line 9, col 1) +9 >})());; + + ~~~ => Pos: (139 to 141) SpanInfo: {"start":103,"length":39} + >(function () { + > return foo(40); + >})() + >:=> (line 7, col 12) to (line 9, col 4) +9 >})());; + + ~~~~ => Pos: (142 to 145) SpanInfo: {"start":99,"length":44} + >foo((function () { + > return foo(40); + >})()) + >:=> (line 7, col 8) to (line 9, col 5) +-------------------------------- +10 >class greeter { + + ~~~~~~~~~~~~~~~~ => Pos: (146 to 161) SpanInfo: {"start":195,"length":1} + >} + >:=> (line 12, col 4) to (line 12, col 5) +-------------------------------- +11 > constructor(a: number) { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (162 to 190) SpanInfo: {"start":195,"length":1} + >} + >:=> (line 12, col 4) to (line 12, col 5) +-------------------------------- +12 > } + + ~~~~~~ => Pos: (191 to 196) SpanInfo: {"start":195,"length":1} + >} + >:=> (line 12, col 4) to (line 12, col 5) +-------------------------------- +13 >} + + ~~ => Pos: (197 to 198) SpanInfo: {"start":197,"length":1} + >} + >:=> (line 13, col 0) to (line 13, col 1) +-------------------------------- +14 >foo(30); + + ~~~~~~~~~ => Pos: (199 to 207) SpanInfo: {"start":199,"length":7} + >foo(30) + >:=> (line 14, col 0) to (line 14, col 7) +-------------------------------- +15 >foo(40 + y); + + ~~~~~~~~~~~~~ => Pos: (208 to 220) SpanInfo: {"start":208,"length":11} + >foo(40 + y) + >:=> (line 15, col 0) to (line 15, col 11) +-------------------------------- +16 >y = foo(30); + + ~~~ => Pos: (221 to 223) SpanInfo: {"start":221,"length":11} + >y = foo(30) + >:=> (line 16, col 0) to (line 16, col 11) +16 >y = foo(30); + + ~~~~~~~~~~ => Pos: (224 to 233) SpanInfo: {"start":225,"length":7} + >foo(30) + >:=> (line 16, col 4) to (line 16, col 11) +-------------------------------- +17 >y = foo(500 + y); + + ~~~ => Pos: (234 to 236) SpanInfo: {"start":234,"length":16} + >y = foo(500 + y) + >:=> (line 17, col 0) to (line 17, col 16) +17 >y = foo(500 + y); + + ~~~~~~~~~~~~~~~ => Pos: (237 to 251) SpanInfo: {"start":238,"length":12} + >foo(500 + y) + >:=> (line 17, col 4) to (line 17, col 16) +-------------------------------- +18 >new greeter((function bar() { + + ~~~~~~~~~~~~ => Pos: (252 to 263) SpanInfo: {"start":252,"length":55} + >new greeter((function bar() { + > return foo(40); + >})()) + >:=> (line 18, col 0) to (line 20, col 5) +18 >new greeter((function bar() { + + ~ => Pos: (264 to 264) SpanInfo: {"start":264,"length":42} + >(function bar() { + > return foo(40); + >})() + >:=> (line 18, col 12) to (line 20, col 4) +18 >new greeter((function bar() { + + ~~~~~~~~~~~~~~~~~ => Pos: (265 to 281) SpanInfo: {"start":286,"length":14} + >return foo(40) + >:=> (line 19, col 4) to (line 19, col 18) +-------------------------------- +19 > return foo(40); + + ~~~~~~~~~~ => Pos: (282 to 291) SpanInfo: {"start":286,"length":14} + >return foo(40) + >:=> (line 19, col 4) to (line 19, col 18) +19 > return foo(40); + + ~~~~~~~~~~ => Pos: (292 to 301) SpanInfo: {"start":293,"length":7} + >foo(40) + >:=> (line 19, col 11) to (line 19, col 18) +-------------------------------- +20 >})()); + + ~ => Pos: (302 to 302) SpanInfo: {"start":302,"length":1} + >} + >:=> (line 20, col 0) to (line 20, col 1) +20 >})()); + + ~~~ => Pos: (303 to 305) SpanInfo: {"start":264,"length":42} + >(function bar() { + > return foo(40); + >})() + >:=> (line 18, col 12) to (line 20, col 4) +20 >})()); + + ~~~ => Pos: (306 to 308) SpanInfo: {"start":252,"length":55} + >new greeter((function bar() { + > return foo(40); + >})()) + >:=> (line 18, col 0) to (line 20, col 5) +-------------------------------- +21 >var anotherGreeter = new greeter((function bar() { + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (309 to 328) SpanInfo: {"start":309,"length":76} + >var anotherGreeter = new greeter((function bar() { + > return foo(40); + >})()) + >:=> (line 21, col 0) to (line 23, col 5) +21 >var anotherGreeter = new greeter((function bar() { + + ~~~~~~~~~~~~~ => Pos: (329 to 341) SpanInfo: {"start":330,"length":55} + >new greeter((function bar() { + > return foo(40); + >})()) + >:=> (line 21, col 21) to (line 23, col 5) +21 >var anotherGreeter = new greeter((function bar() { + + ~ => Pos: (342 to 342) SpanInfo: {"start":342,"length":42} + >(function bar() { + > return foo(40); + >})() + >:=> (line 21, col 33) to (line 23, col 4) +21 >var anotherGreeter = new greeter((function bar() { + + ~~~~~~~~~~~~~~~~~=> Pos: (343 to 359) SpanInfo: {"start":364,"length":14} + >return foo(40) + >:=> (line 22, col 4) to (line 22, col 18) +-------------------------------- +22 > return foo(40); + + ~~~~~~~~~~ => Pos: (360 to 369) SpanInfo: {"start":364,"length":14} + >return foo(40) + >:=> (line 22, col 4) to (line 22, col 18) +22 > return foo(40); + + ~~~~~~~~~~ => Pos: (370 to 379) SpanInfo: {"start":371,"length":7} + >foo(40) + >:=> (line 22, col 11) to (line 22, col 18) +-------------------------------- +23 >})()); + + ~ => Pos: (380 to 380) SpanInfo: {"start":380,"length":1} + >} + >:=> (line 23, col 0) to (line 23, col 1) +23 >})()); + + ~~~ => Pos: (381 to 383) SpanInfo: {"start":342,"length":42} + >(function bar() { + > return foo(40); + >})() + >:=> (line 21, col 33) to (line 23, col 4) +23 >})()); + + ~~~ => Pos: (384 to 386) SpanInfo: {"start":330,"length":55} + >new greeter((function bar() { + > return foo(40); + >})()) + >:=> (line 21, col 21) to (line 23, col 5) +-------------------------------- +24 >anotherGreeter = new greeter(30); + + ~~~~~~~~~~~~~~~~ => Pos: (387 to 402) SpanInfo: {"start":387,"length":32} + >anotherGreeter = new greeter(30) + >:=> (line 24, col 0) to (line 24, col 32) +24 >anotherGreeter = new greeter(30); + + ~~~~~~~~~~~~~~~~~~ => Pos: (403 to 420) SpanInfo: {"start":404,"length":15} + >new greeter(30) + >:=> (line 24, col 17) to (line 24, col 32) +-------------------------------- +25 >anotherGreeter = new greeter(40 + y); + + ~~~~~~~~~~~~~~~~ => Pos: (421 to 436) SpanInfo: {"start":421,"length":36} + >anotherGreeter = new greeter(40 + y) + >:=> (line 25, col 0) to (line 25, col 36) +25 >anotherGreeter = new greeter(40 + y); + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (437 to 458) SpanInfo: {"start":438,"length":19} + >new greeter(40 + y) + >:=> (line 25, col 17) to (line 25, col 36) +-------------------------------- +26 >new greeter(30); + + ~~~~~~~~~~~~~~~~~ => Pos: (459 to 475) SpanInfo: {"start":459,"length":15} + >new greeter(30) + >:=> (line 26, col 0) to (line 26, col 15) +-------------------------------- +27 >new greeter(40 + y); + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (476 to 496) SpanInfo: {"start":476,"length":19} + >new greeter(40 + y) + >:=> (line 27, col 0) to (line 27, col 19) +-------------------------------- +28 >function foo2(x: number, y: string) { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (497 to 534) SpanInfo: {"start":535,"length":1} + >} + >:=> (line 29, col 0) to (line 29, col 1) +-------------------------------- +29 >} + + ~~ => Pos: (535 to 536) SpanInfo: {"start":535,"length":1} + >} + >:=> (line 29, col 0) to (line 29, col 1) +-------------------------------- +30 >foo2(foo(30), foo(40).toString()); + ~~~~~ => Pos: (537 to 541) SpanInfo: {"start":537,"length":33} + >foo2(foo(30), foo(40).toString()) + >:=> (line 30, col 0) to (line 30, col 33) +30 >foo2(foo(30), foo(40).toString()); + ~~~~~~~~ => Pos: (542 to 549) SpanInfo: {"start":542,"length":7} + >foo(30) + >:=> (line 30, col 5) to (line 30, col 12) +30 >foo2(foo(30), foo(40).toString()); + ~~~~~~~~ => Pos: (550 to 557) SpanInfo: {"start":551,"length":7} + >foo(40) + >:=> (line 30, col 14) to (line 30, col 21) +30 >foo2(foo(30), foo(40).toString()); + ~~~~~~~~~~~ => Pos: (558 to 568) SpanInfo: {"start":551,"length":18} + >foo(40).toString() + >:=> (line 30, col 14) to (line 30, col 32) +30 >foo2(foo(30), foo(40).toString()); + ~~ => Pos: (569 to 570) SpanInfo: {"start":537,"length":33} + >foo2(foo(30), foo(40).toString()) + >:=> (line 30, col 0) to (line 30, col 33) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_stmts.baseline b/tests/baselines/reference/bpSpan_stmts.baseline new file mode 100644 index 00000000000..a81559ee9a5 --- /dev/null +++ b/tests/baselines/reference/bpSpan_stmts.baseline @@ -0,0 +1,572 @@ + +1 >function f() { + + ~~~~~~~~~~~~~~~ => Pos: (0 to 14) SpanInfo: undefined +-------------------------------- +2 > var y; + + ~~~~~~~~~~~ => Pos: (15 to 25) SpanInfo: undefined +-------------------------------- +3 > var x = 0; + + ~~~~~~~~~~~~~~~ => Pos: (26 to 40) SpanInfo: {"start":30,"length":9} + >var x = 0 + >:=> (line 3, col 4) to (line 3, col 13) +-------------------------------- +4 > for (var i = 0; i < 10; i++) { + + ~~~~~~~~~~~~~~~~~~~ => Pos: (41 to 59) SpanInfo: {"start":50,"length":9} + >var i = 0 + >:=> (line 4, col 9) to (line 4, col 18) +4 > for (var i = 0; i < 10; i++) { + + ~~~~~~~~ => Pos: (60 to 67) SpanInfo: {"start":61,"length":6} + >i < 10 + >:=> (line 4, col 20) to (line 4, col 26) +4 > for (var i = 0; i < 10; i++) { + + ~~~~~~~~ => Pos: (68 to 75) SpanInfo: {"start":69,"length":3} + >i++ + >:=> (line 4, col 28) to (line 4, col 31) +-------------------------------- +5 > x += i; + + ~~~~~~~~~~~~~~~~ => Pos: (76 to 91) SpanInfo: {"start":84,"length":6} + >x += i + >:=> (line 5, col 8) to (line 5, col 14) +-------------------------------- +6 > x *= 0; + + ~~~~~~~~~~~~~~~~ => Pos: (92 to 107) SpanInfo: {"start":100,"length":6} + >x *= 0 + >:=> (line 6, col 8) to (line 6, col 14) +-------------------------------- +7 > } + + ~~~~~~ => Pos: (108 to 113) SpanInfo: {"start":100,"length":6} + >x *= 0 + >:=> (line 6, col 8) to (line 6, col 14) +-------------------------------- +8 > if (x > 17) { + + ~~~~~~~~~~~~~~~~~~ => Pos: (114 to 131) SpanInfo: {"start":118,"length":11} + >if (x > 17) + >:=> (line 8, col 4) to (line 8, col 15) +-------------------------------- +9 > x /= 9; + + ~~~~~~~~~~~~~~~~ => Pos: (132 to 147) SpanInfo: {"start":140,"length":6} + >x /= 9 + >:=> (line 9, col 8) to (line 9, col 14) +-------------------------------- +10 > } else { + + ~~~~~ => Pos: (148 to 152) SpanInfo: {"start":140,"length":6} + >x /= 9 + >:=> (line 9, col 8) to (line 9, col 14) +10 > } else { + + ~~~~~~~~ => Pos: (153 to 160) SpanInfo: {"start":169,"length":7} + >x += 10 + >:=> (line 11, col 8) to (line 11, col 15) +-------------------------------- +11 > x += 10; + + ~~~~~~~~~~~~~~~~~ => Pos: (161 to 177) SpanInfo: {"start":169,"length":7} + >x += 10 + >:=> (line 11, col 8) to (line 11, col 15) +-------------------------------- +12 > x++; + + ~~~~~~~~~~~~~ => Pos: (178 to 190) SpanInfo: {"start":186,"length":3} + >x++ + >:=> (line 12, col 8) to (line 12, col 11) +-------------------------------- +13 > } + + ~~~~~~ => Pos: (191 to 196) SpanInfo: {"start":186,"length":3} + >x++ + >:=> (line 12, col 8) to (line 12, col 11) +-------------------------------- +14 > var a = [ + + ~~~~~~~~~~~~~~ => Pos: (197 to 210) SpanInfo: {"start":201,"length":47} + >var a = [ + > 1, + > 2, + > 3 + > ] + >:=> (line 14, col 4) to (line 18, col 5) +-------------------------------- +15 > 1, + + ~~~~~~~~~~~ => Pos: (211 to 221) SpanInfo: {"start":201,"length":47} + >var a = [ + > 1, + > 2, + > 3 + > ] + >:=> (line 14, col 4) to (line 18, col 5) +-------------------------------- +16 > 2, + + ~~~~~~~~~~~ => Pos: (222 to 232) SpanInfo: {"start":201,"length":47} + >var a = [ + > 1, + > 2, + > 3 + > ] + >:=> (line 14, col 4) to (line 18, col 5) +-------------------------------- +17 > 3 + + ~~~~~~~~~~ => Pos: (233 to 242) SpanInfo: {"start":201,"length":47} + >var a = [ + > 1, + > 2, + > 3 + > ] + >:=> (line 14, col 4) to (line 18, col 5) +-------------------------------- +18 > ]; + + ~~~~~~~ => Pos: (243 to 249) SpanInfo: {"start":201,"length":47} + >var a = [ + > 1, + > 2, + > 3 + > ] + >:=> (line 14, col 4) to (line 18, col 5) +-------------------------------- +19 > var obj = { + + ~~~~~~~~~~~~~~~~ => Pos: (250 to 265) SpanInfo: {"start":254,"length":50} + >var obj = { + > z: 1, + > q: "hello" + > } + >:=> (line 19, col 4) to (line 22, col 5) +-------------------------------- +20 > z: 1, + + ~~~~~~~~~~~~~~ => Pos: (266 to 279) SpanInfo: {"start":254,"length":50} + >var obj = { + > z: 1, + > q: "hello" + > } + >:=> (line 19, col 4) to (line 22, col 5) +-------------------------------- +21 > q: "hello" + + ~~~~~~~~~~~~~~~~~~~ => Pos: (280 to 298) SpanInfo: {"start":254,"length":50} + >var obj = { + > z: 1, + > q: "hello" + > } + >:=> (line 19, col 4) to (line 22, col 5) +-------------------------------- +22 > }; + + ~~~~~~~ => Pos: (299 to 305) SpanInfo: {"start":254,"length":50} + >var obj = { + > z: 1, + > q: "hello" + > } + >:=> (line 19, col 4) to (line 22, col 5) +-------------------------------- +23 > for (var j in a) { + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (306 to 328) SpanInfo: {"start":310,"length":16} + >for (var j in a) + >:=> (line 23, col 4) to (line 23, col 20) +-------------------------------- +24 > obj.z = a[j]; + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (329 to 350) SpanInfo: {"start":337,"length":12} + >obj.z = a[j] + >:=> (line 24, col 8) to (line 24, col 20) +-------------------------------- +25 > var v = 10; + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (351 to 370) SpanInfo: {"start":359,"length":10} + >var v = 10 + >:=> (line 25, col 8) to (line 25, col 18) +-------------------------------- +26 > } + + ~~~~~~ => Pos: (371 to 376) SpanInfo: {"start":359,"length":10} + >var v = 10 + >:=> (line 25, col 8) to (line 25, col 18) +-------------------------------- +27 > try { + + ~~~~~~~~~~ => Pos: (377 to 386) SpanInfo: {"start":395,"length":14} + >obj.q = "ohhh" + >:=> (line 28, col 8) to (line 28, col 22) +-------------------------------- +28 > obj.q = "ohhh"; + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (387 to 410) SpanInfo: {"start":395,"length":14} + >obj.q = "ohhh" + >:=> (line 28, col 8) to (line 28, col 22) +-------------------------------- +29 > } catch (e) { + + ~~~~~ => Pos: (411 to 415) SpanInfo: {"start":395,"length":14} + >obj.q = "ohhh" + >:=> (line 28, col 8) to (line 28, col 22) +29 > } catch (e) { + + ~~~~~~~~~~~~~ => Pos: (416 to 428) SpanInfo: {"start":437,"length":15} + >if (obj.z < 10) + >:=> (line 30, col 8) to (line 30, col 23) +-------------------------------- +30 > if (obj.z < 10) { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (429 to 454) SpanInfo: {"start":437,"length":15} + >if (obj.z < 10) + >:=> (line 30, col 8) to (line 30, col 23) +-------------------------------- +31 > obj.z = 12; + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (455 to 478) SpanInfo: {"start":467,"length":10} + >obj.z = 12 + >:=> (line 31, col 12) to (line 31, col 22) +-------------------------------- +32 > } else { + + ~~~~~~~~~ => Pos: (479 to 487) SpanInfo: {"start":467,"length":10} + >obj.z = 12 + >:=> (line 31, col 12) to (line 31, col 22) +32 > } else { + + ~~~~~~~~ => Pos: (488 to 495) SpanInfo: {"start":508,"length":13} + >obj.q = "hmm" + >:=> (line 33, col 12) to (line 33, col 25) +-------------------------------- +33 > obj.q = "hmm"; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (496 to 522) SpanInfo: {"start":508,"length":13} + >obj.q = "hmm" + >:=> (line 33, col 12) to (line 33, col 25) +-------------------------------- +34 > } + + ~~~~~~~~~~ => Pos: (523 to 532) SpanInfo: {"start":508,"length":13} + >obj.q = "hmm" + >:=> (line 33, col 12) to (line 33, col 25) +-------------------------------- +35 > } + + ~~~~~~ => Pos: (533 to 538) SpanInfo: {"start":437,"length":15} + >if (obj.z < 10) + >:=> (line 30, col 8) to (line 30, col 23) +-------------------------------- +36 > try { + + ~~~~~~~~~~ => Pos: (539 to 548) SpanInfo: {"start":557,"length":17} + >throw new Error() + >:=> (line 37, col 8) to (line 37, col 25) +-------------------------------- +37 > throw new Error(); + + ~~~~~~~~~~~~~ => Pos: (549 to 561) SpanInfo: {"start":557,"length":17} + >throw new Error() + >:=> (line 37, col 8) to (line 37, col 25) +37 > throw new Error(); + + ~~~~~~~~~~~~~~ => Pos: (562 to 575) SpanInfo: {"start":563,"length":11} + >new Error() + >:=> (line 37, col 14) to (line 37, col 25) +-------------------------------- +38 > } catch (e1) { + + ~~~~~ => Pos: (576 to 580) SpanInfo: {"start":557,"length":17} + >throw new Error() + >:=> (line 37, col 8) to (line 37, col 25) +38 > } catch (e1) { + + ~~~~~~~~~~~~~~ => Pos: (581 to 594) SpanInfo: {"start":603,"length":10} + >var b = e1 + >:=> (line 39, col 8) to (line 39, col 18) +-------------------------------- +39 > var b = e1; + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (595 to 614) SpanInfo: {"start":603,"length":10} + >var b = e1 + >:=> (line 39, col 8) to (line 39, col 18) +-------------------------------- +40 > } finally { + + ~~~~~ => Pos: (615 to 619) SpanInfo: {"start":603,"length":10} + >var b = e1 + >:=> (line 39, col 8) to (line 39, col 18) +40 > } finally { + + ~~~~~~~~~~~ => Pos: (620 to 630) SpanInfo: {"start":639,"length":6} + >y = 70 + >:=> (line 41, col 8) to (line 41, col 14) +-------------------------------- +41 > y = 70; + + ~~~~~~~~~~~~~~~~ => Pos: (631 to 646) SpanInfo: {"start":639,"length":6} + >y = 70 + >:=> (line 41, col 8) to (line 41, col 14) +-------------------------------- +42 > } + + ~~~~~~ => Pos: (647 to 652) SpanInfo: {"start":639,"length":6} + >y = 70 + >:=> (line 41, col 8) to (line 41, col 14) +-------------------------------- +43 > with (obj) { + + ~~~~~~~~~~~~~~~~~ => Pos: (653 to 669) SpanInfo: {"start":678,"length":5} + >i = 2 + >:=> (line 44, col 8) to (line 44, col 13) +-------------------------------- +44 > i = 2; + + ~~~~~~~~~~~~~~~ => Pos: (670 to 684) SpanInfo: {"start":678,"length":5} + >i = 2 + >:=> (line 44, col 8) to (line 44, col 13) +-------------------------------- +45 > z = 10; + + ~~~~~~~~~~~~~~~~ => Pos: (685 to 700) SpanInfo: {"start":693,"length":6} + >z = 10 + >:=> (line 45, col 8) to (line 45, col 14) +-------------------------------- +46 > } + + ~~~~~~ => Pos: (701 to 706) SpanInfo: {"start":693,"length":6} + >z = 10 + >:=> (line 45, col 8) to (line 45, col 14) +-------------------------------- +47 > switch (obj.z) { + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (707 to 727) SpanInfo: {"start":711,"length":14} + >switch (obj.z) + >:=> (line 47, col 4) to (line 47, col 18) +-------------------------------- +48 > case 0: { + + ~~~~~~~~~~~~~~~~~~ => Pos: (728 to 745) SpanInfo: {"start":758,"length":3} + >x++ + >:=> (line 49, col 12) to (line 49, col 15) +-------------------------------- +49 > x++; + + ~~~~~~~~~~~~~~~~~ => Pos: (746 to 762) SpanInfo: {"start":758,"length":3} + >x++ + >:=> (line 49, col 12) to (line 49, col 15) +-------------------------------- +50 > break; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (763 to 781) SpanInfo: {"start":775,"length":5} + >break + >:=> (line 50, col 12) to (line 50, col 17) +-------------------------------- +51 > + + ~ => Pos: (782 to 782) SpanInfo: undefined +-------------------------------- +52 > } + + ~~~~~~~~~~ => Pos: (783 to 792) SpanInfo: {"start":775,"length":5} + >break + >:=> (line 50, col 12) to (line 50, col 17) +-------------------------------- +53 > case 1: { + + ~~~~~~~~~~~~~~~~~~ => Pos: (793 to 810) SpanInfo: {"start":823,"length":3} + >x-- + >:=> (line 54, col 12) to (line 54, col 15) +-------------------------------- +54 > x--; + + ~~~~~~~~~~~~~~~~~ => Pos: (811 to 827) SpanInfo: {"start":823,"length":3} + >x-- + >:=> (line 54, col 12) to (line 54, col 15) +-------------------------------- +55 > break; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (828 to 846) SpanInfo: {"start":840,"length":5} + >break + >:=> (line 55, col 12) to (line 55, col 17) +-------------------------------- +56 > + + ~ => Pos: (847 to 847) SpanInfo: undefined +-------------------------------- +57 > } + + ~~~~~~~~~~ => Pos: (848 to 857) SpanInfo: {"start":840,"length":5} + >break + >:=> (line 55, col 12) to (line 55, col 17) +-------------------------------- +58 > default: { + + ~~~~~~~~~~~~~~~~~~~ => Pos: (858 to 876) SpanInfo: {"start":889,"length":6} + >x *= 2 + >:=> (line 59, col 12) to (line 59, col 18) +-------------------------------- +59 > x *= 2; + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (877 to 896) SpanInfo: {"start":889,"length":6} + >x *= 2 + >:=> (line 59, col 12) to (line 59, col 18) +-------------------------------- +60 > x = 50; + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (897 to 916) SpanInfo: {"start":909,"length":6} + >x = 50 + >:=> (line 60, col 12) to (line 60, col 18) +-------------------------------- +61 > break; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (917 to 935) SpanInfo: {"start":929,"length":5} + >break + >:=> (line 61, col 12) to (line 61, col 17) +-------------------------------- +62 > + + ~ => Pos: (936 to 936) SpanInfo: undefined +-------------------------------- +63 > } + + ~~~~~~~~~~ => Pos: (937 to 946) SpanInfo: {"start":929,"length":5} + >break + >:=> (line 61, col 12) to (line 61, col 17) +-------------------------------- +64 > } + + ~~~~~~ => Pos: (947 to 952) SpanInfo: {"start":889,"length":6} + >x *= 2 + >:=> (line 59, col 12) to (line 59, col 18) +-------------------------------- +65 > while (x < 10) { + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (953 to 973) SpanInfo: {"start":957,"length":14} + >while (x < 10) + >:=> (line 65, col 4) to (line 65, col 18) +-------------------------------- +66 > x++; + + ~~~~~~~~~~~~~ => Pos: (974 to 986) SpanInfo: {"start":982,"length":3} + >x++ + >:=> (line 66, col 8) to (line 66, col 11) +-------------------------------- +67 > } + + ~~~~~~ => Pos: (987 to 992) SpanInfo: {"start":982,"length":3} + >x++ + >:=> (line 66, col 8) to (line 66, col 11) +-------------------------------- +68 > do { + + ~~~~~~~~~ => Pos: (993 to 1001) SpanInfo: {"start":1010,"length":3} + >x-- + >:=> (line 69, col 8) to (line 69, col 11) +-------------------------------- +69 > x--; + + ~~~~~~~~~~~~~ => Pos: (1002 to 1014) SpanInfo: {"start":1010,"length":3} + >x-- + >:=> (line 69, col 8) to (line 69, col 11) +-------------------------------- +70 > } while (x > 4) + + ~~~~~ => Pos: (1015 to 1019) SpanInfo: {"start":1010,"length":3} + >x-- + >:=> (line 69, col 8) to (line 69, col 11) +70 > } while (x > 4) + + ~~~~~~~~~~~~~~~ => Pos: (1020 to 1034) SpanInfo: {"start":1021,"length":13} + >while (x > 4) + >:=> (line 70, col 6) to (line 70, col 19) +-------------------------------- +71 > x = y; + + ~~~~~~~~~~~ => Pos: (1035 to 1045) SpanInfo: {"start":1039,"length":5} + >x = y + >:=> (line 71, col 4) to (line 71, col 9) +-------------------------------- +72 > var z = (x == 1) ? x + 1 : x - 1; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (1046 to 1083) SpanInfo: {"start":1050,"length":32} + >var z = (x == 1) ? x + 1 : x - 1 + >:=> (line 72, col 4) to (line 72, col 36) +-------------------------------- +73 > (x == 1) ? x + 1 : x - 1; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (1084 to 1113) SpanInfo: {"start":1088,"length":24} + >(x == 1) ? x + 1 : x - 1 + >:=> (line 73, col 4) to (line 73, col 28) +-------------------------------- +74 > x === 1; + + ~~~~~~~~~~~~~ => Pos: (1114 to 1126) SpanInfo: {"start":1118,"length":7} + >x === 1 + >:=> (line 74, col 4) to (line 74, col 11) +-------------------------------- +75 > x = z = 40; + + ~~~~~~~~~~~~~~~~ => Pos: (1127 to 1142) SpanInfo: {"start":1131,"length":10} + >x = z = 40 + >:=> (line 75, col 4) to (line 75, col 14) +-------------------------------- +76 > eval("y"); + + ~~~~~~~~~~~~~~~ => Pos: (1143 to 1157) SpanInfo: {"start":1147,"length":9} + >eval("y") + >:=> (line 76, col 4) to (line 76, col 13) +-------------------------------- +77 > return; + + ~~~~~~~~~~~~ => Pos: (1158 to 1169) SpanInfo: {"start":1162,"length":6} + >return + >:=> (line 77, col 4) to (line 77, col 10) +-------------------------------- +78 >} + + ~~ => Pos: (1170 to 1171) SpanInfo: {"start":1170,"length":1} + >} + >:=> (line 78, col 0) to (line 78, col 1) +-------------------------------- +79 >var b = function () { + + ~~~~~~~ => Pos: (1172 to 1178) SpanInfo: {"start":1172,"length":54} + >var b = function () { + > var x = 10; + > x = x + 1; + >} + >:=> (line 79, col 0) to (line 82, col 1) +79 >var b = function () { + + ~~~~~~~~~~~~~~~ => Pos: (1179 to 1193) SpanInfo: {"start":1198,"length":10} + >var x = 10 + >:=> (line 80, col 4) to (line 80, col 14) +-------------------------------- +80 > var x = 10; + + ~~~~~~~~~~~~~~~~ => Pos: (1194 to 1209) SpanInfo: {"start":1198,"length":10} + >var x = 10 + >:=> (line 80, col 4) to (line 80, col 14) +-------------------------------- +81 > x = x + 1; + + ~~~~~~~~~~~~~~~ => Pos: (1210 to 1224) SpanInfo: {"start":1214,"length":9} + >x = x + 1 + >:=> (line 81, col 4) to (line 81, col 13) +-------------------------------- +82 >}; + + ~~~ => Pos: (1225 to 1227) SpanInfo: {"start":1225,"length":1} + >} + >:=> (line 82, col 0) to (line 82, col 1) +-------------------------------- +83 >f(); + ~~~~ => Pos: (1228 to 1231) SpanInfo: {"start":1228,"length":3} + >f() + >:=> (line 83, col 0) to (line 83, col 3) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_switch.baseline b/tests/baselines/reference/bpSpan_switch.baseline index 7629f9a8063..c0e2259784d 100644 --- a/tests/baselines/reference/bpSpan_switch.baseline +++ b/tests/baselines/reference/bpSpan_switch.baseline @@ -162,6 +162,111 @@ >:=> (line 26, col 12) to (line 26, col 22) -------------------------------- 28 >} - ~ => Pos: (347 to 347) SpanInfo: {"start":325,"length":10} + + ~~ => Pos: (347 to 348) SpanInfo: {"start":325,"length":10} >x = x * 10 - >:=> (line 26, col 12) to (line 26, col 22) \ No newline at end of file + >:=> (line 26, col 12) to (line 26, col 22) +-------------------------------- +29 >switch ((function foo() { + + ~~~~~~~~ => Pos: (349 to 356) SpanInfo: {"start":349,"length":50} + >switch ((function foo() { + > return x * 30; + >})()) + >:=> (line 29, col 0) to (line 31, col 5) +29 >switch ((function foo() { + + ~ => Pos: (357 to 357) SpanInfo: {"start":357,"length":41} + >(function foo() { + > return x * 30; + >})() + >:=> (line 29, col 8) to (line 31, col 4) +29 >switch ((function foo() { + + ~~~~~~~~~~~~~~~~~ => Pos: (358 to 374) SpanInfo: {"start":379,"length":13} + >return x * 30 + >:=> (line 30, col 4) to (line 30, col 17) +-------------------------------- +30 > return x * 30; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (375 to 393) SpanInfo: {"start":379,"length":13} + >return x * 30 + >:=> (line 30, col 4) to (line 30, col 17) +-------------------------------- +31 >})()) { + + ~ => Pos: (394 to 394) SpanInfo: {"start":394,"length":1} + >} + >:=> (line 31, col 0) to (line 31, col 1) +31 >})()) { + + ~~~ => Pos: (395 to 397) SpanInfo: {"start":357,"length":41} + >(function foo() { + > return x * 30; + >})() + >:=> (line 29, col 8) to (line 31, col 4) +31 >})()) { + + ~ => Pos: (398 to 398) SpanInfo: {"start":349,"length":50} + >switch ((function foo() { + > return x * 30; + >})()) + >:=> (line 29, col 0) to (line 31, col 5) +31 >})()) { + + ~~~ => Pos: (399 to 401) SpanInfo: {"start":466,"length":3} + >x++ + >:=> (line 35, col 8) to (line 35, col 11) +-------------------------------- +32 > case (function bar() { + + ~~~~~~~~ => Pos: (402 to 409) SpanInfo: {"start":466,"length":3} + >x++ + >:=> (line 35, col 8) to (line 35, col 11) +32 > case (function bar() { + + ~~ => Pos: (410 to 411) SpanInfo: {"start":411,"length":45} + >(function bar() { + > return 30; + > })() + >:=> (line 32, col 9) to (line 34, col 8) +32 > case (function bar() { + + ~~~~~~~~~~~~~~~~~ => Pos: (412 to 428) SpanInfo: {"start":437,"length":9} + >return 30 + >:=> (line 33, col 8) to (line 33, col 17) +-------------------------------- +33 > return 30; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (429 to 447) SpanInfo: {"start":437,"length":9} + >return 30 + >:=> (line 33, col 8) to (line 33, col 17) +-------------------------------- +34 > })(): + + ~~~~~ => Pos: (448 to 452) SpanInfo: {"start":452,"length":1} + >} + >:=> (line 34, col 4) to (line 34, col 5) +34 > })(): + + ~~~ => Pos: (453 to 455) SpanInfo: {"start":411,"length":45} + >(function bar() { + > return 30; + > })() + >:=> (line 32, col 9) to (line 34, col 8) +34 > })(): + + ~~ => Pos: (456 to 457) SpanInfo: {"start":466,"length":3} + >x++ + >:=> (line 35, col 8) to (line 35, col 11) +-------------------------------- +35 > x++; + + ~~~~~~~~~~~~~ => Pos: (458 to 470) SpanInfo: {"start":466,"length":3} + >x++ + >:=> (line 35, col 8) to (line 35, col 11) +-------------------------------- +36 >} + ~ => Pos: (471 to 471) SpanInfo: {"start":466,"length":3} + >x++ + >:=> (line 35, col 8) to (line 35, col 11) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_tryCatchFinally.baseline b/tests/baselines/reference/bpSpan_tryCatchFinally.baseline index 69e2fb0e136..5a9e569f403 100644 --- a/tests/baselines/reference/bpSpan_tryCatchFinally.baseline +++ b/tests/baselines/reference/bpSpan_tryCatchFinally.baseline @@ -77,9 +77,14 @@ -------------------------------- 12 > throw new Error(); - ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (113 to 135) SpanInfo: {"start":117,"length":17} + ~~~~~~~~~ => Pos: (113 to 121) SpanInfo: {"start":117,"length":17} >throw new Error() >:=> (line 12, col 4) to (line 12, col 21) +12 > throw new Error(); + + ~~~~~~~~~~~~~~ => Pos: (122 to 135) SpanInfo: {"start":123,"length":11} + >new Error() + >:=> (line 12, col 10) to (line 12, col 21) -------------------------------- 13 >} @@ -130,6 +135,89 @@ >:=> (line 20, col 4) to (line 20, col 14) -------------------------------- 21 >} - ~ => Pos: (193 to 193) SpanInfo: {"start":181,"length":10} + + ~~ => Pos: (193 to 194) SpanInfo: {"start":181,"length":10} >x = x * 10 - >:=> (line 20, col 4) to (line 20, col 14) \ No newline at end of file + >:=> (line 20, col 4) to (line 20, col 14) +-------------------------------- +22 >try { + + ~~~~~~ => Pos: (195 to 200) SpanInfo: {"start":205,"length":65} + >throw (function foo() { + > new Error(x.toString()); + > })() + >:=> (line 23, col 4) to (line 25, col 8) +-------------------------------- +23 > throw (function foo() { + + ~~~~~~~~~ => Pos: (201 to 209) SpanInfo: {"start":205,"length":65} + >throw (function foo() { + > new Error(x.toString()); + > })() + >:=> (line 23, col 4) to (line 25, col 8) +23 > throw (function foo() { + + ~~ => Pos: (210 to 211) SpanInfo: {"start":211,"length":59} + >(function foo() { + > new Error(x.toString()); + > })() + >:=> (line 23, col 10) to (line 25, col 8) +23 > throw (function foo() { + + ~~~~~~~~~~~~~~~~~ => Pos: (212 to 228) SpanInfo: {"start":237,"length":23} + >new Error(x.toString()) + >:=> (line 24, col 8) to (line 24, col 31) +-------------------------------- +24 > new Error(x.toString()); + + ~~~~~~~~~~~~~~~~~~ => Pos: (229 to 246) SpanInfo: {"start":237,"length":23} + >new Error(x.toString()) + >:=> (line 24, col 8) to (line 24, col 31) +24 > new Error(x.toString()); + + ~~~~~~~~~~~~ => Pos: (247 to 258) SpanInfo: {"start":247,"length":12} + >x.toString() + >:=> (line 24, col 18) to (line 24, col 30) +24 > new Error(x.toString()); + + ~~~ => Pos: (259 to 261) SpanInfo: {"start":237,"length":23} + >new Error(x.toString()) + >:=> (line 24, col 8) to (line 24, col 31) +-------------------------------- +25 > })(); + + ~~~~~ => Pos: (262 to 266) SpanInfo: {"start":266,"length":1} + >} + >:=> (line 25, col 4) to (line 25, col 5) +25 > })(); + + ~~~~~ => Pos: (267 to 271) SpanInfo: {"start":211,"length":59} + >(function foo() { + > new Error(x.toString()); + > })() + >:=> (line 23, col 10) to (line 25, col 8) +-------------------------------- +26 >} + + ~~ => Pos: (272 to 273) SpanInfo: {"start":205,"length":65} + >throw (function foo() { + > new Error(x.toString()); + > })() + >:=> (line 23, col 4) to (line 25, col 8) +-------------------------------- +27 >finally { + + ~~~~~~~~~~ => Pos: (274 to 283) SpanInfo: {"start":288,"length":3} + >x++ + >:=> (line 28, col 4) to (line 28, col 7) +-------------------------------- +28 > x++; + + ~~~~~~~~~ => Pos: (284 to 292) SpanInfo: {"start":288,"length":3} + >x++ + >:=> (line 28, col 4) to (line 28, col 7) +-------------------------------- +29 >} + ~ => Pos: (293 to 293) SpanInfo: {"start":288,"length":3} + >x++ + >:=> (line 28, col 4) to (line 28, col 7) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_typeAssertionExpressions.baseline b/tests/baselines/reference/bpSpan_typeAssertionExpressions.baseline new file mode 100644 index 00000000000..f73b47d8519 --- /dev/null +++ b/tests/baselines/reference/bpSpan_typeAssertionExpressions.baseline @@ -0,0 +1,81 @@ + +1 >class Greeter { + + ~~~~~~~~~~~~~~~~ => Pos: (0 to 15) SpanInfo: {"start":16,"length":1} + >} + >:=> (line 2, col 0) to (line 2, col 1) +-------------------------------- +2 >} + + ~~ => Pos: (16 to 17) SpanInfo: {"start":16,"length":1} + >} + >:=> (line 2, col 0) to (line 2, col 1) +-------------------------------- +3 >var a = new Greeter(); + + ~~~~~~~ => Pos: (18 to 24) SpanInfo: {"start":18,"length":30} + >var a = new Greeter() + >:=> (line 3, col 0) to (line 3, col 30) +3 >var a = new Greeter(); + + ~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (25 to 49) SpanInfo: {"start":35,"length":13} + >new Greeter() + >:=> (line 3, col 17) to (line 3, col 30) +-------------------------------- +4 >a = ( new Greeter()); + + ~~~~~ => Pos: (50 to 54) SpanInfo: {"start":50,"length":29} + >a = ( new Greeter()) + >:=> (line 4, col 0) to (line 4, col 29) +4 >a = ( new Greeter()); + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (55 to 77) SpanInfo: {"start":65,"length":13} + >new Greeter() + >:=> (line 4, col 15) to (line 4, col 28) +4 >a = ( new Greeter()); + + ~~~ => Pos: (78 to 80) SpanInfo: {"start":50,"length":29} + >a = ( new Greeter()) + >:=> (line 4, col 0) to (line 4, col 29) +-------------------------------- +5 >a = (function foo() { + + ~~~ => Pos: (81 to 83) SpanInfo: {"start":81,"length":61} + >a = (function foo() { + > return new Greeter(); + >})() + >:=> (line 5, col 0) to (line 7, col 4) +5 >a = (function foo() { + + ~~~~~~~~~~~ => Pos: (84 to 94) SpanInfo: {"start":94,"length":48} + >(function foo() { + > return new Greeter(); + >})() + >:=> (line 5, col 13) to (line 7, col 4) +5 >a = (function foo() { + + ~~~~~~~~~~~~~~~~~ => Pos: (95 to 111) SpanInfo: {"start":116,"length":20} + >return new Greeter() + >:=> (line 6, col 4) to (line 6, col 24) +-------------------------------- +6 > return new Greeter(); + + ~~~~~~~~~~ => Pos: (112 to 121) SpanInfo: {"start":116,"length":20} + >return new Greeter() + >:=> (line 6, col 4) to (line 6, col 24) +6 > return new Greeter(); + + ~~~~~~~~~~~~~~~~ => Pos: (122 to 137) SpanInfo: {"start":123,"length":13} + >new Greeter() + >:=> (line 6, col 11) to (line 6, col 24) +-------------------------------- +7 >})(); + ~ => Pos: (138 to 138) SpanInfo: {"start":138,"length":1} + >} + >:=> (line 7, col 0) to (line 7, col 1) +7 >})(); + ~~~~ => Pos: (139 to 142) SpanInfo: {"start":94,"length":48} + >(function foo() { + > return new Greeter(); + >})() + >:=> (line 5, col 13) to (line 7, col 4) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_unaryExpressions.baseline b/tests/baselines/reference/bpSpan_unaryExpressions.baseline new file mode 100644 index 00000000000..2ad1191cf95 --- /dev/null +++ b/tests/baselines/reference/bpSpan_unaryExpressions.baseline @@ -0,0 +1,74 @@ + +1 >var x = 10; + + ~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":0,"length":10} + >var x = 10 + >:=> (line 1, col 0) to (line 1, col 10) +-------------------------------- +2 >var y = 20; + + ~~~~~~~~~~~~ => Pos: (12 to 23) SpanInfo: {"start":12,"length":10} + >var y = 20 + >:=> (line 2, col 0) to (line 2, col 10) +-------------------------------- +3 >x++; + + ~~~~~ => Pos: (24 to 28) SpanInfo: {"start":24,"length":3} + >x++ + >:=> (line 3, col 0) to (line 3, col 3) +-------------------------------- +4 >y--; + + ~~~~~ => Pos: (29 to 33) SpanInfo: {"start":29,"length":3} + >y-- + >:=> (line 4, col 0) to (line 4, col 3) +-------------------------------- +5 >typeof (function foo() { + + ~~~~~~ => Pos: (34 to 39) SpanInfo: {"start":34,"length":43} + >typeof (function foo() { + > return y; + >})() + >:=> (line 5, col 0) to (line 7, col 4) +5 >typeof (function foo() { + + ~~ => Pos: (40 to 41) SpanInfo: {"start":41,"length":36} + >(function foo() { + > return y; + >})() + >:=> (line 5, col 7) to (line 7, col 4) +5 >typeof (function foo() { + + ~~~~~~~~~~~~~~~~~ => Pos: (42 to 58) SpanInfo: {"start":63,"length":8} + >return y + >:=> (line 6, col 4) to (line 6, col 12) +-------------------------------- +6 > return y; + + ~~~~~~~~~~~~~~ => Pos: (59 to 72) SpanInfo: {"start":63,"length":8} + >return y + >:=> (line 6, col 4) to (line 6, col 12) +-------------------------------- +7 >})(); + + ~ => Pos: (73 to 73) SpanInfo: {"start":73,"length":1} + >} + >:=> (line 7, col 0) to (line 7, col 1) +7 >})(); + + ~~~~~ => Pos: (74 to 78) SpanInfo: {"start":41,"length":36} + >(function foo() { + > return y; + >})() + >:=> (line 5, col 7) to (line 7, col 4) +-------------------------------- +8 >++x; + + ~~~~~ => Pos: (79 to 83) SpanInfo: {"start":79,"length":3} + >++x + >:=> (line 8, col 0) to (line 8, col 3) +-------------------------------- +9 >++y; + ~~~~ => Pos: (84 to 87) SpanInfo: {"start":84,"length":3} + >++y + >:=> (line 9, col 0) to (line 9, col 3) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_while.baseline b/tests/baselines/reference/bpSpan_while.baseline index c48e049fbd7..91632b78009 100644 --- a/tests/baselines/reference/bpSpan_while.baseline +++ b/tests/baselines/reference/bpSpan_while.baseline @@ -65,6 +65,69 @@ >:=> (line 10, col 0) to (line 10, col 15) -------------------------------- 11 > a++; - ~~~~~~~~ => Pos: (110 to 117) SpanInfo: {"start":114,"length":3} + + ~~~~~~~~~ => Pos: (110 to 118) SpanInfo: {"start":114,"length":3} >a++ - >:=> (line 11, col 4) to (line 11, col 7) \ No newline at end of file + >:=> (line 11, col 4) to (line 11, col 7) +-------------------------------- +12 >while ((function () { + + ~~~~~~~ => Pos: (119 to 125) SpanInfo: {"start":119,"length":52} + >while ((function () { + > return 30 * a; + >})() !== a) + >:=> (line 12, col 0) to (line 14, col 11) +12 >while ((function () { + + ~ => Pos: (126 to 126) SpanInfo: {"start":126,"length":38} + >(function () { + > return 30 * a; + >})() + >:=> (line 12, col 7) to (line 14, col 4) +12 >while ((function () { + + ~~~~~~~~~~~~~~ => Pos: (127 to 140) SpanInfo: {"start":145,"length":13} + >return 30 * a + >:=> (line 13, col 4) to (line 13, col 17) +-------------------------------- +13 > return 30 * a; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (141 to 159) SpanInfo: {"start":145,"length":13} + >return 30 * a + >:=> (line 13, col 4) to (line 13, col 17) +-------------------------------- +14 >})() !== a) { + + ~ => Pos: (160 to 160) SpanInfo: {"start":160,"length":1} + >} + >:=> (line 14, col 0) to (line 14, col 1) +14 >})() !== a) { + + ~~~ => Pos: (161 to 163) SpanInfo: {"start":126,"length":38} + >(function () { + > return 30 * a; + >})() + >:=> (line 12, col 7) to (line 14, col 4) +14 >})() !== a) { + + ~~~~~~~ => Pos: (164 to 170) SpanInfo: {"start":119,"length":52} + >while ((function () { + > return 30 * a; + >})() !== a) + >:=> (line 12, col 0) to (line 14, col 11) +14 >})() !== a) { + + ~~~ => Pos: (171 to 173) SpanInfo: {"start":178,"length":3} + >a-- + >:=> (line 15, col 4) to (line 15, col 7) +-------------------------------- +15 > a--; + + ~~~~~~~~~ => Pos: (174 to 182) SpanInfo: {"start":178,"length":3} + >a-- + >:=> (line 15, col 4) to (line 15, col 7) +-------------------------------- +16 >} + ~ => Pos: (183 to 183) SpanInfo: {"start":178,"length":3} + >a-- + >:=> (line 15, col 4) to (line 15, col 7) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_with.baseline b/tests/baselines/reference/bpSpan_with.baseline new file mode 100644 index 00000000000..d4a00e7a3aa --- /dev/null +++ b/tests/baselines/reference/bpSpan_with.baseline @@ -0,0 +1,21 @@ + +1 >var obj: string; + + ~~~~~~~~~~~~~~~~~ => Pos: (0 to 16) SpanInfo: undefined +-------------------------------- +2 >with (obj) { + + ~~~~~~~~~~~~~ => Pos: (17 to 29) SpanInfo: {"start":34,"length":6} + >x = 10 + >:=> (line 3, col 4) to (line 3, col 10) +-------------------------------- +3 > x = 10; + + ~~~~~~~~~~~~ => Pos: (30 to 41) SpanInfo: {"start":34,"length":6} + >x = 10 + >:=> (line 3, col 4) to (line 3, col 10) +-------------------------------- +4 >} + ~ => Pos: (42 to 42) SpanInfo: {"start":34,"length":6} + >x = 10 + >:=> (line 3, col 4) to (line 3, col 10) \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationArrayLiteralExpressions.ts b/tests/cases/fourslash/breakpointValidationArrayLiteralExpressions.ts new file mode 100644 index 00000000000..efa3e6fbef2 --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationArrayLiteralExpressions.ts @@ -0,0 +1,23 @@ +/// + +// @BaselineFile: bpSpan_arrayLiteralExpressions.baseline +// @Filename: bpSpan_arrayLiteralExpressions.ts +////var a = [10, 20, 30]; +////function foo(a: number) { +//// return a; +////} +////a = [foo(30), (function () { +//// return 30; +////})()]; +////function bar() { +//// return a; +////} +////var x = bar()[0]; +////x = (function () { +//// return a; +////})()[x]; +////a[(function () { +//// return x; +////})()]; + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationBinaryExpressions.ts b/tests/cases/fourslash/breakpointValidationBinaryExpressions.ts new file mode 100644 index 00000000000..55cc6ea3ee7 --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationBinaryExpressions.ts @@ -0,0 +1,17 @@ +/// + +// @BaselineFile: bpSpan_binaryExpressions.baseline +// @Filename: bpSpan_binaryExpressions.ts +////var x = 10; +////var y = 20; +////x += 30; +////x *= 0; +////x = x + 1; +////x = (function foo() { +//// return y; +////})() + y; +////x = y + 30 + (function foo() { +//// return y; +////})() * 40; + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationClasses.ts b/tests/cases/fourslash/breakpointValidationClasses.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationClasses.ts rename to tests/cases/fourslash/breakpointValidationClasses.ts diff --git a/tests/cases/fourslash/breakpointValidationConditionalExpressions.ts b/tests/cases/fourslash/breakpointValidationConditionalExpressions.ts new file mode 100644 index 00000000000..81a19f3fab1 --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationConditionalExpressions.ts @@ -0,0 +1,16 @@ +/// + +// @BaselineFile: bpSpan_conditionalExpressions.baseline +// @Filename: bpSpan_conditionalExpressions.ts +////var x = 10; +////var y = x ? x + 10 : 30; +////var z = (function foo() { +//// return x; +////})() ? y : function bar() { +//// return x; +////} (); +////x = y ? (function () { +//// return z; +////})() : 10; + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationDo.ts b/tests/cases/fourslash/breakpointValidationDo.ts index e0d02ad75f6..ce7863a78e2 100644 --- a/tests/cases/fourslash/breakpointValidationDo.ts +++ b/tests/cases/fourslash/breakpointValidationDo.ts @@ -14,4 +14,9 @@ //// i++; ////} ////while (i < 30); +////do { +//// i--; +////} while ((function () { +//// return 30 * i; +//// })() !== i); verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationForIn.ts b/tests/cases/fourslash/breakpointValidationForIn.ts index da15dd61f10..924433520c7 100644 --- a/tests/cases/fourslash/breakpointValidationForIn.ts +++ b/tests/cases/fourslash/breakpointValidationForIn.ts @@ -16,5 +16,11 @@ ////{ //// WScript.Echo(x); ////} +////var z = 10; +////for (x in function foo() { +//// return new String(); +////}) { +//// z++; +////} verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationFunctionExpressions.ts b/tests/cases/fourslash/breakpointValidationFunctionExpressions.ts similarity index 57% rename from tests/cases/fourslash_old/breakpointValidationFunctionExpressions.ts rename to tests/cases/fourslash/breakpointValidationFunctionExpressions.ts index e47a56cc08f..c4b145270a8 100644 --- a/tests/cases/fourslash_old/breakpointValidationFunctionExpressions.ts +++ b/tests/cases/fourslash/breakpointValidationFunctionExpressions.ts @@ -10,5 +10,17 @@ ////greet("Hello"); ////var incrGreetings = () => greetings++; ////var greetNewMsg = msg => greet(msg); -debugger; +////greetNewMsg = function (msg: string) { +//// return greet(msg); +////}; +////function bar(a = function foo() { +//// return greetings; +////}) { +//// if (!a()) { +//// return a; +//// } +//// return function bar() { +//// return -greetings; +//// }; +////} verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationIfElse.ts b/tests/cases/fourslash/breakpointValidationIfElse.ts index 6df1b844a70..1b5bbc93fb8 100644 --- a/tests/cases/fourslash/breakpointValidationIfElse.ts +++ b/tests/cases/fourslash/breakpointValidationIfElse.ts @@ -19,4 +19,9 @@ ////} else { //// i--; ////} +////if (function foo() { +//// return 30; +////} ()) { +//// i++; +////} verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationObjectLiteralExpressions.ts b/tests/cases/fourslash/breakpointValidationObjectLiteralExpressions.ts new file mode 100644 index 00000000000..fa05a09187c --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationObjectLiteralExpressions.ts @@ -0,0 +1,33 @@ +/// + +// @BaselineFile: bpSpan_objectLiteralExpressions.baseline +// @Filename: bpSpan_objectLiteralExpressions.ts +////var x = { +//// a: 10, +//// b: () => 10, +//// someMethod() { +//// return "Hello"; +//// }, +//// get y() { +//// return 30; +//// }, +//// set z(x: number) { +//// var bar = x; +//// } +////}; +////var a = ({ +//// a: 10, +//// b: () => 10, +//// someMethod() { +//// return "Hello"; +//// }, +//// get y() { +//// return 30; +//// }, +//// set z(x: number) { +//// var bar = x; +//// } +////}).someMethod; +////a(); + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationParenCallOrNewExpressions.ts b/tests/cases/fourslash/breakpointValidationParenCallOrNewExpressions.ts new file mode 100644 index 00000000000..874a848f461 --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationParenCallOrNewExpressions.ts @@ -0,0 +1,35 @@ +/// + +// @BaselineFile: bpSpan_parenCallOrNewExpressions.baseline +// @Filename: bpSpan_parenCallOrNewExpressions.ts +////function foo(a: number) { +//// return a; +////} +////foo((function bar() { +//// return foo(40); +////})()); +////var y = foo((function () { +//// return foo(40); +////})());; +////class greeter { +//// constructor(a: number) { +//// } +////} +////foo(30); +////foo(40 + y); +////y = foo(30); +////y = foo(500 + y); +////new greeter((function bar() { +//// return foo(40); +////})()); +////var anotherGreeter = new greeter((function bar() { +//// return foo(40); +////})()); +////anotherGreeter = new greeter(30); +////anotherGreeter = new greeter(40 + y); +////new greeter(30); +////new greeter(40 + y); +////function foo2(x: number, y: string) { +////} +////foo2(foo(30), foo(40).toString()); +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationStatements.ts b/tests/cases/fourslash/breakpointValidationStatements.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationStatements.ts rename to tests/cases/fourslash/breakpointValidationStatements.ts diff --git a/tests/cases/fourslash/breakpointValidationSwitch.ts b/tests/cases/fourslash/breakpointValidationSwitch.ts index 82c5fff9dea..6fbe676d67a 100644 --- a/tests/cases/fourslash/breakpointValidationSwitch.ts +++ b/tests/cases/fourslash/breakpointValidationSwitch.ts @@ -31,4 +31,12 @@ //// x = x * 10; //// } ////} +////switch ((function foo() { +//// return x * 30; +////})()) { +//// case (function bar() { +//// return 30; +//// })(): +//// x++; +////} verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationTryCatchFinally.ts b/tests/cases/fourslash/breakpointValidationTryCatchFinally.ts index bbeab4f6b00..3aa2b499542 100644 --- a/tests/cases/fourslash/breakpointValidationTryCatchFinally.ts +++ b/tests/cases/fourslash/breakpointValidationTryCatchFinally.ts @@ -24,5 +24,13 @@ ////{ //// x = x * 10; ////} +////try { +//// throw (function foo() { +//// new Error(x.toString()); +//// })(); +////} +////finally { +//// x++; +////} verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationTypeAssertionExpressions.ts b/tests/cases/fourslash/breakpointValidationTypeAssertionExpressions.ts new file mode 100644 index 00000000000..9d79f1e3fb3 --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationTypeAssertionExpressions.ts @@ -0,0 +1,13 @@ +/// + +// @BaselineFile: bpSpan_typeAssertionExpressions.baseline +// @Filename: bpSpan_typeAssertionExpressions.ts +////class Greeter { +////} +////var a = new Greeter(); +////a = ( new Greeter()); +////a = (function foo() { +//// return new Greeter(); +////})(); + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationUnaryExpressions.ts b/tests/cases/fourslash/breakpointValidationUnaryExpressions.ts new file mode 100644 index 00000000000..8b937154516 --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationUnaryExpressions.ts @@ -0,0 +1,15 @@ +/// + +// @BaselineFile: bpSpan_unaryExpressions.baseline +// @Filename: bpSpan_unaryExpressions.ts +////var x = 10; +////var y = 20; +////x++; +////y--; +////typeof (function foo() { +//// return y; +////})(); +////++x; +////++y; + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationWhile.ts b/tests/cases/fourslash/breakpointValidationWhile.ts index 9fc913c702c..fa472b77ed3 100644 --- a/tests/cases/fourslash/breakpointValidationWhile.ts +++ b/tests/cases/fourslash/breakpointValidationWhile.ts @@ -13,4 +13,10 @@ ////while (a == 10) a++; ////while (a == 10) //// a++; +////while ((function () { +//// return 30 * a; +////})() !== a) { +//// a--; +////} + verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationWith.ts b/tests/cases/fourslash/breakpointValidationWith.ts new file mode 100644 index 00000000000..84e729d8efe --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationWith.ts @@ -0,0 +1,10 @@ +/// + +// @BaselineFile: bpSpan_with.baseline +// @Filename: bpSpan_with.ts +////var obj: string; +////with (obj) { +//// x = 10; +////} + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file From 4a8a8920a2b53d38e7522ef1f9a99df3e0da4326 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 20 Oct 2014 23:01:06 -0700 Subject: [PATCH 45/63] Do not set breakpoints on the blank line or comment only line --- src/services/breakpoints.ts | 9 +++++-- .../reference/bpSpan_classes.baseline | 24 +++++-------------- .../reference/bpSpan_inBlankLine.baseline | 15 ++++++++++++ .../reference/bpSpan_inComments.baseline | 19 +++++++++++++++ .../reference/bpSpan_module.baseline | 4 +--- .../breakpointValidationInBlankLine.ts | 9 +++++++ .../breakpointValidationInComments.ts | 10 ++++++++ 7 files changed, 67 insertions(+), 23 deletions(-) create mode 100644 tests/baselines/reference/bpSpan_inBlankLine.baseline create mode 100644 tests/baselines/reference/bpSpan_inComments.baseline create mode 100644 tests/cases/fourslash/breakpointValidationInBlankLine.ts create mode 100644 tests/cases/fourslash/breakpointValidationInComments.ts diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index a9c9bfaff77..a7527d92614 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -10,7 +10,7 @@ module ts.BreakpointResolver { export function spanInSourceFileAtLocation(sourceFile: SourceFile, position: number) { // Cannot set breakpoint in dts file if (sourceFile.flags & NodeFlags.DeclarationFile) { - return; + return undefined; } var tokenAtLocation = getTokenAtPosition(sourceFile, position); @@ -22,11 +22,16 @@ module ts.BreakpointResolver { // token at position will return var keyword on second line as the token but we would like to use // token on same line if trailing trivia (comments or white spaces on same line) part of the last token on that line tokenAtLocation = findPrecedingToken(tokenAtLocation.pos, sourceFile); + + // Its a blank line + if (!tokenAtLocation || sourceFile.getLineAndCharacterFromPosition(tokenAtLocation.getEnd()).line !== lineOfPosition) { + return undefined; + } } // Cannot set breakpoint in ambient declarations if (isInAmbientContext(tokenAtLocation)) { - return; + return undefined; } // Get the span in the node based on its syntax diff --git a/tests/baselines/reference/bpSpan_classes.baseline b/tests/baselines/reference/bpSpan_classes.baseline index 88409460d03..73089699a2b 100644 --- a/tests/baselines/reference/bpSpan_classes.baseline +++ b/tests/baselines/reference/bpSpan_classes.baseline @@ -45,9 +45,7 @@ -------------------------------- 7 > - ~ => Pos: (113 to 113) SpanInfo: {"start":111,"length":1} - >} - >:=> (line 6, col 8) to (line 6, col 9) + ~ => Pos: (113 to 113) SpanInfo: undefined -------------------------------- 8 > greet() { @@ -75,15 +73,11 @@ -------------------------------- 12 > - ~ => Pos: (201 to 201) SpanInfo: {"start":199,"length":1} - >} - >:=> (line 11, col 4) to (line 11, col 5) + ~ => Pos: (201 to 201) SpanInfo: undefined -------------------------------- 13 > - ~ => Pos: (202 to 202) SpanInfo: {"start":199,"length":1} - >} - >:=> (line 11, col 4) to (line 11, col 5) + ~ => Pos: (202 to 202) SpanInfo: undefined -------------------------------- 14 > function foo(greeting: string): Greeter { @@ -110,9 +104,7 @@ -------------------------------- 17 > - ~ => Pos: (293 to 293) SpanInfo: {"start":291,"length":1} - >} - >:=> (line 16, col 4) to (line 16, col 5) + ~ => Pos: (293 to 293) SpanInfo: undefined -------------------------------- 18 > var greeter = new Greeter("Hello, world!"); @@ -213,9 +205,7 @@ -------------------------------- 27 > - ~ => Pos: (695 to 695) SpanInfo: {"start":639,"length":44} - >greeters.push(new Greeter(restGreetings[i])) - >:=> (line 25, col 12) to (line 25, col 56) + ~ => Pos: (695 to 695) SpanInfo: undefined -------------------------------- 28 > return greeters; @@ -231,9 +221,7 @@ -------------------------------- 30 > - ~ => Pos: (727 to 727) SpanInfo: {"start":725,"length":1} - >} - >:=> (line 29, col 4) to (line 29, col 5) + ~ => Pos: (727 to 727) SpanInfo: undefined -------------------------------- 31 > var b = foo2("Hello", "World", "!"); diff --git a/tests/baselines/reference/bpSpan_inBlankLine.baseline b/tests/baselines/reference/bpSpan_inBlankLine.baseline new file mode 100644 index 00000000000..40fe26a16a6 --- /dev/null +++ b/tests/baselines/reference/bpSpan_inBlankLine.baseline @@ -0,0 +1,15 @@ + +1 >var x = 10; + + ~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":0,"length":10} + >var x = 10 + >:=> (line 1, col 0) to (line 1, col 10) +-------------------------------- +2 > + + ~ => Pos: (12 to 12) SpanInfo: undefined +-------------------------------- +3 >var y = 10; + ~~~~~~~~~~~ => Pos: (13 to 23) SpanInfo: {"start":13,"length":10} + >var y = 10 + >:=> (line 3, col 0) to (line 3, col 10) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_inComments.baseline b/tests/baselines/reference/bpSpan_inComments.baseline new file mode 100644 index 00000000000..5c167293513 --- /dev/null +++ b/tests/baselines/reference/bpSpan_inComments.baseline @@ -0,0 +1,19 @@ + +1 >/*comment here*/ var x = 10; /*comment here*/ + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (0 to 45) SpanInfo: {"start":17,"length":10} + >var x = 10 + >:=> (line 1, col 17) to (line 1, col 27) +-------------------------------- +2 >// comment only line + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (46 to 66) SpanInfo: undefined +-------------------------------- +3 >/*multiline comment + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (67 to 86) SpanInfo: undefined +-------------------------------- +4 >another line of multiline comment */ var y = 10; // comment here + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (87 to 150) SpanInfo: {"start":124,"length":10} + >var y = 10 + >:=> (line 4, col 37) to (line 4, col 47) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_module.baseline b/tests/baselines/reference/bpSpan_module.baseline index f00595e2b1e..cdeae25a1dd 100644 --- a/tests/baselines/reference/bpSpan_module.baseline +++ b/tests/baselines/reference/bpSpan_module.baseline @@ -49,9 +49,7 @@ -------------------------------- 9 > - ~ => Pos: (100 to 100) SpanInfo: {"start":98,"length":1} - >} - >:=> (line 8, col 4) to (line 8, col 5) + ~ => Pos: (100 to 100) SpanInfo: undefined -------------------------------- 10 > export function foo() { diff --git a/tests/cases/fourslash/breakpointValidationInBlankLine.ts b/tests/cases/fourslash/breakpointValidationInBlankLine.ts new file mode 100644 index 00000000000..03814fd8157 --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationInBlankLine.ts @@ -0,0 +1,9 @@ +/// + +// @BaselineFile: bpSpan_inBlankLine.baseline +// @Filename: bpSpan_inBlankLine.ts +////var x = 10; +//// +////var y = 10; + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationInComments.ts b/tests/cases/fourslash/breakpointValidationInComments.ts new file mode 100644 index 00000000000..3369db00eeb --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationInComments.ts @@ -0,0 +1,10 @@ +/// + +// @BaselineFile: bpSpan_inComments.baseline +// @Filename: bpSpan_inComments.ts +/////*comment here*/ var x = 10; /*comment here*/ +////// comment only line +/////*multiline comment +////another line of multiline comment */ var y = 10; // comment here + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file From 308670c9cebbee02c4aa85f8b69b4989adea3543 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 20 Oct 2014 23:34:43 -0700 Subject: [PATCH 46/63] Implement getNameOrDottedNameSpan for new compiler --- src/harness/fourslash.ts | 147 ++- src/services/services.ts | 108 ++- .../nameOrDottedSpan_classes.baseline | 522 +++++++++++ .../reference/nameOrDottedSpan_stmts.baseline | 884 ++++++++++++++++++ .../nameOrDottedNameClasses.ts | 0 .../nameOrDottedNameStatements.ts | 0 .../fourslash_old/nameOrDottedName_Classes.ts | 43 - .../nameOrDottedName_Statements.ts | 90 -- 8 files changed, 1540 insertions(+), 254 deletions(-) create mode 100644 tests/baselines/reference/nameOrDottedSpan_classes.baseline create mode 100644 tests/baselines/reference/nameOrDottedSpan_stmts.baseline rename tests/cases/{fourslash_old => fourslash}/nameOrDottedNameClasses.ts (100%) rename tests/cases/{fourslash_old => fourslash}/nameOrDottedNameStatements.ts (100%) delete mode 100644 tests/cases/fourslash_old/nameOrDottedName_Classes.ts delete mode 100644 tests/cases/fourslash_old/nameOrDottedName_Statements.ts diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index ba7c6115812..2a05667ace2 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -987,10 +987,7 @@ module FourSlash { private alignmentForExtraInfo = 50; - public getBreakpointStatementLocation(pos: number, prefixString: string) { - this.taoInvalidReason = 'getBreakpointStatementLocation NYI'; - - var spanInfo = this.languageService.getBreakpointStatementAtPosition(this.activeFile.fileName, pos); + private spanInfoToString(pos: number, spanInfo: TypeScript.TextSpan, prefixString: string) { var resultString = "SpanInfo: " + JSON.stringify(spanInfo); if (spanInfo) { var spanString = this.activeFile.content.substr(spanInfo.start(), spanInfo.length()); @@ -1003,9 +1000,72 @@ module FourSlash { } resultString += "\n" + prefixString + ":=> (" + this.getLineColStringAtPosition(spanInfo.start()) + ") to (" + this.getLineColStringAtPosition(spanInfo.end()) + ")"; } + return resultString; } + private baselineCurrentFileLocations(getSpanAtPos: (pos: number) => TypeScript.TextSpan): string { + var fileLineMap = ts.getLineStarts(this.activeFile.content); + var nextLine = 0; + var resultString = ""; + var currentLine: string; + var previousSpanInfo: string; + var startColumn: number; + var length: number; + var prefixString = " >"; + + var addSpanInfoString = () => { + if (previousSpanInfo) { + resultString += currentLine; + var thisLineMarker = repeatString(startColumn, " ") + repeatString(length, "~"); + thisLineMarker += repeatString(this.alignmentForExtraInfo - thisLineMarker.length - prefixString.length + 1, " "); + resultString += thisLineMarker; + resultString += "=> Pos: (" + (pos - length) + " to " + (pos - 1) + ") "; + resultString += " " + previousSpanInfo; + previousSpanInfo = undefined; + } + }; + + for (var pos = 0; pos < this.activeFile.content.length; pos++) { + if (pos === 0 || pos === fileLineMap[nextLine]) { + nextLine++; + addSpanInfoString(); + if (resultString.length) { + resultString += "\n--------------------------------"; + } + currentLine = "\n" + nextLine.toString() + repeatString(3 - nextLine.toString().length, " ") + ">" + this.activeFile.content.substring(pos, fileLineMap[nextLine]) + "\n "; + startColumn = 0; + length = 0; + } + var spanInfo = this.spanInfoToString(pos, getSpanAtPos(pos), prefixString); + if (previousSpanInfo && previousSpanInfo !== spanInfo) { + addSpanInfoString(); + previousSpanInfo = spanInfo; + startColumn = startColumn + length; + length = 1; + } + else { + previousSpanInfo = spanInfo; + length++; + } + } + addSpanInfoString(); + return resultString; + + function repeatString(count: number, char: string) { + var result = ""; + for (var i = 0; i < count; i++) { + result += char; + } + return result; + } + } + + public getBreakpointStatementLocation(pos: number) { + this.taoInvalidReason = 'getBreakpointStatementLocation NYI'; + return this.languageService.getBreakpointStatementAtPosition(this.activeFile.fileName, pos); + } + public baselineCurrentFileBreakpointLocations() { this.taoInvalidReason = 'baselineCurrentFileBreakpointLocations impossible'; @@ -1013,60 +1073,7 @@ module FourSlash { "Breakpoint Locations for " + this.activeFile.fileName, this.testData.globalOptions[testOptMetadataNames.baselineFile], () => { - var fileLineMap = ts.getLineStarts(this.activeFile.content); - var nextLine = 0; - var resultString = ""; - var currentLine: string; - var previousSpanInfo: string; - var startColumn: number; - var length: number; - var prefixString = " >"; - - var addSpanInfoString = () => { - if (previousSpanInfo) { - resultString += currentLine; - var thisLineMarker = repeatString(startColumn, " ") + repeatString(length, "~"); - thisLineMarker += repeatString(this.alignmentForExtraInfo - thisLineMarker.length - prefixString.length + 1, " "); - resultString += thisLineMarker; - resultString += "=> Pos: (" + (pos - length) + " to " + (pos - 1) + ") "; - resultString += " " + previousSpanInfo; - previousSpanInfo = undefined; - } - }; - - for (var pos = 0; pos < this.activeFile.content.length; pos++) { - if (pos === 0 || pos === fileLineMap[nextLine]) { - nextLine++; - addSpanInfoString(); - if (resultString.length) { - resultString += "\n--------------------------------"; - } - currentLine = "\n" + nextLine.toString() + repeatString(3 - nextLine.toString().length, " ") + ">" + this.activeFile.content.substring(pos, fileLineMap[nextLine]) + "\n "; - startColumn = 0; - length = 0; - } - var spanInfo = this.getBreakpointStatementLocation(pos, prefixString); - if (previousSpanInfo && previousSpanInfo !== spanInfo) { - addSpanInfoString(); - previousSpanInfo = spanInfo; - startColumn = startColumn + length; - length = 1; - } - else { - previousSpanInfo = spanInfo; - length++; - } - } - addSpanInfoString(); - return resultString; - - function repeatString(count: number, char: string) { - var result = ""; - for (var i = 0; i < count; i++) { - result += char; - } - return result; - } + return this.baselineCurrentFileLocations(pos => this.getBreakpointStatementLocation(pos)); }, true /* run immediately */); } @@ -1114,7 +1121,7 @@ module FourSlash { } public printBreakpointLocation(pos: number) { - Harness.IO.log("\n**Pos: " + pos + " " + this.getBreakpointStatementLocation(pos, " ")); + Harness.IO.log("\n**Pos: " + pos + " " + this.spanInfoToString(pos, this.getBreakpointStatementLocation(pos), " ")); } public printBreakpointAtCurrentLocation() { @@ -1624,10 +1631,10 @@ module FourSlash { this.taoInvalidReason = 'verifyCurrentNameOrDottedNameSpanText NYI'; var span = this.languageService.getNameOrDottedNameSpan(this.activeFile.fileName, this.currentCaretPosition, this.currentCaretPosition); - if (span === null) { + if (!span) { this.raiseError('verifyCurrentNameOrDottedNameSpanText\n' + '\tExpected: "' + text + '"\n' + - '\t Actual: null'); + '\t Actual: undefined'); } var actual = this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName).getText(span.start(), span.end()); @@ -1639,12 +1646,8 @@ module FourSlash { } private getNameOrDottedNameSpan(pos: number) { - var spanInfo = this.languageService.getNameOrDottedNameSpan(this.activeFile.fileName, pos, pos); - var resultString = "\n**Pos: " + pos + " SpanInfo: " + JSON.stringify(spanInfo) + "\n** Statement: "; - if (spanInfo !== null) { - resultString = resultString + this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName).getText(spanInfo.start(), spanInfo.end()); - } - return resultString; + this.taoInvalidReason = 'getNameOrDottedNameSpan NYI'; + return this.languageService.getNameOrDottedNameSpan(this.activeFile.fileName, pos, pos); } public baselineCurrentFileNameOrDottedNameSpans() { @@ -1654,18 +1657,14 @@ module FourSlash { "Name OrDottedNameSpans for " + this.activeFile.fileName, this.testData.globalOptions[testOptMetadataNames.baselineFile], () => { - var fileLength = this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName).getLength(); - var resultString = ""; - for (var pos = 0; pos < fileLength; pos++) { - resultString = resultString + this.getNameOrDottedNameSpan(pos); - } - return resultString; + return this.baselineCurrentFileLocations(pos => + this.getNameOrDottedNameSpan(pos)); }, true /* run immediately */); } public printNameOrDottedNameSpans(pos: number) { - Harness.IO.log(this.getNameOrDottedNameSpan(pos)); + Harness.IO.log(this.spanInfoToString(pos, this.getNameOrDottedNameSpan(pos), "**")); } private verifyClassifications(expected: { classificationType: string; text: string; textSpan?: TextSpan }[], actual: ts.ClassifiedSpan[]) { diff --git a/src/services/services.ts b/src/services/services.ts index 080daa1aa53..5e1c97a7fff 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1950,18 +1950,32 @@ module ts { return isLabelOfLabeledStatement(node) || isJumpStatementTarget(node); } + function isRightSideOfQualifiedName(node: Node) { + return node.parent.kind === SyntaxKind.QualifiedName && (node.parent).right === node; + } + + function isRightSideOfPropertyAccess(node: Node) { + return node.parent.kind === SyntaxKind.PropertyAccess && (node.parent).right === node; + } + function isCallExpressionTarget(node: Node): boolean { - if (node.parent.kind === SyntaxKind.PropertyAccess && (node.parent).right === node) + if (isRightSideOfPropertyAccess(node)) { node = node.parent; + } return node.parent.kind === SyntaxKind.CallExpression && (node.parent).func === node; } function isNewExpressionTarget(node: Node): boolean { - if (node.parent.kind === SyntaxKind.PropertyAccess && (node.parent).right === node) + if (isRightSideOfPropertyAccess(node)) { node = node.parent; + } return node.parent.kind === SyntaxKind.NewExpression && (node.parent).func === node; } + function isNameOfModuleDeclaration(node: Node) { + return node.parent.kind === SyntaxKind.ModuleDeclaration && (node.parent).name === node; + } + function isNameOfFunctionDeclaration(node: Node): boolean { return node.kind === SyntaxKind.Identifier && isAnyFunction(node.parent) && (node.parent).name === node; @@ -1994,7 +2008,7 @@ module ts { function isNameOfExternalModuleImportOrDeclaration(node: Node): boolean { return node.kind === SyntaxKind.StringLiteral && - ((node.parent.kind === SyntaxKind.ModuleDeclaration && (node.parent).name === node) || + (isNameOfModuleDeclaration(node) || (node.parent.kind === SyntaxKind.ImportDeclaration && (node.parent).externalModuleName === node)); } @@ -4528,8 +4542,9 @@ module ts { } function isTypeReference(node: Node): boolean { - if (node.parent.kind === SyntaxKind.QualifiedName && (node.parent).right === node) + if (isRightSideOfQualifiedName(node)) { node = node.parent; + } return node.parent.kind === SyntaxKind.TypeReference; } @@ -4679,64 +4694,63 @@ module ts { } function getNameOrDottedNameSpan(filename: string, startPos: number, endPos: number): TypeScript.TextSpan { - function getTypeInfoEligiblePath(filename: string, position: number, isConstructorValidPosition: boolean) { - var sourceUnit = syntaxTreeCache.getCurrentFileSyntaxTree(filename).sourceUnit(); + filename = ts.normalizeSlashes(filename); + // Get node at the location + var node = getTouchingPropertyName(getCurrentSourceFile(filename), startPos); - var ast = TypeScript.ASTHelpers.getAstAtPosition(sourceUnit, position, /*useTrailingTriviaAsLimChar*/ false, /*forceInclusive*/ true); - if (ast === null) { - return null; - } - - if (ast.kind() === TypeScript.SyntaxKind.ParameterList && ast.parent.kind() === TypeScript.SyntaxKind.CallSignature && ast.parent.parent.kind() === TypeScript.SyntaxKind.ConstructorDeclaration) { - ast = ast.parent.parent; - } - - switch (ast.kind()) { - default: - return null; - case TypeScript.SyntaxKind.ConstructorDeclaration: - var constructorAST = ast; - if (!isConstructorValidPosition || !(position >= TypeScript.start(constructorAST) && position <= TypeScript.start(constructorAST) + "constructor".length)) { - return null; - } - else { - return ast; - } - case TypeScript.SyntaxKind.FunctionDeclaration: - return null; - case TypeScript.SyntaxKind.MemberAccessExpression: - case TypeScript.SyntaxKind.QualifiedName: - case TypeScript.SyntaxKind.SuperKeyword: - case TypeScript.SyntaxKind.StringLiteral: - case TypeScript.SyntaxKind.ThisKeyword: - case TypeScript.SyntaxKind.IdentifierName: - return ast; - } + if (!node) { + return; } - filename = TypeScript.switchToForwardSlashes(filename); + switch (node.kind) { + case SyntaxKind.PropertyAccess: + case SyntaxKind.QualifiedName: + case SyntaxKind.StringLiteral: + case SyntaxKind.FalseKeyword: + case SyntaxKind.TrueKeyword: + case SyntaxKind.NullKeyword: + case SyntaxKind.SuperKeyword: + case SyntaxKind.ThisKeyword: + case SyntaxKind.Identifier: + break; - var node = getTypeInfoEligiblePath(filename, startPos, false); - if (!node) return null; + // Cant create the text span + default: + return; + } - while (node) { - if (TypeScript.ASTHelpers.isNameOfMemberAccessExpression(node) || - TypeScript.ASTHelpers.isRightSideOfQualifiedName(node)) { - node = node.parent; + var nodeForStartPos = node; + while (true) { + if (isRightSideOfPropertyAccess(nodeForStartPos) || isRightSideOfQualifiedName(nodeForStartPos)) { + // If on the span is in right side of the the property or qualified name, return the span from the qualified name pos to end of this node + nodeForStartPos = nodeForStartPos.parent; + } + else if (isNameOfModuleDeclaration(nodeForStartPos)) { + // If this is name of a module declarations, check if this is right side of dotted module name + // If parent of the module declaration which is parent of this node is module declaration and its body is the module declaration that this node is name of + // Then this name is name from dotted module + if (nodeForStartPos.parent.parent.kind === SyntaxKind.ModuleDeclaration && + (nodeForStartPos.parent.parent).body === nodeForStartPos.parent) { + // Use parent module declarations name for start pos + nodeForStartPos = (nodeForStartPos.parent.parent).name; + } + else { + // We have to use this name for start pos + break; + } } else { + // Is not a member expression so we have found the node for start pos break; } } - return TypeScript.TextSpan.fromBounds( - TypeScript.start(node), - TypeScript.end(node)); + return TypeScript.TextSpan.fromBounds(nodeForStartPos.getStart(), node.getEnd()); } function getBreakpointStatementAtPosition(filename: string, position: number) { // doesn't use compiler - no need to synchronize with host - filename = TypeScript.switchToForwardSlashes(filename); + filename = ts.normalizeSlashes(filename); return BreakpointResolver.spanInSourceFileAtLocation(getCurrentSourceFile(filename), position); } diff --git a/tests/baselines/reference/nameOrDottedSpan_classes.baseline b/tests/baselines/reference/nameOrDottedSpan_classes.baseline new file mode 100644 index 00000000000..88383c638a8 --- /dev/null +++ b/tests/baselines/reference/nameOrDottedSpan_classes.baseline @@ -0,0 +1,522 @@ + +1 >module Foo.Bar { + + ~~~~~~~ => Pos: (0 to 6) SpanInfo: undefined +1 >module Foo.Bar { + + ~~~~ => Pos: (7 to 10) SpanInfo: {"start":7,"length":3} + >Foo + >:=> (line 1, col 7) to (line 1, col 10) +1 >module Foo.Bar { + + ~~~~ => Pos: (11 to 14) SpanInfo: {"start":7,"length":7} + >Foo.Bar + >:=> (line 1, col 7) to (line 1, col 14) +1 >module Foo.Bar { + + ~~ => Pos: (15 to 16) SpanInfo: undefined +-------------------------------- +2 > "use strict"; + + ~~~~ => Pos: (17 to 20) SpanInfo: undefined +2 > "use strict"; + + ~~~~~~~~~~~~~ => Pos: (21 to 33) SpanInfo: {"start":21,"length":12} + >"use strict" + >:=> (line 2, col 4) to (line 2, col 16) +2 > "use strict"; + + ~ => Pos: (34 to 34) SpanInfo: undefined +-------------------------------- +3 > + + ~ => Pos: (35 to 35) SpanInfo: undefined +-------------------------------- +4 > class Greeter { + + ~~~~~~~~~~ => Pos: (36 to 45) SpanInfo: undefined +4 > class Greeter { + + ~~~~~~~~ => Pos: (46 to 53) SpanInfo: {"start":46,"length":7} + >Greeter + >:=> (line 4, col 10) to (line 4, col 17) +4 > class Greeter { + + ~~ => Pos: (54 to 55) SpanInfo: undefined +-------------------------------- +5 > constructor(public greeting: string) { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (56 to 82) SpanInfo: undefined +5 > constructor(public greeting: string) { + + ~~~~~~~~~ => Pos: (83 to 91) SpanInfo: {"start":83,"length":8} + >greeting + >:=> (line 5, col 27) to (line 5, col 35) +5 > constructor(public greeting: string) { + + ~~~~~~~~~~~=> Pos: (92 to 102) SpanInfo: undefined +-------------------------------- +6 > } + + ~~~~~~~~~~ => Pos: (103 to 112) SpanInfo: undefined +-------------------------------- +7 > + + ~ => Pos: (113 to 113) SpanInfo: undefined +-------------------------------- +8 > greet() { + + ~~~~~~~~ => Pos: (114 to 121) SpanInfo: undefined +8 > greet() { + + ~~~~~~ => Pos: (122 to 127) SpanInfo: {"start":122,"length":5} + >greet + >:=> (line 8, col 8) to (line 8, col 13) +8 > greet() { + + ~~~~ => Pos: (128 to 131) SpanInfo: undefined +-------------------------------- +9 > return "

" + this.greeting + "

"; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (132 to 150) SpanInfo: undefined +9 > return "

" + this.greeting + "

"; + + ~~~~~~~ => Pos: (151 to 157) SpanInfo: {"start":151,"length":6} + >"

" + >:=> (line 9, col 19) to (line 9, col 25) +9 > return "

" + this.greeting + "

"; + + ~~ => Pos: (158 to 159) SpanInfo: undefined +9 > return "

" + this.greeting + "

"; + + ~~~~~ => Pos: (160 to 164) SpanInfo: {"start":160,"length":4} + >this + >:=> (line 9, col 28) to (line 9, col 32) +9 > return "

" + this.greeting + "

"; + + ~~~~~~~~~ => Pos: (165 to 173) SpanInfo: {"start":160,"length":13} + >this.greeting + >:=> (line 9, col 28) to (line 9, col 41) +9 > return "

" + this.greeting + "

"; + + ~~ => Pos: (174 to 175) SpanInfo: undefined +9 > return "

" + this.greeting + "

"; + + ~~~~~~~~=> Pos: (176 to 183) SpanInfo: {"start":176,"length":7} + >"" + >:=> (line 9, col 44) to (line 9, col 51) +9 > return "

" + this.greeting + "

"; + + ~=> Pos: (184 to 184) SpanInfo: undefined +-------------------------------- +10 > } + + ~~~~~~~~~~ => Pos: (185 to 194) SpanInfo: undefined +-------------------------------- +11 > } + + ~~~~~~ => Pos: (195 to 200) SpanInfo: undefined +-------------------------------- +12 > + + ~ => Pos: (201 to 201) SpanInfo: undefined +-------------------------------- +13 > + + ~ => Pos: (202 to 202) SpanInfo: undefined +-------------------------------- +14 > function foo(greeting: string): Greeter { + + ~~~~~~~~~~~~~ => Pos: (203 to 215) SpanInfo: undefined +14 > function foo(greeting: string): Greeter { + + ~~~~ => Pos: (216 to 219) SpanInfo: {"start":216,"length":3} + >foo + >:=> (line 14, col 13) to (line 14, col 16) +14 > function foo(greeting: string): Greeter { + + ~~~~~~~~~ => Pos: (220 to 228) SpanInfo: {"start":220,"length":8} + >greeting + >:=> (line 14, col 17) to (line 14, col 25) +14 > function foo(greeting: string): Greeter { + + ~~~~~~~~~~ => Pos: (229 to 238) SpanInfo: undefined +14 > function foo(greeting: string): Greeter { + + ~~~~~~~~ => Pos: (239 to 246) SpanInfo: {"start":239,"length":7} + >Greeter + >:=> (line 14, col 36) to (line 14, col 43) +14 > function foo(greeting: string): Greeter { + + ~~=> Pos: (247 to 248) SpanInfo: undefined +-------------------------------- +15 > return new Greeter(greeting); + + ~~~~~~~~~~~~~~~~~~~ => Pos: (249 to 267) SpanInfo: undefined +15 > return new Greeter(greeting); + + ~~~~~~~~ => Pos: (268 to 275) SpanInfo: {"start":268,"length":7} + >Greeter + >:=> (line 15, col 19) to (line 15, col 26) +15 > return new Greeter(greeting); + + ~~~~~~~~~ => Pos: (276 to 284) SpanInfo: {"start":276,"length":8} + >greeting + >:=> (line 15, col 27) to (line 15, col 35) +15 > return new Greeter(greeting); + + ~~ => Pos: (285 to 286) SpanInfo: undefined +-------------------------------- +16 > } + + ~~~~~~ => Pos: (287 to 292) SpanInfo: undefined +-------------------------------- +17 > + + ~ => Pos: (293 to 293) SpanInfo: undefined +-------------------------------- +18 > var greeter = new Greeter("Hello, world!"); + + ~~~~~~~~ => Pos: (294 to 301) SpanInfo: undefined +18 > var greeter = new Greeter("Hello, world!"); + + ~~~~~~~~ => Pos: (302 to 309) SpanInfo: {"start":302,"length":7} + >greeter + >:=> (line 18, col 8) to (line 18, col 15) +18 > var greeter = new Greeter("Hello, world!"); + + ~~~~~~ => Pos: (310 to 315) SpanInfo: undefined +18 > var greeter = new Greeter("Hello, world!"); + + ~~~~~~~~ => Pos: (316 to 323) SpanInfo: {"start":316,"length":7} + >Greeter + >:=> (line 18, col 22) to (line 18, col 29) +18 > var greeter = new Greeter("Hello, world!"); + + ~~~~~~~~~~~~~~~~=> Pos: (324 to 339) SpanInfo: {"start":324,"length":15} + >"Hello, world!" + >:=> (line 18, col 30) to (line 18, col 45) +18 > var greeter = new Greeter("Hello, world!"); + + ~~=> Pos: (340 to 341) SpanInfo: undefined +-------------------------------- +19 > var str = greeter.greet(); + + ~~~~~~~~ => Pos: (342 to 349) SpanInfo: undefined +19 > var str = greeter.greet(); + + ~~~~ => Pos: (350 to 353) SpanInfo: {"start":350,"length":3} + >str + >:=> (line 19, col 8) to (line 19, col 11) +19 > var str = greeter.greet(); + + ~~ => Pos: (354 to 355) SpanInfo: undefined +19 > var str = greeter.greet(); + + ~~~~~~~~ => Pos: (356 to 363) SpanInfo: {"start":356,"length":7} + >greeter + >:=> (line 19, col 14) to (line 19, col 21) +19 > var str = greeter.greet(); + + ~~~~~~ => Pos: (364 to 369) SpanInfo: {"start":356,"length":13} + >greeter.greet + >:=> (line 19, col 14) to (line 19, col 27) +19 > var str = greeter.greet(); + + ~~~ => Pos: (370 to 372) SpanInfo: undefined +-------------------------------- +20 > + + ~ => Pos: (373 to 373) SpanInfo: undefined +-------------------------------- +21 > function foo2(greeting: string, ...restGreetings /* more greeting */: string[]) { + + ~~~~~~~~~~~~~ => Pos: (374 to 386) SpanInfo: undefined +21 > function foo2(greeting: string, ...restGreetings /* more greeting */: string[]) { + + ~~~~~ => Pos: (387 to 391) SpanInfo: {"start":387,"length":4} + >foo2 + >:=> (line 21, col 13) to (line 21, col 17) +21 > function foo2(greeting: string, ...restGreetings /* more greeting */: string[]) { + + ~~~~~~~~~ => Pos: (392 to 400) SpanInfo: {"start":392,"length":8} + >greeting + >:=> (line 21, col 18) to (line 21, col 26) +21 > function foo2(greeting: string, ...restGreetings /* more greeting */: string[]) { + + ~~~~~~~~~~~~ => Pos: (401 to 412) SpanInfo: undefined +21 > function foo2(greeting: string, ...restGreetings /* more greeting */: string[]) { + + ~~~~~~~~~~~~~~=> Pos: (413 to 426) SpanInfo: {"start":413,"length":13} + >restGreetings + >:=> (line 21, col 39) to (line 21, col 52) +21 > function foo2(greeting: string, ...restGreetings /* more greeting */: string[]) { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (427 to 459) SpanInfo: undefined +-------------------------------- +22 > var greeters: Greeter[] = []; /* inline block comment */ + + ~~~~~~~~~~~~ => Pos: (460 to 471) SpanInfo: undefined +22 > var greeters: Greeter[] = []; /* inline block comment */ + + ~~~~~~~~~ => Pos: (472 to 480) SpanInfo: {"start":472,"length":8} + >greeters + >:=> (line 22, col 12) to (line 22, col 20) +22 > var greeters: Greeter[] = []; /* inline block comment */ + + ~ => Pos: (481 to 481) SpanInfo: undefined +22 > var greeters: Greeter[] = []; /* inline block comment */ + + ~~~~~~~~ => Pos: (482 to 489) SpanInfo: {"start":482,"length":7} + >Greeter + >:=> (line 22, col 22) to (line 22, col 29) +22 > var greeters: Greeter[] = []; /* inline block comment */ + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (490 to 524) SpanInfo: undefined +-------------------------------- +23 > greeters[0] = new Greeter(greeting); + + ~~~~~~~~ => Pos: (525 to 532) SpanInfo: undefined +23 > greeters[0] = new Greeter(greeting); + + ~~~~~~~~~ => Pos: (533 to 541) SpanInfo: {"start":533,"length":8} + >greeters + >:=> (line 23, col 8) to (line 23, col 16) +23 > greeters[0] = new Greeter(greeting); + + ~~~~~~~~~ => Pos: (542 to 550) SpanInfo: undefined +23 > greeters[0] = new Greeter(greeting); + + ~~~~~~~~ => Pos: (551 to 558) SpanInfo: {"start":551,"length":7} + >Greeter + >:=> (line 23, col 26) to (line 23, col 33) +23 > greeters[0] = new Greeter(greeting); + + ~~~~~~~~~ => Pos: (559 to 567) SpanInfo: {"start":559,"length":8} + >greeting + >:=> (line 23, col 34) to (line 23, col 42) +23 > greeters[0] = new Greeter(greeting); + + ~~ => Pos: (568 to 569) SpanInfo: undefined +-------------------------------- +24 > for (var i = 0; i < restGreetings.length; i++) { + + ~~~~~~~~~~~~~~~~~ => Pos: (570 to 586) SpanInfo: undefined +24 > for (var i = 0; i < restGreetings.length; i++) { + + ~~ => Pos: (587 to 588) SpanInfo: {"start":587,"length":1} + >i + >:=> (line 24, col 17) to (line 24, col 18) +24 > for (var i = 0; i < restGreetings.length; i++) { + + ~~~~~ => Pos: (589 to 593) SpanInfo: undefined +24 > for (var i = 0; i < restGreetings.length; i++) { + + ~~ => Pos: (594 to 595) SpanInfo: {"start":594,"length":1} + >i + >:=> (line 24, col 24) to (line 24, col 25) +24 > for (var i = 0; i < restGreetings.length; i++) { + + ~~ => Pos: (596 to 597) SpanInfo: undefined +24 > for (var i = 0; i < restGreetings.length; i++) { + + ~~~~~~~~~~~~~~ => Pos: (598 to 611) SpanInfo: {"start":598,"length":13} + >restGreetings + >:=> (line 24, col 28) to (line 24, col 41) +24 > for (var i = 0; i < restGreetings.length; i++) { + + ~~~~~~~=> Pos: (612 to 618) SpanInfo: {"start":598,"length":20} + >restGreetings.length + >:=> (line 24, col 28) to (line 24, col 48) +24 > for (var i = 0; i < restGreetings.length; i++) { + + ~=> Pos: (619 to 619) SpanInfo: undefined +24 > for (var i = 0; i < restGreetings.length; i++) { + + ~~=> Pos: (620 to 621) SpanInfo: {"start":620,"length":1} + >i + >:=> (line 24, col 50) to (line 24, col 51) +24 > for (var i = 0; i < restGreetings.length; i++) { + + ~~~~~=> Pos: (622 to 626) SpanInfo: undefined +-------------------------------- +25 > greeters.push(new Greeter(restGreetings[i])); + + ~~~~~~~~~~~~ => Pos: (627 to 638) SpanInfo: undefined +25 > greeters.push(new Greeter(restGreetings[i])); + + ~~~~~~~~~ => Pos: (639 to 647) SpanInfo: {"start":639,"length":8} + >greeters + >:=> (line 25, col 12) to (line 25, col 20) +25 > greeters.push(new Greeter(restGreetings[i])); + + ~~~~~ => Pos: (648 to 652) SpanInfo: {"start":639,"length":13} + >greeters.push + >:=> (line 25, col 12) to (line 25, col 25) +25 > greeters.push(new Greeter(restGreetings[i])); + + ~~~~ => Pos: (653 to 656) SpanInfo: undefined +25 > greeters.push(new Greeter(restGreetings[i])); + + ~~~~~~~~ => Pos: (657 to 664) SpanInfo: {"start":657,"length":7} + >Greeter + >:=> (line 25, col 30) to (line 25, col 37) +25 > greeters.push(new Greeter(restGreetings[i])); + + ~~~~~~~~~~~~~~=> Pos: (665 to 678) SpanInfo: {"start":665,"length":13} + >restGreetings + >:=> (line 25, col 38) to (line 25, col 51) +25 > greeters.push(new Greeter(restGreetings[i])); + + ~~=> Pos: (679 to 680) SpanInfo: {"start":679,"length":1} + >i + >:=> (line 25, col 52) to (line 25, col 53) +25 > greeters.push(new Greeter(restGreetings[i])); + + ~~~~=> Pos: (681 to 684) SpanInfo: undefined +-------------------------------- +26 > } + + ~~~~~~~~~~ => Pos: (685 to 694) SpanInfo: undefined +-------------------------------- +27 > + + ~ => Pos: (695 to 695) SpanInfo: undefined +-------------------------------- +28 > return greeters; + + ~~~~~~~~~~~~~~~ => Pos: (696 to 710) SpanInfo: undefined +28 > return greeters; + + ~~~~~~~~~ => Pos: (711 to 719) SpanInfo: {"start":711,"length":8} + >greeters + >:=> (line 28, col 15) to (line 28, col 23) +28 > return greeters; + + ~ => Pos: (720 to 720) SpanInfo: undefined +-------------------------------- +29 > } + + ~~~~~~ => Pos: (721 to 726) SpanInfo: undefined +-------------------------------- +30 > + + ~ => Pos: (727 to 727) SpanInfo: undefined +-------------------------------- +31 > var b = foo2("Hello", "World", "!"); + + ~~~~~~~~ => Pos: (728 to 735) SpanInfo: undefined +31 > var b = foo2("Hello", "World", "!"); + + ~~ => Pos: (736 to 737) SpanInfo: {"start":736,"length":1} + >b + >:=> (line 31, col 8) to (line 31, col 9) +31 > var b = foo2("Hello", "World", "!"); + + ~~ => Pos: (738 to 739) SpanInfo: undefined +31 > var b = foo2("Hello", "World", "!"); + + ~~~~~ => Pos: (740 to 744) SpanInfo: {"start":740,"length":4} + >foo2 + >:=> (line 31, col 12) to (line 31, col 16) +31 > var b = foo2("Hello", "World", "!"); + + ~~~~~~~~ => Pos: (745 to 752) SpanInfo: {"start":745,"length":7} + >"Hello" + >:=> (line 31, col 17) to (line 31, col 24) +31 > var b = foo2("Hello", "World", "!"); + + ~ => Pos: (753 to 753) SpanInfo: undefined +31 > var b = foo2("Hello", "World", "!"); + + ~~~~~~~~ => Pos: (754 to 761) SpanInfo: {"start":754,"length":7} + >"World" + >:=> (line 31, col 26) to (line 31, col 33) +31 > var b = foo2("Hello", "World", "!"); + + ~ => Pos: (762 to 762) SpanInfo: undefined +31 > var b = foo2("Hello", "World", "!"); + + ~~~~ => Pos: (763 to 766) SpanInfo: {"start":763,"length":3} + >"!" + >:=> (line 31, col 35) to (line 31, col 38) +31 > var b = foo2("Hello", "World", "!"); + + ~~ => Pos: (767 to 768) SpanInfo: undefined +-------------------------------- +32 > // This is simple signle line comment + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (769 to 810) SpanInfo: undefined +-------------------------------- +33 > for (var j = 0; j < b.length; j++) { + + ~~~~~~~~~~~~~ => Pos: (811 to 823) SpanInfo: undefined +33 > for (var j = 0; j < b.length; j++) { + + ~~ => Pos: (824 to 825) SpanInfo: {"start":824,"length":1} + >j + >:=> (line 33, col 13) to (line 33, col 14) +33 > for (var j = 0; j < b.length; j++) { + + ~~~~~ => Pos: (826 to 830) SpanInfo: undefined +33 > for (var j = 0; j < b.length; j++) { + + ~~ => Pos: (831 to 832) SpanInfo: {"start":831,"length":1} + >j + >:=> (line 33, col 20) to (line 33, col 21) +33 > for (var j = 0; j < b.length; j++) { + + ~~ => Pos: (833 to 834) SpanInfo: undefined +33 > for (var j = 0; j < b.length; j++) { + + ~~ => Pos: (835 to 836) SpanInfo: {"start":835,"length":1} + >b + >:=> (line 33, col 24) to (line 33, col 25) +33 > for (var j = 0; j < b.length; j++) { + + ~~~~~~~ => Pos: (837 to 843) SpanInfo: {"start":835,"length":8} + >b.length + >:=> (line 33, col 24) to (line 33, col 32) +33 > for (var j = 0; j < b.length; j++) { + + ~ => Pos: (844 to 844) SpanInfo: undefined +33 > for (var j = 0; j < b.length; j++) { + + ~~ => Pos: (845 to 846) SpanInfo: {"start":845,"length":1} + >j + >:=> (line 33, col 34) to (line 33, col 35) +33 > for (var j = 0; j < b.length; j++) { + + ~~~~~ => Pos: (847 to 851) SpanInfo: undefined +-------------------------------- +34 > b[j].greet(); + + ~~~~~~~~ => Pos: (852 to 859) SpanInfo: undefined +34 > b[j].greet(); + + ~~ => Pos: (860 to 861) SpanInfo: {"start":860,"length":1} + >b + >:=> (line 34, col 8) to (line 34, col 9) +34 > b[j].greet(); + + ~~ => Pos: (862 to 863) SpanInfo: {"start":862,"length":1} + >j + >:=> (line 34, col 10) to (line 34, col 11) +34 > b[j].greet(); + + ~ => Pos: (864 to 864) SpanInfo: undefined +34 > b[j].greet(); + + ~~~~~~ => Pos: (865 to 870) SpanInfo: {"start":860,"length":10} + >b[j].greet + >:=> (line 34, col 8) to (line 34, col 18) +34 > b[j].greet(); + + ~~~ => Pos: (871 to 873) SpanInfo: undefined +-------------------------------- +35 > } + + ~~~~~~ => Pos: (874 to 879) SpanInfo: undefined +-------------------------------- +36 >} + ~ => Pos: (880 to 880) SpanInfo: undefined \ No newline at end of file diff --git a/tests/baselines/reference/nameOrDottedSpan_stmts.baseline b/tests/baselines/reference/nameOrDottedSpan_stmts.baseline new file mode 100644 index 00000000000..d0d35199e81 --- /dev/null +++ b/tests/baselines/reference/nameOrDottedSpan_stmts.baseline @@ -0,0 +1,884 @@ + +1 >function f() { + + ~~~~~~~~~ => Pos: (0 to 8) SpanInfo: undefined +1 >function f() { + + ~~ => Pos: (9 to 10) SpanInfo: {"start":9,"length":1} + >f + >:=> (line 1, col 9) to (line 1, col 10) +1 >function f() { + + ~~~~ => Pos: (11 to 14) SpanInfo: undefined +-------------------------------- +2 > var y; + + ~~~~~~~~ => Pos: (15 to 22) SpanInfo: undefined +2 > var y; + + ~~ => Pos: (23 to 24) SpanInfo: {"start":23,"length":1} + >y + >:=> (line 2, col 8) to (line 2, col 9) +2 > var y; + + ~ => Pos: (25 to 25) SpanInfo: undefined +-------------------------------- +3 > var x = 0; + + ~~~~~~~~ => Pos: (26 to 33) SpanInfo: undefined +3 > var x = 0; + + ~~ => Pos: (34 to 35) SpanInfo: {"start":34,"length":1} + >x + >:=> (line 3, col 8) to (line 3, col 9) +3 > var x = 0; + + ~~~~~ => Pos: (36 to 40) SpanInfo: undefined +-------------------------------- +4 > for (var i = 0; i < 10; i++) { + + ~~~~~~~~~~~~~ => Pos: (41 to 53) SpanInfo: undefined +4 > for (var i = 0; i < 10; i++) { + + ~~ => Pos: (54 to 55) SpanInfo: {"start":54,"length":1} + >i + >:=> (line 4, col 13) to (line 4, col 14) +4 > for (var i = 0; i < 10; i++) { + + ~~~~~ => Pos: (56 to 60) SpanInfo: undefined +4 > for (var i = 0; i < 10; i++) { + + ~~ => Pos: (61 to 62) SpanInfo: {"start":61,"length":1} + >i + >:=> (line 4, col 20) to (line 4, col 21) +4 > for (var i = 0; i < 10; i++) { + + ~~~~~~ => Pos: (63 to 68) SpanInfo: undefined +4 > for (var i = 0; i < 10; i++) { + + ~~ => Pos: (69 to 70) SpanInfo: {"start":69,"length":1} + >i + >:=> (line 4, col 28) to (line 4, col 29) +4 > for (var i = 0; i < 10; i++) { + + ~~~~~ => Pos: (71 to 75) SpanInfo: undefined +-------------------------------- +5 > x += i; + + ~~~~~~~~ => Pos: (76 to 83) SpanInfo: undefined +5 > x += i; + + ~~ => Pos: (84 to 85) SpanInfo: {"start":84,"length":1} + >x + >:=> (line 5, col 8) to (line 5, col 9) +5 > x += i; + + ~~~ => Pos: (86 to 88) SpanInfo: undefined +5 > x += i; + + ~~ => Pos: (89 to 90) SpanInfo: {"start":89,"length":1} + >i + >:=> (line 5, col 13) to (line 5, col 14) +5 > x += i; + + ~ => Pos: (91 to 91) SpanInfo: undefined +-------------------------------- +6 > x *= 0; + + ~~~~~~~~ => Pos: (92 to 99) SpanInfo: undefined +6 > x *= 0; + + ~~ => Pos: (100 to 101) SpanInfo: {"start":100,"length":1} + >x + >:=> (line 6, col 8) to (line 6, col 9) +6 > x *= 0; + + ~~~~~~ => Pos: (102 to 107) SpanInfo: undefined +-------------------------------- +7 > } + + ~~~~~~ => Pos: (108 to 113) SpanInfo: undefined +-------------------------------- +8 > if (x > 17) { + + ~~~~~~~~ => Pos: (114 to 121) SpanInfo: undefined +8 > if (x > 17) { + + ~~ => Pos: (122 to 123) SpanInfo: {"start":122,"length":1} + >x + >:=> (line 8, col 8) to (line 8, col 9) +8 > if (x > 17) { + + ~~~~~~~~ => Pos: (124 to 131) SpanInfo: undefined +-------------------------------- +9 > x /= 9; + + ~~~~~~~~ => Pos: (132 to 139) SpanInfo: undefined +9 > x /= 9; + + ~~ => Pos: (140 to 141) SpanInfo: {"start":140,"length":1} + >x + >:=> (line 9, col 8) to (line 9, col 9) +9 > x /= 9; + + ~~~~~~ => Pos: (142 to 147) SpanInfo: undefined +-------------------------------- +10 > } else { + + ~~~~~~~~~~~~~ => Pos: (148 to 160) SpanInfo: undefined +-------------------------------- +11 > x += 10; + + ~~~~~~~~ => Pos: (161 to 168) SpanInfo: undefined +11 > x += 10; + + ~~ => Pos: (169 to 170) SpanInfo: {"start":169,"length":1} + >x + >:=> (line 11, col 8) to (line 11, col 9) +11 > x += 10; + + ~~~~~~~ => Pos: (171 to 177) SpanInfo: undefined +-------------------------------- +12 > x++; + + ~~~~~~~~ => Pos: (178 to 185) SpanInfo: undefined +12 > x++; + + ~~ => Pos: (186 to 187) SpanInfo: {"start":186,"length":1} + >x + >:=> (line 12, col 8) to (line 12, col 9) +12 > x++; + + ~~~ => Pos: (188 to 190) SpanInfo: undefined +-------------------------------- +13 > } + + ~~~~~~ => Pos: (191 to 196) SpanInfo: undefined +-------------------------------- +14 > var a = [ + + ~~~~~~~~ => Pos: (197 to 204) SpanInfo: undefined +14 > var a = [ + + ~~ => Pos: (205 to 206) SpanInfo: {"start":205,"length":1} + >a + >:=> (line 14, col 8) to (line 14, col 9) +14 > var a = [ + + ~~~~ => Pos: (207 to 210) SpanInfo: undefined +-------------------------------- +15 > 1, + + ~~~~~~~~~~~ => Pos: (211 to 221) SpanInfo: undefined +-------------------------------- +16 > 2, + + ~~~~~~~~~~~ => Pos: (222 to 232) SpanInfo: undefined +-------------------------------- +17 > 3 + + ~~~~~~~~~~ => Pos: (233 to 242) SpanInfo: undefined +-------------------------------- +18 > ]; + + ~~~~~~~ => Pos: (243 to 249) SpanInfo: undefined +-------------------------------- +19 > var obj = { + + ~~~~~~~~ => Pos: (250 to 257) SpanInfo: undefined +19 > var obj = { + + ~~~~ => Pos: (258 to 261) SpanInfo: {"start":258,"length":3} + >obj + >:=> (line 19, col 8) to (line 19, col 11) +19 > var obj = { + + ~~~~ => Pos: (262 to 265) SpanInfo: undefined +-------------------------------- +20 > z: 1, + + ~~~~~~~~ => Pos: (266 to 273) SpanInfo: undefined +20 > z: 1, + + ~~ => Pos: (274 to 275) SpanInfo: {"start":274,"length":1} + >z + >:=> (line 20, col 8) to (line 20, col 9) +20 > z: 1, + + ~~~~ => Pos: (276 to 279) SpanInfo: undefined +-------------------------------- +21 > q: "hello" + + ~~~~~~~~ => Pos: (280 to 287) SpanInfo: undefined +21 > q: "hello" + + ~~ => Pos: (288 to 289) SpanInfo: {"start":288,"length":1} + >q + >:=> (line 21, col 8) to (line 21, col 9) +21 > q: "hello" + + ~ => Pos: (290 to 290) SpanInfo: undefined +21 > q: "hello" + + ~~~~~~~~ => Pos: (291 to 298) SpanInfo: {"start":291,"length":7} + >"hello" + >:=> (line 21, col 11) to (line 21, col 18) +-------------------------------- +22 > }; + + ~~~~~~~ => Pos: (299 to 305) SpanInfo: undefined +-------------------------------- +23 > for (var j in a) { + + ~~~~~~~~~~~~~ => Pos: (306 to 318) SpanInfo: undefined +23 > for (var j in a) { + + ~~ => Pos: (319 to 320) SpanInfo: {"start":319,"length":1} + >j + >:=> (line 23, col 13) to (line 23, col 14) +23 > for (var j in a) { + + ~~~ => Pos: (321 to 323) SpanInfo: undefined +23 > for (var j in a) { + + ~~ => Pos: (324 to 325) SpanInfo: {"start":324,"length":1} + >a + >:=> (line 23, col 18) to (line 23, col 19) +23 > for (var j in a) { + + ~~~ => Pos: (326 to 328) SpanInfo: undefined +-------------------------------- +24 > obj.z = a[j]; + + ~~~~~~~~ => Pos: (329 to 336) SpanInfo: undefined +24 > obj.z = a[j]; + + ~~~~ => Pos: (337 to 340) SpanInfo: {"start":337,"length":3} + >obj + >:=> (line 24, col 8) to (line 24, col 11) +24 > obj.z = a[j]; + + ~~ => Pos: (341 to 342) SpanInfo: {"start":337,"length":5} + >obj.z + >:=> (line 24, col 8) to (line 24, col 13) +24 > obj.z = a[j]; + + ~~ => Pos: (343 to 344) SpanInfo: undefined +24 > obj.z = a[j]; + + ~~ => Pos: (345 to 346) SpanInfo: {"start":345,"length":1} + >a + >:=> (line 24, col 16) to (line 24, col 17) +24 > obj.z = a[j]; + + ~~ => Pos: (347 to 348) SpanInfo: {"start":347,"length":1} + >j + >:=> (line 24, col 18) to (line 24, col 19) +24 > obj.z = a[j]; + + ~~ => Pos: (349 to 350) SpanInfo: undefined +-------------------------------- +25 > var v = 10; + + ~~~~~~~~~~~~ => Pos: (351 to 362) SpanInfo: undefined +25 > var v = 10; + + ~~ => Pos: (363 to 364) SpanInfo: {"start":363,"length":1} + >v + >:=> (line 25, col 12) to (line 25, col 13) +25 > var v = 10; + + ~~~~~~ => Pos: (365 to 370) SpanInfo: undefined +-------------------------------- +26 > } + + ~~~~~~ => Pos: (371 to 376) SpanInfo: undefined +-------------------------------- +27 > try { + + ~~~~~~~~~~ => Pos: (377 to 386) SpanInfo: undefined +-------------------------------- +28 > obj.q = "ohhh"; + + ~~~~~~~~ => Pos: (387 to 394) SpanInfo: undefined +28 > obj.q = "ohhh"; + + ~~~~ => Pos: (395 to 398) SpanInfo: {"start":395,"length":3} + >obj + >:=> (line 28, col 8) to (line 28, col 11) +28 > obj.q = "ohhh"; + + ~~ => Pos: (399 to 400) SpanInfo: {"start":395,"length":5} + >obj.q + >:=> (line 28, col 8) to (line 28, col 13) +28 > obj.q = "ohhh"; + + ~~ => Pos: (401 to 402) SpanInfo: undefined +28 > obj.q = "ohhh"; + + ~~~~~~~ => Pos: (403 to 409) SpanInfo: {"start":403,"length":6} + >"ohhh" + >:=> (line 28, col 16) to (line 28, col 22) +28 > obj.q = "ohhh"; + + ~ => Pos: (410 to 410) SpanInfo: undefined +-------------------------------- +29 > } catch (e) { + + ~~~~~~~~~~~~~ => Pos: (411 to 423) SpanInfo: undefined +29 > } catch (e) { + + ~~ => Pos: (424 to 425) SpanInfo: {"start":424,"length":1} + >e + >:=> (line 29, col 13) to (line 29, col 14) +29 > } catch (e) { + + ~~~ => Pos: (426 to 428) SpanInfo: undefined +-------------------------------- +30 > if (obj.z < 10) { + + ~~~~~~~~~~~~ => Pos: (429 to 440) SpanInfo: undefined +30 > if (obj.z < 10) { + + ~~~~ => Pos: (441 to 444) SpanInfo: {"start":441,"length":3} + >obj + >:=> (line 30, col 12) to (line 30, col 15) +30 > if (obj.z < 10) { + + ~~ => Pos: (445 to 446) SpanInfo: {"start":441,"length":5} + >obj.z + >:=> (line 30, col 12) to (line 30, col 17) +30 > if (obj.z < 10) { + + ~~~~~~~~ => Pos: (447 to 454) SpanInfo: undefined +-------------------------------- +31 > obj.z = 12; + + ~~~~~~~~~~~~ => Pos: (455 to 466) SpanInfo: undefined +31 > obj.z = 12; + + ~~~~ => Pos: (467 to 470) SpanInfo: {"start":467,"length":3} + >obj + >:=> (line 31, col 12) to (line 31, col 15) +31 > obj.z = 12; + + ~~ => Pos: (471 to 472) SpanInfo: {"start":467,"length":5} + >obj.z + >:=> (line 31, col 12) to (line 31, col 17) +31 > obj.z = 12; + + ~~~~~~ => Pos: (473 to 478) SpanInfo: undefined +-------------------------------- +32 > } else { + + ~~~~~~~~~~~~~~~~~ => Pos: (479 to 495) SpanInfo: undefined +-------------------------------- +33 > obj.q = "hmm"; + + ~~~~~~~~~~~~ => Pos: (496 to 507) SpanInfo: undefined +33 > obj.q = "hmm"; + + ~~~~ => Pos: (508 to 511) SpanInfo: {"start":508,"length":3} + >obj + >:=> (line 33, col 12) to (line 33, col 15) +33 > obj.q = "hmm"; + + ~~ => Pos: (512 to 513) SpanInfo: {"start":508,"length":5} + >obj.q + >:=> (line 33, col 12) to (line 33, col 17) +33 > obj.q = "hmm"; + + ~~ => Pos: (514 to 515) SpanInfo: undefined +33 > obj.q = "hmm"; + + ~~~~~~ => Pos: (516 to 521) SpanInfo: {"start":516,"length":5} + >"hmm" + >:=> (line 33, col 20) to (line 33, col 25) +33 > obj.q = "hmm"; + + ~ => Pos: (522 to 522) SpanInfo: undefined +-------------------------------- +34 > } + + ~~~~~~~~~~ => Pos: (523 to 532) SpanInfo: undefined +-------------------------------- +35 > } + + ~~~~~~ => Pos: (533 to 538) SpanInfo: undefined +-------------------------------- +36 > try { + + ~~~~~~~~~~ => Pos: (539 to 548) SpanInfo: undefined +-------------------------------- +37 > throw new Error(); + + ~~~~~~~~~~~~~~~~~~ => Pos: (549 to 566) SpanInfo: undefined +37 > throw new Error(); + + ~~~~~~ => Pos: (567 to 572) SpanInfo: {"start":567,"length":5} + >Error + >:=> (line 37, col 18) to (line 37, col 23) +37 > throw new Error(); + + ~~~ => Pos: (573 to 575) SpanInfo: undefined +-------------------------------- +38 > } catch (e1) { + + ~~~~~~~~~~~~~ => Pos: (576 to 588) SpanInfo: undefined +38 > } catch (e1) { + + ~~~ => Pos: (589 to 591) SpanInfo: {"start":589,"length":2} + >e1 + >:=> (line 38, col 13) to (line 38, col 15) +38 > } catch (e1) { + + ~~~ => Pos: (592 to 594) SpanInfo: undefined +-------------------------------- +39 > var b = e1; + + ~~~~~~~~~~~~ => Pos: (595 to 606) SpanInfo: undefined +39 > var b = e1; + + ~~ => Pos: (607 to 608) SpanInfo: {"start":607,"length":1} + >b + >:=> (line 39, col 12) to (line 39, col 13) +39 > var b = e1; + + ~~ => Pos: (609 to 610) SpanInfo: undefined +39 > var b = e1; + + ~~~ => Pos: (611 to 613) SpanInfo: {"start":611,"length":2} + >e1 + >:=> (line 39, col 16) to (line 39, col 18) +39 > var b = e1; + + ~ => Pos: (614 to 614) SpanInfo: undefined +-------------------------------- +40 > } finally { + + ~~~~~~~~~~~~~~~~ => Pos: (615 to 630) SpanInfo: undefined +-------------------------------- +41 > y = 70; + + ~~~~~~~~ => Pos: (631 to 638) SpanInfo: undefined +41 > y = 70; + + ~~ => Pos: (639 to 640) SpanInfo: {"start":639,"length":1} + >y + >:=> (line 41, col 8) to (line 41, col 9) +41 > y = 70; + + ~~~~~~ => Pos: (641 to 646) SpanInfo: undefined +-------------------------------- +42 > } + + ~~~~~~ => Pos: (647 to 652) SpanInfo: undefined +-------------------------------- +43 > with (obj) { + + ~~~~~~~~~~ => Pos: (653 to 662) SpanInfo: undefined +43 > with (obj) { + + ~~~~ => Pos: (663 to 666) SpanInfo: {"start":663,"length":3} + >obj + >:=> (line 43, col 10) to (line 43, col 13) +43 > with (obj) { + + ~~~ => Pos: (667 to 669) SpanInfo: undefined +-------------------------------- +44 > i = 2; + + ~~~~~~~~ => Pos: (670 to 677) SpanInfo: undefined +44 > i = 2; + + ~~ => Pos: (678 to 679) SpanInfo: {"start":678,"length":1} + >i + >:=> (line 44, col 8) to (line 44, col 9) +44 > i = 2; + + ~~~~~ => Pos: (680 to 684) SpanInfo: undefined +-------------------------------- +45 > z = 10; + + ~~~~~~~~ => Pos: (685 to 692) SpanInfo: undefined +45 > z = 10; + + ~~ => Pos: (693 to 694) SpanInfo: {"start":693,"length":1} + >z + >:=> (line 45, col 8) to (line 45, col 9) +45 > z = 10; + + ~~~~~~ => Pos: (695 to 700) SpanInfo: undefined +-------------------------------- +46 > } + + ~~~~~~ => Pos: (701 to 706) SpanInfo: undefined +-------------------------------- +47 > switch (obj.z) { + + ~~~~~~~~~~~~ => Pos: (707 to 718) SpanInfo: undefined +47 > switch (obj.z) { + + ~~~~ => Pos: (719 to 722) SpanInfo: {"start":719,"length":3} + >obj + >:=> (line 47, col 12) to (line 47, col 15) +47 > switch (obj.z) { + + ~~ => Pos: (723 to 724) SpanInfo: {"start":719,"length":5} + >obj.z + >:=> (line 47, col 12) to (line 47, col 17) +47 > switch (obj.z) { + + ~~~ => Pos: (725 to 727) SpanInfo: undefined +-------------------------------- +48 > case 0: { + + ~~~~~~~~~~~~~~~~~~ => Pos: (728 to 745) SpanInfo: undefined +-------------------------------- +49 > x++; + + ~~~~~~~~~~~~ => Pos: (746 to 757) SpanInfo: undefined +49 > x++; + + ~~ => Pos: (758 to 759) SpanInfo: {"start":758,"length":1} + >x + >:=> (line 49, col 12) to (line 49, col 13) +49 > x++; + + ~~~ => Pos: (760 to 762) SpanInfo: undefined +-------------------------------- +50 > break; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (763 to 781) SpanInfo: undefined +-------------------------------- +51 > + + ~ => Pos: (782 to 782) SpanInfo: undefined +-------------------------------- +52 > } + + ~~~~~~~~~~ => Pos: (783 to 792) SpanInfo: undefined +-------------------------------- +53 > case 1: { + + ~~~~~~~~~~~~~~~~~~ => Pos: (793 to 810) SpanInfo: undefined +-------------------------------- +54 > x--; + + ~~~~~~~~~~~~ => Pos: (811 to 822) SpanInfo: undefined +54 > x--; + + ~~ => Pos: (823 to 824) SpanInfo: {"start":823,"length":1} + >x + >:=> (line 54, col 12) to (line 54, col 13) +54 > x--; + + ~~~ => Pos: (825 to 827) SpanInfo: undefined +-------------------------------- +55 > break; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (828 to 846) SpanInfo: undefined +-------------------------------- +56 > + + ~ => Pos: (847 to 847) SpanInfo: undefined +-------------------------------- +57 > } + + ~~~~~~~~~~ => Pos: (848 to 857) SpanInfo: undefined +-------------------------------- +58 > default: { + + ~~~~~~~~~~~~~~~~~~~ => Pos: (858 to 876) SpanInfo: undefined +-------------------------------- +59 > x *= 2; + + ~~~~~~~~~~~~ => Pos: (877 to 888) SpanInfo: undefined +59 > x *= 2; + + ~~ => Pos: (889 to 890) SpanInfo: {"start":889,"length":1} + >x + >:=> (line 59, col 12) to (line 59, col 13) +59 > x *= 2; + + ~~~~~~ => Pos: (891 to 896) SpanInfo: undefined +-------------------------------- +60 > x = 50; + + ~~~~~~~~~~~~ => Pos: (897 to 908) SpanInfo: undefined +60 > x = 50; + + ~~ => Pos: (909 to 910) SpanInfo: {"start":909,"length":1} + >x + >:=> (line 60, col 12) to (line 60, col 13) +60 > x = 50; + + ~~~~~~ => Pos: (911 to 916) SpanInfo: undefined +-------------------------------- +61 > break; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (917 to 935) SpanInfo: undefined +-------------------------------- +62 > + + ~ => Pos: (936 to 936) SpanInfo: undefined +-------------------------------- +63 > } + + ~~~~~~~~~~ => Pos: (937 to 946) SpanInfo: undefined +-------------------------------- +64 > } + + ~~~~~~ => Pos: (947 to 952) SpanInfo: undefined +-------------------------------- +65 > while (x < 10) { + + ~~~~~~~~~~~ => Pos: (953 to 963) SpanInfo: undefined +65 > while (x < 10) { + + ~~ => Pos: (964 to 965) SpanInfo: {"start":964,"length":1} + >x + >:=> (line 65, col 11) to (line 65, col 12) +65 > while (x < 10) { + + ~~~~~~~~ => Pos: (966 to 973) SpanInfo: undefined +-------------------------------- +66 > x++; + + ~~~~~~~~ => Pos: (974 to 981) SpanInfo: undefined +66 > x++; + + ~~ => Pos: (982 to 983) SpanInfo: {"start":982,"length":1} + >x + >:=> (line 66, col 8) to (line 66, col 9) +66 > x++; + + ~~~ => Pos: (984 to 986) SpanInfo: undefined +-------------------------------- +67 > } + + ~~~~~~ => Pos: (987 to 992) SpanInfo: undefined +-------------------------------- +68 > do { + + ~~~~~~~~~ => Pos: (993 to 1001) SpanInfo: undefined +-------------------------------- +69 > x--; + + ~~~~~~~~ => Pos: (1002 to 1009) SpanInfo: undefined +69 > x--; + + ~~ => Pos: (1010 to 1011) SpanInfo: {"start":1010,"length":1} + >x + >:=> (line 69, col 8) to (line 69, col 9) +69 > x--; + + ~~~ => Pos: (1012 to 1014) SpanInfo: undefined +-------------------------------- +70 > } while (x > 4) + + ~~~~~~~~~~~~~ => Pos: (1015 to 1027) SpanInfo: undefined +70 > } while (x > 4) + + ~~ => Pos: (1028 to 1029) SpanInfo: {"start":1028,"length":1} + >x + >:=> (line 70, col 13) to (line 70, col 14) +70 > } while (x > 4) + + ~~~~~ => Pos: (1030 to 1034) SpanInfo: undefined +-------------------------------- +71 > x = y; + + ~~~~ => Pos: (1035 to 1038) SpanInfo: undefined +71 > x = y; + + ~~ => Pos: (1039 to 1040) SpanInfo: {"start":1039,"length":1} + >x + >:=> (line 71, col 4) to (line 71, col 5) +71 > x = y; + + ~~ => Pos: (1041 to 1042) SpanInfo: undefined +71 > x = y; + + ~~ => Pos: (1043 to 1044) SpanInfo: {"start":1043,"length":1} + >y + >:=> (line 71, col 8) to (line 71, col 9) +71 > x = y; + + ~ => Pos: (1045 to 1045) SpanInfo: undefined +-------------------------------- +72 > var z = (x == 1) ? x + 1 : x - 1; + + ~~~~~~~~ => Pos: (1046 to 1053) SpanInfo: undefined +72 > var z = (x == 1) ? x + 1 : x - 1; + + ~~ => Pos: (1054 to 1055) SpanInfo: {"start":1054,"length":1} + >z + >:=> (line 72, col 8) to (line 72, col 9) +72 > var z = (x == 1) ? x + 1 : x - 1; + + ~~~ => Pos: (1056 to 1058) SpanInfo: undefined +72 > var z = (x == 1) ? x + 1 : x - 1; + + ~~ => Pos: (1059 to 1060) SpanInfo: {"start":1059,"length":1} + >x + >:=> (line 72, col 13) to (line 72, col 14) +72 > var z = (x == 1) ? x + 1 : x - 1; + + ~~~~~~~~ => Pos: (1061 to 1068) SpanInfo: undefined +72 > var z = (x == 1) ? x + 1 : x - 1; + + ~~ => Pos: (1069 to 1070) SpanInfo: {"start":1069,"length":1} + >x + >:=> (line 72, col 23) to (line 72, col 24) +72 > var z = (x == 1) ? x + 1 : x - 1; + + ~~~~~~ => Pos: (1071 to 1076) SpanInfo: undefined +72 > var z = (x == 1) ? x + 1 : x - 1; + + ~~ => Pos: (1077 to 1078) SpanInfo: {"start":1077,"length":1} + >x + >:=> (line 72, col 31) to (line 72, col 32) +72 > var z = (x == 1) ? x + 1 : x - 1; + + ~~~~~ => Pos: (1079 to 1083) SpanInfo: undefined +-------------------------------- +73 > (x == 1) ? x + 1 : x - 1; + + ~~~~~ => Pos: (1084 to 1088) SpanInfo: undefined +73 > (x == 1) ? x + 1 : x - 1; + + ~~ => Pos: (1089 to 1090) SpanInfo: {"start":1089,"length":1} + >x + >:=> (line 73, col 5) to (line 73, col 6) +73 > (x == 1) ? x + 1 : x - 1; + + ~~~~~~~~ => Pos: (1091 to 1098) SpanInfo: undefined +73 > (x == 1) ? x + 1 : x - 1; + + ~~ => Pos: (1099 to 1100) SpanInfo: {"start":1099,"length":1} + >x + >:=> (line 73, col 15) to (line 73, col 16) +73 > (x == 1) ? x + 1 : x - 1; + + ~~~~~~ => Pos: (1101 to 1106) SpanInfo: undefined +73 > (x == 1) ? x + 1 : x - 1; + + ~~ => Pos: (1107 to 1108) SpanInfo: {"start":1107,"length":1} + >x + >:=> (line 73, col 23) to (line 73, col 24) +73 > (x == 1) ? x + 1 : x - 1; + + ~~~~~ => Pos: (1109 to 1113) SpanInfo: undefined +-------------------------------- +74 > x === 1; + + ~~~~ => Pos: (1114 to 1117) SpanInfo: undefined +74 > x === 1; + + ~~ => Pos: (1118 to 1119) SpanInfo: {"start":1118,"length":1} + >x + >:=> (line 74, col 4) to (line 74, col 5) +74 > x === 1; + + ~~~~~~~ => Pos: (1120 to 1126) SpanInfo: undefined +-------------------------------- +75 > x = z = 40; + + ~~~~ => Pos: (1127 to 1130) SpanInfo: undefined +75 > x = z = 40; + + ~~ => Pos: (1131 to 1132) SpanInfo: {"start":1131,"length":1} + >x + >:=> (line 75, col 4) to (line 75, col 5) +75 > x = z = 40; + + ~~ => Pos: (1133 to 1134) SpanInfo: undefined +75 > x = z = 40; + + ~~ => Pos: (1135 to 1136) SpanInfo: {"start":1135,"length":1} + >z + >:=> (line 75, col 8) to (line 75, col 9) +75 > x = z = 40; + + ~~~~~~ => Pos: (1137 to 1142) SpanInfo: undefined +-------------------------------- +76 > eval("y"); + + ~~~~ => Pos: (1143 to 1146) SpanInfo: undefined +76 > eval("y"); + + ~~~~~ => Pos: (1147 to 1151) SpanInfo: {"start":1147,"length":4} + >eval + >:=> (line 76, col 4) to (line 76, col 8) +76 > eval("y"); + + ~~~~ => Pos: (1152 to 1155) SpanInfo: {"start":1152,"length":3} + >"y" + >:=> (line 76, col 9) to (line 76, col 12) +76 > eval("y"); + + ~~ => Pos: (1156 to 1157) SpanInfo: undefined +-------------------------------- +77 > return; + + ~~~~~~~~~~~~ => Pos: (1158 to 1169) SpanInfo: undefined +-------------------------------- +78 >} + + ~~ => Pos: (1170 to 1171) SpanInfo: undefined +-------------------------------- +79 >var b = function () { + + ~~~~ => Pos: (1172 to 1175) SpanInfo: undefined +79 >var b = function () { + + ~~ => Pos: (1176 to 1177) SpanInfo: {"start":1176,"length":1} + >b + >:=> (line 79, col 4) to (line 79, col 5) +79 >var b = function () { + + ~~~~~~~~~~~~~~~~ => Pos: (1178 to 1193) SpanInfo: undefined +-------------------------------- +80 > var x = 10; + + ~~~~~~~~ => Pos: (1194 to 1201) SpanInfo: undefined +80 > var x = 10; + + ~~ => Pos: (1202 to 1203) SpanInfo: {"start":1202,"length":1} + >x + >:=> (line 80, col 8) to (line 80, col 9) +80 > var x = 10; + + ~~~~~~ => Pos: (1204 to 1209) SpanInfo: undefined +-------------------------------- +81 > x = x + 1; + + ~~~~ => Pos: (1210 to 1213) SpanInfo: undefined +81 > x = x + 1; + + ~~ => Pos: (1214 to 1215) SpanInfo: {"start":1214,"length":1} + >x + >:=> (line 81, col 4) to (line 81, col 5) +81 > x = x + 1; + + ~~ => Pos: (1216 to 1217) SpanInfo: undefined +81 > x = x + 1; + + ~~ => Pos: (1218 to 1219) SpanInfo: {"start":1218,"length":1} + >x + >:=> (line 81, col 8) to (line 81, col 9) +81 > x = x + 1; + + ~~~~~ => Pos: (1220 to 1224) SpanInfo: undefined +-------------------------------- +82 >}; + + ~~~ => Pos: (1225 to 1227) SpanInfo: undefined +-------------------------------- +83 >f(); + ~~ => Pos: (1228 to 1229) SpanInfo: {"start":1228,"length":1} + >f + >:=> (line 83, col 0) to (line 83, col 1) +83 >f(); + ~~ => Pos: (1230 to 1231) SpanInfo: undefined \ No newline at end of file diff --git a/tests/cases/fourslash_old/nameOrDottedNameClasses.ts b/tests/cases/fourslash/nameOrDottedNameClasses.ts similarity index 100% rename from tests/cases/fourslash_old/nameOrDottedNameClasses.ts rename to tests/cases/fourslash/nameOrDottedNameClasses.ts diff --git a/tests/cases/fourslash_old/nameOrDottedNameStatements.ts b/tests/cases/fourslash/nameOrDottedNameStatements.ts similarity index 100% rename from tests/cases/fourslash_old/nameOrDottedNameStatements.ts rename to tests/cases/fourslash/nameOrDottedNameStatements.ts diff --git a/tests/cases/fourslash_old/nameOrDottedName_Classes.ts b/tests/cases/fourslash_old/nameOrDottedName_Classes.ts deleted file mode 100644 index 9aa63a7a473..00000000000 --- a/tests/cases/fourslash_old/nameOrDottedName_Classes.ts +++ /dev/null @@ -1,43 +0,0 @@ -/// - -// @BaselineFile: nameOrDottedSpan_classes.baseline -// @Filename: nameOrDottedSpan_classes.ts -////module Foo.Bar { -//// "use strict"; -//// -//// class Greeter { -//// constructor(public greeting: string) { -//// } -//// -//// greet() { -//// return "

" + this.greeting + "

"; -//// } -//// } -//// -//// -//// function foo(greeting: string): Greeter { -//// return new Greeter(greeting); -//// } -//// -//// var greeter = new Greeter("Hello, world!"); -//// var str = greeter.greet(); -//// -//// function foo2(greeting: string, ...restGreetings /* more greeting */: string[]) { -//// var greeters: Greeter[] = []; /* inline block comment */ -//// greeters[0] = new Greeter(greeting); -//// for (var i = 0; i < restGreetings.length; i++) { -//// greeters.push(new Greeter(restGreetings[i])); -//// } -//// -//// return greeters; -//// } -//// -//// var b = foo2("Hello", "World", "!"); -//// // This is simple signle line comment -//// for (var j = 0; j < b.length; j++) { -//// b[j].greet(); -//// } -////} - - -verify.baselineCurrentFileNameOrDottedNameSpans(); \ No newline at end of file diff --git a/tests/cases/fourslash_old/nameOrDottedName_Statements.ts b/tests/cases/fourslash_old/nameOrDottedName_Statements.ts deleted file mode 100644 index 52c9c30a75d..00000000000 --- a/tests/cases/fourslash_old/nameOrDottedName_Statements.ts +++ /dev/null @@ -1,90 +0,0 @@ -/// - -// @BaselineFile: nameOrDottedSpan_stmts.baseline -// @Filename: nameOrDottedSpan_stmts.ts -////function f() { -//// var y; -//// var x = 0; -//// for (var i = 0; i < 10; i++) { -//// x += i; -//// x *= 0; -//// } -//// if (x > 17) { -//// x /= 9; -//// } else { -//// x += 10; -//// x++; -//// } -//// var a = [ -//// 1, -//// 2, -//// 3 -//// ]; -//// var obj = { -//// z: 1, -//// q: "hello" -//// }; -//// for (var j in a) { -//// obj.z = a[j]; -//// var v = 10; -//// } -//// try { -//// obj.q = "ohhh"; -//// } catch (e) { -//// if (obj.z < 10) { -//// obj.z = 12; -//// } else { -//// obj.q = "hmm"; -//// } -//// } -//// try { -//// throw new Error(); -//// } catch (e1) { -//// var b = e1; -//// } finally { -//// y = 70; -//// } -//// with (obj) { -//// i = 2; -//// z = 10; -//// } -//// switch (obj.z) { -//// case 0: { -//// x++; -//// break; -//// -//// } -//// case 1: { -//// x--; -//// break; -//// -//// } -//// default: { -//// x *= 2; -//// x = 50; -//// break; -//// -//// } -//// } -//// while (x < 10) { -//// x++; -//// } -//// do { -//// x--; -//// } while (x > 4) -//// x = y; -//// var z = (x == 1) ? x + 1 : x - 1; -//// (x == 1) ? x + 1 : x - 1; -//// x === 1; -//// x = z = 40; -//// eval("y"); -//// return; -////} -////var b = function () { -//// var x = 10; -//// x = x + 1; -////}; -////f(); - - -verify.baselineCurrentFileNameOrDottedNameSpans(); \ No newline at end of file From 933680b242a7ba0aed2ce758e100071a28e0a705 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 21 Oct 2014 10:25:55 -0700 Subject: [PATCH 47/63] Breakpoint validation in interfaces --- src/services/breakpoints.ts | 5 +- .../reference/bpSpan_interface.baseline | 93 +++++++++++++++++++ .../breakpointValidationInterface.ts | 29 ++++++ 3 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/bpSpan_interface.baseline create mode 100644 tests/cases/fourslash/breakpointValidationInterface.ts diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index a7527d92614..1bb1fafeb35 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -179,6 +179,10 @@ module ts.BreakpointResolver { case SyntaxKind.WithStatement: return spanInWithStatement(node); + // No breakpoint in interface + case SyntaxKind.InterfaceDeclaration: + return undefined; + // Tokens: case SyntaxKind.SemicolonToken: case SyntaxKind.EndOfFileToken: @@ -560,7 +564,6 @@ module ts.BreakpointResolver { return spanInNode(node.parent); } - function spanInWhileKeyword(node: Node): TypeScript.TextSpan { if (node.parent.kind === SyntaxKind.DoStatement) { // Set span on while expression diff --git a/tests/baselines/reference/bpSpan_interface.baseline b/tests/baselines/reference/bpSpan_interface.baseline new file mode 100644 index 00000000000..81d2bac4867 --- /dev/null +++ b/tests/baselines/reference/bpSpan_interface.baseline @@ -0,0 +1,93 @@ + +1 >interface I { + + ~~~~~~~~~~~~~~ => Pos: (0 to 13) SpanInfo: undefined +-------------------------------- +2 > property: string; + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (14 to 35) SpanInfo: undefined +-------------------------------- +3 > method(): number; + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (36 to 57) SpanInfo: undefined +-------------------------------- +4 > (a: string): string; + + ~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (58 to 82) SpanInfo: undefined +-------------------------------- +5 > new (a: string): I; + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (83 to 106) SpanInfo: undefined +-------------------------------- +6 > [a: number]: number; + + ~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (107 to 131) SpanInfo: undefined +-------------------------------- +7 >} + + ~~ => Pos: (132 to 133) SpanInfo: undefined +-------------------------------- +8 >module m { + + ~~~~~~~~~~~ => Pos: (134 to 144) SpanInfo: undefined +-------------------------------- +9 > interface I1 { + + ~~~~~~~~~~~~~~~~~~~ => Pos: (145 to 163) SpanInfo: undefined +-------------------------------- +10 > property: string; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (164 to 189) SpanInfo: undefined +-------------------------------- +11 > method(): number; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (190 to 215) SpanInfo: undefined +-------------------------------- +12 > (a: string): string; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (216 to 244) SpanInfo: undefined +-------------------------------- +13 > new (a: string): I; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (245 to 272) SpanInfo: undefined +-------------------------------- +14 > [a: number]: number; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (273 to 301) SpanInfo: undefined +-------------------------------- +15 > } + + ~~~~~~ => Pos: (302 to 307) SpanInfo: undefined +-------------------------------- +16 > export interface I2 { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (308 to 333) SpanInfo: undefined +-------------------------------- +17 > property: string; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (334 to 359) SpanInfo: undefined +-------------------------------- +18 > method(): number; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (360 to 385) SpanInfo: undefined +-------------------------------- +19 > (a: string): string; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (386 to 414) SpanInfo: undefined +-------------------------------- +20 > new (a: string): I; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (415 to 442) SpanInfo: undefined +-------------------------------- +21 > [a: number]: number; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (443 to 471) SpanInfo: undefined +-------------------------------- +22 > } + + ~~~~~~ => Pos: (472 to 477) SpanInfo: undefined +-------------------------------- +23 >} + ~ => Pos: (478 to 478) SpanInfo: {"start":478,"length":1} + >} + >:=> (line 23, col 0) to (line 23, col 1) \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationInterface.ts b/tests/cases/fourslash/breakpointValidationInterface.ts new file mode 100644 index 00000000000..07c34190fa8 --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationInterface.ts @@ -0,0 +1,29 @@ +/// + +// @BaselineFile: bpSpan_interface.baseline +// @Filename: bpSpan_interface.ts +////interface I { +//// property: string; +//// method(): number; +//// (a: string): string; +//// new (a: string): I; +//// [a: number]: number; +////} +////module m { +//// interface I1 { +//// property: string; +//// method(): number; +//// (a: string): string; +//// new (a: string): I; +//// [a: number]: number; +//// } +//// export interface I2 { +//// property: string; +//// method(): number; +//// (a: string): string; +//// new (a: string): I; +//// [a: number]: number; +//// } +////} + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file From 7a500fbf5e4238d93443b4b7a7b05d55f1f5be86 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 21 Oct 2014 11:33:21 -0700 Subject: [PATCH 48/63] Set breakpoint on whole enum declaration if set on the enum name of enum keyword --- src/services/breakpoints.ts | 26 +-- .../baselines/reference/bpSpan_enums.baseline | 165 +++++++++++++++++- .../fourslash/breakpointValidationEnums.ts | 23 +++ 3 files changed, 187 insertions(+), 27 deletions(-) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 1bb1fafeb35..15140f6c64a 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -161,10 +161,8 @@ module ts.BreakpointResolver { return spanInImportDeclaration(node); case SyntaxKind.EnumDeclaration: - return spanInEnumDeclaration(node); - case SyntaxKind.EnumMember: - return spanInEnumMember(node); + return textSpan(node); case SyntaxKind.ModuleDeclaration: return spanInModuleDeclaration(node); @@ -431,19 +429,6 @@ module ts.BreakpointResolver { return textSpan(importDeclaration, importDeclaration.entityName || importDeclaration.externalModuleName); } - function spanInEnumDeclaration(enumDeclaration: EnumDeclaration): TypeScript.TextSpan { - if (enumDeclaration.members.length) { - return spanInEnumMember(enumDeclaration.members[0]); - } - - // On close brace - return spanInNode(enumDeclaration.getLastToken(sourceFile)); - } - - function spanInEnumMember(enumMember: EnumMember) { - return textSpan(enumMember); - } - function spanInModuleDeclaration(moduleDeclaration: ModuleDeclaration): TypeScript.TextSpan { return spanInNode(moduleDeclaration.body); } @@ -466,8 +451,13 @@ module ts.BreakpointResolver { // Tokens: function spanInOpenBraceToken(node: Node): TypeScript.TextSpan { - if (node.parent.kind === SyntaxKind.SwitchStatement) { - return spanInNodeIfStartsOnSameLine(node.parent, (node.parent).clauses[0]); + switch (node.parent.kind) { + case SyntaxKind.EnumDeclaration: + var enumDeclaration = node.parent; + return spanInNodeIfStartsOnSameLine(findPrecedingToken(node.pos, sourceFile, node.parent), enumDeclaration.members.length ? enumDeclaration.members[0] : enumDeclaration.getLastToken(sourceFile)); + + case SyntaxKind.SwitchStatement: + return spanInNodeIfStartsOnSameLine(node.parent, (node.parent).clauses[0]); } // Default to parent node diff --git a/tests/baselines/reference/bpSpan_enums.baseline b/tests/baselines/reference/bpSpan_enums.baseline index c239d421da5..1dd77f8d417 100644 --- a/tests/baselines/reference/bpSpan_enums.baseline +++ b/tests/baselines/reference/bpSpan_enums.baseline @@ -1,9 +1,13 @@ 1 >enum e { - ~~~~~~~~~ => Pos: (0 to 8) SpanInfo: {"start":13,"length":1} - >x - >:=> (line 2, col 4) to (line 2, col 5) + ~~~~~~~~~ => Pos: (0 to 8) SpanInfo: {"start":0,"length":30} + >enum e { + > x, + > y, + > x + >} + >:=> (line 1, col 0) to (line 5, col 1) -------------------------------- 2 > x, @@ -31,9 +35,14 @@ -------------------------------- 6 >enum e2 { - ~~~~~~~~~~ => Pos: (31 to 40) SpanInfo: {"start":45,"length":6} - >x = 10 - >:=> (line 7, col 4) to (line 7, col 10) + ~~~~~~~~~~ => Pos: (31 to 40) SpanInfo: {"start":31,"length":49} + >enum e2 { + > x = 10, + > y = 10, + > z, + > x2 + >} + >:=> (line 6, col 0) to (line 11, col 1) -------------------------------- 7 > x = 10, @@ -67,9 +76,10 @@ -------------------------------- 12 >enum e3 { - ~~~~~~~~~~ => Pos: (81 to 90) SpanInfo: {"start":91,"length":1} + ~~~~~~~~~~ => Pos: (81 to 90) SpanInfo: {"start":81,"length":11} + >enum e3 { >} - >:=> (line 13, col 0) to (line 13, col 1) + >:=> (line 12, col 0) to (line 13, col 1) -------------------------------- 13 >} @@ -98,4 +108,141 @@ ~~~~~~~ => Pos: (132 to 138) SpanInfo: undefined -------------------------------- 19 >} - ~ => Pos: (139 to 139) SpanInfo: undefined \ No newline at end of file + + ~~ => Pos: (139 to 140) SpanInfo: undefined +-------------------------------- +20 >enum e11 + + ~~~~~~~~~~ => Pos: (141 to 150) SpanInfo: {"start":141,"length":33} + >enum e11 + >{ + > x, + > y, + > x + >} + >:=> (line 20, col 0) to (line 25, col 1) +-------------------------------- +21 >{ + + ~~ => Pos: (151 to 152) SpanInfo: {"start":157,"length":1} + >x + >:=> (line 22, col 4) to (line 22, col 5) +-------------------------------- +22 > x, + + ~~~~~~~ => Pos: (153 to 159) SpanInfo: {"start":157,"length":1} + >x + >:=> (line 22, col 4) to (line 22, col 5) +-------------------------------- +23 > y, + + ~~~~~~~ => Pos: (160 to 166) SpanInfo: {"start":164,"length":1} + >y + >:=> (line 23, col 4) to (line 23, col 5) +-------------------------------- +24 > x + + ~~~~~~ => Pos: (167 to 172) SpanInfo: {"start":171,"length":1} + >x + >:=> (line 24, col 4) to (line 24, col 5) +-------------------------------- +25 >} + + ~~ => Pos: (173 to 174) SpanInfo: {"start":173,"length":1} + >} + >:=> (line 25, col 0) to (line 25, col 1) +-------------------------------- +26 >enum e12 + + ~~~~~~~~~ => Pos: (175 to 183) SpanInfo: {"start":175,"length":50} + >enum e12 + >{ + > x = 10, + > y = 10, + > z, + > x2 + >} + >:=> (line 26, col 0) to (line 32, col 1) +-------------------------------- +27 >{ + + ~~ => Pos: (184 to 185) SpanInfo: {"start":190,"length":6} + >x = 10 + >:=> (line 28, col 4) to (line 28, col 10) +-------------------------------- +28 > x = 10, + + ~~~~~~~~~~~~ => Pos: (186 to 197) SpanInfo: {"start":190,"length":6} + >x = 10 + >:=> (line 28, col 4) to (line 28, col 10) +-------------------------------- +29 > y = 10, + + ~~~~~~~~~~~~ => Pos: (198 to 209) SpanInfo: {"start":202,"length":6} + >y = 10 + >:=> (line 29, col 4) to (line 29, col 10) +-------------------------------- +30 > z, + + ~~~~~~~ => Pos: (210 to 216) SpanInfo: {"start":214,"length":1} + >z + >:=> (line 30, col 4) to (line 30, col 5) +-------------------------------- +31 > x2 + + ~~~~~~~ => Pos: (217 to 223) SpanInfo: {"start":221,"length":2} + >x2 + >:=> (line 31, col 4) to (line 31, col 6) +-------------------------------- +32 >} + + ~~ => Pos: (224 to 225) SpanInfo: {"start":224,"length":1} + >} + >:=> (line 32, col 0) to (line 32, col 1) +-------------------------------- +33 >enum e13 + + ~~~~~~~~~ => Pos: (226 to 234) SpanInfo: {"start":226,"length":12} + >enum e13 + >{ + >} + >:=> (line 33, col 0) to (line 35, col 1) +-------------------------------- +34 >{ + + ~~ => Pos: (235 to 236) SpanInfo: {"start":237,"length":1} + >} + >:=> (line 35, col 0) to (line 35, col 1) +-------------------------------- +35 >} + + ~~ => Pos: (237 to 238) SpanInfo: {"start":237,"length":1} + >} + >:=> (line 35, col 0) to (line 35, col 1) +-------------------------------- +36 >declare enum e14 + + ~~~~~~~~~~~~~~~~~ => Pos: (239 to 255) SpanInfo: undefined +-------------------------------- +37 >{ + + ~~ => Pos: (256 to 257) SpanInfo: undefined +-------------------------------- +38 > x, + + ~~~~~~~ => Pos: (258 to 264) SpanInfo: undefined +-------------------------------- +39 > y, + + ~~~~~~~ => Pos: (265 to 271) SpanInfo: undefined +-------------------------------- +40 > z, + + ~~~~~~~ => Pos: (272 to 278) SpanInfo: undefined +-------------------------------- +41 > x2 + + ~~~~~~~ => Pos: (279 to 285) SpanInfo: undefined +-------------------------------- +42 >} + ~ => Pos: (286 to 286) SpanInfo: undefined \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationEnums.ts b/tests/cases/fourslash/breakpointValidationEnums.ts index cd0dbbdfb23..9d45462013a 100644 --- a/tests/cases/fourslash/breakpointValidationEnums.ts +++ b/tests/cases/fourslash/breakpointValidationEnums.ts @@ -21,5 +21,28 @@ //// z, //// x2 ////} +////enum e11 +////{ +//// x, +//// y, +//// x +////} +////enum e12 +////{ +//// x = 10, +//// y = 10, +//// z, +//// x2 +////} +////enum e13 +////{ +////} +////declare enum e14 +////{ +//// x, +//// y, +//// z, +//// x2 +////} verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file From a410133039d5c5f91bcc8ee659b29def63223ae8 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 21 Oct 2014 12:12:43 -0700 Subject: [PATCH 49/63] Some reorganizing --- src/services/breakpoints.ts | 141 ++++++++++-------------------------- 1 file changed, 40 insertions(+), 101 deletions(-) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 15140f6c64a..95d87171c79 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -82,7 +82,8 @@ module ts.BreakpointResolver { switch (node.kind) { case SyntaxKind.VariableStatement: - return spanInVariableStatement(node); + // Span on first variable declaration + return spanInVariableDeclaration((node).declarations[0]); case SyntaxKind.VariableDeclaration: case SyntaxKind.Property: @@ -111,71 +112,87 @@ module ts.BreakpointResolver { return spanInBlock(node); case SyntaxKind.ExpressionStatement: - return spanInExpressionStatement(node); + // span on the expression + return textSpan((node).expression); case SyntaxKind.ReturnStatement: - return spanInReturnStatement(node); + // span on return keyword and expression if present + return textSpan(node.getChildAt(0), (node).expression); case SyntaxKind.WhileStatement: - return spanInWhileStatement(node); + // Span on while(...) + return textSpan(node, findNextToken((node).expression, node)); case SyntaxKind.DoStatement: - return spanInDoStatement(node); + // span in statement of the do statement + return spanInNode((node).statement); case SyntaxKind.DebuggerStatement: - return spanInDebuggerStatement(node); + // span on debugger keyword + return textSpan(node.getChildAt(0)); case SyntaxKind.IfStatement: - return spanInIfStatement(node); + // set on if(..) span + return textSpan(node, findNextToken((node).expression, node)); case SyntaxKind.LabeledStatement: - return spanInLabeledStatement(node); + // span in statement + return spanInNode((node).statement); case SyntaxKind.BreakStatement: case SyntaxKind.ContinueStatement: - return spanInBreakOrContinueStatement(node); + // On break or continue keyword and label if present + return textSpan(node.getChildAt(0), (node).label); case SyntaxKind.ForStatement: return spanInForStatement(node); case SyntaxKind.ForInStatement: - return spanInForInStatement(node); + // span on for (a in ...) + return textSpan(node, findNextToken((node).expression, node)); case SyntaxKind.SwitchStatement: - return spanInSwitchStatement(node); + // span on switch(...) + return textSpan(node, findNextToken((node).expression, node)); case SyntaxKind.CaseClause: case SyntaxKind.DefaultClause: - return spanInCaseOrDefaultClause(node); + // span in first statement of the clause + return spanInNode((node).statements[0]); case SyntaxKind.TryStatement: - return spanInTryStatement(node); + // span in try block + return spanInBlock((node).tryBlock); case SyntaxKind.ThrowStatement: - return spanInThrowStatement(node); + // span in throw ... + return textSpan(node, (node).expression); case SyntaxKind.ExportAssignment: - return spanInExportAssignment(node); + // span on export = id + return textSpan(node, (node).exportName); case SyntaxKind.ImportDeclaration: - return spanInImportDeclaration(node); + // import statement without including semicolon + return textSpan(node, (node).entityName || (node).externalModuleName); case SyntaxKind.EnumDeclaration: case SyntaxKind.EnumMember: + case SyntaxKind.CallExpression: + case SyntaxKind.NewExpression: + // span on complete node return textSpan(node); case SyntaxKind.ModuleDeclaration: - return spanInModuleDeclaration(node); + // span in module body + return spanInNode((node).body); case SyntaxKind.ClassDeclaration: return spanInClassDeclaration(node); - case SyntaxKind.CallExpression: - case SyntaxKind.NewExpression: - return spanInCallOrNewExpression(node); - case SyntaxKind.WithStatement: - return spanInWithStatement(node); + // span in statement + return spanInNode((node).statement); // No breakpoint in interface case SyntaxKind.InterfaceDeclaration: @@ -241,7 +258,7 @@ module ts.BreakpointResolver { function spanInVariableDeclaration(variableDeclaration: VariableDeclaration): TypeScript.TextSpan { // If declaration of for in statement, just set the span in parent if (variableDeclaration.parent.kind === SyntaxKind.ForInStatement) { - return spanInForInStatement(variableDeclaration.parent); + return spanInNode(variableDeclaration.parent); } var isParentVariableStatement = variableDeclaration.parent.kind === SyntaxKind.VariableStatement; @@ -277,10 +294,6 @@ module ts.BreakpointResolver { } } - function spanInVariableStatement(variableStatement: VariableStatement): TypeScript.TextSpan { - return spanInVariableDeclaration(variableStatement.declarations[0]); - } - function canHaveSpanInParameterDeclaration(parameter: ParameterDeclaration): boolean { // Breakpoint is possible on parameter only if it has initializer, is a rest parameter, or has public or private modifier return !!parameter.initializer || !!(parameter.flags & NodeFlags.Rest) || @@ -351,40 +364,6 @@ module ts.BreakpointResolver { return spanInFirstStatementOfBlock(block); } - function spanInExpressionStatement(expressionStatement: ExpressionStatement): TypeScript.TextSpan { - return textSpan(expressionStatement.expression); - } - - function spanInReturnStatement(returnStatement: ReturnStatement): TypeScript.TextSpan { - return textSpan(returnStatement.getChildAt(0, sourceFile), returnStatement.expression); - } - - function spanInWhileStatement(whileStatement: WhileStatement): TypeScript.TextSpan { - return textSpan(whileStatement, findNextToken(whileStatement.expression, whileStatement)); - } - - function spanInDoStatement(doStatement: DoStatement): TypeScript.TextSpan { - return spanInNode(doStatement.statement); - } - - function spanInDebuggerStatement(node: Node): TypeScript.TextSpan { - // Set breakpoint on debugger keyword - return textSpan(node.getChildAt(0, sourceFile)); - } - - function spanInIfStatement(ifStatement: IfStatement): TypeScript.TextSpan { - // set on if(..) span - return textSpan(ifStatement, findNextToken(ifStatement.expression, ifStatement)); - } - - function spanInLabeledStatement(labeledStatement: LabeledStatement): TypeScript.TextSpan { - return spanInNode(labeledStatement.statement); - } - - function spanInBreakOrContinueStatement(breakOrContinueStatement: BreakOrContinueStatement): TypeScript.TextSpan { - return textSpan(breakOrContinueStatement, breakOrContinueStatement.label || breakOrContinueStatement.getChildAt(0)); - } - function spanInForStatement(forStatement: ForStatement): TypeScript.TextSpan { if (forStatement.declarations) { return spanInNode(forStatement.declarations[0]); @@ -401,38 +380,6 @@ module ts.BreakpointResolver { } } - function spanInForInStatement(forInStatement: ForInStatement): TypeScript.TextSpan { - return textSpan(forInStatement, findNextToken(forInStatement.expression, forInStatement)); - } - - function spanInSwitchStatement(switchStatement: SwitchStatement): TypeScript.TextSpan { - return textSpan(switchStatement, findNextToken(switchStatement.expression, switchStatement)); - } - - function spanInCaseOrDefaultClause(caseOrDefaultClause: CaseOrDefaultClause): TypeScript.TextSpan { - return spanInNode(caseOrDefaultClause.statements[0]); - } - - function spanInTryStatement(tryStatement: TryStatement): TypeScript.TextSpan { - return spanInBlock(tryStatement.tryBlock); - } - - function spanInThrowStatement(throwStatement: ThrowStatement): TypeScript.TextSpan { - return textSpan(throwStatement, throwStatement.expression); - } - - function spanInExportAssignment(exportAssignment: ExportAssignment): TypeScript.TextSpan { - return textSpan(exportAssignment, exportAssignment.exportName); - } - - function spanInImportDeclaration(importDeclaration: ImportDeclaration): TypeScript.TextSpan { - return textSpan(importDeclaration, importDeclaration.entityName || importDeclaration.externalModuleName); - } - - function spanInModuleDeclaration(moduleDeclaration: ModuleDeclaration): TypeScript.TextSpan { - return spanInNode(moduleDeclaration.body); - } - function spanInClassDeclaration(classDeclaration: ClassDeclaration): TypeScript.TextSpan { if (classDeclaration.members.length) { return spanInNode(classDeclaration.members[0]); @@ -441,14 +388,6 @@ module ts.BreakpointResolver { return spanInNode(classDeclaration.getLastToken()); } - function spanInCallOrNewExpression(callOrNewExpression: CallExpression): TypeScript.TextSpan { - return textSpan(callOrNewExpression); - } - - function spanInWithStatement(withStatement: WithStatement): TypeScript.TextSpan { - return spanInNode(withStatement.statement); - } - // Tokens: function spanInOpenBraceToken(node: Node): TypeScript.TextSpan { switch (node.parent.kind) { From b72b3ac850110647a9f5d2c24b3a96cbcf5ca78d Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 21 Oct 2014 12:55:46 -0700 Subject: [PATCH 50/63] Breakpoint span on module and its name is set on whole declaration if it is instantiated --- src/services/breakpoints.ts | 33 ++-- .../reference/bpSpan_classes.baseline | 81 +++++++- .../reference/bpSpan_import.baseline | 7 +- .../reference/bpSpan_interface.baseline | 4 +- .../reference/bpSpan_module.baseline | 177 ++++++++++++++++-- .../fourslash/breakpointValidationModule.ts | 23 +++ 6 files changed, 291 insertions(+), 34 deletions(-) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 95d87171c79..65720f024d7 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -146,7 +146,7 @@ module ts.BreakpointResolver { case SyntaxKind.ForStatement: return spanInForStatement(node); - + case SyntaxKind.ForInStatement: // span on for (a in ...) return textSpan(node, findNextToken((node).expression, node)); @@ -176,6 +176,12 @@ module ts.BreakpointResolver { // import statement without including semicolon return textSpan(node, (node).entityName || (node).externalModuleName); + case SyntaxKind.ModuleDeclaration: + // span on complete module if it is instantiated + if (!isInstantiated(node)) { + return undefined; + } + case SyntaxKind.EnumDeclaration: case SyntaxKind.EnumMember: case SyntaxKind.CallExpression: @@ -183,10 +189,6 @@ module ts.BreakpointResolver { // span on complete node return textSpan(node); - case SyntaxKind.ModuleDeclaration: - // span in module body - return spanInNode((node).body); - case SyntaxKind.ClassDeclaration: return spanInClassDeclaration(node); @@ -349,6 +351,11 @@ module ts.BreakpointResolver { function spanInBlock(block: Block): TypeScript.TextSpan { switch (block.parent.kind) { + case SyntaxKind.ModuleDeclaration: + if (!isInstantiated(block.parent)) { + return undefined; + } + // Set on parent if on same line otherwise on first statement case SyntaxKind.WhileStatement: case SyntaxKind.IfStatement: @@ -405,22 +412,18 @@ module ts.BreakpointResolver { function spanInCloseBraceToken(node: Node): TypeScript.TextSpan { switch (node.parent.kind) { + case SyntaxKind.ModuleBlock: + // If this is not instantiated module block no bp span + if (!isInstantiated(node.parent.parent)) { + return undefined; + } + case SyntaxKind.FunctionBlock: case SyntaxKind.EnumDeclaration: case SyntaxKind.ClassDeclaration: // Span on close brace token return textSpan(node); - case SyntaxKind.ModuleBlock: - var moduleBlock = node.parent; - if (moduleBlock.statements.length || // there are statements in the module block - moduleBlock.parent.parent.kind === SyntaxKind.ModuleDeclaration) { // this is a dotted module body - return textSpan(node); - } - - // No span - return; - case SyntaxKind.Block: case SyntaxKind.TryBlock: case SyntaxKind.CatchBlock: diff --git a/tests/baselines/reference/bpSpan_classes.baseline b/tests/baselines/reference/bpSpan_classes.baseline index 73089699a2b..90d99c85ee5 100644 --- a/tests/baselines/reference/bpSpan_classes.baseline +++ b/tests/baselines/reference/bpSpan_classes.baseline @@ -1,9 +1,84 @@ 1 >module Foo.Bar { - ~~~~~~~~~~~~~~~~~ => Pos: (0 to 16) SpanInfo: {"start":21,"length":12} - >"use strict" - >:=> (line 2, col 4) to (line 2, col 16) + ~~~~~~~~~~~ => Pos: (0 to 10) SpanInfo: {"start":0,"length":881} + >module Foo.Bar { + > "use strict"; + > + > class Greeter { + > constructor(public greeting: string) { + > } + > + > greet() { + > return "

" + this.greeting + "

"; + > } + > } + > + > + > function foo(greeting: string): Greeter { + > return new Greeter(greeting); + > } + > + > var greeter = new Greeter("Hello, world!"); + > var str = greeter.greet(); + > + > function foo2(greeting: string, ...restGreetings /* more greeting */: string[]) { + > var greeters: Greeter[] = []; /* inline block comment */ + > greeters[0] = new Greeter(greeting); + > for (var i = 0; i < restGreetings.length; i++) { + > greeters.push(new Greeter(restGreetings[i])); + > } + > + > return greeters; + > } + > + > var b = foo2("Hello", "World", "!"); + > // This is simple signle line comment + > for (var j = 0; j < b.length; j++) { + > b[j].greet(); + > } + >} + >:=> (line 1, col 0) to (line 36, col 1) +1 >module Foo.Bar { + + ~~~~~~ => Pos: (11 to 16) SpanInfo: {"start":11,"length":870} + >Bar { + > "use strict"; + > + > class Greeter { + > constructor(public greeting: string) { + > } + > + > greet() { + > return "

" + this.greeting + "

"; + > } + > } + > + > + > function foo(greeting: string): Greeter { + > return new Greeter(greeting); + > } + > + > var greeter = new Greeter("Hello, world!"); + > var str = greeter.greet(); + > + > function foo2(greeting: string, ...restGreetings /* more greeting */: string[]) { + > var greeters: Greeter[] = []; /* inline block comment */ + > greeters[0] = new Greeter(greeting); + > for (var i = 0; i < restGreetings.length; i++) { + > greeters.push(new Greeter(restGreetings[i])); + > } + > + > return greeters; + > } + > + > var b = foo2("Hello", "World", "!"); + > // This is simple signle line comment + > for (var j = 0; j < b.length; j++) { + > b[j].greet(); + > } + >} + >:=> (line 1, col 11) to (line 36, col 1) -------------------------------- 2 > "use strict"; diff --git a/tests/baselines/reference/bpSpan_import.baseline b/tests/baselines/reference/bpSpan_import.baseline index 43e843ebd01..7c8e35125f5 100644 --- a/tests/baselines/reference/bpSpan_import.baseline +++ b/tests/baselines/reference/bpSpan_import.baseline @@ -1,9 +1,12 @@ 1 >module m { - ~~~~~~~~~~~ => Pos: (0 to 10) SpanInfo: {"start":29,"length":1} + ~~~~~~~~~~~ => Pos: (0 to 10) SpanInfo: {"start":0,"length":32} + >module m { + > class c { + > } >} - >:=> (line 3, col 4) to (line 3, col 5) + >:=> (line 1, col 0) to (line 4, col 1) -------------------------------- 2 > class c { diff --git a/tests/baselines/reference/bpSpan_interface.baseline b/tests/baselines/reference/bpSpan_interface.baseline index 81d2bac4867..14e7921757d 100644 --- a/tests/baselines/reference/bpSpan_interface.baseline +++ b/tests/baselines/reference/bpSpan_interface.baseline @@ -88,6 +88,4 @@ ~~~~~~ => Pos: (472 to 477) SpanInfo: undefined -------------------------------- 23 >} - ~ => Pos: (478 to 478) SpanInfo: {"start":478,"length":1} - >} - >:=> (line 23, col 0) to (line 23, col 1) \ No newline at end of file + ~ => Pos: (478 to 478) SpanInfo: undefined \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_module.baseline b/tests/baselines/reference/bpSpan_module.baseline index cdeae25a1dd..bdf5d486175 100644 --- a/tests/baselines/reference/bpSpan_module.baseline +++ b/tests/baselines/reference/bpSpan_module.baseline @@ -1,9 +1,12 @@ 1 >module m2 { - ~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":16,"length":10} - >var a = 10 - >:=> (line 2, col 4) to (line 2, col 14) + ~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":0,"length":38} + >module m2 { + > var a = 10; + > a++; + >} + >:=> (line 1, col 0) to (line 4, col 1) -------------------------------- 2 > var a = 10; @@ -25,15 +28,25 @@ -------------------------------- 5 >module m3 { - ~~~~~~~~~~~~ => Pos: (39 to 50) SpanInfo: {"start":75,"length":17} - >export var x = 30 - >:=> (line 7, col 8) to (line 7, col 25) + ~~~~~~~~~~~~ => Pos: (39 to 50) SpanInfo: {"start":39,"length":118} + >module m3 { + > module m4 { + > export var x = 30; + > } + > + > export function foo() { + > return m4.x; + > } + >} + >:=> (line 5, col 0) to (line 13, col 1) -------------------------------- 6 > module m4 { - ~~~~~~~~~~~~~~~~ => Pos: (51 to 66) SpanInfo: {"start":75,"length":17} - >export var x = 30 - >:=> (line 7, col 8) to (line 7, col 25) + ~~~~~~~~~~~~~~~~ => Pos: (51 to 66) SpanInfo: {"start":55,"length":44} + >module m4 { + > export var x = 30; + > } + >:=> (line 6, col 4) to (line 8, col 5) -------------------------------- 7 > export var x = 30; @@ -70,6 +83,148 @@ >:=> (line 12, col 4) to (line 12, col 5) -------------------------------- 13 >} - ~ => Pos: (156 to 156) SpanInfo: {"start":156,"length":1} + + ~~ => Pos: (156 to 157) SpanInfo: {"start":156,"length":1} >} - >:=> (line 13, col 0) to (line 13, col 1) \ No newline at end of file + >:=> (line 13, col 0) to (line 13, col 1) +-------------------------------- +14 >module m4 { + + ~~~~~~~~~~~~ => Pos: (158 to 169) SpanInfo: undefined +-------------------------------- +15 > interface I { } + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (170 to 189) SpanInfo: undefined +-------------------------------- +16 >} + + ~~ => Pos: (190 to 191) SpanInfo: undefined +-------------------------------- +17 >module m12 + + ~~~~~~~~~~~ => Pos: (192 to 202) SpanInfo: {"start":192,"length":39} + >module m12 + >{ + > var a = 10; + > a++; + >} + >:=> (line 17, col 0) to (line 21, col 1) +-------------------------------- +18 >{ + + ~~ => Pos: (203 to 204) SpanInfo: {"start":209,"length":10} + >var a = 10 + >:=> (line 19, col 4) to (line 19, col 14) +-------------------------------- +19 > var a = 10; + + ~~~~~~~~~~~~~~~~ => Pos: (205 to 220) SpanInfo: {"start":209,"length":10} + >var a = 10 + >:=> (line 19, col 4) to (line 19, col 14) +-------------------------------- +20 > a++; + + ~~~~~~~~~ => Pos: (221 to 229) SpanInfo: {"start":225,"length":3} + >a++ + >:=> (line 20, col 4) to (line 20, col 7) +-------------------------------- +21 >} + + ~~ => Pos: (230 to 231) SpanInfo: {"start":230,"length":1} + >} + >:=> (line 21, col 0) to (line 21, col 1) +-------------------------------- +22 >module m13 + + ~~~~~~~~~~~ => Pos: (232 to 242) SpanInfo: {"start":232,"length":125} + >module m13 + >{ + > module m14 + > { + > export var x = 30; + > } + > + > export function foo() { + > return m4.x; + > } + >} + >:=> (line 22, col 0) to (line 32, col 1) +-------------------------------- +23 >{ + + ~~ => Pos: (243 to 244) SpanInfo: {"start":249,"length":50} + >module m14 + > { + > export var x = 30; + > } + >:=> (line 24, col 4) to (line 27, col 5) +-------------------------------- +24 > module m14 + + ~~~~~~~~~~~~~~~~ => Pos: (245 to 260) SpanInfo: {"start":249,"length":50} + >module m14 + > { + > export var x = 30; + > } + >:=> (line 24, col 4) to (line 27, col 5) +-------------------------------- +25 > { + + ~~~~~~ => Pos: (261 to 266) SpanInfo: {"start":275,"length":17} + >export var x = 30 + >:=> (line 26, col 8) to (line 26, col 25) +-------------------------------- +26 > export var x = 30; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (267 to 293) SpanInfo: {"start":275,"length":17} + >export var x = 30 + >:=> (line 26, col 8) to (line 26, col 25) +-------------------------------- +27 > } + + ~~~~~~ => Pos: (294 to 299) SpanInfo: {"start":298,"length":1} + >} + >:=> (line 27, col 4) to (line 27, col 5) +-------------------------------- +28 > + + ~ => Pos: (300 to 300) SpanInfo: undefined +-------------------------------- +29 > export function foo() { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (301 to 328) SpanInfo: {"start":337,"length":11} + >return m4.x + >:=> (line 30, col 8) to (line 30, col 19) +-------------------------------- +30 > return m4.x; + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (329 to 349) SpanInfo: {"start":337,"length":11} + >return m4.x + >:=> (line 30, col 8) to (line 30, col 19) +-------------------------------- +31 > } + + ~~~~~~ => Pos: (350 to 355) SpanInfo: {"start":354,"length":1} + >} + >:=> (line 31, col 4) to (line 31, col 5) +-------------------------------- +32 >} + + ~~ => Pos: (356 to 357) SpanInfo: {"start":356,"length":1} + >} + >:=> (line 32, col 0) to (line 32, col 1) +-------------------------------- +33 >module m14 + + ~~~~~~~~~~~~ => Pos: (358 to 369) SpanInfo: undefined +-------------------------------- +34 >{ + + ~~ => Pos: (370 to 371) SpanInfo: undefined +-------------------------------- +35 > interface I { } + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (372 to 391) SpanInfo: undefined +-------------------------------- +36 >} + ~ => Pos: (392 to 392) SpanInfo: undefined \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationModule.ts b/tests/cases/fourslash/breakpointValidationModule.ts index ec862853f84..3427cef72b3 100644 --- a/tests/cases/fourslash/breakpointValidationModule.ts +++ b/tests/cases/fourslash/breakpointValidationModule.ts @@ -15,5 +15,28 @@ //// return m4.x; //// } ////} +////module m4 { +//// interface I { } +////} +////module m12 +////{ +//// var a = 10; +//// a++; +////} +////module m13 +////{ +//// module m14 +//// { +//// export var x = 30; +//// } +//// +//// export function foo() { +//// return m4.x; +//// } +////} +////module m14 +////{ +//// interface I { } +////} verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file From 84016da726ac6233215cfdb404d7cd440e816d97 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 21 Oct 2014 13:17:44 -0700 Subject: [PATCH 51/63] Breakpoint span on class and its name is set on whole declaration --- src/services/breakpoints.ts | 16 +- .../baselines/reference/bpSpan_class.baseline | 233 +++++++++++++++++- .../reference/bpSpan_classes.baseline | 13 +- .../bpSpan_exportAssignment.baseline | 6 +- .../reference/bpSpan_import.baseline | 7 +- .../bpSpan_parenCallOrNewExpressions.baseline | 7 +- .../bpSpan_typeAssertionExpressions.baseline | 5 +- .../fourslash/breakpointValidationClass.ts | 30 +++ 8 files changed, 291 insertions(+), 26 deletions(-) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 65720f024d7..22b28cd3ffe 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -182,6 +182,7 @@ module ts.BreakpointResolver { return undefined; } + case SyntaxKind.ClassDeclaration: case SyntaxKind.EnumDeclaration: case SyntaxKind.EnumMember: case SyntaxKind.CallExpression: @@ -189,9 +190,6 @@ module ts.BreakpointResolver { // span on complete node return textSpan(node); - case SyntaxKind.ClassDeclaration: - return spanInClassDeclaration(node); - case SyntaxKind.WithStatement: // span in statement return spanInNode((node).statement); @@ -387,14 +385,6 @@ module ts.BreakpointResolver { } } - function spanInClassDeclaration(classDeclaration: ClassDeclaration): TypeScript.TextSpan { - if (classDeclaration.members.length) { - return spanInNode(classDeclaration.members[0]); - } - - return spanInNode(classDeclaration.getLastToken()); - } - // Tokens: function spanInOpenBraceToken(node: Node): TypeScript.TextSpan { switch (node.parent.kind) { @@ -402,6 +392,10 @@ module ts.BreakpointResolver { var enumDeclaration = node.parent; return spanInNodeIfStartsOnSameLine(findPrecedingToken(node.pos, sourceFile, node.parent), enumDeclaration.members.length ? enumDeclaration.members[0] : enumDeclaration.getLastToken(sourceFile)); + case SyntaxKind.ClassDeclaration: + var classDeclaration = node.parent; + return spanInNodeIfStartsOnSameLine(findPrecedingToken(node.pos, sourceFile, node.parent), classDeclaration.members.length ? classDeclaration.members[0] : classDeclaration.getLastToken(sourceFile)); + case SyntaxKind.SwitchStatement: return spanInNodeIfStartsOnSameLine(node.parent, (node.parent).clauses[0]); } diff --git a/tests/baselines/reference/bpSpan_class.baseline b/tests/baselines/reference/bpSpan_class.baseline index a628510bb9e..816df2168fa 100644 --- a/tests/baselines/reference/bpSpan_class.baseline +++ b/tests/baselines/reference/bpSpan_class.baseline @@ -1,9 +1,26 @@ 1 >class Greeter { - ~~~~~~~~~~~~~~~~ => Pos: (0 to 15) SpanInfo: {"start":79,"length":1} + ~~~~~~~~~~~~~~~~ => Pos: (0 to 15) SpanInfo: {"start":0,"length":396} + >class Greeter { + > constructor(public greeting: string, ...b: string[]) { + > } + > greet() { + > return "

" + this.greeting + "

"; + > } + > private x: string; + > private x1: number = 10; + > private fn() { + > return this.greeting; + > } + > get greetings() { + > return this.greeting; + > } + > set greetings(greetings: string) { + > this.greeting = greetings; + > } >} - >:=> (line 3, col 4) to (line 3, col 5) + >:=> (line 1, col 0) to (line 18, col 1) -------------------------------- 2 > constructor(public greeting: string, ...b: string[]) { @@ -115,6 +132,214 @@ >:=> (line 17, col 4) to (line 17, col 5) -------------------------------- 18 >} - ~ => Pos: (395 to 395) SpanInfo: {"start":395,"length":1} + + ~~ => Pos: (395 to 396) SpanInfo: {"start":395,"length":1} >} - >:=> (line 18, col 0) to (line 18, col 1) \ No newline at end of file + >:=> (line 18, col 0) to (line 18, col 1) +-------------------------------- +19 >class Greeter2 { + + ~~~~~~~~~~~~~~~~~ => Pos: (397 to 413) SpanInfo: {"start":397,"length":18} + >class Greeter2 { + >} + >:=> (line 19, col 0) to (line 20, col 1) +-------------------------------- +20 >} + + ~~ => Pos: (414 to 415) SpanInfo: {"start":414,"length":1} + >} + >:=> (line 20, col 0) to (line 20, col 1) +-------------------------------- +21 >class Greeter1 + + ~~~~~~~~~~~~~~~~ => Pos: (416 to 431) SpanInfo: {"start":416,"length":419} + >class Greeter1 + >{ + > constructor(public greeting: string, ...b: string[]) + > { + > } + > greet() + > { + > return "

" + this.greeting + "

"; + > } + > private x: string; + > private x1: number = 10; + > private fn() + > { + > return this.greeting; + > } + > get greetings() + > { + > return this.greeting; + > } + > set greetings(greetings: string) + > { + > this.greeting = greetings; + > } + >} + >:=> (line 21, col 0) to (line 44, col 1) +-------------------------------- +22 >{ + + ~~ => Pos: (432 to 433) SpanInfo: {"start":501,"length":1} + >} + >:=> (line 25, col 4) to (line 25, col 5) +-------------------------------- +23 > constructor(public greeting: string, ...b: string[]) + + ~~~~~~~~~~~~~~~~ => Pos: (434 to 449) SpanInfo: {"start":501,"length":1} + >} + >:=> (line 25, col 4) to (line 25, col 5) +23 > constructor(public greeting: string, ...b: string[]) + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (450 to 473) SpanInfo: {"start":450,"length":23} + >public greeting: string + >:=> (line 23, col 16) to (line 23, col 39) +23 > constructor(public greeting: string, ...b: string[]) + + ~~~~~~~~~~~~~~~~~=> Pos: (474 to 490) SpanInfo: {"start":475,"length":14} + >...b: string[] + >:=> (line 23, col 41) to (line 23, col 55) +-------------------------------- +24 > { + + ~~~~~~ => Pos: (491 to 496) SpanInfo: {"start":501,"length":1} + >} + >:=> (line 25, col 4) to (line 25, col 5) +-------------------------------- +25 > } + + ~~~~~~ => Pos: (497 to 502) SpanInfo: {"start":501,"length":1} + >} + >:=> (line 25, col 4) to (line 25, col 5) +-------------------------------- +26 > greet() + + ~~~~~~~~~~~~ => Pos: (503 to 514) SpanInfo: {"start":529,"length":39} + >return "

" + this.greeting + "

" + >:=> (line 28, col 8) to (line 28, col 47) +-------------------------------- +27 > { + + ~~~~~~ => Pos: (515 to 520) SpanInfo: {"start":529,"length":39} + >return "

" + this.greeting + "

" + >:=> (line 28, col 8) to (line 28, col 47) +-------------------------------- +28 > return "

" + this.greeting + "

"; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (521 to 569) SpanInfo: {"start":529,"length":39} + >return "

" + this.greeting + "

" + >:=> (line 28, col 8) to (line 28, col 47) +-------------------------------- +29 > } + + ~~~~~~ => Pos: (570 to 575) SpanInfo: {"start":574,"length":1} + >} + >:=> (line 29, col 4) to (line 29, col 5) +-------------------------------- +30 > private x: string; + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (576 to 598) SpanInfo: undefined +-------------------------------- +31 > private x1: number = 10; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (599 to 627) SpanInfo: {"start":603,"length":24} + >private x1: number = 10; + >:=> (line 31, col 4) to (line 31, col 28) +-------------------------------- +32 > private fn() + + ~~~~~~~~~~~~~~~~~ => Pos: (628 to 644) SpanInfo: {"start":659,"length":20} + >return this.greeting + >:=> (line 34, col 8) to (line 34, col 28) +-------------------------------- +33 > { + + ~~~~~~ => Pos: (645 to 650) SpanInfo: {"start":659,"length":20} + >return this.greeting + >:=> (line 34, col 8) to (line 34, col 28) +-------------------------------- +34 > return this.greeting; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (651 to 680) SpanInfo: {"start":659,"length":20} + >return this.greeting + >:=> (line 34, col 8) to (line 34, col 28) +-------------------------------- +35 > } + + ~~~~~~ => Pos: (681 to 686) SpanInfo: {"start":685,"length":1} + >} + >:=> (line 35, col 4) to (line 35, col 5) +-------------------------------- +36 > get greetings() + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (687 to 707) SpanInfo: {"start":722,"length":20} + >return this.greeting + >:=> (line 38, col 8) to (line 38, col 28) +-------------------------------- +37 > { + + ~~~~~~ => Pos: (708 to 713) SpanInfo: {"start":722,"length":20} + >return this.greeting + >:=> (line 38, col 8) to (line 38, col 28) +-------------------------------- +38 > return this.greeting; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (714 to 743) SpanInfo: {"start":722,"length":20} + >return this.greeting + >:=> (line 38, col 8) to (line 38, col 28) +-------------------------------- +39 > } + + ~~~~~~ => Pos: (744 to 749) SpanInfo: {"start":748,"length":1} + >} + >:=> (line 39, col 4) to (line 39, col 5) +-------------------------------- +40 > set greetings(greetings: string) + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (750 to 786) SpanInfo: {"start":801,"length":25} + >this.greeting = greetings + >:=> (line 42, col 8) to (line 42, col 33) +-------------------------------- +41 > { + + ~~~~~~ => Pos: (787 to 792) SpanInfo: {"start":801,"length":25} + >this.greeting = greetings + >:=> (line 42, col 8) to (line 42, col 33) +-------------------------------- +42 > this.greeting = greetings; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (793 to 827) SpanInfo: {"start":801,"length":25} + >this.greeting = greetings + >:=> (line 42, col 8) to (line 42, col 33) +-------------------------------- +43 > } + + ~~~~~~ => Pos: (828 to 833) SpanInfo: {"start":832,"length":1} + >} + >:=> (line 43, col 4) to (line 43, col 5) +-------------------------------- +44 >} + + ~~ => Pos: (834 to 835) SpanInfo: {"start":834,"length":1} + >} + >:=> (line 44, col 0) to (line 44, col 1) +-------------------------------- +45 >class Greeter12 + + ~~~~~~~~~~~~~~~~ => Pos: (836 to 851) SpanInfo: {"start":836,"length":19} + >class Greeter12 + >{ + >} + >:=> (line 45, col 0) to (line 47, col 1) +-------------------------------- +46 >{ + + ~~ => Pos: (852 to 853) SpanInfo: {"start":854,"length":1} + >} + >:=> (line 47, col 0) to (line 47, col 1) +-------------------------------- +47 >} + ~ => Pos: (854 to 854) SpanInfo: {"start":854,"length":1} + >} + >:=> (line 47, col 0) to (line 47, col 1) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_classes.baseline b/tests/baselines/reference/bpSpan_classes.baseline index 90d99c85ee5..e9de5123d1c 100644 --- a/tests/baselines/reference/bpSpan_classes.baseline +++ b/tests/baselines/reference/bpSpan_classes.baseline @@ -92,9 +92,16 @@ -------------------------------- 4 > class Greeter { - ~~~~~~~~~~~~~~~~~~~~ => Pos: (36 to 55) SpanInfo: {"start":111,"length":1} - >} - >:=> (line 6, col 8) to (line 6, col 9) + ~~~~~~~~~~~~~~~~~~~~ => Pos: (36 to 55) SpanInfo: {"start":40,"length":160} + >class Greeter { + > constructor(public greeting: string) { + > } + > + > greet() { + > return "

" + this.greeting + "

"; + > } + > } + >:=> (line 4, col 4) to (line 11, col 5) -------------------------------- 5 > constructor(public greeting: string) { diff --git a/tests/baselines/reference/bpSpan_exportAssignment.baseline b/tests/baselines/reference/bpSpan_exportAssignment.baseline index 9086e218329..a9d635a929c 100644 --- a/tests/baselines/reference/bpSpan_exportAssignment.baseline +++ b/tests/baselines/reference/bpSpan_exportAssignment.baseline @@ -1,7 +1,11 @@ 1 >class a { - ~~~~~~~~~~ => Pos: (0 to 9) SpanInfo: undefined + ~~~~~~~~~~ => Pos: (0 to 9) SpanInfo: {"start":0,"length":25} + >class a { + > public c; + >} + >:=> (line 1, col 0) to (line 3, col 1) -------------------------------- 2 > public c; diff --git a/tests/baselines/reference/bpSpan_import.baseline b/tests/baselines/reference/bpSpan_import.baseline index 7c8e35125f5..26279b48f26 100644 --- a/tests/baselines/reference/bpSpan_import.baseline +++ b/tests/baselines/reference/bpSpan_import.baseline @@ -10,9 +10,10 @@ -------------------------------- 2 > class c { - ~~~~~~~~~~~~~~ => Pos: (11 to 24) SpanInfo: {"start":29,"length":1} - >} - >:=> (line 3, col 4) to (line 3, col 5) + ~~~~~~~~~~~~~~ => Pos: (11 to 24) SpanInfo: {"start":15,"length":15} + >class c { + > } + >:=> (line 2, col 4) to (line 3, col 5) -------------------------------- 3 > } diff --git a/tests/baselines/reference/bpSpan_parenCallOrNewExpressions.baseline b/tests/baselines/reference/bpSpan_parenCallOrNewExpressions.baseline index 80692f05178..47c932640f9 100644 --- a/tests/baselines/reference/bpSpan_parenCallOrNewExpressions.baseline +++ b/tests/baselines/reference/bpSpan_parenCallOrNewExpressions.baseline @@ -128,9 +128,12 @@ -------------------------------- 10 >class greeter { - ~~~~~~~~~~~~~~~~ => Pos: (146 to 161) SpanInfo: {"start":195,"length":1} + ~~~~~~~~~~~~~~~~ => Pos: (146 to 161) SpanInfo: {"start":146,"length":52} + >class greeter { + > constructor(a: number) { + > } >} - >:=> (line 12, col 4) to (line 12, col 5) + >:=> (line 10, col 0) to (line 13, col 1) -------------------------------- 11 > constructor(a: number) { diff --git a/tests/baselines/reference/bpSpan_typeAssertionExpressions.baseline b/tests/baselines/reference/bpSpan_typeAssertionExpressions.baseline index f73b47d8519..c04ddb8503b 100644 --- a/tests/baselines/reference/bpSpan_typeAssertionExpressions.baseline +++ b/tests/baselines/reference/bpSpan_typeAssertionExpressions.baseline @@ -1,9 +1,10 @@ 1 >class Greeter { - ~~~~~~~~~~~~~~~~ => Pos: (0 to 15) SpanInfo: {"start":16,"length":1} + ~~~~~~~~~~~~~~~~ => Pos: (0 to 15) SpanInfo: {"start":0,"length":17} + >class Greeter { >} - >:=> (line 2, col 0) to (line 2, col 1) + >:=> (line 1, col 0) to (line 2, col 1) -------------------------------- 2 >} diff --git a/tests/cases/fourslash/breakpointValidationClass.ts b/tests/cases/fourslash/breakpointValidationClass.ts index e9104bc6d27..99209c465b2 100644 --- a/tests/cases/fourslash/breakpointValidationClass.ts +++ b/tests/cases/fourslash/breakpointValidationClass.ts @@ -20,4 +20,34 @@ //// this.greeting = greetings; //// } ////} +////class Greeter2 { +////} +////class Greeter1 +////{ +//// constructor(public greeting: string, ...b: string[]) +//// { +//// } +//// greet() +//// { +//// return "

" + this.greeting + "

"; +//// } +//// private x: string; +//// private x1: number = 10; +//// private fn() +//// { +//// return this.greeting; +//// } +//// get greetings() +//// { +//// return this.greeting; +//// } +//// set greetings(greetings: string) +//// { +//// this.greeting = greetings; +//// } +////} +////class Greeter12 +////{ +////} + verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file From 897f23a5dc93a87235a1b009ad6f652162eef239 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 21 Oct 2014 14:02:47 -0700 Subject: [PATCH 52/63] Span on whole function if the function is exported --- src/services/breakpoints.ts | 19 +- .../reference/bpSpan_functions.baseline | 274 +++++++++++++++++- .../reference/bpSpan_module.baseline | 16 +- .../breakpointValidationFunctions.ts | 31 ++ 4 files changed, 327 insertions(+), 13 deletions(-) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 22b28cd3ffe..40b18b1edc4 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -318,10 +318,19 @@ module ts.BreakpointResolver { } } + function canFunctionHaveSpanInWholeDeclaration(functionDeclaration: FunctionDeclaration) { + return !!(functionDeclaration.flags & NodeFlags.Export); + } + function spanInFunctionDeclaration(functionDeclaration: FunctionDeclaration): TypeScript.TextSpan { // No breakpoints in the function signature if (!functionDeclaration.body) { - return; + return undefined; + } + + if (canFunctionHaveSpanInWholeDeclaration(functionDeclaration)) { + // Set the span on whole function declaration + return textSpan(functionDeclaration); } // Set span in function body @@ -329,12 +338,12 @@ module ts.BreakpointResolver { } function spanInFunctionBlock(block: Block): TypeScript.TextSpan { - if (block.statements.length) { - return spanInFirstStatementOfBlock(block); + var nodeForSpanInBlock = block.statements.length ? block.statements[0] : block.getLastToken(); + if (canFunctionHaveSpanInWholeDeclaration(block.parent)) { + return spanInNodeIfStartsOnSameLine(block.parent, nodeForSpanInBlock); } - // On close parenthesis - return spanInNode(block.getLastToken()); + return spanInNode(nodeForSpanInBlock); } function spanInFirstStatementOfBlock(block: Block): TypeScript.TextSpan { diff --git a/tests/baselines/reference/bpSpan_functions.baseline b/tests/baselines/reference/bpSpan_functions.baseline index 623474ec93b..535f177c0f6 100644 --- a/tests/baselines/reference/bpSpan_functions.baseline +++ b/tests/baselines/reference/bpSpan_functions.baseline @@ -97,6 +97,276 @@ >:=> (line 12, col 4) to (line 12, col 10) -------------------------------- 13 >} - ~ => Pos: (323 to 323) SpanInfo: {"start":323,"length":1} + + ~~ => Pos: (323 to 324) SpanInfo: {"start":323,"length":1} >} - >:=> (line 13, col 0) to (line 13, col 1) \ No newline at end of file + >:=> (line 13, col 0) to (line 13, col 1) +-------------------------------- +14 >module m { + + ~~~~~~~~~~~ => Pos: (325 to 335) SpanInfo: {"start":325,"length":389} + >module m { + > var greetings = 0; + > function greet(greeting: string): number { + > greetings++; + > return greetings; + > } + > function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + > greetings++; + > return greetings; + > } + > function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + > { + > return; + > } + >} + >:=> (line 14, col 0) to (line 28, col 1) +-------------------------------- +15 > var greetings = 0; + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (336 to 358) SpanInfo: {"start":340,"length":17} + >var greetings = 0 + >:=> (line 15, col 4) to (line 15, col 21) +-------------------------------- +16 > function greet(greeting: string): number { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (359 to 405) SpanInfo: {"start":414,"length":11} + >greetings++ + >:=> (line 17, col 8) to (line 17, col 19) +-------------------------------- +17 > greetings++; + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (406 to 426) SpanInfo: {"start":414,"length":11} + >greetings++ + >:=> (line 17, col 8) to (line 17, col 19) +-------------------------------- +18 > return greetings; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (427 to 452) SpanInfo: {"start":435,"length":16} + >return greetings + >:=> (line 18, col 8) to (line 18, col 24) +-------------------------------- +19 > } + + ~~~~~~ => Pos: (453 to 458) SpanInfo: {"start":457,"length":1} + >} + >:=> (line 19, col 4) to (line 19, col 5) +-------------------------------- +20 > function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (459 to 495) SpanInfo: {"start":560,"length":11} + >greetings++ + >:=> (line 21, col 8) to (line 21, col 19) +20 > function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~~~~~~~~~~~~~~~~~~=> Pos: (496 to 515) SpanInfo: {"start":497,"length":6} + >n = 10 + >:=> (line 20, col 38) to (line 20, col 44) +20 > function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (516 to 548) SpanInfo: {"start":517,"length":23} + >...restParams: string[] + >:=> (line 20, col 58) to (line 20, col 81) +20 > function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~=> Pos: (549 to 551) SpanInfo: {"start":560,"length":11} + >greetings++ + >:=> (line 21, col 8) to (line 21, col 19) +-------------------------------- +21 > greetings++; + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (552 to 572) SpanInfo: {"start":560,"length":11} + >greetings++ + >:=> (line 21, col 8) to (line 21, col 19) +-------------------------------- +22 > return greetings; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (573 to 598) SpanInfo: {"start":581,"length":16} + >return greetings + >:=> (line 22, col 8) to (line 22, col 24) +-------------------------------- +23 > } + + ~~~~~~ => Pos: (599 to 604) SpanInfo: {"start":603,"length":1} + >} + >:=> (line 23, col 4) to (line 23, col 5) +-------------------------------- +24 > function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (605 to 638) SpanInfo: {"start":699,"length":6} + >return + >:=> (line 26, col 8) to (line 26, col 14) +24 > function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + + ~~~~~~~~~~~~~~~~~~~~=> Pos: (639 to 658) SpanInfo: {"start":640,"length":6} + >n = 10 + >:=> (line 24, col 35) to (line 24, col 41) +24 > function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + + ~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (659 to 684) SpanInfo: {"start":660,"length":23} + >...restParams: string[] + >:=> (line 24, col 55) to (line 24, col 78) +-------------------------------- +25 > { + + ~~~~~~ => Pos: (685 to 690) SpanInfo: {"start":699,"length":6} + >return + >:=> (line 26, col 8) to (line 26, col 14) +-------------------------------- +26 > return; + + ~~~~~~~~~~~~~~~~ => Pos: (691 to 706) SpanInfo: {"start":699,"length":6} + >return + >:=> (line 26, col 8) to (line 26, col 14) +-------------------------------- +27 > } + + ~~~~~~ => Pos: (707 to 712) SpanInfo: {"start":711,"length":1} + >} + >:=> (line 27, col 4) to (line 27, col 5) +-------------------------------- +28 >} + + ~~ => Pos: (713 to 714) SpanInfo: {"start":713,"length":1} + >} + >:=> (line 28, col 0) to (line 28, col 1) +-------------------------------- +29 >module m1 { + + ~~~~~~~~~~~~ => Pos: (715 to 726) SpanInfo: {"start":715,"length":411} + >module m1 { + > var greetings = 0; + > export function greet(greeting: string): number { + > greetings++; + > return greetings; + > } + > export function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + > greetings++; + > return greetings; + > } + > export function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + > { + > return; + > } + >} + >:=> (line 29, col 0) to (line 43, col 1) +-------------------------------- +30 > var greetings = 0; + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (727 to 749) SpanInfo: {"start":731,"length":17} + >var greetings = 0 + >:=> (line 30, col 4) to (line 30, col 21) +-------------------------------- +31 > export function greet(greeting: string): number { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (750 to 803) SpanInfo: {"start":754,"length":102} + >export function greet(greeting: string): number { + > greetings++; + > return greetings; + > } + >:=> (line 31, col 4) to (line 34, col 5) +-------------------------------- +32 > greetings++; + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (804 to 824) SpanInfo: {"start":812,"length":11} + >greetings++ + >:=> (line 32, col 8) to (line 32, col 19) +-------------------------------- +33 > return greetings; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (825 to 850) SpanInfo: {"start":833,"length":16} + >return greetings + >:=> (line 33, col 8) to (line 33, col 24) +-------------------------------- +34 > } + + ~~~~~~ => Pos: (851 to 856) SpanInfo: {"start":855,"length":1} + >} + >:=> (line 34, col 4) to (line 34, col 5) +-------------------------------- +35 > export function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (857 to 900) SpanInfo: {"start":861,"length":148} + >export function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + > greetings++; + > return greetings; + > } + >:=> (line 35, col 4) to (line 38, col 5) +35 > export function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~~~~~~~~~~~~~~~~~~=> Pos: (901 to 920) SpanInfo: {"start":902,"length":6} + >n = 10 + >:=> (line 35, col 45) to (line 35, col 51) +35 > export function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (921 to 953) SpanInfo: {"start":922,"length":23} + >...restParams: string[] + >:=> (line 35, col 65) to (line 35, col 88) +35 > export function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~=> Pos: (954 to 956) SpanInfo: {"start":861,"length":148} + >export function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + > greetings++; + > return greetings; + > } + >:=> (line 35, col 4) to (line 38, col 5) +-------------------------------- +36 > greetings++; + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (957 to 977) SpanInfo: {"start":965,"length":11} + >greetings++ + >:=> (line 36, col 8) to (line 36, col 19) +-------------------------------- +37 > return greetings; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (978 to 1003) SpanInfo: {"start":986,"length":16} + >return greetings + >:=> (line 37, col 8) to (line 37, col 24) +-------------------------------- +38 > } + + ~~~~~~ => Pos: (1004 to 1009) SpanInfo: {"start":1008,"length":1} + >} + >:=> (line 38, col 4) to (line 38, col 5) +-------------------------------- +39 > export function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (1010 to 1050) SpanInfo: {"start":1014,"length":110} + >export function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + > { + > return; + > } + >:=> (line 39, col 4) to (line 42, col 5) +39 > export function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + + ~~~~~~~~~~~~~~~~~~~~=> Pos: (1051 to 1070) SpanInfo: {"start":1052,"length":6} + >n = 10 + >:=> (line 39, col 42) to (line 39, col 48) +39 > export function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + + ~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (1071 to 1096) SpanInfo: {"start":1072,"length":23} + >...restParams: string[] + >:=> (line 39, col 62) to (line 39, col 85) +-------------------------------- +40 > { + + ~~~~~~ => Pos: (1097 to 1102) SpanInfo: {"start":1111,"length":6} + >return + >:=> (line 41, col 8) to (line 41, col 14) +-------------------------------- +41 > return; + + ~~~~~~~~~~~~~~~~ => Pos: (1103 to 1118) SpanInfo: {"start":1111,"length":6} + >return + >:=> (line 41, col 8) to (line 41, col 14) +-------------------------------- +42 > } + + ~~~~~~ => Pos: (1119 to 1124) SpanInfo: {"start":1123,"length":1} + >} + >:=> (line 42, col 4) to (line 42, col 5) +-------------------------------- +43 >} + ~ => Pos: (1125 to 1125) SpanInfo: {"start":1125,"length":1} + >} + >:=> (line 43, col 0) to (line 43, col 1) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_module.baseline b/tests/baselines/reference/bpSpan_module.baseline index bdf5d486175..14145512658 100644 --- a/tests/baselines/reference/bpSpan_module.baseline +++ b/tests/baselines/reference/bpSpan_module.baseline @@ -66,9 +66,11 @@ -------------------------------- 10 > export function foo() { - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (101 to 128) SpanInfo: {"start":137,"length":11} - >return m4.x - >:=> (line 11, col 8) to (line 11, col 19) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (101 to 128) SpanInfo: {"start":105,"length":50} + >export function foo() { + > return m4.x; + > } + >:=> (line 10, col 4) to (line 12, col 5) -------------------------------- 11 > return m4.x; @@ -192,9 +194,11 @@ -------------------------------- 29 > export function foo() { - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (301 to 328) SpanInfo: {"start":337,"length":11} - >return m4.x - >:=> (line 30, col 8) to (line 30, col 19) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (301 to 328) SpanInfo: {"start":305,"length":50} + >export function foo() { + > return m4.x; + > } + >:=> (line 29, col 4) to (line 31, col 5) -------------------------------- 30 > return m4.x; diff --git a/tests/cases/fourslash/breakpointValidationFunctions.ts b/tests/cases/fourslash/breakpointValidationFunctions.ts index 4ab0c7c577e..0f38394d8e0 100644 --- a/tests/cases/fourslash/breakpointValidationFunctions.ts +++ b/tests/cases/fourslash/breakpointValidationFunctions.ts @@ -15,4 +15,35 @@ ////{ //// return; ////} +////module m { +//// var greetings = 0; +//// function greet(greeting: string): number { +//// greetings++; +//// return greetings; +//// } +//// function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { +//// greetings++; +//// return greetings; +//// } +//// function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) +//// { +//// return; +//// } +////} +////module m1 { +//// var greetings = 0; +//// export function greet(greeting: string): number { +//// greetings++; +//// return greetings; +//// } +//// export function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { +//// greetings++; +//// return greetings; +//// } +//// export function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) +//// { +//// return; +//// } +////} + verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file From e464a3d6fb19c4ef303dd61f94ffd291091fe06b Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 21 Oct 2014 14:19:41 -0700 Subject: [PATCH 53/63] Span on whole method/accessors if they are of class declaration --- src/services/breakpoints.ts | 3 +- .../baselines/reference/bpSpan_class.baseline | 68 ++++++++++++------- .../reference/bpSpan_classes.baseline | 8 ++- 3 files changed, 51 insertions(+), 28 deletions(-) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 40b18b1edc4..a7e5613a477 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -319,7 +319,8 @@ module ts.BreakpointResolver { } function canFunctionHaveSpanInWholeDeclaration(functionDeclaration: FunctionDeclaration) { - return !!(functionDeclaration.flags & NodeFlags.Export); + return !!(functionDeclaration.flags & NodeFlags.Export) || + (functionDeclaration.parent.kind === SyntaxKind.ClassDeclaration && functionDeclaration.kind !== SyntaxKind.Constructor); } function spanInFunctionDeclaration(functionDeclaration: FunctionDeclaration): TypeScript.TextSpan { diff --git a/tests/baselines/reference/bpSpan_class.baseline b/tests/baselines/reference/bpSpan_class.baseline index 816df2168fa..3370762f72b 100644 --- a/tests/baselines/reference/bpSpan_class.baseline +++ b/tests/baselines/reference/bpSpan_class.baseline @@ -51,9 +51,11 @@ -------------------------------- 4 > greet() { - ~~~~~~~~~~~~~~ => Pos: (81 to 94) SpanInfo: {"start":103,"length":39} - >return "

" + this.greeting + "

" - >:=> (line 5, col 8) to (line 5, col 47) + ~~~~~~~~~~~~~~ => Pos: (81 to 94) SpanInfo: {"start":85,"length":64} + >greet() { + > return "

" + this.greeting + "

"; + > } + >:=> (line 4, col 4) to (line 6, col 5) -------------------------------- 5 > return "

" + this.greeting + "

"; @@ -79,9 +81,11 @@ -------------------------------- 9 > private fn() { - ~~~~~~~~~~~~~~~~~~~ => Pos: (202 to 220) SpanInfo: {"start":229,"length":20} - >return this.greeting - >:=> (line 10, col 8) to (line 10, col 28) + ~~~~~~~~~~~~~~~~~~~ => Pos: (202 to 220) SpanInfo: {"start":206,"length":50} + >private fn() { + > return this.greeting; + > } + >:=> (line 9, col 4) to (line 11, col 5) -------------------------------- 10 > return this.greeting; @@ -97,9 +101,11 @@ -------------------------------- 12 > get greetings() { - ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (257 to 278) SpanInfo: {"start":287,"length":20} - >return this.greeting - >:=> (line 13, col 8) to (line 13, col 28) + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (257 to 278) SpanInfo: {"start":261,"length":53} + >get greetings() { + > return this.greeting; + > } + >:=> (line 12, col 4) to (line 14, col 5) -------------------------------- 13 > return this.greeting; @@ -115,9 +121,11 @@ -------------------------------- 15 > set greetings(greetings: string) { - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (315 to 353) SpanInfo: {"start":362,"length":25} - >this.greeting = greetings - >:=> (line 16, col 8) to (line 16, col 33) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (315 to 353) SpanInfo: {"start":319,"length":75} + >set greetings(greetings: string) { + > this.greeting = greetings; + > } + >:=> (line 15, col 4) to (line 17, col 5) -------------------------------- 16 > this.greeting = greetings; @@ -215,9 +223,12 @@ -------------------------------- 26 > greet() - ~~~~~~~~~~~~ => Pos: (503 to 514) SpanInfo: {"start":529,"length":39} - >return "

" + this.greeting + "

" - >:=> (line 28, col 8) to (line 28, col 47) + ~~~~~~~~~~~~ => Pos: (503 to 514) SpanInfo: {"start":507,"length":68} + >greet() + > { + > return "

" + this.greeting + "

"; + > } + >:=> (line 26, col 4) to (line 29, col 5) -------------------------------- 27 > { @@ -249,9 +260,12 @@ -------------------------------- 32 > private fn() - ~~~~~~~~~~~~~~~~~ => Pos: (628 to 644) SpanInfo: {"start":659,"length":20} - >return this.greeting - >:=> (line 34, col 8) to (line 34, col 28) + ~~~~~~~~~~~~~~~~~ => Pos: (628 to 644) SpanInfo: {"start":632,"length":54} + >private fn() + > { + > return this.greeting; + > } + >:=> (line 32, col 4) to (line 35, col 5) -------------------------------- 33 > { @@ -273,9 +287,12 @@ -------------------------------- 36 > get greetings() - ~~~~~~~~~~~~~~~~~~~~~ => Pos: (687 to 707) SpanInfo: {"start":722,"length":20} - >return this.greeting - >:=> (line 38, col 8) to (line 38, col 28) + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (687 to 707) SpanInfo: {"start":691,"length":58} + >get greetings() + > { + > return this.greeting; + > } + >:=> (line 36, col 4) to (line 39, col 5) -------------------------------- 37 > { @@ -297,9 +314,12 @@ -------------------------------- 40 > set greetings(greetings: string) - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (750 to 786) SpanInfo: {"start":801,"length":25} - >this.greeting = greetings - >:=> (line 42, col 8) to (line 42, col 33) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (750 to 786) SpanInfo: {"start":754,"length":79} + >set greetings(greetings: string) + > { + > this.greeting = greetings; + > } + >:=> (line 40, col 4) to (line 43, col 5) -------------------------------- 41 > { diff --git a/tests/baselines/reference/bpSpan_classes.baseline b/tests/baselines/reference/bpSpan_classes.baseline index e9de5123d1c..811109af835 100644 --- a/tests/baselines/reference/bpSpan_classes.baseline +++ b/tests/baselines/reference/bpSpan_classes.baseline @@ -131,9 +131,11 @@ -------------------------------- 8 > greet() { - ~~~~~~~~~~~~~~~~~~ => Pos: (114 to 131) SpanInfo: {"start":144,"length":39} - >return "

" + this.greeting + "

" - >:=> (line 9, col 12) to (line 9, col 51) + ~~~~~~~~~~~~~~~~~~ => Pos: (114 to 131) SpanInfo: {"start":122,"length":72} + >greet() { + > return "

" + this.greeting + "

"; + > } + >:=> (line 8, col 8) to (line 10, col 9) -------------------------------- 9 > return "

" + this.greeting + "

"; From e87f18cc635d140c5e849c7a48082d759ccab4eb Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 21 Oct 2014 18:09:05 -0700 Subject: [PATCH 54/63] Exported variables can have breakpoint even if they do not have initializer --- src/services/breakpoints.ts | 2 +- .../reference/bpSpan_variables.baseline | 71 ++++++++++++++++++- .../breakpointValidationVariables.ts | 8 +++ 3 files changed, 78 insertions(+), 3 deletions(-) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index a7e5613a477..13c9386353f 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -270,7 +270,7 @@ module ts.BreakpointResolver { : undefined; // Breakpoint is possible in variableDeclaration only if there is initialization - if (variableDeclaration.initializer) { + if (variableDeclaration.initializer || (variableDeclaration.flags & NodeFlags.Export)) { if (declarations && declarations[0] === variableDeclaration) { if (isParentVariableStatement) { // First declaration - include var keyword diff --git a/tests/baselines/reference/bpSpan_variables.baseline b/tests/baselines/reference/bpSpan_variables.baseline index 1dbb80512f5..1904c34b835 100644 --- a/tests/baselines/reference/bpSpan_variables.baseline +++ b/tests/baselines/reference/bpSpan_variables.baseline @@ -16,8 +16,75 @@ >:=> (line 3, col 0) to (line 3, col 10) -------------------------------- 4 >var c2, d2 = 10; + ~~~~~~~ => Pos: (37 to 43) SpanInfo: undefined 4 >var c2, d2 = 10; - ~~~~~~~~~ => Pos: (44 to 52) SpanInfo: {"start":45,"length":7} + + ~~~~~~~~~~ => Pos: (44 to 53) SpanInfo: {"start":45,"length":7} >d2 = 10 - >:=> (line 4, col 8) to (line 4, col 15) \ No newline at end of file + >:=> (line 4, col 8) to (line 4, col 15) +-------------------------------- +5 >module m { + + ~~~~~~~~~~~ => Pos: (54 to 64) SpanInfo: {"start":54,"length":146} + >module m { + > var x1; + > var x2 = 10, x3 = 10; + > var x4, x5; + > export var xx1; + > export var xx2 = 10, xx3 = 10; + > export var xx4, xx5; + >} + >:=> (line 5, col 0) to (line 12, col 1) +-------------------------------- +6 > var x1; + + ~~~~~~~~~~~~ => Pos: (65 to 76) SpanInfo: undefined +-------------------------------- +7 > var x2 = 10, x3 = 10; + + ~~~~~~~~~~~~~~~~ => Pos: (77 to 92) SpanInfo: {"start":81,"length":11} + >var x2 = 10 + >:=> (line 7, col 4) to (line 7, col 15) +7 > var x2 = 10, x3 = 10; + + ~~~~~~~~~~ => Pos: (93 to 102) SpanInfo: {"start":94,"length":7} + >x3 = 10 + >:=> (line 7, col 17) to (line 7, col 24) +-------------------------------- +8 > var x4, x5; + + ~~~~~~~~~~~~~~~~ => Pos: (103 to 118) SpanInfo: undefined +-------------------------------- +9 > export var xx1; + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (119 to 138) SpanInfo: {"start":123,"length":14} + >export var xx1 + >:=> (line 9, col 4) to (line 9, col 18) +-------------------------------- +10 > export var xx2 = 10, xx3 = 10; + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (139 to 162) SpanInfo: {"start":143,"length":19} + >export var xx2 = 10 + >:=> (line 10, col 4) to (line 10, col 23) +10 > export var xx2 = 10, xx3 = 10; + + ~~~~~~~~~~~ => Pos: (163 to 173) SpanInfo: {"start":164,"length":8} + >xx3 = 10 + >:=> (line 10, col 25) to (line 10, col 33) +-------------------------------- +11 > export var xx4, xx5; + + ~~~~~~~~~~~~~~~~~~~ => Pos: (174 to 192) SpanInfo: {"start":178,"length":14} + >export var xx4 + >:=> (line 11, col 4) to (line 11, col 18) +11 > export var xx4, xx5; + + ~~~~~~ => Pos: (193 to 198) SpanInfo: {"start":194,"length":3} + >xx5 + >:=> (line 11, col 20) to (line 11, col 23) +-------------------------------- +12 >} + ~ => Pos: (199 to 199) SpanInfo: {"start":199,"length":1} + >} + >:=> (line 12, col 0) to (line 12, col 1) \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationVariables.ts b/tests/cases/fourslash/breakpointValidationVariables.ts index 3f581ac80f7..054826e7e09 100644 --- a/tests/cases/fourslash/breakpointValidationVariables.ts +++ b/tests/cases/fourslash/breakpointValidationVariables.ts @@ -6,5 +6,13 @@ ////var b; ////var c = 10, d, e; ////var c2, d2 = 10; +////module m { +//// var x1; +//// var x2 = 10, x3 = 10; +//// var x4, x5; +//// export var xx1; +//// export var xx2 = 10, xx3 = 10; +//// export var xx4, xx5; +////} verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file From 3f2211f463a43354c913a33bfb4386174b1da7d3 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 22 Oct 2014 11:13:56 -0700 Subject: [PATCH 55/63] Code review feedback update --- src/services/breakpoints.ts | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 13c9386353f..3a72ee9bfa6 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -265,9 +265,9 @@ module ts.BreakpointResolver { var isDeclarationOfForStatement = variableDeclaration.parent.kind === SyntaxKind.ForStatement && contains((variableDeclaration.parent).declarations, variableDeclaration); var declarations = isParentVariableStatement ? (variableDeclaration.parent).declarations - : isDeclarationOfForStatement - ? (variableDeclaration.parent).declarations - : undefined; + : isDeclarationOfForStatement + ? (variableDeclaration.parent).declarations + : undefined; // Breakpoint is possible in variableDeclaration only if there is initialization if (variableDeclaration.initializer || (variableDeclaration.flags & NodeFlags.Export)) { @@ -347,16 +347,6 @@ module ts.BreakpointResolver { return spanInNode(nodeForSpanInBlock); } - function spanInFirstStatementOfBlock(block: Block): TypeScript.TextSpan { - // Set breakpoint in first statement - return spanInNode(block.statements[0]); - } - - function spanInLastStatementOfBlock(block: Block): TypeScript.TextSpan { - // Set breakpoint in first statement - return spanInNode(block.statements[block.statements.length - 1]); - } - function spanInBlock(block: Block): TypeScript.TextSpan { switch (block.parent.kind) { case SyntaxKind.ModuleDeclaration: @@ -376,7 +366,7 @@ module ts.BreakpointResolver { } // Default action is to set on first statement - return spanInFirstStatementOfBlock(block); + return spanInNode(block.statements[0]); } function spanInForStatement(forStatement: ForStatement): TypeScript.TextSpan { @@ -389,7 +379,6 @@ module ts.BreakpointResolver { if (forStatement.condition) { return textSpan(forStatement.condition); } - if (forStatement.iterator) { return textSpan(forStatement.iterator); } @@ -432,7 +421,7 @@ module ts.BreakpointResolver { case SyntaxKind.TryBlock: case SyntaxKind.CatchBlock: case SyntaxKind.FinallyBlock: - return spanInLastStatementOfBlock(node.parent); + return spanInNode((node.parent).statements[(node.parent).statements.length - 1]);; case SyntaxKind.SwitchStatement: // breakpoint in last statement of the last clause From 32606ac1b6a99dfe96595a39664292fe3b552067 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 22 Oct 2014 15:56:00 -0700 Subject: [PATCH 56/63] Addressed CR feedback. --- src/services/services.ts | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 6afbe11c554..09be4ef63ec 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4782,7 +4782,7 @@ module ts { var sourceFile = getCurrentSourceFile(fileName); var result: ClassifiedSpan[] = []; - processElement(sourceFile, sourceFile); + processElement(sourceFile); return result; @@ -4796,11 +4796,11 @@ module ts { } } - function classifyToken(token: Node, tokenOwner: Node, sourceFile: SourceFile): void { + function classifyToken(token: Node): void { forEach(getLeadingCommentRanges(sourceFile.text, token.getFullStart()), classifyComment); if (token.getWidth() > 0) { - var type = classifyTokenType(token, tokenOwner); + var type = classifyTokenType(token); if (type) { result.push({ textSpan: new TypeScript.TextSpan(token.getStart(), token.getWidth()), @@ -4812,7 +4812,7 @@ module ts { forEach(getTrailingCommentRanges(sourceFile.text, token.getEnd()), classifyComment); } - function classifyTokenType(token: Node, tokenOwner: Node): string { + function classifyTokenType(token: Node): string { var tokenKind = token.kind; if (isKeyword(tokenKind)) { return ClassificationTypeNames.keyword; @@ -4821,20 +4821,20 @@ module ts { // Special case < and > If they appear in a generic context they are punctuation, // not operators. if (tokenKind === SyntaxKind.LessThanToken || tokenKind === SyntaxKind.GreaterThanToken) { - var tokenParentKind = token.parent.kind; // If the node owning the token has a type argument list or type parameter list, then // we can effectively assume that a '<' and '>' belong to those lists. - if (getTypeArgumentOrTypeParameterList(tokenOwner)) { + if (getTypeArgumentOrTypeParameterList(token.parent)) { return ClassificationTypeNames.punctuation; } } if (isPunctuation(token)) { - if (tokenOwner.kind === SyntaxKind.BinaryExpression || - tokenOwner.kind === SyntaxKind.VariableDeclaration || // the '=' in a variable declaration is special cased here. - tokenOwner.kind === SyntaxKind.PrefixOperator || - tokenOwner.kind === SyntaxKind.PostfixOperator || - tokenOwner.kind === SyntaxKind.ConditionalExpression) { + // the '=' in a variable declaration is special cased here. + if (token.parent.kind === SyntaxKind.BinaryExpression || + token.parent.kind === SyntaxKind.VariableDeclaration || + token.parent.kind === SyntaxKind.PrefixOperator || + token.parent.kind === SyntaxKind.PostfixOperator || + token.parent.kind === SyntaxKind.ConditionalExpression) { return ClassificationTypeNames.operator; } else { @@ -4852,29 +4852,29 @@ module ts { return ClassificationTypeNames.stringLiteral; } else if (tokenKind === SyntaxKind.Identifier) { - switch (tokenOwner.kind) { + switch (token.parent.kind) { case SyntaxKind.ClassDeclaration: - if ((tokenOwner).name === token) { + if ((token.parent).name === token) { return ClassificationTypeNames.className; } return; case SyntaxKind.TypeParameter: - if ((tokenOwner).name === token) { + if ((token.parent).name === token) { return ClassificationTypeNames.typeParameterName; } return; case SyntaxKind.InterfaceDeclaration: - if ((tokenOwner).name === token) { + if ((token.parent).name === token) { return ClassificationTypeNames.interfaceName; } return; case SyntaxKind.EnumDeclaration: - if ((tokenOwner).name === token) { + if ((token.parent).name === token) { return ClassificationTypeNames.enumName; } return; case SyntaxKind.ModuleDeclaration: - if ((tokenOwner).name === token) { + if ((token.parent).name === token) { return ClassificationTypeNames.moduleName; } return; @@ -4884,18 +4884,18 @@ module ts { } } - function processElement(element: Node, sourceFile: SourceFile) { + function processElement(element: Node) { // Ignore nodes that don't intersect the original span to classify. if (span.intersectsWith(element.getFullStart(), element.getFullWidth())) { var children = element.getChildren(); for (var i = 0, n = children.length; i < n; i++) { var child = children[i]; if (isToken(child)) { - classifyToken(child, element, sourceFile); + classifyToken(child); } else { // Recurse into our child nodes. - processElement(child, sourceFile); + processElement(child); } } } From 10a7e6ba70ce41038625e9039aaf580e232fd5fd Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 22 Oct 2014 16:57:43 -0700 Subject: [PATCH 57/63] Fixing in, for...in, and instanceof with union type operands --- src/compiler/checker.ts | 18 +++++++++++------- src/compiler/types.ts | 1 + .../inOperatorWithInvalidOperands.ts | 13 ++++++++----- .../inOperator/inOperatorWithValidOperands.ts | 12 +++++++++++- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 229fcf51f17..6f10e145fd3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4143,8 +4143,8 @@ module ts { // Get the narrowed type of a given symbol at a given location function getNarrowedTypeOfSymbol(symbol: Symbol, node: Node) { var type = getTypeOfSymbol(symbol); - // Only narrow when symbol is variable of a non-primitive type - if (symbol.flags & SymbolFlags.Variable && isTypeAnyOrObjectOrTypeParameter(type)) { + // Only narrow when symbol is variable of a structured type + if (symbol.flags & SymbolFlags.Variable && type.flags & TypeFlags.Structured) { while (true) { var child = node; node = node.parent; @@ -5679,8 +5679,12 @@ module ts { return numberType; } - function isTypeAnyOrObjectOrTypeParameter(type: Type): boolean { - return (type.flags & (TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter)) !== 0; + // Return true if type is any, an object type, a type parameter, or a union type composed of only those kinds of types + function isStructuredType(type: Type): boolean { + if (type.flags & TypeFlags.Union) { + return !forEach((type).types, t => !isStructuredType(t)); + } + return (type.flags & TypeFlags.Structured) !== 0; } function checkInstanceOfExpression(node: BinaryExpression, leftType: Type, rightType: Type): Type { @@ -5689,7 +5693,7 @@ module ts { // and the right operand to be of type Any or a subtype of the 'Function' interface type. // The result is always of the Boolean primitive type. // NOTE: do not raise error if leftType is unknown as related error was already reported - if (leftType !== unknownType && !isTypeAnyOrObjectOrTypeParameter(leftType)) { + if (leftType !== unknownType && !isStructuredType(leftType)) { error(node.left, Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } // NOTE: do not raise error if right is unknown as related error was already reported @@ -5707,7 +5711,7 @@ module ts { if (leftType !== anyType && leftType !== stringType && leftType !== numberType) { error(node.left, Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_types_any_string_or_number); } - if (!isTypeAnyOrObjectOrTypeParameter(rightType)) { + if (!isStructuredType(rightType)) { error(node.right, Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; @@ -6928,7 +6932,7 @@ module ts { var exprType = checkExpression(node.expression); // unknownType is returned i.e. if node.expression is identifier whose name cannot be resolved // in this case error about missing name is already reported - do not report extra one - if (!isTypeAnyOrObjectOrTypeParameter(exprType) && exprType !== unknownType) { + if (!isStructuredType(exprType) && exprType !== unknownType) { error(node.expression, Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index ea58b1166c6..48c74d8f2af 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -909,6 +909,7 @@ module ts { StringLike = String | StringLiteral, NumberLike = Number | Enum, ObjectType = Class | Interface | Reference | Tuple | Anonymous, + Structured = Any | ObjectType | Union | TypeParameter } // Properties common to all types diff --git a/tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts b/tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts index c0c93155671..0c6f1403220 100644 --- a/tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts +++ b/tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts @@ -25,16 +25,19 @@ var b1: number; var b2: boolean; var b3: string; var b4: void; +var b5: string | number; var rb1 = x in b1; var rb2 = x in b2; var rb3 = x in b3; var rb4 = x in b4; -var rb5 = x in 0; -var rb6 = x in false; -var rb7 = x in ''; -var rb8 = x in null; -var rb9 = x in undefined; +var rb5 = x in b5; +var rb6 = x in 0; +var rb7 = x in false; +var rb8 = x in ''; +var rb9 = x in null; +var rb10 = x in undefined; + // both operands are invalid var rc1 = {} in ''; \ No newline at end of file diff --git a/tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithValidOperands.ts b/tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithValidOperands.ts index 400d59fff65..a4cdfd00a6b 100644 --- a/tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithValidOperands.ts +++ b/tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithValidOperands.ts @@ -20,4 +20,14 @@ var rb2 = x in {}; function foo(t: T) { var rb3 = x in t; -} \ No newline at end of file +} + +interface X { x: number } +interface Y { y: number } + +var c1: X | Y; +var c2: X; +var c3: Y; + +var rc1 = x in c1; +var rc2 = x in (c2 || c3); From 5505371c5a3dc2e7f5b3bd21aa15b4f6e96ea537 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 22 Oct 2014 16:58:13 -0700 Subject: [PATCH 58/63] Accepting new baselines --- .../inOperatorWithInvalidOperands.errors.txt | 34 ++++++++++------- .../inOperatorWithInvalidOperands.js | 25 ++++++++----- .../reference/inOperatorWithValidOperands.js | 18 ++++++++- .../inOperatorWithValidOperands.types | 37 +++++++++++++++++++ 4 files changed, 89 insertions(+), 25 deletions(-) diff --git a/tests/baselines/reference/inOperatorWithInvalidOperands.errors.txt b/tests/baselines/reference/inOperatorWithInvalidOperands.errors.txt index 9411d016dcb..5f538eef40c 100644 --- a/tests/baselines/reference/inOperatorWithInvalidOperands.errors.txt +++ b/tests/baselines/reference/inOperatorWithInvalidOperands.errors.txt @@ -7,7 +7,6 @@ tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInv tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(18,11): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(19,11): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(20,11): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. -tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(29,16): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(30,16): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(31,16): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(32,16): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter @@ -16,11 +15,13 @@ tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInv tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(35,16): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(36,16): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(37,16): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter -tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(40,11): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. -tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(40,17): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter +tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(38,16): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter +tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(39,17): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter +tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(43,11): error TS2360: The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'. +tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(43,17): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter -==== tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts (20 errors) ==== +==== tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts (21 errors) ==== enum E { a } var x: any; @@ -66,6 +67,7 @@ tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInv var b2: boolean; var b3: string; var b4: void; + var b5: string | number; var rb1 = x in b1; ~~ @@ -79,22 +81,26 @@ tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInv var rb4 = x in b4; ~~ !!! error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter - var rb5 = x in 0; - ~ -!!! error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter - var rb6 = x in false; - ~~~~~ -!!! error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter - var rb7 = x in ''; + var rb5 = x in b5; ~~ !!! error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter - var rb8 = x in null; + var rb6 = x in 0; + ~ +!!! error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter + var rb7 = x in false; + ~~~~~ +!!! error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter + var rb8 = x in ''; + ~~ +!!! error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter + var rb9 = x in null; ~~~~ !!! error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter - var rb9 = x in undefined; - ~~~~~~~~~ + var rb10 = x in undefined; + ~~~~~~~~~ !!! error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter + // both operands are invalid var rc1 = {} in ''; ~~ diff --git a/tests/baselines/reference/inOperatorWithInvalidOperands.js b/tests/baselines/reference/inOperatorWithInvalidOperands.js index eb117aafde3..29293f880ed 100644 --- a/tests/baselines/reference/inOperatorWithInvalidOperands.js +++ b/tests/baselines/reference/inOperatorWithInvalidOperands.js @@ -26,16 +26,19 @@ var b1: number; var b2: boolean; var b3: string; var b4: void; +var b5: string | number; var rb1 = x in b1; var rb2 = x in b2; var rb3 = x in b3; var rb4 = x in b4; -var rb5 = x in 0; -var rb6 = x in false; -var rb7 = x in ''; -var rb8 = x in null; -var rb9 = x in undefined; +var rb5 = x in b5; +var rb6 = x in 0; +var rb7 = x in false; +var rb8 = x in ''; +var rb9 = x in null; +var rb10 = x in undefined; + // both operands are invalid var rc1 = {} in ''; @@ -67,14 +70,16 @@ var b1; var b2; var b3; var b4; +var b5; var rb1 = x in b1; var rb2 = x in b2; var rb3 = x in b3; var rb4 = x in b4; -var rb5 = x in 0; -var rb6 = x in false; -var rb7 = x in ''; -var rb8 = x in null; -var rb9 = x in undefined; +var rb5 = x in b5; +var rb6 = x in 0; +var rb7 = x in false; +var rb8 = x in ''; +var rb9 = x in null; +var rb10 = x in undefined; // both operands are invalid var rc1 = {} in ''; diff --git a/tests/baselines/reference/inOperatorWithValidOperands.js b/tests/baselines/reference/inOperatorWithValidOperands.js index 16df96f22fb..561abbe340b 100644 --- a/tests/baselines/reference/inOperatorWithValidOperands.js +++ b/tests/baselines/reference/inOperatorWithValidOperands.js @@ -21,7 +21,18 @@ var rb2 = x in {}; function foo(t: T) { var rb3 = x in t; -} +} + +interface X { x: number } +interface Y { y: number } + +var c1: X | Y; +var c2: X; +var c3: Y; + +var rc1 = x in c1; +var rc2 = x in (c2 || c3); + //// [inOperatorWithValidOperands.js] var x; @@ -42,3 +53,8 @@ var rb2 = x in {}; function foo(t) { var rb3 = x in t; } +var c1; +var c2; +var c3; +var rc1 = x in c1; +var rc2 = x in (c2 || c3); diff --git a/tests/baselines/reference/inOperatorWithValidOperands.types b/tests/baselines/reference/inOperatorWithValidOperands.types index f621c3bf55d..27ba22055bf 100644 --- a/tests/baselines/reference/inOperatorWithValidOperands.types +++ b/tests/baselines/reference/inOperatorWithValidOperands.types @@ -67,3 +67,40 @@ function foo(t: T) { >x : any >t : T } + +interface X { x: number } +>X : X +>x : number + +interface Y { y: number } +>Y : Y +>y : number + +var c1: X | Y; +>c1 : X | Y +>X : X +>Y : Y + +var c2: X; +>c2 : X +>X : X + +var c3: Y; +>c3 : Y +>Y : Y + +var rc1 = x in c1; +>rc1 : boolean +>x in c1 : boolean +>x : any +>c1 : X | Y + +var rc2 = x in (c2 || c3); +>rc2 : boolean +>x in (c2 || c3) : boolean +>x : any +>(c2 || c3) : X | Y +>c2 || c3 : X | Y +>c2 : X +>c3 : Y + From c514b9231d321d258d329082ca085e508cc3d89c Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 23 Oct 2014 13:43:22 -0700 Subject: [PATCH 59/63] Actually removed reference to the diagnostics file. Addresses the original intention of #932. --- src/compiler/sys.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 57ad0260cb6..d685a30d959 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -1,4 +1,3 @@ -/// interface System { args: string[]; From db9c9f1072ff2c497b3f69c8d0456363443fd861 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 23 Oct 2014 15:04:27 -0700 Subject: [PATCH 60/63] Update LKG --- bin/tsc.js | 4038 ++++++++++++-------- bin/typescriptServices.js | 7510 +++++++++++++++++++++++-------------- 2 files changed, 7231 insertions(+), 4317 deletions(-) diff --git a/bin/tsc.js b/bin/tsc.js index 07cccb86d1b..bb432bf9c47 100644 --- a/bin/tsc.js +++ b/bin/tsc.js @@ -19,6 +19,7 @@ var ts; Unterminated_string_literal: { code: 1002, category: 1 /* Error */, key: "Unterminated string literal." }, Identifier_expected: { code: 1003, category: 1 /* Error */, key: "Identifier expected." }, _0_expected: { code: 1005, category: 1 /* Error */, key: "'{0}' expected." }, + A_file_cannot_have_a_reference_to_itself: { code: 1006, category: 1 /* Error */, key: "A file cannot have a reference to itself." }, Trailing_comma_not_allowed: { code: 1009, category: 1 /* Error */, key: "Trailing comma not allowed." }, Asterisk_Slash_expected: { code: 1010, category: 1 /* Error */, key: "'*/' expected." }, Unexpected_token: { code: 1012, category: 1 /* Error */, key: "Unexpected token." }, @@ -127,6 +128,7 @@ var ts; Cannot_compile_external_modules_unless_the_module_flag_is_provided: { code: 1148, category: 1 /* Error */, key: "Cannot compile external modules unless the '--module' flag is provided." }, Filename_0_differs_from_already_included_filename_1_only_in_casing: { code: 1149, category: 1 /* Error */, key: "Filename '{0}' differs from already included filename '{1}' only in casing" }, new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: 1 /* Error */, key: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, + An_enum_member_cannot_have_a_numeric_name: { code: 1151, category: 1 /* Error */, key: "An enum member cannot have a numeric name." }, Duplicate_identifier_0: { code: 2300, category: 1 /* Error */, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: 1 /* Error */, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: 1 /* Error */, key: "Static members cannot reference class type parameters." }, @@ -193,8 +195,6 @@ var ts; The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type: { code: 2363, category: 1 /* Error */, key: "The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type." }, Invalid_left_hand_side_of_assignment_expression: { code: 2364, category: 1 /* Error */, key: "Invalid left-hand side of assignment expression." }, Operator_0_cannot_be_applied_to_types_1_and_2: { code: 2365, category: 1 /* Error */, key: "Operator '{0}' cannot be applied to types '{1}' and '{2}'." }, - No_best_common_type_exists_between_0_1_and_2: { code: 2366, category: 1 /* Error */, key: "No best common type exists between '{0}', '{1}', and '{2}'." }, - No_best_common_type_exists_between_0_and_1: { code: 2367, category: 1 /* Error */, key: "No best common type exists between '{0}' and '{1}'." }, Type_parameter_name_cannot_be_0: { code: 2368, category: 1 /* Error */, key: "Type parameter name cannot be '{0}'" }, A_parameter_property_is_only_allowed_in_a_constructor_implementation: { code: 2369, category: 1 /* Error */, key: "A parameter property is only allowed in a constructor implementation." }, A_rest_parameter_must_be_of_an_array_type: { code: 2370, category: 1 /* Error */, key: "A rest parameter must be of an array type." }, @@ -274,6 +274,7 @@ var ts; Property_0_is_protected_in_type_1_but_public_in_type_2: { code: 2444, category: 1 /* Error */, key: "Property '{0}' is protected in type '{1}' but public in type '{2}'." }, Property_0_is_protected_and_only_accessible_within_class_1_and_its_subclasses: { code: 2445, category: 1 /* Error */, key: "Property '{0}' is protected and only accessible within class '{1}' and its subclasses." }, Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1: { code: 2446, category: 1 /* Error */, key: "Property '{0}' is protected and only accessible through an instance of class '{1}'." }, + The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead: { code: 2447, category: 1 /* Error */, key: "The '{0}' operator is not allowed for boolean types. Consider using '{1}' instead." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: 1 /* Error */, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4001, category: 1 /* Error */, key: "Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: 1 /* Error */, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, @@ -758,14 +759,14 @@ var ts; return result; } } - function getLeadingComments(text, pos) { + function getLeadingCommentRanges(text, pos) { return getCommentRanges(text, pos, false); } - ts.getLeadingComments = getLeadingComments; - function getTrailingComments(text, pos) { + ts.getLeadingCommentRanges = getLeadingCommentRanges; + function getTrailingCommentRanges(text, pos) { return getCommentRanges(text, pos, true); } - ts.getTrailingComments = getTrailingComments; + ts.getTrailingCommentRanges = getTrailingCommentRanges; function isIdentifierStart(ch, languageVersion) { return ch >= 65 /* A */ && ch <= 90 /* Z */ || ch >= 97 /* a */ && ch <= 122 /* z */ || ch === 36 /* $ */ || ch === 95 /* _ */ || ch > 127 /* maxAsciiCharacter */ && isUnicodeIdentifierStart(ch, languageVersion); } @@ -1492,60 +1493,62 @@ var ts; SyntaxKind[SyntaxKind["TypeLiteral"] = 129] = "TypeLiteral"; SyntaxKind[SyntaxKind["ArrayType"] = 130] = "ArrayType"; SyntaxKind[SyntaxKind["TupleType"] = 131] = "TupleType"; - SyntaxKind[SyntaxKind["ArrayLiteral"] = 132] = "ArrayLiteral"; - SyntaxKind[SyntaxKind["ObjectLiteral"] = 133] = "ObjectLiteral"; - SyntaxKind[SyntaxKind["PropertyAssignment"] = 134] = "PropertyAssignment"; - SyntaxKind[SyntaxKind["PropertyAccess"] = 135] = "PropertyAccess"; - SyntaxKind[SyntaxKind["IndexedAccess"] = 136] = "IndexedAccess"; - SyntaxKind[SyntaxKind["CallExpression"] = 137] = "CallExpression"; - SyntaxKind[SyntaxKind["NewExpression"] = 138] = "NewExpression"; - SyntaxKind[SyntaxKind["TypeAssertion"] = 139] = "TypeAssertion"; - SyntaxKind[SyntaxKind["ParenExpression"] = 140] = "ParenExpression"; - SyntaxKind[SyntaxKind["FunctionExpression"] = 141] = "FunctionExpression"; - SyntaxKind[SyntaxKind["ArrowFunction"] = 142] = "ArrowFunction"; - SyntaxKind[SyntaxKind["PrefixOperator"] = 143] = "PrefixOperator"; - SyntaxKind[SyntaxKind["PostfixOperator"] = 144] = "PostfixOperator"; - SyntaxKind[SyntaxKind["BinaryExpression"] = 145] = "BinaryExpression"; - SyntaxKind[SyntaxKind["ConditionalExpression"] = 146] = "ConditionalExpression"; - SyntaxKind[SyntaxKind["OmittedExpression"] = 147] = "OmittedExpression"; - SyntaxKind[SyntaxKind["Block"] = 148] = "Block"; - SyntaxKind[SyntaxKind["VariableStatement"] = 149] = "VariableStatement"; - SyntaxKind[SyntaxKind["EmptyStatement"] = 150] = "EmptyStatement"; - SyntaxKind[SyntaxKind["ExpressionStatement"] = 151] = "ExpressionStatement"; - SyntaxKind[SyntaxKind["IfStatement"] = 152] = "IfStatement"; - SyntaxKind[SyntaxKind["DoStatement"] = 153] = "DoStatement"; - SyntaxKind[SyntaxKind["WhileStatement"] = 154] = "WhileStatement"; - SyntaxKind[SyntaxKind["ForStatement"] = 155] = "ForStatement"; - SyntaxKind[SyntaxKind["ForInStatement"] = 156] = "ForInStatement"; - SyntaxKind[SyntaxKind["ContinueStatement"] = 157] = "ContinueStatement"; - SyntaxKind[SyntaxKind["BreakStatement"] = 158] = "BreakStatement"; - SyntaxKind[SyntaxKind["ReturnStatement"] = 159] = "ReturnStatement"; - SyntaxKind[SyntaxKind["WithStatement"] = 160] = "WithStatement"; - SyntaxKind[SyntaxKind["SwitchStatement"] = 161] = "SwitchStatement"; - SyntaxKind[SyntaxKind["CaseClause"] = 162] = "CaseClause"; - SyntaxKind[SyntaxKind["DefaultClause"] = 163] = "DefaultClause"; - SyntaxKind[SyntaxKind["LabeledStatement"] = 164] = "LabeledStatement"; - SyntaxKind[SyntaxKind["ThrowStatement"] = 165] = "ThrowStatement"; - SyntaxKind[SyntaxKind["TryStatement"] = 166] = "TryStatement"; - SyntaxKind[SyntaxKind["TryBlock"] = 167] = "TryBlock"; - SyntaxKind[SyntaxKind["CatchBlock"] = 168] = "CatchBlock"; - SyntaxKind[SyntaxKind["FinallyBlock"] = 169] = "FinallyBlock"; - SyntaxKind[SyntaxKind["DebuggerStatement"] = 170] = "DebuggerStatement"; - SyntaxKind[SyntaxKind["VariableDeclaration"] = 171] = "VariableDeclaration"; - SyntaxKind[SyntaxKind["FunctionDeclaration"] = 172] = "FunctionDeclaration"; - SyntaxKind[SyntaxKind["FunctionBlock"] = 173] = "FunctionBlock"; - SyntaxKind[SyntaxKind["ClassDeclaration"] = 174] = "ClassDeclaration"; - SyntaxKind[SyntaxKind["InterfaceDeclaration"] = 175] = "InterfaceDeclaration"; - SyntaxKind[SyntaxKind["EnumDeclaration"] = 176] = "EnumDeclaration"; - SyntaxKind[SyntaxKind["ModuleDeclaration"] = 177] = "ModuleDeclaration"; - SyntaxKind[SyntaxKind["ModuleBlock"] = 178] = "ModuleBlock"; - SyntaxKind[SyntaxKind["ImportDeclaration"] = 179] = "ImportDeclaration"; - SyntaxKind[SyntaxKind["ExportAssignment"] = 180] = "ExportAssignment"; - SyntaxKind[SyntaxKind["EnumMember"] = 181] = "EnumMember"; - SyntaxKind[SyntaxKind["SourceFile"] = 182] = "SourceFile"; - SyntaxKind[SyntaxKind["Program"] = 183] = "Program"; - SyntaxKind[SyntaxKind["SyntaxList"] = 184] = "SyntaxList"; - SyntaxKind[SyntaxKind["Count"] = 185] = "Count"; + SyntaxKind[SyntaxKind["UnionType"] = 132] = "UnionType"; + SyntaxKind[SyntaxKind["ParenType"] = 133] = "ParenType"; + SyntaxKind[SyntaxKind["ArrayLiteral"] = 134] = "ArrayLiteral"; + SyntaxKind[SyntaxKind["ObjectLiteral"] = 135] = "ObjectLiteral"; + SyntaxKind[SyntaxKind["PropertyAssignment"] = 136] = "PropertyAssignment"; + SyntaxKind[SyntaxKind["PropertyAccess"] = 137] = "PropertyAccess"; + SyntaxKind[SyntaxKind["IndexedAccess"] = 138] = "IndexedAccess"; + SyntaxKind[SyntaxKind["CallExpression"] = 139] = "CallExpression"; + SyntaxKind[SyntaxKind["NewExpression"] = 140] = "NewExpression"; + SyntaxKind[SyntaxKind["TypeAssertion"] = 141] = "TypeAssertion"; + SyntaxKind[SyntaxKind["ParenExpression"] = 142] = "ParenExpression"; + SyntaxKind[SyntaxKind["FunctionExpression"] = 143] = "FunctionExpression"; + SyntaxKind[SyntaxKind["ArrowFunction"] = 144] = "ArrowFunction"; + SyntaxKind[SyntaxKind["PrefixOperator"] = 145] = "PrefixOperator"; + SyntaxKind[SyntaxKind["PostfixOperator"] = 146] = "PostfixOperator"; + SyntaxKind[SyntaxKind["BinaryExpression"] = 147] = "BinaryExpression"; + SyntaxKind[SyntaxKind["ConditionalExpression"] = 148] = "ConditionalExpression"; + SyntaxKind[SyntaxKind["OmittedExpression"] = 149] = "OmittedExpression"; + SyntaxKind[SyntaxKind["Block"] = 150] = "Block"; + SyntaxKind[SyntaxKind["VariableStatement"] = 151] = "VariableStatement"; + SyntaxKind[SyntaxKind["EmptyStatement"] = 152] = "EmptyStatement"; + SyntaxKind[SyntaxKind["ExpressionStatement"] = 153] = "ExpressionStatement"; + SyntaxKind[SyntaxKind["IfStatement"] = 154] = "IfStatement"; + SyntaxKind[SyntaxKind["DoStatement"] = 155] = "DoStatement"; + SyntaxKind[SyntaxKind["WhileStatement"] = 156] = "WhileStatement"; + SyntaxKind[SyntaxKind["ForStatement"] = 157] = "ForStatement"; + SyntaxKind[SyntaxKind["ForInStatement"] = 158] = "ForInStatement"; + SyntaxKind[SyntaxKind["ContinueStatement"] = 159] = "ContinueStatement"; + SyntaxKind[SyntaxKind["BreakStatement"] = 160] = "BreakStatement"; + SyntaxKind[SyntaxKind["ReturnStatement"] = 161] = "ReturnStatement"; + SyntaxKind[SyntaxKind["WithStatement"] = 162] = "WithStatement"; + SyntaxKind[SyntaxKind["SwitchStatement"] = 163] = "SwitchStatement"; + SyntaxKind[SyntaxKind["CaseClause"] = 164] = "CaseClause"; + SyntaxKind[SyntaxKind["DefaultClause"] = 165] = "DefaultClause"; + SyntaxKind[SyntaxKind["LabeledStatement"] = 166] = "LabeledStatement"; + SyntaxKind[SyntaxKind["ThrowStatement"] = 167] = "ThrowStatement"; + SyntaxKind[SyntaxKind["TryStatement"] = 168] = "TryStatement"; + SyntaxKind[SyntaxKind["TryBlock"] = 169] = "TryBlock"; + SyntaxKind[SyntaxKind["CatchBlock"] = 170] = "CatchBlock"; + SyntaxKind[SyntaxKind["FinallyBlock"] = 171] = "FinallyBlock"; + SyntaxKind[SyntaxKind["DebuggerStatement"] = 172] = "DebuggerStatement"; + SyntaxKind[SyntaxKind["VariableDeclaration"] = 173] = "VariableDeclaration"; + SyntaxKind[SyntaxKind["FunctionDeclaration"] = 174] = "FunctionDeclaration"; + SyntaxKind[SyntaxKind["FunctionBlock"] = 175] = "FunctionBlock"; + SyntaxKind[SyntaxKind["ClassDeclaration"] = 176] = "ClassDeclaration"; + SyntaxKind[SyntaxKind["InterfaceDeclaration"] = 177] = "InterfaceDeclaration"; + SyntaxKind[SyntaxKind["EnumDeclaration"] = 178] = "EnumDeclaration"; + SyntaxKind[SyntaxKind["ModuleDeclaration"] = 179] = "ModuleDeclaration"; + SyntaxKind[SyntaxKind["ModuleBlock"] = 180] = "ModuleBlock"; + SyntaxKind[SyntaxKind["ImportDeclaration"] = 181] = "ImportDeclaration"; + SyntaxKind[SyntaxKind["ExportAssignment"] = 182] = "ExportAssignment"; + SyntaxKind[SyntaxKind["EnumMember"] = 183] = "EnumMember"; + SyntaxKind[SyntaxKind["SourceFile"] = 184] = "SourceFile"; + SyntaxKind[SyntaxKind["Program"] = 185] = "Program"; + SyntaxKind[SyntaxKind["SyntaxList"] = 186] = "SyntaxList"; + SyntaxKind[SyntaxKind["Count"] = 187] = "Count"; SyntaxKind[SyntaxKind["FirstAssignment"] = SyntaxKind.EqualsToken] = "FirstAssignment"; SyntaxKind[SyntaxKind["LastAssignment"] = SyntaxKind.CaretEqualsToken] = "LastAssignment"; SyntaxKind[SyntaxKind["FirstReservedWord"] = SyntaxKind.BreakKeyword] = "FirstReservedWord"; @@ -1555,11 +1558,13 @@ var ts; SyntaxKind[SyntaxKind["FirstFutureReservedWord"] = SyntaxKind.ImplementsKeyword] = "FirstFutureReservedWord"; SyntaxKind[SyntaxKind["LastFutureReservedWord"] = SyntaxKind.YieldKeyword] = "LastFutureReservedWord"; SyntaxKind[SyntaxKind["FirstTypeNode"] = SyntaxKind.TypeReference] = "FirstTypeNode"; - SyntaxKind[SyntaxKind["LastTypeNode"] = SyntaxKind.TupleType] = "LastTypeNode"; + SyntaxKind[SyntaxKind["LastTypeNode"] = SyntaxKind.ParenType] = "LastTypeNode"; SyntaxKind[SyntaxKind["FirstPunctuation"] = SyntaxKind.OpenBraceToken] = "FirstPunctuation"; SyntaxKind[SyntaxKind["LastPunctuation"] = SyntaxKind.CaretEqualsToken] = "LastPunctuation"; SyntaxKind[SyntaxKind["FirstToken"] = SyntaxKind.EndOfFileToken] = "FirstToken"; SyntaxKind[SyntaxKind["LastToken"] = SyntaxKind.StringKeyword] = "LastToken"; + SyntaxKind[SyntaxKind["FirstTriviaToken"] = SyntaxKind.SingleLineCommentTrivia] = "FirstTriviaToken"; + SyntaxKind[SyntaxKind["LastTriviaToken"] = SyntaxKind.WhitespaceTrivia] = "LastTriviaToken"; })(ts.SyntaxKind || (ts.SyntaxKind = {})); var SyntaxKind = ts.SyntaxKind; (function (NodeFlags) { @@ -1592,8 +1597,18 @@ var ts; TypeFormatFlags[TypeFormatFlags["WriteArrayAsGenericType"] = 0x00000001] = "WriteArrayAsGenericType"; TypeFormatFlags[TypeFormatFlags["UseTypeOfFunction"] = 0x00000002] = "UseTypeOfFunction"; TypeFormatFlags[TypeFormatFlags["NoTruncation"] = 0x00000004] = "NoTruncation"; + TypeFormatFlags[TypeFormatFlags["WriteArrowStyleSignature"] = 0x00000008] = "WriteArrowStyleSignature"; + TypeFormatFlags[TypeFormatFlags["WriteOwnNameForAnyLike"] = 0x00000010] = "WriteOwnNameForAnyLike"; + TypeFormatFlags[TypeFormatFlags["WriteTypeArgumentsOfSignature"] = 0x00000020] = "WriteTypeArgumentsOfSignature"; + TypeFormatFlags[TypeFormatFlags["InElementType"] = 0x00000040] = "InElementType"; })(ts.TypeFormatFlags || (ts.TypeFormatFlags = {})); var TypeFormatFlags = ts.TypeFormatFlags; + (function (SymbolFormatFlags) { + SymbolFormatFlags[SymbolFormatFlags["None"] = 0x00000000] = "None"; + SymbolFormatFlags[SymbolFormatFlags["WriteTypeParametersOrArguments"] = 0x00000001] = "WriteTypeParametersOrArguments"; + SymbolFormatFlags[SymbolFormatFlags["UseOnlyExternalAliasing"] = 0x00000002] = "UseOnlyExternalAliasing"; + })(ts.SymbolFormatFlags || (ts.SymbolFormatFlags = {})); + var SymbolFormatFlags = ts.SymbolFormatFlags; (function (SymbolAccessibility) { SymbolAccessibility[SymbolAccessibility["Accessible"] = 0] = "Accessible"; SymbolAccessibility[SymbolAccessibility["NotAccessible"] = 1] = "NotAccessible"; @@ -1628,6 +1643,7 @@ var ts; SymbolFlags[SymbolFlags["Merged"] = 0x01000000] = "Merged"; SymbolFlags[SymbolFlags["Transient"] = 0x02000000] = "Transient"; SymbolFlags[SymbolFlags["Prototype"] = 0x04000000] = "Prototype"; + SymbolFlags[SymbolFlags["UnionProperty"] = 0x08000000] = "UnionProperty"; SymbolFlags[SymbolFlags["Value"] = SymbolFlags.Variable | SymbolFlags.Property | SymbolFlags.EnumMember | SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.Enum | SymbolFlags.ValueModule | SymbolFlags.Method | SymbolFlags.GetAccessor | SymbolFlags.SetAccessor] = "Value"; SymbolFlags[SymbolFlags["Type"] = SymbolFlags.Class | SymbolFlags.Interface | SymbolFlags.Enum | SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral | SymbolFlags.TypeParameter] = "Type"; SymbolFlags[SymbolFlags["Namespace"] = SymbolFlags.ValueModule | SymbolFlags.NamespaceModule] = "Namespace"; @@ -1667,6 +1683,7 @@ var ts; NodeCheckFlags[NodeCheckFlags["SuperInstance"] = 0x00000010] = "SuperInstance"; NodeCheckFlags[NodeCheckFlags["SuperStatic"] = 0x00000020] = "SuperStatic"; NodeCheckFlags[NodeCheckFlags["ContextChecked"] = 0x00000040] = "ContextChecked"; + NodeCheckFlags[NodeCheckFlags["EnumValuesComputed"] = 0x00000080] = "EnumValuesComputed"; })(ts.NodeCheckFlags || (ts.NodeCheckFlags = {})); var NodeCheckFlags = ts.NodeCheckFlags; (function (TypeFlags) { @@ -1684,12 +1701,14 @@ var ts; TypeFlags[TypeFlags["Interface"] = 0x00000800] = "Interface"; TypeFlags[TypeFlags["Reference"] = 0x00001000] = "Reference"; TypeFlags[TypeFlags["Tuple"] = 0x00002000] = "Tuple"; - TypeFlags[TypeFlags["Anonymous"] = 0x00004000] = "Anonymous"; - TypeFlags[TypeFlags["FromSignature"] = 0x00008000] = "FromSignature"; + TypeFlags[TypeFlags["Union"] = 0x00004000] = "Union"; + TypeFlags[TypeFlags["Anonymous"] = 0x00008000] = "Anonymous"; + TypeFlags[TypeFlags["FromSignature"] = 0x00010000] = "FromSignature"; TypeFlags[TypeFlags["Intrinsic"] = TypeFlags.Any | TypeFlags.String | TypeFlags.Number | TypeFlags.Boolean | TypeFlags.Void | TypeFlags.Undefined | TypeFlags.Null] = "Intrinsic"; TypeFlags[TypeFlags["StringLike"] = TypeFlags.String | TypeFlags.StringLiteral] = "StringLike"; TypeFlags[TypeFlags["NumberLike"] = TypeFlags.Number | TypeFlags.Enum] = "NumberLike"; TypeFlags[TypeFlags["ObjectType"] = TypeFlags.Class | TypeFlags.Interface | TypeFlags.Reference | TypeFlags.Tuple | TypeFlags.Anonymous] = "ObjectType"; + TypeFlags[TypeFlags["Structured"] = TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.Union | TypeFlags.TypeParameter] = "Structured"; })(ts.TypeFlags || (ts.TypeFlags = {})); var TypeFlags = ts.TypeFlags; (function (SignatureKind) { @@ -1851,8 +1870,9 @@ var ts; var result; if (array) { for (var i = 0, len = array.length; i < len; i++) { - if (result = callback(array[i])) + if (result = callback(array[i])) { break; + } } } return result; @@ -1880,6 +1900,18 @@ var ts; return -1; } ts.indexOf = indexOf; + function countWhere(array, predicate) { + var count = 0; + if (array) { + for (var i = 0, len = array.length; i < len; i++) { + if (predicate(array[i])) { + count++; + } + } + } + return count; + } + ts.countWhere = countWhere; function filter(array, f) { if (array) { var result = []; @@ -1911,7 +1943,7 @@ var ts; return array1.concat(array2); } ts.concatenate = concatenate; - function uniqueElements(array) { + function deduplicate(array) { if (array) { var result = []; for (var i = 0, len = array.length; i < len; i++) { @@ -1922,7 +1954,7 @@ var ts; } return result; } - ts.uniqueElements = uniqueElements; + ts.deduplicate = deduplicate; function sum(array, prop) { var result = 0; for (var i = 0; i < array.length; i++) { @@ -2020,10 +2052,7 @@ var ts; } ts.localizedDiagnosticMessages = undefined; function getLocaleSpecificMessage(message) { - if (ts.localizedDiagnosticMessages) { - message = ts.localizedDiagnosticMessages[message]; - } - return message; + return ts.localizedDiagnosticMessages && ts.localizedDiagnosticMessages[message] ? ts.localizedDiagnosticMessages[message] : message; } ts.getLocaleSpecificMessage = getLocaleSpecificMessage; function createFileDiagnostic(file, start, length, message) { @@ -2244,14 +2273,14 @@ var ts; return getNormalizedPathComponents(pathOrUrl, currentDirectory); } } - function getRelativePathToDirectoryOrUrl(directoryPathOrUrl, relativeOrAbsolutePath, currentDirectory, isAbsolutePathAnUrl) { + function getRelativePathToDirectoryOrUrl(directoryPathOrUrl, relativeOrAbsolutePath, currentDirectory, getCanonicalFileName, isAbsolutePathAnUrl) { var pathComponents = getNormalizedPathOrUrlComponents(relativeOrAbsolutePath, currentDirectory); var directoryComponents = getNormalizedPathOrUrlComponents(directoryPathOrUrl, currentDirectory); if (directoryComponents.length > 1 && directoryComponents[directoryComponents.length - 1] === "") { directoryComponents.length--; } for (var joinStartIndex = 0; joinStartIndex < pathComponents.length && joinStartIndex < directoryComponents.length; joinStartIndex++) { - if (directoryComponents[joinStartIndex] !== pathComponents[joinStartIndex]) { + if (getCanonicalFileName(directoryComponents[joinStartIndex]) !== getCanonicalFileName(pathComponents[joinStartIndex])) { break; } } @@ -2295,6 +2324,37 @@ var ts; return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension; } ts.fileExtensionIs = fileExtensionIs; + var supportedExtensions = [".d.ts", ".ts", ".js"]; + function removeFileExtension(path) { + for (var i = 0; i < supportedExtensions.length; i++) { + var ext = supportedExtensions[i]; + if (fileExtensionIs(path, ext)) { + return path.substr(0, path.length - ext.length); + } + } + return path; + } + ts.removeFileExtension = removeFileExtension; + var escapedCharsRegExp = /[\t\v\f\b\0\r\n\"\\\u2028\u2029\u0085]/g; + var escapedCharsMap = { + "\t": "\\t", + "\v": "\\v", + "\f": "\\f", + "\b": "\\b", + "\0": "\\0", + "\r": "\\r", + "\n": "\\n", + "\"": "\\\"", + "\u2028": "\\u2028", + "\u2029": "\\u2029", + "\u0085": "\\u0085" + }; + function escapeString(s) { + return escapedCharsRegExp.test(s) ? s.replace(escapedCharsRegExp, function (c) { + return escapedCharsMap[c] || c; + }) : s; + } + ts.escapeString = escapeString; function Symbol(flags, name) { this.flags = flags; this.name = name; @@ -2383,7 +2443,7 @@ var sys = (function () { return fileStream.ReadText(); } catch (e) { - throw e.number === -2147024809 ? new Error(ts.Diagnostics.Unsupported_file_encoding.key) : e; + throw e; } finally { fileStream.Close(); @@ -2549,7 +2609,7 @@ var sys = (function () { })(); var ts; (function (ts) { - var nodeConstructors = new Array(185 /* Count */); + var nodeConstructors = new Array(187 /* Count */); function getNodeConstructor(kind) { return nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind)); } @@ -2561,19 +2621,8 @@ var ts; node.flags = flags; return node; } - var moduleExtensions = [".d.ts", ".ts", ".js"]; - function getModuleNameFromFilename(filename) { - for (var i = 0; i < moduleExtensions.length; i++) { - var ext = moduleExtensions[i]; - var len = filename.length - ext.length; - if (len > 0 && filename.substr(len) === ext) - return filename.substr(0, len); - } - return filename; - } - ts.getModuleNameFromFilename = getModuleNameFromFilename; function getSourceFileOfNode(node) { - while (node && node.kind !== 182 /* SourceFile */) + while (node && node.kind !== 184 /* SourceFile */) node = node.parent; return node; } @@ -2592,15 +2641,15 @@ var ts; return ts.skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos); } ts.getTokenPosOfNode = getTokenPosOfNode; - function getSourceTextOfNodeFromSourceText(sourceText, node) { + function getTextOfNodeFromSourceText(sourceText, node) { return sourceText.substring(ts.skipTrivia(sourceText, node.pos), node.end); } - ts.getSourceTextOfNodeFromSourceText = getSourceTextOfNodeFromSourceText; - function getSourceTextOfNode(node) { + ts.getTextOfNodeFromSourceText = getTextOfNodeFromSourceText; + function getTextOfNode(node) { var text = getSourceFileOfNode(node).text; return text.substring(ts.skipTrivia(text, node.pos), node.end); } - ts.getSourceTextOfNode = getSourceTextOfNode; + ts.getTextOfNode = getTextOfNode; function escapeIdentifier(identifier) { return identifier.length >= 2 && identifier.charCodeAt(0) === 95 /* _ */ && identifier.charCodeAt(1) === 95 /* _ */ ? "_" + identifier : identifier; } @@ -2610,7 +2659,7 @@ var ts; } ts.unescapeIdentifier = unescapeIdentifier; function identifierToString(identifier) { - return identifier.kind === 115 /* Missing */ ? "(Missing)" : getSourceTextOfNode(identifier); + return identifier.kind === 115 /* Missing */ ? "(Missing)" : getTextOfNode(identifier); } ts.identifierToString = identifierToString; function createDiagnosticForNode(node, message, arg0, arg1, arg2) { @@ -2632,12 +2681,12 @@ var ts; function getErrorSpanForNode(node) { var errorSpan; switch (node.kind) { - case 171 /* VariableDeclaration */: - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 177 /* ModuleDeclaration */: - case 176 /* EnumDeclaration */: - case 181 /* EnumMember */: + case 173 /* VariableDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 179 /* ModuleDeclaration */: + case 178 /* EnumDeclaration */: + case 183 /* EnumMember */: errorSpan = node.name; break; } @@ -2648,8 +2697,12 @@ var ts; return file.externalModuleIndicator !== undefined; } ts.isExternalModule = isExternalModule; + function isDeclarationFile(file) { + return (file.flags & 1024 /* DeclarationFile */) !== 0; + } + ts.isDeclarationFile = isDeclarationFile; function isPrologueDirective(node) { - return node.kind === 151 /* ExpressionStatement */ && node.expression.kind === 7 /* StringLiteral */; + return node.kind === 153 /* ExpressionStatement */ && node.expression.kind === 7 /* StringLiteral */; } ts.isPrologueDirective = isPrologueDirective; function isEvalOrArgumentsIdentifier(node) { @@ -2659,17 +2712,18 @@ var ts; ts.Debug.assert(isPrologueDirective(node)); return node.expression.text === "use strict"; } - function getLeadingCommentsOfNode(node, sourceFileOfNode) { + function getLeadingCommentRangesOfNode(node, sourceFileOfNode) { + sourceFileOfNode = sourceFileOfNode || getSourceFileOfNode(node); if (node.kind === 118 /* Parameter */ || node.kind === 117 /* TypeParameter */) { - return ts.concatenate(ts.getTrailingComments(sourceFileOfNode.text, node.pos), ts.getLeadingComments(sourceFileOfNode.text, node.pos)); + return ts.concatenate(ts.getTrailingCommentRanges(sourceFileOfNode.text, node.pos), ts.getLeadingCommentRanges(sourceFileOfNode.text, node.pos)); } else { - return ts.getLeadingComments(sourceFileOfNode.text, node.pos); + return ts.getLeadingCommentRanges(sourceFileOfNode.text, node.pos); } } - ts.getLeadingCommentsOfNode = getLeadingCommentsOfNode; + ts.getLeadingCommentRangesOfNode = getLeadingCommentRangesOfNode; function getJsDocComments(node, sourceFileOfNode) { - return ts.filter(getLeadingCommentsOfNode(node, sourceFileOfNode), function (comment) { return isJsDocComment(comment); }); + return ts.filter(getLeadingCommentRangesOfNode(node, sourceFileOfNode), function (comment) { return isJsDocComment(comment); }); function isJsDocComment(comment) { return sourceFileOfNode.text.charCodeAt(comment.pos + 1) === 42 /* asterisk */ && sourceFileOfNode.text.charCodeAt(comment.pos + 2) === 42 /* asterisk */ && sourceFileOfNode.text.charCodeAt(comment.pos + 3) !== 47 /* slash */; } @@ -2703,7 +2757,7 @@ var ts; case 118 /* Parameter */: return child(node.name) || child(node.type) || child(node.initializer); case 119 /* Property */: - case 134 /* PropertyAssignment */: + case 136 /* PropertyAssignment */: return child(node.name) || child(node.type) || child(node.initializer); case 124 /* CallSignature */: case 125 /* ConstructSignature */: @@ -2713,9 +2767,9 @@ var ts; case 121 /* Constructor */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 141 /* FunctionExpression */: - case 172 /* FunctionDeclaration */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 174 /* FunctionDeclaration */: + case 144 /* ArrowFunction */: return child(node.name) || children(node.typeParameters) || children(node.parameters) || child(node.type) || child(node.body); case 127 /* TypeReference */: return child(node.typeName) || children(node.typeArguments); @@ -2727,84 +2781,88 @@ var ts; return child(node.elementType); case 131 /* TupleType */: return children(node.elementTypes); - case 132 /* ArrayLiteral */: + case 132 /* UnionType */: + return children(node.types); + case 133 /* ParenType */: + return child(node.type); + case 134 /* ArrayLiteral */: return children(node.elements); - case 133 /* ObjectLiteral */: + case 135 /* ObjectLiteral */: return children(node.properties); - case 135 /* PropertyAccess */: + case 137 /* PropertyAccess */: return child(node.left) || child(node.right); - case 136 /* IndexedAccess */: + case 138 /* IndexedAccess */: return child(node.object) || child(node.index); - case 137 /* CallExpression */: - case 138 /* NewExpression */: + case 139 /* CallExpression */: + case 140 /* NewExpression */: return child(node.func) || children(node.typeArguments) || children(node.arguments); - case 139 /* TypeAssertion */: + case 141 /* TypeAssertion */: return child(node.type) || child(node.operand); - case 140 /* ParenExpression */: + case 142 /* ParenExpression */: return child(node.expression); - case 143 /* PrefixOperator */: - case 144 /* PostfixOperator */: + case 145 /* PrefixOperator */: + case 146 /* PostfixOperator */: return child(node.operand); - case 145 /* BinaryExpression */: + case 147 /* BinaryExpression */: return child(node.left) || child(node.right); - case 146 /* ConditionalExpression */: + case 148 /* ConditionalExpression */: return child(node.condition) || child(node.whenTrue) || child(node.whenFalse); - case 148 /* Block */: - case 167 /* TryBlock */: - case 169 /* FinallyBlock */: - case 173 /* FunctionBlock */: - case 178 /* ModuleBlock */: - case 182 /* SourceFile */: + case 150 /* Block */: + case 169 /* TryBlock */: + case 171 /* FinallyBlock */: + case 175 /* FunctionBlock */: + case 180 /* ModuleBlock */: + case 184 /* SourceFile */: return children(node.statements); - case 149 /* VariableStatement */: + case 151 /* VariableStatement */: return children(node.declarations); - case 151 /* ExpressionStatement */: + case 153 /* ExpressionStatement */: return child(node.expression); - case 152 /* IfStatement */: + case 154 /* IfStatement */: return child(node.expression) || child(node.thenStatement) || child(node.elseStatement); - case 153 /* DoStatement */: + case 155 /* DoStatement */: return child(node.statement) || child(node.expression); - case 154 /* WhileStatement */: + case 156 /* WhileStatement */: return child(node.expression) || child(node.statement); - case 155 /* ForStatement */: + case 157 /* ForStatement */: return children(node.declarations) || child(node.initializer) || child(node.condition) || child(node.iterator) || child(node.statement); - case 156 /* ForInStatement */: + case 158 /* ForInStatement */: return child(node.declaration) || child(node.variable) || child(node.expression) || child(node.statement); - case 157 /* ContinueStatement */: - case 158 /* BreakStatement */: + case 159 /* ContinueStatement */: + case 160 /* BreakStatement */: return child(node.label); - case 159 /* ReturnStatement */: + case 161 /* ReturnStatement */: return child(node.expression); - case 160 /* WithStatement */: + case 162 /* WithStatement */: return child(node.expression) || child(node.statement); - case 161 /* SwitchStatement */: + case 163 /* SwitchStatement */: return child(node.expression) || children(node.clauses); - case 162 /* CaseClause */: - case 163 /* DefaultClause */: + case 164 /* CaseClause */: + case 165 /* DefaultClause */: return child(node.expression) || children(node.statements); - case 164 /* LabeledStatement */: + case 166 /* LabeledStatement */: return child(node.label) || child(node.statement); - case 165 /* ThrowStatement */: + case 167 /* ThrowStatement */: return child(node.expression); - case 166 /* TryStatement */: + case 168 /* TryStatement */: return child(node.tryBlock) || child(node.catchBlock) || child(node.finallyBlock); - case 168 /* CatchBlock */: + case 170 /* CatchBlock */: return child(node.variable) || children(node.statements); - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: return child(node.name) || child(node.type) || child(node.initializer); - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: return child(node.name) || children(node.typeParameters) || child(node.baseType) || children(node.implementedTypes) || children(node.members); - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: return child(node.name) || children(node.typeParameters) || children(node.baseTypes) || children(node.members); - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: return child(node.name) || children(node.members); - case 181 /* EnumMember */: + case 183 /* EnumMember */: return child(node.name) || child(node.initializer); - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return child(node.name) || child(node.body); - case 179 /* ImportDeclaration */: + case 181 /* ImportDeclaration */: return child(node.name) || child(node.entityName) || child(node.externalModuleName); - case 180 /* ExportAssignment */: + case 182 /* ExportAssignment */: return child(node.exportName); } } @@ -2813,24 +2871,24 @@ var ts; return traverse(body); function traverse(node) { switch (node.kind) { - case 159 /* ReturnStatement */: + case 161 /* ReturnStatement */: return visitor(node); - case 148 /* Block */: - case 173 /* FunctionBlock */: - case 152 /* IfStatement */: - case 153 /* DoStatement */: - case 154 /* WhileStatement */: - case 155 /* ForStatement */: - case 156 /* ForInStatement */: - case 160 /* WithStatement */: - case 161 /* SwitchStatement */: - case 162 /* CaseClause */: - case 163 /* DefaultClause */: - case 164 /* LabeledStatement */: - case 166 /* TryStatement */: - case 167 /* TryBlock */: - case 168 /* CatchBlock */: - case 169 /* FinallyBlock */: + case 150 /* Block */: + case 175 /* FunctionBlock */: + case 154 /* IfStatement */: + case 155 /* DoStatement */: + case 156 /* WhileStatement */: + case 157 /* ForStatement */: + case 158 /* ForInStatement */: + case 162 /* WithStatement */: + case 163 /* SwitchStatement */: + case 164 /* CaseClause */: + case 165 /* DefaultClause */: + case 166 /* LabeledStatement */: + case 168 /* TryStatement */: + case 169 /* TryBlock */: + case 170 /* CatchBlock */: + case 171 /* FinallyBlock */: return forEachChild(node, traverse); } } @@ -2839,9 +2897,9 @@ var ts; function isAnyFunction(node) { if (node) { switch (node.kind) { - case 141 /* FunctionExpression */: - case 172 /* FunctionDeclaration */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 174 /* FunctionDeclaration */: + case 144 /* ArrowFunction */: case 120 /* Method */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: @@ -2868,20 +2926,20 @@ var ts; return undefined; } switch (node.kind) { - case 142 /* ArrowFunction */: + case 144 /* ArrowFunction */: if (!includeArrowFunctions) { continue; } - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: - case 177 /* ModuleDeclaration */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: + case 179 /* ModuleDeclaration */: case 119 /* Property */: case 120 /* Method */: case 121 /* Constructor */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 176 /* EnumDeclaration */: - case 182 /* SourceFile */: + case 178 /* EnumDeclaration */: + case 184 /* SourceFile */: return node; } } @@ -2921,19 +2979,19 @@ var ts; switch (node.kind) { case 117 /* TypeParameter */: case 118 /* Parameter */: - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: case 119 /* Property */: - case 134 /* PropertyAssignment */: - case 181 /* EnumMember */: + case 136 /* PropertyAssignment */: + case 183 /* EnumMember */: case 120 /* Method */: - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 176 /* EnumDeclaration */: - case 177 /* ModuleDeclaration */: - case 179 /* ImportDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: + case 179 /* ModuleDeclaration */: + case 181 /* ImportDeclaration */: return true; } return false; @@ -2941,24 +2999,24 @@ var ts; ts.isDeclaration = isDeclaration; function isStatement(n) { switch (n.kind) { - case 158 /* BreakStatement */: - case 157 /* ContinueStatement */: - case 170 /* DebuggerStatement */: - case 153 /* DoStatement */: - case 151 /* ExpressionStatement */: - case 150 /* EmptyStatement */: - case 156 /* ForInStatement */: - case 155 /* ForStatement */: - case 152 /* IfStatement */: - case 164 /* LabeledStatement */: - case 159 /* ReturnStatement */: - case 161 /* SwitchStatement */: + case 160 /* BreakStatement */: + case 159 /* ContinueStatement */: + case 172 /* DebuggerStatement */: + case 155 /* DoStatement */: + case 153 /* ExpressionStatement */: + case 152 /* EmptyStatement */: + case 158 /* ForInStatement */: + case 157 /* ForStatement */: + case 154 /* IfStatement */: + case 166 /* LabeledStatement */: + case 161 /* ReturnStatement */: + case 163 /* SwitchStatement */: case 88 /* ThrowKeyword */: - case 166 /* TryStatement */: - case 149 /* VariableStatement */: - case 154 /* WhileStatement */: - case 160 /* WithStatement */: - case 180 /* ExportAssignment */: + case 168 /* TryStatement */: + case 151 /* VariableStatement */: + case 156 /* WhileStatement */: + case 162 /* WithStatement */: + case 182 /* ExportAssignment */: return true; default: return false; @@ -2970,10 +3028,10 @@ var ts; return false; } var parent = name.parent; - if (isDeclaration(parent) || parent.kind === 141 /* FunctionExpression */) { + if (isDeclaration(parent) || parent.kind === 143 /* FunctionExpression */) { return parent.name === name; } - if (parent.kind === 168 /* CatchBlock */) { + if (parent.kind === 170 /* CatchBlock */) { return parent.variable === name; } return false; @@ -2981,15 +3039,15 @@ var ts; ts.isDeclarationOrFunctionExpressionOrCatchVariableName = isDeclarationOrFunctionExpressionOrCatchVariableName; function getAncestor(node, kind) { switch (kind) { - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: while (node) { switch (node.kind) { - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: return node; - case 176 /* EnumDeclaration */: - case 175 /* InterfaceDeclaration */: - case 177 /* ModuleDeclaration */: - case 179 /* ImportDeclaration */: + case 178 /* EnumDeclaration */: + case 177 /* InterfaceDeclaration */: + case 179 /* ModuleDeclaration */: + case 181 /* ImportDeclaration */: return undefined; default: node = node.parent; @@ -3088,12 +3146,6 @@ var ts; ModifierContext[ModifierContext["ClassMembers"] = 2] = "ClassMembers"; ModifierContext[ModifierContext["Parameters"] = 3] = "Parameters"; })(ModifierContext || (ModifierContext = {})); - var TrailingCommaBehavior; - (function (TrailingCommaBehavior) { - TrailingCommaBehavior[TrailingCommaBehavior["Disallow"] = 0] = "Disallow"; - TrailingCommaBehavior[TrailingCommaBehavior["Allow"] = 1] = "Allow"; - TrailingCommaBehavior[TrailingCommaBehavior["Preserve"] = 2] = "Preserve"; - })(TrailingCommaBehavior || (TrailingCommaBehavior = {})); var ControlBlockContext; (function (ControlBlockContext) { ControlBlockContext[ControlBlockContext["NotNested"] = 0] = "NotNested"; @@ -3104,6 +3156,10 @@ var ts; return ts.SyntaxKind.FirstKeyword <= token && token <= ts.SyntaxKind.LastKeyword; } ts.isKeyword = isKeyword; + function isTrivia(token) { + return ts.SyntaxKind.FirstTriviaToken <= token && token <= ts.SyntaxKind.LastTriviaToken; + } + ts.isTrivia = isTrivia; function isModifier(token) { switch (token) { case 102 /* PublicKeyword */: @@ -3364,7 +3420,9 @@ var ts; return finishNode(node); } error(ts.Diagnostics.Identifier_expected); - return createMissingNode(); + var node = createMissingNode(); + node.text = ""; + return node; } function parseIdentifier() { return createIdentifier(isIdentifier()); @@ -3416,14 +3474,14 @@ var ts; case 14 /* TypeParameters */: return isIdentifier(); case 10 /* ArgumentExpressions */: - return isExpression(); + return token === 18 /* CommaToken */ || isExpression(); case 12 /* ArrayLiteralMembers */: return token === 18 /* CommaToken */ || isExpression(); case 13 /* Parameters */: return isParameter(); case 15 /* TypeArguments */: case 16 /* TupleElementTypes */: - return isType(); + return token === 18 /* CommaToken */ || isType(); } ts.Debug.fail("Non-exhaustive case in 'isListElement'."); } @@ -3516,7 +3574,7 @@ var ts; parsingContext = saveParsingContext; return result; } - function parseDelimitedList(kind, parseElement, trailingCommaBehavior) { + function parseDelimitedList(kind, parseElement, allowTrailingComma) { var saveParsingContext = parsingContext; parsingContext |= 1 << kind; var result = []; @@ -3537,16 +3595,6 @@ var ts; error(ts.Diagnostics._0_expected, ","); } else if (isListTerminator(kind)) { - if (commaStart >= 0) { - if (trailingCommaBehavior === 0 /* Disallow */) { - if (file.syntacticErrors.length === errorCountBeforeParsingList) { - grammarErrorAtPos(commaStart, scanner.getStartPos() - commaStart, ts.Diagnostics.Trailing_comma_not_allowed); - } - } - else if (trailingCommaBehavior === 2 /* Preserve */) { - result.push(createNode(147 /* OmittedExpression */)); - } - } break; } else { @@ -3557,6 +3605,14 @@ var ts; nextToken(); } } + if (commaStart >= 0) { + if (!allowTrailingComma) { + if (file.syntacticErrors.length === errorCountBeforeParsingList) { + grammarErrorAtPos(commaStart, scanner.getStartPos() - commaStart, ts.Diagnostics.Trailing_comma_not_allowed); + } + } + result.hasTrailingComma = true; + } result.end = getNodeEnd(); parsingContext = saveParsingContext; return result; @@ -3576,7 +3632,7 @@ var ts; } function parseBracketedList(kind, parseElement, startToken, endToken) { if (parseExpected(startToken)) { - var result = parseDelimitedList(kind, parseElement, 0 /* Disallow */); + var result = parseDelimitedList(kind, parseElement, false); parseExpected(endToken); return result; } @@ -3880,6 +3936,13 @@ var ts; } return finishNode(node); } + function parseParenType() { + var node = createNode(133 /* ParenType */); + parseExpected(11 /* OpenParenToken */); + node.type = parseType(); + parseExpected(12 /* CloseParenToken */); + return finishNode(node); + } function parseFunctionType(signatureKind) { var node = createNode(129 /* TypeLiteral */); var member = createNode(signatureKind); @@ -3911,10 +3974,7 @@ var ts; case 13 /* OpenBracketToken */: return parseTupleType(); case 11 /* OpenParenToken */: - case 19 /* LessThanToken */: - return parseFunctionType(124 /* CallSignature */); - case 82 /* NewKeyword */: - return parseFunctionType(125 /* ConstructSignature */); + return parseParenType(); default: if (isIdentifier()) { return parseTypeReference(); @@ -3939,15 +3999,15 @@ var ts; case 11 /* OpenParenToken */: return lookAhead(function () { nextToken(); - return token === 12 /* CloseParenToken */ || isParameter(); + return token === 12 /* CloseParenToken */ || isParameter() || isType(); }); default: return isIdentifier(); } } - function parseType() { + function parsePrimaryType() { var type = parseNonArrayType(); - while (type && !scanner.hasPrecedingLineBreak() && parseOptional(13 /* OpenBracketToken */)) { + while (!scanner.hasPrecedingLineBreak() && parseOptional(13 /* OpenBracketToken */)) { parseExpected(14 /* CloseBracketToken */); var node = createNode(130 /* ArrayType */, type.pos); node.elementType = type; @@ -3955,6 +4015,51 @@ var ts; } return type; } + function parseUnionType() { + var type = parsePrimaryType(); + if (token === 39 /* BarToken */) { + var types = [type]; + types.pos = type.pos; + while (parseOptional(39 /* BarToken */)) { + types.push(parsePrimaryType()); + } + types.end = getNodeEnd(); + var node = createNode(132 /* UnionType */, type.pos); + node.types = types; + type = finishNode(node); + } + return type; + } + function isFunctionType() { + return token === 19 /* LessThanToken */ || token === 11 /* OpenParenToken */ && lookAhead(function () { + nextToken(); + if (token === 12 /* CloseParenToken */ || token === 16 /* DotDotDotToken */) { + return true; + } + if (isIdentifier() || isModifier(token)) { + nextToken(); + if (token === 46 /* ColonToken */ || token === 18 /* CommaToken */ || token === 45 /* QuestionToken */ || token === 47 /* EqualsToken */ || isIdentifier() || isModifier(token)) { + return true; + } + if (token === 12 /* CloseParenToken */) { + nextToken(); + if (token === 27 /* EqualsGreaterThanToken */) { + return true; + } + } + } + return false; + }); + } + function parseType() { + if (isFunctionType()) { + return parseFunctionType(124 /* CallSignature */); + } + if (token === 82 /* NewKeyword */) { + return parseFunctionType(125 /* ConstructSignature */); + } + return parseUnionType(); + } function parseTypeAnnotation() { return parseOptional(46 /* ColonToken */) ? parseType() : undefined; } @@ -4031,14 +4136,14 @@ var ts; function isLeftHandSideExpression(expr) { if (expr) { switch (expr.kind) { - case 135 /* PropertyAccess */: - case 136 /* IndexedAccess */: - case 138 /* NewExpression */: - case 137 /* CallExpression */: - case 132 /* ArrayLiteral */: - case 140 /* ParenExpression */: - case 133 /* ObjectLiteral */: - case 141 /* FunctionExpression */: + case 137 /* PropertyAccess */: + case 138 /* IndexedAccess */: + case 140 /* NewExpression */: + case 139 /* CallExpression */: + case 134 /* ArrayLiteral */: + case 142 /* ParenExpression */: + case 135 /* ObjectLiteral */: + case 143 /* FunctionExpression */: case 59 /* Identifier */: case 115 /* Missing */: case 8 /* RegularExpressionLiteral */: @@ -4079,7 +4184,7 @@ var ts; return parseArrowExpressionTail(pos, sig, false); } else { - return makeFunctionExpression(142 /* ArrowFunction */, pos, undefined, sig, createMissingNode()); + return makeFunctionExpression(144 /* ArrowFunction */, pos, undefined, sig, createMissingNode()); } } var sig = tryParseSignatureIfArrowOrBraceFollows(); @@ -4153,7 +4258,7 @@ var ts; else { body = parseAssignmentExpression(noIn); } - return makeFunctionExpression(142 /* ArrowFunction */, pos, undefined, sig, body); + return makeFunctionExpression(144 /* ArrowFunction */, pos, undefined, sig, body); } function isAssignmentOperator() { return token >= ts.SyntaxKind.FirstAssignment && token <= ts.SyntaxKind.LastAssignment; @@ -4161,7 +4266,7 @@ var ts; function parseConditionalExpression(noIn) { var expr = parseBinaryExpression(noIn); while (parseOptional(45 /* QuestionToken */)) { - var node = createNode(146 /* ConditionalExpression */, expr.pos); + var node = createNode(148 /* ConditionalExpression */, expr.pos); node.condition = expr; node.whenTrue = parseAssignmentExpression(false); parseExpected(46 /* ColonToken */); @@ -4225,7 +4330,7 @@ var ts; return undefined; } function makeBinaryExpression(left, operator, right) { - var node = createNode(145 /* BinaryExpression */, left.pos); + var node = createNode(147 /* BinaryExpression */, left.pos); node.left = left; node.operator = operator; node.right = right; @@ -4247,14 +4352,14 @@ var ts; nextToken(); var operand = parseUnaryExpression(); if (isInStrictMode) { - if ((token === 33 /* PlusPlusToken */ || token === 34 /* MinusMinusToken */) && isEvalOrArgumentsIdentifier(operand)) { + if ((operator === 33 /* PlusPlusToken */ || operator === 34 /* MinusMinusToken */) && isEvalOrArgumentsIdentifier(operand)) { reportInvalidUseInStrictMode(operand); } - else if (token === 68 /* DeleteKeyword */ && operand.kind === 59 /* Identifier */) { + else if (operator === 68 /* DeleteKeyword */ && operand.kind === 59 /* Identifier */) { grammarErrorOnNode(operand, ts.Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode); } } - return makeUnaryExpression(143 /* PrefixOperator */, pos, operator, operand); + return makeUnaryExpression(145 /* PrefixOperator */, pos, operator, operand); case 19 /* LessThanToken */: return parseTypeAssertion(); } @@ -4271,12 +4376,12 @@ var ts; } var operator = token; nextToken(); - expr = makeUnaryExpression(144 /* PostfixOperator */, expr.pos, operator, expr); + expr = makeUnaryExpression(146 /* PostfixOperator */, expr.pos, operator, expr); } return expr; } function parseTypeAssertion() { - var node = createNode(139 /* TypeAssertion */); + var node = createNode(141 /* TypeAssertion */); parseExpected(19 /* LessThanToken */); node.type = parseType(); parseExpected(20 /* GreaterThanToken */); @@ -4293,7 +4398,7 @@ var ts; while (true) { var dotStart = scanner.getTokenPos(); if (parseOptional(15 /* DotToken */)) { - var propertyAccess = createNode(135 /* PropertyAccess */, expr.pos); + var propertyAccess = createNode(137 /* PropertyAccess */, expr.pos); if (scanner.hasPrecedingLineBreak() && scanner.isReservedWord() && lookAhead(function () { return scanner.isReservedWord(); })) { grammarErrorAtPos(dotStart, scanner.getStartPos() - dotStart, ts.Diagnostics.Identifier_expected); var id = createMissingNode(); @@ -4308,7 +4413,7 @@ var ts; } var bracketStart = scanner.getTokenPos(); if (parseOptional(13 /* OpenBracketToken */)) { - var indexedAccess = createNode(136 /* IndexedAccess */, expr.pos); + var indexedAccess = createNode(138 /* IndexedAccess */, expr.pos); indexedAccess.object = expr; if (inNewExpression && parseOptional(14 /* CloseBracketToken */)) { indexedAccess.index = createMissingNode(); @@ -4326,7 +4431,7 @@ var ts; continue; } if ((token === 11 /* OpenParenToken */ || token === 19 /* LessThanToken */) && !inNewExpression) { - var callExpr = createNode(137 /* CallExpression */, expr.pos); + var callExpr = createNode(139 /* CallExpression */, expr.pos); callExpr.func = expr; if (token === 19 /* LessThanToken */) { if (!(callExpr.typeArguments = tryParse(parseTypeArgumentsAndOpenParen))) @@ -4335,7 +4440,7 @@ var ts; else { parseExpected(11 /* OpenParenToken */); } - callExpr.arguments = parseDelimitedList(10 /* ArgumentExpressions */, parseAssignmentExpression, 0 /* Disallow */); + callExpr.arguments = parseDelimitedList(10 /* ArgumentExpressions */, parseArgumentExpression, false); parseExpected(12 /* CloseParenToken */); expr = finishNode(callExpr); continue; @@ -4351,12 +4456,21 @@ var ts; function parseTypeArguments() { var typeArgumentListStart = scanner.getTokenPos(); var errorCountBeforeTypeParameterList = file.syntacticErrors.length; - var result = parseBracketedList(15 /* TypeArguments */, parseType, 19 /* LessThanToken */, 20 /* GreaterThanToken */); + var result = parseBracketedList(15 /* TypeArguments */, parseSingleTypeArgument, 19 /* LessThanToken */, 20 /* GreaterThanToken */); if (!result.length && file.syntacticErrors.length === errorCountBeforeTypeParameterList) { grammarErrorAtPos(typeArgumentListStart, scanner.getStartPos() - typeArgumentListStart, ts.Diagnostics.Type_argument_list_cannot_be_empty); } return result; } + function parseSingleTypeArgument() { + if (token === 18 /* CommaToken */) { + var errorStart = scanner.getTokenPos(); + var errorLength = scanner.getTextPos() - errorStart; + grammarErrorAtPos(errorStart, errorLength, ts.Diagnostics.Type_expected); + return createNode(115 /* Missing */); + } + return parseType(); + } function parsePrimaryExpression() { switch (token) { case 87 /* ThisKeyword */: @@ -4393,31 +4507,45 @@ var ts; return createMissingNode(); } function parseParenExpression() { - var node = createNode(140 /* ParenExpression */); + var node = createNode(142 /* ParenExpression */); parseExpected(11 /* OpenParenToken */); node.expression = parseExpression(); parseExpected(12 /* CloseParenToken */); return finishNode(node); } + function parseAssignmentExpressionOrOmittedExpression(omittedExpressionDiagnostic) { + if (token === 18 /* CommaToken */) { + if (omittedExpressionDiagnostic) { + var errorStart = scanner.getTokenPos(); + var errorLength = scanner.getTextPos() - errorStart; + grammarErrorAtPos(errorStart, errorLength, omittedExpressionDiagnostic); + } + return createNode(149 /* OmittedExpression */); + } + return parseAssignmentExpression(); + } function parseArrayLiteralElement() { - return token === 18 /* CommaToken */ ? createNode(147 /* OmittedExpression */) : parseAssignmentExpression(); + return parseAssignmentExpressionOrOmittedExpression(undefined); + } + function parseArgumentExpression() { + return parseAssignmentExpressionOrOmittedExpression(ts.Diagnostics.Argument_expression_expected); } function parseArrayLiteral() { - var node = createNode(132 /* ArrayLiteral */); + var node = createNode(134 /* ArrayLiteral */); parseExpected(13 /* OpenBracketToken */); if (scanner.hasPrecedingLineBreak()) node.flags |= 256 /* MultiLine */; - node.elements = parseDelimitedList(12 /* ArrayLiteralMembers */, parseArrayLiteralElement, 2 /* Preserve */); + node.elements = parseDelimitedList(12 /* ArrayLiteralMembers */, parseArrayLiteralElement, true); parseExpected(14 /* CloseBracketToken */); return finishNode(node); } function parsePropertyAssignment() { - var node = createNode(134 /* PropertyAssignment */); + var node = createNode(136 /* PropertyAssignment */); node.name = parsePropertyName(); if (token === 11 /* OpenParenToken */ || token === 19 /* LessThanToken */) { var sig = parseSignature(124 /* CallSignature */, 46 /* ColonToken */, false); var body = parseBody(false); - node.initializer = makeFunctionExpression(141 /* FunctionExpression */, node.pos, undefined, sig, body); + node.initializer = makeFunctionExpression(143 /* FunctionExpression */, node.pos, undefined, sig, body); } else { parseExpected(46 /* ColonToken */); @@ -4435,13 +4563,12 @@ var ts; return parsePropertyAssignment(); } function parseObjectLiteral() { - var node = createNode(133 /* ObjectLiteral */); + var node = createNode(135 /* ObjectLiteral */); parseExpected(9 /* OpenBraceToken */); if (scanner.hasPrecedingLineBreak()) { node.flags |= 256 /* MultiLine */; } - var trailingCommaBehavior = languageVersion === 0 /* ES3 */ ? 1 /* Allow */ : 2 /* Preserve */; - node.properties = parseDelimitedList(11 /* ObjectLiteralMembers */, parseObjectLiteralMember, trailingCommaBehavior); + node.properties = parseDelimitedList(11 /* ObjectLiteralMembers */, parseObjectLiteralMember, true); parseExpected(10 /* CloseBraceToken */); var seen = {}; var Property = 1; @@ -4449,11 +4576,11 @@ var ts; var SetAccesor = 4; var GetOrSetAccessor = GetAccessor | SetAccesor; ts.forEach(node.properties, function (p) { - if (p.kind === 147 /* OmittedExpression */) { + if (p.kind === 149 /* OmittedExpression */) { return; } var currentKind; - if (p.kind === 134 /* PropertyAssignment */) { + if (p.kind === 136 /* PropertyAssignment */) { currentKind = Property; } else if (p.kind === 122 /* GetAccessor */) { @@ -4499,7 +4626,7 @@ var ts; if (name && isInStrictMode && isEvalOrArgumentsIdentifier(name)) { reportInvalidUseInStrictMode(name); } - return makeFunctionExpression(141 /* FunctionExpression */, pos, name, sig, body); + return makeFunctionExpression(143 /* FunctionExpression */, pos, name, sig, body); } function makeFunctionExpression(kind, pos, name, sig, body) { var node = createNode(kind, pos); @@ -4511,17 +4638,17 @@ var ts; return finishNode(node); } function parseNewExpression() { - var node = createNode(138 /* NewExpression */); + var node = createNode(140 /* NewExpression */); parseExpected(82 /* NewKeyword */); node.func = parseCallAndAccess(parsePrimaryExpression(), true); if (parseOptional(11 /* OpenParenToken */) || token === 19 /* LessThanToken */ && (node.typeArguments = tryParse(parseTypeArgumentsAndOpenParen))) { - node.arguments = parseDelimitedList(10 /* ArgumentExpressions */, parseAssignmentExpression, 0 /* Disallow */); + node.arguments = parseDelimitedList(10 /* ArgumentExpressions */, parseArgumentExpression, false); parseExpected(12 /* CloseParenToken */); } return finishNode(node); } function parseBlock(ignoreMissingOpenBrace, checkForStrictMode) { - var node = createNode(148 /* Block */); + var node = createNode(150 /* Block */); if (parseExpected(9 /* OpenBraceToken */) || ignoreMissingOpenBrace) { node.statements = parseList(2 /* BlockStatements */, checkForStrictMode, parseStatement); parseExpected(10 /* CloseBraceToken */); @@ -4544,7 +4671,7 @@ var ts; } labelledStatementInfo.pushFunctionBoundary(); var block = parseBlock(ignoreMissingOpenBrace, true); - block.kind = 173 /* FunctionBlock */; + block.kind = 175 /* FunctionBlock */; labelledStatementInfo.pop(); inFunctionBody = saveInFunctionBody; inSwitchStatement = saveInSwitchStatement; @@ -4552,12 +4679,12 @@ var ts; return block; } function parseEmptyStatement() { - var node = createNode(150 /* EmptyStatement */); + var node = createNode(152 /* EmptyStatement */); parseExpected(17 /* SemicolonToken */); return finishNode(node); } function parseIfStatement() { - var node = createNode(152 /* IfStatement */); + var node = createNode(154 /* IfStatement */); parseExpected(78 /* IfKeyword */); parseExpected(11 /* OpenParenToken */); node.expression = parseExpression(); @@ -4567,7 +4694,7 @@ var ts; return finishNode(node); } function parseDoStatement() { - var node = createNode(153 /* DoStatement */); + var node = createNode(155 /* DoStatement */); parseExpected(69 /* DoKeyword */); var saveInIterationStatement = inIterationStatement; inIterationStatement = 1 /* Nested */; @@ -4581,7 +4708,7 @@ var ts; return finishNode(node); } function parseWhileStatement() { - var node = createNode(154 /* WhileStatement */); + var node = createNode(156 /* WhileStatement */); parseExpected(94 /* WhileKeyword */); parseExpected(11 /* OpenParenToken */); node.expression = parseExpression(); @@ -4609,7 +4736,7 @@ var ts; } var forOrForInStatement; if (parseOptional(80 /* InKeyword */)) { - var forInStatement = createNode(156 /* ForInStatement */, pos); + var forInStatement = createNode(158 /* ForInStatement */, pos); if (declarations) { if (declarations.length > 1) { error(ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement); @@ -4624,7 +4751,7 @@ var ts; forOrForInStatement = forInStatement; } else { - var forStatement = createNode(155 /* ForStatement */, pos); + var forStatement = createNode(157 /* ForStatement */, pos); if (declarations) forStatement.declarations = declarations; if (varOrInit) @@ -4649,7 +4776,7 @@ var ts; function parseBreakOrContinueStatement(kind) { var node = createNode(kind); var errorCountBeforeStatement = file.syntacticErrors.length; - parseExpected(kind === 158 /* BreakStatement */ ? 60 /* BreakKeyword */ : 65 /* ContinueKeyword */); + parseExpected(kind === 160 /* BreakStatement */ ? 60 /* BreakKeyword */ : 65 /* ContinueKeyword */); if (!canParseSemicolon()) node.label = parseIdentifier(); parseSemicolon(); @@ -4665,7 +4792,7 @@ var ts; return node; } function checkBareBreakOrContinueStatement(node) { - if (node.kind === 158 /* BreakStatement */) { + if (node.kind === 160 /* BreakStatement */) { if (inIterationStatement === 1 /* Nested */ || inSwitchStatement === 1 /* Nested */) { return; } @@ -4674,7 +4801,7 @@ var ts; return; } } - else if (node.kind === 157 /* ContinueStatement */) { + else if (node.kind === 159 /* ContinueStatement */) { if (inIterationStatement === 1 /* Nested */) { return; } @@ -4690,7 +4817,7 @@ var ts; grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary); } function checkBreakOrContinueStatementWithLabel(node) { - var nodeIsNestedInLabel = labelledStatementInfo.nodeIsNestedInLabel(node.label, node.kind === 157 /* ContinueStatement */, false); + var nodeIsNestedInLabel = labelledStatementInfo.nodeIsNestedInLabel(node.label, node.kind === 159 /* ContinueStatement */, false); if (nodeIsNestedInLabel === 1 /* Nested */) { return; } @@ -4698,10 +4825,10 @@ var ts; grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary); return; } - if (node.kind === 157 /* ContinueStatement */) { + if (node.kind === 159 /* ContinueStatement */) { grammarErrorOnNode(node, ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement); } - else if (node.kind === 158 /* BreakStatement */) { + else if (node.kind === 160 /* BreakStatement */) { grammarErrorOnNode(node, ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement); } else { @@ -4709,7 +4836,7 @@ var ts; } } function parseReturnStatement() { - var node = createNode(159 /* ReturnStatement */); + var node = createNode(161 /* ReturnStatement */); var errorCountBeforeReturnStatement = file.syntacticErrors.length; var returnTokenStart = scanner.getTokenPos(); var returnTokenLength = scanner.getTextPos() - returnTokenStart; @@ -4723,7 +4850,7 @@ var ts; return finishNode(node); } function parseWithStatement() { - var node = createNode(160 /* WithStatement */); + var node = createNode(162 /* WithStatement */); var startPos = scanner.getTokenPos(); parseExpected(95 /* WithKeyword */); var endPos = scanner.getStartPos(); @@ -4738,7 +4865,7 @@ var ts; return node; } function parseCaseClause() { - var node = createNode(162 /* CaseClause */); + var node = createNode(164 /* CaseClause */); parseExpected(61 /* CaseKeyword */); node.expression = parseExpression(); parseExpected(46 /* ColonToken */); @@ -4746,7 +4873,7 @@ var ts; return finishNode(node); } function parseDefaultClause() { - var node = createNode(163 /* DefaultClause */); + var node = createNode(165 /* DefaultClause */); parseExpected(67 /* DefaultKeyword */); parseExpected(46 /* ColonToken */); node.statements = parseList(4 /* SwitchClauseStatements */, false, parseStatement); @@ -4756,7 +4883,7 @@ var ts; return token === 61 /* CaseKeyword */ ? parseCaseClause() : parseDefaultClause(); } function parseSwitchStatement() { - var node = createNode(161 /* SwitchStatement */); + var node = createNode(163 /* SwitchStatement */); parseExpected(86 /* SwitchKeyword */); parseExpected(11 /* OpenParenToken */); node.expression = parseExpression(); @@ -4767,7 +4894,7 @@ var ts; node.clauses = parseList(3 /* SwitchClauses */, false, parseCaseOrDefaultClause); inSwitchStatement = saveInSwitchStatement; parseExpected(10 /* CloseBraceToken */); - var defaultClauses = ts.filter(node.clauses, function (clause) { return clause.kind === 163 /* DefaultClause */; }); + var defaultClauses = ts.filter(node.clauses, function (clause) { return clause.kind === 165 /* DefaultClause */; }); for (var i = 1, n = defaultClauses.length; i < n; i++) { var clause = defaultClauses[i]; var start = ts.skipTrivia(file.text, clause.pos); @@ -4777,7 +4904,7 @@ var ts; return finishNode(node); } function parseThrowStatement() { - var node = createNode(165 /* ThrowStatement */); + var node = createNode(167 /* ThrowStatement */); parseExpected(88 /* ThrowKeyword */); if (scanner.hasPrecedingLineBreak()) { error(ts.Diagnostics.Line_break_not_permitted_here); @@ -4787,13 +4914,13 @@ var ts; return finishNode(node); } function parseTryStatement() { - var node = createNode(166 /* TryStatement */); - node.tryBlock = parseTokenAndBlock(90 /* TryKeyword */, 167 /* TryBlock */); + var node = createNode(168 /* TryStatement */); + node.tryBlock = parseTokenAndBlock(90 /* TryKeyword */, 169 /* TryBlock */); if (token === 62 /* CatchKeyword */) { node.catchBlock = parseCatchBlock(); } if (token === 75 /* FinallyKeyword */) { - node.finallyBlock = parseTokenAndBlock(75 /* FinallyKeyword */, 169 /* FinallyBlock */); + node.finallyBlock = parseTokenAndBlock(75 /* FinallyKeyword */, 171 /* FinallyBlock */); } if (!(node.catchBlock || node.finallyBlock)) { error(ts.Diagnostics.catch_or_finally_expected); @@ -4818,7 +4945,7 @@ var ts; var typeAnnotation = parseTypeAnnotation(); parseExpected(12 /* CloseParenToken */); var result = parseBlock(false, false); - result.kind = 168 /* CatchBlock */; + result.kind = 170 /* CatchBlock */; result.pos = pos; result.variable = variable; if (typeAnnotation) { @@ -4830,7 +4957,7 @@ var ts; return result; } function parseDebuggerStatement() { - var node = createNode(170 /* DebuggerStatement */); + var node = createNode(172 /* DebuggerStatement */); parseExpected(66 /* DebuggerKeyword */); parseSemicolon(); return finishNode(node); @@ -4848,18 +4975,18 @@ var ts; return isIdentifier() && lookAhead(function () { return nextToken() === 46 /* ColonToken */; }); } function parseLabelledStatement() { - var node = createNode(164 /* LabeledStatement */); + var node = createNode(166 /* LabeledStatement */); node.label = parseIdentifier(); parseExpected(46 /* ColonToken */); if (labelledStatementInfo.nodeIsNestedInLabel(node.label, false, true)) { - grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, getSourceTextOfNodeFromSourceText(sourceText, node.label)); + grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, getTextOfNodeFromSourceText(sourceText, node.label)); } labelledStatementInfo.addLabel(node.label); node.statement = isLabel() ? parseLabelledStatement() : parseStatementWithLabelSet(); return finishNode(node); } function parseExpressionStatement() { - var node = createNode(151 /* ExpressionStatement */); + var node = createNode(153 /* ExpressionStatement */); node.expression = parseExpression(); parseSemicolon(); return finishNode(node); @@ -4923,9 +5050,9 @@ var ts; case 76 /* ForKeyword */: return parseForOrForInStatement(); case 65 /* ContinueKeyword */: - return parseBreakOrContinueStatement(157 /* ContinueStatement */); + return parseBreakOrContinueStatement(159 /* ContinueStatement */); case 60 /* BreakKeyword */: - return parseBreakOrContinueStatement(158 /* BreakStatement */); + return parseBreakOrContinueStatement(160 /* BreakStatement */); case 84 /* ReturnKeyword */: return parseReturnStatement(); case 95 /* WithKeyword */: @@ -4968,7 +5095,7 @@ var ts; error(ts.Diagnostics.Block_or_expected); } function parseVariableDeclaration(flags, noIn) { - var node = createNode(171 /* VariableDeclaration */); + var node = createNode(173 /* VariableDeclaration */); node.flags = flags; var errorCountBeforeVariableDeclaration = file.syntacticErrors.length; node.name = parseIdentifier(); @@ -4985,10 +5112,10 @@ var ts; return finishNode(node); } function parseVariableDeclarationList(flags, noIn) { - return parseDelimitedList(9 /* VariableDeclarations */, function () { return parseVariableDeclaration(flags, noIn); }, 0 /* Disallow */); + return parseDelimitedList(9 /* VariableDeclarations */, function () { return parseVariableDeclaration(flags, noIn); }, false); } function parseVariableStatement(pos, flags) { - var node = createNode(149 /* VariableStatement */, pos); + var node = createNode(151 /* VariableStatement */, pos); if (flags) node.flags = flags; var errorCountBeforeVarStatement = file.syntacticErrors.length; @@ -5002,7 +5129,7 @@ var ts; return node; } function parseFunctionDeclaration(pos, flags) { - var node = createNode(172 /* FunctionDeclaration */, pos); + var node = createNode(174 /* FunctionDeclaration */, pos); if (flags) node.flags = flags; parseExpected(77 /* FunctionKeyword */); @@ -5313,7 +5440,7 @@ var ts; ts.Debug.fail("Should not have attempted to parse class member declaration."); } function parseClassDeclaration(pos, flags) { - var node = createNode(174 /* ClassDeclaration */, pos); + var node = createNode(176 /* ClassDeclaration */, pos); node.flags = flags; var errorCountBeforeClassDeclaration = file.syntacticErrors.length; parseExpected(63 /* ClassKeyword */); @@ -5324,7 +5451,7 @@ var ts; var implementsKeywordLength; if (parseOptional(96 /* ImplementsKeyword */)) { implementsKeywordLength = scanner.getStartPos() - implementsKeywordStart; - node.implementedTypes = parseDelimitedList(8 /* BaseTypeReferences */, parseTypeReference, 0 /* Disallow */); + node.implementedTypes = parseDelimitedList(8 /* BaseTypeReferences */, parseTypeReference, false); } var errorCountBeforeClassBody = file.syntacticErrors.length; if (parseExpected(9 /* OpenBraceToken */)) { @@ -5340,7 +5467,7 @@ var ts; return finishNode(node); } function parseInterfaceDeclaration(pos, flags) { - var node = createNode(175 /* InterfaceDeclaration */, pos); + var node = createNode(177 /* InterfaceDeclaration */, pos); node.flags = flags; var errorCountBeforeInterfaceDeclaration = file.syntacticErrors.length; parseExpected(97 /* InterfaceKeyword */); @@ -5350,7 +5477,7 @@ var ts; var extendsKeywordLength; if (parseOptional(73 /* ExtendsKeyword */)) { extendsKeywordLength = scanner.getStartPos() - extendsKeywordStart; - node.baseTypes = parseDelimitedList(8 /* BaseTypeReferences */, parseTypeReference, 0 /* Disallow */); + node.baseTypes = parseDelimitedList(8 /* BaseTypeReferences */, parseTypeReference, false); } var errorCountBeforeInterfaceBody = file.syntacticErrors.length; node.members = parseTypeLiteral().members; @@ -5364,7 +5491,7 @@ var ts; function isInteger(literalExpression) { return /^[0-9]+([eE]\+?[0-9]+)?$/.test(literalExpression.text); } - if (expression.kind === 143 /* PrefixOperator */) { + if (expression.kind === 145 /* PrefixOperator */) { var unaryExpression = expression; if (unaryExpression.operator === 28 /* PlusToken */ || unaryExpression.operator === 29 /* MinusToken */) { expression = unaryExpression.operand; @@ -5377,7 +5504,7 @@ var ts; } var inConstantEnumMemberSection = true; function parseAndCheckEnumMember() { - var node = createNode(181 /* EnumMember */); + var node = createNode(183 /* EnumMember */); var errorCountBeforeEnumMember = file.syntacticErrors.length; node.name = parsePropertyName(); node.initializer = parseInitializer(false); @@ -5394,12 +5521,12 @@ var ts; } return finishNode(node); } - var node = createNode(176 /* EnumDeclaration */, pos); + var node = createNode(178 /* EnumDeclaration */, pos); node.flags = flags; parseExpected(71 /* EnumKeyword */); node.name = parseIdentifier(); if (parseExpected(9 /* OpenBraceToken */)) { - node.members = parseDelimitedList(7 /* EnumMembers */, parseAndCheckEnumMember, 1 /* Allow */); + node.members = parseDelimitedList(7 /* EnumMembers */, parseAndCheckEnumMember, true); parseExpected(10 /* CloseBraceToken */); } else { @@ -5408,7 +5535,7 @@ var ts; return finishNode(node); } function parseModuleBody() { - var node = createNode(178 /* ModuleBlock */); + var node = createNode(180 /* ModuleBlock */); if (parseExpected(9 /* OpenBraceToken */)) { node.statements = parseList(1 /* ModuleElements */, false, parseModuleElement); parseExpected(10 /* CloseBraceToken */); @@ -5419,7 +5546,7 @@ var ts; return finishNode(node); } function parseInternalModuleTail(pos, flags) { - var node = createNode(177 /* ModuleDeclaration */, pos); + var node = createNode(179 /* ModuleDeclaration */, pos); node.flags = flags; node.name = parseIdentifier(); if (parseOptional(15 /* DotToken */)) { @@ -5428,10 +5555,10 @@ var ts; else { node.body = parseModuleBody(); ts.forEach(node.body.statements, function (s) { - if (s.kind === 180 /* ExportAssignment */) { + if (s.kind === 182 /* ExportAssignment */) { grammarErrorOnNode(s, ts.Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); } - else if (s.kind === 179 /* ImportDeclaration */ && s.externalModuleName) { + else if (s.kind === 181 /* ImportDeclaration */ && s.externalModuleName) { grammarErrorOnNode(s, ts.Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); } }); @@ -5439,7 +5566,7 @@ var ts; return finishNode(node); } function parseAmbientExternalModuleDeclaration(pos, flags) { - var node = createNode(177 /* ModuleDeclaration */, pos); + var node = createNode(179 /* ModuleDeclaration */, pos); node.flags = flags; node.name = parseStringLiteral(); if (!inAmbientContext) { @@ -5459,7 +5586,7 @@ var ts; return token === 7 /* StringLiteral */ ? parseAmbientExternalModuleDeclaration(pos, flags) : parseInternalModuleTail(pos, flags); } function parseImportDeclaration(pos, flags) { - var node = createNode(179 /* ImportDeclaration */, pos); + var node = createNode(181 /* ImportDeclaration */, pos); node.flags = flags; parseExpected(79 /* ImportKeyword */); node.name = parseIdentifier(); @@ -5476,7 +5603,7 @@ var ts; return finishNode(node); } function parseExportAssignmentTail(pos) { - var node = createNode(180 /* ExportAssignment */, pos); + var node = createNode(182 /* ExportAssignment */, pos); node.exportName = parseIdentifier(); parseSemicolon(); return finishNode(node); @@ -5593,15 +5720,16 @@ var ts; } else { var matchResult = ts.fullTripleSlashReferencePathRegEx.exec(comment); + var start = range.pos; + var end = range.end; + var length = end - start; if (!matchResult) { - var start = range.pos; - var length = range.end - start; errorAtPos(start, length, ts.Diagnostics.Invalid_reference_directive_syntax); } else { referencedFiles.push({ - pos: range.pos, - end: range.end, + pos: start, + end: end, filename: matchResult[3] }); } @@ -5622,7 +5750,7 @@ var ts; }; } function getExternalModuleIndicator() { - return ts.forEach(file.statements, function (node) { return node.flags & 1 /* Export */ || node.kind === 179 /* ImportDeclaration */ && node.externalModuleName || node.kind === 180 /* ExportAssignment */ ? node : undefined; }); + return ts.forEach(file.statements, function (node) { return node.flags & 1 /* Export */ || node.kind === 181 /* ImportDeclaration */ && node.externalModuleName || node.kind === 182 /* ExportAssignment */ ? node : undefined; }); } scanner = ts.createScanner(languageVersion, true, sourceText, scanError, onComment); var rootNodeFlags = 0; @@ -5630,7 +5758,7 @@ var ts; rootNodeFlags = 1024 /* DeclarationFile */; inAmbientContext = true; } - file = createRootNode(182 /* SourceFile */, 0, sourceText.length, rootNodeFlags); + file = createRootNode(184 /* SourceFile */, 0, sourceText.length, rootNodeFlags); file.filename = ts.normalizePath(filename); file.text = sourceText; file.getLineAndCharacterFromPosition = getLineAndCharacterlFromSourcePosition; @@ -5704,6 +5832,9 @@ var ts; else if (!findSourceFile(filename, isDefaultLib, refFile, refPos, refEnd)) { diagnostic = ts.Diagnostics.File_0_not_found; } + else if (refFile && host.getCanonicalFileName(filename) === host.getCanonicalFileName(refFile.filename)) { + diagnostic = ts.Diagnostics.A_file_cannot_have_a_reference_to_itself; + } } else { if (!(findSourceFile(filename + ".ts", isDefaultLib, refFile, refPos, refEnd) || findSourceFile(filename + ".d.ts", isDefaultLib, refFile, refPos, refEnd))) { @@ -5754,12 +5885,13 @@ var ts; } function processReferencedFiles(file, basePath) { ts.forEach(file.referencedFiles, function (ref) { - processSourceFile(ts.normalizePath(ts.combinePaths(basePath, ref.filename)), false, file, ref.pos, ref.end); + var referencedFilename = ts.isRootedDiskPath(ref.filename) ? ref.filename : ts.combinePaths(basePath, ref.filename); + processSourceFile(ts.normalizePath(referencedFilename), false, file, ref.pos, ref.end); }); } function processImportedModules(file, basePath) { ts.forEach(file.statements, function (node) { - if (node.kind === 179 /* ImportDeclaration */ && node.externalModuleName) { + if (node.kind === 181 /* ImportDeclaration */ && node.externalModuleName) { var nameLiteral = node.externalModuleName; var moduleName = nameLiteral.text; if (moduleName) { @@ -5777,9 +5909,9 @@ var ts; } } } - else if (node.kind === 177 /* ModuleDeclaration */ && node.name.kind === 7 /* StringLiteral */ && (node.flags & 2 /* Ambient */ || file.flags & 1024 /* DeclarationFile */)) { + else if (node.kind === 179 /* ModuleDeclaration */ && node.name.kind === 7 /* StringLiteral */ && (node.flags & 2 /* Ambient */ || isDeclarationFile(file))) { forEachChild(node.body, function (node) { - if (node.kind === 179 /* ImportDeclaration */ && node.externalModuleName) { + if (node.kind === 181 /* ImportDeclaration */ && node.externalModuleName) { var nameLiteral = node.externalModuleName; var moduleName = nameLiteral.text; if (moduleName) { @@ -5852,16 +5984,16 @@ var ts; var ts; (function (ts) { function isInstantiated(node) { - if (node.kind === 175 /* InterfaceDeclaration */) { + if (node.kind === 177 /* InterfaceDeclaration */) { return false; } - else if (node.kind === 179 /* ImportDeclaration */ && !(node.flags & 1 /* Export */)) { + else if (node.kind === 181 /* ImportDeclaration */ && !(node.flags & 1 /* Export */)) { return false; } - else if (node.kind === 178 /* ModuleBlock */ && !ts.forEachChild(node, isInstantiated)) { + else if (node.kind === 180 /* ModuleBlock */ && !ts.forEachChild(node, isInstantiated)) { return false; } - else if (node.kind === 177 /* ModuleDeclaration */ && !isInstantiated(node.body)) { + else if (node.kind === 179 /* ModuleDeclaration */ && !isInstantiated(node.body)) { return false; } else { @@ -5900,7 +6032,7 @@ var ts; } function getDeclarationName(node) { if (node.name) { - if (node.kind === 177 /* ModuleDeclaration */ && node.name.kind === 7 /* StringLiteral */) { + if (node.kind === 179 /* ModuleDeclaration */ && node.name.kind === 7 /* StringLiteral */) { return '"' + node.name.text + '"'; } return node.name.text; @@ -5927,7 +6059,10 @@ var ts; if (node.name) { node.name.parent = node; } - file.semanticErrors.push(ts.createDiagnosticForNode(node.name ? node.name : node, ts.Diagnostics.Duplicate_identifier_0, getDisplayName(node))); + ts.forEach(symbol.declarations, function (declaration) { + file.semanticErrors.push(ts.createDiagnosticForNode(declaration.name, ts.Diagnostics.Duplicate_identifier_0, getDisplayName(declaration))); + }); + file.semanticErrors.push(ts.createDiagnosticForNode(node.name, ts.Diagnostics.Duplicate_identifier_0, getDisplayName(node))); symbol = createSymbol(0, name); } } @@ -5936,7 +6071,7 @@ var ts; } addDeclarationToSymbol(symbol, node, includes); symbol.parent = parent; - if (node.kind === 174 /* ClassDeclaration */ && symbol.exports) { + if (node.kind === 176 /* ClassDeclaration */ && symbol.exports) { var prototypeSymbol = createSymbol(2 /* Property */ | 67108864 /* Prototype */, "prototype"); if (ts.hasProperty(symbol.exports, prototypeSymbol.name)) { if (node.name) { @@ -5968,7 +6103,7 @@ var ts; if (symbolKind & ts.SymbolFlags.Namespace) { exportKind |= 2097152 /* ExportNamespace */; } - if (node.flags & 1 /* Export */ || (node.kind !== 179 /* ImportDeclaration */ && isAmbientContext(container))) { + if (node.flags & 1 /* Export */ || (node.kind !== 181 /* ImportDeclaration */ && isAmbientContext(container))) { if (exportKind) { var local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes); local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); @@ -6004,10 +6139,10 @@ var ts; } function bindDeclaration(node, symbolKind, symbolExcludes) { switch (container.kind) { - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: declareModuleMember(node, symbolKind, symbolExcludes); break; - case 182 /* SourceFile */: + case 184 /* SourceFile */: if (ts.isExternalModule(container)) { declareModuleMember(node, symbolKind, symbolExcludes); break; @@ -6019,22 +6154,22 @@ var ts; case 121 /* Constructor */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes); break; - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: if (node.flags & 128 /* Static */) { declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); break; } case 129 /* TypeLiteral */: - case 133 /* ObjectLiteral */: - case 175 /* InterfaceDeclaration */: + case 135 /* ObjectLiteral */: + case 177 /* InterfaceDeclaration */: declareSymbol(container.symbol.members, container.symbol, node, symbolKind, symbolExcludes); break; - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); break; } @@ -6081,14 +6216,14 @@ var ts; case 118 /* Parameter */: bindDeclaration(node, 1 /* Variable */, ts.SymbolFlags.ParameterExcludes); break; - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: bindDeclaration(node, 1 /* Variable */, ts.SymbolFlags.VariableExcludes); break; case 119 /* Property */: - case 134 /* PropertyAssignment */: + case 136 /* PropertyAssignment */: bindDeclaration(node, 2 /* Property */, ts.SymbolFlags.PropertyExcludes); break; - case 181 /* EnumMember */: + case 183 /* EnumMember */: bindDeclaration(node, 4 /* EnumMember */, ts.SymbolFlags.EnumMemberExcludes); break; case 124 /* CallSignature */: @@ -6103,7 +6238,7 @@ var ts; case 126 /* IndexSignature */: bindDeclaration(node, 131072 /* IndexSignature */, 0); break; - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: bindDeclaration(node, 8 /* Function */, ts.SymbolFlags.FunctionExcludes); break; case 121 /* Constructor */: @@ -6118,34 +6253,34 @@ var ts; case 129 /* TypeLiteral */: bindAnonymousDeclaration(node, 512 /* TypeLiteral */, "__type"); break; - case 133 /* ObjectLiteral */: + case 135 /* ObjectLiteral */: bindAnonymousDeclaration(node, 1024 /* ObjectLiteral */, "__object"); break; - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: bindAnonymousDeclaration(node, 8 /* Function */, "__function"); break; - case 168 /* CatchBlock */: + case 170 /* CatchBlock */: bindCatchVariableDeclaration(node); break; - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: bindDeclaration(node, 16 /* Class */, ts.SymbolFlags.ClassExcludes); break; - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: bindDeclaration(node, 32 /* Interface */, ts.SymbolFlags.InterfaceExcludes); break; - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: bindDeclaration(node, 64 /* Enum */, ts.SymbolFlags.EnumExcludes); break; - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: bindModuleDeclaration(node); break; - case 179 /* ImportDeclaration */: + case 181 /* ImportDeclaration */: bindDeclaration(node, 4194304 /* Import */, ts.SymbolFlags.ImportExcludes); break; - case 182 /* SourceFile */: + case 184 /* SourceFile */: if (ts.isExternalModule(node)) { - bindAnonymousDeclaration(node, 128 /* ValueModule */, '"' + ts.getModuleNameFromFilename(node.filename) + '"'); + bindAnonymousDeclaration(node, 128 /* ValueModule */, '"' + ts.removeFileExtension(node.filename) + '"'); break; } default: @@ -6167,11 +6302,12 @@ var ts; } return indentStrings[level]; } + ts.getIndentString = getIndentString; function getIndentSize() { return indentStrings[1].length; } function shouldEmitToOwnFile(sourceFile, compilerOptions) { - if (!(sourceFile.flags & 1024 /* DeclarationFile */)) { + if (!ts.isDeclarationFile(sourceFile)) { if ((ts.isExternalModule(sourceFile) || !compilerOptions.out) && !ts.fileExtensionIs(sourceFile.filename, ".js")) { return true; } @@ -6181,7 +6317,7 @@ var ts; } ts.shouldEmitToOwnFile = shouldEmitToOwnFile; function isExternalModuleOrDeclarationFile(sourceFile) { - return ts.isExternalModule(sourceFile) || (sourceFile.flags & 1024 /* DeclarationFile */) !== 0; + return ts.isExternalModule(sourceFile) || ts.isDeclarationFile(sourceFile); } ts.isExternalModuleOrDeclarationFile = isExternalModuleOrDeclarationFile; function emitFiles(resolver, targetSourceFile) { @@ -6198,10 +6334,10 @@ var ts; } function getOwnEmitOutputFilePath(sourceFile, extension) { if (compilerOptions.outDir) { - var emitOutputFilePathWithoutExtension = ts.getModuleNameFromFilename(getSourceFilePathInNewDir(compilerOptions.outDir, sourceFile)); + var emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(compilerOptions.outDir, sourceFile)); } else { - var emitOutputFilePathWithoutExtension = ts.getModuleNameFromFilename(sourceFile.filename); + var emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.filename); } return emitOutputFilePathWithoutExtension + extension; } @@ -6235,7 +6371,7 @@ var ts; setAccessor: setAccessor }; } - function createTextWriter(writeSymbol) { + function createTextWriter() { var output = ""; var indent = 0; var lineStart = true; @@ -6278,7 +6414,6 @@ var ts; } return { write: write, - writeSymbol: writeSymbol, rawWrite: rawWrite, writeLiteral: writeLiteral, writeLine: writeLine, @@ -6387,7 +6522,7 @@ var ts; } } function emitJavaScript(jsFilePath, root) { - var writer = createTextWriter(writeSymbol); + var writer = createTextWriter(); var write = writer.write; var writeLine = writer.writeLine; var increaseIndent = writer.increaseIndent; @@ -6417,8 +6552,6 @@ var ts; var scopeEmitEnd = function () { }; var sourceMapData; - function writeSymbol(symbol, enclosingDeclaration, meaning) { - } function initializeEmitterWithSourceMaps() { var sourceMapDir; var sourceMapSourceIndex = -1; @@ -6523,7 +6656,7 @@ var ts; } function recordNewSourceFileStart(node) { var sourcesDirectoryPath = compilerOptions.sourceRoot ? program.getCommonSourceDirectory() : sourceMapDir; - sourceMapData.sourceMapSources.push(ts.getRelativePathToDirectoryOrUrl(sourcesDirectoryPath, node.filename, compilerHost.getCurrentDirectory(), true)); + sourceMapData.sourceMapSources.push(ts.getRelativePathToDirectoryOrUrl(sourcesDirectoryPath, node.filename, compilerHost.getCurrentDirectory(), compilerHost.getCanonicalFileName, true)); sourceMapSourceIndex = sourceMapData.sourceMapSources.length - 1; sourceMapData.inputSourceFileNames.push(node.filename); } @@ -6550,7 +6683,7 @@ var ts; if (scopeName) { recordScopeNameStart(scopeName); } - else if (node.kind === 172 /* FunctionDeclaration */ || node.kind === 141 /* FunctionExpression */ || node.kind === 120 /* Method */ || node.kind === 122 /* GetAccessor */ || node.kind === 123 /* SetAccessor */ || node.kind === 177 /* ModuleDeclaration */ || node.kind === 174 /* ClassDeclaration */ || node.kind === 176 /* EnumDeclaration */) { + else if (node.kind === 174 /* FunctionDeclaration */ || node.kind === 143 /* FunctionExpression */ || node.kind === 120 /* Method */ || node.kind === 122 /* GetAccessor */ || node.kind === 123 /* SetAccessor */ || node.kind === 179 /* ModuleDeclaration */ || node.kind === 176 /* ClassDeclaration */ || node.kind === 178 /* EnumDeclaration */) { if (node.name) { scopeName = node.name.text; } @@ -6569,20 +6702,6 @@ var ts; writeCommentRange(comment, writer); recordSourceMapSpan(comment.end); } - var escapedCharsRegExp = /[\t\v\f\b\0\r\n\"\u2028\u2029\u0085]/g; - var escapedCharsMap = { - "\t": "\\t", - "\v": "\\v", - "\f": "\\f", - "\b": "\\b", - "\0": "\\0", - "\r": "\\r", - "\n": "\\n", - "\"": "\\\"", - "\u2028": "\\u2028", - "\u2029": "\\u2029", - "\u0085": "\\u0085" - }; function serializeSourceMapContents(version, file, sourceRoot, sources, names, mappings) { if (typeof JSON !== "undefined") { return JSON.stringify({ @@ -6594,19 +6713,14 @@ var ts; mappings: mappings }); } - return "{\"version\":" + version + ",\"file\":\"" + escapeString(file) + "\",\"sourceRoot\":\"" + escapeString(sourceRoot) + "\",\"sources\":[" + serializeStringArray(sources) + "],\"names\":[" + serializeStringArray(names) + "],\"mappings\":\"" + escapeString(mappings) + "\"}"; - function escapeString(s) { - return escapedCharsRegExp.test(s) ? s.replace(escapedCharsRegExp, function (c) { - return escapedCharsMap[c] || c; - }) : s; - } + return "{\"version\":" + version + ",\"file\":\"" + ts.escapeString(file) + "\",\"sourceRoot\":\"" + ts.escapeString(sourceRoot) + "\",\"sources\":[" + serializeStringArray(sources) + "],\"names\":[" + serializeStringArray(names) + "],\"mappings\":\"" + ts.escapeString(mappings) + "\"}"; function serializeStringArray(list) { var output = ""; for (var i = 0, n = list.length; i < n; i++) { if (i) { output += ","; } - output += "\"" + escapeString(list[i]) + "\""; + output += "\"" + ts.escapeString(list[i]) + "\""; } return output; } @@ -6640,7 +6754,7 @@ var ts; } if (!ts.isRootedDiskPath(sourceMapDir) && !ts.isUrl(sourceMapDir)) { sourceMapDir = ts.combinePaths(program.getCommonSourceDirectory(), sourceMapDir); - sourceMapData.jsSourceMappingURL = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizePath(jsFilePath)), ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL), compilerHost.getCurrentDirectory(), true); + sourceMapData.jsSourceMappingURL = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizePath(jsFilePath)), ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL), compilerHost.getCurrentDirectory(), compilerHost.getCanonicalFileName, true); } else { sourceMapData.jsSourceMappingURL = ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL); @@ -6651,7 +6765,7 @@ var ts; } function emitNodeWithMap(node) { if (node) { - if (node.kind != 182 /* SourceFile */) { + if (node.kind != 184 /* SourceFile */) { recordEmitNodeStartSpan(node); emitNode(node); recordEmitNodeEndSpan(node); @@ -6690,25 +6804,42 @@ var ts; emit(node); } } - function emitCommaList(nodes, count) { - if (!(count >= 0)) - count = nodes.length; - if (nodes) { - for (var i = 0; i < count; i++) { - if (i) - write(", "); - emit(nodes[i]); + function emitTrailingCommaIfPresent(nodeList, isMultiline) { + if (nodeList.hasTrailingComma) { + write(","); + if (isMultiline) { + writeLine(); } } } - function emitMultiLineList(nodes) { + function emitCommaList(nodes, includeTrailingComma, count) { + if (!(count >= 0)) { + count = nodes.length; + } + if (nodes) { + for (var i = 0; i < count; i++) { + if (i) { + write(", "); + } + emit(nodes[i]); + } + if (includeTrailingComma) { + emitTrailingCommaIfPresent(nodes, false); + } + } + } + function emitMultiLineList(nodes, includeTrailingComma) { if (nodes) { for (var i = 0; i < nodes.length; i++) { - if (i) + if (i) { write(","); + } writeLine(); emit(nodes[i]); } + if (includeTrailingComma) { + emitTrailingCommaIfPresent(nodes, true); + } } } function emitLines(nodes) { @@ -6748,28 +6879,28 @@ var ts; var parent = node.parent; switch (parent.kind) { case 118 /* Parameter */: - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: case 119 /* Property */: - case 134 /* PropertyAssignment */: - case 181 /* EnumMember */: + case 136 /* PropertyAssignment */: + case 183 /* EnumMember */: case 120 /* Method */: - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 141 /* FunctionExpression */: - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 176 /* EnumDeclaration */: - case 177 /* ModuleDeclaration */: - case 179 /* ImportDeclaration */: + case 143 /* FunctionExpression */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: + case 179 /* ModuleDeclaration */: + case 181 /* ImportDeclaration */: return parent.name === node; - case 158 /* BreakStatement */: - case 157 /* ContinueStatement */: - case 180 /* ExportAssignment */: + case 160 /* BreakStatement */: + case 159 /* ContinueStatement */: + case 182 /* ExportAssignment */: return false; - case 164 /* LabeledStatement */: + case 166 /* LabeledStatement */: return node.parent.label === node; - case 168 /* CatchBlock */: + case 170 /* CatchBlock */: return node.parent.variable === node; } } @@ -6807,14 +6938,14 @@ var ts; if (node.flags & 256 /* MultiLine */) { write("["); increaseIndent(); - emitMultiLineList(node.elements); + emitMultiLineList(node.elements, true); decreaseIndent(); writeLine(); write("]"); } else { write("["); - emitCommaList(node.elements); + emitCommaList(node.elements, true); write("]"); } } @@ -6825,14 +6956,14 @@ var ts; else if (node.flags & 256 /* MultiLine */) { write("{"); increaseIndent(); - emitMultiLineList(node.properties); + emitMultiLineList(node.properties, compilerOptions.target >= 1 /* ES5 */); decreaseIndent(); writeLine(); write("}"); } else { write("{ "); - emitCommaList(node.properties); + emitCommaList(node.properties, compilerOptions.target >= 1 /* ES5 */); write(" }"); } } @@ -6844,14 +6975,15 @@ var ts; emitTrailingComments(node); } function emitPropertyAccess(node) { - var text = resolver.getPropertyAccessSubstitution(node); - if (text) { - write(text); - return; + var constantValue = resolver.getConstantValue(node); + if (constantValue !== undefined) { + write(constantValue.toString() + " /* " + ts.identifierToString(node.right) + " */"); + } + else { + emit(node.left); + write("."); + emit(node.right); } - emit(node.left); - write("."); - emit(node.right); } function emitIndexedAccess(node) { emit(node.object); @@ -6867,20 +6999,20 @@ var ts; } else { emit(node.func); - superCall = node.func.kind === 135 /* PropertyAccess */ && node.func.left.kind === 85 /* SuperKeyword */; + superCall = node.func.kind === 137 /* PropertyAccess */ && node.func.left.kind === 85 /* SuperKeyword */; } if (superCall) { write(".call("); emitThis(node.func); if (node.arguments.length) { write(", "); - emitCommaList(node.arguments); + emitCommaList(node.arguments, false); } write(")"); } else { write("("); - emitCommaList(node.arguments); + emitCommaList(node.arguments, false); write(")"); } } @@ -6889,17 +7021,17 @@ var ts; emit(node.func); if (node.arguments) { write("("); - emitCommaList(node.arguments); + emitCommaList(node.arguments, false); write(")"); } } function emitParenExpression(node) { - if (node.expression.kind === 139 /* TypeAssertion */) { + if (node.expression.kind === 141 /* TypeAssertion */) { var operand = node.expression.operand; - while (operand.kind == 139 /* TypeAssertion */) { + while (operand.kind == 141 /* TypeAssertion */) { operand = operand.operand; } - if (operand.kind !== 143 /* PrefixOperator */ && operand.kind !== 144 /* PostfixOperator */ && operand.kind !== 138 /* NewExpression */ && !(operand.kind === 137 /* CallExpression */ && node.parent.kind === 138 /* NewExpression */) && !(operand.kind === 141 /* FunctionExpression */ && node.parent.kind === 137 /* CallExpression */)) { + if (operand.kind !== 145 /* PrefixOperator */ && operand.kind !== 146 /* PostfixOperator */ && operand.kind !== 140 /* NewExpression */ && !(operand.kind === 139 /* CallExpression */ && node.parent.kind === 140 /* NewExpression */) && !(operand.kind === 143 /* FunctionExpression */ && node.parent.kind === 139 /* CallExpression */)) { emit(operand); return; } @@ -6909,13 +7041,13 @@ var ts; write(")"); } function emitUnaryExpression(node) { - if (node.kind === 143 /* PrefixOperator */) { + if (node.kind === 145 /* PrefixOperator */) { write(ts.tokenToString(node.operator)); } if (node.operator >= 59 /* Identifier */) { write(" "); } - else if (node.kind === 143 /* PrefixOperator */ && node.operand.kind === 143 /* PrefixOperator */) { + else if (node.kind === 145 /* PrefixOperator */ && node.operand.kind === 145 /* PrefixOperator */) { var operand = node.operand; if (node.operator === 28 /* PlusToken */ && (operand.operator === 28 /* PlusToken */ || operand.operator === 33 /* PlusPlusToken */)) { write(" "); @@ -6925,7 +7057,7 @@ var ts; } } emit(node.operand); - if (node.kind === 144 /* PostfixOperator */) { + if (node.kind === 146 /* PostfixOperator */) { write(ts.tokenToString(node.operator)); } } @@ -6948,8 +7080,8 @@ var ts; emitToken(9 /* OpenBraceToken */, node.pos); increaseIndent(); scopeEmitStart(node.parent); - if (node.kind === 178 /* ModuleBlock */) { - ts.Debug.assert(node.parent.kind === 177 /* ModuleDeclaration */); + if (node.kind === 180 /* ModuleBlock */) { + ts.Debug.assert(node.parent.kind === 179 /* ModuleDeclaration */); emitCaptureThisForNodeIfNecessary(node.parent); } emitLines(node.statements); @@ -6959,7 +7091,7 @@ var ts; scopeEmitEnd(); } function emitEmbeddedStatement(node) { - if (node.kind === 148 /* Block */) { + if (node.kind === 150 /* Block */) { write(" "); emit(node); } @@ -6971,7 +7103,7 @@ var ts; } } function emitExpressionStatement(node) { - var isArrowExpression = node.expression.kind === 142 /* ArrowFunction */; + var isArrowExpression = node.expression.kind === 144 /* ArrowFunction */; emitLeadingComments(node); if (isArrowExpression) write("("); @@ -6992,7 +7124,7 @@ var ts; if (node.elseStatement) { writeLine(); emitToken(70 /* ElseKeyword */, node.thenStatement.end); - if (node.elseStatement.kind === 152 /* IfStatement */) { + if (node.elseStatement.kind === 154 /* IfStatement */) { write(" "); emit(node.elseStatement); } @@ -7005,7 +7137,7 @@ var ts; function emitDoStatement(node) { write("do"); emitEmbeddedStatement(node.statement); - if (node.statement.kind === 148 /* Block */) { + if (node.statement.kind === 150 /* Block */) { write(" "); } else { @@ -7028,7 +7160,7 @@ var ts; if (node.declarations) { emitToken(92 /* VarKeyword */, endPos); write(" "); - emitCommaList(node.declarations); + emitCommaList(node.declarations, false); } if (node.initializer) { emit(node.initializer); @@ -7058,7 +7190,7 @@ var ts; emitEmbeddedStatement(node.statement); } function emitBreakOrContinueStatement(node) { - emitToken(node.kind === 158 /* BreakStatement */ ? 60 /* BreakKeyword */ : 65 /* ContinueKeyword */, node.pos); + emitToken(node.kind === 160 /* BreakStatement */ ? 60 /* BreakKeyword */ : 65 /* ContinueKeyword */, node.pos); emitOptional(" ", node.label); write(";"); } @@ -7090,7 +7222,7 @@ var ts; emitToken(10 /* CloseBraceToken */, node.clauses.end); } function emitCaseOrDefaultClause(node) { - if (node.kind === 162 /* CaseClause */) { + if (node.kind === 164 /* CaseClause */) { write("case "); emit(node.expression); write(":"); @@ -7139,7 +7271,7 @@ var ts; function getContainingModule(node) { do { node = node.parent; - } while (node && node.kind !== 177 /* ModuleDeclaration */); + } while (node && node.kind !== 179 /* ModuleDeclaration */); return node; } function emitModuleMemberName(node) { @@ -7162,7 +7294,7 @@ var ts; emitLeadingComments(node); if (!(node.flags & 1 /* Export */)) write("var "); - emitCommaList(node.declarations); + emitCommaList(node.declarations, false); write(";"); emitTrailingComments(node); } @@ -7242,7 +7374,7 @@ var ts; emitLeadingComments(node); } write("function "); - if (node.kind === 172 /* FunctionDeclaration */ || (node.kind === 141 /* FunctionExpression */ && node.name)) { + if (node.kind === 174 /* FunctionDeclaration */ || (node.kind === 143 /* FunctionExpression */ && node.name)) { emit(node.name); } emitSignatureAndBody(node); @@ -7262,7 +7394,7 @@ var ts; increaseIndent(); write("("); if (node) { - emitCommaList(node.parameters, node.parameters.length - (ts.hasRestParameters(node) ? 1 : 0)); + emitCommaList(node.parameters, false, node.parameters.length - (ts.hasRestParameters(node) ? 1 : 0)); } write(")"); decreaseIndent(); @@ -7272,16 +7404,16 @@ var ts; write(" {"); scopeEmitStart(node); increaseIndent(); - emitDetachedComments(node.body.kind === 173 /* FunctionBlock */ ? node.body.statements : node.body); + emitDetachedComments(node.body.kind === 175 /* FunctionBlock */ ? node.body.statements : node.body); var startIndex = 0; - if (node.body.kind === 173 /* FunctionBlock */) { + if (node.body.kind === 175 /* FunctionBlock */) { startIndex = emitDirectivePrologues(node.body.statements, true); } var outPos = writer.getTextPos(); emitCaptureThisForNodeIfNecessary(node); emitDefaultValueAssignments(node); emitRestParameter(node); - if (node.body.kind !== 173 /* FunctionBlock */ && outPos === writer.getTextPos()) { + if (node.body.kind !== 175 /* FunctionBlock */ && outPos === writer.getTextPos()) { decreaseIndent(); write(" "); emitStart(node.body); @@ -7294,7 +7426,7 @@ var ts; emitEnd(node.body); } else { - if (node.body.kind === 173 /* FunctionBlock */) { + if (node.body.kind === 175 /* FunctionBlock */) { emitLinesStartingAt(node.body.statements, startIndex); } else { @@ -7306,7 +7438,7 @@ var ts; emitTrailingComments(node.body); } writeLine(); - if (node.body.kind === 173 /* FunctionBlock */) { + if (node.body.kind === 175 /* FunctionBlock */) { emitLeadingCommentsOfPosition(node.body.statements.end); decreaseIndent(); emitToken(10 /* CloseBraceToken */, node.body.statements.end); @@ -7332,9 +7464,9 @@ var ts; function findInitialSuperCall(ctor) { if (ctor.body) { var statement = ctor.body.statements[0]; - if (statement && statement.kind === 151 /* ExpressionStatement */) { + if (statement && statement.kind === 153 /* ExpressionStatement */) { var expr = statement.expression; - if (expr && expr.kind === 137 /* CallExpression */) { + if (expr && expr.kind === 139 /* CallExpression */) { var func = expr.func; if (func && func.kind === 85 /* SuperKeyword */) { return statement; @@ -7648,7 +7780,7 @@ var ts; } } function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration) { - if (moduleDeclaration.body.kind === 177 /* ModuleDeclaration */) { + if (moduleDeclaration.body.kind === 179 /* ModuleDeclaration */) { var recursiveInnerModule = getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration.body); return recursiveInnerModule || moduleDeclaration.body; } @@ -7670,7 +7802,7 @@ var ts; write(resolver.getLocalNameOfContainer(node)); emitEnd(node.name); write(") "); - if (node.body.kind === 178 /* ModuleBlock */) { + if (node.body.kind === 180 /* ModuleBlock */) { emit(node.body); } else { @@ -7704,7 +7836,7 @@ var ts; emitImportDeclaration = !ts.isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportedViaEntityName(node); } if (emitImportDeclaration) { - if (node.externalModuleName && node.parent.kind === 182 /* SourceFile */ && compilerOptions.module === 2 /* AMD */) { + if (node.externalModuleName && node.parent.kind === 184 /* SourceFile */ && compilerOptions.module === 2 /* AMD */) { if (node.flags & 1 /* Export */) { writeLine(); emitLeadingComments(node); @@ -7744,7 +7876,7 @@ var ts; function getExternalImportDeclarations(node) { var result = []; ts.forEach(node.statements, function (stat) { - if (stat.kind === 179 /* ImportDeclaration */ && stat.externalModuleName && resolver.isReferencedImportDeclaration(stat)) { + if (stat.kind === 181 /* ImportDeclaration */ && stat.externalModuleName && resolver.isReferencedImportDeclaration(stat)) { result.push(stat); } }); @@ -7752,7 +7884,7 @@ var ts; } function getFirstExportAssignment(sourceFile) { return ts.forEach(sourceFile.statements, function (node) { - if (node.kind === 180 /* ExportAssignment */) { + if (node.kind === 182 /* ExportAssignment */) { return node; } }); @@ -7891,94 +8023,94 @@ var ts; return emitLiteral(node); case 116 /* QualifiedName */: return emitPropertyAccess(node); - case 132 /* ArrayLiteral */: + case 134 /* ArrayLiteral */: return emitArrayLiteral(node); - case 133 /* ObjectLiteral */: + case 135 /* ObjectLiteral */: return emitObjectLiteral(node); - case 134 /* PropertyAssignment */: + case 136 /* PropertyAssignment */: return emitPropertyAssignment(node); - case 135 /* PropertyAccess */: + case 137 /* PropertyAccess */: return emitPropertyAccess(node); - case 136 /* IndexedAccess */: + case 138 /* IndexedAccess */: return emitIndexedAccess(node); - case 137 /* CallExpression */: + case 139 /* CallExpression */: return emitCallExpression(node); - case 138 /* NewExpression */: + case 140 /* NewExpression */: return emitNewExpression(node); - case 139 /* TypeAssertion */: + case 141 /* TypeAssertion */: return emit(node.operand); - case 140 /* ParenExpression */: + case 142 /* ParenExpression */: return emitParenExpression(node); - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: return emitFunctionDeclaration(node); - case 143 /* PrefixOperator */: - case 144 /* PostfixOperator */: + case 145 /* PrefixOperator */: + case 146 /* PostfixOperator */: return emitUnaryExpression(node); - case 145 /* BinaryExpression */: + case 147 /* BinaryExpression */: return emitBinaryExpression(node); - case 146 /* ConditionalExpression */: + case 148 /* ConditionalExpression */: return emitConditionalExpression(node); - case 147 /* OmittedExpression */: + case 149 /* OmittedExpression */: return; - case 148 /* Block */: - case 167 /* TryBlock */: - case 169 /* FinallyBlock */: - case 173 /* FunctionBlock */: - case 178 /* ModuleBlock */: + case 150 /* Block */: + case 169 /* TryBlock */: + case 171 /* FinallyBlock */: + case 175 /* FunctionBlock */: + case 180 /* ModuleBlock */: return emitBlock(node); - case 149 /* VariableStatement */: + case 151 /* VariableStatement */: return emitVariableStatement(node); - case 150 /* EmptyStatement */: + case 152 /* EmptyStatement */: return write(";"); - case 151 /* ExpressionStatement */: + case 153 /* ExpressionStatement */: return emitExpressionStatement(node); - case 152 /* IfStatement */: + case 154 /* IfStatement */: return emitIfStatement(node); - case 153 /* DoStatement */: + case 155 /* DoStatement */: return emitDoStatement(node); - case 154 /* WhileStatement */: + case 156 /* WhileStatement */: return emitWhileStatement(node); - case 155 /* ForStatement */: + case 157 /* ForStatement */: return emitForStatement(node); - case 156 /* ForInStatement */: + case 158 /* ForInStatement */: return emitForInStatement(node); - case 157 /* ContinueStatement */: - case 158 /* BreakStatement */: + case 159 /* ContinueStatement */: + case 160 /* BreakStatement */: return emitBreakOrContinueStatement(node); - case 159 /* ReturnStatement */: + case 161 /* ReturnStatement */: return emitReturnStatement(node); - case 160 /* WithStatement */: + case 162 /* WithStatement */: return emitWithStatement(node); - case 161 /* SwitchStatement */: + case 163 /* SwitchStatement */: return emitSwitchStatement(node); - case 162 /* CaseClause */: - case 163 /* DefaultClause */: + case 164 /* CaseClause */: + case 165 /* DefaultClause */: return emitCaseOrDefaultClause(node); - case 164 /* LabeledStatement */: + case 166 /* LabeledStatement */: return emitLabelledStatement(node); - case 165 /* ThrowStatement */: + case 167 /* ThrowStatement */: return emitThrowStatement(node); - case 166 /* TryStatement */: + case 168 /* TryStatement */: return emitTryStatement(node); - case 168 /* CatchBlock */: + case 170 /* CatchBlock */: return emitCatchBlock(node); - case 170 /* DebuggerStatement */: + case 172 /* DebuggerStatement */: return emitDebuggerStatement(node); - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: return emitVariableDeclaration(node); - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: return emitClassDeclaration(node); - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: return emitInterfaceDeclaration(node); - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: return emitEnumDeclaration(node); - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return emitModuleDeclaration(node); - case 179 /* ImportDeclaration */: + case 181 /* ImportDeclaration */: return emitImportDeclaration(node); - case 182 /* SourceFile */: + case 184 /* SourceFile */: return emitSourceFile(node); } } @@ -7986,7 +8118,7 @@ var ts; return detachedCommentsInfo !== undefined && detachedCommentsInfo[detachedCommentsInfo.length - 1].nodePos === pos; } function getLeadingCommentsWithoutDetachedComments() { - var leadingComments = ts.getLeadingComments(currentSourceFile.text, detachedCommentsInfo[detachedCommentsInfo.length - 1].detachedCommentEndPos); + var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, detachedCommentsInfo[detachedCommentsInfo.length - 1].detachedCommentEndPos); if (detachedCommentsInfo.length - 1) { detachedCommentsInfo.pop(); } @@ -7996,13 +8128,13 @@ var ts; return leadingComments; } function getLeadingCommentsToEmit(node) { - if (node.parent.kind === 182 /* SourceFile */ || node.pos !== node.parent.pos) { + if (node.parent.kind === 184 /* SourceFile */ || node.pos !== node.parent.pos) { var leadingComments; if (hasDetachedComments(node.pos)) { leadingComments = getLeadingCommentsWithoutDetachedComments(); } else { - leadingComments = ts.getLeadingCommentsOfNode(node, currentSourceFile); + leadingComments = ts.getLeadingCommentRangesOfNode(node, currentSourceFile); } return leadingComments; } @@ -8013,8 +8145,8 @@ var ts; emitComments(leadingComments, true, writer, writeComment); } function emitTrailingDeclarationComments(node) { - if (node.parent.kind === 182 /* SourceFile */ || node.end !== node.parent.end) { - var trailingComments = ts.getTrailingComments(currentSourceFile.text, node.end); + if (node.parent.kind === 184 /* SourceFile */ || node.end !== node.parent.end) { + var trailingComments = ts.getTrailingCommentRanges(currentSourceFile.text, node.end); emitComments(trailingComments, false, writer, writeComment); } } @@ -8024,13 +8156,13 @@ var ts; leadingComments = getLeadingCommentsWithoutDetachedComments(); } else { - leadingComments = ts.getLeadingComments(currentSourceFile.text, pos); + leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, pos); } emitNewLineBeforeLeadingComments({ pos: pos, end: pos }, leadingComments, writer); emitComments(leadingComments, true, writer, writeComment); } function emitDetachedCommentsAtPosition(node) { - var leadingComments = ts.getLeadingComments(currentSourceFile.text, node.pos); + var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, node.pos); if (leadingComments) { var detachedComments = []; var lastComment; @@ -8092,7 +8224,7 @@ var ts; writeEmittedFiles(writer.getText(), compilerOptions.emitBOM); } function emitDeclarations(jsFilePath, root) { - var writer = createTextWriter(writeSymbol); + var writer = createTextWriterWithSymbolWriter(); var write = writer.write; var writeLine = writer.writeLine; var increaseIndent = writer.increaseIndent; @@ -8103,11 +8235,23 @@ var ts; } : writeJsDocComments; var aliasDeclarationEmitInfo = []; var getSymbolVisibilityDiagnosticMessage; + function createTextWriterWithSymbolWriter() { + var writer = createTextWriter(); + writer.trackSymbol = trackSymbol; + writer.writeKeyword = writer.write; + writer.writeOperator = writer.write; + writer.writePunctuation = writer.write; + writer.writeSpace = writer.write; + writer.writeStringLiteral = writer.writeLiteral; + writer.writeParameter = writer.write; + writer.writeSymbol = writer.write; + return writer; + } function writeAsychronousImportDeclarations(importDeclarations) { var oldWriter = writer; ts.forEach(importDeclarations, function (aliasToWrite) { var aliasEmitInfo = ts.forEach(aliasDeclarationEmitInfo, function (declEmitInfo) { return declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined; }); - writer = createTextWriter(writeSymbol); + writer = createTextWriterWithSymbolWriter(); for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) { writer.increaseIndent(); } @@ -8116,10 +8260,9 @@ var ts; }); writer = oldWriter; } - function writeSymbol(symbol, enclosingDeclaration, meaning) { + function trackSymbol(symbol, enclosingDeclaration, meaning) { var symbolAccesibilityResult = resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning); if (symbolAccesibilityResult.accessibility === 0 /* Accessible */) { - resolver.writeSymbol(symbol, enclosingDeclaration, meaning, writer); if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) { writeAsychronousImportDeclarations(symbolAccesibilityResult.aliasesToMakeVisible); } @@ -8194,7 +8337,7 @@ var ts; if (node.flags & 1 /* Export */) { write("export "); } - if (node.kind !== 175 /* InterfaceDeclaration */) { + if (node.kind !== 177 /* InterfaceDeclaration */) { write("declare "); } } @@ -8250,7 +8393,7 @@ var ts; emitDeclarationFlags(node); write("module "); emitSourceTextOfNode(node.name); - while (node.body.kind !== 178 /* ModuleBlock */) { + while (node.body.kind !== 180 /* ModuleBlock */) { node = node.body; write("."); emitSourceTextOfNode(node.name); @@ -8298,10 +8441,10 @@ var ts; function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; switch (node.parent.kind) { - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1; break; - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1; break; case 125 /* ConstructSignature */: @@ -8314,14 +8457,14 @@ var ts; if (node.parent.flags & 128 /* Static */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.parent.kind === 174 /* ClassDeclaration */) { + else if (node.parent.parent.kind === 176 /* ClassDeclaration */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; } else { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; } break; - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1; break; default: @@ -8359,7 +8502,7 @@ var ts; resolver.writeTypeAtLocation(node, enclosingDeclaration, 1 /* WriteArrayAsGenericType */ | 2 /* UseTypeOfFunction */, writer); function getHeritageClauseVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; - if (node.parent.kind === 174 /* ClassDeclaration */) { + if (node.parent.kind === 176 /* ClassDeclaration */) { if (symbolAccesibilityResult.errorModuleName) { diagnosticMessage = isImplementsList ? ts.Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2; } @@ -8444,7 +8587,7 @@ var ts; writeLine(); } function emitVariableDeclaration(node) { - if (node.kind !== 171 /* VariableDeclaration */ || resolver.isDeclarationVisible(node)) { + if (node.kind !== 173 /* VariableDeclaration */ || resolver.isDeclarationVisible(node)) { emitSourceTextOfNode(node.name); if (node.kind === 119 /* Property */ && (node.flags & 4 /* QuestionMark */)) { write("?"); @@ -8457,14 +8600,14 @@ var ts; } function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; - if (node.kind === 171 /* VariableDeclaration */) { + if (node.kind === 173 /* VariableDeclaration */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Exported_variable_0_has_or_is_using_private_name_1; } else if (node.kind === 119 /* Property */) { if (node.flags & 128 /* Static */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.kind === 174 /* ClassDeclaration */) { + else if (node.parent.kind === 176 /* ClassDeclaration */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1; } else { @@ -8535,10 +8678,10 @@ var ts; } } function emitFunctionDeclaration(node) { - if ((node.kind !== 172 /* FunctionDeclaration */ || resolver.isDeclarationVisible(node)) && !resolver.isImplementationOfOverload(node)) { + if ((node.kind !== 174 /* FunctionDeclaration */ || resolver.isDeclarationVisible(node)) && !resolver.isImplementationOfOverload(node)) { emitJsDocComments(node); emitDeclarationFlags(node); - if (node.kind === 172 /* FunctionDeclaration */) { + if (node.kind === 174 /* FunctionDeclaration */) { write("function "); emitSourceTextOfNode(node.name); } @@ -8600,14 +8743,14 @@ var ts; if (node.flags & 128 /* Static */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0; } - else if (node.parent.kind === 174 /* ClassDeclaration */) { + else if (node.parent.kind === 176 /* ClassDeclaration */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0; } else { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0; } break; - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_private_name_0; break; default: @@ -8651,14 +8794,14 @@ var ts; if (node.parent.flags & 128 /* Static */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.parent.kind === 174 /* ClassDeclaration */) { + else if (node.parent.parent.kind === 176 /* ClassDeclaration */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; } else { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; } break; - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1; break; default: @@ -8674,7 +8817,7 @@ var ts; function emitNode(node) { switch (node.kind) { case 121 /* Constructor */: - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: case 120 /* Method */: return emitFunctionDeclaration(node); case 125 /* ConstructSignature */: @@ -8685,44 +8828,44 @@ var ts; case 122 /* GetAccessor */: case 123 /* SetAccessor */: return emitAccessorDeclaration(node); - case 149 /* VariableStatement */: + case 151 /* VariableStatement */: return emitVariableStatement(node); case 119 /* Property */: return emitPropertyDeclaration(node); - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: return emitInterfaceDeclaration(node); - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: return emitClassDeclaration(node); - case 181 /* EnumMember */: + case 183 /* EnumMember */: return emitEnumMemberDeclaration(node); - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: return emitEnumDeclaration(node); - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return emitModuleDeclaration(node); - case 179 /* ImportDeclaration */: + case 181 /* ImportDeclaration */: return emitImportDeclaration(node); - case 180 /* ExportAssignment */: + case 182 /* ExportAssignment */: return emitExportAssignment(node); - case 182 /* SourceFile */: + case 184 /* SourceFile */: return emitSourceFile(node); } } - function resolveScriptReference(sourceFile, reference) { + function tryResolveScriptReference(sourceFile, reference) { var referenceFileName = ts.normalizePath(ts.combinePaths(ts.getDirectoryPath(sourceFile.filename), reference.filename)); return program.getSourceFile(referenceFileName); } var referencePathsOutput = ""; function writeReferencePath(referencedFile) { - var declFileName = referencedFile.flags & 1024 /* DeclarationFile */ ? referencedFile.filename : shouldEmitToOwnFile(referencedFile, compilerOptions) ? getOwnEmitOutputFilePath(referencedFile, ".d.ts") : ts.getModuleNameFromFilename(compilerOptions.out) + ".d.ts"; - declFileName = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizeSlashes(jsFilePath)), declFileName, compilerHost.getCurrentDirectory(), false); + var declFileName = referencedFile.flags & 1024 /* DeclarationFile */ ? referencedFile.filename : shouldEmitToOwnFile(referencedFile, compilerOptions) ? getOwnEmitOutputFilePath(referencedFile, ".d.ts") : ts.removeFileExtension(compilerOptions.out) + ".d.ts"; + declFileName = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizeSlashes(jsFilePath)), declFileName, compilerHost.getCurrentDirectory(), compilerHost.getCanonicalFileName, false); referencePathsOutput += "/// " + newLine; } if (root) { if (!compilerOptions.noResolve) { var addedGlobalFileReference = false; ts.forEach(root.referencedFiles, function (fileReference) { - var referencedFile = resolveScriptReference(root, fileReference); - if ((referencedFile.flags & 1024 /* DeclarationFile */) || shouldEmitToOwnFile(referencedFile, compilerOptions) || !addedGlobalFileReference) { + var referencedFile = tryResolveScriptReference(root, fileReference); + if (referencedFile && ((referencedFile.flags & 1024 /* DeclarationFile */) || shouldEmitToOwnFile(referencedFile, compilerOptions) || !addedGlobalFileReference)) { writeReferencePath(referencedFile); if (!isExternalModuleOrDeclarationFile(referencedFile)) { addedGlobalFileReference = true; @@ -8738,8 +8881,8 @@ var ts; if (!isExternalModuleOrDeclarationFile(sourceFile)) { if (!compilerOptions.noResolve) { ts.forEach(sourceFile.referencedFiles, function (fileReference) { - var referencedFile = resolveScriptReference(sourceFile, fileReference); - if (isExternalModuleOrDeclarationFile(referencedFile) && !ts.contains(emittedReferencedFiles, referencedFile)) { + var referencedFile = tryResolveScriptReference(sourceFile, fileReference); + if (referencedFile && (isExternalModuleOrDeclarationFile(referencedFile) && !ts.contains(emittedReferencedFiles, referencedFile))) { writeReferencePath(referencedFile); emittedReferencedFiles.push(referencedFile); } @@ -8761,7 +8904,7 @@ var ts; } }); declarationOutput += synchronousDeclarationOutput.substring(appliedSyncOutputPos); - writeFile(ts.getModuleNameFromFilename(jsFilePath) + ".d.ts", declarationOutput, compilerOptions.emitBOM); + writeFile(ts.removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, compilerOptions.emitBOM); } } var hasSemanticErrors = resolver.hasSemanticErrors(); @@ -8778,13 +8921,18 @@ var ts; emitFile(jsFilePath, sourceFile); } }); + if (compilerOptions.out) { + emitFile(compilerOptions.out); + } } else { - var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, ".js"); - emitFile(jsFilePath, targetSourceFile); - } - if (compilerOptions.out) { - emitFile(compilerOptions.out); + if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) { + var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, ".js"); + emitFile(jsFilePath, targetSourceFile); + } + else if (!ts.isDeclarationFile(targetSourceFile) && compilerOptions.out) { + emitFile(compilerOptions.out); + } } diagnostics.sort(ts.compareDiagnostics); diagnostics = ts.deduplicateSortedDiagnostics(diagnostics); @@ -8826,6 +8974,33 @@ var ts; return undefined; } ts.getDeclarationOfKind = getDeclarationOfKind; + var stringWriters = []; + function getSingleLineStringWriter() { + if (stringWriters.length == 0) { + var str = ""; + var writeText = function (text) { return str += text; }; + return { + string: function () { return str; }, + writeKeyword: writeText, + writeOperator: writeText, + writePunctuation: writeText, + writeSpace: writeText, + writeStringLiteral: writeText, + writeParameter: writeText, + writeSymbol: writeText, + writeLine: function () { return str += " "; }, + increaseIndent: function () { + }, + decreaseIndent: function () { + }, + clear: function () { return str = ""; }, + trackSymbol: function () { + } + }; + } + return stringWriters.pop(); + } + ts.getSingleLineStringWriter = getSingleLineStringWriter; function createTypeChecker(program, fullTypeCheck) { var Symbol = ts.objectAllocator.getSymbolConstructor(); var Type = ts.objectAllocator.getTypeConstructor(); @@ -8854,13 +9029,21 @@ var ts; getSymbolsInScope: getSymbolsInScope, getSymbolInfo: getSymbolInfo, getTypeOfNode: getTypeOfNode, - getApparentType: getApparentType, typeToString: typeToString, + getSymbolDisplayBuilder: getSymbolDisplayBuilder, symbolToString: symbolToString, - getAugmentedPropertiesOfApparentType: getAugmentedPropertiesOfApparentType, - getRootSymbol: getRootSymbol, + getAugmentedPropertiesOfType: getAugmentedPropertiesOfType, + getRootSymbols: getRootSymbols, getContextualType: getContextualType, - getFullyQualifiedName: getFullyQualifiedName + getFullyQualifiedName: getFullyQualifiedName, + getResolvedSignature: getResolvedSignature, + getEnumMemberValue: getEnumMemberValue, + isValidPropertyAccess: isValidPropertyAccess, + getSignatureFromDeclaration: getSignatureFromDeclaration, + isImplementationOfOverload: isImplementationOfOverload, + getAliasedSymbol: resolveImport, + isUndefinedSymbol: function (symbol) { return symbol === undefinedSymbol; }, + isArgumentsSymbol: function (symbol) { return symbol === argumentsSymbol; } }; var undefinedSymbol = createSymbol(2 /* Property */ | 33554432 /* Transient */, "undefined"); var argumentsSymbol = createSymbol(2 /* Property */ | 33554432 /* Transient */, "arguments"); @@ -8890,6 +9073,7 @@ var ts; var globalBooleanType; var globalRegExpType; var tupleTypes = {}; + var unionTypes = {}; var stringLiteralTypes = {}; var emitExtends = false; var mergedSymbols = []; @@ -9021,10 +9205,10 @@ var ts; return nodeLinks[node.id] || (nodeLinks[node.id] = {}); } function getSourceFile(node) { - return ts.getAncestor(node, 182 /* SourceFile */); + return ts.getAncestor(node, 184 /* SourceFile */); } function isGlobalSourceFile(node) { - return node.kind === 182 /* SourceFile */ && !ts.isExternalModule(node); + return node.kind === 184 /* SourceFile */ && !ts.isExternalModule(node); } function getSymbol(symbols, name, meaning) { if (meaning && ts.hasProperty(symbols, name)) { @@ -9064,21 +9248,21 @@ var ts; } } switch (location.kind) { - case 182 /* SourceFile */: + case 184 /* SourceFile */: if (!ts.isExternalModule(location)) break; - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & ts.SymbolFlags.ModuleMember)) { return returnResolvedSymbol(result); } break; - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 4 /* EnumMember */)) { return returnResolvedSymbol(result); } break; case 119 /* Property */: - if (location.parent.kind === 174 /* ClassDeclaration */ && !(location.flags & 128 /* Static */)) { + if (location.parent.kind === 176 /* ClassDeclaration */ && !(location.flags & 128 /* Static */)) { var ctor = findConstructorDeclaration(location.parent); if (ctor && ctor.locals) { if (getSymbol(ctor.locals, name, meaning & ts.SymbolFlags.Value)) { @@ -9087,8 +9271,8 @@ var ts; } } break; - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & ts.SymbolFlags.Type)) { if (lastLocation && lastLocation.flags & 128 /* Static */) { error(errorLocation, ts.Diagnostics.Static_members_cannot_reference_class_type_parameters); @@ -9103,13 +9287,13 @@ var ts; case 121 /* Constructor */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 172 /* FunctionDeclaration */: - case 142 /* ArrowFunction */: + case 174 /* FunctionDeclaration */: + case 144 /* ArrowFunction */: if (name === "arguments") { return returnResolvedSymbol(argumentsSymbol); } break; - case 141 /* FunctionExpression */: + case 143 /* FunctionExpression */: if (name === "arguments") { return returnResolvedSymbol(argumentsSymbol); } @@ -9118,7 +9302,7 @@ var ts; return returnResolvedSymbol(location.symbol); } break; - case 168 /* CatchBlock */: + case 170 /* CatchBlock */: var id = location.variable; if (name === id.text) { return returnResolvedSymbol(location.symbol); @@ -9138,7 +9322,7 @@ var ts; var links = getSymbolLinks(symbol); if (!links.target) { links.target = resolvingSymbol; - var node = getDeclarationOfKind(symbol, 179 /* ImportDeclaration */); + var node = getDeclarationOfKind(symbol, 181 /* ImportDeclaration */); var target = node.externalModuleName ? resolveExternalModuleName(node, node.externalModuleName) : getSymbolOfPartOfRightHandSideOfImport(node.entityName, node); if (links.target === resolvingSymbol) { links.target = target || unknownSymbol; @@ -9154,7 +9338,7 @@ var ts; } function getSymbolOfPartOfRightHandSideOfImport(entityName, importDeclaration) { if (!importDeclaration) { - importDeclaration = ts.getAncestor(entityName, 179 /* ImportDeclaration */); + importDeclaration = ts.getAncestor(entityName, 181 /* ImportDeclaration */); ts.Debug.assert(importDeclaration); } if (entityName.kind === 59 /* Identifier */ && isRightSideOfQualifiedNameOrPropertyAccess(entityName)) { @@ -9164,7 +9348,7 @@ var ts; return resolveEntityName(importDeclaration, entityName, ts.SymbolFlags.Namespace); } else { - ts.Debug.assert(entityName.parent.kind === 179 /* ImportDeclaration */); + ts.Debug.assert(entityName.parent.kind === 181 /* ImportDeclaration */); return resolveEntityName(importDeclaration, entityName, ts.SymbolFlags.Value | ts.SymbolFlags.Type | ts.SymbolFlags.Namespace); } } @@ -9269,9 +9453,9 @@ var ts; var seenExportedMember = false; var result = []; ts.forEach(symbol.declarations, function (declaration) { - var block = (declaration.kind === 182 /* SourceFile */ ? declaration : declaration.body); + var block = (declaration.kind === 184 /* SourceFile */ ? declaration : declaration.body); ts.forEach(block.statements, function (node) { - if (node.kind === 180 /* ExportAssignment */) { + if (node.kind === 182 /* ExportAssignment */) { result.push(node); } else { @@ -9298,15 +9482,15 @@ var ts; return symbol && (symbol.flags & 524288 /* ExportValue */) !== 0 ? getMergedSymbol(symbol.exportSymbol) : symbol; } function symbolIsValue(symbol) { + if (symbol.flags & 8388608 /* Instantiated */) { + return symbolIsValue(getSymbolLinks(symbol).target); + } if (symbol.flags & ts.SymbolFlags.Value) { return true; } if (symbol.flags & 4194304 /* Import */) { return (resolveImport(symbol).flags & ts.SymbolFlags.Value) !== 0; } - if (symbol.flags & 8388608 /* Instantiated */) { - return (getSymbolLinks(symbol).target.flags & ts.SymbolFlags.Value) !== 0; - } return false; } function findConstructorDeclaration(node) { @@ -9364,7 +9548,7 @@ var ts; return type; } function createAnonymousType(symbol, members, callSignatures, constructSignatures, stringIndexType, numberIndexType) { - return setObjectTypeMembers(createObjectType(16384 /* Anonymous */, symbol), members, callSignatures, constructSignatures, stringIndexType, numberIndexType); + return setObjectTypeMembers(createObjectType(32768 /* Anonymous */, symbol), members, callSignatures, constructSignatures, stringIndexType, numberIndexType); } function isOptionalProperty(propertySymbol) { return propertySymbol.valueDeclaration && propertySymbol.valueDeclaration.flags & 4 /* QuestionMark */ && propertySymbol.valueDeclaration.kind !== 118 /* Parameter */; @@ -9378,17 +9562,17 @@ var ts; } } switch (location.kind) { - case 182 /* SourceFile */: + case 184 /* SourceFile */: if (!ts.isExternalModule(location)) { break; } - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: if (result = callback(getSymbolOfNode(location).exports)) { return result; } break; - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: if (result = callback(getSymbolOfNode(location).members)) { return result; } @@ -9400,13 +9584,13 @@ var ts; function getQualifiedLeftMeaning(rightMeaning) { return rightMeaning === ts.SymbolFlags.Value ? ts.SymbolFlags.Value : ts.SymbolFlags.Namespace; } - function getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning) { + function getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, useOnlyExternalAliasing) { function getAccessibleSymbolChainFromSymbolTable(symbols) { function canQualifySymbol(symbolFromSymbolTable, meaning) { if (!needsQualification(symbolFromSymbolTable, enclosingDeclaration, meaning)) { return true; } - var accessibleParent = getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, getQualifiedLeftMeaning(meaning)); + var accessibleParent = getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, getQualifiedLeftMeaning(meaning), useOnlyExternalAliasing); return !!accessibleParent; } function isAccessible(symbolFromSymbolTable, resolvedAliasSymbol) { @@ -9419,13 +9603,15 @@ var ts; } return ts.forEachValue(symbols, function (symbolFromSymbolTable) { if (symbolFromSymbolTable.flags & 4194304 /* Import */) { - var resolvedImportedSymbol = resolveImport(symbolFromSymbolTable); - if (isAccessible(symbolFromSymbolTable, resolveImport(symbolFromSymbolTable))) { - return [symbolFromSymbolTable]; - } - var accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined; - if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, getQualifiedLeftMeaning(meaning))) { - return [symbolFromSymbolTable].concat(accessibleSymbolsFromExports); + if (!useOnlyExternalAliasing || ts.forEach(symbolFromSymbolTable.declarations, function (declaration) { return declaration.kind === 181 /* ImportDeclaration */ && declaration.externalModuleName; })) { + var resolvedImportedSymbol = resolveImport(symbolFromSymbolTable); + if (isAccessible(symbolFromSymbolTable, resolveImport(symbolFromSymbolTable))) { + return [symbolFromSymbolTable]; + } + var accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined; + if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, getQualifiedLeftMeaning(meaning))) { + return [symbolFromSymbolTable].concat(accessibleSymbolsFromExports); + } } } }); @@ -9458,7 +9644,7 @@ var ts; var initialSymbol = symbol; var meaningToLook = meaning; while (symbol) { - var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook); + var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook, false); if (accessibleSymbolChain) { var hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0]); if (!hasAccessibleDeclarations) { @@ -9499,7 +9685,7 @@ var ts; } } function hasExternalModuleSymbol(declaration) { - return (declaration.kind === 177 /* ModuleDeclaration */ && declaration.name.kind === 7 /* StringLiteral */) || (declaration.kind === 182 /* SourceFile */ && ts.isExternalModule(declaration)); + return (declaration.kind === 179 /* ModuleDeclaration */ && declaration.name.kind === 7 /* StringLiteral */) || (declaration.kind === 184 /* SourceFile */ && ts.isExternalModule(declaration)); } function hasVisibleDeclarations(symbol) { var aliasesToMakeVisible; @@ -9509,7 +9695,7 @@ var ts; return { aliasesToMakeVisible: aliasesToMakeVisible }; function getIsDeclarationVisible(declaration) { if (!isDeclarationVisible(declaration)) { - if (declaration.kind === 179 /* ImportDeclaration */ && !(declaration.flags & 1 /* Export */) && isDeclarationVisible(declaration.parent)) { + if (declaration.kind === 181 /* ImportDeclaration */ && !(declaration.flags & 1 /* Export */) && isDeclarationVisible(declaration.parent)) { getNodeLinks(declaration).isVisible = true; if (aliasesToMakeVisible) { if (!ts.contains(aliasesToMakeVisible, declaration)) { @@ -9533,283 +9719,416 @@ var ts; var hasNamespaceDeclarationsVisibile = hasVisibleDeclarations(symbolOfNameSpace); return hasNamespaceDeclarationsVisibile ? { accessibility: 0 /* Accessible */, aliasesToMakeVisible: hasNamespaceDeclarationsVisibile.aliasesToMakeVisible } : { accessibility: 1 /* NotAccessible */, errorSymbolName: firstIdentifierName }; } + function releaseStringWriter(writer) { + writer.clear(); + stringWriters.push(writer); + } + function writeKeyword(writer, kind) { + writer.writeKeyword(ts.tokenToString(kind)); + } + function writePunctuation(writer, kind) { + writer.writePunctuation(ts.tokenToString(kind)); + } + function writeOperator(writer, kind) { + writer.writeOperator(ts.tokenToString(kind)); + } + function writeSpace(writer) { + writer.writeSpace(" "); + } function symbolToString(symbol, enclosingDeclaration, meaning) { - function getSymbolName(symbol) { + var writer = getSingleLineStringWriter(); + getSymbolDisplayBuilder().buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning); + var result = writer.string(); + releaseStringWriter(writer); + return result; + } + function typeToString(type, enclosingDeclaration, flags) { + var writer = getSingleLineStringWriter(); + getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); + var result = writer.string(); + releaseStringWriter(writer); + var maxLength = compilerOptions.noErrorTruncation || flags & 4 /* NoTruncation */ ? undefined : 100; + if (maxLength && result.length >= maxLength) { + result = result.substr(0, maxLength - "...".length) + "..."; + } + return result; + } + var _displayBuilder; + function getSymbolDisplayBuilder() { + function appendSymbolNameOnly(symbol, writer) { if (symbol.declarations && symbol.declarations.length > 0) { var declaration = symbol.declarations[0]; if (declaration.name) { - return ts.identifierToString(declaration.name); - } - } - return symbol.name; - } - if (enclosingDeclaration && !(symbol.flags & 262144 /* TypeParameter */)) { - var symbolName; - while (symbol) { - var isFirstName = !symbolName; - var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning); - var currentSymbolName; - if (accessibleSymbolChain) { - currentSymbolName = ts.map(accessibleSymbolChain, function (accessibleSymbol) { return getSymbolName(accessibleSymbol); }).join("."); - } - else { - if (!isFirstName && ts.forEach(symbol.declarations, function (declaration) { return hasExternalModuleSymbol(declaration); })) { - break; - } - currentSymbolName = getSymbolName(symbol); - } - symbolName = currentSymbolName + (isFirstName ? "" : ("." + symbolName)); - if (accessibleSymbolChain && !needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) { - break; - } - symbol = getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol); - meaning = getQualifiedLeftMeaning(meaning); - } - return symbolName; - } - return getSymbolName(symbol); - } - function writeSymbolToTextWriter(symbol, enclosingDeclaration, meaning, writer) { - writer.write(symbolToString(symbol, enclosingDeclaration, meaning)); - } - function createSingleLineTextWriter(maxLength) { - var result = ""; - var overflow = false; - function write(s) { - if (!overflow) { - result += s; - if (result.length > maxLength) { - result = result.substr(0, maxLength - 3) + "..."; - overflow = true; - } - } - } - return { - write: write, - writeSymbol: function (symbol, enclosingDeclaration, meaning) { - writeSymbolToTextWriter(symbol, enclosingDeclaration, meaning, this); - }, - writeLine: function () { - write(" "); - }, - increaseIndent: function () { - }, - decreaseIndent: function () { - }, - getText: function () { - return result; - } - }; - } - function typeToString(type, enclosingDeclaration, flags) { - var maxLength = compilerOptions.noErrorTruncation || flags & 4 /* NoTruncation */ ? undefined : 100; - var stringWriter = createSingleLineTextWriter(maxLength); - writeTypeToTextWriter(type, enclosingDeclaration, flags, stringWriter); - return stringWriter.getText(); - } - function writeTypeToTextWriter(type, enclosingDeclaration, flags, writer) { - var typeStack; - return writeType(type, true); - function writeType(type, allowFunctionOrConstructorTypeLiteral) { - if (type.flags & ts.TypeFlags.Intrinsic) { - writer.write(type.intrinsicName); - } - else if (type.flags & 4096 /* Reference */) { - writeTypeReference(type); - } - else if (type.flags & (1024 /* Class */ | 2048 /* Interface */ | 128 /* Enum */ | 512 /* TypeParameter */)) { - writer.writeSymbol(type.symbol, enclosingDeclaration, ts.SymbolFlags.Type); - } - else if (type.flags & 8192 /* Tuple */) { - writeTupleType(type); - } - else if (type.flags & 16384 /* Anonymous */) { - writeAnonymousType(type, allowFunctionOrConstructorTypeLiteral); - } - else if (type.flags & 256 /* StringLiteral */) { - writer.write(type.text); - } - else { - writer.write("{ ... }"); - } - } - function writeTypeList(types) { - for (var i = 0; i < types.length; i++) { - if (i > 0) { - writer.write(", "); - } - writeType(types[i], true); - } - } - function writeTypeReference(type) { - if (type.target === globalArrayType && !(flags & 1 /* WriteArrayAsGenericType */)) { - writeType(type.typeArguments[0], false); - writer.write("[]"); - } - else { - writer.writeSymbol(type.target.symbol, enclosingDeclaration, ts.SymbolFlags.Type); - writer.write("<"); - writeTypeList(type.typeArguments); - writer.write(">"); - } - } - function writeTupleType(type) { - writer.write("["); - writeTypeList(type.elementTypes); - writer.write("]"); - } - function writeAnonymousType(type, allowFunctionOrConstructorTypeLiteral) { - if (type.symbol && type.symbol.flags & (16 /* Class */ | 64 /* Enum */ | 128 /* ValueModule */)) { - writeTypeofSymbol(type); - } - else if (shouldWriteTypeOfFunctionSymbol()) { - writeTypeofSymbol(type); - } - else if (typeStack && ts.contains(typeStack, type)) { - writer.write("any"); - } - else { - if (!typeStack) { - typeStack = []; - } - typeStack.push(type); - writeLiteralType(type, allowFunctionOrConstructorTypeLiteral); - typeStack.pop(); - } - function shouldWriteTypeOfFunctionSymbol() { - if (type.symbol) { - var isStaticMethodSymbol = !!(type.symbol.flags & 2048 /* Method */ && ts.forEach(type.symbol.declarations, function (declaration) { return declaration.flags & 128 /* Static */; })); - var isNonLocalFunctionSymbol = !!(type.symbol.flags & 8 /* Function */) && (type.symbol.parent || ts.forEach(type.symbol.declarations, function (declaration) { return declaration.parent.kind === 182 /* SourceFile */ || declaration.parent.kind === 178 /* ModuleBlock */; })); - if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { - return !!(flags & 2 /* UseTypeOfFunction */) || (typeStack && ts.contains(typeStack, type)); - } - } - } - } - function writeTypeofSymbol(type) { - writer.write("typeof "); - writer.writeSymbol(type.symbol, enclosingDeclaration, ts.SymbolFlags.Value); - } - function writeLiteralType(type, allowFunctionOrConstructorTypeLiteral) { - var resolved = resolveObjectTypeMembers(type); - if (!resolved.properties.length && !resolved.stringIndexType && !resolved.numberIndexType) { - if (!resolved.callSignatures.length && !resolved.constructSignatures.length) { - writer.write("{}"); + writer.writeSymbol(ts.identifierToString(declaration.name), symbol); return; } - if (allowFunctionOrConstructorTypeLiteral) { + } + writer.writeSymbol(symbol.name, symbol); + } + function buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning, flags) { + var parentSymbol; + function appendParentTypeArgumentsAndSymbolName(symbol) { + if (parentSymbol) { + if (flags & 1 /* WriteTypeParametersOrArguments */) { + if (symbol.flags & 8388608 /* Instantiated */) { + buildDisplayForTypeArgumentsAndDelimiters(getTypeParametersOfClassOrInterface(parentSymbol), symbol.mapper, writer, enclosingDeclaration); + } + else { + buildTypeParameterDisplayFromSymbol(parentSymbol, writer, enclosingDeclaration); + } + } + writePunctuation(writer, 15 /* DotToken */); + } + parentSymbol = symbol; + appendSymbolNameOnly(symbol, writer); + } + writer.trackSymbol(symbol, enclosingDeclaration, meaning); + function walkSymbol(symbol, meaning) { + if (symbol) { + var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, !!(flags & 2 /* UseOnlyExternalAliasing */)); + if (!accessibleSymbolChain || needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) { + walkSymbol(getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol), getQualifiedLeftMeaning(meaning)); + } + if (accessibleSymbolChain) { + for (var i = 0, n = accessibleSymbolChain.length; i < n; i++) { + appendParentTypeArgumentsAndSymbolName(accessibleSymbolChain[i]); + } + } + else { + if (!parentSymbol && ts.forEach(symbol.declarations, function (declaration) { return hasExternalModuleSymbol(declaration); })) { + return; + } + if (symbol.flags & 512 /* TypeLiteral */ || symbol.flags & 1024 /* ObjectLiteral */) { + return; + } + appendParentTypeArgumentsAndSymbolName(symbol); + } + } + } + if (enclosingDeclaration && !(symbol.flags & 262144 /* TypeParameter */)) { + walkSymbol(symbol, meaning); + return; + } + return appendParentTypeArgumentsAndSymbolName(symbol); + } + function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, typeStack) { + var globalFlagsToPass = globalFlags & 16 /* WriteOwnNameForAnyLike */; + return writeType(type, globalFlags); + function writeType(type, flags) { + if (type.flags & ts.TypeFlags.Intrinsic) { + writer.writeKeyword(!(globalFlags & 16 /* WriteOwnNameForAnyLike */) && (type.flags & 1 /* Any */) ? "any" : type.intrinsicName); + } + else if (type.flags & 4096 /* Reference */) { + writeTypeReference(type, flags); + } + else if (type.flags & (1024 /* Class */ | 2048 /* Interface */ | 128 /* Enum */ | 512 /* TypeParameter */)) { + buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, ts.SymbolFlags.Type); + } + else if (type.flags & 8192 /* Tuple */) { + writeTupleType(type); + } + else if (type.flags & 16384 /* Union */) { + writeUnionType(type, flags); + } + else if (type.flags & 32768 /* Anonymous */) { + writeAnonymousType(type, flags); + } + else if (type.flags & 256 /* StringLiteral */) { + writer.writeStringLiteral(type.text); + } + else { + writePunctuation(writer, 9 /* OpenBraceToken */); + writeSpace(writer); + writePunctuation(writer, 16 /* DotDotDotToken */); + writeSpace(writer); + writePunctuation(writer, 10 /* CloseBraceToken */); + } + } + function writeTypeList(types, union) { + for (var i = 0; i < types.length; i++) { + if (i > 0) { + if (union) { + writeSpace(writer); + } + writePunctuation(writer, union ? 39 /* BarToken */ : 18 /* CommaToken */); + writeSpace(writer); + } + writeType(types[i], union ? 64 /* InElementType */ : 0 /* None */); + } + } + function writeTypeReference(type, flags) { + if (type.target === globalArrayType && !(flags & 1 /* WriteArrayAsGenericType */)) { + writeType(type.typeArguments[0], 64 /* InElementType */); + writePunctuation(writer, 13 /* OpenBracketToken */); + writePunctuation(writer, 14 /* CloseBracketToken */); + } + else { + buildSymbolDisplay(type.target.symbol, writer, enclosingDeclaration, ts.SymbolFlags.Type); + writePunctuation(writer, 19 /* LessThanToken */); + writeTypeList(type.typeArguments, false); + writePunctuation(writer, 20 /* GreaterThanToken */); + } + } + function writeTupleType(type) { + writePunctuation(writer, 13 /* OpenBracketToken */); + writeTypeList(type.elementTypes, false); + writePunctuation(writer, 14 /* CloseBracketToken */); + } + function writeUnionType(type, flags) { + if (flags & 64 /* InElementType */) { + writePunctuation(writer, 11 /* OpenParenToken */); + } + writeTypeList(type.types, true); + if (flags & 64 /* InElementType */) { + writePunctuation(writer, 12 /* CloseParenToken */); + } + } + function writeAnonymousType(type, flags) { + if (type.symbol && type.symbol.flags & (16 /* Class */ | 64 /* Enum */ | 128 /* ValueModule */)) { + writeTypeofSymbol(type); + } + else if (shouldWriteTypeOfFunctionSymbol()) { + writeTypeofSymbol(type); + } + else if (typeStack && ts.contains(typeStack, type)) { + writeKeyword(writer, 105 /* AnyKeyword */); + } + else { + if (!typeStack) { + typeStack = []; + } + typeStack.push(type); + writeLiteralType(type, flags); + typeStack.pop(); + } + function shouldWriteTypeOfFunctionSymbol() { + if (type.symbol) { + var isStaticMethodSymbol = !!(type.symbol.flags & 2048 /* Method */ && ts.forEach(type.symbol.declarations, function (declaration) { return declaration.flags & 128 /* Static */; })); + var isNonLocalFunctionSymbol = !!(type.symbol.flags & 8 /* Function */) && (type.symbol.parent || ts.forEach(type.symbol.declarations, function (declaration) { return declaration.parent.kind === 184 /* SourceFile */ || declaration.parent.kind === 180 /* ModuleBlock */; })); + if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { + return !!(flags & 2 /* UseTypeOfFunction */) || (typeStack && ts.contains(typeStack, type)); + } + } + } + } + function writeTypeofSymbol(type) { + writeKeyword(writer, 91 /* TypeOfKeyword */); + writeSpace(writer); + buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, ts.SymbolFlags.Value); + } + function writeLiteralType(type, flags) { + var resolved = resolveObjectOrUnionTypeMembers(type); + if (!resolved.properties.length && !resolved.stringIndexType && !resolved.numberIndexType) { + if (!resolved.callSignatures.length && !resolved.constructSignatures.length) { + writePunctuation(writer, 9 /* OpenBraceToken */); + writePunctuation(writer, 10 /* CloseBraceToken */); + return; + } if (resolved.callSignatures.length === 1 && !resolved.constructSignatures.length) { - writeSignature(resolved.callSignatures[0], true); + if (flags & 64 /* InElementType */) { + writePunctuation(writer, 11 /* OpenParenToken */); + } + buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, typeStack); + if (flags & 64 /* InElementType */) { + writePunctuation(writer, 12 /* CloseParenToken */); + } return; } if (resolved.constructSignatures.length === 1 && !resolved.callSignatures.length) { - writer.write("new "); - writeSignature(resolved.constructSignatures[0], true); + if (flags & 64 /* InElementType */) { + writePunctuation(writer, 11 /* OpenParenToken */); + } + writeKeyword(writer, 82 /* NewKeyword */); + writeSpace(writer); + buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, typeStack); + if (flags & 64 /* InElementType */) { + writePunctuation(writer, 12 /* CloseParenToken */); + } return; } } - } - writer.write("{"); - writer.writeLine(); - writer.increaseIndent(); - for (var i = 0; i < resolved.callSignatures.length; i++) { - writeSignature(resolved.callSignatures[i]); - writer.write(";"); + writePunctuation(writer, 9 /* OpenBraceToken */); writer.writeLine(); - } - for (var i = 0; i < resolved.constructSignatures.length; i++) { - writer.write("new "); - writeSignature(resolved.constructSignatures[i]); - writer.write(";"); - writer.writeLine(); - } - if (resolved.stringIndexType) { - writer.write("[x: string]: "); - writeType(resolved.stringIndexType, true); - writer.write(";"); - writer.writeLine(); - } - if (resolved.numberIndexType) { - writer.write("[x: number]: "); - writeType(resolved.numberIndexType, true); - writer.write(";"); - writer.writeLine(); - } - for (var i = 0; i < resolved.properties.length; i++) { - var p = resolved.properties[i]; - var t = getTypeOfSymbol(p); - if (p.flags & (8 /* Function */ | 2048 /* Method */) && !getPropertiesOfType(t).length) { - var signatures = getSignaturesOfType(t, 0 /* Call */); - for (var j = 0; j < signatures.length; j++) { - writer.writeSymbol(p); - if (isOptionalProperty(p)) { - writer.write("?"); + writer.increaseIndent(); + for (var i = 0; i < resolved.callSignatures.length; i++) { + buildSignatureDisplay(resolved.callSignatures[i], writer, enclosingDeclaration, globalFlagsToPass, typeStack); + writePunctuation(writer, 17 /* SemicolonToken */); + writer.writeLine(); + } + for (var i = 0; i < resolved.constructSignatures.length; i++) { + writeKeyword(writer, 82 /* NewKeyword */); + writeSpace(writer); + buildSignatureDisplay(resolved.constructSignatures[i], writer, enclosingDeclaration, globalFlagsToPass, typeStack); + writePunctuation(writer, 17 /* SemicolonToken */); + writer.writeLine(); + } + if (resolved.stringIndexType) { + writePunctuation(writer, 13 /* OpenBracketToken */); + writer.writeParameter("x"); + writePunctuation(writer, 46 /* ColonToken */); + writeSpace(writer); + writeKeyword(writer, 114 /* StringKeyword */); + writePunctuation(writer, 14 /* CloseBracketToken */); + writePunctuation(writer, 46 /* ColonToken */); + writeSpace(writer); + writeType(resolved.stringIndexType, 0 /* None */); + writePunctuation(writer, 17 /* SemicolonToken */); + writer.writeLine(); + } + if (resolved.numberIndexType) { + writePunctuation(writer, 13 /* OpenBracketToken */); + writer.writeParameter("x"); + writePunctuation(writer, 46 /* ColonToken */); + writeSpace(writer); + writeKeyword(writer, 112 /* NumberKeyword */); + writePunctuation(writer, 14 /* CloseBracketToken */); + writePunctuation(writer, 46 /* ColonToken */); + writeSpace(writer); + writeType(resolved.numberIndexType, 0 /* None */); + writePunctuation(writer, 17 /* SemicolonToken */); + writer.writeLine(); + } + for (var i = 0; i < resolved.properties.length; i++) { + var p = resolved.properties[i]; + var t = getTypeOfSymbol(p); + if (p.flags & (8 /* Function */ | 2048 /* Method */) && !getPropertiesOfObjectType(t).length) { + var signatures = getSignaturesOfType(t, 0 /* Call */); + for (var j = 0; j < signatures.length; j++) { + buildSymbolDisplay(p, writer); + if (isOptionalProperty(p)) { + writePunctuation(writer, 45 /* QuestionToken */); + } + buildSignatureDisplay(signatures[j], writer, enclosingDeclaration, globalFlagsToPass, typeStack); + writePunctuation(writer, 17 /* SemicolonToken */); + writer.writeLine(); } - writeSignature(signatures[j]); - writer.write(";"); + } + else { + buildSymbolDisplay(p, writer); + if (isOptionalProperty(p)) { + writePunctuation(writer, 45 /* QuestionToken */); + } + writePunctuation(writer, 46 /* ColonToken */); + writeSpace(writer); + writeType(t, 0 /* None */); + writePunctuation(writer, 17 /* SemicolonToken */); writer.writeLine(); } } - else { - writer.writeSymbol(p); - if (isOptionalProperty(p)) { - writer.write("?"); - } - writer.write(": "); - writeType(t, true); - writer.write(";"); - writer.writeLine(); - } + writer.decreaseIndent(); + writePunctuation(writer, 10 /* CloseBraceToken */); } - writer.decreaseIndent(); - writer.write("}"); } - function writeSignature(signature, arrowStyle) { - if (signature.typeParameters) { - writer.write("<"); - for (var i = 0; i < signature.typeParameters.length; i++) { + function buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaraiton, flags) { + var targetSymbol = getTargetSymbol(symbol); + if (targetSymbol.flags & 16 /* Class */ || targetSymbol.flags & 32 /* Interface */) { + buildDisplayForTypeParametersAndDelimiters(getTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags); + } + } + function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, typeStack) { + appendSymbolNameOnly(tp.symbol, writer); + var constraint = getConstraintOfTypeParameter(tp); + if (constraint) { + writeSpace(writer); + writeKeyword(writer, 73 /* ExtendsKeyword */); + writeSpace(writer); + buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, typeStack); + } + } + function buildParameterDisplay(p, writer, enclosingDeclaration, flags, typeStack) { + if (getDeclarationFlagsFromSymbol(p) & 8 /* Rest */) { + writePunctuation(writer, 16 /* DotDotDotToken */); + } + appendSymbolNameOnly(p, writer); + if (p.valueDeclaration.flags & 4 /* QuestionMark */ || p.valueDeclaration.initializer) { + writePunctuation(writer, 45 /* QuestionToken */); + } + writePunctuation(writer, 46 /* ColonToken */); + writeSpace(writer); + buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, typeStack); + } + function buildDisplayForTypeParametersAndDelimiters(typeParameters, writer, enclosingDeclaration, flags, typeStack) { + if (typeParameters && typeParameters.length) { + writePunctuation(writer, 19 /* LessThanToken */); + for (var i = 0; i < typeParameters.length; i++) { if (i > 0) { - writer.write(", "); - } - var tp = signature.typeParameters[i]; - writer.writeSymbol(tp.symbol); - var constraint = getConstraintOfTypeParameter(tp); - if (constraint) { - writer.write(" extends "); - writeType(constraint, true); + writePunctuation(writer, 18 /* CommaToken */); + writeSpace(writer); } + buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, typeStack); } - writer.write(">"); + writePunctuation(writer, 20 /* GreaterThanToken */); } - writer.write("("); - for (var i = 0; i < signature.parameters.length; i++) { - if (i > 0) { - writer.write(", "); - } - var p = signature.parameters[i]; - if (getDeclarationFlagsFromSymbol(p) & 8 /* Rest */) { - writer.write("..."); - } - writer.writeSymbol(p); - if (p.valueDeclaration.flags & 4 /* QuestionMark */ || p.valueDeclaration.initializer) { - writer.write("?"); - } - writer.write(": "); - writeType(getTypeOfSymbol(p), true); - } - writer.write(arrowStyle ? ") => " : "): "); - writeType(getReturnTypeOfSignature(signature), true); } + function buildDisplayForTypeArgumentsAndDelimiters(typeParameters, mapper, writer, enclosingDeclaration, flags, typeStack) { + if (typeParameters && typeParameters.length) { + writePunctuation(writer, 19 /* LessThanToken */); + for (var i = 0; i < typeParameters.length; i++) { + if (i > 0) { + writePunctuation(writer, 18 /* CommaToken */); + writeSpace(writer); + } + buildTypeDisplay(mapper(typeParameters[i]), writer, enclosingDeclaration, 0 /* None */); + } + writePunctuation(writer, 20 /* GreaterThanToken */); + } + } + function buildDisplayForParametersAndDelimiters(parameters, writer, enclosingDeclaration, flags, typeStack) { + writePunctuation(writer, 11 /* OpenParenToken */); + for (var i = 0; i < parameters.length; i++) { + if (i > 0) { + writePunctuation(writer, 18 /* CommaToken */); + writeSpace(writer); + } + buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, typeStack); + } + writePunctuation(writer, 12 /* CloseParenToken */); + } + function buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack) { + if (flags & 8 /* WriteArrowStyleSignature */) { + writeSpace(writer); + writePunctuation(writer, 27 /* EqualsGreaterThanToken */); + } + else { + writePunctuation(writer, 46 /* ColonToken */); + } + writeSpace(writer); + buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, typeStack); + } + function buildSignatureDisplay(signature, writer, enclosingDeclaration, flags, typeStack) { + if (signature.target && (flags & 32 /* WriteTypeArgumentsOfSignature */)) { + buildDisplayForTypeArgumentsAndDelimiters(signature.target.typeParameters, signature.mapper, writer, enclosingDeclaration); + } + else { + buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, typeStack); + } + buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, typeStack); + buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack); + } + return _displayBuilder || (_displayBuilder = { + symbolToString: symbolToString, + typeToString: typeToString, + buildSymbolDisplay: buildSymbolDisplay, + buildTypeDisplay: buildTypeDisplay, + buildTypeParameterDisplay: buildTypeParameterDisplay, + buildParameterDisplay: buildParameterDisplay, + buildDisplayForParametersAndDelimiters: buildDisplayForParametersAndDelimiters, + buildDisplayForTypeParametersAndDelimiters: buildDisplayForTypeParametersAndDelimiters, + buildDisplayForTypeArgumentsAndDelimiters: buildDisplayForTypeArgumentsAndDelimiters, + buildTypeParameterDisplayFromSymbol: buildTypeParameterDisplayFromSymbol, + buildSignatureDisplay: buildSignatureDisplay, + buildReturnTypeDisplay: buildReturnTypeDisplay + }); } function isDeclarationVisible(node) { function getContainingExternalModule(node) { for (; node; node = node.parent) { - if (node.kind === 177 /* ModuleDeclaration */) { + if (node.kind === 179 /* ModuleDeclaration */) { if (node.name.kind === 7 /* StringLiteral */) { return node; } } - else if (node.kind === 182 /* SourceFile */) { + else if (node.kind === 184 /* SourceFile */) { return ts.isExternalModule(node) ? node : undefined; } } @@ -9851,15 +10170,15 @@ var ts; } function determineIfDeclarationIsVisible() { switch (node.kind) { - case 171 /* VariableDeclaration */: - case 177 /* ModuleDeclaration */: - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 172 /* FunctionDeclaration */: - case 176 /* EnumDeclaration */: - case 179 /* ImportDeclaration */: - var parent = node.kind === 171 /* VariableDeclaration */ ? node.parent.parent : node.parent; - if (!(node.flags & 1 /* Export */) && !(node.kind !== 179 /* ImportDeclaration */ && parent.kind !== 182 /* SourceFile */ && ts.isInAmbientContext(parent))) { + case 173 /* VariableDeclaration */: + case 179 /* ModuleDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 174 /* FunctionDeclaration */: + case 178 /* EnumDeclaration */: + case 181 /* ImportDeclaration */: + var parent = node.kind === 173 /* VariableDeclaration */ ? node.parent.parent : node.parent; + if (!(node.flags & 1 /* Export */) && !(node.kind !== 181 /* ImportDeclaration */ && parent.kind !== 184 /* SourceFile */ && ts.isInAmbientContext(parent))) { return isGlobalSourceFile(parent) || isUsedInExportAssignment(node); } return isDeclarationVisible(parent); @@ -9873,9 +10192,9 @@ var ts; case 124 /* CallSignature */: case 126 /* IndexSignature */: case 118 /* Parameter */: - case 178 /* ModuleBlock */: + case 180 /* ModuleBlock */: return isDeclarationVisible(node.parent); - case 182 /* SourceFile */: + case 184 /* SourceFile */: return true; default: ts.Debug.fail("isDeclarationVisible unknown: SyntaxKind: " + ts.SyntaxKind[node.kind]); @@ -9889,31 +10208,12 @@ var ts; return links.isVisible; } } - function getApparentType(type) { - if (type.flags & 512 /* TypeParameter */) { - do { - type = getConstraintOfTypeParameter(type); - } while (type && type.flags & 512 /* TypeParameter */); - if (!type) - type = emptyObjectType; - } - if (type.flags & ts.TypeFlags.StringLike) { - type = globalStringType; - } - else if (type.flags & ts.TypeFlags.NumberLike) { - type = globalNumberType; - } - else if (type.flags & 8 /* Boolean */) { - type = globalBooleanType; - } - return type; - } function getTypeOfPrototypeProperty(prototype) { var classType = getDeclaredTypeOfSymbol(prototype.parent); return classType.typeParameters ? createTypeReference(classType, ts.map(classType.typeParameters, function (_) { return anyType; })) : classType; } function getTypeOfVariableDeclaration(declaration) { - if (declaration.parent.kind === 156 /* ForInStatement */) { + if (declaration.parent.kind === 158 /* ForInStatement */) { return anyType; } if (declaration.type) { @@ -9934,7 +10234,7 @@ var ts; } if (declaration.initializer) { var type = checkAndMarkExpression(declaration.initializer); - if (declaration.kind !== 134 /* PropertyAssignment */) { + if (declaration.kind !== 136 /* PropertyAssignment */) { var unwidenedType = type; type = getWidenedType(type); if (type !== unwidenedType) { @@ -9976,7 +10276,7 @@ var ts; return links.type = getTypeOfPrototypeProperty(symbol); } var declaration = symbol.valueDeclaration; - if (declaration.kind === 168 /* CatchBlock */) { + if (declaration.kind === 170 /* CatchBlock */) { return links.type = anyType; } links.type = resolvingType; @@ -10057,7 +10357,7 @@ var ts; function getTypeOfFuncClassEnumModule(symbol) { var links = getSymbolLinks(symbol); if (!links.type) { - links.type = createObjectType(16384 /* Anonymous */, symbol); + links.type = createObjectType(32768 /* Anonymous */, symbol); } return links.type; } @@ -10083,6 +10383,9 @@ var ts; return links.type; } function getTypeOfSymbol(symbol) { + if (symbol.flags & 8388608 /* Instantiated */) { + return getTypeOfInstantiatedSymbol(symbol); + } if (symbol.flags & (1 /* Variable */ | 2 /* Property */)) { return getTypeOfVariableOrParameterOrProperty(symbol); } @@ -10098,9 +10401,6 @@ var ts; if (symbol.flags & 4194304 /* Import */) { return getTypeOfImport(symbol); } - if (symbol.flags & 8388608 /* Instantiated */) { - return getTypeOfInstantiatedSymbol(symbol); - } return unknownType; } function getTargetType(type) { @@ -10116,7 +10416,7 @@ var ts; function getTypeParametersOfClassOrInterface(symbol) { var result; ts.forEach(symbol.declarations, function (node) { - if (node.kind === 175 /* InterfaceDeclaration */ || node.kind === 174 /* ClassDeclaration */) { + if (node.kind === 177 /* InterfaceDeclaration */ || node.kind === 176 /* ClassDeclaration */) { var declaration = node; if (declaration.typeParameters && declaration.typeParameters.length) { ts.forEach(declaration.typeParameters, function (node) { @@ -10147,7 +10447,7 @@ var ts; type.typeArguments = type.typeParameters; } type.baseTypes = []; - var declaration = getDeclarationOfKind(symbol, 174 /* ClassDeclaration */); + var declaration = getDeclarationOfKind(symbol, 176 /* ClassDeclaration */); if (declaration.baseType) { var baseType = getTypeFromTypeReferenceNode(declaration.baseType); if (baseType !== unknownType) { @@ -10187,7 +10487,7 @@ var ts; } type.baseTypes = []; ts.forEach(symbol.declarations, function (declaration) { - if (declaration.kind === 175 /* InterfaceDeclaration */ && declaration.baseTypes) { + if (declaration.kind === 177 /* InterfaceDeclaration */ && declaration.baseTypes) { ts.forEach(declaration.baseTypes, function (node) { var baseType = getTypeFromTypeReferenceNode(node); if (baseType !== unknownType) { @@ -10243,6 +10543,7 @@ var ts; return links.declaredType; } function getDeclaredTypeOfSymbol(symbol) { + ts.Debug.assert((symbol.flags & 8388608 /* Instantiated */) === 0); if (symbol.flags & 16 /* Class */) { return getDeclaredTypeOfClass(symbol); } @@ -10258,7 +10559,6 @@ var ts; if (symbol.flags & 4194304 /* Import */) { return getDeclaredTypeOfImport(symbol); } - ts.Debug.assert((symbol.flags & 8388608 /* Instantiated */) === 0); return unknownType; } function createSymbolTable(symbols) { @@ -10301,7 +10601,7 @@ var ts; if (type.baseTypes.length) { members = createSymbolTable(type.declaredProperties); ts.forEach(type.baseTypes, function (baseType) { - addInheritedMembers(members, getPropertiesOfType(baseType)); + addInheritedMembers(members, getPropertiesOfObjectType(baseType)); callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(baseType, 0 /* Call */)); constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(baseType, 1 /* Construct */)); stringIndexType = stringIndexType || getIndexTypeOfType(baseType, 0 /* String */); @@ -10320,7 +10620,7 @@ var ts; var numberIndexType = target.declaredNumberIndexType ? instantiateType(target.declaredNumberIndexType, mapper) : undefined; ts.forEach(target.baseTypes, function (baseType) { var instantiatedBaseType = instantiateType(baseType, mapper); - addInheritedMembers(members, getPropertiesOfType(instantiatedBaseType)); + addInheritedMembers(members, getPropertiesOfObjectType(instantiatedBaseType)); callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, 0 /* Call */)); constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(instantiatedBaseType, 1 /* Construct */)); stringIndexType = stringIndexType || getIndexTypeOfType(instantiatedBaseType, 0 /* String */); @@ -10365,11 +10665,61 @@ var ts; return members; } function resolveTupleTypeMembers(type) { - var arrayType = resolveObjectTypeMembers(createArrayType(getBestCommonType(type.elementTypes))); + var arrayType = resolveObjectOrUnionTypeMembers(createArrayType(getUnionType(type.elementTypes))); var members = createTupleTypeMemberSymbols(type.elementTypes); addInheritedMembers(members, arrayType.properties); setObjectTypeMembers(type, members, arrayType.callSignatures, arrayType.constructSignatures, arrayType.stringIndexType, arrayType.numberIndexType); } + function signatureListsIdentical(s, t) { + if (s.length !== t.length) { + return false; + } + for (var i = 0; i < s.length; i++) { + if (!compareSignatures(s[i], t[i], false, isTypeIdenticalTo)) { + return false; + } + } + return true; + } + function getUnionSignatures(types, kind) { + var signatureLists = ts.map(types, function (t) { return getSignaturesOfType(t, kind); }); + var signatures = signatureLists[0]; + for (var i = 0; i < signatures.length; i++) { + if (signatures[i].typeParameters) { + return emptyArray; + } + } + for (var i = 1; i < signatureLists.length; i++) { + if (!signatureListsIdentical(signatures, signatureLists[i])) { + return emptyArray; + } + } + var result = ts.map(signatures, cloneSignature); + for (var i = 0; i < result.length; i++) { + var s = result[i]; + s.resolvedReturnType = undefined; + s.unionSignatures = ts.map(signatureLists, function (signatures) { return signatures[i]; }); + } + return result; + } + function getUnionIndexType(types, kind) { + var indexTypes = []; + for (var i = 0; i < types.length; i++) { + var indexType = getIndexTypeOfType(types[i], kind); + if (!indexType) { + return undefined; + } + indexTypes.push(indexType); + } + return getUnionType(indexTypes); + } + function resolveUnionTypeMembers(type) { + var callSignatures = getUnionSignatures(type.types, 0 /* Call */); + var constructSignatures = getUnionSignatures(type.types, 1 /* Construct */); + var stringIndexType = getUnionIndexType(type.types, 0 /* String */); + var numberIndexType = getUnionIndexType(type.types, 1 /* Number */); + setObjectTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexType, numberIndexType); + } function resolveAnonymousTypeMembers(type) { var symbol = type.symbol; if (symbol.flags & 512 /* TypeLiteral */) { @@ -10397,7 +10747,7 @@ var ts; } if (classType.baseTypes.length) { members = createSymbolTable(getNamedMembers(members)); - addInheritedMembers(members, getPropertiesOfType(getTypeOfSymbol(classType.baseTypes[0].symbol))); + addInheritedMembers(members, getPropertiesOfObjectType(getTypeOfSymbol(classType.baseTypes[0].symbol))); } } var stringIndexType = undefined; @@ -10405,70 +10755,166 @@ var ts; } setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); } - function resolveObjectTypeMembers(type) { + function resolveObjectOrUnionTypeMembers(type) { if (!type.members) { if (type.flags & (1024 /* Class */ | 2048 /* Interface */)) { resolveClassOrInterfaceMembers(type); } - else if (type.flags & 16384 /* Anonymous */) { + else if (type.flags & 32768 /* Anonymous */) { resolveAnonymousTypeMembers(type); } else if (type.flags & 8192 /* Tuple */) { resolveTupleTypeMembers(type); } + else if (type.flags & 16384 /* Union */) { + resolveUnionTypeMembers(type); + } else { resolveTypeReferenceMembers(type); } } return type; } - function getPropertiesOfType(type) { + function getPropertiesOfObjectType(type) { if (type.flags & ts.TypeFlags.ObjectType) { - return resolveObjectTypeMembers(type).properties; + return resolveObjectOrUnionTypeMembers(type).properties; } return emptyArray; } + function getPropertyOfObjectType(type, name) { + if (type.flags & ts.TypeFlags.ObjectType) { + var resolved = resolveObjectOrUnionTypeMembers(type); + if (ts.hasProperty(resolved.members, name)) { + var symbol = resolved.members[name]; + if (symbolIsValue(symbol)) { + return symbol; + } + } + } + } + function getPropertiesOfUnionType(type) { + var result = []; + ts.forEach(getPropertiesOfType(type.types[0]), function (prop) { + var unionProp = getPropertyOfUnionType(type, prop.name); + if (unionProp) { + result.push(unionProp); + } + }); + return result; + } + function getPropertiesOfType(type) { + if (type.flags & 16384 /* Union */) { + return getPropertiesOfUnionType(type); + } + return getPropertiesOfObjectType(getApparentType(type)); + } + function getApparentType(type) { + if (type.flags & 512 /* TypeParameter */) { + do { + type = getConstraintOfTypeParameter(type); + } while (type && type.flags & 512 /* TypeParameter */); + if (!type) { + type = emptyObjectType; + } + } + if (type.flags & ts.TypeFlags.StringLike) { + type = globalStringType; + } + else if (type.flags & ts.TypeFlags.NumberLike) { + type = globalNumberType; + } + else if (type.flags & 8 /* Boolean */) { + type = globalBooleanType; + } + return type; + } + function createUnionProperty(unionType, name) { + var types = unionType.types; + var props; + for (var i = 0; i < types.length; i++) { + var type = getApparentType(types[i]); + if (type !== unknownType) { + var prop = getPropertyOfType(type, name); + if (!prop) { + return undefined; + } + if (!props) { + props = [prop]; + } + else { + props.push(prop); + } + } + } + var propTypes = []; + var declarations = []; + for (var i = 0; i < props.length; i++) { + var prop = props[i]; + if (prop.declarations) { + declarations.push.apply(declarations, prop.declarations); + } + propTypes.push(getTypeOfSymbol(prop)); + } + var result = createSymbol(2 /* Property */ | 33554432 /* Transient */ | 134217728 /* UnionProperty */, name); + result.unionType = unionType; + result.declarations = declarations; + result.type = getUnionType(propTypes); + return result; + } + function getPropertyOfUnionType(type, name) { + var properties = type.resolvedProperties || (type.resolvedProperties = {}); + if (ts.hasProperty(properties, name)) { + return properties[name]; + } + var property = createUnionProperty(type, name); + if (property) { + properties[name] = property; + } + return property; + } function getPropertyOfType(type, name) { - if (type.flags & ts.TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); - if (ts.hasProperty(resolved.members, name)) { - var symbol = resolved.members[name]; - if (symbolIsValue(symbol)) { - return symbol; - } + if (type.flags & 16384 /* Union */) { + return getPropertyOfUnionType(type, name); + } + if (!(type.flags & ts.TypeFlags.ObjectType)) { + type = getApparentType(type); + if (!(type.flags & ts.TypeFlags.ObjectType)) { + return undefined; } } - } - function getPropertyOfApparentType(type, name) { - if (type.flags & ts.TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); - if (ts.hasProperty(resolved.members, name)) { - var symbol = resolved.members[name]; - if (symbolIsValue(symbol)) { - return symbol; - } + var resolved = resolveObjectOrUnionTypeMembers(type); + if (ts.hasProperty(resolved.members, name)) { + var symbol = resolved.members[name]; + if (symbolIsValue(symbol)) { + return symbol; } - if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { - var symbol = getPropertyOfType(globalFunctionType, name); - if (symbol) - return symbol; - } - return getPropertyOfType(globalObjectType, name); } + if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { + var symbol = getPropertyOfObjectType(globalFunctionType, name); + if (symbol) + return symbol; + } + return getPropertyOfObjectType(globalObjectType, name); } - function getSignaturesOfType(type, kind) { - if (type.flags & ts.TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); + function getSignaturesOfObjectOrUnionType(type, kind) { + if (type.flags & (ts.TypeFlags.ObjectType | 16384 /* Union */)) { + var resolved = resolveObjectOrUnionTypeMembers(type); return kind === 0 /* Call */ ? resolved.callSignatures : resolved.constructSignatures; } return emptyArray; } - function getIndexTypeOfType(type, kind) { - if (type.flags & ts.TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); + function getSignaturesOfType(type, kind) { + return getSignaturesOfObjectOrUnionType(getApparentType(type), kind); + } + function getIndexTypeOfObjectOrUnionType(type, kind) { + if (type.flags & (ts.TypeFlags.ObjectType | 16384 /* Union */)) { + var resolved = resolveObjectOrUnionTypeMembers(type); return kind === 0 /* String */ ? resolved.stringIndexType : resolved.numberIndexType; } } + function getIndexTypeOfType(type, kind) { + return getIndexTypeOfObjectOrUnionType(getApparentType(type), kind); + } function getTypeParametersFromDeclaration(typeParameterDeclarations) { var result = []; ts.forEach(typeParameterDeclarations, function (node) { @@ -10529,7 +10975,7 @@ var ts; for (var i = 0, len = symbol.declarations.length; i < len; i++) { var node = symbol.declarations[i]; switch (node.kind) { - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: case 120 /* Method */: case 121 /* Constructor */: case 124 /* CallSignature */: @@ -10537,8 +10983,8 @@ var ts; case 126 /* IndexSignature */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: if (i > 0 && node.body) { var previous = symbol.declarations[i - 1]; if (node.parent === previous.parent && node.kind === previous.kind && node.pos === previous.end) { @@ -10556,6 +11002,9 @@ var ts; if (signature.target) { var type = instantiateType(getReturnTypeOfSignature(signature.target), signature.mapper); } + else if (signature.unionSignatures) { + var type = getUnionType(ts.map(signature.unionSignatures, getReturnTypeOfSignature)); + } else { var type = getReturnTypeFromBody(signature.declaration); } @@ -10605,7 +11054,7 @@ var ts; function getOrCreateTypeFromSignature(signature) { if (!signature.isolatedSignatureType) { var isConstructor = signature.declaration.kind === 121 /* Constructor */ || signature.declaration.kind === 125 /* ConstructSignature */; - var type = createObjectType(16384 /* Anonymous */ | 32768 /* FromSignature */); + var type = createObjectType(32768 /* Anonymous */ | 65536 /* FromSignature */); type.members = emptySymbols; type.properties = emptyArray; type.callSignatures = !isConstructor ? [signature] : emptyArray; @@ -10756,9 +11205,9 @@ var ts; for (var i = 0; i < declarations.length; i++) { var declaration = declarations[i]; switch (declaration.kind) { - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 176 /* EnumDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: return declaration; } } @@ -10810,10 +11259,98 @@ var ts; } return links.resolvedType; } + function addTypeToSortedSet(sortedSet, type) { + if (type.flags & 16384 /* Union */) { + addTypesToSortedSet(sortedSet, type.types); + } + else { + var i = 0; + var id = type.id; + while (i < sortedSet.length && sortedSet[i].id < id) { + i++; + } + if (i === sortedSet.length || sortedSet[i].id !== id) { + sortedSet.splice(i, 0, type); + } + } + } + function addTypesToSortedSet(sortedTypes, types) { + for (var i = 0, len = types.length; i < len; i++) { + addTypeToSortedSet(sortedTypes, types[i]); + } + } + function isSubtypeOfAny(candidate, types) { + for (var i = 0, len = types.length; i < len; i++) { + if (candidate !== types[i] && isTypeSubtypeOf(candidate, types[i])) { + return true; + } + } + return false; + } + function removeSubtypes(types) { + var i = types.length; + while (i > 0) { + i--; + if (isSubtypeOfAny(types[i], types)) { + types.splice(i, 1); + } + } + } + function containsAnyType(types) { + for (var i = 0; i < types.length; i++) { + if (types[i].flags & 1 /* Any */) { + return true; + } + } + return false; + } + function removeAllButLast(types, typeToRemove) { + var i = types.length; + while (i > 0 && types.length > 1) { + i--; + if (types[i] === typeToRemove) { + types.splice(i, 1); + } + } + } + function getUnionType(types, noSubtypeReduction) { + if (types.length === 0) { + return emptyObjectType; + } + var sortedTypes = []; + addTypesToSortedSet(sortedTypes, types); + if (noSubtypeReduction) { + if (containsAnyType(sortedTypes)) { + return anyType; + } + removeAllButLast(sortedTypes, undefinedType); + removeAllButLast(sortedTypes, nullType); + } + else { + removeSubtypes(sortedTypes); + } + if (sortedTypes.length === 1) { + return sortedTypes[0]; + } + var id = getTypeListId(sortedTypes); + var type = unionTypes[id]; + if (!type) { + type = unionTypes[id] = createObjectType(16384 /* Union */); + type.types = sortedTypes; + } + return type; + } + function getTypeFromUnionTypeNode(node) { + var links = getNodeLinks(node); + if (!links.resolvedType) { + links.resolvedType = getUnionType(ts.map(node.types, getTypeFromTypeNode), true); + } + return links.resolvedType; + } function getTypeFromTypeLiteralNode(node) { var links = getNodeLinks(node); if (!links.resolvedType) { - links.resolvedType = createObjectType(16384 /* Anonymous */, node.symbol); + links.resolvedType = createObjectType(32768 /* Anonymous */, node.symbol); } return links.resolvedType; } @@ -10821,7 +11358,7 @@ var ts; if (ts.hasProperty(stringLiteralTypes, node.text)) return stringLiteralTypes[node.text]; var type = stringLiteralTypes[node.text] = createType(256 /* StringLiteral */); - type.text = ts.getSourceTextOfNode(node); + type.text = ts.getTextOfNode(node); return type; } function getTypeFromStringLiteral(node) { @@ -10853,6 +11390,10 @@ var ts; return getTypeFromArrayTypeNode(node); case 131 /* TupleType */: return getTypeFromTupleTypeNode(node); + case 132 /* UnionType */: + return getTypeFromUnionTypeNode(node); + case 133 /* ParenType */: + return getTypeFromTypeNode(node.type); case 129 /* TypeLiteral */: return getTypeFromTypeLiteralNode(node); case 59 /* Identifier */: @@ -10959,7 +11500,7 @@ var ts; symbol = links.target; mapper = combineTypeMappers(links.mapper, mapper); } - var result = createSymbol(8388608 /* Instantiated */ | 33554432 /* Transient */, symbol.name); + var result = createSymbol(8388608 /* Instantiated */ | 33554432 /* Transient */ | symbol.flags, symbol.name); result.declarations = symbol.declarations; result.parent = symbol.parent; result.target = symbol; @@ -10970,8 +11511,8 @@ var ts; return result; } function instantiateAnonymousType(type, mapper) { - var result = createObjectType(16384 /* Anonymous */, type.symbol); - result.properties = instantiateList(getPropertiesOfType(type), mapper, instantiateSymbol); + var result = createObjectType(32768 /* Anonymous */, type.symbol); + result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol); result.members = createSymbolTable(result.properties); result.callSignatures = instantiateList(getSignaturesOfType(type, 0 /* Call */), mapper, instantiateSignature); result.constructSignatures = instantiateList(getSignaturesOfType(type, 1 /* Construct */), mapper, instantiateSignature); @@ -10988,7 +11529,7 @@ var ts; if (type.flags & 512 /* TypeParameter */) { return mapper(type); } - if (type.flags & 16384 /* Anonymous */) { + if (type.flags & 32768 /* Anonymous */) { return type.symbol && type.symbol.flags & (8 /* Function */ | 2048 /* Method */ | 512 /* TypeLiteral */ | 1024 /* ObjectLiteral */) ? instantiateAnonymousType(type, mapper) : type; } if (type.flags & 4096 /* Reference */) { @@ -10997,30 +11538,33 @@ var ts; if (type.flags & 8192 /* Tuple */) { return createTupleType(instantiateList(type.elementTypes, mapper, instantiateType)); } + if (type.flags & 16384 /* Union */) { + return getUnionType(instantiateList(type.types, mapper, instantiateType), true); + } } return type; } function isContextSensitiveExpression(node) { switch (node.kind) { - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: return !node.typeParameters && !ts.forEach(node.parameters, function (p) { return p.type; }); - case 133 /* ObjectLiteral */: - return ts.forEach(node.properties, function (p) { return p.kind === 134 /* PropertyAssignment */ && isContextSensitiveExpression(p.initializer); }); - case 132 /* ArrayLiteral */: + case 135 /* ObjectLiteral */: + return ts.forEach(node.properties, function (p) { return p.kind === 136 /* PropertyAssignment */ && isContextSensitiveExpression(p.initializer); }); + case 134 /* ArrayLiteral */: return ts.forEach(node.elements, function (e) { return isContextSensitiveExpression(e); }); - case 146 /* ConditionalExpression */: + case 148 /* ConditionalExpression */: return isContextSensitiveExpression(node.whenTrue) || isContextSensitiveExpression(node.whenFalse); - case 145 /* BinaryExpression */: + case 147 /* BinaryExpression */: return node.operator === 44 /* BarBarToken */ && (isContextSensitiveExpression(node.left) || isContextSensitiveExpression(node.right)); } return false; } function getTypeWithoutConstructors(type) { if (type.flags & ts.TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); + var resolved = resolveObjectOrUnionTypeMembers(type); if (resolved.constructSignatures.length) { - var result = createObjectType(16384 /* Anonymous */, type.symbol); + var result = createObjectType(32768 /* Anonymous */, type.symbol); result.members = resolved.members; result.properties = resolved.properties; result.callSignatures = resolved.callSignatures; @@ -11070,7 +11614,7 @@ var ts; var ok = true; for (var i = 0, len = type.baseTypes.length; i < len; ++i) { var base = type.baseTypes[i]; - var properties = getPropertiesOfType(base); + var properties = getPropertiesOfObjectType(base); for (var j = 0, proplen = properties.length; j < proplen; ++j) { var prop = properties[j]; if (!ts.hasProperty(seen, prop.name)) { @@ -11155,7 +11699,17 @@ var ts; return true; } } - if (source.flags & 512 /* TypeParameter */ && target.flags & 512 /* TypeParameter */) { + if (source.flags & 16384 /* Union */) { + if (unionTypeRelatedToType(source, target, reportErrors)) { + return true; + } + } + else if (target.flags & 16384 /* Union */) { + if (typeRelatedToUnionType(source, target, reportErrors)) { + return true; + } + } + else if (source.flags & 512 /* TypeParameter */ && target.flags & 512 /* TypeParameter */) { if (typeParameterRelatedTo(source, target, reportErrors)) { return true; } @@ -11183,6 +11737,24 @@ var ts; } return false; } + function typeRelatedToUnionType(source, target, reportErrors) { + var targetTypes = target.types; + for (var i = 0, len = targetTypes.length; i < len; i++) { + if (isRelatedTo(source, targetTypes[i], reportErrors && i === len - 1)) { + return true; + } + } + return false; + } + function unionTypeRelatedToType(source, target, reportErrors) { + var sourceTypes = source.types; + for (var i = 0, len = sourceTypes.length; i < len; i++) { + if (!isRelatedTo(sourceTypes[i], target, reportErrors)) { + return false; + } + } + return true; + } function typesRelatedTo(sources, targets, reportErrors) { for (var i = 0, len = sources.length; i < len; i++) { if (!isRelatedTo(sources[i], targets[i], reportErrors)) @@ -11270,35 +11842,15 @@ var ts; } function propertiesRelatedTo(source, target, reportErrors) { if (relation === identityRelation) { - return propertiesAreIdenticalTo(source, target, reportErrors); + return propertiesIdenticalTo(source, target, reportErrors); } - else { - return propertiesAreSubtypeOrAssignableTo(source, target, reportErrors); - } - } - function propertiesAreIdenticalTo(source, target, reportErrors) { - var sourceProperties = getPropertiesOfType(source); - var targetProperties = getPropertiesOfType(target); - if (sourceProperties.length !== targetProperties.length) { - return false; - } - for (var i = 0, len = sourceProperties.length; i < len; ++i) { - var sourceProp = sourceProperties[i]; - var targetProp = getPropertyOfType(target, sourceProp.name); - if (!targetProp || !isPropertyIdenticalToRecursive(sourceProp, targetProp, reportErrors, isRelatedTo)) { - return false; - } - } - return true; - } - function propertiesAreSubtypeOrAssignableTo(source, target, reportErrors) { - var properties = getPropertiesOfType(target); + var properties = getPropertiesOfObjectType(target); for (var i = 0; i < properties.length; i++) { var targetProp = properties[i]; - var sourceProp = getPropertyOfApparentType(source, targetProp.name); + var sourceProp = getPropertyOfType(source, targetProp.name); if (sourceProp !== targetProp) { if (!sourceProp) { - if (!isOptionalProperty(targetProp)) { + if (relation === subtypeRelation || !isOptionalProperty(targetProp)) { if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_missing_in_type_1, symbolToString(targetProp), typeToString(source)); } @@ -11355,67 +11907,25 @@ var ts; } return true; } - function signaturesRelatedTo(source, target, kind, reportErrors) { - if (relation === identityRelation) { - return areSignaturesIdenticalTo(source, target, kind, reportErrors); - } - else { - return areSignaturesSubtypeOrAssignableTo(source, target, kind, reportErrors); - } - } - function areSignaturesIdenticalTo(source, target, kind, reportErrors) { - var sourceSignatures = getSignaturesOfType(source, kind); - var targetSignatures = getSignaturesOfType(target, kind); - if (sourceSignatures.length !== targetSignatures.length) { + function propertiesIdenticalTo(source, target, reportErrors) { + var sourceProperties = getPropertiesOfObjectType(source); + var targetProperties = getPropertiesOfObjectType(target); + if (sourceProperties.length !== targetProperties.length) { return false; } - for (var i = 0, len = sourceSignatures.length; i < len; ++i) { - if (!isSignatureIdenticalTo(sourceSignatures[i], targetSignatures[i], reportErrors)) { + for (var i = 0, len = sourceProperties.length; i < len; ++i) { + var sourceProp = sourceProperties[i]; + var targetProp = getPropertyOfObjectType(target, sourceProp.name); + if (!targetProp || !isPropertyIdenticalToRecursive(sourceProp, targetProp, reportErrors, isRelatedTo)) { return false; } } return true; } - function isSignatureIdenticalTo(source, target, reportErrors) { - if (source === target) { - return true; + function signaturesRelatedTo(source, target, kind, reportErrors) { + if (relation === identityRelation) { + return signaturesIdenticalTo(source, target, kind, reportErrors); } - if (source.hasRestParameter !== target.hasRestParameter) { - return false; - } - if (source.parameters.length !== target.parameters.length) { - return false; - } - if (source.minArgumentCount !== target.minArgumentCount) { - return false; - } - if (source.typeParameters && target.typeParameters) { - if (source.typeParameters.length !== target.typeParameters.length) { - return false; - } - for (var i = 0, len = source.typeParameters.length; i < len; ++i) { - if (!isRelatedTo(source.typeParameters[i], target.typeParameters[i], reportErrors)) { - return false; - } - } - } - else if (source.typeParameters || source.typeParameters) { - return false; - } - source = getErasedSignature(source); - target = getErasedSignature(target); - for (var i = 0, len = source.parameters.length; i < len; i++) { - var s = source.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(source) : getTypeOfSymbol(source.parameters[i]); - var t = target.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(target) : getTypeOfSymbol(target.parameters[i]); - if (!isRelatedTo(s, t, reportErrors)) { - return false; - } - } - var t = getReturnTypeOfSignature(target); - var s = getReturnTypeOfSignature(source); - return isRelatedTo(s, t, reportErrors); - } - function areSignaturesSubtypeOrAssignableTo(source, target, kind, reportErrors) { if (target === anyFunctionType || source === anyFunctionType) return true; var sourceSignatures = getSignaturesOfType(source, kind); @@ -11423,12 +11933,12 @@ var ts; var saveErrorInfo = errorInfo; outer: for (var i = 0; i < targetSignatures.length; i++) { var t = targetSignatures[i]; - if (!t.hasStringLiterals || target.flags & 32768 /* FromSignature */) { + if (!t.hasStringLiterals || target.flags & 65536 /* FromSignature */) { var localErrors = reportErrors; for (var j = 0; j < sourceSignatures.length; j++) { var s = sourceSignatures[j]; - if (!s.hasStringLiterals || source.flags & 32768 /* FromSignature */) { - if (isSignatureSubtypeOrAssignableTo(s, t, localErrors)) { + if (!s.hasStringLiterals || source.flags & 65536 /* FromSignature */) { + if (signatureRelatedTo(s, t, localErrors)) { errorInfo = saveErrorInfo; continue outer; } @@ -11440,7 +11950,7 @@ var ts; } return true; } - function isSignatureSubtypeOrAssignableTo(source, target, reportErrors) { + function signatureRelatedTo(source, target, reportErrors) { if (source === target) { return true; } @@ -11488,67 +11998,107 @@ var ts; var s = getReturnTypeOfSignature(source); return isRelatedTo(s, t, reportErrors); } + function signaturesIdenticalTo(source, target, kind, reportErrors) { + var sourceSignatures = getSignaturesOfType(source, kind); + var targetSignatures = getSignaturesOfType(target, kind); + if (sourceSignatures.length !== targetSignatures.length) { + return false; + } + for (var i = 0, len = sourceSignatures.length; i < len; ++i) { + if (!compareSignatures(sourceSignatures[i], targetSignatures[i], true, isRelatedTo)) { + return false; + } + } + return true; + } function stringIndexTypesRelatedTo(source, target, reportErrors) { if (relation === identityRelation) { - return areIndexTypesIdenticalTo(0 /* String */, source, target, reportErrors); + return indexTypesIdenticalTo(0 /* String */, source, target, reportErrors); } - else { - var targetType = getIndexTypeOfType(target, 0 /* String */); - if (targetType) { - var sourceType = getIndexTypeOfType(source, 0 /* String */); - if (!sourceType) { - if (reportErrors) { - reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); - } - return false; - } - if (!isRelatedTo(sourceType, targetType, reportErrors)) { - if (reportErrors) { - reportError(ts.Diagnostics.Index_signatures_are_incompatible_Colon); - } - return false; + var targetType = getIndexTypeOfType(target, 0 /* String */); + if (targetType) { + var sourceType = getIndexTypeOfType(source, 0 /* String */); + if (!sourceType) { + if (reportErrors) { + reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } + return false; + } + if (!isRelatedTo(sourceType, targetType, reportErrors)) { + if (reportErrors) { + reportError(ts.Diagnostics.Index_signatures_are_incompatible_Colon); + } + return false; } - return true; } + return true; } function numberIndexTypesRelatedTo(source, target, reportErrors) { if (relation === identityRelation) { - return areIndexTypesIdenticalTo(1 /* Number */, source, target, reportErrors); + return indexTypesIdenticalTo(1 /* Number */, source, target, reportErrors); } - else { - var targetType = getIndexTypeOfType(target, 1 /* Number */); - if (targetType) { - var sourceStringType = getIndexTypeOfType(source, 0 /* String */); - var sourceNumberType = getIndexTypeOfType(source, 1 /* Number */); - if (!(sourceStringType || sourceNumberType)) { - if (reportErrors) { - reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); - } - return false; - } - if (sourceStringType && sourceNumberType) { - var compatible = isRelatedTo(sourceStringType, targetType, false) || isRelatedTo(sourceNumberType, targetType, reportErrors); - } - else { - var compatible = isRelatedTo(sourceStringType || sourceNumberType, targetType, reportErrors); - } - if (!compatible) { - if (reportErrors) { - reportError(ts.Diagnostics.Index_signatures_are_incompatible_Colon); - } - return false; + var targetType = getIndexTypeOfType(target, 1 /* Number */); + if (targetType) { + var sourceStringType = getIndexTypeOfType(source, 0 /* String */); + var sourceNumberType = getIndexTypeOfType(source, 1 /* Number */); + if (!(sourceStringType || sourceNumberType)) { + if (reportErrors) { + reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } + return false; + } + if (sourceStringType && sourceNumberType) { + var compatible = isRelatedTo(sourceStringType, targetType, false) || isRelatedTo(sourceNumberType, targetType, reportErrors); + } + else { + var compatible = isRelatedTo(sourceStringType || sourceNumberType, targetType, reportErrors); + } + if (!compatible) { + if (reportErrors) { + reportError(ts.Diagnostics.Index_signatures_are_incompatible_Colon); + } + return false; } - return true; } + return true; } - function areIndexTypesIdenticalTo(indexKind, source, target, reportErrors) { + function indexTypesIdenticalTo(indexKind, source, target, reportErrors) { var targetType = getIndexTypeOfType(target, indexKind); var sourceType = getIndexTypeOfType(source, indexKind); return (!sourceType && !targetType) || (sourceType && targetType && isRelatedTo(sourceType, targetType, reportErrors)); } } + function compareSignatures(source, target, compareReturnTypes, compareTypes) { + if (source === target) { + return true; + } + if (source.parameters.length !== target.parameters.length || source.minArgumentCount !== target.minArgumentCount || source.hasRestParameter !== target.hasRestParameter) { + return false; + } + if (source.typeParameters && target.typeParameters) { + if (source.typeParameters.length !== target.typeParameters.length) { + return false; + } + for (var i = 0, len = source.typeParameters.length; i < len; ++i) { + if (!compareTypes(source.typeParameters[i], target.typeParameters[i])) { + return false; + } + } + } + else if (source.typeParameters || source.typeParameters) { + return false; + } + source = getErasedSignature(source); + target = getErasedSignature(target); + for (var i = 0, len = source.parameters.length; i < len; i++) { + var s = source.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(source) : getTypeOfSymbol(source.parameters[i]); + var t = target.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(target) : getTypeOfSymbol(target.parameters[i]); + if (!compareTypes(s, t)) { + return false; + } + } + return !compareReturnTypes || compareTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target)); + } function isSupertypeOfEach(candidate, types) { for (var i = 0, len = types.length; i < len; i++) { if (candidate !== types[i] && !isTypeSubtypeOf(types[i], candidate)) @@ -11556,13 +12106,11 @@ var ts; } return true; } - function getBestCommonType(types, contextualType, candidatesOnly) { - if (contextualType && isSupertypeOfEach(contextualType, types)) - return contextualType; - return ts.forEach(types, function (t) { return isSupertypeOfEach(t, types) ? t : undefined; }) || (candidatesOnly ? undefined : emptyObjectType); + function getCommonSupertype(types) { + return ts.forEach(types, function (t) { return isSupertypeOfEach(t, types) ? t : undefined; }); } function isTypeOfObjectLiteral(type) { - return (type.flags & 16384 /* Anonymous */) && type.symbol && (type.symbol.flags & 1024 /* ObjectLiteral */) ? true : false; + return (type.flags & 32768 /* Anonymous */) && type.symbol && (type.symbol.flags & 1024 /* ObjectLiteral */) ? true : false; } function isArrayType(type) { return type.flags & 4096 /* Reference */ && type.target === globalArrayType; @@ -11573,10 +12121,13 @@ var ts; } return type; } - function getWidenedType(type, supressNoImplicitAnyErrors) { + function getWidenedType(type, suppressNoImplicitAnyErrors) { if (type.flags & (32 /* Undefined */ | 64 /* Null */)) { return anyType; } + if (type.flags & 16384 /* Union */) { + return getWidenedTypeOfUnion(type); + } if (isTypeOfObjectLiteral(type)) { return getWidenedTypeOfObjectLiteral(type); } @@ -11584,8 +12135,11 @@ var ts; return getWidenedTypeOfArrayLiteral(type); } return type; + function getWidenedTypeOfUnion(type) { + return getUnionType(ts.map(type.types, function (t) { return getWidenedType(t, suppressNoImplicitAnyErrors); })); + } function getWidenedTypeOfObjectLiteral(type) { - var properties = getPropertiesOfType(type); + var properties = getPropertiesOfObjectType(type); if (properties.length) { var widenedTypes = []; var propTypeWasWidened = false; @@ -11594,7 +12148,7 @@ var ts; var widenedType = getWidenedType(propType); if (propType !== widenedType) { propTypeWasWidened = true; - if (!supressNoImplicitAnyErrors && program.getCompilerOptions().noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + if (!suppressNoImplicitAnyErrors && compilerOptions.noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { error(p.valueDeclaration, ts.Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(widenedType)); } } @@ -11604,7 +12158,7 @@ var ts; var members = {}; var index = 0; ts.forEach(properties, function (p) { - var symbol = createSymbol(2 /* Property */ | 33554432 /* Transient */, p.name); + var symbol = createSymbol(2 /* Property */ | 33554432 /* Transient */ | p.flags, p.name); symbol.declarations = p.declarations; symbol.parent = p.parent; symbol.type = widenedTypes[index++]; @@ -11626,7 +12180,7 @@ var ts; } function getWidenedTypeOfArrayLiteral(type) { var elementType = type.typeArguments[0]; - var widenedType = getWidenedType(elementType, supressNoImplicitAnyErrors); + var widenedType = getWidenedType(elementType, suppressNoImplicitAnyErrors); type = elementType !== widenedType ? createArrayType(widenedType) : type; return type; } @@ -11657,12 +12211,14 @@ var ts; callback(s, t); } } - function createInferenceContext(typeParameters) { + function createInferenceContext(typeParameters, inferUnionTypes) { var inferences = []; for (var i = 0; i < typeParameters.length; i++) inferences.push([]); return { typeParameters: typeParameters, + inferUnionTypes: inferUnionTypes, + inferenceCount: 0, inferences: inferences, inferredTypes: new Array(typeParameters.length) }; @@ -11697,6 +12253,7 @@ var ts; var typeParameters = context.typeParameters; for (var i = 0; i < typeParameters.length; i++) { if (target === typeParameters[i]) { + context.inferenceCount++; var inferences = context.inferences[i]; if (!ts.contains(inferences, source)) inferences.push(source); @@ -11711,7 +12268,32 @@ var ts; inferFromTypes(sourceTypes[i], targetTypes[i]); } } - else if (source.flags & ts.TypeFlags.ObjectType && (target.flags & (4096 /* Reference */ | 8192 /* Tuple */) || (target.flags & 16384 /* Anonymous */) && target.symbol && target.symbol.flags & (2048 /* Method */ | 512 /* TypeLiteral */))) { + else if (target.flags & 16384 /* Union */) { + var targetTypes = target.types; + var startCount = context.inferenceCount; + var typeParameterCount = 0; + var typeParameter; + for (var i = 0; i < targetTypes.length; i++) { + var t = targetTypes[i]; + if (t.flags & 512 /* TypeParameter */ && ts.contains(context.typeParameters, t)) { + typeParameter = t; + typeParameterCount++; + } + else { + inferFromTypes(source, t); + } + } + if (context.inferenceCount === startCount && typeParameterCount === 1) { + inferFromTypes(source, typeParameter); + } + } + else if (source.flags & 16384 /* Union */) { + var sourceTypes = source.types; + for (var i = 0; i < sourceTypes.length; i++) { + inferFromTypes(sourceTypes[i], target); + } + } + else if (source.flags & ts.TypeFlags.ObjectType && (target.flags & (4096 /* Reference */ | 8192 /* Tuple */) || (target.flags & 32768 /* Anonymous */) && target.symbol && target.symbol.flags & (2048 /* Method */ | 512 /* TypeLiteral */))) { if (!isInProcess(source, target) && isWithinDepthLimit(source, sourceStack) && isWithinDepthLimit(target, targetStack)) { if (depth === 0) { sourceStack = []; @@ -11731,10 +12313,10 @@ var ts; } } function inferFromProperties(source, target) { - var properties = getPropertiesOfType(target); + var properties = getPropertiesOfObjectType(target); for (var i = 0; i < properties.length; i++) { var targetProp = properties[i]; - var sourceProp = getPropertyOfType(source, targetProp.name); + var sourceProp = getPropertyOfObjectType(source, targetProp.name); if (sourceProp) { inferFromTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp)); } @@ -11767,9 +12349,16 @@ var ts; function getInferredType(context, index) { var result = context.inferredTypes[index]; if (!result) { - var commonType = getWidenedType(getBestCommonType(context.inferences[index])); + var inferences = context.inferences[index]; + if (inferences.length) { + var unionOrSuperType = context.inferUnionTypes ? getUnionType(inferences) : getCommonSupertype(inferences); + var inferredType = unionOrSuperType ? getWidenedType(unionOrSuperType) : undefinedType; + } + else { + inferredType = emptyObjectType; + } var constraint = getConstraintOfTypeParameter(context.typeParameters[index]); - var result = constraint && !isTypeAssignableTo(commonType, constraint) ? constraint : commonType; + var result = constraint && !isTypeAssignableTo(inferredType, constraint) ? constraint : inferredType; context.inferredTypes[index] = result; } return result; @@ -11784,37 +12373,244 @@ var ts; function hasAncestor(node, kind) { return ts.getAncestor(node, kind) !== undefined; } - function checkIdentifier(node) { - function isInTypeQuery(node) { - while (node) { - switch (node.kind) { - case 128 /* TypeQuery */: - return true; - case 59 /* Identifier */: - case 116 /* QualifiedName */: - node = node.parent; - continue; - default: - return false; + function getResolvedSymbol(node) { + var links = getNodeLinks(node); + if (!links.resolvedSymbol) { + links.resolvedSymbol = resolveName(node, node.text, ts.SymbolFlags.Value | 524288 /* ExportValue */, ts.Diagnostics.Cannot_find_name_0, ts.identifierToString(node)) || unknownSymbol; + } + return links.resolvedSymbol; + } + function isInTypeQuery(node) { + while (node) { + switch (node.kind) { + case 128 /* TypeQuery */: + return true; + case 59 /* Identifier */: + case 116 /* QualifiedName */: + node = node.parent; + continue; + default: + return false; + } + } + ts.Debug.fail("should not get here"); + } + function subtractPrimitiveTypes(type, subtractMask) { + if (type.flags & 16384 /* Union */) { + var types = type.types; + if (ts.forEach(types, function (t) { return t.flags & subtractMask; })) { + return getUnionType(ts.filter(types, function (t) { return !(t.flags & subtractMask); })); + } + } + return type; + } + function isVariableAssignedWithin(symbol, node) { + var links = getNodeLinks(node); + if (links.assignmentChecks) { + var cachedResult = links.assignmentChecks[symbol.id]; + if (cachedResult !== undefined) { + return cachedResult; + } + } + else { + links.assignmentChecks = {}; + } + return links.assignmentChecks[symbol.id] = isAssignedIn(node); + function isAssignedInBinaryExpression(node) { + if (node.operator >= ts.SyntaxKind.FirstAssignment && node.operator <= ts.SyntaxKind.LastAssignment) { + var n = node.left; + while (n.kind === 142 /* ParenExpression */) { + n = n.expression; + } + if (n.kind === 59 /* Identifier */ && getResolvedSymbol(n) === symbol) { + return true; } } - ts.Debug.fail("should not get here"); + return ts.forEachChild(node, isAssignedIn); } - var symbol = resolveName(node, node.text, ts.SymbolFlags.Value | 524288 /* ExportValue */, ts.Diagnostics.Cannot_find_name_0, ts.identifierToString(node)); - if (!symbol) { - symbol = unknownSymbol; + function isAssignedInVariableDeclaration(node) { + if (getSymbolOfNode(node) === symbol && node.initializer) { + return true; + } + return ts.forEachChild(node, isAssignedIn); } + function isAssignedIn(node) { + switch (node.kind) { + case 147 /* BinaryExpression */: + return isAssignedInBinaryExpression(node); + case 173 /* VariableDeclaration */: + return isAssignedInVariableDeclaration(node); + case 134 /* ArrayLiteral */: + case 135 /* ObjectLiteral */: + case 137 /* PropertyAccess */: + case 138 /* IndexedAccess */: + case 139 /* CallExpression */: + case 140 /* NewExpression */: + case 141 /* TypeAssertion */: + case 142 /* ParenExpression */: + case 145 /* PrefixOperator */: + case 146 /* PostfixOperator */: + case 148 /* ConditionalExpression */: + case 150 /* Block */: + case 151 /* VariableStatement */: + case 153 /* ExpressionStatement */: + case 154 /* IfStatement */: + case 155 /* DoStatement */: + case 156 /* WhileStatement */: + case 157 /* ForStatement */: + case 158 /* ForInStatement */: + case 161 /* ReturnStatement */: + case 162 /* WithStatement */: + case 163 /* SwitchStatement */: + case 164 /* CaseClause */: + case 165 /* DefaultClause */: + case 166 /* LabeledStatement */: + case 167 /* ThrowStatement */: + case 168 /* TryStatement */: + case 169 /* TryBlock */: + case 170 /* CatchBlock */: + case 171 /* FinallyBlock */: + return ts.forEachChild(node, isAssignedIn); + } + return false; + } + } + function getNarrowedTypeOfSymbol(symbol, node) { + var type = getTypeOfSymbol(symbol); + if (symbol.flags & 1 /* Variable */ && type.flags & ts.TypeFlags.Structured) { + while (true) { + var child = node; + node = node.parent; + if (!node || node.kind === 175 /* FunctionBlock */ || node.kind === 180 /* ModuleBlock */) { + break; + } + var narrowedType = type; + switch (node.kind) { + case 154 /* IfStatement */: + if (child !== node.expression) { + narrowedType = narrowType(type, node.expression, child === node.thenStatement); + } + break; + case 148 /* ConditionalExpression */: + if (child !== node.condition) { + narrowedType = narrowType(type, node.condition, child === node.whenTrue); + } + break; + case 147 /* BinaryExpression */: + if (child === node.right) { + if (node.operator === 43 /* AmpersandAmpersandToken */) { + narrowedType = narrowType(type, node.left, true); + } + else if (node.operator === 44 /* BarBarToken */) { + narrowedType = narrowType(type, node.left, false); + } + } + break; + } + if (narrowedType !== type) { + if (isVariableAssignedWithin(symbol, node)) { + break; + } + type = narrowedType; + } + } + } + return type; + function narrowTypeByEquality(type, expr, assumeTrue) { + var left = expr.left; + var right = expr.right; + if (left.kind !== 145 /* PrefixOperator */ || left.operator !== 91 /* TypeOfKeyword */ || left.operand.kind !== 59 /* Identifier */ || right.kind !== 7 /* StringLiteral */ || getResolvedSymbol(left.operand) !== symbol) { + return type; + } + var t = right.text; + var checkType = t === "string" ? stringType : t === "number" ? numberType : t === "boolean" ? booleanType : emptyObjectType; + if (expr.operator === 26 /* ExclamationEqualsEqualsToken */) { + assumeTrue = !assumeTrue; + } + if (assumeTrue) { + return checkType === emptyObjectType ? subtractPrimitiveTypes(type, 2 /* String */ | 4 /* Number */ | 8 /* Boolean */) : checkType; + } + else { + return checkType === emptyObjectType ? type : subtractPrimitiveTypes(type, checkType.flags); + } + } + function narrowTypeByAnd(type, expr, assumeTrue) { + if (assumeTrue) { + return narrowType(narrowType(type, expr.left, true), expr.right, true); + } + else { + return getUnionType([ + narrowType(type, expr.left, false), + narrowType(narrowType(type, expr.left, true), expr.right, false) + ]); + } + } + function narrowTypeByOr(type, expr, assumeTrue) { + if (assumeTrue) { + return getUnionType([ + narrowType(type, expr.left, true), + narrowType(narrowType(type, expr.left, false), expr.right, true) + ]); + } + else { + return narrowType(narrowType(type, expr.left, false), expr.right, false); + } + } + function narrowTypeByInstanceof(type, expr, assumeTrue) { + if (!assumeTrue || expr.left.kind !== 59 /* Identifier */ || getResolvedSymbol(expr.left) !== symbol) { + return type; + } + var rightType = checkExpression(expr.right); + if (!isTypeSubtypeOf(rightType, globalFunctionType)) { + return type; + } + var prototypeProperty = getPropertyOfType(rightType, "prototype"); + if (!prototypeProperty) { + return type; + } + var prototypeType = getTypeOfSymbol(prototypeProperty); + return isTypeSubtypeOf(prototypeType, type) ? prototypeType : type; + } + function narrowType(type, expr, assumeTrue) { + switch (expr.kind) { + case 142 /* ParenExpression */: + return narrowType(type, expr.expression, assumeTrue); + case 147 /* BinaryExpression */: + var operator = expr.operator; + if (operator === 25 /* EqualsEqualsEqualsToken */ || operator === 26 /* ExclamationEqualsEqualsToken */) { + return narrowTypeByEquality(type, expr, assumeTrue); + } + else if (operator === 43 /* AmpersandAmpersandToken */) { + return narrowTypeByAnd(type, expr, assumeTrue); + } + else if (operator === 44 /* BarBarToken */) { + return narrowTypeByOr(type, expr, assumeTrue); + } + else if (operator === 81 /* InstanceOfKeyword */) { + return narrowTypeByInstanceof(type, expr, assumeTrue); + } + break; + case 145 /* PrefixOperator */: + if (expr.operator === 41 /* ExclamationToken */) { + return narrowType(type, expr.operand, !assumeTrue); + } + break; + } + return type; + } + } + function checkIdentifier(node) { + var symbol = getResolvedSymbol(node); if (symbol.flags & 4194304 /* Import */) { getSymbolLinks(symbol).referenced = !isInTypeQuery(node); } - getNodeLinks(node).resolvedSymbol = symbol; checkCollisionWithCapturedSuperVariable(node, node); checkCollisionWithCapturedThisVariable(node, node); checkCollisionWithIndexVariableInGeneratedCode(node, node); - return getTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol)); + return getNarrowedTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol), node); } function captureLexicalThis(node, container) { - var classNode = container.parent && container.parent.kind === 174 /* ClassDeclaration */ ? container.parent : undefined; + var classNode = container.parent && container.parent.kind === 176 /* ClassDeclaration */ ? container.parent : undefined; getNodeLinks(node).flags |= 2 /* LexicalThis */; if (container.kind === 119 /* Property */ || container.kind === 121 /* Constructor */) { getNodeLinks(classNode).flags |= 4 /* CaptureThis */; @@ -11826,15 +12622,15 @@ var ts; function checkThisExpression(node) { var container = ts.getThisContainer(node, true); var needToCaptureLexicalThis = false; - if (container.kind === 142 /* ArrowFunction */) { + if (container.kind === 144 /* ArrowFunction */) { container = ts.getThisContainer(container, false); needToCaptureLexicalThis = true; } switch (container.kind) { - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_module_body); break; - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: error(node, ts.Diagnostics.this_cannot_be_referenced_in_current_location); break; case 121 /* Constructor */: @@ -11851,7 +12647,7 @@ var ts; if (needToCaptureLexicalThis) { captureLexicalThis(node, container); } - var classNode = container.parent && container.parent.kind === 174 /* ClassDeclaration */ ? container.parent : undefined; + var classNode = container.parent && container.parent.kind === 176 /* ClassDeclaration */ ? container.parent : undefined; if (classNode) { var symbol = getSymbolOfNode(classNode); return container.flags & 128 /* Static */ ? getTypeOfSymbol(symbol) : getDeclaredTypeOfSymbol(symbol); @@ -11864,9 +12660,9 @@ var ts; if (!node) return node; switch (node.kind) { - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: case 119 /* Property */: case 120 /* Method */: case 121 /* Constructor */: @@ -11885,8 +12681,8 @@ var ts; return false; } function checkSuperExpression(node) { - var isCallExpression = node.parent.kind === 137 /* CallExpression */ && node.parent.func === node; - var enclosingClass = ts.getAncestor(node, 174 /* ClassDeclaration */); + var isCallExpression = node.parent.kind === 139 /* CallExpression */ && node.parent.func === node; + var enclosingClass = ts.getAncestor(node, 176 /* ClassDeclaration */); var baseClass; if (enclosingClass && enclosingClass.baseType) { var classType = getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClass)); @@ -11904,11 +12700,11 @@ var ts; } else { var needToCaptureLexicalThis = false; - while (container && container.kind === 142 /* ArrowFunction */) { + while (container && container.kind === 144 /* ArrowFunction */) { container = getSuperContainer(container); needToCaptureLexicalThis = true; } - if (container && container.parent && container.parent.kind === 174 /* ClassDeclaration */) { + if (container && container.parent && container.parent.kind === 176 /* ClassDeclaration */) { if (container.flags & 128 /* Static */) { canUseSuperExpression = container.kind === 120 /* Method */ || container.kind === 122 /* GetAccessor */ || container.kind === 123 /* SetAccessor */; } @@ -11947,11 +12743,19 @@ var ts; } function getContextuallyTypedParameterType(parameter) { var func = parameter.parent; - if (func.kind === 141 /* FunctionExpression */ || func.kind === 142 /* ArrowFunction */) { + if (func.kind === 143 /* FunctionExpression */ || func.kind === 144 /* ArrowFunction */) { if (isContextSensitiveExpression(func)) { - var signature = getContextualSignature(func); - if (signature) { - return getTypeAtPosition(signature, ts.indexOf(func.parameters, parameter)); + var contextualSignature = getContextualSignature(func); + if (contextualSignature) { + var funcHasRestParameters = ts.hasRestParameters(func); + var len = func.parameters.length - (funcHasRestParameters ? 1 : 0); + var indexOfParameter = ts.indexOf(func.parameters, parameter); + if (indexOfParameter < len) { + return getTypeAtPosition(contextualSignature, indexOfParameter); + } + if (indexOfParameter === (func.parameters.length - 1) && funcHasRestParameters && contextualSignature.hasRestParameter && func.parameters.length >= contextualSignature.parameters.length) { + return getTypeOfSymbol(contextualSignature.parameters[contextualSignature.parameters.length - 1]); + } } } } @@ -12008,17 +12812,51 @@ var ts; } return undefined; } + function applyToContextualType(type, mapper) { + if (!(type.flags & 16384 /* Union */)) { + return mapper(type); + } + var types = type.types; + var mappedType; + var mappedTypes; + for (var i = 0; i < types.length; i++) { + var t = mapper(types[i]); + if (t) { + if (!mappedType) { + mappedType = t; + } + else if (!mappedTypes) { + mappedTypes = [mappedType, t]; + } + else { + mappedTypes.push(t); + } + } + } + return mappedTypes ? getUnionType(mappedTypes) : mappedType; + } + function getTypeOfPropertyOfContextualType(type, name) { + return applyToContextualType(type, function (t) { + var prop = getPropertyOfObjectType(t, name); + return prop ? getTypeOfSymbol(prop) : undefined; + }); + } + function getIndexTypeOfContextualType(type, kind) { + return applyToContextualType(type, function (t) { return getIndexTypeOfObjectOrUnionType(t, kind); }); + } + function contextualTypeIsTupleType(type) { + return !!(type.flags & 16384 /* Union */ ? ts.forEach(type.types, function (t) { return getPropertyOfObjectType(t, "0"); }) : getPropertyOfObjectType(type, "0")); + } + function contextualTypeHasIndexSignature(type, kind) { + return !!(type.flags & 16384 /* Union */ ? ts.forEach(type.types, function (t) { return getIndexTypeOfObjectOrUnionType(t, kind); }) : getIndexTypeOfObjectOrUnionType(type, kind)); + } function getContextualTypeForPropertyExpression(node) { var declaration = node.parent; var objectLiteral = declaration.parent; var type = getContextualType(objectLiteral); var name = declaration.name.text; if (type && name) { - var prop = getPropertyOfType(type, name); - if (prop) { - return getTypeOfSymbol(prop); - } - return isNumericName(name) && getIndexTypeOfType(type, 1 /* Number */) || getIndexTypeOfType(type, 0 /* String */); + return getTypeOfPropertyOfContextualType(type, name) || isNumericName(name) && getIndexTypeOfContextualType(type, 1 /* Number */) || getIndexTypeOfContextualType(type, 0 /* String */); } return undefined; } @@ -12027,11 +12865,7 @@ var ts; var type = getContextualType(arrayLiteral); if (type) { var index = ts.indexOf(arrayLiteral.elements, node); - var prop = getPropertyOfType(type, "" + index); - if (prop) { - return getTypeOfSymbol(prop); - } - return getIndexTypeOfType(type, 1 /* Number */); + return getTypeOfPropertyOfContextualType(type, "" + index) || getIndexTypeOfContextualType(type, 1 /* Number */); } return undefined; } @@ -12048,70 +12882,78 @@ var ts; } var parent = node.parent; switch (parent.kind) { - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: case 118 /* Parameter */: case 119 /* Property */: return getContextualTypeForInitializerExpression(node); - case 142 /* ArrowFunction */: - case 159 /* ReturnStatement */: + case 144 /* ArrowFunction */: + case 161 /* ReturnStatement */: return getContextualTypeForReturnExpression(node); - case 137 /* CallExpression */: - case 138 /* NewExpression */: + case 139 /* CallExpression */: + case 140 /* NewExpression */: return getContextualTypeForArgument(node); - case 139 /* TypeAssertion */: + case 141 /* TypeAssertion */: return getTypeFromTypeNode(parent.type); - case 145 /* BinaryExpression */: + case 147 /* BinaryExpression */: return getContextualTypeForBinaryOperand(node); - case 134 /* PropertyAssignment */: + case 136 /* PropertyAssignment */: return getContextualTypeForPropertyExpression(node); - case 132 /* ArrayLiteral */: + case 134 /* ArrayLiteral */: return getContextualTypeForElementExpression(node); - case 146 /* ConditionalExpression */: + case 148 /* ConditionalExpression */: return getContextualTypeForConditionalOperand(node); } return undefined; } + function getNonGenericSignature(type) { + var signatures = getSignaturesOfObjectOrUnionType(type, 0 /* Call */); + if (signatures.length === 1) { + var signature = signatures[0]; + if (!signature.typeParameters) { + return signature; + } + } + } function getContextualSignature(node) { var type = getContextualType(node); - if (type) { - var signatures = getSignaturesOfType(type, 0 /* Call */); - if (signatures.length === 1) { - var signature = signatures[0]; - if (!signature.typeParameters) { - return signature; + if (!type) { + return undefined; + } + if (!(type.flags & 16384 /* Union */)) { + return getNonGenericSignature(type); + } + var result; + var types = type.types; + for (var i = 0; i < types.length; i++) { + var signature = getNonGenericSignature(types[i]); + if (signature) { + if (!result) { + result = signature; + } + else if (!compareSignatures(result, signature, true, isTypeIdenticalTo)) { + return undefined; } } } - return undefined; + return result; } function isInferentialContext(mapper) { return mapper && mapper !== identityMapper; } function checkArrayLiteral(node, contextualMapper) { - var contextualType = getContextualType(node); var elements = node.elements; - var elementTypes = []; - var isTupleLiteral = false; - for (var i = 0; i < elements.length; i++) { - if (contextualType && getPropertyOfType(contextualType, "" + i)) { - isTupleLiteral = true; - } - var element = elements[i]; - var type = element.kind !== 147 /* OmittedExpression */ ? checkExpression(element, contextualMapper) : undefinedType; - elementTypes.push(type); + if (!elements.length) { + return createArrayType(undefinedType); } - if (isTupleLiteral) { + var elementTypes = ts.map(elements, function (e) { return checkExpression(e, contextualMapper); }); + var contextualType = getContextualType(node); + if (contextualType && contextualTypeIsTupleType(contextualType)) { return createTupleType(elementTypes); } - var contextualElementType = contextualType && !isInferentialContext(contextualMapper) ? getIndexTypeOfType(contextualType, 1 /* Number */) : undefined; - var elementType = getBestCommonType(ts.uniqueElements(elementTypes), contextualElementType, true); - if (!elementType) { - elementType = elements.length ? emptyObjectType : undefinedType; - } - return createArrayType(elementType); + return createArrayType(getUnionType(elementTypes)); } function isNumericName(name) { - return !isNaN(name); + return (+name).toString() === name; } function checkObjectLiteral(node, contextualMapper) { var members = node.symbol.members; @@ -12122,7 +12964,7 @@ var ts; var member = members[id]; if (member.flags & 2 /* Property */) { var type = checkExpression(member.declarations[0].initializer, contextualMapper); - var prop = createSymbol(2 /* Property */ | 33554432 /* Transient */, member.name); + var prop = createSymbol(2 /* Property */ | 33554432 /* Transient */ | member.flags, member.name); prop.declarations = member.declarations; prop.parent = member.parent; if (member.valueDeclaration) @@ -12148,22 +12990,21 @@ var ts; var numberIndexType = getIndexType(1 /* Number */); return createAnonymousType(node.symbol, properties, emptyArray, emptyArray, stringIndexType, numberIndexType); function getIndexType(kind) { - if (contextualType) { - var indexType = getIndexTypeOfType(contextualType, kind); - if (indexType) { - var propTypes = []; - for (var id in properties) { - if (ts.hasProperty(properties, id)) { - if (kind === 0 /* String */ || isNumericName(id)) { - var type = getTypeOfSymbol(properties[id]); - if (!ts.contains(propTypes, type)) - propTypes.push(type); + if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) { + var propTypes = []; + for (var id in properties) { + if (ts.hasProperty(properties, id)) { + if (kind === 0 /* String */ || isNumericName(id)) { + var type = getTypeOfSymbol(properties[id]); + if (!ts.contains(propTypes, type)) { + propTypes.push(type); } } } - return getBestCommonType(propTypes, isInferentialContext(contextualMapper) ? undefined : indexType); } + return propTypes.length ? getUnionType(propTypes) : undefinedType; } + return undefined; } } function getDeclarationKindFromSymbol(s) { @@ -12177,7 +13018,7 @@ var ts; if (!(flags & (32 /* Private */ | 64 /* Protected */))) { return; } - var enclosingClassDeclaration = ts.getAncestor(node, 174 /* ClassDeclaration */); + var enclosingClassDeclaration = ts.getAncestor(node, 176 /* ClassDeclaration */); var enclosingClass = enclosingClassDeclaration ? getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClassDeclaration)) : undefined; var declaringClass = getDeclaredTypeOfSymbol(prop.parent); if (flags & 32 /* Private */) { @@ -12209,7 +13050,7 @@ var ts; if (apparentType === unknownType) { return unknownType; } - var prop = getPropertyOfApparentType(apparentType, node.right.text); + var prop = getPropertyOfType(apparentType, node.right.text); if (!prop) { if (node.right.text) { error(node.right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.identifierToString(node.right), typeToString(type)); @@ -12229,30 +13070,43 @@ var ts; } return anyType; } + function isValidPropertyAccess(node, propertyName) { + var type = checkExpression(node.left); + if (type !== unknownType && type !== anyType) { + var prop = getPropertyOfType(getWidenedType(type), propertyName); + if (prop && prop.parent && prop.parent.flags & 16 /* Class */) { + if (node.left.kind === 85 /* SuperKeyword */ && getDeclarationKindFromSymbol(prop) !== 120 /* Method */) { + return false; + } + else { + var diagnosticsCount = diagnostics.length; + checkClassPropertyAccess(node, type, prop); + return diagnostics.length === diagnosticsCount; + } + } + } + return true; + } function checkIndexedAccess(node) { - var objectType = checkExpression(node.object); + var objectType = getApparentType(checkExpression(node.object)); var indexType = checkExpression(node.index); if (objectType === unknownType) return unknownType; - var apparentType = getApparentType(objectType); - if (apparentType === unknownType) { - return unknownType; - } if (node.index.kind === 7 /* StringLiteral */ || node.index.kind === 6 /* NumericLiteral */) { var name = node.index.text; - var prop = getPropertyOfApparentType(apparentType, name); + var prop = getPropertyOfType(objectType, name); if (prop) { return getTypeOfSymbol(prop); } } if (indexType.flags & (1 /* Any */ | ts.TypeFlags.StringLike | ts.TypeFlags.NumberLike)) { if (indexType.flags & (1 /* Any */ | ts.TypeFlags.NumberLike)) { - var numberIndexType = getIndexTypeOfType(apparentType, 1 /* Number */); + var numberIndexType = getIndexTypeOfType(objectType, 1 /* Number */); if (numberIndexType) { return numberIndexType; } } - var stringIndexType = getIndexTypeOfType(apparentType, 0 /* String */); + var stringIndexType = getIndexTypeOfType(objectType, 0 /* String */); if (stringIndexType) { return stringIndexType; } @@ -12274,46 +13128,24 @@ var ts; resolveUntypedCall(node); return unknownSignature; } - function isCandidateSignature(node, signature) { - var args = node.arguments || emptyArray; - return args.length >= signature.minArgumentCount && (signature.hasRestParameter || args.length <= signature.parameters.length) && (!node.typeArguments || signature.typeParameters && node.typeArguments.length === signature.typeParameters.length); - } - function collectCandidates(node, signatures) { - var result = []; - var lastParent; - var lastSymbol; - var cutoffPos = 0; - var pos; - for (var i = 0; i < signatures.length; i++) { - var signature = signatures[i]; - if (isCandidateSignature(node, signature)) { - var symbol = signature.declaration && getSymbolOfNode(signature.declaration); - var parent = signature.declaration && signature.declaration.parent; - if (!lastSymbol || symbol === lastSymbol) { - if (lastParent && parent === lastParent) { - pos++; - } - else { - lastParent = parent; - pos = cutoffPos; - } - } - else { - pos = cutoffPos = result.length; - lastParent = parent; - } - lastSymbol = symbol; - for (var j = result.length; j > pos; j--) { - result[j] = result[j - 1]; - } - result[pos] = signature; - } + function signatureHasCorrectArity(node, signature) { + if (!node.arguments) { + return signature.minArgumentCount === 0; } - return result; + var args = node.arguments; + var numberOfArgs = args.hasTrailingComma ? args.length + 1 : args.length; + var hasTooManyArguments = !signature.hasRestParameter && numberOfArgs > signature.parameters.length; + var hasRightNumberOfTypeArguments = !node.typeArguments || (signature.typeParameters && node.typeArguments.length === signature.typeParameters.length); + if (hasTooManyArguments || !hasRightNumberOfTypeArguments) { + return false; + } + var callIsIncomplete = args.end === node.end; + var hasEnoughArguments = numberOfArgs >= signature.minArgumentCount; + return callIsIncomplete || hasEnoughArguments; } function getSingleCallSignature(type) { if (type.flags & ts.TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); + var resolved = resolveObjectOrUnionTypeMembers(type); if (resolved.callSignatures.length === 1 && resolved.constructSignatures.length === 0 && resolved.properties.length === 0 && !resolved.stringIndexType && !resolved.numberIndexType) { return resolved.callSignatures[0]; } @@ -12321,7 +13153,7 @@ var ts; return undefined; } function instantiateSignatureInContextOf(signature, contextualSignature, contextualMapper) { - var context = createInferenceContext(signature.typeParameters); + var context = createInferenceContext(signature.typeParameters, true); forEachMatchingParameterType(contextualSignature, signature, function (source, target) { inferTypes(context, instantiateType(source, contextualMapper), target); }); @@ -12329,9 +13161,12 @@ var ts; } function inferTypeArguments(signature, args, excludeArgument) { var typeParameters = signature.typeParameters; - var context = createInferenceContext(typeParameters); + var context = createInferenceContext(typeParameters, false); var mapper = createInferenceMapper(context); for (var i = 0; i < args.length; i++) { + if (args[i].kind === 149 /* OmittedExpression */) { + continue; + } if (!excludeArgument || excludeArgument[i] === undefined) { var parameterType = getTypeAtPosition(signature, i); inferTypes(context, checkExpressionWithContextualType(args[i], parameterType, mapper), parameterType); @@ -12339,13 +13174,17 @@ var ts; } if (excludeArgument) { for (var i = 0; i < args.length; i++) { + if (args[i].kind === 149 /* OmittedExpression */) { + continue; + } if (excludeArgument[i] === false) { var parameterType = getTypeAtPosition(signature, i); inferTypes(context, checkExpressionWithContextualType(args[i], parameterType, mapper), parameterType); } } } - return getInferredTypes(context); + var inferredTypes = getInferredTypes(context); + return ts.contains(inferredTypes, undefinedType) ? undefined : inferredTypes; } function checkTypeArguments(signature, typeArguments) { var typeParameters = signature.typeParameters; @@ -12365,6 +13204,9 @@ var ts; if (node.arguments) { for (var i = 0; i < node.arguments.length; i++) { var arg = node.arguments[i]; + if (arg.kind === 149 /* OmittedExpression */) { + continue; + } var paramType = getTypeAtPosition(signature, i); var argType = arg.kind === 7 /* StringLiteral */ && !reportErrors ? getStringLiteralType(arg) : checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined); var isValidArgument = checkTypeRelatedTo(argType, paramType, relation, reportErrors ? arg : undefined, ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1, ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1); @@ -12375,9 +13217,10 @@ var ts; } return true; } - function resolveCall(node, signatures) { + function resolveCall(node, signatures, candidatesOutArray) { ts.forEach(node.typeArguments, checkSourceElement); - var candidates = collectCandidates(node, signatures); + var candidates = candidatesOutArray || []; + collectCandidates(); if (!candidates.length) { error(node, ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); return resolveErrorCall(node); @@ -12392,14 +13235,22 @@ var ts; } } var relation = candidates.length === 1 ? assignableRelation : subtypeRelation; + var lastCandidate; while (true) { for (var i = 0; i < candidates.length; i++) { + if (!signatureHasCorrectArity(node, candidates[i])) { + continue; + } while (true) { var candidate = candidates[i]; if (candidate.typeParameters) { var typeArguments = node.typeArguments ? checkTypeArguments(candidate, node.typeArguments) : inferTypeArguments(candidate, args, excludeArgument); + if (!typeArguments) { + break; + } candidate = getSignatureInstantiation(candidate, typeArguments); } + lastCandidate = candidate; if (!checkApplicableSignature(node, candidate, relation, excludeArgument, false)) { break; } @@ -12415,28 +13266,70 @@ var ts; } relation = assignableRelation; } - checkApplicableSignature(node, candidate, relation, undefined, true); + if (lastCandidate) { + checkApplicableSignature(node, lastCandidate, relation, undefined, true); + } + else { + error(node, ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); + } + if (!fullTypeCheck) { + for (var i = 0, n = candidates.length; i < n; i++) { + if (signatureHasCorrectArity(node, candidates[i])) { + return candidates[i]; + } + } + } return resolveErrorCall(node); + function collectCandidates() { + var result = candidates; + var lastParent; + var lastSymbol; + var cutoffPos = 0; + var pos; + ts.Debug.assert(!result.length); + for (var i = 0; i < signatures.length; i++) { + var signature = signatures[i]; + if (true) { + var symbol = signature.declaration && getSymbolOfNode(signature.declaration); + var parent = signature.declaration && signature.declaration.parent; + if (!lastSymbol || symbol === lastSymbol) { + if (lastParent && parent === lastParent) { + pos++; + } + else { + lastParent = parent; + pos = cutoffPos; + } + } + else { + pos = cutoffPos = result.length; + lastParent = parent; + } + lastSymbol = symbol; + for (var j = result.length; j > pos; j--) { + result[j] = result[j - 1]; + } + result[pos] = signature; + } + } + } } - function resolveCallExpression(node) { + function resolveCallExpression(node, candidatesOutArray) { if (node.func.kind === 85 /* SuperKeyword */) { var superType = checkSuperExpression(node.func); if (superType !== unknownType) { - return resolveCall(node, getSignaturesOfType(superType, 1 /* Construct */)); + return resolveCall(node, getSignaturesOfType(superType, 1 /* Construct */), candidatesOutArray); } return resolveUntypedCall(node); } var funcType = checkExpression(node.func); - if (funcType === unknownType) { - return resolveErrorCall(node); - } var apparentType = getApparentType(funcType); if (apparentType === unknownType) { return resolveErrorCall(node); } var callSignatures = getSignaturesOfType(apparentType, 0 /* Call */); var constructSignatures = getSignaturesOfType(apparentType, 1 /* Construct */); - if ((funcType === anyType) || (!callSignatures.length && !constructSignatures.length && isTypeAssignableTo(funcType, globalFunctionType))) { + if (funcType === anyType || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & 16384 /* Union */) && isTypeAssignableTo(funcType, globalFunctionType))) { if (node.typeArguments) { error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); } @@ -12451,13 +13344,10 @@ var ts; } return resolveErrorCall(node); } - return resolveCall(node, callSignatures); + return resolveCall(node, callSignatures, candidatesOutArray); } - function resolveNewExpression(node) { + function resolveNewExpression(node, candidatesOutArray) { var expressionType = checkExpression(node.func); - if (expressionType === unknownType) { - return resolveErrorCall(node); - } if (expressionType === anyType) { if (node.typeArguments) { error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); @@ -12470,11 +13360,11 @@ var ts; } var constructSignatures = getSignaturesOfType(expressionType, 1 /* Construct */); if (constructSignatures.length) { - return resolveCall(node, constructSignatures); + return resolveCall(node, constructSignatures, candidatesOutArray); } var callSignatures = getSignaturesOfType(expressionType, 0 /* Call */); if (callSignatures.length) { - var signature = resolveCall(node, callSignatures); + var signature = resolveCall(node, callSignatures, candidatesOutArray); if (getReturnTypeOfSignature(signature) !== voidType) { error(node, ts.Diagnostics.Only_a_void_function_can_be_called_with_the_new_keyword); } @@ -12483,11 +13373,11 @@ var ts; error(node, ts.Diagnostics.Cannot_use_new_with_an_expression_whose_type_lacks_a_call_or_construct_signature); return resolveErrorCall(node); } - function getResolvedSignature(node) { + function getResolvedSignature(node, candidatesOutArray) { var links = getNodeLinks(node); - if (!links.resolvedSignature) { + if (!links.resolvedSignature || candidatesOutArray) { links.resolvedSignature = anySignature; - links.resolvedSignature = node.kind === 137 /* CallExpression */ ? resolveCallExpression(node) : resolveNewExpression(node); + links.resolvedSignature = node.kind === 139 /* CallExpression */ ? resolveCallExpression(node, candidatesOutArray) : resolveNewExpression(node, candidatesOutArray); } return links.resolvedSignature; } @@ -12496,7 +13386,7 @@ var ts; if (node.func.kind === 85 /* SuperKeyword */) { return voidType; } - if (node.kind === 138 /* NewExpression */) { + if (node.kind === 140 /* NewExpression */) { var declaration = signature.declaration; if (declaration && (declaration.kind !== 121 /* Constructor */ && declaration.kind !== 125 /* ConstructSignature */)) { if (compilerOptions.noImplicitAny) { @@ -12535,23 +13425,24 @@ var ts; } } function getReturnTypeFromBody(func, contextualMapper) { - if (func.body.kind !== 173 /* FunctionBlock */) { + var contextualSignature = getContextualSignature(func); + if (func.body.kind !== 175 /* FunctionBlock */) { var unwidenedType = checkAndMarkExpression(func.body, contextualMapper); var widenedType = getWidenedType(unwidenedType); - if (fullTypeCheck && compilerOptions.noImplicitAny && widenedType !== unwidenedType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + if (fullTypeCheck && compilerOptions.noImplicitAny && !contextualSignature && widenedType !== unwidenedType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { error(func, ts.Diagnostics.Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type, typeToString(widenedType)); } return widenedType; } var types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper); if (types.length > 0) { - var commonType = getBestCommonType(types, undefined, true); + var commonType = contextualSignature ? getUnionType(types) : getCommonSupertype(types); if (!commonType) { error(func, ts.Diagnostics.No_best_common_type_exists_among_return_expressions); return unknownType; } var widenedType = getWidenedType(commonType); - if (fullTypeCheck && compilerOptions.noImplicitAny && widenedType !== commonType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + if (fullTypeCheck && compilerOptions.noImplicitAny && !contextualSignature && widenedType !== commonType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { var typeName = typeToString(widenedType); if (func.name) { error(func, ts.Diagnostics._0_which_lacks_return_type_annotation_implicitly_has_an_1_return_type, ts.identifierToString(func.name), typeName); @@ -12583,7 +13474,7 @@ var ts; }); } function bodyContainsSingleThrowStatement(body) { - return (body.statements.length === 1) && (body.statements[0].kind === 165 /* ThrowStatement */); + return (body.statements.length === 1) && (body.statements[0].kind === 167 /* ThrowStatement */); } function checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(func, returnType) { if (!fullTypeCheck) { @@ -12592,7 +13483,7 @@ var ts; if (returnType === voidType || returnType === anyType) { return; } - if (!func.body || func.body.kind !== 173 /* FunctionBlock */) { + if (!func.body || func.body.kind !== 175 /* FunctionBlock */) { return; } var bodyBlock = func.body; @@ -12636,7 +13527,7 @@ var ts; if (node.type) { checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } - if (node.body.kind === 173 /* FunctionBlock */) { + if (node.body.kind === 175 /* FunctionBlock */) { checkSourceElement(node.body); } else { @@ -12664,12 +13555,12 @@ var ts; case 59 /* Identifier */: var symbol = findSymbol(n); return !symbol || symbol === unknownSymbol || symbol === argumentsSymbol || (symbol.flags & 1 /* Variable */) !== 0; - case 135 /* PropertyAccess */: + case 137 /* PropertyAccess */: var symbol = findSymbol(n); return !symbol || symbol === unknownSymbol || (symbol.flags & ~4 /* EnumMember */) !== 0; - case 136 /* IndexedAccess */: + case 138 /* IndexedAccess */: return true; - case 140 /* ParenExpression */: + case 142 /* ParenExpression */: return isReferenceOrErrorExpression(n.expression); default: return false; @@ -12713,14 +13604,17 @@ var ts; } return numberType; } - function isTypeAnyTypeObjectTypeOrTypeParameter(type) { - return type === anyType || ((type.flags & (ts.TypeFlags.ObjectType | 512 /* TypeParameter */)) !== 0); + function isStructuredType(type) { + if (type.flags & 16384 /* Union */) { + return !ts.forEach(type.types, function (t) { return !isStructuredType(t); }); + } + return (type.flags & ts.TypeFlags.Structured) !== 0; } function checkInstanceOfExpression(node, leftType, rightType) { - if (!isTypeAnyTypeObjectTypeOrTypeParameter(leftType)) { + if (leftType !== unknownType && !isStructuredType(leftType)) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } - if (rightType !== anyType && !isTypeSubtypeOf(rightType, globalFunctionType)) { + if (rightType !== unknownType && rightType !== anyType && !isTypeSubtypeOf(rightType, globalFunctionType)) { error(node.right, ts.Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type); } return booleanType; @@ -12729,7 +13623,7 @@ var ts; if (leftType !== anyType && leftType !== stringType && leftType !== numberType) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_types_any_string_or_number); } - if (!isTypeAnyTypeObjectTypeOrTypeParameter(rightType)) { + if (!isStructuredType(rightType)) { error(node.right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; @@ -12763,10 +13657,16 @@ var ts; leftType = rightType; if (rightType.flags & (32 /* Undefined */ | 64 /* Null */)) rightType = leftType; - var leftOk = checkArithmeticOperandType(node.left, leftType, ts.Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); - var rightOk = checkArithmeticOperandType(node.right, rightType, ts.Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); - if (leftOk && rightOk) { - checkAssignmentOperator(numberType); + var suggestedOperator; + if ((leftType.flags & 8 /* Boolean */) && (rightType.flags & 8 /* Boolean */) && (suggestedOperator = getSuggestedBooleanOperator(node.operator)) !== undefined) { + error(node, ts.Diagnostics.The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead, ts.tokenToString(node.operator), ts.tokenToString(suggestedOperator)); + } + else { + var leftOk = checkArithmeticOperandType(node.left, leftType, ts.Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); + var rightOk = checkArithmeticOperandType(node.right, rightType, ts.Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); + if (leftOk && rightOk) { + checkAssignmentOperator(numberType); + } } return numberType; case 28 /* PlusToken */: @@ -12801,7 +13701,7 @@ var ts; case 20 /* GreaterThanToken */: case 21 /* LessThanEqualsToken */: case 22 /* GreaterThanEqualsToken */: - if (!isTypeSubtypeOf(leftType, rightType) && !isTypeSubtypeOf(rightType, leftType)) { + if (!isTypeAssignableTo(leftType, rightType) && !isTypeAssignableTo(rightType, leftType)) { reportOperatorError(); } return booleanType; @@ -12812,13 +13712,28 @@ var ts; case 43 /* AmpersandAmpersandToken */: return rightType; case 44 /* BarBarToken */: - return getBestCommonType([leftType, rightType], isInferentialContext(contextualMapper) ? undefined : getContextualType(node)); + return getUnionType([leftType, rightType]); case 47 /* EqualsToken */: checkAssignmentOperator(rightType); return rightType; case 18 /* CommaToken */: return rightType; } + function getSuggestedBooleanOperator(operator) { + switch (operator) { + case 39 /* BarToken */: + case 57 /* BarEqualsToken */: + return 44 /* BarBarToken */; + case 40 /* CaretToken */: + case 58 /* CaretEqualsToken */: + return 26 /* ExclamationEqualsEqualsToken */; + case 38 /* AmpersandToken */: + case 56 /* AmpersandEqualsToken */: + return 43 /* AmpersandAmpersandToken */; + default: + return undefined; + } + } function checkAssignmentOperator(valueType) { if (fullTypeCheck && operator >= ts.SyntaxKind.FirstAssignment && operator <= ts.SyntaxKind.LastAssignment) { var ok = checkReferenceExpression(node.left, ts.Diagnostics.Invalid_left_hand_side_of_assignment_expression); @@ -12835,18 +13750,7 @@ var ts; checkExpression(node.condition); var type1 = checkExpression(node.whenTrue, contextualMapper); var type2 = checkExpression(node.whenFalse, contextualMapper); - var contextualType = isInferentialContext(contextualMapper) ? undefined : getContextualType(node); - var resultType = getBestCommonType([type1, type2], contextualType, true); - if (!resultType) { - if (contextualType) { - error(node, ts.Diagnostics.No_best_common_type_exists_between_0_1_and_2, typeToString(contextualType), typeToString(type1), typeToString(type2)); - } - else { - error(node, ts.Diagnostics.No_best_common_type_exists_between_0_and_1, typeToString(type1), typeToString(type2)); - } - resultType = emptyObjectType; - } - return resultType; + return getUnionType([type1, type2]); } function checkExpressionWithContextualType(node, contextualType, contextualMapper) { var saveContextualType = node.contextualType; @@ -12897,32 +13801,34 @@ var ts; return globalRegExpType; case 116 /* QualifiedName */: return checkPropertyAccess(node); - case 132 /* ArrayLiteral */: + case 134 /* ArrayLiteral */: return checkArrayLiteral(node, contextualMapper); - case 133 /* ObjectLiteral */: + case 135 /* ObjectLiteral */: return checkObjectLiteral(node, contextualMapper); - case 135 /* PropertyAccess */: + case 137 /* PropertyAccess */: return checkPropertyAccess(node); - case 136 /* IndexedAccess */: + case 138 /* IndexedAccess */: return checkIndexedAccess(node); - case 137 /* CallExpression */: - case 138 /* NewExpression */: + case 139 /* CallExpression */: + case 140 /* NewExpression */: return checkCallExpression(node); - case 139 /* TypeAssertion */: + case 141 /* TypeAssertion */: return checkTypeAssertion(node); - case 140 /* ParenExpression */: + case 142 /* ParenExpression */: return checkExpression(node.expression); - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: return checkFunctionExpression(node, contextualMapper); - case 143 /* PrefixOperator */: + case 145 /* PrefixOperator */: return checkPrefixExpression(node); - case 144 /* PostfixOperator */: + case 146 /* PostfixOperator */: return checkPostfixExpression(node); - case 145 /* BinaryExpression */: + case 147 /* BinaryExpression */: return checkBinaryExpression(node, contextualMapper); - case 146 /* ConditionalExpression */: + case 148 /* ConditionalExpression */: return checkConditionalExpression(node, contextualMapper); + case 149 /* OmittedExpression */: + return undefinedType; } return unknownType; } @@ -12985,7 +13891,7 @@ var ts; if (fullTypeCheck) { checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); - checkCollistionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkCollisionWithArgumentsInGeneratedCode(node); if (compilerOptions.noImplicitAny && !node.type) { switch (node.kind) { @@ -13001,7 +13907,7 @@ var ts; checkSpecializedSignatureDeclaration(node); } function checkTypeForDuplicateIndexSignatures(node) { - if (node.kind === 175 /* InterfaceDeclaration */) { + if (node.kind === 177 /* InterfaceDeclaration */) { var nodeSymbol = getSymbolOfNode(node); if (nodeSymbol.declarations.length > 0 && nodeSymbol.declarations[0] !== node) { return; @@ -13057,17 +13963,17 @@ var ts; return; } function isSuperCallExpression(n) { - return n.kind === 137 /* CallExpression */ && n.func.kind === 85 /* SuperKeyword */; + return n.kind === 139 /* CallExpression */ && n.func.kind === 85 /* SuperKeyword */; } function containsSuperCall(n) { if (isSuperCallExpression(n)) { return true; } switch (n.kind) { - case 141 /* FunctionExpression */: - case 172 /* FunctionDeclaration */: - case 142 /* ArrowFunction */: - case 133 /* ObjectLiteral */: + case 143 /* FunctionExpression */: + case 174 /* FunctionDeclaration */: + case 144 /* ArrowFunction */: + case 135 /* ObjectLiteral */: return false; default: return ts.forEachChild(n, containsSuperCall); @@ -13077,7 +13983,7 @@ var ts; if (n.kind === 87 /* ThisKeyword */) { error(n, ts.Diagnostics.this_cannot_be_referenced_in_current_location); } - else if (n.kind !== 141 /* FunctionExpression */ && n.kind !== 172 /* FunctionDeclaration */) { + else if (n.kind !== 143 /* FunctionExpression */ && n.kind !== 174 /* FunctionDeclaration */) { ts.forEachChild(n, markThisReferencesAsErrors); } } @@ -13089,7 +13995,7 @@ var ts; var superCallShouldBeFirst = ts.forEach(node.parent.members, isInstancePropertyWithInitializer) || ts.forEach(node.parameters, function (p) { return p.flags & (16 /* Public */ | 32 /* Private */ | 64 /* Protected */); }); if (superCallShouldBeFirst) { var statements = node.body.statements; - if (!statements.length || statements[0].kind !== 151 /* ExpressionStatement */ || !isSuperCallExpression(statements[0].expression)) { + if (!statements.length || statements[0].kind !== 153 /* ExpressionStatement */ || !isSuperCallExpression(statements[0].expression)) { error(node, ts.Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties); } else { @@ -13158,6 +14064,9 @@ var ts; function checkTupleType(node) { ts.forEach(node.elementTypes, checkSourceElement); } + function checkUnionType(node) { + ts.forEach(node.types, checkSourceElement); + } function isPrivateWithinAmbient(node) { return (node.flags & 32 /* Private */) && ts.isInAmbientContext(node); } @@ -13175,7 +14084,7 @@ var ts; } var symbol = getSymbolOfNode(signatureDeclarationNode); var signaturesToCheck; - if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 175 /* InterfaceDeclaration */) { + if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 177 /* InterfaceDeclaration */) { ts.Debug.assert(signatureDeclarationNode.kind === 124 /* CallSignature */ || signatureDeclarationNode.kind === 125 /* ConstructSignature */); var signatureKind = signatureDeclarationNode.kind === 124 /* CallSignature */ ? 0 /* Call */ : 1 /* Construct */; var containingSymbol = getSymbolOfNode(signatureDeclarationNode.parent); @@ -13195,7 +14104,7 @@ var ts; } function getEffectiveDeclarationFlags(n, flagsToCheck) { var flags = n.flags; - if (n.parent.kind !== 175 /* InterfaceDeclaration */ && ts.isInAmbientContext(n)) { + if (n.parent.kind !== 177 /* InterfaceDeclaration */ && ts.isInAmbientContext(n)) { if (!(flags & 2 /* Ambient */)) { flags |= 1 /* Export */; } @@ -13239,6 +14148,9 @@ var ts; var declarations = symbol.declarations; var isConstructor = (symbol.flags & 4096 /* Constructor */) !== 0; function reportImplementationExpectedError(node) { + if (node.name && node.name.kind === 115 /* Missing */) { + return; + } var seen = false; var subsequentNode = ts.forEachChild(node.parent, function (c) { if (seen) { @@ -13273,23 +14185,25 @@ var ts; } } var isExportSymbolInsideModule = symbol.parent && symbol.parent.flags & ts.SymbolFlags.Module; + var duplicateFunctionDeclaration = false; + var multipleConstructorImplementation = false; for (var i = 0; i < declarations.length; i++) { var node = declarations[i]; var inAmbientContext = ts.isInAmbientContext(node); - var inAmbientContextOrInterface = node.parent.kind === 175 /* InterfaceDeclaration */ || node.parent.kind === 129 /* TypeLiteral */ || inAmbientContext; + var inAmbientContextOrInterface = node.parent.kind === 177 /* InterfaceDeclaration */ || node.parent.kind === 129 /* TypeLiteral */ || inAmbientContext; if (inAmbientContextOrInterface) { previousDeclaration = undefined; } - if (node.kind === 172 /* FunctionDeclaration */ || node.kind === 120 /* Method */ || node.kind === 121 /* Constructor */) { + if (node.kind === 174 /* FunctionDeclaration */ || node.kind === 120 /* Method */ || node.kind === 121 /* Constructor */) { var currentNodeFlags = getEffectiveDeclarationFlags(node, flagsToCheck); someNodeFlags |= currentNodeFlags; allNodeFlags &= currentNodeFlags; if (node.body && bodyDeclaration) { if (isConstructor) { - error(node, ts.Diagnostics.Multiple_constructor_implementations_are_not_allowed); + multipleConstructorImplementation = true; } else { - error(node, ts.Diagnostics.Duplicate_function_implementation); + duplicateFunctionDeclaration = true; } } else if (!isExportSymbolInsideModule && previousDeclaration && previousDeclaration.parent === node.parent && previousDeclaration.end !== node.pos) { @@ -13309,6 +14223,16 @@ var ts; } } } + if (multipleConstructorImplementation) { + ts.forEach(declarations, function (declaration) { + error(declaration, ts.Diagnostics.Multiple_constructor_implementations_are_not_allowed); + }); + } + if (duplicateFunctionDeclaration) { + ts.forEach(declarations, function (declaration) { + error(declaration.name, ts.Diagnostics.Duplicate_function_implementation); + }); + } if (!isExportSymbolInsideModule && lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body) { reportImplementationExpectedError(lastSeenNonAmbientDeclaration); } @@ -13364,14 +14288,14 @@ var ts; } function getDeclarationSpaces(d) { switch (d.kind) { - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: return 1048576 /* ExportType */; - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return d.name.kind === 7 /* StringLiteral */ || ts.isInstantiated(d) ? 2097152 /* ExportNamespace */ | 524288 /* ExportValue */ : 2097152 /* ExportNamespace */; - case 174 /* ClassDeclaration */: - case 176 /* EnumDeclaration */: + case 176 /* ClassDeclaration */: + case 178 /* EnumDeclaration */: return 1048576 /* ExportType */ | 524288 /* ExportValue */; - case 179 /* ImportDeclaration */: + case 181 /* ImportDeclaration */: var result = 0; var target = resolveImport(getSymbolOfNode(d)); ts.forEach(target.declarations, function (d) { @@ -13446,10 +14370,10 @@ var ts; return; } switch (current.kind) { - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: case 120 /* Method */: - case 142 /* ArrowFunction */: + case 144 /* ArrowFunction */: case 121 /* Constructor */: if (ts.hasRestParameters(current)) { error(node, ts.Diagnostics.Expression_resolves_to_variable_declaration_i_that_compiler_uses_to_initialize_rest_parameter); @@ -13501,7 +14425,7 @@ var ts; if (!needCollisionCheckForIdentifier(node, name, "_super")) { return; } - var enclosingClass = ts.getAncestor(node, 174 /* ClassDeclaration */); + var enclosingClass = ts.getAncestor(node, 176 /* ClassDeclaration */); if (!enclosingClass || ts.isInAmbientContext(enclosingClass)) { return; } @@ -13515,15 +14439,15 @@ var ts; } } } - function checkCollistionWithRequireExportsInGeneratedCode(node, name) { + function checkCollisionWithRequireExportsInGeneratedCode(node, name) { if (!needCollisionCheckForIdentifier(node, name, "require") && !needCollisionCheckForIdentifier(node, name, "exports")) { return; } - if (node.kind === 177 /* ModuleDeclaration */ && !ts.isInstantiated(node)) { + if (node.kind === 179 /* ModuleDeclaration */ && !ts.isInstantiated(node)) { return; } - var parent = node.kind === 171 /* VariableDeclaration */ ? node.parent.parent : node.parent; - if (parent.kind === 182 /* SourceFile */ && ts.isExternalModule(parent)) { + var parent = node.kind === 173 /* VariableDeclaration */ ? node.parent.parent : node.parent; + if (parent.kind === 184 /* SourceFile */ && ts.isExternalModule(parent)) { error(name, ts.Diagnostics.Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_an_external_module, name.text, name.text); } } @@ -13548,7 +14472,7 @@ var ts; } checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); - checkCollistionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); if (!useTypeFromValueDeclaration) { if (typeOfValueDeclaration !== unknownType && type !== unknownType && !isTypeIdenticalTo(typeOfValueDeclaration, type)) { error(node.name, ts.Diagnostics.Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2, ts.identifierToString(node.name), typeToString(typeOfValueDeclaration), typeToString(type)); @@ -13603,7 +14527,7 @@ var ts; } } var exprType = checkExpression(node.expression); - if (!isTypeAnyTypeObjectTypeOrTypeParameter(exprType) && exprType !== unknownType) { + if (!isStructuredType(exprType) && exprType !== unknownType) { error(node.expression, ts.Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } checkSourceElement(node.statement); @@ -13679,7 +14603,7 @@ var ts; errorNode = indexDeclaration; } else if (type.flags & 2048 /* Interface */) { - var someBaseClassHasBothPropertyAndIndexer = ts.forEach(type.baseTypes, function (base) { return getPropertyOfType(base, prop.name) && getIndexTypeOfType(base, indexKind); }); + var someBaseClassHasBothPropertyAndIndexer = ts.forEach(type.baseTypes, function (base) { return getPropertyOfObjectType(base, prop.name) && getIndexTypeOfType(base, indexKind); }); errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : type.symbol.declarations[0]; } if (errorNode && !isTypeAssignableTo(propertyType, indexType)) { @@ -13692,7 +14616,7 @@ var ts; var stringIndexType = getIndexTypeOfType(type, 0 /* String */); var numberIndexType = getIndexTypeOfType(type, 1 /* Number */); if (stringIndexType || numberIndexType) { - ts.forEach(getPropertiesOfType(type), function (prop) { + ts.forEach(getPropertiesOfObjectType(type), function (prop) { var propType = getTypeOfSymbol(prop); checkIndexConstraintForProperty(prop, propType, declaredStringIndexer, stringIndexType, 0 /* String */); checkIndexConstraintForProperty(prop, propType, declaredNumberIndexer, numberIndexType, 1 /* Number */); @@ -13739,7 +14663,7 @@ var ts; checkTypeNameIsReserved(node.name, ts.Diagnostics.Class_name_cannot_be_0); checkTypeParameters(node.typeParameters); checkCollisionWithCapturedThisVariable(node, node.name); - checkCollistionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); var type = getDeclaredTypeOfSymbol(symbol); @@ -13788,13 +14712,13 @@ var ts; return s.flags & 8388608 /* Instantiated */ ? getSymbolLinks(s).target : s; } function checkKindsOfPropertyMemberOverrides(type, baseType) { - var baseProperties = getPropertiesOfType(baseType); + var baseProperties = getPropertiesOfObjectType(baseType); for (var i = 0, len = baseProperties.length; i < len; ++i) { var base = getTargetSymbol(baseProperties[i]); if (base.flags & 67108864 /* Prototype */) { continue; } - var derived = getTargetSymbol(getPropertyOfType(type, base.name)); + var derived = getTargetSymbol(getPropertyOfObjectType(type, base.name)); if (derived) { var baseDeclarationFlags = getDeclarationFlagsFromSymbol(base); var derivedDeclarationFlags = getDeclarationFlagsFromSymbol(derived); @@ -13864,7 +14788,7 @@ var ts; checkTypeNameIsReserved(node.name, ts.Diagnostics.Interface_name_cannot_be_0); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); - var firstInterfaceDecl = getDeclarationOfKind(symbol, 175 /* InterfaceDeclaration */); + var firstInterfaceDecl = getDeclarationOfKind(symbol, 177 /* InterfaceDeclaration */); if (symbol.declarations.length > 1) { if (node !== firstInterfaceDecl && !areTypeParametersIdentical(firstInterfaceDecl.typeParameters, node.typeParameters)) { error(node.name, ts.Diagnostics.All_declarations_of_an_interface_must_have_identical_type_parameters); @@ -13886,9 +14810,9 @@ var ts; checkTypeForDuplicateIndexSignatures(node); } } - function getConstantValue(node) { + function getConstantValueForExpression(node) { var isNegative = false; - if (node.kind === 143 /* PrefixOperator */) { + if (node.kind === 145 /* PrefixOperator */) { var unaryExpression = node; if (unaryExpression.operator === 29 /* MinusToken */ || unaryExpression.operator === 28 /* PlusToken */) { node = unaryExpression.operand; @@ -13901,38 +14825,49 @@ var ts; } return undefined; } + function computeEnumMemberValues(node) { + var nodeLinks = getNodeLinks(node); + if (!(nodeLinks.flags & 128 /* EnumValuesComputed */)) { + var enumSymbol = getSymbolOfNode(node); + var enumType = getDeclaredTypeOfSymbol(enumSymbol); + var autoValue = 0; + var ambient = ts.isInAmbientContext(node); + ts.forEach(node.members, function (member) { + if (isNumericName(member.name.text)) { + error(member.name, ts.Diagnostics.An_enum_member_cannot_have_a_numeric_name); + } + var initializer = member.initializer; + if (initializer) { + autoValue = getConstantValueForExpression(initializer); + if (autoValue === undefined && !ambient) { + checkTypeAssignableTo(checkExpression(initializer), enumType, initializer, undefined, undefined); + } + } + else if (ambient) { + autoValue = undefined; + } + if (autoValue !== undefined) { + getNodeLinks(member).enumMemberValue = autoValue++; + } + }); + nodeLinks.flags |= 128 /* EnumValuesComputed */; + } + } function checkEnumDeclaration(node) { if (!fullTypeCheck) { return; } checkTypeNameIsReserved(node.name, ts.Diagnostics.Enum_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); - checkCollistionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); + computeEnumMemberValues(node); var enumSymbol = getSymbolOfNode(node); - var enumType = getDeclaredTypeOfSymbol(enumSymbol); - var autoValue = 0; - var ambient = ts.isInAmbientContext(node); - ts.forEach(node.members, function (member) { - var initializer = member.initializer; - if (initializer) { - autoValue = getConstantValue(initializer); - if (autoValue === undefined && !ambient) { - checkTypeAssignableTo(checkExpression(initializer), enumType, initializer, undefined, undefined); - } - } - else if (ambient) { - autoValue = undefined; - } - if (autoValue !== undefined) { - getNodeLinks(member).enumMemberValue = autoValue++; - } - }); var firstDeclaration = getDeclarationOfKind(enumSymbol, node.kind); if (node === firstDeclaration) { var seenEnumMissingInitialInitializer = false; ts.forEach(enumSymbol.declarations, function (declaration) { - if (declaration.kind !== 176 /* EnumDeclaration */) { + if (declaration.kind !== 178 /* EnumDeclaration */) { return false; } var enumDeclaration = declaration; @@ -13955,7 +14890,7 @@ var ts; var declarations = symbol.declarations; for (var i = 0; i < declarations.length; i++) { var declaration = declarations[i]; - if ((declaration.kind === 174 /* ClassDeclaration */ || (declaration.kind === 172 /* FunctionDeclaration */ && declaration.body)) && !ts.isInAmbientContext(declaration)) { + if ((declaration.kind === 176 /* ClassDeclaration */ || (declaration.kind === 174 /* FunctionDeclaration */ && declaration.body)) && !ts.isInAmbientContext(declaration)) { return declaration; } } @@ -13964,7 +14899,7 @@ var ts; function checkModuleDeclaration(node) { if (fullTypeCheck) { checkCollisionWithCapturedThisVariable(node, node.name); - checkCollistionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); if (symbol.flags & 128 /* ValueModule */ && symbol.declarations.length > 1 && !ts.isInAmbientContext(node)) { @@ -13997,7 +14932,7 @@ var ts; } function checkImportDeclaration(node) { checkCollisionWithCapturedThisVariable(node, node.name); - checkCollistionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); var symbol = getSymbolOfNode(node); var target; if (node.entityName) { @@ -14018,10 +14953,10 @@ var ts; } } else { - if (node.parent.kind === 182 /* SourceFile */) { + if (node.parent.kind === 184 /* SourceFile */) { target = resolveImport(symbol); } - else if (node.parent.kind === 178 /* ModuleBlock */ && node.parent.parent.name.kind === 7 /* StringLiteral */) { + else if (node.parent.kind === 180 /* ModuleBlock */ && node.parent.parent.name.kind === 7 /* StringLiteral */) { if (isExternalModuleNameRelative(node.externalModuleName.text)) { error(node, ts.Diagnostics.Import_declaration_in_an_ambient_external_module_declaration_cannot_reference_external_module_through_relative_external_module_name); target = unknownSymbol; @@ -14043,7 +14978,7 @@ var ts; } function checkExportAssignment(node) { var container = node.parent; - if (container.kind !== 182 /* SourceFile */) { + if (container.kind !== 184 /* SourceFile */) { container = container.parent; } checkTypeOfExportAssignmentSymbol(getSymbolOfNode(container)); @@ -14079,62 +15014,66 @@ var ts; return checkArrayType(node); case 131 /* TupleType */: return checkTupleType(node); - case 172 /* FunctionDeclaration */: + case 132 /* UnionType */: + return checkUnionType(node); + case 133 /* ParenType */: + return checkSourceElement(node.type); + case 174 /* FunctionDeclaration */: return checkFunctionDeclaration(node); - case 148 /* Block */: + case 150 /* Block */: return checkBlock(node); - case 173 /* FunctionBlock */: - case 178 /* ModuleBlock */: + case 175 /* FunctionBlock */: + case 180 /* ModuleBlock */: return checkBody(node); - case 149 /* VariableStatement */: + case 151 /* VariableStatement */: return checkVariableStatement(node); - case 151 /* ExpressionStatement */: + case 153 /* ExpressionStatement */: return checkExpressionStatement(node); - case 152 /* IfStatement */: + case 154 /* IfStatement */: return checkIfStatement(node); - case 153 /* DoStatement */: + case 155 /* DoStatement */: return checkDoStatement(node); - case 154 /* WhileStatement */: + case 156 /* WhileStatement */: return checkWhileStatement(node); - case 155 /* ForStatement */: + case 157 /* ForStatement */: return checkForStatement(node); - case 156 /* ForInStatement */: + case 158 /* ForInStatement */: return checkForInStatement(node); - case 157 /* ContinueStatement */: - case 158 /* BreakStatement */: + case 159 /* ContinueStatement */: + case 160 /* BreakStatement */: return checkBreakOrContinueStatement(node); - case 159 /* ReturnStatement */: + case 161 /* ReturnStatement */: return checkReturnStatement(node); - case 160 /* WithStatement */: + case 162 /* WithStatement */: return checkWithStatement(node); - case 161 /* SwitchStatement */: + case 163 /* SwitchStatement */: return checkSwitchStatement(node); - case 164 /* LabeledStatement */: + case 166 /* LabeledStatement */: return checkLabeledStatement(node); - case 165 /* ThrowStatement */: + case 167 /* ThrowStatement */: return checkThrowStatement(node); - case 166 /* TryStatement */: + case 168 /* TryStatement */: return checkTryStatement(node); - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: return ts.Debug.fail("Checker encountered variable declaration"); - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: return checkClassDeclaration(node); - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: return checkInterfaceDeclaration(node); - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: return checkEnumDeclaration(node); - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return checkModuleDeclaration(node); - case 179 /* ImportDeclaration */: + case 181 /* ImportDeclaration */: return checkImportDeclaration(node); - case 180 /* ExportAssignment */: + case 182 /* ExportAssignment */: return checkExportAssignment(node); } } function checkFunctionExpressionBodies(node) { switch (node.kind) { - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: ts.forEach(node.parameters, checkFunctionExpressionBodies); checkFunctionExpressionBody(node); break; @@ -14142,54 +15081,54 @@ var ts; case 121 /* Constructor */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: ts.forEach(node.parameters, checkFunctionExpressionBodies); break; - case 160 /* WithStatement */: + case 162 /* WithStatement */: checkFunctionExpressionBodies(node.expression); break; case 118 /* Parameter */: case 119 /* Property */: - case 132 /* ArrayLiteral */: - case 133 /* ObjectLiteral */: - case 134 /* PropertyAssignment */: - case 135 /* PropertyAccess */: - case 136 /* IndexedAccess */: - case 137 /* CallExpression */: - case 138 /* NewExpression */: - case 139 /* TypeAssertion */: - case 140 /* ParenExpression */: - case 143 /* PrefixOperator */: - case 144 /* PostfixOperator */: - case 145 /* BinaryExpression */: - case 146 /* ConditionalExpression */: - case 148 /* Block */: - case 173 /* FunctionBlock */: - case 178 /* ModuleBlock */: - case 149 /* VariableStatement */: - case 151 /* ExpressionStatement */: - case 152 /* IfStatement */: - case 153 /* DoStatement */: - case 154 /* WhileStatement */: - case 155 /* ForStatement */: - case 156 /* ForInStatement */: - case 157 /* ContinueStatement */: - case 158 /* BreakStatement */: - case 159 /* ReturnStatement */: - case 161 /* SwitchStatement */: - case 162 /* CaseClause */: - case 163 /* DefaultClause */: - case 164 /* LabeledStatement */: - case 165 /* ThrowStatement */: - case 166 /* TryStatement */: - case 167 /* TryBlock */: - case 168 /* CatchBlock */: - case 169 /* FinallyBlock */: - case 171 /* VariableDeclaration */: - case 174 /* ClassDeclaration */: - case 176 /* EnumDeclaration */: - case 181 /* EnumMember */: - case 182 /* SourceFile */: + case 134 /* ArrayLiteral */: + case 135 /* ObjectLiteral */: + case 136 /* PropertyAssignment */: + case 137 /* PropertyAccess */: + case 138 /* IndexedAccess */: + case 139 /* CallExpression */: + case 140 /* NewExpression */: + case 141 /* TypeAssertion */: + case 142 /* ParenExpression */: + case 145 /* PrefixOperator */: + case 146 /* PostfixOperator */: + case 147 /* BinaryExpression */: + case 148 /* ConditionalExpression */: + case 150 /* Block */: + case 175 /* FunctionBlock */: + case 180 /* ModuleBlock */: + case 151 /* VariableStatement */: + case 153 /* ExpressionStatement */: + case 154 /* IfStatement */: + case 155 /* DoStatement */: + case 156 /* WhileStatement */: + case 157 /* ForStatement */: + case 158 /* ForInStatement */: + case 159 /* ContinueStatement */: + case 160 /* BreakStatement */: + case 161 /* ReturnStatement */: + case 163 /* SwitchStatement */: + case 164 /* CaseClause */: + case 165 /* DefaultClause */: + case 166 /* LabeledStatement */: + case 167 /* ThrowStatement */: + case 168 /* TryStatement */: + case 169 /* TryBlock */: + case 170 /* CatchBlock */: + case 171 /* FinallyBlock */: + case 173 /* VariableDeclaration */: + case 176 /* ClassDeclaration */: + case 178 /* EnumDeclaration */: + case 183 /* EnumMember */: + case 184 /* SourceFile */: ts.forEachChild(node, checkFunctionExpressionBodies); break; } @@ -14260,7 +15199,7 @@ var ts; function isInsideWithStatementBody(node) { if (node) { while (node.parent) { - if (node.parent.kind === 160 /* WithStatement */ && node.parent.statement === node) { + if (node.parent.kind === 162 /* WithStatement */ && node.parent.statement === node) { return true; } node = node.parent; @@ -14296,27 +15235,27 @@ var ts; copySymbols(location.locals, meaning); } switch (location.kind) { - case 182 /* SourceFile */: + case 184 /* SourceFile */: if (!ts.isExternalModule(location)) break; - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: copySymbols(getSymbolOfNode(location).exports, meaning & ts.SymbolFlags.ModuleMember); break; - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: copySymbols(getSymbolOfNode(location).exports, meaning & 4 /* EnumMember */); break; - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: if (!(memberFlags & 128 /* Static */)) { copySymbols(getSymbolOfNode(location).members, meaning & ts.SymbolFlags.Type); } break; - case 141 /* FunctionExpression */: + case 143 /* FunctionExpression */: if (location.name) { copySymbol(location.symbol, meaning); } break; - case 168 /* CatchBlock */: + case 170 /* CatchBlock */: if (location.variable.text) { copySymbol(location.symbol, meaning); } @@ -14334,9 +15273,9 @@ var ts; function isTypeDeclaration(node) { switch (node.kind) { case 117 /* TypeParameter */: - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 176 /* EnumDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: return true; } } @@ -14354,21 +15293,21 @@ var ts; case 89 /* TrueKeyword */: case 74 /* FalseKeyword */: case 8 /* RegularExpressionLiteral */: - case 132 /* ArrayLiteral */: - case 133 /* ObjectLiteral */: - case 135 /* PropertyAccess */: - case 136 /* IndexedAccess */: - case 137 /* CallExpression */: - case 138 /* NewExpression */: - case 139 /* TypeAssertion */: - case 140 /* ParenExpression */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: - case 143 /* PrefixOperator */: - case 144 /* PostfixOperator */: - case 145 /* BinaryExpression */: - case 146 /* ConditionalExpression */: - case 147 /* OmittedExpression */: + case 134 /* ArrayLiteral */: + case 135 /* ObjectLiteral */: + case 137 /* PropertyAccess */: + case 138 /* IndexedAccess */: + case 139 /* CallExpression */: + case 140 /* NewExpression */: + case 141 /* TypeAssertion */: + case 142 /* ParenExpression */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: + case 145 /* PrefixOperator */: + case 146 /* PostfixOperator */: + case 147 /* BinaryExpression */: + case 148 /* ConditionalExpression */: + case 149 /* OmittedExpression */: return true; case 116 /* QualifiedName */: while (node.parent.kind === 116 /* QualifiedName */) @@ -14382,28 +15321,28 @@ var ts; case 7 /* StringLiteral */: var parent = node.parent; switch (parent.kind) { - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: case 118 /* Parameter */: case 119 /* Property */: - case 181 /* EnumMember */: - case 134 /* PropertyAssignment */: + case 183 /* EnumMember */: + case 136 /* PropertyAssignment */: return parent.initializer === node; - case 151 /* ExpressionStatement */: - case 152 /* IfStatement */: - case 153 /* DoStatement */: - case 154 /* WhileStatement */: - case 159 /* ReturnStatement */: - case 160 /* WithStatement */: - case 161 /* SwitchStatement */: - case 162 /* CaseClause */: - case 165 /* ThrowStatement */: - case 161 /* SwitchStatement */: + case 153 /* ExpressionStatement */: + case 154 /* IfStatement */: + case 155 /* DoStatement */: + case 156 /* WhileStatement */: + case 161 /* ReturnStatement */: + case 162 /* WithStatement */: + case 163 /* SwitchStatement */: + case 164 /* CaseClause */: + case 167 /* ThrowStatement */: + case 163 /* SwitchStatement */: return parent.expression === node; - case 155 /* ForStatement */: + case 157 /* ForStatement */: return parent.initializer === node || parent.condition === node || parent.iterator === node; - case 156 /* ForInStatement */: + case 158 /* ForInStatement */: return parent.variable === node || parent.expression === node; - case 139 /* TypeAssertion */: + case 141 /* TypeAssertion */: return node === parent.operand; default: if (isExpression(parent)) { @@ -14414,7 +15353,7 @@ var ts; return false; } function isTypeNode(node) { - if (node.kind >= ts.SyntaxKind.FirstTypeNode && node.kind <= ts.SyntaxKind.LastTypeNode) { + if (ts.SyntaxKind.FirstTypeNode <= node.kind && node.kind <= ts.SyntaxKind.LastTypeNode) { return true; } switch (node.kind) { @@ -14424,7 +15363,7 @@ var ts; case 106 /* BooleanKeyword */: return true; case 93 /* VoidKeyword */: - return node.parent.kind !== 143 /* PrefixOperator */; + return node.parent.kind !== 145 /* PrefixOperator */; case 7 /* StringLiteral */: return node.parent.kind === 118 /* Parameter */; case 59 /* Identifier */: @@ -14432,11 +15371,12 @@ var ts; node = node.parent; } case 116 /* QualifiedName */: + ts.Debug.assert(node.kind === 59 /* Identifier */ || node.kind === 116 /* QualifiedName */, "'node' was expected to be a qualified name or identifier in 'isTypeNode'."); var parent = node.parent; if (parent.kind === 128 /* TypeQuery */) { return false; } - if (parent.kind >= ts.SyntaxKind.FirstTypeNode && parent.kind <= ts.SyntaxKind.LastTypeNode) { + if (ts.SyntaxKind.FirstTypeNode <= parent.kind && parent.kind <= ts.SyntaxKind.LastTypeNode) { return true; } switch (parent.kind) { @@ -14444,11 +15384,11 @@ var ts; return node === parent.constraint; case 119 /* Property */: case 118 /* Parameter */: - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: return node === parent.type; - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: case 121 /* Constructor */: case 120 /* Method */: case 122 /* GetAccessor */: @@ -14458,11 +15398,11 @@ var ts; case 125 /* ConstructSignature */: case 126 /* IndexSignature */: return node === parent.type; - case 139 /* TypeAssertion */: + case 141 /* TypeAssertion */: return node === parent.type; - case 137 /* CallExpression */: - case 138 /* NewExpression */: - return parent.typeArguments.indexOf(node) >= 0; + case 139 /* CallExpression */: + case 140 /* NewExpression */: + return parent.typeArguments && parent.typeArguments.indexOf(node) >= 0; } } return false; @@ -14471,22 +15411,22 @@ var ts; while (node.parent.kind === 116 /* QualifiedName */) { node = node.parent; } - if (node.parent.kind === 179 /* ImportDeclaration */) { + if (node.parent.kind === 181 /* ImportDeclaration */) { return node.parent.entityName === node; } - if (node.parent.kind === 180 /* ExportAssignment */) { + if (node.parent.kind === 182 /* ExportAssignment */) { return node.parent.exportName === node; } return false; } function isRightSideOfQualifiedNameOrPropertyAccess(node) { - return (node.parent.kind === 116 /* QualifiedName */ || node.parent.kind === 135 /* PropertyAccess */) && node.parent.right === node; + return (node.parent.kind === 116 /* QualifiedName */ || node.parent.kind === 137 /* PropertyAccess */) && node.parent.right === node; } function getSymbolOfEntityName(entityName) { if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(entityName)) { return getSymbolOfNode(entityName.parent); } - if (entityName.parent.kind === 180 /* ExportAssignment */) { + if (entityName.parent.kind === 182 /* ExportAssignment */) { return resolveEntityName(entityName.parent.parent, entityName, ts.SymbolFlags.Value | ts.SymbolFlags.Type | ts.SymbolFlags.Namespace | 4194304 /* Import */); } if (isInRightSideOfImportOrExportAssignment(entityName)) { @@ -14500,7 +15440,7 @@ var ts; var meaning = ts.SymbolFlags.Value | 4194304 /* Import */; return resolveEntityName(entityName, entityName, meaning); } - else if (entityName.kind === 116 /* QualifiedName */ || entityName.kind === 135 /* PropertyAccess */) { + else if (entityName.kind === 116 /* QualifiedName */ || entityName.kind === 137 /* PropertyAccess */) { var symbol = getNodeLinks(entityName).resolvedSymbol; if (!symbol) { checkPropertyAccess(entityName); @@ -14526,11 +15466,11 @@ var ts; return getSymbolOfNode(node.parent); } if (node.kind === 59 /* Identifier */ && isInRightSideOfImportOrExportAssignment(node)) { - return node.parent.kind === 180 /* ExportAssignment */ ? getSymbolOfEntityName(node) : getSymbolOfPartOfRightHandSideOfImport(node); + return node.parent.kind === 182 /* ExportAssignment */ ? getSymbolOfEntityName(node) : getSymbolOfPartOfRightHandSideOfImport(node); } switch (node.kind) { case 59 /* Identifier */: - case 135 /* PropertyAccess */: + case 137 /* PropertyAccess */: case 116 /* QualifiedName */: return getSymbolOfEntityName(node); case 87 /* ThisKeyword */: @@ -14544,20 +15484,20 @@ var ts; } return undefined; case 7 /* StringLiteral */: - if (node.parent.kind === 179 /* ImportDeclaration */ && node.parent.externalModuleName === node) { + if (node.parent.kind === 181 /* ImportDeclaration */ && node.parent.externalModuleName === node) { var importSymbol = getSymbolOfNode(node.parent); var moduleType = getTypeOfSymbol(importSymbol); return moduleType ? moduleType.symbol : undefined; } case 6 /* NumericLiteral */: - if (node.parent.kind == 136 /* IndexedAccess */ && node.parent.index === node) { + if (node.parent.kind == 138 /* IndexedAccess */ && node.parent.index === node) { var objectType = checkExpression(node.parent.object); if (objectType === unknownType) return undefined; var apparentType = getApparentType(objectType); if (apparentType === unknownType) return undefined; - return getPropertyOfApparentType(apparentType, node.text); + return getPropertyOfType(apparentType, node.text); } break; } @@ -14602,41 +15542,37 @@ var ts; } return checkExpression(expr); } - function getAugmentedPropertiesOfApparentType(type) { - var apparentType = getApparentType(type); - if (apparentType.flags & ts.TypeFlags.ObjectType) { - var propertiesByName = {}; - var results = []; - ts.forEach(getPropertiesOfType(apparentType), function (s) { - propertiesByName[s.name] = s; - results.push(s); - }); - var resolved = resolveObjectTypeMembers(type); - ts.forEachValue(resolved.members, function (s) { - if (symbolIsValue(s) && !propertiesByName[s.name]) { - propertiesByName[s.name] = s; - results.push(s); + function getAugmentedPropertiesOfType(type) { + var type = getApparentType(type); + var propsByName = createSymbolTable(getPropertiesOfType(type)); + if (getSignaturesOfType(type, 0 /* Call */).length || getSignaturesOfType(type, 1 /* Construct */).length) { + ts.forEach(getPropertiesOfType(globalFunctionType), function (p) { + if (!ts.hasProperty(propsByName, p.name)) { + propsByName[p.name] = p; } }); - if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { - ts.forEach(getPropertiesOfType(globalFunctionType), function (s) { - if (!propertiesByName[s.name]) { - propertiesByName[s.name] = s; - results.push(s); - } - }); - } - return results; - } - else { - return getPropertiesOfType(apparentType); } + return getNamedMembers(propsByName); } - function getRootSymbol(symbol) { - return ((symbol.flags & 33554432 /* Transient */) && getSymbolLinks(symbol).target) || symbol; + function getRootSymbols(symbol) { + if (symbol.flags & 134217728 /* UnionProperty */) { + var symbols = []; + var name = symbol.name; + ts.forEach(getSymbolLinks(symbol).unionType.types, function (t) { + symbols.push(getPropertyOfType(t, name)); + }); + return symbols; + } + else if (symbol.flags & 33554432 /* Transient */) { + var target = getSymbolLinks(symbol).target; + if (target) { + return [target]; + } + } + return [symbol]; } function isExternalModuleSymbol(symbol) { - return symbol.flags & 128 /* ValueModule */ && symbol.declarations.length === 1 && symbol.declarations[0].kind === 182 /* SourceFile */; + return symbol.flags & 128 /* ValueModule */ && symbol.declarations.length === 1 && symbol.declarations[0].kind === 184 /* SourceFile */; } function isNodeDescendentOf(node, ancestor) { while (node) { @@ -14662,14 +15598,14 @@ var ts; while (!isUniqueLocalName(ts.escapeIdentifier(prefix + name), container)) { prefix += "_"; } - links.localModuleName = prefix + ts.getSourceTextOfNode(container.name); + links.localModuleName = prefix + ts.getTextOfNode(container.name); } return links.localModuleName; } function getLocalNameForSymbol(symbol, location) { var node = location; while (node) { - if ((node.kind === 177 /* ModuleDeclaration */ || node.kind === 176 /* EnumDeclaration */) && getSymbolOfNode(node) === symbol) { + if ((node.kind === 179 /* ModuleDeclaration */ || node.kind === 178 /* EnumDeclaration */) && getSymbolOfNode(node) === symbol) { return getLocalNameOfContainer(node); } node = node.parent; @@ -14688,22 +15624,12 @@ var ts; } } } - function getPropertyAccessSubstitution(node) { - var symbol = getNodeLinks(node).resolvedSymbol; - if (symbol && (symbol.flags & 4 /* EnumMember */)) { - var declaration = symbol.valueDeclaration; - var constantValue; - if (declaration.kind === 181 /* EnumMember */ && (constantValue = getNodeLinks(declaration).enumMemberValue) !== undefined) { - return constantValue.toString() + " /* " + ts.identifierToString(declaration.name) + " */"; - } - } - } function getExportAssignmentName(node) { var symbol = getExportAssignmentSymbol(getSymbolOfNode(node)); return symbol && symbolIsValue(symbol) ? symbolToString(symbol) : undefined; } function isTopLevelValueImportedViaEntityName(node) { - if (node.parent.kind !== 182 /* SourceFile */ || !node.entityName) { + if (node.parent.kind !== 184 /* SourceFile */ || !node.entityName) { return false; } var symbol = getSymbolOfNode(node); @@ -14738,23 +15664,34 @@ var ts; return getNodeLinks(node).flags; } function getEnumMemberValue(node) { + computeEnumMemberValues(node.parent); return getNodeLinks(node).enumMemberValue; } + function getConstantValue(node) { + var symbol = getNodeLinks(node).resolvedSymbol; + if (symbol && (symbol.flags & 4 /* EnumMember */)) { + var declaration = symbol.valueDeclaration; + var constantValue; + if (declaration.kind === 183 /* EnumMember */ && (constantValue = getNodeLinks(declaration).enumMemberValue) !== undefined) { + return constantValue; + } + } + return undefined; + } function writeTypeAtLocation(location, enclosingDeclaration, flags, writer) { var symbol = getSymbolOfNode(location); var type = symbol && !(symbol.flags & 512 /* TypeLiteral */) ? getTypeOfSymbol(symbol) : getTypeFromTypeNode(location); - writeTypeToTextWriter(type, enclosingDeclaration, flags, writer); + getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); } function writeReturnTypeOfSignatureDeclaration(signatureDeclaration, enclosingDeclaration, flags, writer) { var signature = getSignatureFromDeclaration(signatureDeclaration); - writeTypeToTextWriter(getReturnTypeOfSignature(signature), enclosingDeclaration, flags, writer); + getSymbolDisplayBuilder().buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags); } function invokeEmitter(targetSourceFile) { var resolver = { getProgram: function () { return program; }, getLocalNameOfContainer: getLocalNameOfContainer, getExpressionNamePrefix: getExpressionNamePrefix, - getPropertyAccessSubstitution: getPropertyAccessSubstitution, getExportAssignmentName: getExportAssignmentName, isReferencedImportDeclaration: isReferencedImportDeclaration, getNodeCheckFlags: getNodeCheckFlags, @@ -14765,9 +15702,9 @@ var ts; isImplementationOfOverload: isImplementationOfOverload, writeTypeAtLocation: writeTypeAtLocation, writeReturnTypeOfSignatureDeclaration: writeReturnTypeOfSignatureDeclaration, - writeSymbol: writeSymbolToTextWriter, isSymbolAccessible: isSymbolAccessible, - isImportDeclarationEntityNameReferenceDeclarationVisibile: isImportDeclarationEntityNameReferenceDeclarationVisibile + isImportDeclarationEntityNameReferenceDeclarationVisibile: isImportDeclarationEntityNameReferenceDeclarationVisibile, + getConstantValue: getConstantValue }; checkProgram(); return ts.emitFiles(resolver, targetSourceFile); @@ -15024,7 +15961,7 @@ var ts; })(ts || (ts = {})); var ts; (function (ts) { - var version = "1.1.0.0"; + var version = "1.3.0.0"; function validateLocaleAndSetLanguage(locale, errors) { var matchResult = /^([a-z]+)([_\-]([a-z]+))?$/.exec(locale.toLowerCase()); if (!matchResult) { @@ -15123,13 +16060,14 @@ var ts; function getCanonicalFileName(fileName) { return sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(); } + var unsupportedFileEncodingErrorCode = -2147024809; function getSourceFile(filename, languageVersion, onError) { try { var text = sys.readFile(filename, options.charset); } catch (e) { if (onError) { - onError(e.message); + onError(e.number === unsupportedFileEncodingErrorCode ? getDiagnosticText(ts.Diagnostics.Unsupported_file_encoding) : e.message); } text = ""; } @@ -15326,7 +16264,7 @@ var ts; output += sys.newLine + sys.newLine; var padding = makePadding(marginLength); output += getDiagnosticText(ts.Diagnostics.Examples_Colon_0, makePadding(marginLength - examplesLength) + "tsc hello.ts") + sys.newLine; - output += padding + "tsc --out foo.js foo.ts" + sys.newLine; + output += padding + "tsc --out file.js file.ts" + sys.newLine; output += padding + "tsc @args.txt" + sys.newLine; output += sys.newLine; output += getDiagnosticText(ts.Diagnostics.Options_Colon) + sys.newLine; diff --git a/bin/typescriptServices.js b/bin/typescriptServices.js index 38f2d4e1ecf..6bd9677a26a 100644 --- a/bin/typescriptServices.js +++ b/bin/typescriptServices.js @@ -19,6 +19,7 @@ var ts; Unterminated_string_literal: { code: 1002, category: 1 /* Error */, key: "Unterminated string literal." }, Identifier_expected: { code: 1003, category: 1 /* Error */, key: "Identifier expected." }, _0_expected: { code: 1005, category: 1 /* Error */, key: "'{0}' expected." }, + A_file_cannot_have_a_reference_to_itself: { code: 1006, category: 1 /* Error */, key: "A file cannot have a reference to itself." }, Trailing_comma_not_allowed: { code: 1009, category: 1 /* Error */, key: "Trailing comma not allowed." }, Asterisk_Slash_expected: { code: 1010, category: 1 /* Error */, key: "'*/' expected." }, Unexpected_token: { code: 1012, category: 1 /* Error */, key: "Unexpected token." }, @@ -127,6 +128,7 @@ var ts; Cannot_compile_external_modules_unless_the_module_flag_is_provided: { code: 1148, category: 1 /* Error */, key: "Cannot compile external modules unless the '--module' flag is provided." }, Filename_0_differs_from_already_included_filename_1_only_in_casing: { code: 1149, category: 1 /* Error */, key: "Filename '{0}' differs from already included filename '{1}' only in casing" }, new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: 1 /* Error */, key: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, + An_enum_member_cannot_have_a_numeric_name: { code: 1151, category: 1 /* Error */, key: "An enum member cannot have a numeric name." }, Duplicate_identifier_0: { code: 2300, category: 1 /* Error */, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: 1 /* Error */, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: 1 /* Error */, key: "Static members cannot reference class type parameters." }, @@ -193,8 +195,6 @@ var ts; The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type: { code: 2363, category: 1 /* Error */, key: "The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type." }, Invalid_left_hand_side_of_assignment_expression: { code: 2364, category: 1 /* Error */, key: "Invalid left-hand side of assignment expression." }, Operator_0_cannot_be_applied_to_types_1_and_2: { code: 2365, category: 1 /* Error */, key: "Operator '{0}' cannot be applied to types '{1}' and '{2}'." }, - No_best_common_type_exists_between_0_1_and_2: { code: 2366, category: 1 /* Error */, key: "No best common type exists between '{0}', '{1}', and '{2}'." }, - No_best_common_type_exists_between_0_and_1: { code: 2367, category: 1 /* Error */, key: "No best common type exists between '{0}' and '{1}'." }, Type_parameter_name_cannot_be_0: { code: 2368, category: 1 /* Error */, key: "Type parameter name cannot be '{0}'" }, A_parameter_property_is_only_allowed_in_a_constructor_implementation: { code: 2369, category: 1 /* Error */, key: "A parameter property is only allowed in a constructor implementation." }, A_rest_parameter_must_be_of_an_array_type: { code: 2370, category: 1 /* Error */, key: "A rest parameter must be of an array type." }, @@ -274,6 +274,7 @@ var ts; Property_0_is_protected_in_type_1_but_public_in_type_2: { code: 2444, category: 1 /* Error */, key: "Property '{0}' is protected in type '{1}' but public in type '{2}'." }, Property_0_is_protected_and_only_accessible_within_class_1_and_its_subclasses: { code: 2445, category: 1 /* Error */, key: "Property '{0}' is protected and only accessible within class '{1}' and its subclasses." }, Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1: { code: 2446, category: 1 /* Error */, key: "Property '{0}' is protected and only accessible through an instance of class '{1}'." }, + The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead: { code: 2447, category: 1 /* Error */, key: "The '{0}' operator is not allowed for boolean types. Consider using '{1}' instead." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: 1 /* Error */, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4001, category: 1 /* Error */, key: "Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: 1 /* Error */, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, @@ -526,10 +527,10 @@ var ts; "|=": 57 /* BarEqualsToken */, "^=": 58 /* CaretEqualsToken */ }; - var unicodeES3IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1610, 1649, 1747, 1749, 1749, 1765, 1766, 1786, 1788, 1808, 1808, 1810, 1836, 1920, 1957, 2309, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2784, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3294, 3294, 3296, 3297, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3424, 3425, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3805, 3840, 3840, 3904, 3911, 3913, 3946, 3976, 3979, 4096, 4129, 4131, 4135, 4137, 4138, 4176, 4181, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6067, 6176, 6263, 6272, 6312, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8319, 8319, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12346, 12353, 12436, 12445, 12446, 12449, 12538, 12540, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65138, 65140, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, ]; - var unicodeES3IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 768, 846, 864, 866, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1155, 1158, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1441, 1443, 1465, 1467, 1469, 1471, 1471, 1473, 1474, 1476, 1476, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1621, 1632, 1641, 1648, 1747, 1749, 1756, 1759, 1768, 1770, 1773, 1776, 1788, 1808, 1836, 1840, 1866, 1920, 1968, 2305, 2307, 2309, 2361, 2364, 2381, 2384, 2388, 2392, 2403, 2406, 2415, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2492, 2494, 2500, 2503, 2504, 2507, 2509, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2562, 2562, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2649, 2652, 2654, 2654, 2662, 2676, 2689, 2691, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2784, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2876, 2883, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2913, 2918, 2927, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3031, 3031, 3047, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3134, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3168, 3169, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3262, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3297, 3302, 3311, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3390, 3395, 3398, 3400, 3402, 3405, 3415, 3415, 3424, 3425, 3430, 3439, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3805, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3946, 3953, 3972, 3974, 3979, 3984, 3991, 3993, 4028, 4038, 4038, 4096, 4129, 4131, 4135, 4137, 4138, 4140, 4146, 4150, 4153, 4160, 4169, 4176, 4185, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 4969, 4977, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6099, 6112, 6121, 6160, 6169, 6176, 6263, 6272, 6313, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8255, 8256, 8319, 8319, 8400, 8412, 8417, 8417, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12346, 12353, 12436, 12441, 12442, 12445, 12446, 12449, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65056, 65059, 65075, 65076, 65101, 65103, 65136, 65138, 65140, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65381, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, ]; - var unicodeES5IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 880, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1568, 1610, 1646, 1647, 1649, 1747, 1749, 1749, 1765, 1766, 1774, 1775, 1786, 1788, 1791, 1791, 1808, 1808, 1810, 1839, 1869, 1957, 1969, 1969, 1994, 2026, 2036, 2037, 2042, 2042, 2048, 2069, 2074, 2074, 2084, 2084, 2088, 2088, 2112, 2136, 2208, 2208, 2210, 2220, 2308, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2417, 2423, 2425, 2431, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2493, 2493, 2510, 2510, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2785, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2929, 2929, 2947, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3024, 3024, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3133, 3160, 3161, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3261, 3261, 3294, 3294, 3296, 3297, 3313, 3314, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3389, 3406, 3406, 3424, 3425, 3450, 3455, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3807, 3840, 3840, 3904, 3911, 3913, 3948, 3976, 3980, 4096, 4138, 4159, 4159, 4176, 4181, 4186, 4189, 4193, 4193, 4197, 4198, 4206, 4208, 4213, 4225, 4238, 4238, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5905, 5920, 5937, 5952, 5969, 5984, 5996, 5998, 6000, 6016, 6067, 6103, 6103, 6108, 6108, 6176, 6263, 6272, 6312, 6314, 6314, 6320, 6389, 6400, 6428, 6480, 6509, 6512, 6516, 6528, 6571, 6593, 6599, 6656, 6678, 6688, 6740, 6823, 6823, 6917, 6963, 6981, 6987, 7043, 7072, 7086, 7087, 7098, 7141, 7168, 7203, 7245, 7247, 7258, 7293, 7401, 7404, 7406, 7409, 7413, 7414, 7424, 7615, 7680, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8305, 8305, 8319, 8319, 8336, 8348, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11502, 11506, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11648, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11823, 11823, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12348, 12353, 12438, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42527, 42538, 42539, 42560, 42606, 42623, 42647, 42656, 42735, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43009, 43011, 43013, 43015, 43018, 43020, 43042, 43072, 43123, 43138, 43187, 43250, 43255, 43259, 43259, 43274, 43301, 43312, 43334, 43360, 43388, 43396, 43442, 43471, 43471, 43520, 43560, 43584, 43586, 43588, 43595, 43616, 43638, 43642, 43642, 43648, 43695, 43697, 43697, 43701, 43702, 43705, 43709, 43712, 43712, 43714, 43714, 43739, 43741, 43744, 43754, 43762, 43764, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44002, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, ]; - var unicodeES5IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 768, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1155, 1159, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1469, 1471, 1471, 1473, 1474, 1476, 1477, 1479, 1479, 1488, 1514, 1520, 1522, 1552, 1562, 1568, 1641, 1646, 1747, 1749, 1756, 1759, 1768, 1770, 1788, 1791, 1791, 1808, 1866, 1869, 1969, 1984, 2037, 2042, 2042, 2048, 2093, 2112, 2139, 2208, 2208, 2210, 2220, 2276, 2302, 2304, 2403, 2406, 2415, 2417, 2423, 2425, 2431, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2500, 2503, 2504, 2507, 2510, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2561, 2563, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2641, 2641, 2649, 2652, 2654, 2654, 2662, 2677, 2689, 2691, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2787, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2876, 2884, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2915, 2918, 2927, 2929, 2929, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3024, 3024, 3031, 3031, 3046, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3160, 3161, 3168, 3171, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3260, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3299, 3302, 3311, 3313, 3314, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3396, 3398, 3400, 3402, 3406, 3415, 3415, 3424, 3427, 3430, 3439, 3450, 3455, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3807, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3948, 3953, 3972, 3974, 3991, 3993, 4028, 4038, 4038, 4096, 4169, 4176, 4253, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4957, 4959, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5908, 5920, 5940, 5952, 5971, 5984, 5996, 5998, 6000, 6002, 6003, 6016, 6099, 6103, 6103, 6108, 6109, 6112, 6121, 6155, 6157, 6160, 6169, 6176, 6263, 6272, 6314, 6320, 6389, 6400, 6428, 6432, 6443, 6448, 6459, 6470, 6509, 6512, 6516, 6528, 6571, 6576, 6601, 6608, 6617, 6656, 6683, 6688, 6750, 6752, 6780, 6783, 6793, 6800, 6809, 6823, 6823, 6912, 6987, 6992, 7001, 7019, 7027, 7040, 7155, 7168, 7223, 7232, 7241, 7245, 7293, 7376, 7378, 7380, 7414, 7424, 7654, 7676, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8204, 8205, 8255, 8256, 8276, 8276, 8305, 8305, 8319, 8319, 8336, 8348, 8400, 8412, 8417, 8417, 8421, 8432, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11647, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11744, 11775, 11823, 11823, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12348, 12353, 12438, 12441, 12442, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42539, 42560, 42607, 42612, 42621, 42623, 42647, 42655, 42737, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43047, 43072, 43123, 43136, 43204, 43216, 43225, 43232, 43255, 43259, 43259, 43264, 43309, 43312, 43347, 43360, 43388, 43392, 43456, 43471, 43481, 43520, 43574, 43584, 43597, 43600, 43609, 43616, 43638, 43642, 43643, 43648, 43714, 43739, 43741, 43744, 43759, 43762, 43766, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44010, 44012, 44013, 44016, 44025, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65024, 65039, 65056, 65062, 65075, 65076, 65101, 65103, 65136, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, ]; + var unicodeES3IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1610, 1649, 1747, 1749, 1749, 1765, 1766, 1786, 1788, 1808, 1808, 1810, 1836, 1920, 1957, 2309, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2784, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3294, 3294, 3296, 3297, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3424, 3425, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3805, 3840, 3840, 3904, 3911, 3913, 3946, 3976, 3979, 4096, 4129, 4131, 4135, 4137, 4138, 4176, 4181, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6067, 6176, 6263, 6272, 6312, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8319, 8319, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12346, 12353, 12436, 12445, 12446, 12449, 12538, 12540, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65138, 65140, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,]; + var unicodeES3IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 768, 846, 864, 866, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1155, 1158, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1441, 1443, 1465, 1467, 1469, 1471, 1471, 1473, 1474, 1476, 1476, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1621, 1632, 1641, 1648, 1747, 1749, 1756, 1759, 1768, 1770, 1773, 1776, 1788, 1808, 1836, 1840, 1866, 1920, 1968, 2305, 2307, 2309, 2361, 2364, 2381, 2384, 2388, 2392, 2403, 2406, 2415, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2492, 2494, 2500, 2503, 2504, 2507, 2509, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2562, 2562, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2649, 2652, 2654, 2654, 2662, 2676, 2689, 2691, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2784, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2876, 2883, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2913, 2918, 2927, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3031, 3031, 3047, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3134, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3168, 3169, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3262, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3297, 3302, 3311, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3390, 3395, 3398, 3400, 3402, 3405, 3415, 3415, 3424, 3425, 3430, 3439, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3805, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3946, 3953, 3972, 3974, 3979, 3984, 3991, 3993, 4028, 4038, 4038, 4096, 4129, 4131, 4135, 4137, 4138, 4140, 4146, 4150, 4153, 4160, 4169, 4176, 4185, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 4969, 4977, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6099, 6112, 6121, 6160, 6169, 6176, 6263, 6272, 6313, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8255, 8256, 8319, 8319, 8400, 8412, 8417, 8417, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12346, 12353, 12436, 12441, 12442, 12445, 12446, 12449, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65056, 65059, 65075, 65076, 65101, 65103, 65136, 65138, 65140, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65381, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,]; + var unicodeES5IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 880, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1568, 1610, 1646, 1647, 1649, 1747, 1749, 1749, 1765, 1766, 1774, 1775, 1786, 1788, 1791, 1791, 1808, 1808, 1810, 1839, 1869, 1957, 1969, 1969, 1994, 2026, 2036, 2037, 2042, 2042, 2048, 2069, 2074, 2074, 2084, 2084, 2088, 2088, 2112, 2136, 2208, 2208, 2210, 2220, 2308, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2417, 2423, 2425, 2431, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2493, 2493, 2510, 2510, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2785, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2929, 2929, 2947, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3024, 3024, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3133, 3160, 3161, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3261, 3261, 3294, 3294, 3296, 3297, 3313, 3314, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3389, 3406, 3406, 3424, 3425, 3450, 3455, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3807, 3840, 3840, 3904, 3911, 3913, 3948, 3976, 3980, 4096, 4138, 4159, 4159, 4176, 4181, 4186, 4189, 4193, 4193, 4197, 4198, 4206, 4208, 4213, 4225, 4238, 4238, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5905, 5920, 5937, 5952, 5969, 5984, 5996, 5998, 6000, 6016, 6067, 6103, 6103, 6108, 6108, 6176, 6263, 6272, 6312, 6314, 6314, 6320, 6389, 6400, 6428, 6480, 6509, 6512, 6516, 6528, 6571, 6593, 6599, 6656, 6678, 6688, 6740, 6823, 6823, 6917, 6963, 6981, 6987, 7043, 7072, 7086, 7087, 7098, 7141, 7168, 7203, 7245, 7247, 7258, 7293, 7401, 7404, 7406, 7409, 7413, 7414, 7424, 7615, 7680, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8305, 8305, 8319, 8319, 8336, 8348, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11502, 11506, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11648, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11823, 11823, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12348, 12353, 12438, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42527, 42538, 42539, 42560, 42606, 42623, 42647, 42656, 42735, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43009, 43011, 43013, 43015, 43018, 43020, 43042, 43072, 43123, 43138, 43187, 43250, 43255, 43259, 43259, 43274, 43301, 43312, 43334, 43360, 43388, 43396, 43442, 43471, 43471, 43520, 43560, 43584, 43586, 43588, 43595, 43616, 43638, 43642, 43642, 43648, 43695, 43697, 43697, 43701, 43702, 43705, 43709, 43712, 43712, 43714, 43714, 43739, 43741, 43744, 43754, 43762, 43764, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44002, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,]; + var unicodeES5IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 768, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1155, 1159, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1469, 1471, 1471, 1473, 1474, 1476, 1477, 1479, 1479, 1488, 1514, 1520, 1522, 1552, 1562, 1568, 1641, 1646, 1747, 1749, 1756, 1759, 1768, 1770, 1788, 1791, 1791, 1808, 1866, 1869, 1969, 1984, 2037, 2042, 2042, 2048, 2093, 2112, 2139, 2208, 2208, 2210, 2220, 2276, 2302, 2304, 2403, 2406, 2415, 2417, 2423, 2425, 2431, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2500, 2503, 2504, 2507, 2510, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2561, 2563, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2641, 2641, 2649, 2652, 2654, 2654, 2662, 2677, 2689, 2691, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2787, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2876, 2884, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2915, 2918, 2927, 2929, 2929, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3024, 3024, 3031, 3031, 3046, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3160, 3161, 3168, 3171, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3260, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3299, 3302, 3311, 3313, 3314, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3396, 3398, 3400, 3402, 3406, 3415, 3415, 3424, 3427, 3430, 3439, 3450, 3455, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3807, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3948, 3953, 3972, 3974, 3991, 3993, 4028, 4038, 4038, 4096, 4169, 4176, 4253, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4957, 4959, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5908, 5920, 5940, 5952, 5971, 5984, 5996, 5998, 6000, 6002, 6003, 6016, 6099, 6103, 6103, 6108, 6109, 6112, 6121, 6155, 6157, 6160, 6169, 6176, 6263, 6272, 6314, 6320, 6389, 6400, 6428, 6432, 6443, 6448, 6459, 6470, 6509, 6512, 6516, 6528, 6571, 6576, 6601, 6608, 6617, 6656, 6683, 6688, 6750, 6752, 6780, 6783, 6793, 6800, 6809, 6823, 6823, 6912, 6987, 6992, 7001, 7019, 7027, 7040, 7155, 7168, 7223, 7232, 7241, 7245, 7293, 7376, 7378, 7380, 7414, 7424, 7654, 7676, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8204, 8205, 8255, 8256, 8276, 8276, 8305, 8305, 8319, 8319, 8336, 8348, 8400, 8412, 8417, 8417, 8421, 8432, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11647, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11744, 11775, 11823, 11823, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12348, 12353, 12438, 12441, 12442, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42539, 42560, 42607, 42612, 42621, 42623, 42647, 42655, 42737, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43047, 43072, 43123, 43136, 43204, 43216, 43225, 43232, 43255, 43259, 43259, 43264, 43309, 43312, 43347, 43360, 43388, 43392, 43456, 43471, 43481, 43520, 43574, 43584, 43597, 43600, 43609, 43616, 43638, 43642, 43643, 43648, 43714, 43739, 43741, 43744, 43759, 43762, 43766, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44010, 44012, 44013, 44016, 44025, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65024, 65039, 65056, 65062, 65075, 65076, 65101, 65103, 65136, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,]; function lookupInUnicodeMap(code, map) { if (code < map[0]) { return false; @@ -758,14 +759,14 @@ var ts; return result; } } - function getLeadingComments(text, pos) { + function getLeadingCommentRanges(text, pos) { return getCommentRanges(text, pos, false); } - ts.getLeadingComments = getLeadingComments; - function getTrailingComments(text, pos) { + ts.getLeadingCommentRanges = getLeadingCommentRanges; + function getTrailingCommentRanges(text, pos) { return getCommentRanges(text, pos, true); } - ts.getTrailingComments = getTrailingComments; + ts.getTrailingCommentRanges = getTrailingCommentRanges; function isIdentifierStart(ch, languageVersion) { return ch >= 65 /* A */ && ch <= 90 /* Z */ || ch >= 97 /* a */ && ch <= 122 /* z */ || ch === 36 /* $ */ || ch === 95 /* _ */ || ch > 127 /* maxAsciiCharacter */ && isUnicodeIdentifierStart(ch, languageVersion); } @@ -1492,60 +1493,62 @@ var ts; SyntaxKind[SyntaxKind["TypeLiteral"] = 129] = "TypeLiteral"; SyntaxKind[SyntaxKind["ArrayType"] = 130] = "ArrayType"; SyntaxKind[SyntaxKind["TupleType"] = 131] = "TupleType"; - SyntaxKind[SyntaxKind["ArrayLiteral"] = 132] = "ArrayLiteral"; - SyntaxKind[SyntaxKind["ObjectLiteral"] = 133] = "ObjectLiteral"; - SyntaxKind[SyntaxKind["PropertyAssignment"] = 134] = "PropertyAssignment"; - SyntaxKind[SyntaxKind["PropertyAccess"] = 135] = "PropertyAccess"; - SyntaxKind[SyntaxKind["IndexedAccess"] = 136] = "IndexedAccess"; - SyntaxKind[SyntaxKind["CallExpression"] = 137] = "CallExpression"; - SyntaxKind[SyntaxKind["NewExpression"] = 138] = "NewExpression"; - SyntaxKind[SyntaxKind["TypeAssertion"] = 139] = "TypeAssertion"; - SyntaxKind[SyntaxKind["ParenExpression"] = 140] = "ParenExpression"; - SyntaxKind[SyntaxKind["FunctionExpression"] = 141] = "FunctionExpression"; - SyntaxKind[SyntaxKind["ArrowFunction"] = 142] = "ArrowFunction"; - SyntaxKind[SyntaxKind["PrefixOperator"] = 143] = "PrefixOperator"; - SyntaxKind[SyntaxKind["PostfixOperator"] = 144] = "PostfixOperator"; - SyntaxKind[SyntaxKind["BinaryExpression"] = 145] = "BinaryExpression"; - SyntaxKind[SyntaxKind["ConditionalExpression"] = 146] = "ConditionalExpression"; - SyntaxKind[SyntaxKind["OmittedExpression"] = 147] = "OmittedExpression"; - SyntaxKind[SyntaxKind["Block"] = 148] = "Block"; - SyntaxKind[SyntaxKind["VariableStatement"] = 149] = "VariableStatement"; - SyntaxKind[SyntaxKind["EmptyStatement"] = 150] = "EmptyStatement"; - SyntaxKind[SyntaxKind["ExpressionStatement"] = 151] = "ExpressionStatement"; - SyntaxKind[SyntaxKind["IfStatement"] = 152] = "IfStatement"; - SyntaxKind[SyntaxKind["DoStatement"] = 153] = "DoStatement"; - SyntaxKind[SyntaxKind["WhileStatement"] = 154] = "WhileStatement"; - SyntaxKind[SyntaxKind["ForStatement"] = 155] = "ForStatement"; - SyntaxKind[SyntaxKind["ForInStatement"] = 156] = "ForInStatement"; - SyntaxKind[SyntaxKind["ContinueStatement"] = 157] = "ContinueStatement"; - SyntaxKind[SyntaxKind["BreakStatement"] = 158] = "BreakStatement"; - SyntaxKind[SyntaxKind["ReturnStatement"] = 159] = "ReturnStatement"; - SyntaxKind[SyntaxKind["WithStatement"] = 160] = "WithStatement"; - SyntaxKind[SyntaxKind["SwitchStatement"] = 161] = "SwitchStatement"; - SyntaxKind[SyntaxKind["CaseClause"] = 162] = "CaseClause"; - SyntaxKind[SyntaxKind["DefaultClause"] = 163] = "DefaultClause"; - SyntaxKind[SyntaxKind["LabeledStatement"] = 164] = "LabeledStatement"; - SyntaxKind[SyntaxKind["ThrowStatement"] = 165] = "ThrowStatement"; - SyntaxKind[SyntaxKind["TryStatement"] = 166] = "TryStatement"; - SyntaxKind[SyntaxKind["TryBlock"] = 167] = "TryBlock"; - SyntaxKind[SyntaxKind["CatchBlock"] = 168] = "CatchBlock"; - SyntaxKind[SyntaxKind["FinallyBlock"] = 169] = "FinallyBlock"; - SyntaxKind[SyntaxKind["DebuggerStatement"] = 170] = "DebuggerStatement"; - SyntaxKind[SyntaxKind["VariableDeclaration"] = 171] = "VariableDeclaration"; - SyntaxKind[SyntaxKind["FunctionDeclaration"] = 172] = "FunctionDeclaration"; - SyntaxKind[SyntaxKind["FunctionBlock"] = 173] = "FunctionBlock"; - SyntaxKind[SyntaxKind["ClassDeclaration"] = 174] = "ClassDeclaration"; - SyntaxKind[SyntaxKind["InterfaceDeclaration"] = 175] = "InterfaceDeclaration"; - SyntaxKind[SyntaxKind["EnumDeclaration"] = 176] = "EnumDeclaration"; - SyntaxKind[SyntaxKind["ModuleDeclaration"] = 177] = "ModuleDeclaration"; - SyntaxKind[SyntaxKind["ModuleBlock"] = 178] = "ModuleBlock"; - SyntaxKind[SyntaxKind["ImportDeclaration"] = 179] = "ImportDeclaration"; - SyntaxKind[SyntaxKind["ExportAssignment"] = 180] = "ExportAssignment"; - SyntaxKind[SyntaxKind["EnumMember"] = 181] = "EnumMember"; - SyntaxKind[SyntaxKind["SourceFile"] = 182] = "SourceFile"; - SyntaxKind[SyntaxKind["Program"] = 183] = "Program"; - SyntaxKind[SyntaxKind["SyntaxList"] = 184] = "SyntaxList"; - SyntaxKind[SyntaxKind["Count"] = 185] = "Count"; + SyntaxKind[SyntaxKind["UnionType"] = 132] = "UnionType"; + SyntaxKind[SyntaxKind["ParenType"] = 133] = "ParenType"; + SyntaxKind[SyntaxKind["ArrayLiteral"] = 134] = "ArrayLiteral"; + SyntaxKind[SyntaxKind["ObjectLiteral"] = 135] = "ObjectLiteral"; + SyntaxKind[SyntaxKind["PropertyAssignment"] = 136] = "PropertyAssignment"; + SyntaxKind[SyntaxKind["PropertyAccess"] = 137] = "PropertyAccess"; + SyntaxKind[SyntaxKind["IndexedAccess"] = 138] = "IndexedAccess"; + SyntaxKind[SyntaxKind["CallExpression"] = 139] = "CallExpression"; + SyntaxKind[SyntaxKind["NewExpression"] = 140] = "NewExpression"; + SyntaxKind[SyntaxKind["TypeAssertion"] = 141] = "TypeAssertion"; + SyntaxKind[SyntaxKind["ParenExpression"] = 142] = "ParenExpression"; + SyntaxKind[SyntaxKind["FunctionExpression"] = 143] = "FunctionExpression"; + SyntaxKind[SyntaxKind["ArrowFunction"] = 144] = "ArrowFunction"; + SyntaxKind[SyntaxKind["PrefixOperator"] = 145] = "PrefixOperator"; + SyntaxKind[SyntaxKind["PostfixOperator"] = 146] = "PostfixOperator"; + SyntaxKind[SyntaxKind["BinaryExpression"] = 147] = "BinaryExpression"; + SyntaxKind[SyntaxKind["ConditionalExpression"] = 148] = "ConditionalExpression"; + SyntaxKind[SyntaxKind["OmittedExpression"] = 149] = "OmittedExpression"; + SyntaxKind[SyntaxKind["Block"] = 150] = "Block"; + SyntaxKind[SyntaxKind["VariableStatement"] = 151] = "VariableStatement"; + SyntaxKind[SyntaxKind["EmptyStatement"] = 152] = "EmptyStatement"; + SyntaxKind[SyntaxKind["ExpressionStatement"] = 153] = "ExpressionStatement"; + SyntaxKind[SyntaxKind["IfStatement"] = 154] = "IfStatement"; + SyntaxKind[SyntaxKind["DoStatement"] = 155] = "DoStatement"; + SyntaxKind[SyntaxKind["WhileStatement"] = 156] = "WhileStatement"; + SyntaxKind[SyntaxKind["ForStatement"] = 157] = "ForStatement"; + SyntaxKind[SyntaxKind["ForInStatement"] = 158] = "ForInStatement"; + SyntaxKind[SyntaxKind["ContinueStatement"] = 159] = "ContinueStatement"; + SyntaxKind[SyntaxKind["BreakStatement"] = 160] = "BreakStatement"; + SyntaxKind[SyntaxKind["ReturnStatement"] = 161] = "ReturnStatement"; + SyntaxKind[SyntaxKind["WithStatement"] = 162] = "WithStatement"; + SyntaxKind[SyntaxKind["SwitchStatement"] = 163] = "SwitchStatement"; + SyntaxKind[SyntaxKind["CaseClause"] = 164] = "CaseClause"; + SyntaxKind[SyntaxKind["DefaultClause"] = 165] = "DefaultClause"; + SyntaxKind[SyntaxKind["LabeledStatement"] = 166] = "LabeledStatement"; + SyntaxKind[SyntaxKind["ThrowStatement"] = 167] = "ThrowStatement"; + SyntaxKind[SyntaxKind["TryStatement"] = 168] = "TryStatement"; + SyntaxKind[SyntaxKind["TryBlock"] = 169] = "TryBlock"; + SyntaxKind[SyntaxKind["CatchBlock"] = 170] = "CatchBlock"; + SyntaxKind[SyntaxKind["FinallyBlock"] = 171] = "FinallyBlock"; + SyntaxKind[SyntaxKind["DebuggerStatement"] = 172] = "DebuggerStatement"; + SyntaxKind[SyntaxKind["VariableDeclaration"] = 173] = "VariableDeclaration"; + SyntaxKind[SyntaxKind["FunctionDeclaration"] = 174] = "FunctionDeclaration"; + SyntaxKind[SyntaxKind["FunctionBlock"] = 175] = "FunctionBlock"; + SyntaxKind[SyntaxKind["ClassDeclaration"] = 176] = "ClassDeclaration"; + SyntaxKind[SyntaxKind["InterfaceDeclaration"] = 177] = "InterfaceDeclaration"; + SyntaxKind[SyntaxKind["EnumDeclaration"] = 178] = "EnumDeclaration"; + SyntaxKind[SyntaxKind["ModuleDeclaration"] = 179] = "ModuleDeclaration"; + SyntaxKind[SyntaxKind["ModuleBlock"] = 180] = "ModuleBlock"; + SyntaxKind[SyntaxKind["ImportDeclaration"] = 181] = "ImportDeclaration"; + SyntaxKind[SyntaxKind["ExportAssignment"] = 182] = "ExportAssignment"; + SyntaxKind[SyntaxKind["EnumMember"] = 183] = "EnumMember"; + SyntaxKind[SyntaxKind["SourceFile"] = 184] = "SourceFile"; + SyntaxKind[SyntaxKind["Program"] = 185] = "Program"; + SyntaxKind[SyntaxKind["SyntaxList"] = 186] = "SyntaxList"; + SyntaxKind[SyntaxKind["Count"] = 187] = "Count"; SyntaxKind[SyntaxKind["FirstAssignment"] = SyntaxKind.EqualsToken] = "FirstAssignment"; SyntaxKind[SyntaxKind["LastAssignment"] = SyntaxKind.CaretEqualsToken] = "LastAssignment"; SyntaxKind[SyntaxKind["FirstReservedWord"] = SyntaxKind.BreakKeyword] = "FirstReservedWord"; @@ -1555,11 +1558,13 @@ var ts; SyntaxKind[SyntaxKind["FirstFutureReservedWord"] = SyntaxKind.ImplementsKeyword] = "FirstFutureReservedWord"; SyntaxKind[SyntaxKind["LastFutureReservedWord"] = SyntaxKind.YieldKeyword] = "LastFutureReservedWord"; SyntaxKind[SyntaxKind["FirstTypeNode"] = SyntaxKind.TypeReference] = "FirstTypeNode"; - SyntaxKind[SyntaxKind["LastTypeNode"] = SyntaxKind.TupleType] = "LastTypeNode"; + SyntaxKind[SyntaxKind["LastTypeNode"] = SyntaxKind.ParenType] = "LastTypeNode"; SyntaxKind[SyntaxKind["FirstPunctuation"] = SyntaxKind.OpenBraceToken] = "FirstPunctuation"; SyntaxKind[SyntaxKind["LastPunctuation"] = SyntaxKind.CaretEqualsToken] = "LastPunctuation"; SyntaxKind[SyntaxKind["FirstToken"] = SyntaxKind.EndOfFileToken] = "FirstToken"; SyntaxKind[SyntaxKind["LastToken"] = SyntaxKind.StringKeyword] = "LastToken"; + SyntaxKind[SyntaxKind["FirstTriviaToken"] = SyntaxKind.SingleLineCommentTrivia] = "FirstTriviaToken"; + SyntaxKind[SyntaxKind["LastTriviaToken"] = SyntaxKind.WhitespaceTrivia] = "LastTriviaToken"; })(ts.SyntaxKind || (ts.SyntaxKind = {})); var SyntaxKind = ts.SyntaxKind; (function (NodeFlags) { @@ -1592,8 +1597,18 @@ var ts; TypeFormatFlags[TypeFormatFlags["WriteArrayAsGenericType"] = 0x00000001] = "WriteArrayAsGenericType"; TypeFormatFlags[TypeFormatFlags["UseTypeOfFunction"] = 0x00000002] = "UseTypeOfFunction"; TypeFormatFlags[TypeFormatFlags["NoTruncation"] = 0x00000004] = "NoTruncation"; + TypeFormatFlags[TypeFormatFlags["WriteArrowStyleSignature"] = 0x00000008] = "WriteArrowStyleSignature"; + TypeFormatFlags[TypeFormatFlags["WriteOwnNameForAnyLike"] = 0x00000010] = "WriteOwnNameForAnyLike"; + TypeFormatFlags[TypeFormatFlags["WriteTypeArgumentsOfSignature"] = 0x00000020] = "WriteTypeArgumentsOfSignature"; + TypeFormatFlags[TypeFormatFlags["InElementType"] = 0x00000040] = "InElementType"; })(ts.TypeFormatFlags || (ts.TypeFormatFlags = {})); var TypeFormatFlags = ts.TypeFormatFlags; + (function (SymbolFormatFlags) { + SymbolFormatFlags[SymbolFormatFlags["None"] = 0x00000000] = "None"; + SymbolFormatFlags[SymbolFormatFlags["WriteTypeParametersOrArguments"] = 0x00000001] = "WriteTypeParametersOrArguments"; + SymbolFormatFlags[SymbolFormatFlags["UseOnlyExternalAliasing"] = 0x00000002] = "UseOnlyExternalAliasing"; + })(ts.SymbolFormatFlags || (ts.SymbolFormatFlags = {})); + var SymbolFormatFlags = ts.SymbolFormatFlags; (function (SymbolAccessibility) { SymbolAccessibility[SymbolAccessibility["Accessible"] = 0] = "Accessible"; SymbolAccessibility[SymbolAccessibility["NotAccessible"] = 1] = "NotAccessible"; @@ -1628,6 +1643,7 @@ var ts; SymbolFlags[SymbolFlags["Merged"] = 0x01000000] = "Merged"; SymbolFlags[SymbolFlags["Transient"] = 0x02000000] = "Transient"; SymbolFlags[SymbolFlags["Prototype"] = 0x04000000] = "Prototype"; + SymbolFlags[SymbolFlags["UnionProperty"] = 0x08000000] = "UnionProperty"; SymbolFlags[SymbolFlags["Value"] = SymbolFlags.Variable | SymbolFlags.Property | SymbolFlags.EnumMember | SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.Enum | SymbolFlags.ValueModule | SymbolFlags.Method | SymbolFlags.GetAccessor | SymbolFlags.SetAccessor] = "Value"; SymbolFlags[SymbolFlags["Type"] = SymbolFlags.Class | SymbolFlags.Interface | SymbolFlags.Enum | SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral | SymbolFlags.TypeParameter] = "Type"; SymbolFlags[SymbolFlags["Namespace"] = SymbolFlags.ValueModule | SymbolFlags.NamespaceModule] = "Namespace"; @@ -1667,6 +1683,7 @@ var ts; NodeCheckFlags[NodeCheckFlags["SuperInstance"] = 0x00000010] = "SuperInstance"; NodeCheckFlags[NodeCheckFlags["SuperStatic"] = 0x00000020] = "SuperStatic"; NodeCheckFlags[NodeCheckFlags["ContextChecked"] = 0x00000040] = "ContextChecked"; + NodeCheckFlags[NodeCheckFlags["EnumValuesComputed"] = 0x00000080] = "EnumValuesComputed"; })(ts.NodeCheckFlags || (ts.NodeCheckFlags = {})); var NodeCheckFlags = ts.NodeCheckFlags; (function (TypeFlags) { @@ -1684,12 +1701,14 @@ var ts; TypeFlags[TypeFlags["Interface"] = 0x00000800] = "Interface"; TypeFlags[TypeFlags["Reference"] = 0x00001000] = "Reference"; TypeFlags[TypeFlags["Tuple"] = 0x00002000] = "Tuple"; - TypeFlags[TypeFlags["Anonymous"] = 0x00004000] = "Anonymous"; - TypeFlags[TypeFlags["FromSignature"] = 0x00008000] = "FromSignature"; + TypeFlags[TypeFlags["Union"] = 0x00004000] = "Union"; + TypeFlags[TypeFlags["Anonymous"] = 0x00008000] = "Anonymous"; + TypeFlags[TypeFlags["FromSignature"] = 0x00010000] = "FromSignature"; TypeFlags[TypeFlags["Intrinsic"] = TypeFlags.Any | TypeFlags.String | TypeFlags.Number | TypeFlags.Boolean | TypeFlags.Void | TypeFlags.Undefined | TypeFlags.Null] = "Intrinsic"; TypeFlags[TypeFlags["StringLike"] = TypeFlags.String | TypeFlags.StringLiteral] = "StringLike"; TypeFlags[TypeFlags["NumberLike"] = TypeFlags.Number | TypeFlags.Enum] = "NumberLike"; TypeFlags[TypeFlags["ObjectType"] = TypeFlags.Class | TypeFlags.Interface | TypeFlags.Reference | TypeFlags.Tuple | TypeFlags.Anonymous] = "ObjectType"; + TypeFlags[TypeFlags["Structured"] = TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.Union | TypeFlags.TypeParameter] = "Structured"; })(ts.TypeFlags || (ts.TypeFlags = {})); var TypeFlags = ts.TypeFlags; (function (SignatureKind) { @@ -1851,8 +1870,9 @@ var ts; var result; if (array) { for (var i = 0, len = array.length; i < len; i++) { - if (result = callback(array[i])) + if (result = callback(array[i])) { break; + } } } return result; @@ -1880,6 +1900,18 @@ var ts; return -1; } ts.indexOf = indexOf; + function countWhere(array, predicate) { + var count = 0; + if (array) { + for (var i = 0, len = array.length; i < len; i++) { + if (predicate(array[i])) { + count++; + } + } + } + return count; + } + ts.countWhere = countWhere; function filter(array, f) { if (array) { var result = []; @@ -1911,7 +1943,7 @@ var ts; return array1.concat(array2); } ts.concatenate = concatenate; - function uniqueElements(array) { + function deduplicate(array) { if (array) { var result = []; for (var i = 0, len = array.length; i < len; i++) { @@ -1922,7 +1954,7 @@ var ts; } return result; } - ts.uniqueElements = uniqueElements; + ts.deduplicate = deduplicate; function sum(array, prop) { var result = 0; for (var i = 0; i < array.length; i++) { @@ -2020,10 +2052,7 @@ var ts; } ts.localizedDiagnosticMessages = undefined; function getLocaleSpecificMessage(message) { - if (ts.localizedDiagnosticMessages) { - message = ts.localizedDiagnosticMessages[message]; - } - return message; + return ts.localizedDiagnosticMessages && ts.localizedDiagnosticMessages[message] ? ts.localizedDiagnosticMessages[message] : message; } ts.getLocaleSpecificMessage = getLocaleSpecificMessage; function createFileDiagnostic(file, start, length, message) { @@ -2244,14 +2273,14 @@ var ts; return getNormalizedPathComponents(pathOrUrl, currentDirectory); } } - function getRelativePathToDirectoryOrUrl(directoryPathOrUrl, relativeOrAbsolutePath, currentDirectory, isAbsolutePathAnUrl) { + function getRelativePathToDirectoryOrUrl(directoryPathOrUrl, relativeOrAbsolutePath, currentDirectory, getCanonicalFileName, isAbsolutePathAnUrl) { var pathComponents = getNormalizedPathOrUrlComponents(relativeOrAbsolutePath, currentDirectory); var directoryComponents = getNormalizedPathOrUrlComponents(directoryPathOrUrl, currentDirectory); if (directoryComponents.length > 1 && directoryComponents[directoryComponents.length - 1] === "") { directoryComponents.length--; } for (var joinStartIndex = 0; joinStartIndex < pathComponents.length && joinStartIndex < directoryComponents.length; joinStartIndex++) { - if (directoryComponents[joinStartIndex] !== pathComponents[joinStartIndex]) { + if (getCanonicalFileName(directoryComponents[joinStartIndex]) !== getCanonicalFileName(pathComponents[joinStartIndex])) { break; } } @@ -2295,6 +2324,37 @@ var ts; return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension; } ts.fileExtensionIs = fileExtensionIs; + var supportedExtensions = [".d.ts", ".ts", ".js"]; + function removeFileExtension(path) { + for (var i = 0; i < supportedExtensions.length; i++) { + var ext = supportedExtensions[i]; + if (fileExtensionIs(path, ext)) { + return path.substr(0, path.length - ext.length); + } + } + return path; + } + ts.removeFileExtension = removeFileExtension; + var escapedCharsRegExp = /[\t\v\f\b\0\r\n\"\\\u2028\u2029\u0085]/g; + var escapedCharsMap = { + "\t": "\\t", + "\v": "\\v", + "\f": "\\f", + "\b": "\\b", + "\0": "\\0", + "\r": "\\r", + "\n": "\\n", + "\"": "\\\"", + "\u2028": "\\u2028", + "\u2029": "\\u2029", + "\u0085": "\\u0085" + }; + function escapeString(s) { + return escapedCharsRegExp.test(s) ? s.replace(escapedCharsRegExp, function (c) { + return escapedCharsMap[c] || c; + }) : s; + } + ts.escapeString = escapeString; function Symbol(flags, name) { this.flags = flags; this.name = name; @@ -2354,7 +2414,7 @@ var ts; })(ts || (ts = {})); var ts; (function (ts) { - var nodeConstructors = new Array(185 /* Count */); + var nodeConstructors = new Array(187 /* Count */); function getNodeConstructor(kind) { return nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind)); } @@ -2366,19 +2426,8 @@ var ts; node.flags = flags; return node; } - var moduleExtensions = [".d.ts", ".ts", ".js"]; - function getModuleNameFromFilename(filename) { - for (var i = 0; i < moduleExtensions.length; i++) { - var ext = moduleExtensions[i]; - var len = filename.length - ext.length; - if (len > 0 && filename.substr(len) === ext) - return filename.substr(0, len); - } - return filename; - } - ts.getModuleNameFromFilename = getModuleNameFromFilename; function getSourceFileOfNode(node) { - while (node && node.kind !== 182 /* SourceFile */) + while (node && node.kind !== 184 /* SourceFile */) node = node.parent; return node; } @@ -2397,15 +2446,15 @@ var ts; return ts.skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos); } ts.getTokenPosOfNode = getTokenPosOfNode; - function getSourceTextOfNodeFromSourceText(sourceText, node) { + function getTextOfNodeFromSourceText(sourceText, node) { return sourceText.substring(ts.skipTrivia(sourceText, node.pos), node.end); } - ts.getSourceTextOfNodeFromSourceText = getSourceTextOfNodeFromSourceText; - function getSourceTextOfNode(node) { + ts.getTextOfNodeFromSourceText = getTextOfNodeFromSourceText; + function getTextOfNode(node) { var text = getSourceFileOfNode(node).text; return text.substring(ts.skipTrivia(text, node.pos), node.end); } - ts.getSourceTextOfNode = getSourceTextOfNode; + ts.getTextOfNode = getTextOfNode; function escapeIdentifier(identifier) { return identifier.length >= 2 && identifier.charCodeAt(0) === 95 /* _ */ && identifier.charCodeAt(1) === 95 /* _ */ ? "_" + identifier : identifier; } @@ -2415,7 +2464,7 @@ var ts; } ts.unescapeIdentifier = unescapeIdentifier; function identifierToString(identifier) { - return identifier.kind === 115 /* Missing */ ? "(Missing)" : getSourceTextOfNode(identifier); + return identifier.kind === 115 /* Missing */ ? "(Missing)" : getTextOfNode(identifier); } ts.identifierToString = identifierToString; function createDiagnosticForNode(node, message, arg0, arg1, arg2) { @@ -2437,12 +2486,12 @@ var ts; function getErrorSpanForNode(node) { var errorSpan; switch (node.kind) { - case 171 /* VariableDeclaration */: - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 177 /* ModuleDeclaration */: - case 176 /* EnumDeclaration */: - case 181 /* EnumMember */: + case 173 /* VariableDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 179 /* ModuleDeclaration */: + case 178 /* EnumDeclaration */: + case 183 /* EnumMember */: errorSpan = node.name; break; } @@ -2453,8 +2502,12 @@ var ts; return file.externalModuleIndicator !== undefined; } ts.isExternalModule = isExternalModule; + function isDeclarationFile(file) { + return (file.flags & 1024 /* DeclarationFile */) !== 0; + } + ts.isDeclarationFile = isDeclarationFile; function isPrologueDirective(node) { - return node.kind === 151 /* ExpressionStatement */ && node.expression.kind === 7 /* StringLiteral */; + return node.kind === 153 /* ExpressionStatement */ && node.expression.kind === 7 /* StringLiteral */; } ts.isPrologueDirective = isPrologueDirective; function isEvalOrArgumentsIdentifier(node) { @@ -2464,17 +2517,18 @@ var ts; ts.Debug.assert(isPrologueDirective(node)); return node.expression.text === "use strict"; } - function getLeadingCommentsOfNode(node, sourceFileOfNode) { + function getLeadingCommentRangesOfNode(node, sourceFileOfNode) { + sourceFileOfNode = sourceFileOfNode || getSourceFileOfNode(node); if (node.kind === 118 /* Parameter */ || node.kind === 117 /* TypeParameter */) { - return ts.concatenate(ts.getTrailingComments(sourceFileOfNode.text, node.pos), ts.getLeadingComments(sourceFileOfNode.text, node.pos)); + return ts.concatenate(ts.getTrailingCommentRanges(sourceFileOfNode.text, node.pos), ts.getLeadingCommentRanges(sourceFileOfNode.text, node.pos)); } else { - return ts.getLeadingComments(sourceFileOfNode.text, node.pos); + return ts.getLeadingCommentRanges(sourceFileOfNode.text, node.pos); } } - ts.getLeadingCommentsOfNode = getLeadingCommentsOfNode; + ts.getLeadingCommentRangesOfNode = getLeadingCommentRangesOfNode; function getJsDocComments(node, sourceFileOfNode) { - return ts.filter(getLeadingCommentsOfNode(node, sourceFileOfNode), function (comment) { return isJsDocComment(comment); }); + return ts.filter(getLeadingCommentRangesOfNode(node, sourceFileOfNode), function (comment) { return isJsDocComment(comment); }); function isJsDocComment(comment) { return sourceFileOfNode.text.charCodeAt(comment.pos + 1) === 42 /* asterisk */ && sourceFileOfNode.text.charCodeAt(comment.pos + 2) === 42 /* asterisk */ && sourceFileOfNode.text.charCodeAt(comment.pos + 3) !== 47 /* slash */; } @@ -2508,7 +2562,7 @@ var ts; case 118 /* Parameter */: return child(node.name) || child(node.type) || child(node.initializer); case 119 /* Property */: - case 134 /* PropertyAssignment */: + case 136 /* PropertyAssignment */: return child(node.name) || child(node.type) || child(node.initializer); case 124 /* CallSignature */: case 125 /* ConstructSignature */: @@ -2518,9 +2572,9 @@ var ts; case 121 /* Constructor */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 141 /* FunctionExpression */: - case 172 /* FunctionDeclaration */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 174 /* FunctionDeclaration */: + case 144 /* ArrowFunction */: return child(node.name) || children(node.typeParameters) || children(node.parameters) || child(node.type) || child(node.body); case 127 /* TypeReference */: return child(node.typeName) || children(node.typeArguments); @@ -2532,84 +2586,88 @@ var ts; return child(node.elementType); case 131 /* TupleType */: return children(node.elementTypes); - case 132 /* ArrayLiteral */: + case 132 /* UnionType */: + return children(node.types); + case 133 /* ParenType */: + return child(node.type); + case 134 /* ArrayLiteral */: return children(node.elements); - case 133 /* ObjectLiteral */: + case 135 /* ObjectLiteral */: return children(node.properties); - case 135 /* PropertyAccess */: + case 137 /* PropertyAccess */: return child(node.left) || child(node.right); - case 136 /* IndexedAccess */: + case 138 /* IndexedAccess */: return child(node.object) || child(node.index); - case 137 /* CallExpression */: - case 138 /* NewExpression */: + case 139 /* CallExpression */: + case 140 /* NewExpression */: return child(node.func) || children(node.typeArguments) || children(node.arguments); - case 139 /* TypeAssertion */: + case 141 /* TypeAssertion */: return child(node.type) || child(node.operand); - case 140 /* ParenExpression */: + case 142 /* ParenExpression */: return child(node.expression); - case 143 /* PrefixOperator */: - case 144 /* PostfixOperator */: + case 145 /* PrefixOperator */: + case 146 /* PostfixOperator */: return child(node.operand); - case 145 /* BinaryExpression */: + case 147 /* BinaryExpression */: return child(node.left) || child(node.right); - case 146 /* ConditionalExpression */: + case 148 /* ConditionalExpression */: return child(node.condition) || child(node.whenTrue) || child(node.whenFalse); - case 148 /* Block */: - case 167 /* TryBlock */: - case 169 /* FinallyBlock */: - case 173 /* FunctionBlock */: - case 178 /* ModuleBlock */: - case 182 /* SourceFile */: + case 150 /* Block */: + case 169 /* TryBlock */: + case 171 /* FinallyBlock */: + case 175 /* FunctionBlock */: + case 180 /* ModuleBlock */: + case 184 /* SourceFile */: return children(node.statements); - case 149 /* VariableStatement */: + case 151 /* VariableStatement */: return children(node.declarations); - case 151 /* ExpressionStatement */: + case 153 /* ExpressionStatement */: return child(node.expression); - case 152 /* IfStatement */: + case 154 /* IfStatement */: return child(node.expression) || child(node.thenStatement) || child(node.elseStatement); - case 153 /* DoStatement */: + case 155 /* DoStatement */: return child(node.statement) || child(node.expression); - case 154 /* WhileStatement */: + case 156 /* WhileStatement */: return child(node.expression) || child(node.statement); - case 155 /* ForStatement */: + case 157 /* ForStatement */: return children(node.declarations) || child(node.initializer) || child(node.condition) || child(node.iterator) || child(node.statement); - case 156 /* ForInStatement */: + case 158 /* ForInStatement */: return child(node.declaration) || child(node.variable) || child(node.expression) || child(node.statement); - case 157 /* ContinueStatement */: - case 158 /* BreakStatement */: + case 159 /* ContinueStatement */: + case 160 /* BreakStatement */: return child(node.label); - case 159 /* ReturnStatement */: + case 161 /* ReturnStatement */: return child(node.expression); - case 160 /* WithStatement */: + case 162 /* WithStatement */: return child(node.expression) || child(node.statement); - case 161 /* SwitchStatement */: + case 163 /* SwitchStatement */: return child(node.expression) || children(node.clauses); - case 162 /* CaseClause */: - case 163 /* DefaultClause */: + case 164 /* CaseClause */: + case 165 /* DefaultClause */: return child(node.expression) || children(node.statements); - case 164 /* LabeledStatement */: + case 166 /* LabeledStatement */: return child(node.label) || child(node.statement); - case 165 /* ThrowStatement */: + case 167 /* ThrowStatement */: return child(node.expression); - case 166 /* TryStatement */: + case 168 /* TryStatement */: return child(node.tryBlock) || child(node.catchBlock) || child(node.finallyBlock); - case 168 /* CatchBlock */: + case 170 /* CatchBlock */: return child(node.variable) || children(node.statements); - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: return child(node.name) || child(node.type) || child(node.initializer); - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: return child(node.name) || children(node.typeParameters) || child(node.baseType) || children(node.implementedTypes) || children(node.members); - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: return child(node.name) || children(node.typeParameters) || children(node.baseTypes) || children(node.members); - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: return child(node.name) || children(node.members); - case 181 /* EnumMember */: + case 183 /* EnumMember */: return child(node.name) || child(node.initializer); - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return child(node.name) || child(node.body); - case 179 /* ImportDeclaration */: + case 181 /* ImportDeclaration */: return child(node.name) || child(node.entityName) || child(node.externalModuleName); - case 180 /* ExportAssignment */: + case 182 /* ExportAssignment */: return child(node.exportName); } } @@ -2618,24 +2676,24 @@ var ts; return traverse(body); function traverse(node) { switch (node.kind) { - case 159 /* ReturnStatement */: + case 161 /* ReturnStatement */: return visitor(node); - case 148 /* Block */: - case 173 /* FunctionBlock */: - case 152 /* IfStatement */: - case 153 /* DoStatement */: - case 154 /* WhileStatement */: - case 155 /* ForStatement */: - case 156 /* ForInStatement */: - case 160 /* WithStatement */: - case 161 /* SwitchStatement */: - case 162 /* CaseClause */: - case 163 /* DefaultClause */: - case 164 /* LabeledStatement */: - case 166 /* TryStatement */: - case 167 /* TryBlock */: - case 168 /* CatchBlock */: - case 169 /* FinallyBlock */: + case 150 /* Block */: + case 175 /* FunctionBlock */: + case 154 /* IfStatement */: + case 155 /* DoStatement */: + case 156 /* WhileStatement */: + case 157 /* ForStatement */: + case 158 /* ForInStatement */: + case 162 /* WithStatement */: + case 163 /* SwitchStatement */: + case 164 /* CaseClause */: + case 165 /* DefaultClause */: + case 166 /* LabeledStatement */: + case 168 /* TryStatement */: + case 169 /* TryBlock */: + case 170 /* CatchBlock */: + case 171 /* FinallyBlock */: return forEachChild(node, traverse); } } @@ -2644,9 +2702,9 @@ var ts; function isAnyFunction(node) { if (node) { switch (node.kind) { - case 141 /* FunctionExpression */: - case 172 /* FunctionDeclaration */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 174 /* FunctionDeclaration */: + case 144 /* ArrowFunction */: case 120 /* Method */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: @@ -2673,20 +2731,20 @@ var ts; return undefined; } switch (node.kind) { - case 142 /* ArrowFunction */: + case 144 /* ArrowFunction */: if (!includeArrowFunctions) { continue; } - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: - case 177 /* ModuleDeclaration */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: + case 179 /* ModuleDeclaration */: case 119 /* Property */: case 120 /* Method */: case 121 /* Constructor */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 176 /* EnumDeclaration */: - case 182 /* SourceFile */: + case 178 /* EnumDeclaration */: + case 184 /* SourceFile */: return node; } } @@ -2726,19 +2784,19 @@ var ts; switch (node.kind) { case 117 /* TypeParameter */: case 118 /* Parameter */: - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: case 119 /* Property */: - case 134 /* PropertyAssignment */: - case 181 /* EnumMember */: + case 136 /* PropertyAssignment */: + case 183 /* EnumMember */: case 120 /* Method */: - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 176 /* EnumDeclaration */: - case 177 /* ModuleDeclaration */: - case 179 /* ImportDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: + case 179 /* ModuleDeclaration */: + case 181 /* ImportDeclaration */: return true; } return false; @@ -2746,24 +2804,24 @@ var ts; ts.isDeclaration = isDeclaration; function isStatement(n) { switch (n.kind) { - case 158 /* BreakStatement */: - case 157 /* ContinueStatement */: - case 170 /* DebuggerStatement */: - case 153 /* DoStatement */: - case 151 /* ExpressionStatement */: - case 150 /* EmptyStatement */: - case 156 /* ForInStatement */: - case 155 /* ForStatement */: - case 152 /* IfStatement */: - case 164 /* LabeledStatement */: - case 159 /* ReturnStatement */: - case 161 /* SwitchStatement */: + case 160 /* BreakStatement */: + case 159 /* ContinueStatement */: + case 172 /* DebuggerStatement */: + case 155 /* DoStatement */: + case 153 /* ExpressionStatement */: + case 152 /* EmptyStatement */: + case 158 /* ForInStatement */: + case 157 /* ForStatement */: + case 154 /* IfStatement */: + case 166 /* LabeledStatement */: + case 161 /* ReturnStatement */: + case 163 /* SwitchStatement */: case 88 /* ThrowKeyword */: - case 166 /* TryStatement */: - case 149 /* VariableStatement */: - case 154 /* WhileStatement */: - case 160 /* WithStatement */: - case 180 /* ExportAssignment */: + case 168 /* TryStatement */: + case 151 /* VariableStatement */: + case 156 /* WhileStatement */: + case 162 /* WithStatement */: + case 182 /* ExportAssignment */: return true; default: return false; @@ -2775,10 +2833,10 @@ var ts; return false; } var parent = name.parent; - if (isDeclaration(parent) || parent.kind === 141 /* FunctionExpression */) { + if (isDeclaration(parent) || parent.kind === 143 /* FunctionExpression */) { return parent.name === name; } - if (parent.kind === 168 /* CatchBlock */) { + if (parent.kind === 170 /* CatchBlock */) { return parent.variable === name; } return false; @@ -2786,15 +2844,15 @@ var ts; ts.isDeclarationOrFunctionExpressionOrCatchVariableName = isDeclarationOrFunctionExpressionOrCatchVariableName; function getAncestor(node, kind) { switch (kind) { - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: while (node) { switch (node.kind) { - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: return node; - case 176 /* EnumDeclaration */: - case 175 /* InterfaceDeclaration */: - case 177 /* ModuleDeclaration */: - case 179 /* ImportDeclaration */: + case 178 /* EnumDeclaration */: + case 177 /* InterfaceDeclaration */: + case 179 /* ModuleDeclaration */: + case 181 /* ImportDeclaration */: return undefined; default: node = node.parent; @@ -2893,12 +2951,6 @@ var ts; ModifierContext[ModifierContext["ClassMembers"] = 2] = "ClassMembers"; ModifierContext[ModifierContext["Parameters"] = 3] = "Parameters"; })(ModifierContext || (ModifierContext = {})); - var TrailingCommaBehavior; - (function (TrailingCommaBehavior) { - TrailingCommaBehavior[TrailingCommaBehavior["Disallow"] = 0] = "Disallow"; - TrailingCommaBehavior[TrailingCommaBehavior["Allow"] = 1] = "Allow"; - TrailingCommaBehavior[TrailingCommaBehavior["Preserve"] = 2] = "Preserve"; - })(TrailingCommaBehavior || (TrailingCommaBehavior = {})); var ControlBlockContext; (function (ControlBlockContext) { ControlBlockContext[ControlBlockContext["NotNested"] = 0] = "NotNested"; @@ -2909,6 +2961,10 @@ var ts; return ts.SyntaxKind.FirstKeyword <= token && token <= ts.SyntaxKind.LastKeyword; } ts.isKeyword = isKeyword; + function isTrivia(token) { + return ts.SyntaxKind.FirstTriviaToken <= token && token <= ts.SyntaxKind.LastTriviaToken; + } + ts.isTrivia = isTrivia; function isModifier(token) { switch (token) { case 102 /* PublicKeyword */: @@ -3169,7 +3225,9 @@ var ts; return finishNode(node); } error(ts.Diagnostics.Identifier_expected); - return createMissingNode(); + var node = createMissingNode(); + node.text = ""; + return node; } function parseIdentifier() { return createIdentifier(isIdentifier()); @@ -3221,14 +3279,14 @@ var ts; case 14 /* TypeParameters */: return isIdentifier(); case 10 /* ArgumentExpressions */: - return isExpression(); + return token === 18 /* CommaToken */ || isExpression(); case 12 /* ArrayLiteralMembers */: return token === 18 /* CommaToken */ || isExpression(); case 13 /* Parameters */: return isParameter(); case 15 /* TypeArguments */: case 16 /* TupleElementTypes */: - return isType(); + return token === 18 /* CommaToken */ || isType(); } ts.Debug.fail("Non-exhaustive case in 'isListElement'."); } @@ -3321,7 +3379,7 @@ var ts; parsingContext = saveParsingContext; return result; } - function parseDelimitedList(kind, parseElement, trailingCommaBehavior) { + function parseDelimitedList(kind, parseElement, allowTrailingComma) { var saveParsingContext = parsingContext; parsingContext |= 1 << kind; var result = []; @@ -3342,16 +3400,6 @@ var ts; error(ts.Diagnostics._0_expected, ","); } else if (isListTerminator(kind)) { - if (commaStart >= 0) { - if (trailingCommaBehavior === 0 /* Disallow */) { - if (file.syntacticErrors.length === errorCountBeforeParsingList) { - grammarErrorAtPos(commaStart, scanner.getStartPos() - commaStart, ts.Diagnostics.Trailing_comma_not_allowed); - } - } - else if (trailingCommaBehavior === 2 /* Preserve */) { - result.push(createNode(147 /* OmittedExpression */)); - } - } break; } else { @@ -3362,6 +3410,14 @@ var ts; nextToken(); } } + if (commaStart >= 0) { + if (!allowTrailingComma) { + if (file.syntacticErrors.length === errorCountBeforeParsingList) { + grammarErrorAtPos(commaStart, scanner.getStartPos() - commaStart, ts.Diagnostics.Trailing_comma_not_allowed); + } + } + result.hasTrailingComma = true; + } result.end = getNodeEnd(); parsingContext = saveParsingContext; return result; @@ -3381,7 +3437,7 @@ var ts; } function parseBracketedList(kind, parseElement, startToken, endToken) { if (parseExpected(startToken)) { - var result = parseDelimitedList(kind, parseElement, 0 /* Disallow */); + var result = parseDelimitedList(kind, parseElement, false); parseExpected(endToken); return result; } @@ -3685,6 +3741,13 @@ var ts; } return finishNode(node); } + function parseParenType() { + var node = createNode(133 /* ParenType */); + parseExpected(11 /* OpenParenToken */); + node.type = parseType(); + parseExpected(12 /* CloseParenToken */); + return finishNode(node); + } function parseFunctionType(signatureKind) { var node = createNode(129 /* TypeLiteral */); var member = createNode(signatureKind); @@ -3716,10 +3779,7 @@ var ts; case 13 /* OpenBracketToken */: return parseTupleType(); case 11 /* OpenParenToken */: - case 19 /* LessThanToken */: - return parseFunctionType(124 /* CallSignature */); - case 82 /* NewKeyword */: - return parseFunctionType(125 /* ConstructSignature */); + return parseParenType(); default: if (isIdentifier()) { return parseTypeReference(); @@ -3744,15 +3804,15 @@ var ts; case 11 /* OpenParenToken */: return lookAhead(function () { nextToken(); - return token === 12 /* CloseParenToken */ || isParameter(); + return token === 12 /* CloseParenToken */ || isParameter() || isType(); }); default: return isIdentifier(); } } - function parseType() { + function parsePrimaryType() { var type = parseNonArrayType(); - while (type && !scanner.hasPrecedingLineBreak() && parseOptional(13 /* OpenBracketToken */)) { + while (!scanner.hasPrecedingLineBreak() && parseOptional(13 /* OpenBracketToken */)) { parseExpected(14 /* CloseBracketToken */); var node = createNode(130 /* ArrayType */, type.pos); node.elementType = type; @@ -3760,6 +3820,51 @@ var ts; } return type; } + function parseUnionType() { + var type = parsePrimaryType(); + if (token === 39 /* BarToken */) { + var types = [type]; + types.pos = type.pos; + while (parseOptional(39 /* BarToken */)) { + types.push(parsePrimaryType()); + } + types.end = getNodeEnd(); + var node = createNode(132 /* UnionType */, type.pos); + node.types = types; + type = finishNode(node); + } + return type; + } + function isFunctionType() { + return token === 19 /* LessThanToken */ || token === 11 /* OpenParenToken */ && lookAhead(function () { + nextToken(); + if (token === 12 /* CloseParenToken */ || token === 16 /* DotDotDotToken */) { + return true; + } + if (isIdentifier() || isModifier(token)) { + nextToken(); + if (token === 46 /* ColonToken */ || token === 18 /* CommaToken */ || token === 45 /* QuestionToken */ || token === 47 /* EqualsToken */ || isIdentifier() || isModifier(token)) { + return true; + } + if (token === 12 /* CloseParenToken */) { + nextToken(); + if (token === 27 /* EqualsGreaterThanToken */) { + return true; + } + } + } + return false; + }); + } + function parseType() { + if (isFunctionType()) { + return parseFunctionType(124 /* CallSignature */); + } + if (token === 82 /* NewKeyword */) { + return parseFunctionType(125 /* ConstructSignature */); + } + return parseUnionType(); + } function parseTypeAnnotation() { return parseOptional(46 /* ColonToken */) ? parseType() : undefined; } @@ -3836,14 +3941,14 @@ var ts; function isLeftHandSideExpression(expr) { if (expr) { switch (expr.kind) { - case 135 /* PropertyAccess */: - case 136 /* IndexedAccess */: - case 138 /* NewExpression */: - case 137 /* CallExpression */: - case 132 /* ArrayLiteral */: - case 140 /* ParenExpression */: - case 133 /* ObjectLiteral */: - case 141 /* FunctionExpression */: + case 137 /* PropertyAccess */: + case 138 /* IndexedAccess */: + case 140 /* NewExpression */: + case 139 /* CallExpression */: + case 134 /* ArrayLiteral */: + case 142 /* ParenExpression */: + case 135 /* ObjectLiteral */: + case 143 /* FunctionExpression */: case 59 /* Identifier */: case 115 /* Missing */: case 8 /* RegularExpressionLiteral */: @@ -3884,7 +3989,7 @@ var ts; return parseArrowExpressionTail(pos, sig, false); } else { - return makeFunctionExpression(142 /* ArrowFunction */, pos, undefined, sig, createMissingNode()); + return makeFunctionExpression(144 /* ArrowFunction */, pos, undefined, sig, createMissingNode()); } } var sig = tryParseSignatureIfArrowOrBraceFollows(); @@ -3958,7 +4063,7 @@ var ts; else { body = parseAssignmentExpression(noIn); } - return makeFunctionExpression(142 /* ArrowFunction */, pos, undefined, sig, body); + return makeFunctionExpression(144 /* ArrowFunction */, pos, undefined, sig, body); } function isAssignmentOperator() { return token >= ts.SyntaxKind.FirstAssignment && token <= ts.SyntaxKind.LastAssignment; @@ -3966,7 +4071,7 @@ var ts; function parseConditionalExpression(noIn) { var expr = parseBinaryExpression(noIn); while (parseOptional(45 /* QuestionToken */)) { - var node = createNode(146 /* ConditionalExpression */, expr.pos); + var node = createNode(148 /* ConditionalExpression */, expr.pos); node.condition = expr; node.whenTrue = parseAssignmentExpression(false); parseExpected(46 /* ColonToken */); @@ -4030,7 +4135,7 @@ var ts; return undefined; } function makeBinaryExpression(left, operator, right) { - var node = createNode(145 /* BinaryExpression */, left.pos); + var node = createNode(147 /* BinaryExpression */, left.pos); node.left = left; node.operator = operator; node.right = right; @@ -4052,14 +4157,14 @@ var ts; nextToken(); var operand = parseUnaryExpression(); if (isInStrictMode) { - if ((token === 33 /* PlusPlusToken */ || token === 34 /* MinusMinusToken */) && isEvalOrArgumentsIdentifier(operand)) { + if ((operator === 33 /* PlusPlusToken */ || operator === 34 /* MinusMinusToken */) && isEvalOrArgumentsIdentifier(operand)) { reportInvalidUseInStrictMode(operand); } - else if (token === 68 /* DeleteKeyword */ && operand.kind === 59 /* Identifier */) { + else if (operator === 68 /* DeleteKeyword */ && operand.kind === 59 /* Identifier */) { grammarErrorOnNode(operand, ts.Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode); } } - return makeUnaryExpression(143 /* PrefixOperator */, pos, operator, operand); + return makeUnaryExpression(145 /* PrefixOperator */, pos, operator, operand); case 19 /* LessThanToken */: return parseTypeAssertion(); } @@ -4076,12 +4181,12 @@ var ts; } var operator = token; nextToken(); - expr = makeUnaryExpression(144 /* PostfixOperator */, expr.pos, operator, expr); + expr = makeUnaryExpression(146 /* PostfixOperator */, expr.pos, operator, expr); } return expr; } function parseTypeAssertion() { - var node = createNode(139 /* TypeAssertion */); + var node = createNode(141 /* TypeAssertion */); parseExpected(19 /* LessThanToken */); node.type = parseType(); parseExpected(20 /* GreaterThanToken */); @@ -4098,7 +4203,7 @@ var ts; while (true) { var dotStart = scanner.getTokenPos(); if (parseOptional(15 /* DotToken */)) { - var propertyAccess = createNode(135 /* PropertyAccess */, expr.pos); + var propertyAccess = createNode(137 /* PropertyAccess */, expr.pos); if (scanner.hasPrecedingLineBreak() && scanner.isReservedWord() && lookAhead(function () { return scanner.isReservedWord(); })) { grammarErrorAtPos(dotStart, scanner.getStartPos() - dotStart, ts.Diagnostics.Identifier_expected); var id = createMissingNode(); @@ -4113,7 +4218,7 @@ var ts; } var bracketStart = scanner.getTokenPos(); if (parseOptional(13 /* OpenBracketToken */)) { - var indexedAccess = createNode(136 /* IndexedAccess */, expr.pos); + var indexedAccess = createNode(138 /* IndexedAccess */, expr.pos); indexedAccess.object = expr; if (inNewExpression && parseOptional(14 /* CloseBracketToken */)) { indexedAccess.index = createMissingNode(); @@ -4131,7 +4236,7 @@ var ts; continue; } if ((token === 11 /* OpenParenToken */ || token === 19 /* LessThanToken */) && !inNewExpression) { - var callExpr = createNode(137 /* CallExpression */, expr.pos); + var callExpr = createNode(139 /* CallExpression */, expr.pos); callExpr.func = expr; if (token === 19 /* LessThanToken */) { if (!(callExpr.typeArguments = tryParse(parseTypeArgumentsAndOpenParen))) @@ -4140,7 +4245,7 @@ var ts; else { parseExpected(11 /* OpenParenToken */); } - callExpr.arguments = parseDelimitedList(10 /* ArgumentExpressions */, parseAssignmentExpression, 0 /* Disallow */); + callExpr.arguments = parseDelimitedList(10 /* ArgumentExpressions */, parseArgumentExpression, false); parseExpected(12 /* CloseParenToken */); expr = finishNode(callExpr); continue; @@ -4156,12 +4261,21 @@ var ts; function parseTypeArguments() { var typeArgumentListStart = scanner.getTokenPos(); var errorCountBeforeTypeParameterList = file.syntacticErrors.length; - var result = parseBracketedList(15 /* TypeArguments */, parseType, 19 /* LessThanToken */, 20 /* GreaterThanToken */); + var result = parseBracketedList(15 /* TypeArguments */, parseSingleTypeArgument, 19 /* LessThanToken */, 20 /* GreaterThanToken */); if (!result.length && file.syntacticErrors.length === errorCountBeforeTypeParameterList) { grammarErrorAtPos(typeArgumentListStart, scanner.getStartPos() - typeArgumentListStart, ts.Diagnostics.Type_argument_list_cannot_be_empty); } return result; } + function parseSingleTypeArgument() { + if (token === 18 /* CommaToken */) { + var errorStart = scanner.getTokenPos(); + var errorLength = scanner.getTextPos() - errorStart; + grammarErrorAtPos(errorStart, errorLength, ts.Diagnostics.Type_expected); + return createNode(115 /* Missing */); + } + return parseType(); + } function parsePrimaryExpression() { switch (token) { case 87 /* ThisKeyword */: @@ -4198,31 +4312,45 @@ var ts; return createMissingNode(); } function parseParenExpression() { - var node = createNode(140 /* ParenExpression */); + var node = createNode(142 /* ParenExpression */); parseExpected(11 /* OpenParenToken */); node.expression = parseExpression(); parseExpected(12 /* CloseParenToken */); return finishNode(node); } + function parseAssignmentExpressionOrOmittedExpression(omittedExpressionDiagnostic) { + if (token === 18 /* CommaToken */) { + if (omittedExpressionDiagnostic) { + var errorStart = scanner.getTokenPos(); + var errorLength = scanner.getTextPos() - errorStart; + grammarErrorAtPos(errorStart, errorLength, omittedExpressionDiagnostic); + } + return createNode(149 /* OmittedExpression */); + } + return parseAssignmentExpression(); + } function parseArrayLiteralElement() { - return token === 18 /* CommaToken */ ? createNode(147 /* OmittedExpression */) : parseAssignmentExpression(); + return parseAssignmentExpressionOrOmittedExpression(undefined); + } + function parseArgumentExpression() { + return parseAssignmentExpressionOrOmittedExpression(ts.Diagnostics.Argument_expression_expected); } function parseArrayLiteral() { - var node = createNode(132 /* ArrayLiteral */); + var node = createNode(134 /* ArrayLiteral */); parseExpected(13 /* OpenBracketToken */); if (scanner.hasPrecedingLineBreak()) node.flags |= 256 /* MultiLine */; - node.elements = parseDelimitedList(12 /* ArrayLiteralMembers */, parseArrayLiteralElement, 2 /* Preserve */); + node.elements = parseDelimitedList(12 /* ArrayLiteralMembers */, parseArrayLiteralElement, true); parseExpected(14 /* CloseBracketToken */); return finishNode(node); } function parsePropertyAssignment() { - var node = createNode(134 /* PropertyAssignment */); + var node = createNode(136 /* PropertyAssignment */); node.name = parsePropertyName(); if (token === 11 /* OpenParenToken */ || token === 19 /* LessThanToken */) { var sig = parseSignature(124 /* CallSignature */, 46 /* ColonToken */, false); var body = parseBody(false); - node.initializer = makeFunctionExpression(141 /* FunctionExpression */, node.pos, undefined, sig, body); + node.initializer = makeFunctionExpression(143 /* FunctionExpression */, node.pos, undefined, sig, body); } else { parseExpected(46 /* ColonToken */); @@ -4240,13 +4368,12 @@ var ts; return parsePropertyAssignment(); } function parseObjectLiteral() { - var node = createNode(133 /* ObjectLiteral */); + var node = createNode(135 /* ObjectLiteral */); parseExpected(9 /* OpenBraceToken */); if (scanner.hasPrecedingLineBreak()) { node.flags |= 256 /* MultiLine */; } - var trailingCommaBehavior = languageVersion === 0 /* ES3 */ ? 1 /* Allow */ : 2 /* Preserve */; - node.properties = parseDelimitedList(11 /* ObjectLiteralMembers */, parseObjectLiteralMember, trailingCommaBehavior); + node.properties = parseDelimitedList(11 /* ObjectLiteralMembers */, parseObjectLiteralMember, true); parseExpected(10 /* CloseBraceToken */); var seen = {}; var Property = 1; @@ -4254,11 +4381,11 @@ var ts; var SetAccesor = 4; var GetOrSetAccessor = GetAccessor | SetAccesor; ts.forEach(node.properties, function (p) { - if (p.kind === 147 /* OmittedExpression */) { + if (p.kind === 149 /* OmittedExpression */) { return; } var currentKind; - if (p.kind === 134 /* PropertyAssignment */) { + if (p.kind === 136 /* PropertyAssignment */) { currentKind = Property; } else if (p.kind === 122 /* GetAccessor */) { @@ -4304,7 +4431,7 @@ var ts; if (name && isInStrictMode && isEvalOrArgumentsIdentifier(name)) { reportInvalidUseInStrictMode(name); } - return makeFunctionExpression(141 /* FunctionExpression */, pos, name, sig, body); + return makeFunctionExpression(143 /* FunctionExpression */, pos, name, sig, body); } function makeFunctionExpression(kind, pos, name, sig, body) { var node = createNode(kind, pos); @@ -4316,17 +4443,17 @@ var ts; return finishNode(node); } function parseNewExpression() { - var node = createNode(138 /* NewExpression */); + var node = createNode(140 /* NewExpression */); parseExpected(82 /* NewKeyword */); node.func = parseCallAndAccess(parsePrimaryExpression(), true); if (parseOptional(11 /* OpenParenToken */) || token === 19 /* LessThanToken */ && (node.typeArguments = tryParse(parseTypeArgumentsAndOpenParen))) { - node.arguments = parseDelimitedList(10 /* ArgumentExpressions */, parseAssignmentExpression, 0 /* Disallow */); + node.arguments = parseDelimitedList(10 /* ArgumentExpressions */, parseArgumentExpression, false); parseExpected(12 /* CloseParenToken */); } return finishNode(node); } function parseBlock(ignoreMissingOpenBrace, checkForStrictMode) { - var node = createNode(148 /* Block */); + var node = createNode(150 /* Block */); if (parseExpected(9 /* OpenBraceToken */) || ignoreMissingOpenBrace) { node.statements = parseList(2 /* BlockStatements */, checkForStrictMode, parseStatement); parseExpected(10 /* CloseBraceToken */); @@ -4349,7 +4476,7 @@ var ts; } labelledStatementInfo.pushFunctionBoundary(); var block = parseBlock(ignoreMissingOpenBrace, true); - block.kind = 173 /* FunctionBlock */; + block.kind = 175 /* FunctionBlock */; labelledStatementInfo.pop(); inFunctionBody = saveInFunctionBody; inSwitchStatement = saveInSwitchStatement; @@ -4357,12 +4484,12 @@ var ts; return block; } function parseEmptyStatement() { - var node = createNode(150 /* EmptyStatement */); + var node = createNode(152 /* EmptyStatement */); parseExpected(17 /* SemicolonToken */); return finishNode(node); } function parseIfStatement() { - var node = createNode(152 /* IfStatement */); + var node = createNode(154 /* IfStatement */); parseExpected(78 /* IfKeyword */); parseExpected(11 /* OpenParenToken */); node.expression = parseExpression(); @@ -4372,7 +4499,7 @@ var ts; return finishNode(node); } function parseDoStatement() { - var node = createNode(153 /* DoStatement */); + var node = createNode(155 /* DoStatement */); parseExpected(69 /* DoKeyword */); var saveInIterationStatement = inIterationStatement; inIterationStatement = 1 /* Nested */; @@ -4386,7 +4513,7 @@ var ts; return finishNode(node); } function parseWhileStatement() { - var node = createNode(154 /* WhileStatement */); + var node = createNode(156 /* WhileStatement */); parseExpected(94 /* WhileKeyword */); parseExpected(11 /* OpenParenToken */); node.expression = parseExpression(); @@ -4414,7 +4541,7 @@ var ts; } var forOrForInStatement; if (parseOptional(80 /* InKeyword */)) { - var forInStatement = createNode(156 /* ForInStatement */, pos); + var forInStatement = createNode(158 /* ForInStatement */, pos); if (declarations) { if (declarations.length > 1) { error(ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement); @@ -4429,7 +4556,7 @@ var ts; forOrForInStatement = forInStatement; } else { - var forStatement = createNode(155 /* ForStatement */, pos); + var forStatement = createNode(157 /* ForStatement */, pos); if (declarations) forStatement.declarations = declarations; if (varOrInit) @@ -4454,7 +4581,7 @@ var ts; function parseBreakOrContinueStatement(kind) { var node = createNode(kind); var errorCountBeforeStatement = file.syntacticErrors.length; - parseExpected(kind === 158 /* BreakStatement */ ? 60 /* BreakKeyword */ : 65 /* ContinueKeyword */); + parseExpected(kind === 160 /* BreakStatement */ ? 60 /* BreakKeyword */ : 65 /* ContinueKeyword */); if (!canParseSemicolon()) node.label = parseIdentifier(); parseSemicolon(); @@ -4470,7 +4597,7 @@ var ts; return node; } function checkBareBreakOrContinueStatement(node) { - if (node.kind === 158 /* BreakStatement */) { + if (node.kind === 160 /* BreakStatement */) { if (inIterationStatement === 1 /* Nested */ || inSwitchStatement === 1 /* Nested */) { return; } @@ -4479,7 +4606,7 @@ var ts; return; } } - else if (node.kind === 157 /* ContinueStatement */) { + else if (node.kind === 159 /* ContinueStatement */) { if (inIterationStatement === 1 /* Nested */) { return; } @@ -4495,7 +4622,7 @@ var ts; grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary); } function checkBreakOrContinueStatementWithLabel(node) { - var nodeIsNestedInLabel = labelledStatementInfo.nodeIsNestedInLabel(node.label, node.kind === 157 /* ContinueStatement */, false); + var nodeIsNestedInLabel = labelledStatementInfo.nodeIsNestedInLabel(node.label, node.kind === 159 /* ContinueStatement */, false); if (nodeIsNestedInLabel === 1 /* Nested */) { return; } @@ -4503,10 +4630,10 @@ var ts; grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary); return; } - if (node.kind === 157 /* ContinueStatement */) { + if (node.kind === 159 /* ContinueStatement */) { grammarErrorOnNode(node, ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement); } - else if (node.kind === 158 /* BreakStatement */) { + else if (node.kind === 160 /* BreakStatement */) { grammarErrorOnNode(node, ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement); } else { @@ -4514,7 +4641,7 @@ var ts; } } function parseReturnStatement() { - var node = createNode(159 /* ReturnStatement */); + var node = createNode(161 /* ReturnStatement */); var errorCountBeforeReturnStatement = file.syntacticErrors.length; var returnTokenStart = scanner.getTokenPos(); var returnTokenLength = scanner.getTextPos() - returnTokenStart; @@ -4528,7 +4655,7 @@ var ts; return finishNode(node); } function parseWithStatement() { - var node = createNode(160 /* WithStatement */); + var node = createNode(162 /* WithStatement */); var startPos = scanner.getTokenPos(); parseExpected(95 /* WithKeyword */); var endPos = scanner.getStartPos(); @@ -4543,7 +4670,7 @@ var ts; return node; } function parseCaseClause() { - var node = createNode(162 /* CaseClause */); + var node = createNode(164 /* CaseClause */); parseExpected(61 /* CaseKeyword */); node.expression = parseExpression(); parseExpected(46 /* ColonToken */); @@ -4551,7 +4678,7 @@ var ts; return finishNode(node); } function parseDefaultClause() { - var node = createNode(163 /* DefaultClause */); + var node = createNode(165 /* DefaultClause */); parseExpected(67 /* DefaultKeyword */); parseExpected(46 /* ColonToken */); node.statements = parseList(4 /* SwitchClauseStatements */, false, parseStatement); @@ -4561,7 +4688,7 @@ var ts; return token === 61 /* CaseKeyword */ ? parseCaseClause() : parseDefaultClause(); } function parseSwitchStatement() { - var node = createNode(161 /* SwitchStatement */); + var node = createNode(163 /* SwitchStatement */); parseExpected(86 /* SwitchKeyword */); parseExpected(11 /* OpenParenToken */); node.expression = parseExpression(); @@ -4572,7 +4699,7 @@ var ts; node.clauses = parseList(3 /* SwitchClauses */, false, parseCaseOrDefaultClause); inSwitchStatement = saveInSwitchStatement; parseExpected(10 /* CloseBraceToken */); - var defaultClauses = ts.filter(node.clauses, function (clause) { return clause.kind === 163 /* DefaultClause */; }); + var defaultClauses = ts.filter(node.clauses, function (clause) { return clause.kind === 165 /* DefaultClause */; }); for (var i = 1, n = defaultClauses.length; i < n; i++) { var clause = defaultClauses[i]; var start = ts.skipTrivia(file.text, clause.pos); @@ -4582,7 +4709,7 @@ var ts; return finishNode(node); } function parseThrowStatement() { - var node = createNode(165 /* ThrowStatement */); + var node = createNode(167 /* ThrowStatement */); parseExpected(88 /* ThrowKeyword */); if (scanner.hasPrecedingLineBreak()) { error(ts.Diagnostics.Line_break_not_permitted_here); @@ -4592,13 +4719,13 @@ var ts; return finishNode(node); } function parseTryStatement() { - var node = createNode(166 /* TryStatement */); - node.tryBlock = parseTokenAndBlock(90 /* TryKeyword */, 167 /* TryBlock */); + var node = createNode(168 /* TryStatement */); + node.tryBlock = parseTokenAndBlock(90 /* TryKeyword */, 169 /* TryBlock */); if (token === 62 /* CatchKeyword */) { node.catchBlock = parseCatchBlock(); } if (token === 75 /* FinallyKeyword */) { - node.finallyBlock = parseTokenAndBlock(75 /* FinallyKeyword */, 169 /* FinallyBlock */); + node.finallyBlock = parseTokenAndBlock(75 /* FinallyKeyword */, 171 /* FinallyBlock */); } if (!(node.catchBlock || node.finallyBlock)) { error(ts.Diagnostics.catch_or_finally_expected); @@ -4623,7 +4750,7 @@ var ts; var typeAnnotation = parseTypeAnnotation(); parseExpected(12 /* CloseParenToken */); var result = parseBlock(false, false); - result.kind = 168 /* CatchBlock */; + result.kind = 170 /* CatchBlock */; result.pos = pos; result.variable = variable; if (typeAnnotation) { @@ -4635,7 +4762,7 @@ var ts; return result; } function parseDebuggerStatement() { - var node = createNode(170 /* DebuggerStatement */); + var node = createNode(172 /* DebuggerStatement */); parseExpected(66 /* DebuggerKeyword */); parseSemicolon(); return finishNode(node); @@ -4653,18 +4780,18 @@ var ts; return isIdentifier() && lookAhead(function () { return nextToken() === 46 /* ColonToken */; }); } function parseLabelledStatement() { - var node = createNode(164 /* LabeledStatement */); + var node = createNode(166 /* LabeledStatement */); node.label = parseIdentifier(); parseExpected(46 /* ColonToken */); if (labelledStatementInfo.nodeIsNestedInLabel(node.label, false, true)) { - grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, getSourceTextOfNodeFromSourceText(sourceText, node.label)); + grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, getTextOfNodeFromSourceText(sourceText, node.label)); } labelledStatementInfo.addLabel(node.label); node.statement = isLabel() ? parseLabelledStatement() : parseStatementWithLabelSet(); return finishNode(node); } function parseExpressionStatement() { - var node = createNode(151 /* ExpressionStatement */); + var node = createNode(153 /* ExpressionStatement */); node.expression = parseExpression(); parseSemicolon(); return finishNode(node); @@ -4728,9 +4855,9 @@ var ts; case 76 /* ForKeyword */: return parseForOrForInStatement(); case 65 /* ContinueKeyword */: - return parseBreakOrContinueStatement(157 /* ContinueStatement */); + return parseBreakOrContinueStatement(159 /* ContinueStatement */); case 60 /* BreakKeyword */: - return parseBreakOrContinueStatement(158 /* BreakStatement */); + return parseBreakOrContinueStatement(160 /* BreakStatement */); case 84 /* ReturnKeyword */: return parseReturnStatement(); case 95 /* WithKeyword */: @@ -4773,7 +4900,7 @@ var ts; error(ts.Diagnostics.Block_or_expected); } function parseVariableDeclaration(flags, noIn) { - var node = createNode(171 /* VariableDeclaration */); + var node = createNode(173 /* VariableDeclaration */); node.flags = flags; var errorCountBeforeVariableDeclaration = file.syntacticErrors.length; node.name = parseIdentifier(); @@ -4790,10 +4917,10 @@ var ts; return finishNode(node); } function parseVariableDeclarationList(flags, noIn) { - return parseDelimitedList(9 /* VariableDeclarations */, function () { return parseVariableDeclaration(flags, noIn); }, 0 /* Disallow */); + return parseDelimitedList(9 /* VariableDeclarations */, function () { return parseVariableDeclaration(flags, noIn); }, false); } function parseVariableStatement(pos, flags) { - var node = createNode(149 /* VariableStatement */, pos); + var node = createNode(151 /* VariableStatement */, pos); if (flags) node.flags = flags; var errorCountBeforeVarStatement = file.syntacticErrors.length; @@ -4807,7 +4934,7 @@ var ts; return node; } function parseFunctionDeclaration(pos, flags) { - var node = createNode(172 /* FunctionDeclaration */, pos); + var node = createNode(174 /* FunctionDeclaration */, pos); if (flags) node.flags = flags; parseExpected(77 /* FunctionKeyword */); @@ -5118,7 +5245,7 @@ var ts; ts.Debug.fail("Should not have attempted to parse class member declaration."); } function parseClassDeclaration(pos, flags) { - var node = createNode(174 /* ClassDeclaration */, pos); + var node = createNode(176 /* ClassDeclaration */, pos); node.flags = flags; var errorCountBeforeClassDeclaration = file.syntacticErrors.length; parseExpected(63 /* ClassKeyword */); @@ -5129,7 +5256,7 @@ var ts; var implementsKeywordLength; if (parseOptional(96 /* ImplementsKeyword */)) { implementsKeywordLength = scanner.getStartPos() - implementsKeywordStart; - node.implementedTypes = parseDelimitedList(8 /* BaseTypeReferences */, parseTypeReference, 0 /* Disallow */); + node.implementedTypes = parseDelimitedList(8 /* BaseTypeReferences */, parseTypeReference, false); } var errorCountBeforeClassBody = file.syntacticErrors.length; if (parseExpected(9 /* OpenBraceToken */)) { @@ -5145,7 +5272,7 @@ var ts; return finishNode(node); } function parseInterfaceDeclaration(pos, flags) { - var node = createNode(175 /* InterfaceDeclaration */, pos); + var node = createNode(177 /* InterfaceDeclaration */, pos); node.flags = flags; var errorCountBeforeInterfaceDeclaration = file.syntacticErrors.length; parseExpected(97 /* InterfaceKeyword */); @@ -5155,7 +5282,7 @@ var ts; var extendsKeywordLength; if (parseOptional(73 /* ExtendsKeyword */)) { extendsKeywordLength = scanner.getStartPos() - extendsKeywordStart; - node.baseTypes = parseDelimitedList(8 /* BaseTypeReferences */, parseTypeReference, 0 /* Disallow */); + node.baseTypes = parseDelimitedList(8 /* BaseTypeReferences */, parseTypeReference, false); } var errorCountBeforeInterfaceBody = file.syntacticErrors.length; node.members = parseTypeLiteral().members; @@ -5169,7 +5296,7 @@ var ts; function isInteger(literalExpression) { return /^[0-9]+([eE]\+?[0-9]+)?$/.test(literalExpression.text); } - if (expression.kind === 143 /* PrefixOperator */) { + if (expression.kind === 145 /* PrefixOperator */) { var unaryExpression = expression; if (unaryExpression.operator === 28 /* PlusToken */ || unaryExpression.operator === 29 /* MinusToken */) { expression = unaryExpression.operand; @@ -5182,7 +5309,7 @@ var ts; } var inConstantEnumMemberSection = true; function parseAndCheckEnumMember() { - var node = createNode(181 /* EnumMember */); + var node = createNode(183 /* EnumMember */); var errorCountBeforeEnumMember = file.syntacticErrors.length; node.name = parsePropertyName(); node.initializer = parseInitializer(false); @@ -5199,12 +5326,12 @@ var ts; } return finishNode(node); } - var node = createNode(176 /* EnumDeclaration */, pos); + var node = createNode(178 /* EnumDeclaration */, pos); node.flags = flags; parseExpected(71 /* EnumKeyword */); node.name = parseIdentifier(); if (parseExpected(9 /* OpenBraceToken */)) { - node.members = parseDelimitedList(7 /* EnumMembers */, parseAndCheckEnumMember, 1 /* Allow */); + node.members = parseDelimitedList(7 /* EnumMembers */, parseAndCheckEnumMember, true); parseExpected(10 /* CloseBraceToken */); } else { @@ -5213,7 +5340,7 @@ var ts; return finishNode(node); } function parseModuleBody() { - var node = createNode(178 /* ModuleBlock */); + var node = createNode(180 /* ModuleBlock */); if (parseExpected(9 /* OpenBraceToken */)) { node.statements = parseList(1 /* ModuleElements */, false, parseModuleElement); parseExpected(10 /* CloseBraceToken */); @@ -5224,7 +5351,7 @@ var ts; return finishNode(node); } function parseInternalModuleTail(pos, flags) { - var node = createNode(177 /* ModuleDeclaration */, pos); + var node = createNode(179 /* ModuleDeclaration */, pos); node.flags = flags; node.name = parseIdentifier(); if (parseOptional(15 /* DotToken */)) { @@ -5233,10 +5360,10 @@ var ts; else { node.body = parseModuleBody(); ts.forEach(node.body.statements, function (s) { - if (s.kind === 180 /* ExportAssignment */) { + if (s.kind === 182 /* ExportAssignment */) { grammarErrorOnNode(s, ts.Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); } - else if (s.kind === 179 /* ImportDeclaration */ && s.externalModuleName) { + else if (s.kind === 181 /* ImportDeclaration */ && s.externalModuleName) { grammarErrorOnNode(s, ts.Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); } }); @@ -5244,7 +5371,7 @@ var ts; return finishNode(node); } function parseAmbientExternalModuleDeclaration(pos, flags) { - var node = createNode(177 /* ModuleDeclaration */, pos); + var node = createNode(179 /* ModuleDeclaration */, pos); node.flags = flags; node.name = parseStringLiteral(); if (!inAmbientContext) { @@ -5264,7 +5391,7 @@ var ts; return token === 7 /* StringLiteral */ ? parseAmbientExternalModuleDeclaration(pos, flags) : parseInternalModuleTail(pos, flags); } function parseImportDeclaration(pos, flags) { - var node = createNode(179 /* ImportDeclaration */, pos); + var node = createNode(181 /* ImportDeclaration */, pos); node.flags = flags; parseExpected(79 /* ImportKeyword */); node.name = parseIdentifier(); @@ -5281,7 +5408,7 @@ var ts; return finishNode(node); } function parseExportAssignmentTail(pos) { - var node = createNode(180 /* ExportAssignment */, pos); + var node = createNode(182 /* ExportAssignment */, pos); node.exportName = parseIdentifier(); parseSemicolon(); return finishNode(node); @@ -5398,15 +5525,16 @@ var ts; } else { var matchResult = ts.fullTripleSlashReferencePathRegEx.exec(comment); + var start = range.pos; + var end = range.end; + var length = end - start; if (!matchResult) { - var start = range.pos; - var length = range.end - start; errorAtPos(start, length, ts.Diagnostics.Invalid_reference_directive_syntax); } else { referencedFiles.push({ - pos: range.pos, - end: range.end, + pos: start, + end: end, filename: matchResult[3] }); } @@ -5427,7 +5555,7 @@ var ts; }; } function getExternalModuleIndicator() { - return ts.forEach(file.statements, function (node) { return node.flags & 1 /* Export */ || node.kind === 179 /* ImportDeclaration */ && node.externalModuleName || node.kind === 180 /* ExportAssignment */ ? node : undefined; }); + return ts.forEach(file.statements, function (node) { return node.flags & 1 /* Export */ || node.kind === 181 /* ImportDeclaration */ && node.externalModuleName || node.kind === 182 /* ExportAssignment */ ? node : undefined; }); } scanner = ts.createScanner(languageVersion, true, sourceText, scanError, onComment); var rootNodeFlags = 0; @@ -5435,7 +5563,7 @@ var ts; rootNodeFlags = 1024 /* DeclarationFile */; inAmbientContext = true; } - file = createRootNode(182 /* SourceFile */, 0, sourceText.length, rootNodeFlags); + file = createRootNode(184 /* SourceFile */, 0, sourceText.length, rootNodeFlags); file.filename = ts.normalizePath(filename); file.text = sourceText; file.getLineAndCharacterFromPosition = getLineAndCharacterlFromSourcePosition; @@ -5509,6 +5637,9 @@ var ts; else if (!findSourceFile(filename, isDefaultLib, refFile, refPos, refEnd)) { diagnostic = ts.Diagnostics.File_0_not_found; } + else if (refFile && host.getCanonicalFileName(filename) === host.getCanonicalFileName(refFile.filename)) { + diagnostic = ts.Diagnostics.A_file_cannot_have_a_reference_to_itself; + } } else { if (!(findSourceFile(filename + ".ts", isDefaultLib, refFile, refPos, refEnd) || findSourceFile(filename + ".d.ts", isDefaultLib, refFile, refPos, refEnd))) { @@ -5559,12 +5690,13 @@ var ts; } function processReferencedFiles(file, basePath) { ts.forEach(file.referencedFiles, function (ref) { - processSourceFile(ts.normalizePath(ts.combinePaths(basePath, ref.filename)), false, file, ref.pos, ref.end); + var referencedFilename = ts.isRootedDiskPath(ref.filename) ? ref.filename : ts.combinePaths(basePath, ref.filename); + processSourceFile(ts.normalizePath(referencedFilename), false, file, ref.pos, ref.end); }); } function processImportedModules(file, basePath) { ts.forEach(file.statements, function (node) { - if (node.kind === 179 /* ImportDeclaration */ && node.externalModuleName) { + if (node.kind === 181 /* ImportDeclaration */ && node.externalModuleName) { var nameLiteral = node.externalModuleName; var moduleName = nameLiteral.text; if (moduleName) { @@ -5582,9 +5714,9 @@ var ts; } } } - else if (node.kind === 177 /* ModuleDeclaration */ && node.name.kind === 7 /* StringLiteral */ && (node.flags & 2 /* Ambient */ || file.flags & 1024 /* DeclarationFile */)) { + else if (node.kind === 179 /* ModuleDeclaration */ && node.name.kind === 7 /* StringLiteral */ && (node.flags & 2 /* Ambient */ || isDeclarationFile(file))) { forEachChild(node.body, function (node) { - if (node.kind === 179 /* ImportDeclaration */ && node.externalModuleName) { + if (node.kind === 181 /* ImportDeclaration */ && node.externalModuleName) { var nameLiteral = node.externalModuleName; var moduleName = nameLiteral.text; if (moduleName) { @@ -5657,16 +5789,16 @@ var ts; var ts; (function (ts) { function isInstantiated(node) { - if (node.kind === 175 /* InterfaceDeclaration */) { + if (node.kind === 177 /* InterfaceDeclaration */) { return false; } - else if (node.kind === 179 /* ImportDeclaration */ && !(node.flags & 1 /* Export */)) { + else if (node.kind === 181 /* ImportDeclaration */ && !(node.flags & 1 /* Export */)) { return false; } - else if (node.kind === 178 /* ModuleBlock */ && !ts.forEachChild(node, isInstantiated)) { + else if (node.kind === 180 /* ModuleBlock */ && !ts.forEachChild(node, isInstantiated)) { return false; } - else if (node.kind === 177 /* ModuleDeclaration */ && !isInstantiated(node.body)) { + else if (node.kind === 179 /* ModuleDeclaration */ && !isInstantiated(node.body)) { return false; } else { @@ -5705,7 +5837,7 @@ var ts; } function getDeclarationName(node) { if (node.name) { - if (node.kind === 177 /* ModuleDeclaration */ && node.name.kind === 7 /* StringLiteral */) { + if (node.kind === 179 /* ModuleDeclaration */ && node.name.kind === 7 /* StringLiteral */) { return '"' + node.name.text + '"'; } return node.name.text; @@ -5732,7 +5864,10 @@ var ts; if (node.name) { node.name.parent = node; } - file.semanticErrors.push(ts.createDiagnosticForNode(node.name ? node.name : node, ts.Diagnostics.Duplicate_identifier_0, getDisplayName(node))); + ts.forEach(symbol.declarations, function (declaration) { + file.semanticErrors.push(ts.createDiagnosticForNode(declaration.name, ts.Diagnostics.Duplicate_identifier_0, getDisplayName(declaration))); + }); + file.semanticErrors.push(ts.createDiagnosticForNode(node.name, ts.Diagnostics.Duplicate_identifier_0, getDisplayName(node))); symbol = createSymbol(0, name); } } @@ -5741,7 +5876,7 @@ var ts; } addDeclarationToSymbol(symbol, node, includes); symbol.parent = parent; - if (node.kind === 174 /* ClassDeclaration */ && symbol.exports) { + if (node.kind === 176 /* ClassDeclaration */ && symbol.exports) { var prototypeSymbol = createSymbol(2 /* Property */ | 67108864 /* Prototype */, "prototype"); if (ts.hasProperty(symbol.exports, prototypeSymbol.name)) { if (node.name) { @@ -5773,7 +5908,7 @@ var ts; if (symbolKind & ts.SymbolFlags.Namespace) { exportKind |= 2097152 /* ExportNamespace */; } - if (node.flags & 1 /* Export */ || (node.kind !== 179 /* ImportDeclaration */ && isAmbientContext(container))) { + if (node.flags & 1 /* Export */ || (node.kind !== 181 /* ImportDeclaration */ && isAmbientContext(container))) { if (exportKind) { var local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes); local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); @@ -5809,10 +5944,10 @@ var ts; } function bindDeclaration(node, symbolKind, symbolExcludes) { switch (container.kind) { - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: declareModuleMember(node, symbolKind, symbolExcludes); break; - case 182 /* SourceFile */: + case 184 /* SourceFile */: if (ts.isExternalModule(container)) { declareModuleMember(node, symbolKind, symbolExcludes); break; @@ -5824,22 +5959,22 @@ var ts; case 121 /* Constructor */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes); break; - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: if (node.flags & 128 /* Static */) { declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); break; } case 129 /* TypeLiteral */: - case 133 /* ObjectLiteral */: - case 175 /* InterfaceDeclaration */: + case 135 /* ObjectLiteral */: + case 177 /* InterfaceDeclaration */: declareSymbol(container.symbol.members, container.symbol, node, symbolKind, symbolExcludes); break; - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); break; } @@ -5886,14 +6021,14 @@ var ts; case 118 /* Parameter */: bindDeclaration(node, 1 /* Variable */, ts.SymbolFlags.ParameterExcludes); break; - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: bindDeclaration(node, 1 /* Variable */, ts.SymbolFlags.VariableExcludes); break; case 119 /* Property */: - case 134 /* PropertyAssignment */: + case 136 /* PropertyAssignment */: bindDeclaration(node, 2 /* Property */, ts.SymbolFlags.PropertyExcludes); break; - case 181 /* EnumMember */: + case 183 /* EnumMember */: bindDeclaration(node, 4 /* EnumMember */, ts.SymbolFlags.EnumMemberExcludes); break; case 124 /* CallSignature */: @@ -5908,7 +6043,7 @@ var ts; case 126 /* IndexSignature */: bindDeclaration(node, 131072 /* IndexSignature */, 0); break; - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: bindDeclaration(node, 8 /* Function */, ts.SymbolFlags.FunctionExcludes); break; case 121 /* Constructor */: @@ -5923,34 +6058,34 @@ var ts; case 129 /* TypeLiteral */: bindAnonymousDeclaration(node, 512 /* TypeLiteral */, "__type"); break; - case 133 /* ObjectLiteral */: + case 135 /* ObjectLiteral */: bindAnonymousDeclaration(node, 1024 /* ObjectLiteral */, "__object"); break; - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: bindAnonymousDeclaration(node, 8 /* Function */, "__function"); break; - case 168 /* CatchBlock */: + case 170 /* CatchBlock */: bindCatchVariableDeclaration(node); break; - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: bindDeclaration(node, 16 /* Class */, ts.SymbolFlags.ClassExcludes); break; - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: bindDeclaration(node, 32 /* Interface */, ts.SymbolFlags.InterfaceExcludes); break; - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: bindDeclaration(node, 64 /* Enum */, ts.SymbolFlags.EnumExcludes); break; - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: bindModuleDeclaration(node); break; - case 179 /* ImportDeclaration */: + case 181 /* ImportDeclaration */: bindDeclaration(node, 4194304 /* Import */, ts.SymbolFlags.ImportExcludes); break; - case 182 /* SourceFile */: + case 184 /* SourceFile */: if (ts.isExternalModule(node)) { - bindAnonymousDeclaration(node, 128 /* ValueModule */, '"' + ts.getModuleNameFromFilename(node.filename) + '"'); + bindAnonymousDeclaration(node, 128 /* ValueModule */, '"' + ts.removeFileExtension(node.filename) + '"'); break; } default: @@ -5972,11 +6107,12 @@ var ts; } return indentStrings[level]; } + ts.getIndentString = getIndentString; function getIndentSize() { return indentStrings[1].length; } function shouldEmitToOwnFile(sourceFile, compilerOptions) { - if (!(sourceFile.flags & 1024 /* DeclarationFile */)) { + if (!ts.isDeclarationFile(sourceFile)) { if ((ts.isExternalModule(sourceFile) || !compilerOptions.out) && !ts.fileExtensionIs(sourceFile.filename, ".js")) { return true; } @@ -5986,7 +6122,7 @@ var ts; } ts.shouldEmitToOwnFile = shouldEmitToOwnFile; function isExternalModuleOrDeclarationFile(sourceFile) { - return ts.isExternalModule(sourceFile) || (sourceFile.flags & 1024 /* DeclarationFile */) !== 0; + return ts.isExternalModule(sourceFile) || ts.isDeclarationFile(sourceFile); } ts.isExternalModuleOrDeclarationFile = isExternalModuleOrDeclarationFile; function emitFiles(resolver, targetSourceFile) { @@ -6003,10 +6139,10 @@ var ts; } function getOwnEmitOutputFilePath(sourceFile, extension) { if (compilerOptions.outDir) { - var emitOutputFilePathWithoutExtension = ts.getModuleNameFromFilename(getSourceFilePathInNewDir(compilerOptions.outDir, sourceFile)); + var emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(compilerOptions.outDir, sourceFile)); } else { - var emitOutputFilePathWithoutExtension = ts.getModuleNameFromFilename(sourceFile.filename); + var emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.filename); } return emitOutputFilePathWithoutExtension + extension; } @@ -6040,7 +6176,7 @@ var ts; setAccessor: setAccessor }; } - function createTextWriter(writeSymbol) { + function createTextWriter() { var output = ""; var indent = 0; var lineStart = true; @@ -6083,7 +6219,6 @@ var ts; } return { write: write, - writeSymbol: writeSymbol, rawWrite: rawWrite, writeLiteral: writeLiteral, writeLine: writeLine, @@ -6192,7 +6327,7 @@ var ts; } } function emitJavaScript(jsFilePath, root) { - var writer = createTextWriter(writeSymbol); + var writer = createTextWriter(); var write = writer.write; var writeLine = writer.writeLine; var increaseIndent = writer.increaseIndent; @@ -6222,8 +6357,6 @@ var ts; var scopeEmitEnd = function () { }; var sourceMapData; - function writeSymbol(symbol, enclosingDeclaration, meaning) { - } function initializeEmitterWithSourceMaps() { var sourceMapDir; var sourceMapSourceIndex = -1; @@ -6328,7 +6461,7 @@ var ts; } function recordNewSourceFileStart(node) { var sourcesDirectoryPath = compilerOptions.sourceRoot ? program.getCommonSourceDirectory() : sourceMapDir; - sourceMapData.sourceMapSources.push(ts.getRelativePathToDirectoryOrUrl(sourcesDirectoryPath, node.filename, compilerHost.getCurrentDirectory(), true)); + sourceMapData.sourceMapSources.push(ts.getRelativePathToDirectoryOrUrl(sourcesDirectoryPath, node.filename, compilerHost.getCurrentDirectory(), compilerHost.getCanonicalFileName, true)); sourceMapSourceIndex = sourceMapData.sourceMapSources.length - 1; sourceMapData.inputSourceFileNames.push(node.filename); } @@ -6355,7 +6488,7 @@ var ts; if (scopeName) { recordScopeNameStart(scopeName); } - else if (node.kind === 172 /* FunctionDeclaration */ || node.kind === 141 /* FunctionExpression */ || node.kind === 120 /* Method */ || node.kind === 122 /* GetAccessor */ || node.kind === 123 /* SetAccessor */ || node.kind === 177 /* ModuleDeclaration */ || node.kind === 174 /* ClassDeclaration */ || node.kind === 176 /* EnumDeclaration */) { + else if (node.kind === 174 /* FunctionDeclaration */ || node.kind === 143 /* FunctionExpression */ || node.kind === 120 /* Method */ || node.kind === 122 /* GetAccessor */ || node.kind === 123 /* SetAccessor */ || node.kind === 179 /* ModuleDeclaration */ || node.kind === 176 /* ClassDeclaration */ || node.kind === 178 /* EnumDeclaration */) { if (node.name) { scopeName = node.name.text; } @@ -6374,20 +6507,6 @@ var ts; writeCommentRange(comment, writer); recordSourceMapSpan(comment.end); } - var escapedCharsRegExp = /[\t\v\f\b\0\r\n\"\u2028\u2029\u0085]/g; - var escapedCharsMap = { - "\t": "\\t", - "\v": "\\v", - "\f": "\\f", - "\b": "\\b", - "\0": "\\0", - "\r": "\\r", - "\n": "\\n", - "\"": "\\\"", - "\u2028": "\\u2028", - "\u2029": "\\u2029", - "\u0085": "\\u0085" - }; function serializeSourceMapContents(version, file, sourceRoot, sources, names, mappings) { if (typeof JSON !== "undefined") { return JSON.stringify({ @@ -6399,19 +6518,14 @@ var ts; mappings: mappings }); } - return "{\"version\":" + version + ",\"file\":\"" + escapeString(file) + "\",\"sourceRoot\":\"" + escapeString(sourceRoot) + "\",\"sources\":[" + serializeStringArray(sources) + "],\"names\":[" + serializeStringArray(names) + "],\"mappings\":\"" + escapeString(mappings) + "\"}"; - function escapeString(s) { - return escapedCharsRegExp.test(s) ? s.replace(escapedCharsRegExp, function (c) { - return escapedCharsMap[c] || c; - }) : s; - } + return "{\"version\":" + version + ",\"file\":\"" + ts.escapeString(file) + "\",\"sourceRoot\":\"" + ts.escapeString(sourceRoot) + "\",\"sources\":[" + serializeStringArray(sources) + "],\"names\":[" + serializeStringArray(names) + "],\"mappings\":\"" + ts.escapeString(mappings) + "\"}"; function serializeStringArray(list) { var output = ""; for (var i = 0, n = list.length; i < n; i++) { if (i) { output += ","; } - output += "\"" + escapeString(list[i]) + "\""; + output += "\"" + ts.escapeString(list[i]) + "\""; } return output; } @@ -6445,7 +6559,7 @@ var ts; } if (!ts.isRootedDiskPath(sourceMapDir) && !ts.isUrl(sourceMapDir)) { sourceMapDir = ts.combinePaths(program.getCommonSourceDirectory(), sourceMapDir); - sourceMapData.jsSourceMappingURL = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizePath(jsFilePath)), ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL), compilerHost.getCurrentDirectory(), true); + sourceMapData.jsSourceMappingURL = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizePath(jsFilePath)), ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL), compilerHost.getCurrentDirectory(), compilerHost.getCanonicalFileName, true); } else { sourceMapData.jsSourceMappingURL = ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL); @@ -6456,7 +6570,7 @@ var ts; } function emitNodeWithMap(node) { if (node) { - if (node.kind != 182 /* SourceFile */) { + if (node.kind != 184 /* SourceFile */) { recordEmitNodeStartSpan(node); emitNode(node); recordEmitNodeEndSpan(node); @@ -6495,25 +6609,42 @@ var ts; emit(node); } } - function emitCommaList(nodes, count) { - if (!(count >= 0)) - count = nodes.length; - if (nodes) { - for (var i = 0; i < count; i++) { - if (i) - write(", "); - emit(nodes[i]); + function emitTrailingCommaIfPresent(nodeList, isMultiline) { + if (nodeList.hasTrailingComma) { + write(","); + if (isMultiline) { + writeLine(); } } } - function emitMultiLineList(nodes) { + function emitCommaList(nodes, includeTrailingComma, count) { + if (!(count >= 0)) { + count = nodes.length; + } + if (nodes) { + for (var i = 0; i < count; i++) { + if (i) { + write(", "); + } + emit(nodes[i]); + } + if (includeTrailingComma) { + emitTrailingCommaIfPresent(nodes, false); + } + } + } + function emitMultiLineList(nodes, includeTrailingComma) { if (nodes) { for (var i = 0; i < nodes.length; i++) { - if (i) + if (i) { write(","); + } writeLine(); emit(nodes[i]); } + if (includeTrailingComma) { + emitTrailingCommaIfPresent(nodes, true); + } } } function emitLines(nodes) { @@ -6553,28 +6684,28 @@ var ts; var parent = node.parent; switch (parent.kind) { case 118 /* Parameter */: - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: case 119 /* Property */: - case 134 /* PropertyAssignment */: - case 181 /* EnumMember */: + case 136 /* PropertyAssignment */: + case 183 /* EnumMember */: case 120 /* Method */: - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 141 /* FunctionExpression */: - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 176 /* EnumDeclaration */: - case 177 /* ModuleDeclaration */: - case 179 /* ImportDeclaration */: + case 143 /* FunctionExpression */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: + case 179 /* ModuleDeclaration */: + case 181 /* ImportDeclaration */: return parent.name === node; - case 158 /* BreakStatement */: - case 157 /* ContinueStatement */: - case 180 /* ExportAssignment */: + case 160 /* BreakStatement */: + case 159 /* ContinueStatement */: + case 182 /* ExportAssignment */: return false; - case 164 /* LabeledStatement */: + case 166 /* LabeledStatement */: return node.parent.label === node; - case 168 /* CatchBlock */: + case 170 /* CatchBlock */: return node.parent.variable === node; } } @@ -6612,14 +6743,14 @@ var ts; if (node.flags & 256 /* MultiLine */) { write("["); increaseIndent(); - emitMultiLineList(node.elements); + emitMultiLineList(node.elements, true); decreaseIndent(); writeLine(); write("]"); } else { write("["); - emitCommaList(node.elements); + emitCommaList(node.elements, true); write("]"); } } @@ -6630,14 +6761,14 @@ var ts; else if (node.flags & 256 /* MultiLine */) { write("{"); increaseIndent(); - emitMultiLineList(node.properties); + emitMultiLineList(node.properties, compilerOptions.target >= 1 /* ES5 */); decreaseIndent(); writeLine(); write("}"); } else { write("{ "); - emitCommaList(node.properties); + emitCommaList(node.properties, compilerOptions.target >= 1 /* ES5 */); write(" }"); } } @@ -6649,14 +6780,15 @@ var ts; emitTrailingComments(node); } function emitPropertyAccess(node) { - var text = resolver.getPropertyAccessSubstitution(node); - if (text) { - write(text); - return; + var constantValue = resolver.getConstantValue(node); + if (constantValue !== undefined) { + write(constantValue.toString() + " /* " + ts.identifierToString(node.right) + " */"); + } + else { + emit(node.left); + write("."); + emit(node.right); } - emit(node.left); - write("."); - emit(node.right); } function emitIndexedAccess(node) { emit(node.object); @@ -6672,20 +6804,20 @@ var ts; } else { emit(node.func); - superCall = node.func.kind === 135 /* PropertyAccess */ && node.func.left.kind === 85 /* SuperKeyword */; + superCall = node.func.kind === 137 /* PropertyAccess */ && node.func.left.kind === 85 /* SuperKeyword */; } if (superCall) { write(".call("); emitThis(node.func); if (node.arguments.length) { write(", "); - emitCommaList(node.arguments); + emitCommaList(node.arguments, false); } write(")"); } else { write("("); - emitCommaList(node.arguments); + emitCommaList(node.arguments, false); write(")"); } } @@ -6694,17 +6826,17 @@ var ts; emit(node.func); if (node.arguments) { write("("); - emitCommaList(node.arguments); + emitCommaList(node.arguments, false); write(")"); } } function emitParenExpression(node) { - if (node.expression.kind === 139 /* TypeAssertion */) { + if (node.expression.kind === 141 /* TypeAssertion */) { var operand = node.expression.operand; - while (operand.kind == 139 /* TypeAssertion */) { + while (operand.kind == 141 /* TypeAssertion */) { operand = operand.operand; } - if (operand.kind !== 143 /* PrefixOperator */ && operand.kind !== 144 /* PostfixOperator */ && operand.kind !== 138 /* NewExpression */ && !(operand.kind === 137 /* CallExpression */ && node.parent.kind === 138 /* NewExpression */) && !(operand.kind === 141 /* FunctionExpression */ && node.parent.kind === 137 /* CallExpression */)) { + if (operand.kind !== 145 /* PrefixOperator */ && operand.kind !== 146 /* PostfixOperator */ && operand.kind !== 140 /* NewExpression */ && !(operand.kind === 139 /* CallExpression */ && node.parent.kind === 140 /* NewExpression */) && !(operand.kind === 143 /* FunctionExpression */ && node.parent.kind === 139 /* CallExpression */)) { emit(operand); return; } @@ -6714,13 +6846,13 @@ var ts; write(")"); } function emitUnaryExpression(node) { - if (node.kind === 143 /* PrefixOperator */) { + if (node.kind === 145 /* PrefixOperator */) { write(ts.tokenToString(node.operator)); } if (node.operator >= 59 /* Identifier */) { write(" "); } - else if (node.kind === 143 /* PrefixOperator */ && node.operand.kind === 143 /* PrefixOperator */) { + else if (node.kind === 145 /* PrefixOperator */ && node.operand.kind === 145 /* PrefixOperator */) { var operand = node.operand; if (node.operator === 28 /* PlusToken */ && (operand.operator === 28 /* PlusToken */ || operand.operator === 33 /* PlusPlusToken */)) { write(" "); @@ -6730,7 +6862,7 @@ var ts; } } emit(node.operand); - if (node.kind === 144 /* PostfixOperator */) { + if (node.kind === 146 /* PostfixOperator */) { write(ts.tokenToString(node.operator)); } } @@ -6753,8 +6885,8 @@ var ts; emitToken(9 /* OpenBraceToken */, node.pos); increaseIndent(); scopeEmitStart(node.parent); - if (node.kind === 178 /* ModuleBlock */) { - ts.Debug.assert(node.parent.kind === 177 /* ModuleDeclaration */); + if (node.kind === 180 /* ModuleBlock */) { + ts.Debug.assert(node.parent.kind === 179 /* ModuleDeclaration */); emitCaptureThisForNodeIfNecessary(node.parent); } emitLines(node.statements); @@ -6764,7 +6896,7 @@ var ts; scopeEmitEnd(); } function emitEmbeddedStatement(node) { - if (node.kind === 148 /* Block */) { + if (node.kind === 150 /* Block */) { write(" "); emit(node); } @@ -6776,7 +6908,7 @@ var ts; } } function emitExpressionStatement(node) { - var isArrowExpression = node.expression.kind === 142 /* ArrowFunction */; + var isArrowExpression = node.expression.kind === 144 /* ArrowFunction */; emitLeadingComments(node); if (isArrowExpression) write("("); @@ -6797,7 +6929,7 @@ var ts; if (node.elseStatement) { writeLine(); emitToken(70 /* ElseKeyword */, node.thenStatement.end); - if (node.elseStatement.kind === 152 /* IfStatement */) { + if (node.elseStatement.kind === 154 /* IfStatement */) { write(" "); emit(node.elseStatement); } @@ -6810,7 +6942,7 @@ var ts; function emitDoStatement(node) { write("do"); emitEmbeddedStatement(node.statement); - if (node.statement.kind === 148 /* Block */) { + if (node.statement.kind === 150 /* Block */) { write(" "); } else { @@ -6833,7 +6965,7 @@ var ts; if (node.declarations) { emitToken(92 /* VarKeyword */, endPos); write(" "); - emitCommaList(node.declarations); + emitCommaList(node.declarations, false); } if (node.initializer) { emit(node.initializer); @@ -6863,7 +6995,7 @@ var ts; emitEmbeddedStatement(node.statement); } function emitBreakOrContinueStatement(node) { - emitToken(node.kind === 158 /* BreakStatement */ ? 60 /* BreakKeyword */ : 65 /* ContinueKeyword */, node.pos); + emitToken(node.kind === 160 /* BreakStatement */ ? 60 /* BreakKeyword */ : 65 /* ContinueKeyword */, node.pos); emitOptional(" ", node.label); write(";"); } @@ -6895,7 +7027,7 @@ var ts; emitToken(10 /* CloseBraceToken */, node.clauses.end); } function emitCaseOrDefaultClause(node) { - if (node.kind === 162 /* CaseClause */) { + if (node.kind === 164 /* CaseClause */) { write("case "); emit(node.expression); write(":"); @@ -6944,7 +7076,7 @@ var ts; function getContainingModule(node) { do { node = node.parent; - } while (node && node.kind !== 177 /* ModuleDeclaration */); + } while (node && node.kind !== 179 /* ModuleDeclaration */); return node; } function emitModuleMemberName(node) { @@ -6967,7 +7099,7 @@ var ts; emitLeadingComments(node); if (!(node.flags & 1 /* Export */)) write("var "); - emitCommaList(node.declarations); + emitCommaList(node.declarations, false); write(";"); emitTrailingComments(node); } @@ -7047,7 +7179,7 @@ var ts; emitLeadingComments(node); } write("function "); - if (node.kind === 172 /* FunctionDeclaration */ || (node.kind === 141 /* FunctionExpression */ && node.name)) { + if (node.kind === 174 /* FunctionDeclaration */ || (node.kind === 143 /* FunctionExpression */ && node.name)) { emit(node.name); } emitSignatureAndBody(node); @@ -7067,7 +7199,7 @@ var ts; increaseIndent(); write("("); if (node) { - emitCommaList(node.parameters, node.parameters.length - (ts.hasRestParameters(node) ? 1 : 0)); + emitCommaList(node.parameters, false, node.parameters.length - (ts.hasRestParameters(node) ? 1 : 0)); } write(")"); decreaseIndent(); @@ -7077,16 +7209,16 @@ var ts; write(" {"); scopeEmitStart(node); increaseIndent(); - emitDetachedComments(node.body.kind === 173 /* FunctionBlock */ ? node.body.statements : node.body); + emitDetachedComments(node.body.kind === 175 /* FunctionBlock */ ? node.body.statements : node.body); var startIndex = 0; - if (node.body.kind === 173 /* FunctionBlock */) { + if (node.body.kind === 175 /* FunctionBlock */) { startIndex = emitDirectivePrologues(node.body.statements, true); } var outPos = writer.getTextPos(); emitCaptureThisForNodeIfNecessary(node); emitDefaultValueAssignments(node); emitRestParameter(node); - if (node.body.kind !== 173 /* FunctionBlock */ && outPos === writer.getTextPos()) { + if (node.body.kind !== 175 /* FunctionBlock */ && outPos === writer.getTextPos()) { decreaseIndent(); write(" "); emitStart(node.body); @@ -7099,7 +7231,7 @@ var ts; emitEnd(node.body); } else { - if (node.body.kind === 173 /* FunctionBlock */) { + if (node.body.kind === 175 /* FunctionBlock */) { emitLinesStartingAt(node.body.statements, startIndex); } else { @@ -7111,7 +7243,7 @@ var ts; emitTrailingComments(node.body); } writeLine(); - if (node.body.kind === 173 /* FunctionBlock */) { + if (node.body.kind === 175 /* FunctionBlock */) { emitLeadingCommentsOfPosition(node.body.statements.end); decreaseIndent(); emitToken(10 /* CloseBraceToken */, node.body.statements.end); @@ -7137,9 +7269,9 @@ var ts; function findInitialSuperCall(ctor) { if (ctor.body) { var statement = ctor.body.statements[0]; - if (statement && statement.kind === 151 /* ExpressionStatement */) { + if (statement && statement.kind === 153 /* ExpressionStatement */) { var expr = statement.expression; - if (expr && expr.kind === 137 /* CallExpression */) { + if (expr && expr.kind === 139 /* CallExpression */) { var func = expr.func; if (func && func.kind === 85 /* SuperKeyword */) { return statement; @@ -7453,7 +7585,7 @@ var ts; } } function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration) { - if (moduleDeclaration.body.kind === 177 /* ModuleDeclaration */) { + if (moduleDeclaration.body.kind === 179 /* ModuleDeclaration */) { var recursiveInnerModule = getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration.body); return recursiveInnerModule || moduleDeclaration.body; } @@ -7475,7 +7607,7 @@ var ts; write(resolver.getLocalNameOfContainer(node)); emitEnd(node.name); write(") "); - if (node.body.kind === 178 /* ModuleBlock */) { + if (node.body.kind === 180 /* ModuleBlock */) { emit(node.body); } else { @@ -7509,7 +7641,7 @@ var ts; emitImportDeclaration = !ts.isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportedViaEntityName(node); } if (emitImportDeclaration) { - if (node.externalModuleName && node.parent.kind === 182 /* SourceFile */ && compilerOptions.module === 2 /* AMD */) { + if (node.externalModuleName && node.parent.kind === 184 /* SourceFile */ && compilerOptions.module === 2 /* AMD */) { if (node.flags & 1 /* Export */) { writeLine(); emitLeadingComments(node); @@ -7549,7 +7681,7 @@ var ts; function getExternalImportDeclarations(node) { var result = []; ts.forEach(node.statements, function (stat) { - if (stat.kind === 179 /* ImportDeclaration */ && stat.externalModuleName && resolver.isReferencedImportDeclaration(stat)) { + if (stat.kind === 181 /* ImportDeclaration */ && stat.externalModuleName && resolver.isReferencedImportDeclaration(stat)) { result.push(stat); } }); @@ -7557,7 +7689,7 @@ var ts; } function getFirstExportAssignment(sourceFile) { return ts.forEach(sourceFile.statements, function (node) { - if (node.kind === 180 /* ExportAssignment */) { + if (node.kind === 182 /* ExportAssignment */) { return node; } }); @@ -7696,94 +7828,94 @@ var ts; return emitLiteral(node); case 116 /* QualifiedName */: return emitPropertyAccess(node); - case 132 /* ArrayLiteral */: + case 134 /* ArrayLiteral */: return emitArrayLiteral(node); - case 133 /* ObjectLiteral */: + case 135 /* ObjectLiteral */: return emitObjectLiteral(node); - case 134 /* PropertyAssignment */: + case 136 /* PropertyAssignment */: return emitPropertyAssignment(node); - case 135 /* PropertyAccess */: + case 137 /* PropertyAccess */: return emitPropertyAccess(node); - case 136 /* IndexedAccess */: + case 138 /* IndexedAccess */: return emitIndexedAccess(node); - case 137 /* CallExpression */: + case 139 /* CallExpression */: return emitCallExpression(node); - case 138 /* NewExpression */: + case 140 /* NewExpression */: return emitNewExpression(node); - case 139 /* TypeAssertion */: + case 141 /* TypeAssertion */: return emit(node.operand); - case 140 /* ParenExpression */: + case 142 /* ParenExpression */: return emitParenExpression(node); - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: return emitFunctionDeclaration(node); - case 143 /* PrefixOperator */: - case 144 /* PostfixOperator */: + case 145 /* PrefixOperator */: + case 146 /* PostfixOperator */: return emitUnaryExpression(node); - case 145 /* BinaryExpression */: + case 147 /* BinaryExpression */: return emitBinaryExpression(node); - case 146 /* ConditionalExpression */: + case 148 /* ConditionalExpression */: return emitConditionalExpression(node); - case 147 /* OmittedExpression */: + case 149 /* OmittedExpression */: return; - case 148 /* Block */: - case 167 /* TryBlock */: - case 169 /* FinallyBlock */: - case 173 /* FunctionBlock */: - case 178 /* ModuleBlock */: + case 150 /* Block */: + case 169 /* TryBlock */: + case 171 /* FinallyBlock */: + case 175 /* FunctionBlock */: + case 180 /* ModuleBlock */: return emitBlock(node); - case 149 /* VariableStatement */: + case 151 /* VariableStatement */: return emitVariableStatement(node); - case 150 /* EmptyStatement */: + case 152 /* EmptyStatement */: return write(";"); - case 151 /* ExpressionStatement */: + case 153 /* ExpressionStatement */: return emitExpressionStatement(node); - case 152 /* IfStatement */: + case 154 /* IfStatement */: return emitIfStatement(node); - case 153 /* DoStatement */: + case 155 /* DoStatement */: return emitDoStatement(node); - case 154 /* WhileStatement */: + case 156 /* WhileStatement */: return emitWhileStatement(node); - case 155 /* ForStatement */: + case 157 /* ForStatement */: return emitForStatement(node); - case 156 /* ForInStatement */: + case 158 /* ForInStatement */: return emitForInStatement(node); - case 157 /* ContinueStatement */: - case 158 /* BreakStatement */: + case 159 /* ContinueStatement */: + case 160 /* BreakStatement */: return emitBreakOrContinueStatement(node); - case 159 /* ReturnStatement */: + case 161 /* ReturnStatement */: return emitReturnStatement(node); - case 160 /* WithStatement */: + case 162 /* WithStatement */: return emitWithStatement(node); - case 161 /* SwitchStatement */: + case 163 /* SwitchStatement */: return emitSwitchStatement(node); - case 162 /* CaseClause */: - case 163 /* DefaultClause */: + case 164 /* CaseClause */: + case 165 /* DefaultClause */: return emitCaseOrDefaultClause(node); - case 164 /* LabeledStatement */: + case 166 /* LabeledStatement */: return emitLabelledStatement(node); - case 165 /* ThrowStatement */: + case 167 /* ThrowStatement */: return emitThrowStatement(node); - case 166 /* TryStatement */: + case 168 /* TryStatement */: return emitTryStatement(node); - case 168 /* CatchBlock */: + case 170 /* CatchBlock */: return emitCatchBlock(node); - case 170 /* DebuggerStatement */: + case 172 /* DebuggerStatement */: return emitDebuggerStatement(node); - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: return emitVariableDeclaration(node); - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: return emitClassDeclaration(node); - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: return emitInterfaceDeclaration(node); - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: return emitEnumDeclaration(node); - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return emitModuleDeclaration(node); - case 179 /* ImportDeclaration */: + case 181 /* ImportDeclaration */: return emitImportDeclaration(node); - case 182 /* SourceFile */: + case 184 /* SourceFile */: return emitSourceFile(node); } } @@ -7791,7 +7923,7 @@ var ts; return detachedCommentsInfo !== undefined && detachedCommentsInfo[detachedCommentsInfo.length - 1].nodePos === pos; } function getLeadingCommentsWithoutDetachedComments() { - var leadingComments = ts.getLeadingComments(currentSourceFile.text, detachedCommentsInfo[detachedCommentsInfo.length - 1].detachedCommentEndPos); + var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, detachedCommentsInfo[detachedCommentsInfo.length - 1].detachedCommentEndPos); if (detachedCommentsInfo.length - 1) { detachedCommentsInfo.pop(); } @@ -7801,13 +7933,13 @@ var ts; return leadingComments; } function getLeadingCommentsToEmit(node) { - if (node.parent.kind === 182 /* SourceFile */ || node.pos !== node.parent.pos) { + if (node.parent.kind === 184 /* SourceFile */ || node.pos !== node.parent.pos) { var leadingComments; if (hasDetachedComments(node.pos)) { leadingComments = getLeadingCommentsWithoutDetachedComments(); } else { - leadingComments = ts.getLeadingCommentsOfNode(node, currentSourceFile); + leadingComments = ts.getLeadingCommentRangesOfNode(node, currentSourceFile); } return leadingComments; } @@ -7818,8 +7950,8 @@ var ts; emitComments(leadingComments, true, writer, writeComment); } function emitTrailingDeclarationComments(node) { - if (node.parent.kind === 182 /* SourceFile */ || node.end !== node.parent.end) { - var trailingComments = ts.getTrailingComments(currentSourceFile.text, node.end); + if (node.parent.kind === 184 /* SourceFile */ || node.end !== node.parent.end) { + var trailingComments = ts.getTrailingCommentRanges(currentSourceFile.text, node.end); emitComments(trailingComments, false, writer, writeComment); } } @@ -7829,13 +7961,13 @@ var ts; leadingComments = getLeadingCommentsWithoutDetachedComments(); } else { - leadingComments = ts.getLeadingComments(currentSourceFile.text, pos); + leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, pos); } emitNewLineBeforeLeadingComments({ pos: pos, end: pos }, leadingComments, writer); emitComments(leadingComments, true, writer, writeComment); } function emitDetachedCommentsAtPosition(node) { - var leadingComments = ts.getLeadingComments(currentSourceFile.text, node.pos); + var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, node.pos); if (leadingComments) { var detachedComments = []; var lastComment; @@ -7897,7 +8029,7 @@ var ts; writeEmittedFiles(writer.getText(), compilerOptions.emitBOM); } function emitDeclarations(jsFilePath, root) { - var writer = createTextWriter(writeSymbol); + var writer = createTextWriterWithSymbolWriter(); var write = writer.write; var writeLine = writer.writeLine; var increaseIndent = writer.increaseIndent; @@ -7908,11 +8040,23 @@ var ts; } : writeJsDocComments; var aliasDeclarationEmitInfo = []; var getSymbolVisibilityDiagnosticMessage; + function createTextWriterWithSymbolWriter() { + var writer = createTextWriter(); + writer.trackSymbol = trackSymbol; + writer.writeKeyword = writer.write; + writer.writeOperator = writer.write; + writer.writePunctuation = writer.write; + writer.writeSpace = writer.write; + writer.writeStringLiteral = writer.writeLiteral; + writer.writeParameter = writer.write; + writer.writeSymbol = writer.write; + return writer; + } function writeAsychronousImportDeclarations(importDeclarations) { var oldWriter = writer; ts.forEach(importDeclarations, function (aliasToWrite) { var aliasEmitInfo = ts.forEach(aliasDeclarationEmitInfo, function (declEmitInfo) { return declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined; }); - writer = createTextWriter(writeSymbol); + writer = createTextWriterWithSymbolWriter(); for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) { writer.increaseIndent(); } @@ -7921,10 +8065,9 @@ var ts; }); writer = oldWriter; } - function writeSymbol(symbol, enclosingDeclaration, meaning) { + function trackSymbol(symbol, enclosingDeclaration, meaning) { var symbolAccesibilityResult = resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning); if (symbolAccesibilityResult.accessibility === 0 /* Accessible */) { - resolver.writeSymbol(symbol, enclosingDeclaration, meaning, writer); if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) { writeAsychronousImportDeclarations(symbolAccesibilityResult.aliasesToMakeVisible); } @@ -7999,7 +8142,7 @@ var ts; if (node.flags & 1 /* Export */) { write("export "); } - if (node.kind !== 175 /* InterfaceDeclaration */) { + if (node.kind !== 177 /* InterfaceDeclaration */) { write("declare "); } } @@ -8055,7 +8198,7 @@ var ts; emitDeclarationFlags(node); write("module "); emitSourceTextOfNode(node.name); - while (node.body.kind !== 178 /* ModuleBlock */) { + while (node.body.kind !== 180 /* ModuleBlock */) { node = node.body; write("."); emitSourceTextOfNode(node.name); @@ -8103,10 +8246,10 @@ var ts; function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; switch (node.parent.kind) { - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1; break; - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1; break; case 125 /* ConstructSignature */: @@ -8119,14 +8262,14 @@ var ts; if (node.parent.flags & 128 /* Static */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.parent.kind === 174 /* ClassDeclaration */) { + else if (node.parent.parent.kind === 176 /* ClassDeclaration */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; } else { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; } break; - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1; break; default: @@ -8164,7 +8307,7 @@ var ts; resolver.writeTypeAtLocation(node, enclosingDeclaration, 1 /* WriteArrayAsGenericType */ | 2 /* UseTypeOfFunction */, writer); function getHeritageClauseVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; - if (node.parent.kind === 174 /* ClassDeclaration */) { + if (node.parent.kind === 176 /* ClassDeclaration */) { if (symbolAccesibilityResult.errorModuleName) { diagnosticMessage = isImplementsList ? ts.Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2; } @@ -8249,7 +8392,7 @@ var ts; writeLine(); } function emitVariableDeclaration(node) { - if (node.kind !== 171 /* VariableDeclaration */ || resolver.isDeclarationVisible(node)) { + if (node.kind !== 173 /* VariableDeclaration */ || resolver.isDeclarationVisible(node)) { emitSourceTextOfNode(node.name); if (node.kind === 119 /* Property */ && (node.flags & 4 /* QuestionMark */)) { write("?"); @@ -8262,14 +8405,14 @@ var ts; } function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; - if (node.kind === 171 /* VariableDeclaration */) { + if (node.kind === 173 /* VariableDeclaration */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Exported_variable_0_has_or_is_using_private_name_1; } else if (node.kind === 119 /* Property */) { if (node.flags & 128 /* Static */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.kind === 174 /* ClassDeclaration */) { + else if (node.parent.kind === 176 /* ClassDeclaration */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1; } else { @@ -8340,10 +8483,10 @@ var ts; } } function emitFunctionDeclaration(node) { - if ((node.kind !== 172 /* FunctionDeclaration */ || resolver.isDeclarationVisible(node)) && !resolver.isImplementationOfOverload(node)) { + if ((node.kind !== 174 /* FunctionDeclaration */ || resolver.isDeclarationVisible(node)) && !resolver.isImplementationOfOverload(node)) { emitJsDocComments(node); emitDeclarationFlags(node); - if (node.kind === 172 /* FunctionDeclaration */) { + if (node.kind === 174 /* FunctionDeclaration */) { write("function "); emitSourceTextOfNode(node.name); } @@ -8405,14 +8548,14 @@ var ts; if (node.flags & 128 /* Static */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0; } - else if (node.parent.kind === 174 /* ClassDeclaration */) { + else if (node.parent.kind === 176 /* ClassDeclaration */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0; } else { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0; } break; - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_private_name_0; break; default: @@ -8456,14 +8599,14 @@ var ts; if (node.parent.flags & 128 /* Static */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.parent.kind === 174 /* ClassDeclaration */) { + else if (node.parent.parent.kind === 176 /* ClassDeclaration */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; } else { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; } break; - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1; break; default: @@ -8479,7 +8622,7 @@ var ts; function emitNode(node) { switch (node.kind) { case 121 /* Constructor */: - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: case 120 /* Method */: return emitFunctionDeclaration(node); case 125 /* ConstructSignature */: @@ -8490,44 +8633,44 @@ var ts; case 122 /* GetAccessor */: case 123 /* SetAccessor */: return emitAccessorDeclaration(node); - case 149 /* VariableStatement */: + case 151 /* VariableStatement */: return emitVariableStatement(node); case 119 /* Property */: return emitPropertyDeclaration(node); - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: return emitInterfaceDeclaration(node); - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: return emitClassDeclaration(node); - case 181 /* EnumMember */: + case 183 /* EnumMember */: return emitEnumMemberDeclaration(node); - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: return emitEnumDeclaration(node); - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return emitModuleDeclaration(node); - case 179 /* ImportDeclaration */: + case 181 /* ImportDeclaration */: return emitImportDeclaration(node); - case 180 /* ExportAssignment */: + case 182 /* ExportAssignment */: return emitExportAssignment(node); - case 182 /* SourceFile */: + case 184 /* SourceFile */: return emitSourceFile(node); } } - function resolveScriptReference(sourceFile, reference) { + function tryResolveScriptReference(sourceFile, reference) { var referenceFileName = ts.normalizePath(ts.combinePaths(ts.getDirectoryPath(sourceFile.filename), reference.filename)); return program.getSourceFile(referenceFileName); } var referencePathsOutput = ""; function writeReferencePath(referencedFile) { - var declFileName = referencedFile.flags & 1024 /* DeclarationFile */ ? referencedFile.filename : shouldEmitToOwnFile(referencedFile, compilerOptions) ? getOwnEmitOutputFilePath(referencedFile, ".d.ts") : ts.getModuleNameFromFilename(compilerOptions.out) + ".d.ts"; - declFileName = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizeSlashes(jsFilePath)), declFileName, compilerHost.getCurrentDirectory(), false); + var declFileName = referencedFile.flags & 1024 /* DeclarationFile */ ? referencedFile.filename : shouldEmitToOwnFile(referencedFile, compilerOptions) ? getOwnEmitOutputFilePath(referencedFile, ".d.ts") : ts.removeFileExtension(compilerOptions.out) + ".d.ts"; + declFileName = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizeSlashes(jsFilePath)), declFileName, compilerHost.getCurrentDirectory(), compilerHost.getCanonicalFileName, false); referencePathsOutput += "/// " + newLine; } if (root) { if (!compilerOptions.noResolve) { var addedGlobalFileReference = false; ts.forEach(root.referencedFiles, function (fileReference) { - var referencedFile = resolveScriptReference(root, fileReference); - if ((referencedFile.flags & 1024 /* DeclarationFile */) || shouldEmitToOwnFile(referencedFile, compilerOptions) || !addedGlobalFileReference) { + var referencedFile = tryResolveScriptReference(root, fileReference); + if (referencedFile && ((referencedFile.flags & 1024 /* DeclarationFile */) || shouldEmitToOwnFile(referencedFile, compilerOptions) || !addedGlobalFileReference)) { writeReferencePath(referencedFile); if (!isExternalModuleOrDeclarationFile(referencedFile)) { addedGlobalFileReference = true; @@ -8543,8 +8686,8 @@ var ts; if (!isExternalModuleOrDeclarationFile(sourceFile)) { if (!compilerOptions.noResolve) { ts.forEach(sourceFile.referencedFiles, function (fileReference) { - var referencedFile = resolveScriptReference(sourceFile, fileReference); - if (isExternalModuleOrDeclarationFile(referencedFile) && !ts.contains(emittedReferencedFiles, referencedFile)) { + var referencedFile = tryResolveScriptReference(sourceFile, fileReference); + if (referencedFile && (isExternalModuleOrDeclarationFile(referencedFile) && !ts.contains(emittedReferencedFiles, referencedFile))) { writeReferencePath(referencedFile); emittedReferencedFiles.push(referencedFile); } @@ -8566,7 +8709,7 @@ var ts; } }); declarationOutput += synchronousDeclarationOutput.substring(appliedSyncOutputPos); - writeFile(ts.getModuleNameFromFilename(jsFilePath) + ".d.ts", declarationOutput, compilerOptions.emitBOM); + writeFile(ts.removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, compilerOptions.emitBOM); } } var hasSemanticErrors = resolver.hasSemanticErrors(); @@ -8583,13 +8726,18 @@ var ts; emitFile(jsFilePath, sourceFile); } }); + if (compilerOptions.out) { + emitFile(compilerOptions.out); + } } else { - var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, ".js"); - emitFile(jsFilePath, targetSourceFile); - } - if (compilerOptions.out) { - emitFile(compilerOptions.out); + if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) { + var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, ".js"); + emitFile(jsFilePath, targetSourceFile); + } + else if (!ts.isDeclarationFile(targetSourceFile) && compilerOptions.out) { + emitFile(compilerOptions.out); + } } diagnostics.sort(ts.compareDiagnostics); diagnostics = ts.deduplicateSortedDiagnostics(diagnostics); @@ -8631,6 +8779,33 @@ var ts; return undefined; } ts.getDeclarationOfKind = getDeclarationOfKind; + var stringWriters = []; + function getSingleLineStringWriter() { + if (stringWriters.length == 0) { + var str = ""; + var writeText = function (text) { return str += text; }; + return { + string: function () { return str; }, + writeKeyword: writeText, + writeOperator: writeText, + writePunctuation: writeText, + writeSpace: writeText, + writeStringLiteral: writeText, + writeParameter: writeText, + writeSymbol: writeText, + writeLine: function () { return str += " "; }, + increaseIndent: function () { + }, + decreaseIndent: function () { + }, + clear: function () { return str = ""; }, + trackSymbol: function () { + } + }; + } + return stringWriters.pop(); + } + ts.getSingleLineStringWriter = getSingleLineStringWriter; function createTypeChecker(program, fullTypeCheck) { var Symbol = ts.objectAllocator.getSymbolConstructor(); var Type = ts.objectAllocator.getTypeConstructor(); @@ -8659,13 +8834,21 @@ var ts; getSymbolsInScope: getSymbolsInScope, getSymbolInfo: getSymbolInfo, getTypeOfNode: getTypeOfNode, - getApparentType: getApparentType, typeToString: typeToString, + getSymbolDisplayBuilder: getSymbolDisplayBuilder, symbolToString: symbolToString, - getAugmentedPropertiesOfApparentType: getAugmentedPropertiesOfApparentType, - getRootSymbol: getRootSymbol, + getAugmentedPropertiesOfType: getAugmentedPropertiesOfType, + getRootSymbols: getRootSymbols, getContextualType: getContextualType, - getFullyQualifiedName: getFullyQualifiedName + getFullyQualifiedName: getFullyQualifiedName, + getResolvedSignature: getResolvedSignature, + getEnumMemberValue: getEnumMemberValue, + isValidPropertyAccess: isValidPropertyAccess, + getSignatureFromDeclaration: getSignatureFromDeclaration, + isImplementationOfOverload: isImplementationOfOverload, + getAliasedSymbol: resolveImport, + isUndefinedSymbol: function (symbol) { return symbol === undefinedSymbol; }, + isArgumentsSymbol: function (symbol) { return symbol === argumentsSymbol; } }; var undefinedSymbol = createSymbol(2 /* Property */ | 33554432 /* Transient */, "undefined"); var argumentsSymbol = createSymbol(2 /* Property */ | 33554432 /* Transient */, "arguments"); @@ -8695,6 +8878,7 @@ var ts; var globalBooleanType; var globalRegExpType; var tupleTypes = {}; + var unionTypes = {}; var stringLiteralTypes = {}; var emitExtends = false; var mergedSymbols = []; @@ -8826,10 +9010,10 @@ var ts; return nodeLinks[node.id] || (nodeLinks[node.id] = {}); } function getSourceFile(node) { - return ts.getAncestor(node, 182 /* SourceFile */); + return ts.getAncestor(node, 184 /* SourceFile */); } function isGlobalSourceFile(node) { - return node.kind === 182 /* SourceFile */ && !ts.isExternalModule(node); + return node.kind === 184 /* SourceFile */ && !ts.isExternalModule(node); } function getSymbol(symbols, name, meaning) { if (meaning && ts.hasProperty(symbols, name)) { @@ -8869,21 +9053,21 @@ var ts; } } switch (location.kind) { - case 182 /* SourceFile */: + case 184 /* SourceFile */: if (!ts.isExternalModule(location)) break; - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & ts.SymbolFlags.ModuleMember)) { return returnResolvedSymbol(result); } break; - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 4 /* EnumMember */)) { return returnResolvedSymbol(result); } break; case 119 /* Property */: - if (location.parent.kind === 174 /* ClassDeclaration */ && !(location.flags & 128 /* Static */)) { + if (location.parent.kind === 176 /* ClassDeclaration */ && !(location.flags & 128 /* Static */)) { var ctor = findConstructorDeclaration(location.parent); if (ctor && ctor.locals) { if (getSymbol(ctor.locals, name, meaning & ts.SymbolFlags.Value)) { @@ -8892,8 +9076,8 @@ var ts; } } break; - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & ts.SymbolFlags.Type)) { if (lastLocation && lastLocation.flags & 128 /* Static */) { error(errorLocation, ts.Diagnostics.Static_members_cannot_reference_class_type_parameters); @@ -8908,13 +9092,13 @@ var ts; case 121 /* Constructor */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 172 /* FunctionDeclaration */: - case 142 /* ArrowFunction */: + case 174 /* FunctionDeclaration */: + case 144 /* ArrowFunction */: if (name === "arguments") { return returnResolvedSymbol(argumentsSymbol); } break; - case 141 /* FunctionExpression */: + case 143 /* FunctionExpression */: if (name === "arguments") { return returnResolvedSymbol(argumentsSymbol); } @@ -8923,7 +9107,7 @@ var ts; return returnResolvedSymbol(location.symbol); } break; - case 168 /* CatchBlock */: + case 170 /* CatchBlock */: var id = location.variable; if (name === id.text) { return returnResolvedSymbol(location.symbol); @@ -8943,7 +9127,7 @@ var ts; var links = getSymbolLinks(symbol); if (!links.target) { links.target = resolvingSymbol; - var node = getDeclarationOfKind(symbol, 179 /* ImportDeclaration */); + var node = getDeclarationOfKind(symbol, 181 /* ImportDeclaration */); var target = node.externalModuleName ? resolveExternalModuleName(node, node.externalModuleName) : getSymbolOfPartOfRightHandSideOfImport(node.entityName, node); if (links.target === resolvingSymbol) { links.target = target || unknownSymbol; @@ -8959,7 +9143,7 @@ var ts; } function getSymbolOfPartOfRightHandSideOfImport(entityName, importDeclaration) { if (!importDeclaration) { - importDeclaration = ts.getAncestor(entityName, 179 /* ImportDeclaration */); + importDeclaration = ts.getAncestor(entityName, 181 /* ImportDeclaration */); ts.Debug.assert(importDeclaration); } if (entityName.kind === 59 /* Identifier */ && isRightSideOfQualifiedNameOrPropertyAccess(entityName)) { @@ -8969,7 +9153,7 @@ var ts; return resolveEntityName(importDeclaration, entityName, ts.SymbolFlags.Namespace); } else { - ts.Debug.assert(entityName.parent.kind === 179 /* ImportDeclaration */); + ts.Debug.assert(entityName.parent.kind === 181 /* ImportDeclaration */); return resolveEntityName(importDeclaration, entityName, ts.SymbolFlags.Value | ts.SymbolFlags.Type | ts.SymbolFlags.Namespace); } } @@ -9074,9 +9258,9 @@ var ts; var seenExportedMember = false; var result = []; ts.forEach(symbol.declarations, function (declaration) { - var block = (declaration.kind === 182 /* SourceFile */ ? declaration : declaration.body); + var block = (declaration.kind === 184 /* SourceFile */ ? declaration : declaration.body); ts.forEach(block.statements, function (node) { - if (node.kind === 180 /* ExportAssignment */) { + if (node.kind === 182 /* ExportAssignment */) { result.push(node); } else { @@ -9103,15 +9287,15 @@ var ts; return symbol && (symbol.flags & 524288 /* ExportValue */) !== 0 ? getMergedSymbol(symbol.exportSymbol) : symbol; } function symbolIsValue(symbol) { + if (symbol.flags & 8388608 /* Instantiated */) { + return symbolIsValue(getSymbolLinks(symbol).target); + } if (symbol.flags & ts.SymbolFlags.Value) { return true; } if (symbol.flags & 4194304 /* Import */) { return (resolveImport(symbol).flags & ts.SymbolFlags.Value) !== 0; } - if (symbol.flags & 8388608 /* Instantiated */) { - return (getSymbolLinks(symbol).target.flags & ts.SymbolFlags.Value) !== 0; - } return false; } function findConstructorDeclaration(node) { @@ -9169,7 +9353,7 @@ var ts; return type; } function createAnonymousType(symbol, members, callSignatures, constructSignatures, stringIndexType, numberIndexType) { - return setObjectTypeMembers(createObjectType(16384 /* Anonymous */, symbol), members, callSignatures, constructSignatures, stringIndexType, numberIndexType); + return setObjectTypeMembers(createObjectType(32768 /* Anonymous */, symbol), members, callSignatures, constructSignatures, stringIndexType, numberIndexType); } function isOptionalProperty(propertySymbol) { return propertySymbol.valueDeclaration && propertySymbol.valueDeclaration.flags & 4 /* QuestionMark */ && propertySymbol.valueDeclaration.kind !== 118 /* Parameter */; @@ -9183,17 +9367,17 @@ var ts; } } switch (location.kind) { - case 182 /* SourceFile */: + case 184 /* SourceFile */: if (!ts.isExternalModule(location)) { break; } - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: if (result = callback(getSymbolOfNode(location).exports)) { return result; } break; - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: if (result = callback(getSymbolOfNode(location).members)) { return result; } @@ -9205,13 +9389,13 @@ var ts; function getQualifiedLeftMeaning(rightMeaning) { return rightMeaning === ts.SymbolFlags.Value ? ts.SymbolFlags.Value : ts.SymbolFlags.Namespace; } - function getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning) { + function getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, useOnlyExternalAliasing) { function getAccessibleSymbolChainFromSymbolTable(symbols) { function canQualifySymbol(symbolFromSymbolTable, meaning) { if (!needsQualification(symbolFromSymbolTable, enclosingDeclaration, meaning)) { return true; } - var accessibleParent = getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, getQualifiedLeftMeaning(meaning)); + var accessibleParent = getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, getQualifiedLeftMeaning(meaning), useOnlyExternalAliasing); return !!accessibleParent; } function isAccessible(symbolFromSymbolTable, resolvedAliasSymbol) { @@ -9224,13 +9408,15 @@ var ts; } return ts.forEachValue(symbols, function (symbolFromSymbolTable) { if (symbolFromSymbolTable.flags & 4194304 /* Import */) { - var resolvedImportedSymbol = resolveImport(symbolFromSymbolTable); - if (isAccessible(symbolFromSymbolTable, resolveImport(symbolFromSymbolTable))) { - return [symbolFromSymbolTable]; - } - var accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined; - if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, getQualifiedLeftMeaning(meaning))) { - return [symbolFromSymbolTable].concat(accessibleSymbolsFromExports); + if (!useOnlyExternalAliasing || ts.forEach(symbolFromSymbolTable.declarations, function (declaration) { return declaration.kind === 181 /* ImportDeclaration */ && declaration.externalModuleName; })) { + var resolvedImportedSymbol = resolveImport(symbolFromSymbolTable); + if (isAccessible(symbolFromSymbolTable, resolveImport(symbolFromSymbolTable))) { + return [symbolFromSymbolTable]; + } + var accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined; + if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, getQualifiedLeftMeaning(meaning))) { + return [symbolFromSymbolTable].concat(accessibleSymbolsFromExports); + } } } }); @@ -9263,7 +9449,7 @@ var ts; var initialSymbol = symbol; var meaningToLook = meaning; while (symbol) { - var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook); + var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook, false); if (accessibleSymbolChain) { var hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0]); if (!hasAccessibleDeclarations) { @@ -9304,7 +9490,7 @@ var ts; } } function hasExternalModuleSymbol(declaration) { - return (declaration.kind === 177 /* ModuleDeclaration */ && declaration.name.kind === 7 /* StringLiteral */) || (declaration.kind === 182 /* SourceFile */ && ts.isExternalModule(declaration)); + return (declaration.kind === 179 /* ModuleDeclaration */ && declaration.name.kind === 7 /* StringLiteral */) || (declaration.kind === 184 /* SourceFile */ && ts.isExternalModule(declaration)); } function hasVisibleDeclarations(symbol) { var aliasesToMakeVisible; @@ -9314,7 +9500,7 @@ var ts; return { aliasesToMakeVisible: aliasesToMakeVisible }; function getIsDeclarationVisible(declaration) { if (!isDeclarationVisible(declaration)) { - if (declaration.kind === 179 /* ImportDeclaration */ && !(declaration.flags & 1 /* Export */) && isDeclarationVisible(declaration.parent)) { + if (declaration.kind === 181 /* ImportDeclaration */ && !(declaration.flags & 1 /* Export */) && isDeclarationVisible(declaration.parent)) { getNodeLinks(declaration).isVisible = true; if (aliasesToMakeVisible) { if (!ts.contains(aliasesToMakeVisible, declaration)) { @@ -9338,283 +9524,416 @@ var ts; var hasNamespaceDeclarationsVisibile = hasVisibleDeclarations(symbolOfNameSpace); return hasNamespaceDeclarationsVisibile ? { accessibility: 0 /* Accessible */, aliasesToMakeVisible: hasNamespaceDeclarationsVisibile.aliasesToMakeVisible } : { accessibility: 1 /* NotAccessible */, errorSymbolName: firstIdentifierName }; } + function releaseStringWriter(writer) { + writer.clear(); + stringWriters.push(writer); + } + function writeKeyword(writer, kind) { + writer.writeKeyword(ts.tokenToString(kind)); + } + function writePunctuation(writer, kind) { + writer.writePunctuation(ts.tokenToString(kind)); + } + function writeOperator(writer, kind) { + writer.writeOperator(ts.tokenToString(kind)); + } + function writeSpace(writer) { + writer.writeSpace(" "); + } function symbolToString(symbol, enclosingDeclaration, meaning) { - function getSymbolName(symbol) { + var writer = getSingleLineStringWriter(); + getSymbolDisplayBuilder().buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning); + var result = writer.string(); + releaseStringWriter(writer); + return result; + } + function typeToString(type, enclosingDeclaration, flags) { + var writer = getSingleLineStringWriter(); + getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); + var result = writer.string(); + releaseStringWriter(writer); + var maxLength = compilerOptions.noErrorTruncation || flags & 4 /* NoTruncation */ ? undefined : 100; + if (maxLength && result.length >= maxLength) { + result = result.substr(0, maxLength - "...".length) + "..."; + } + return result; + } + var _displayBuilder; + function getSymbolDisplayBuilder() { + function appendSymbolNameOnly(symbol, writer) { if (symbol.declarations && symbol.declarations.length > 0) { var declaration = symbol.declarations[0]; if (declaration.name) { - return ts.identifierToString(declaration.name); - } - } - return symbol.name; - } - if (enclosingDeclaration && !(symbol.flags & 262144 /* TypeParameter */)) { - var symbolName; - while (symbol) { - var isFirstName = !symbolName; - var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning); - var currentSymbolName; - if (accessibleSymbolChain) { - currentSymbolName = ts.map(accessibleSymbolChain, function (accessibleSymbol) { return getSymbolName(accessibleSymbol); }).join("."); - } - else { - if (!isFirstName && ts.forEach(symbol.declarations, function (declaration) { return hasExternalModuleSymbol(declaration); })) { - break; - } - currentSymbolName = getSymbolName(symbol); - } - symbolName = currentSymbolName + (isFirstName ? "" : ("." + symbolName)); - if (accessibleSymbolChain && !needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) { - break; - } - symbol = getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol); - meaning = getQualifiedLeftMeaning(meaning); - } - return symbolName; - } - return getSymbolName(symbol); - } - function writeSymbolToTextWriter(symbol, enclosingDeclaration, meaning, writer) { - writer.write(symbolToString(symbol, enclosingDeclaration, meaning)); - } - function createSingleLineTextWriter(maxLength) { - var result = ""; - var overflow = false; - function write(s) { - if (!overflow) { - result += s; - if (result.length > maxLength) { - result = result.substr(0, maxLength - 3) + "..."; - overflow = true; - } - } - } - return { - write: write, - writeSymbol: function (symbol, enclosingDeclaration, meaning) { - writeSymbolToTextWriter(symbol, enclosingDeclaration, meaning, this); - }, - writeLine: function () { - write(" "); - }, - increaseIndent: function () { - }, - decreaseIndent: function () { - }, - getText: function () { - return result; - } - }; - } - function typeToString(type, enclosingDeclaration, flags) { - var maxLength = compilerOptions.noErrorTruncation || flags & 4 /* NoTruncation */ ? undefined : 100; - var stringWriter = createSingleLineTextWriter(maxLength); - writeTypeToTextWriter(type, enclosingDeclaration, flags, stringWriter); - return stringWriter.getText(); - } - function writeTypeToTextWriter(type, enclosingDeclaration, flags, writer) { - var typeStack; - return writeType(type, true); - function writeType(type, allowFunctionOrConstructorTypeLiteral) { - if (type.flags & ts.TypeFlags.Intrinsic) { - writer.write(type.intrinsicName); - } - else if (type.flags & 4096 /* Reference */) { - writeTypeReference(type); - } - else if (type.flags & (1024 /* Class */ | 2048 /* Interface */ | 128 /* Enum */ | 512 /* TypeParameter */)) { - writer.writeSymbol(type.symbol, enclosingDeclaration, ts.SymbolFlags.Type); - } - else if (type.flags & 8192 /* Tuple */) { - writeTupleType(type); - } - else if (type.flags & 16384 /* Anonymous */) { - writeAnonymousType(type, allowFunctionOrConstructorTypeLiteral); - } - else if (type.flags & 256 /* StringLiteral */) { - writer.write(type.text); - } - else { - writer.write("{ ... }"); - } - } - function writeTypeList(types) { - for (var i = 0; i < types.length; i++) { - if (i > 0) { - writer.write(", "); - } - writeType(types[i], true); - } - } - function writeTypeReference(type) { - if (type.target === globalArrayType && !(flags & 1 /* WriteArrayAsGenericType */)) { - writeType(type.typeArguments[0], false); - writer.write("[]"); - } - else { - writer.writeSymbol(type.target.symbol, enclosingDeclaration, ts.SymbolFlags.Type); - writer.write("<"); - writeTypeList(type.typeArguments); - writer.write(">"); - } - } - function writeTupleType(type) { - writer.write("["); - writeTypeList(type.elementTypes); - writer.write("]"); - } - function writeAnonymousType(type, allowFunctionOrConstructorTypeLiteral) { - if (type.symbol && type.symbol.flags & (16 /* Class */ | 64 /* Enum */ | 128 /* ValueModule */)) { - writeTypeofSymbol(type); - } - else if (shouldWriteTypeOfFunctionSymbol()) { - writeTypeofSymbol(type); - } - else if (typeStack && ts.contains(typeStack, type)) { - writer.write("any"); - } - else { - if (!typeStack) { - typeStack = []; - } - typeStack.push(type); - writeLiteralType(type, allowFunctionOrConstructorTypeLiteral); - typeStack.pop(); - } - function shouldWriteTypeOfFunctionSymbol() { - if (type.symbol) { - var isStaticMethodSymbol = !!(type.symbol.flags & 2048 /* Method */ && ts.forEach(type.symbol.declarations, function (declaration) { return declaration.flags & 128 /* Static */; })); - var isNonLocalFunctionSymbol = !!(type.symbol.flags & 8 /* Function */) && (type.symbol.parent || ts.forEach(type.symbol.declarations, function (declaration) { return declaration.parent.kind === 182 /* SourceFile */ || declaration.parent.kind === 178 /* ModuleBlock */; })); - if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { - return !!(flags & 2 /* UseTypeOfFunction */) || (typeStack && ts.contains(typeStack, type)); - } - } - } - } - function writeTypeofSymbol(type) { - writer.write("typeof "); - writer.writeSymbol(type.symbol, enclosingDeclaration, ts.SymbolFlags.Value); - } - function writeLiteralType(type, allowFunctionOrConstructorTypeLiteral) { - var resolved = resolveObjectTypeMembers(type); - if (!resolved.properties.length && !resolved.stringIndexType && !resolved.numberIndexType) { - if (!resolved.callSignatures.length && !resolved.constructSignatures.length) { - writer.write("{}"); + writer.writeSymbol(ts.identifierToString(declaration.name), symbol); return; } - if (allowFunctionOrConstructorTypeLiteral) { + } + writer.writeSymbol(symbol.name, symbol); + } + function buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning, flags) { + var parentSymbol; + function appendParentTypeArgumentsAndSymbolName(symbol) { + if (parentSymbol) { + if (flags & 1 /* WriteTypeParametersOrArguments */) { + if (symbol.flags & 8388608 /* Instantiated */) { + buildDisplayForTypeArgumentsAndDelimiters(getTypeParametersOfClassOrInterface(parentSymbol), symbol.mapper, writer, enclosingDeclaration); + } + else { + buildTypeParameterDisplayFromSymbol(parentSymbol, writer, enclosingDeclaration); + } + } + writePunctuation(writer, 15 /* DotToken */); + } + parentSymbol = symbol; + appendSymbolNameOnly(symbol, writer); + } + writer.trackSymbol(symbol, enclosingDeclaration, meaning); + function walkSymbol(symbol, meaning) { + if (symbol) { + var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, !!(flags & 2 /* UseOnlyExternalAliasing */)); + if (!accessibleSymbolChain || needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) { + walkSymbol(getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol), getQualifiedLeftMeaning(meaning)); + } + if (accessibleSymbolChain) { + for (var i = 0, n = accessibleSymbolChain.length; i < n; i++) { + appendParentTypeArgumentsAndSymbolName(accessibleSymbolChain[i]); + } + } + else { + if (!parentSymbol && ts.forEach(symbol.declarations, function (declaration) { return hasExternalModuleSymbol(declaration); })) { + return; + } + if (symbol.flags & 512 /* TypeLiteral */ || symbol.flags & 1024 /* ObjectLiteral */) { + return; + } + appendParentTypeArgumentsAndSymbolName(symbol); + } + } + } + if (enclosingDeclaration && !(symbol.flags & 262144 /* TypeParameter */)) { + walkSymbol(symbol, meaning); + return; + } + return appendParentTypeArgumentsAndSymbolName(symbol); + } + function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, typeStack) { + var globalFlagsToPass = globalFlags & 16 /* WriteOwnNameForAnyLike */; + return writeType(type, globalFlags); + function writeType(type, flags) { + if (type.flags & ts.TypeFlags.Intrinsic) { + writer.writeKeyword(!(globalFlags & 16 /* WriteOwnNameForAnyLike */) && (type.flags & 1 /* Any */) ? "any" : type.intrinsicName); + } + else if (type.flags & 4096 /* Reference */) { + writeTypeReference(type, flags); + } + else if (type.flags & (1024 /* Class */ | 2048 /* Interface */ | 128 /* Enum */ | 512 /* TypeParameter */)) { + buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, ts.SymbolFlags.Type); + } + else if (type.flags & 8192 /* Tuple */) { + writeTupleType(type); + } + else if (type.flags & 16384 /* Union */) { + writeUnionType(type, flags); + } + else if (type.flags & 32768 /* Anonymous */) { + writeAnonymousType(type, flags); + } + else if (type.flags & 256 /* StringLiteral */) { + writer.writeStringLiteral(type.text); + } + else { + writePunctuation(writer, 9 /* OpenBraceToken */); + writeSpace(writer); + writePunctuation(writer, 16 /* DotDotDotToken */); + writeSpace(writer); + writePunctuation(writer, 10 /* CloseBraceToken */); + } + } + function writeTypeList(types, union) { + for (var i = 0; i < types.length; i++) { + if (i > 0) { + if (union) { + writeSpace(writer); + } + writePunctuation(writer, union ? 39 /* BarToken */ : 18 /* CommaToken */); + writeSpace(writer); + } + writeType(types[i], union ? 64 /* InElementType */ : 0 /* None */); + } + } + function writeTypeReference(type, flags) { + if (type.target === globalArrayType && !(flags & 1 /* WriteArrayAsGenericType */)) { + writeType(type.typeArguments[0], 64 /* InElementType */); + writePunctuation(writer, 13 /* OpenBracketToken */); + writePunctuation(writer, 14 /* CloseBracketToken */); + } + else { + buildSymbolDisplay(type.target.symbol, writer, enclosingDeclaration, ts.SymbolFlags.Type); + writePunctuation(writer, 19 /* LessThanToken */); + writeTypeList(type.typeArguments, false); + writePunctuation(writer, 20 /* GreaterThanToken */); + } + } + function writeTupleType(type) { + writePunctuation(writer, 13 /* OpenBracketToken */); + writeTypeList(type.elementTypes, false); + writePunctuation(writer, 14 /* CloseBracketToken */); + } + function writeUnionType(type, flags) { + if (flags & 64 /* InElementType */) { + writePunctuation(writer, 11 /* OpenParenToken */); + } + writeTypeList(type.types, true); + if (flags & 64 /* InElementType */) { + writePunctuation(writer, 12 /* CloseParenToken */); + } + } + function writeAnonymousType(type, flags) { + if (type.symbol && type.symbol.flags & (16 /* Class */ | 64 /* Enum */ | 128 /* ValueModule */)) { + writeTypeofSymbol(type); + } + else if (shouldWriteTypeOfFunctionSymbol()) { + writeTypeofSymbol(type); + } + else if (typeStack && ts.contains(typeStack, type)) { + writeKeyword(writer, 105 /* AnyKeyword */); + } + else { + if (!typeStack) { + typeStack = []; + } + typeStack.push(type); + writeLiteralType(type, flags); + typeStack.pop(); + } + function shouldWriteTypeOfFunctionSymbol() { + if (type.symbol) { + var isStaticMethodSymbol = !!(type.symbol.flags & 2048 /* Method */ && ts.forEach(type.symbol.declarations, function (declaration) { return declaration.flags & 128 /* Static */; })); + var isNonLocalFunctionSymbol = !!(type.symbol.flags & 8 /* Function */) && (type.symbol.parent || ts.forEach(type.symbol.declarations, function (declaration) { return declaration.parent.kind === 184 /* SourceFile */ || declaration.parent.kind === 180 /* ModuleBlock */; })); + if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { + return !!(flags & 2 /* UseTypeOfFunction */) || (typeStack && ts.contains(typeStack, type)); + } + } + } + } + function writeTypeofSymbol(type) { + writeKeyword(writer, 91 /* TypeOfKeyword */); + writeSpace(writer); + buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, ts.SymbolFlags.Value); + } + function writeLiteralType(type, flags) { + var resolved = resolveObjectOrUnionTypeMembers(type); + if (!resolved.properties.length && !resolved.stringIndexType && !resolved.numberIndexType) { + if (!resolved.callSignatures.length && !resolved.constructSignatures.length) { + writePunctuation(writer, 9 /* OpenBraceToken */); + writePunctuation(writer, 10 /* CloseBraceToken */); + return; + } if (resolved.callSignatures.length === 1 && !resolved.constructSignatures.length) { - writeSignature(resolved.callSignatures[0], true); + if (flags & 64 /* InElementType */) { + writePunctuation(writer, 11 /* OpenParenToken */); + } + buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, typeStack); + if (flags & 64 /* InElementType */) { + writePunctuation(writer, 12 /* CloseParenToken */); + } return; } if (resolved.constructSignatures.length === 1 && !resolved.callSignatures.length) { - writer.write("new "); - writeSignature(resolved.constructSignatures[0], true); + if (flags & 64 /* InElementType */) { + writePunctuation(writer, 11 /* OpenParenToken */); + } + writeKeyword(writer, 82 /* NewKeyword */); + writeSpace(writer); + buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, typeStack); + if (flags & 64 /* InElementType */) { + writePunctuation(writer, 12 /* CloseParenToken */); + } return; } } - } - writer.write("{"); - writer.writeLine(); - writer.increaseIndent(); - for (var i = 0; i < resolved.callSignatures.length; i++) { - writeSignature(resolved.callSignatures[i]); - writer.write(";"); + writePunctuation(writer, 9 /* OpenBraceToken */); writer.writeLine(); - } - for (var i = 0; i < resolved.constructSignatures.length; i++) { - writer.write("new "); - writeSignature(resolved.constructSignatures[i]); - writer.write(";"); - writer.writeLine(); - } - if (resolved.stringIndexType) { - writer.write("[x: string]: "); - writeType(resolved.stringIndexType, true); - writer.write(";"); - writer.writeLine(); - } - if (resolved.numberIndexType) { - writer.write("[x: number]: "); - writeType(resolved.numberIndexType, true); - writer.write(";"); - writer.writeLine(); - } - for (var i = 0; i < resolved.properties.length; i++) { - var p = resolved.properties[i]; - var t = getTypeOfSymbol(p); - if (p.flags & (8 /* Function */ | 2048 /* Method */) && !getPropertiesOfType(t).length) { - var signatures = getSignaturesOfType(t, 0 /* Call */); - for (var j = 0; j < signatures.length; j++) { - writer.writeSymbol(p); - if (isOptionalProperty(p)) { - writer.write("?"); + writer.increaseIndent(); + for (var i = 0; i < resolved.callSignatures.length; i++) { + buildSignatureDisplay(resolved.callSignatures[i], writer, enclosingDeclaration, globalFlagsToPass, typeStack); + writePunctuation(writer, 17 /* SemicolonToken */); + writer.writeLine(); + } + for (var i = 0; i < resolved.constructSignatures.length; i++) { + writeKeyword(writer, 82 /* NewKeyword */); + writeSpace(writer); + buildSignatureDisplay(resolved.constructSignatures[i], writer, enclosingDeclaration, globalFlagsToPass, typeStack); + writePunctuation(writer, 17 /* SemicolonToken */); + writer.writeLine(); + } + if (resolved.stringIndexType) { + writePunctuation(writer, 13 /* OpenBracketToken */); + writer.writeParameter("x"); + writePunctuation(writer, 46 /* ColonToken */); + writeSpace(writer); + writeKeyword(writer, 114 /* StringKeyword */); + writePunctuation(writer, 14 /* CloseBracketToken */); + writePunctuation(writer, 46 /* ColonToken */); + writeSpace(writer); + writeType(resolved.stringIndexType, 0 /* None */); + writePunctuation(writer, 17 /* SemicolonToken */); + writer.writeLine(); + } + if (resolved.numberIndexType) { + writePunctuation(writer, 13 /* OpenBracketToken */); + writer.writeParameter("x"); + writePunctuation(writer, 46 /* ColonToken */); + writeSpace(writer); + writeKeyword(writer, 112 /* NumberKeyword */); + writePunctuation(writer, 14 /* CloseBracketToken */); + writePunctuation(writer, 46 /* ColonToken */); + writeSpace(writer); + writeType(resolved.numberIndexType, 0 /* None */); + writePunctuation(writer, 17 /* SemicolonToken */); + writer.writeLine(); + } + for (var i = 0; i < resolved.properties.length; i++) { + var p = resolved.properties[i]; + var t = getTypeOfSymbol(p); + if (p.flags & (8 /* Function */ | 2048 /* Method */) && !getPropertiesOfObjectType(t).length) { + var signatures = getSignaturesOfType(t, 0 /* Call */); + for (var j = 0; j < signatures.length; j++) { + buildSymbolDisplay(p, writer); + if (isOptionalProperty(p)) { + writePunctuation(writer, 45 /* QuestionToken */); + } + buildSignatureDisplay(signatures[j], writer, enclosingDeclaration, globalFlagsToPass, typeStack); + writePunctuation(writer, 17 /* SemicolonToken */); + writer.writeLine(); } - writeSignature(signatures[j]); - writer.write(";"); + } + else { + buildSymbolDisplay(p, writer); + if (isOptionalProperty(p)) { + writePunctuation(writer, 45 /* QuestionToken */); + } + writePunctuation(writer, 46 /* ColonToken */); + writeSpace(writer); + writeType(t, 0 /* None */); + writePunctuation(writer, 17 /* SemicolonToken */); writer.writeLine(); } } - else { - writer.writeSymbol(p); - if (isOptionalProperty(p)) { - writer.write("?"); - } - writer.write(": "); - writeType(t, true); - writer.write(";"); - writer.writeLine(); - } + writer.decreaseIndent(); + writePunctuation(writer, 10 /* CloseBraceToken */); } - writer.decreaseIndent(); - writer.write("}"); } - function writeSignature(signature, arrowStyle) { - if (signature.typeParameters) { - writer.write("<"); - for (var i = 0; i < signature.typeParameters.length; i++) { + function buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaraiton, flags) { + var targetSymbol = getTargetSymbol(symbol); + if (targetSymbol.flags & 16 /* Class */ || targetSymbol.flags & 32 /* Interface */) { + buildDisplayForTypeParametersAndDelimiters(getTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags); + } + } + function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, typeStack) { + appendSymbolNameOnly(tp.symbol, writer); + var constraint = getConstraintOfTypeParameter(tp); + if (constraint) { + writeSpace(writer); + writeKeyword(writer, 73 /* ExtendsKeyword */); + writeSpace(writer); + buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, typeStack); + } + } + function buildParameterDisplay(p, writer, enclosingDeclaration, flags, typeStack) { + if (getDeclarationFlagsFromSymbol(p) & 8 /* Rest */) { + writePunctuation(writer, 16 /* DotDotDotToken */); + } + appendSymbolNameOnly(p, writer); + if (p.valueDeclaration.flags & 4 /* QuestionMark */ || p.valueDeclaration.initializer) { + writePunctuation(writer, 45 /* QuestionToken */); + } + writePunctuation(writer, 46 /* ColonToken */); + writeSpace(writer); + buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, typeStack); + } + function buildDisplayForTypeParametersAndDelimiters(typeParameters, writer, enclosingDeclaration, flags, typeStack) { + if (typeParameters && typeParameters.length) { + writePunctuation(writer, 19 /* LessThanToken */); + for (var i = 0; i < typeParameters.length; i++) { if (i > 0) { - writer.write(", "); - } - var tp = signature.typeParameters[i]; - writer.writeSymbol(tp.symbol); - var constraint = getConstraintOfTypeParameter(tp); - if (constraint) { - writer.write(" extends "); - writeType(constraint, true); + writePunctuation(writer, 18 /* CommaToken */); + writeSpace(writer); } + buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, typeStack); } - writer.write(">"); + writePunctuation(writer, 20 /* GreaterThanToken */); } - writer.write("("); - for (var i = 0; i < signature.parameters.length; i++) { - if (i > 0) { - writer.write(", "); - } - var p = signature.parameters[i]; - if (getDeclarationFlagsFromSymbol(p) & 8 /* Rest */) { - writer.write("..."); - } - writer.writeSymbol(p); - if (p.valueDeclaration.flags & 4 /* QuestionMark */ || p.valueDeclaration.initializer) { - writer.write("?"); - } - writer.write(": "); - writeType(getTypeOfSymbol(p), true); - } - writer.write(arrowStyle ? ") => " : "): "); - writeType(getReturnTypeOfSignature(signature), true); } + function buildDisplayForTypeArgumentsAndDelimiters(typeParameters, mapper, writer, enclosingDeclaration, flags, typeStack) { + if (typeParameters && typeParameters.length) { + writePunctuation(writer, 19 /* LessThanToken */); + for (var i = 0; i < typeParameters.length; i++) { + if (i > 0) { + writePunctuation(writer, 18 /* CommaToken */); + writeSpace(writer); + } + buildTypeDisplay(mapper(typeParameters[i]), writer, enclosingDeclaration, 0 /* None */); + } + writePunctuation(writer, 20 /* GreaterThanToken */); + } + } + function buildDisplayForParametersAndDelimiters(parameters, writer, enclosingDeclaration, flags, typeStack) { + writePunctuation(writer, 11 /* OpenParenToken */); + for (var i = 0; i < parameters.length; i++) { + if (i > 0) { + writePunctuation(writer, 18 /* CommaToken */); + writeSpace(writer); + } + buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, typeStack); + } + writePunctuation(writer, 12 /* CloseParenToken */); + } + function buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack) { + if (flags & 8 /* WriteArrowStyleSignature */) { + writeSpace(writer); + writePunctuation(writer, 27 /* EqualsGreaterThanToken */); + } + else { + writePunctuation(writer, 46 /* ColonToken */); + } + writeSpace(writer); + buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, typeStack); + } + function buildSignatureDisplay(signature, writer, enclosingDeclaration, flags, typeStack) { + if (signature.target && (flags & 32 /* WriteTypeArgumentsOfSignature */)) { + buildDisplayForTypeArgumentsAndDelimiters(signature.target.typeParameters, signature.mapper, writer, enclosingDeclaration); + } + else { + buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, typeStack); + } + buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, typeStack); + buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack); + } + return _displayBuilder || (_displayBuilder = { + symbolToString: symbolToString, + typeToString: typeToString, + buildSymbolDisplay: buildSymbolDisplay, + buildTypeDisplay: buildTypeDisplay, + buildTypeParameterDisplay: buildTypeParameterDisplay, + buildParameterDisplay: buildParameterDisplay, + buildDisplayForParametersAndDelimiters: buildDisplayForParametersAndDelimiters, + buildDisplayForTypeParametersAndDelimiters: buildDisplayForTypeParametersAndDelimiters, + buildDisplayForTypeArgumentsAndDelimiters: buildDisplayForTypeArgumentsAndDelimiters, + buildTypeParameterDisplayFromSymbol: buildTypeParameterDisplayFromSymbol, + buildSignatureDisplay: buildSignatureDisplay, + buildReturnTypeDisplay: buildReturnTypeDisplay + }); } function isDeclarationVisible(node) { function getContainingExternalModule(node) { for (; node; node = node.parent) { - if (node.kind === 177 /* ModuleDeclaration */) { + if (node.kind === 179 /* ModuleDeclaration */) { if (node.name.kind === 7 /* StringLiteral */) { return node; } } - else if (node.kind === 182 /* SourceFile */) { + else if (node.kind === 184 /* SourceFile */) { return ts.isExternalModule(node) ? node : undefined; } } @@ -9656,15 +9975,15 @@ var ts; } function determineIfDeclarationIsVisible() { switch (node.kind) { - case 171 /* VariableDeclaration */: - case 177 /* ModuleDeclaration */: - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 172 /* FunctionDeclaration */: - case 176 /* EnumDeclaration */: - case 179 /* ImportDeclaration */: - var parent = node.kind === 171 /* VariableDeclaration */ ? node.parent.parent : node.parent; - if (!(node.flags & 1 /* Export */) && !(node.kind !== 179 /* ImportDeclaration */ && parent.kind !== 182 /* SourceFile */ && ts.isInAmbientContext(parent))) { + case 173 /* VariableDeclaration */: + case 179 /* ModuleDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 174 /* FunctionDeclaration */: + case 178 /* EnumDeclaration */: + case 181 /* ImportDeclaration */: + var parent = node.kind === 173 /* VariableDeclaration */ ? node.parent.parent : node.parent; + if (!(node.flags & 1 /* Export */) && !(node.kind !== 181 /* ImportDeclaration */ && parent.kind !== 184 /* SourceFile */ && ts.isInAmbientContext(parent))) { return isGlobalSourceFile(parent) || isUsedInExportAssignment(node); } return isDeclarationVisible(parent); @@ -9678,9 +9997,9 @@ var ts; case 124 /* CallSignature */: case 126 /* IndexSignature */: case 118 /* Parameter */: - case 178 /* ModuleBlock */: + case 180 /* ModuleBlock */: return isDeclarationVisible(node.parent); - case 182 /* SourceFile */: + case 184 /* SourceFile */: return true; default: ts.Debug.fail("isDeclarationVisible unknown: SyntaxKind: " + ts.SyntaxKind[node.kind]); @@ -9694,31 +10013,12 @@ var ts; return links.isVisible; } } - function getApparentType(type) { - if (type.flags & 512 /* TypeParameter */) { - do { - type = getConstraintOfTypeParameter(type); - } while (type && type.flags & 512 /* TypeParameter */); - if (!type) - type = emptyObjectType; - } - if (type.flags & ts.TypeFlags.StringLike) { - type = globalStringType; - } - else if (type.flags & ts.TypeFlags.NumberLike) { - type = globalNumberType; - } - else if (type.flags & 8 /* Boolean */) { - type = globalBooleanType; - } - return type; - } function getTypeOfPrototypeProperty(prototype) { var classType = getDeclaredTypeOfSymbol(prototype.parent); return classType.typeParameters ? createTypeReference(classType, ts.map(classType.typeParameters, function (_) { return anyType; })) : classType; } function getTypeOfVariableDeclaration(declaration) { - if (declaration.parent.kind === 156 /* ForInStatement */) { + if (declaration.parent.kind === 158 /* ForInStatement */) { return anyType; } if (declaration.type) { @@ -9739,7 +10039,7 @@ var ts; } if (declaration.initializer) { var type = checkAndMarkExpression(declaration.initializer); - if (declaration.kind !== 134 /* PropertyAssignment */) { + if (declaration.kind !== 136 /* PropertyAssignment */) { var unwidenedType = type; type = getWidenedType(type); if (type !== unwidenedType) { @@ -9781,7 +10081,7 @@ var ts; return links.type = getTypeOfPrototypeProperty(symbol); } var declaration = symbol.valueDeclaration; - if (declaration.kind === 168 /* CatchBlock */) { + if (declaration.kind === 170 /* CatchBlock */) { return links.type = anyType; } links.type = resolvingType; @@ -9862,7 +10162,7 @@ var ts; function getTypeOfFuncClassEnumModule(symbol) { var links = getSymbolLinks(symbol); if (!links.type) { - links.type = createObjectType(16384 /* Anonymous */, symbol); + links.type = createObjectType(32768 /* Anonymous */, symbol); } return links.type; } @@ -9888,6 +10188,9 @@ var ts; return links.type; } function getTypeOfSymbol(symbol) { + if (symbol.flags & 8388608 /* Instantiated */) { + return getTypeOfInstantiatedSymbol(symbol); + } if (symbol.flags & (1 /* Variable */ | 2 /* Property */)) { return getTypeOfVariableOrParameterOrProperty(symbol); } @@ -9903,9 +10206,6 @@ var ts; if (symbol.flags & 4194304 /* Import */) { return getTypeOfImport(symbol); } - if (symbol.flags & 8388608 /* Instantiated */) { - return getTypeOfInstantiatedSymbol(symbol); - } return unknownType; } function getTargetType(type) { @@ -9921,7 +10221,7 @@ var ts; function getTypeParametersOfClassOrInterface(symbol) { var result; ts.forEach(symbol.declarations, function (node) { - if (node.kind === 175 /* InterfaceDeclaration */ || node.kind === 174 /* ClassDeclaration */) { + if (node.kind === 177 /* InterfaceDeclaration */ || node.kind === 176 /* ClassDeclaration */) { var declaration = node; if (declaration.typeParameters && declaration.typeParameters.length) { ts.forEach(declaration.typeParameters, function (node) { @@ -9952,7 +10252,7 @@ var ts; type.typeArguments = type.typeParameters; } type.baseTypes = []; - var declaration = getDeclarationOfKind(symbol, 174 /* ClassDeclaration */); + var declaration = getDeclarationOfKind(symbol, 176 /* ClassDeclaration */); if (declaration.baseType) { var baseType = getTypeFromTypeReferenceNode(declaration.baseType); if (baseType !== unknownType) { @@ -9992,7 +10292,7 @@ var ts; } type.baseTypes = []; ts.forEach(symbol.declarations, function (declaration) { - if (declaration.kind === 175 /* InterfaceDeclaration */ && declaration.baseTypes) { + if (declaration.kind === 177 /* InterfaceDeclaration */ && declaration.baseTypes) { ts.forEach(declaration.baseTypes, function (node) { var baseType = getTypeFromTypeReferenceNode(node); if (baseType !== unknownType) { @@ -10048,6 +10348,7 @@ var ts; return links.declaredType; } function getDeclaredTypeOfSymbol(symbol) { + ts.Debug.assert((symbol.flags & 8388608 /* Instantiated */) === 0); if (symbol.flags & 16 /* Class */) { return getDeclaredTypeOfClass(symbol); } @@ -10063,7 +10364,6 @@ var ts; if (symbol.flags & 4194304 /* Import */) { return getDeclaredTypeOfImport(symbol); } - ts.Debug.assert((symbol.flags & 8388608 /* Instantiated */) === 0); return unknownType; } function createSymbolTable(symbols) { @@ -10106,7 +10406,7 @@ var ts; if (type.baseTypes.length) { members = createSymbolTable(type.declaredProperties); ts.forEach(type.baseTypes, function (baseType) { - addInheritedMembers(members, getPropertiesOfType(baseType)); + addInheritedMembers(members, getPropertiesOfObjectType(baseType)); callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(baseType, 0 /* Call */)); constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(baseType, 1 /* Construct */)); stringIndexType = stringIndexType || getIndexTypeOfType(baseType, 0 /* String */); @@ -10125,7 +10425,7 @@ var ts; var numberIndexType = target.declaredNumberIndexType ? instantiateType(target.declaredNumberIndexType, mapper) : undefined; ts.forEach(target.baseTypes, function (baseType) { var instantiatedBaseType = instantiateType(baseType, mapper); - addInheritedMembers(members, getPropertiesOfType(instantiatedBaseType)); + addInheritedMembers(members, getPropertiesOfObjectType(instantiatedBaseType)); callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, 0 /* Call */)); constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(instantiatedBaseType, 1 /* Construct */)); stringIndexType = stringIndexType || getIndexTypeOfType(instantiatedBaseType, 0 /* String */); @@ -10170,11 +10470,61 @@ var ts; return members; } function resolveTupleTypeMembers(type) { - var arrayType = resolveObjectTypeMembers(createArrayType(getBestCommonType(type.elementTypes))); + var arrayType = resolveObjectOrUnionTypeMembers(createArrayType(getUnionType(type.elementTypes))); var members = createTupleTypeMemberSymbols(type.elementTypes); addInheritedMembers(members, arrayType.properties); setObjectTypeMembers(type, members, arrayType.callSignatures, arrayType.constructSignatures, arrayType.stringIndexType, arrayType.numberIndexType); } + function signatureListsIdentical(s, t) { + if (s.length !== t.length) { + return false; + } + for (var i = 0; i < s.length; i++) { + if (!compareSignatures(s[i], t[i], false, isTypeIdenticalTo)) { + return false; + } + } + return true; + } + function getUnionSignatures(types, kind) { + var signatureLists = ts.map(types, function (t) { return getSignaturesOfType(t, kind); }); + var signatures = signatureLists[0]; + for (var i = 0; i < signatures.length; i++) { + if (signatures[i].typeParameters) { + return emptyArray; + } + } + for (var i = 1; i < signatureLists.length; i++) { + if (!signatureListsIdentical(signatures, signatureLists[i])) { + return emptyArray; + } + } + var result = ts.map(signatures, cloneSignature); + for (var i = 0; i < result.length; i++) { + var s = result[i]; + s.resolvedReturnType = undefined; + s.unionSignatures = ts.map(signatureLists, function (signatures) { return signatures[i]; }); + } + return result; + } + function getUnionIndexType(types, kind) { + var indexTypes = []; + for (var i = 0; i < types.length; i++) { + var indexType = getIndexTypeOfType(types[i], kind); + if (!indexType) { + return undefined; + } + indexTypes.push(indexType); + } + return getUnionType(indexTypes); + } + function resolveUnionTypeMembers(type) { + var callSignatures = getUnionSignatures(type.types, 0 /* Call */); + var constructSignatures = getUnionSignatures(type.types, 1 /* Construct */); + var stringIndexType = getUnionIndexType(type.types, 0 /* String */); + var numberIndexType = getUnionIndexType(type.types, 1 /* Number */); + setObjectTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexType, numberIndexType); + } function resolveAnonymousTypeMembers(type) { var symbol = type.symbol; if (symbol.flags & 512 /* TypeLiteral */) { @@ -10202,7 +10552,7 @@ var ts; } if (classType.baseTypes.length) { members = createSymbolTable(getNamedMembers(members)); - addInheritedMembers(members, getPropertiesOfType(getTypeOfSymbol(classType.baseTypes[0].symbol))); + addInheritedMembers(members, getPropertiesOfObjectType(getTypeOfSymbol(classType.baseTypes[0].symbol))); } } var stringIndexType = undefined; @@ -10210,70 +10560,166 @@ var ts; } setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); } - function resolveObjectTypeMembers(type) { + function resolveObjectOrUnionTypeMembers(type) { if (!type.members) { if (type.flags & (1024 /* Class */ | 2048 /* Interface */)) { resolveClassOrInterfaceMembers(type); } - else if (type.flags & 16384 /* Anonymous */) { + else if (type.flags & 32768 /* Anonymous */) { resolveAnonymousTypeMembers(type); } else if (type.flags & 8192 /* Tuple */) { resolveTupleTypeMembers(type); } + else if (type.flags & 16384 /* Union */) { + resolveUnionTypeMembers(type); + } else { resolveTypeReferenceMembers(type); } } return type; } - function getPropertiesOfType(type) { + function getPropertiesOfObjectType(type) { if (type.flags & ts.TypeFlags.ObjectType) { - return resolveObjectTypeMembers(type).properties; + return resolveObjectOrUnionTypeMembers(type).properties; } return emptyArray; } + function getPropertyOfObjectType(type, name) { + if (type.flags & ts.TypeFlags.ObjectType) { + var resolved = resolveObjectOrUnionTypeMembers(type); + if (ts.hasProperty(resolved.members, name)) { + var symbol = resolved.members[name]; + if (symbolIsValue(symbol)) { + return symbol; + } + } + } + } + function getPropertiesOfUnionType(type) { + var result = []; + ts.forEach(getPropertiesOfType(type.types[0]), function (prop) { + var unionProp = getPropertyOfUnionType(type, prop.name); + if (unionProp) { + result.push(unionProp); + } + }); + return result; + } + function getPropertiesOfType(type) { + if (type.flags & 16384 /* Union */) { + return getPropertiesOfUnionType(type); + } + return getPropertiesOfObjectType(getApparentType(type)); + } + function getApparentType(type) { + if (type.flags & 512 /* TypeParameter */) { + do { + type = getConstraintOfTypeParameter(type); + } while (type && type.flags & 512 /* TypeParameter */); + if (!type) { + type = emptyObjectType; + } + } + if (type.flags & ts.TypeFlags.StringLike) { + type = globalStringType; + } + else if (type.flags & ts.TypeFlags.NumberLike) { + type = globalNumberType; + } + else if (type.flags & 8 /* Boolean */) { + type = globalBooleanType; + } + return type; + } + function createUnionProperty(unionType, name) { + var types = unionType.types; + var props; + for (var i = 0; i < types.length; i++) { + var type = getApparentType(types[i]); + if (type !== unknownType) { + var prop = getPropertyOfType(type, name); + if (!prop) { + return undefined; + } + if (!props) { + props = [prop]; + } + else { + props.push(prop); + } + } + } + var propTypes = []; + var declarations = []; + for (var i = 0; i < props.length; i++) { + var prop = props[i]; + if (prop.declarations) { + declarations.push.apply(declarations, prop.declarations); + } + propTypes.push(getTypeOfSymbol(prop)); + } + var result = createSymbol(2 /* Property */ | 33554432 /* Transient */ | 134217728 /* UnionProperty */, name); + result.unionType = unionType; + result.declarations = declarations; + result.type = getUnionType(propTypes); + return result; + } + function getPropertyOfUnionType(type, name) { + var properties = type.resolvedProperties || (type.resolvedProperties = {}); + if (ts.hasProperty(properties, name)) { + return properties[name]; + } + var property = createUnionProperty(type, name); + if (property) { + properties[name] = property; + } + return property; + } function getPropertyOfType(type, name) { - if (type.flags & ts.TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); - if (ts.hasProperty(resolved.members, name)) { - var symbol = resolved.members[name]; - if (symbolIsValue(symbol)) { - return symbol; - } + if (type.flags & 16384 /* Union */) { + return getPropertyOfUnionType(type, name); + } + if (!(type.flags & ts.TypeFlags.ObjectType)) { + type = getApparentType(type); + if (!(type.flags & ts.TypeFlags.ObjectType)) { + return undefined; } } - } - function getPropertyOfApparentType(type, name) { - if (type.flags & ts.TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); - if (ts.hasProperty(resolved.members, name)) { - var symbol = resolved.members[name]; - if (symbolIsValue(symbol)) { - return symbol; - } + var resolved = resolveObjectOrUnionTypeMembers(type); + if (ts.hasProperty(resolved.members, name)) { + var symbol = resolved.members[name]; + if (symbolIsValue(symbol)) { + return symbol; } - if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { - var symbol = getPropertyOfType(globalFunctionType, name); - if (symbol) - return symbol; - } - return getPropertyOfType(globalObjectType, name); } + if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { + var symbol = getPropertyOfObjectType(globalFunctionType, name); + if (symbol) + return symbol; + } + return getPropertyOfObjectType(globalObjectType, name); } - function getSignaturesOfType(type, kind) { - if (type.flags & ts.TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); + function getSignaturesOfObjectOrUnionType(type, kind) { + if (type.flags & (ts.TypeFlags.ObjectType | 16384 /* Union */)) { + var resolved = resolveObjectOrUnionTypeMembers(type); return kind === 0 /* Call */ ? resolved.callSignatures : resolved.constructSignatures; } return emptyArray; } - function getIndexTypeOfType(type, kind) { - if (type.flags & ts.TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); + function getSignaturesOfType(type, kind) { + return getSignaturesOfObjectOrUnionType(getApparentType(type), kind); + } + function getIndexTypeOfObjectOrUnionType(type, kind) { + if (type.flags & (ts.TypeFlags.ObjectType | 16384 /* Union */)) { + var resolved = resolveObjectOrUnionTypeMembers(type); return kind === 0 /* String */ ? resolved.stringIndexType : resolved.numberIndexType; } } + function getIndexTypeOfType(type, kind) { + return getIndexTypeOfObjectOrUnionType(getApparentType(type), kind); + } function getTypeParametersFromDeclaration(typeParameterDeclarations) { var result = []; ts.forEach(typeParameterDeclarations, function (node) { @@ -10334,7 +10780,7 @@ var ts; for (var i = 0, len = symbol.declarations.length; i < len; i++) { var node = symbol.declarations[i]; switch (node.kind) { - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: case 120 /* Method */: case 121 /* Constructor */: case 124 /* CallSignature */: @@ -10342,8 +10788,8 @@ var ts; case 126 /* IndexSignature */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: if (i > 0 && node.body) { var previous = symbol.declarations[i - 1]; if (node.parent === previous.parent && node.kind === previous.kind && node.pos === previous.end) { @@ -10361,6 +10807,9 @@ var ts; if (signature.target) { var type = instantiateType(getReturnTypeOfSignature(signature.target), signature.mapper); } + else if (signature.unionSignatures) { + var type = getUnionType(ts.map(signature.unionSignatures, getReturnTypeOfSignature)); + } else { var type = getReturnTypeFromBody(signature.declaration); } @@ -10410,7 +10859,7 @@ var ts; function getOrCreateTypeFromSignature(signature) { if (!signature.isolatedSignatureType) { var isConstructor = signature.declaration.kind === 121 /* Constructor */ || signature.declaration.kind === 125 /* ConstructSignature */; - var type = createObjectType(16384 /* Anonymous */ | 32768 /* FromSignature */); + var type = createObjectType(32768 /* Anonymous */ | 65536 /* FromSignature */); type.members = emptySymbols; type.properties = emptyArray; type.callSignatures = !isConstructor ? [signature] : emptyArray; @@ -10561,9 +11010,9 @@ var ts; for (var i = 0; i < declarations.length; i++) { var declaration = declarations[i]; switch (declaration.kind) { - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 176 /* EnumDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: return declaration; } } @@ -10615,10 +11064,98 @@ var ts; } return links.resolvedType; } + function addTypeToSortedSet(sortedSet, type) { + if (type.flags & 16384 /* Union */) { + addTypesToSortedSet(sortedSet, type.types); + } + else { + var i = 0; + var id = type.id; + while (i < sortedSet.length && sortedSet[i].id < id) { + i++; + } + if (i === sortedSet.length || sortedSet[i].id !== id) { + sortedSet.splice(i, 0, type); + } + } + } + function addTypesToSortedSet(sortedTypes, types) { + for (var i = 0, len = types.length; i < len; i++) { + addTypeToSortedSet(sortedTypes, types[i]); + } + } + function isSubtypeOfAny(candidate, types) { + for (var i = 0, len = types.length; i < len; i++) { + if (candidate !== types[i] && isTypeSubtypeOf(candidate, types[i])) { + return true; + } + } + return false; + } + function removeSubtypes(types) { + var i = types.length; + while (i > 0) { + i--; + if (isSubtypeOfAny(types[i], types)) { + types.splice(i, 1); + } + } + } + function containsAnyType(types) { + for (var i = 0; i < types.length; i++) { + if (types[i].flags & 1 /* Any */) { + return true; + } + } + return false; + } + function removeAllButLast(types, typeToRemove) { + var i = types.length; + while (i > 0 && types.length > 1) { + i--; + if (types[i] === typeToRemove) { + types.splice(i, 1); + } + } + } + function getUnionType(types, noSubtypeReduction) { + if (types.length === 0) { + return emptyObjectType; + } + var sortedTypes = []; + addTypesToSortedSet(sortedTypes, types); + if (noSubtypeReduction) { + if (containsAnyType(sortedTypes)) { + return anyType; + } + removeAllButLast(sortedTypes, undefinedType); + removeAllButLast(sortedTypes, nullType); + } + else { + removeSubtypes(sortedTypes); + } + if (sortedTypes.length === 1) { + return sortedTypes[0]; + } + var id = getTypeListId(sortedTypes); + var type = unionTypes[id]; + if (!type) { + type = unionTypes[id] = createObjectType(16384 /* Union */); + type.types = sortedTypes; + } + return type; + } + function getTypeFromUnionTypeNode(node) { + var links = getNodeLinks(node); + if (!links.resolvedType) { + links.resolvedType = getUnionType(ts.map(node.types, getTypeFromTypeNode), true); + } + return links.resolvedType; + } function getTypeFromTypeLiteralNode(node) { var links = getNodeLinks(node); if (!links.resolvedType) { - links.resolvedType = createObjectType(16384 /* Anonymous */, node.symbol); + links.resolvedType = createObjectType(32768 /* Anonymous */, node.symbol); } return links.resolvedType; } @@ -10626,7 +11163,7 @@ var ts; if (ts.hasProperty(stringLiteralTypes, node.text)) return stringLiteralTypes[node.text]; var type = stringLiteralTypes[node.text] = createType(256 /* StringLiteral */); - type.text = ts.getSourceTextOfNode(node); + type.text = ts.getTextOfNode(node); return type; } function getTypeFromStringLiteral(node) { @@ -10658,6 +11195,10 @@ var ts; return getTypeFromArrayTypeNode(node); case 131 /* TupleType */: return getTypeFromTupleTypeNode(node); + case 132 /* UnionType */: + return getTypeFromUnionTypeNode(node); + case 133 /* ParenType */: + return getTypeFromTypeNode(node.type); case 129 /* TypeLiteral */: return getTypeFromTypeLiteralNode(node); case 59 /* Identifier */: @@ -10764,7 +11305,7 @@ var ts; symbol = links.target; mapper = combineTypeMappers(links.mapper, mapper); } - var result = createSymbol(8388608 /* Instantiated */ | 33554432 /* Transient */, symbol.name); + var result = createSymbol(8388608 /* Instantiated */ | 33554432 /* Transient */ | symbol.flags, symbol.name); result.declarations = symbol.declarations; result.parent = symbol.parent; result.target = symbol; @@ -10775,8 +11316,8 @@ var ts; return result; } function instantiateAnonymousType(type, mapper) { - var result = createObjectType(16384 /* Anonymous */, type.symbol); - result.properties = instantiateList(getPropertiesOfType(type), mapper, instantiateSymbol); + var result = createObjectType(32768 /* Anonymous */, type.symbol); + result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol); result.members = createSymbolTable(result.properties); result.callSignatures = instantiateList(getSignaturesOfType(type, 0 /* Call */), mapper, instantiateSignature); result.constructSignatures = instantiateList(getSignaturesOfType(type, 1 /* Construct */), mapper, instantiateSignature); @@ -10793,7 +11334,7 @@ var ts; if (type.flags & 512 /* TypeParameter */) { return mapper(type); } - if (type.flags & 16384 /* Anonymous */) { + if (type.flags & 32768 /* Anonymous */) { return type.symbol && type.symbol.flags & (8 /* Function */ | 2048 /* Method */ | 512 /* TypeLiteral */ | 1024 /* ObjectLiteral */) ? instantiateAnonymousType(type, mapper) : type; } if (type.flags & 4096 /* Reference */) { @@ -10802,30 +11343,33 @@ var ts; if (type.flags & 8192 /* Tuple */) { return createTupleType(instantiateList(type.elementTypes, mapper, instantiateType)); } + if (type.flags & 16384 /* Union */) { + return getUnionType(instantiateList(type.types, mapper, instantiateType), true); + } } return type; } function isContextSensitiveExpression(node) { switch (node.kind) { - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: return !node.typeParameters && !ts.forEach(node.parameters, function (p) { return p.type; }); - case 133 /* ObjectLiteral */: - return ts.forEach(node.properties, function (p) { return p.kind === 134 /* PropertyAssignment */ && isContextSensitiveExpression(p.initializer); }); - case 132 /* ArrayLiteral */: + case 135 /* ObjectLiteral */: + return ts.forEach(node.properties, function (p) { return p.kind === 136 /* PropertyAssignment */ && isContextSensitiveExpression(p.initializer); }); + case 134 /* ArrayLiteral */: return ts.forEach(node.elements, function (e) { return isContextSensitiveExpression(e); }); - case 146 /* ConditionalExpression */: + case 148 /* ConditionalExpression */: return isContextSensitiveExpression(node.whenTrue) || isContextSensitiveExpression(node.whenFalse); - case 145 /* BinaryExpression */: + case 147 /* BinaryExpression */: return node.operator === 44 /* BarBarToken */ && (isContextSensitiveExpression(node.left) || isContextSensitiveExpression(node.right)); } return false; } function getTypeWithoutConstructors(type) { if (type.flags & ts.TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); + var resolved = resolveObjectOrUnionTypeMembers(type); if (resolved.constructSignatures.length) { - var result = createObjectType(16384 /* Anonymous */, type.symbol); + var result = createObjectType(32768 /* Anonymous */, type.symbol); result.members = resolved.members; result.properties = resolved.properties; result.callSignatures = resolved.callSignatures; @@ -10875,7 +11419,7 @@ var ts; var ok = true; for (var i = 0, len = type.baseTypes.length; i < len; ++i) { var base = type.baseTypes[i]; - var properties = getPropertiesOfType(base); + var properties = getPropertiesOfObjectType(base); for (var j = 0, proplen = properties.length; j < proplen; ++j) { var prop = properties[j]; if (!ts.hasProperty(seen, prop.name)) { @@ -10960,7 +11504,17 @@ var ts; return true; } } - if (source.flags & 512 /* TypeParameter */ && target.flags & 512 /* TypeParameter */) { + if (source.flags & 16384 /* Union */) { + if (unionTypeRelatedToType(source, target, reportErrors)) { + return true; + } + } + else if (target.flags & 16384 /* Union */) { + if (typeRelatedToUnionType(source, target, reportErrors)) { + return true; + } + } + else if (source.flags & 512 /* TypeParameter */ && target.flags & 512 /* TypeParameter */) { if (typeParameterRelatedTo(source, target, reportErrors)) { return true; } @@ -10988,6 +11542,24 @@ var ts; } return false; } + function typeRelatedToUnionType(source, target, reportErrors) { + var targetTypes = target.types; + for (var i = 0, len = targetTypes.length; i < len; i++) { + if (isRelatedTo(source, targetTypes[i], reportErrors && i === len - 1)) { + return true; + } + } + return false; + } + function unionTypeRelatedToType(source, target, reportErrors) { + var sourceTypes = source.types; + for (var i = 0, len = sourceTypes.length; i < len; i++) { + if (!isRelatedTo(sourceTypes[i], target, reportErrors)) { + return false; + } + } + return true; + } function typesRelatedTo(sources, targets, reportErrors) { for (var i = 0, len = sources.length; i < len; i++) { if (!isRelatedTo(sources[i], targets[i], reportErrors)) @@ -11075,35 +11647,15 @@ var ts; } function propertiesRelatedTo(source, target, reportErrors) { if (relation === identityRelation) { - return propertiesAreIdenticalTo(source, target, reportErrors); + return propertiesIdenticalTo(source, target, reportErrors); } - else { - return propertiesAreSubtypeOrAssignableTo(source, target, reportErrors); - } - } - function propertiesAreIdenticalTo(source, target, reportErrors) { - var sourceProperties = getPropertiesOfType(source); - var targetProperties = getPropertiesOfType(target); - if (sourceProperties.length !== targetProperties.length) { - return false; - } - for (var i = 0, len = sourceProperties.length; i < len; ++i) { - var sourceProp = sourceProperties[i]; - var targetProp = getPropertyOfType(target, sourceProp.name); - if (!targetProp || !isPropertyIdenticalToRecursive(sourceProp, targetProp, reportErrors, isRelatedTo)) { - return false; - } - } - return true; - } - function propertiesAreSubtypeOrAssignableTo(source, target, reportErrors) { - var properties = getPropertiesOfType(target); + var properties = getPropertiesOfObjectType(target); for (var i = 0; i < properties.length; i++) { var targetProp = properties[i]; - var sourceProp = getPropertyOfApparentType(source, targetProp.name); + var sourceProp = getPropertyOfType(source, targetProp.name); if (sourceProp !== targetProp) { if (!sourceProp) { - if (!isOptionalProperty(targetProp)) { + if (relation === subtypeRelation || !isOptionalProperty(targetProp)) { if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_missing_in_type_1, symbolToString(targetProp), typeToString(source)); } @@ -11160,67 +11712,25 @@ var ts; } return true; } - function signaturesRelatedTo(source, target, kind, reportErrors) { - if (relation === identityRelation) { - return areSignaturesIdenticalTo(source, target, kind, reportErrors); - } - else { - return areSignaturesSubtypeOrAssignableTo(source, target, kind, reportErrors); - } - } - function areSignaturesIdenticalTo(source, target, kind, reportErrors) { - var sourceSignatures = getSignaturesOfType(source, kind); - var targetSignatures = getSignaturesOfType(target, kind); - if (sourceSignatures.length !== targetSignatures.length) { + function propertiesIdenticalTo(source, target, reportErrors) { + var sourceProperties = getPropertiesOfObjectType(source); + var targetProperties = getPropertiesOfObjectType(target); + if (sourceProperties.length !== targetProperties.length) { return false; } - for (var i = 0, len = sourceSignatures.length; i < len; ++i) { - if (!isSignatureIdenticalTo(sourceSignatures[i], targetSignatures[i], reportErrors)) { + for (var i = 0, len = sourceProperties.length; i < len; ++i) { + var sourceProp = sourceProperties[i]; + var targetProp = getPropertyOfObjectType(target, sourceProp.name); + if (!targetProp || !isPropertyIdenticalToRecursive(sourceProp, targetProp, reportErrors, isRelatedTo)) { return false; } } return true; } - function isSignatureIdenticalTo(source, target, reportErrors) { - if (source === target) { - return true; + function signaturesRelatedTo(source, target, kind, reportErrors) { + if (relation === identityRelation) { + return signaturesIdenticalTo(source, target, kind, reportErrors); } - if (source.hasRestParameter !== target.hasRestParameter) { - return false; - } - if (source.parameters.length !== target.parameters.length) { - return false; - } - if (source.minArgumentCount !== target.minArgumentCount) { - return false; - } - if (source.typeParameters && target.typeParameters) { - if (source.typeParameters.length !== target.typeParameters.length) { - return false; - } - for (var i = 0, len = source.typeParameters.length; i < len; ++i) { - if (!isRelatedTo(source.typeParameters[i], target.typeParameters[i], reportErrors)) { - return false; - } - } - } - else if (source.typeParameters || source.typeParameters) { - return false; - } - source = getErasedSignature(source); - target = getErasedSignature(target); - for (var i = 0, len = source.parameters.length; i < len; i++) { - var s = source.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(source) : getTypeOfSymbol(source.parameters[i]); - var t = target.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(target) : getTypeOfSymbol(target.parameters[i]); - if (!isRelatedTo(s, t, reportErrors)) { - return false; - } - } - var t = getReturnTypeOfSignature(target); - var s = getReturnTypeOfSignature(source); - return isRelatedTo(s, t, reportErrors); - } - function areSignaturesSubtypeOrAssignableTo(source, target, kind, reportErrors) { if (target === anyFunctionType || source === anyFunctionType) return true; var sourceSignatures = getSignaturesOfType(source, kind); @@ -11228,12 +11738,12 @@ var ts; var saveErrorInfo = errorInfo; outer: for (var i = 0; i < targetSignatures.length; i++) { var t = targetSignatures[i]; - if (!t.hasStringLiterals || target.flags & 32768 /* FromSignature */) { + if (!t.hasStringLiterals || target.flags & 65536 /* FromSignature */) { var localErrors = reportErrors; for (var j = 0; j < sourceSignatures.length; j++) { var s = sourceSignatures[j]; - if (!s.hasStringLiterals || source.flags & 32768 /* FromSignature */) { - if (isSignatureSubtypeOrAssignableTo(s, t, localErrors)) { + if (!s.hasStringLiterals || source.flags & 65536 /* FromSignature */) { + if (signatureRelatedTo(s, t, localErrors)) { errorInfo = saveErrorInfo; continue outer; } @@ -11245,7 +11755,7 @@ var ts; } return true; } - function isSignatureSubtypeOrAssignableTo(source, target, reportErrors) { + function signatureRelatedTo(source, target, reportErrors) { if (source === target) { return true; } @@ -11293,67 +11803,107 @@ var ts; var s = getReturnTypeOfSignature(source); return isRelatedTo(s, t, reportErrors); } + function signaturesIdenticalTo(source, target, kind, reportErrors) { + var sourceSignatures = getSignaturesOfType(source, kind); + var targetSignatures = getSignaturesOfType(target, kind); + if (sourceSignatures.length !== targetSignatures.length) { + return false; + } + for (var i = 0, len = sourceSignatures.length; i < len; ++i) { + if (!compareSignatures(sourceSignatures[i], targetSignatures[i], true, isRelatedTo)) { + return false; + } + } + return true; + } function stringIndexTypesRelatedTo(source, target, reportErrors) { if (relation === identityRelation) { - return areIndexTypesIdenticalTo(0 /* String */, source, target, reportErrors); + return indexTypesIdenticalTo(0 /* String */, source, target, reportErrors); } - else { - var targetType = getIndexTypeOfType(target, 0 /* String */); - if (targetType) { - var sourceType = getIndexTypeOfType(source, 0 /* String */); - if (!sourceType) { - if (reportErrors) { - reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); - } - return false; - } - if (!isRelatedTo(sourceType, targetType, reportErrors)) { - if (reportErrors) { - reportError(ts.Diagnostics.Index_signatures_are_incompatible_Colon); - } - return false; + var targetType = getIndexTypeOfType(target, 0 /* String */); + if (targetType) { + var sourceType = getIndexTypeOfType(source, 0 /* String */); + if (!sourceType) { + if (reportErrors) { + reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } + return false; + } + if (!isRelatedTo(sourceType, targetType, reportErrors)) { + if (reportErrors) { + reportError(ts.Diagnostics.Index_signatures_are_incompatible_Colon); + } + return false; } - return true; } + return true; } function numberIndexTypesRelatedTo(source, target, reportErrors) { if (relation === identityRelation) { - return areIndexTypesIdenticalTo(1 /* Number */, source, target, reportErrors); + return indexTypesIdenticalTo(1 /* Number */, source, target, reportErrors); } - else { - var targetType = getIndexTypeOfType(target, 1 /* Number */); - if (targetType) { - var sourceStringType = getIndexTypeOfType(source, 0 /* String */); - var sourceNumberType = getIndexTypeOfType(source, 1 /* Number */); - if (!(sourceStringType || sourceNumberType)) { - if (reportErrors) { - reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); - } - return false; - } - if (sourceStringType && sourceNumberType) { - var compatible = isRelatedTo(sourceStringType, targetType, false) || isRelatedTo(sourceNumberType, targetType, reportErrors); - } - else { - var compatible = isRelatedTo(sourceStringType || sourceNumberType, targetType, reportErrors); - } - if (!compatible) { - if (reportErrors) { - reportError(ts.Diagnostics.Index_signatures_are_incompatible_Colon); - } - return false; + var targetType = getIndexTypeOfType(target, 1 /* Number */); + if (targetType) { + var sourceStringType = getIndexTypeOfType(source, 0 /* String */); + var sourceNumberType = getIndexTypeOfType(source, 1 /* Number */); + if (!(sourceStringType || sourceNumberType)) { + if (reportErrors) { + reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } + return false; + } + if (sourceStringType && sourceNumberType) { + var compatible = isRelatedTo(sourceStringType, targetType, false) || isRelatedTo(sourceNumberType, targetType, reportErrors); + } + else { + var compatible = isRelatedTo(sourceStringType || sourceNumberType, targetType, reportErrors); + } + if (!compatible) { + if (reportErrors) { + reportError(ts.Diagnostics.Index_signatures_are_incompatible_Colon); + } + return false; } - return true; } + return true; } - function areIndexTypesIdenticalTo(indexKind, source, target, reportErrors) { + function indexTypesIdenticalTo(indexKind, source, target, reportErrors) { var targetType = getIndexTypeOfType(target, indexKind); var sourceType = getIndexTypeOfType(source, indexKind); return (!sourceType && !targetType) || (sourceType && targetType && isRelatedTo(sourceType, targetType, reportErrors)); } } + function compareSignatures(source, target, compareReturnTypes, compareTypes) { + if (source === target) { + return true; + } + if (source.parameters.length !== target.parameters.length || source.minArgumentCount !== target.minArgumentCount || source.hasRestParameter !== target.hasRestParameter) { + return false; + } + if (source.typeParameters && target.typeParameters) { + if (source.typeParameters.length !== target.typeParameters.length) { + return false; + } + for (var i = 0, len = source.typeParameters.length; i < len; ++i) { + if (!compareTypes(source.typeParameters[i], target.typeParameters[i])) { + return false; + } + } + } + else if (source.typeParameters || source.typeParameters) { + return false; + } + source = getErasedSignature(source); + target = getErasedSignature(target); + for (var i = 0, len = source.parameters.length; i < len; i++) { + var s = source.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(source) : getTypeOfSymbol(source.parameters[i]); + var t = target.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(target) : getTypeOfSymbol(target.parameters[i]); + if (!compareTypes(s, t)) { + return false; + } + } + return !compareReturnTypes || compareTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target)); + } function isSupertypeOfEach(candidate, types) { for (var i = 0, len = types.length; i < len; i++) { if (candidate !== types[i] && !isTypeSubtypeOf(types[i], candidate)) @@ -11361,13 +11911,11 @@ var ts; } return true; } - function getBestCommonType(types, contextualType, candidatesOnly) { - if (contextualType && isSupertypeOfEach(contextualType, types)) - return contextualType; - return ts.forEach(types, function (t) { return isSupertypeOfEach(t, types) ? t : undefined; }) || (candidatesOnly ? undefined : emptyObjectType); + function getCommonSupertype(types) { + return ts.forEach(types, function (t) { return isSupertypeOfEach(t, types) ? t : undefined; }); } function isTypeOfObjectLiteral(type) { - return (type.flags & 16384 /* Anonymous */) && type.symbol && (type.symbol.flags & 1024 /* ObjectLiteral */) ? true : false; + return (type.flags & 32768 /* Anonymous */) && type.symbol && (type.symbol.flags & 1024 /* ObjectLiteral */) ? true : false; } function isArrayType(type) { return type.flags & 4096 /* Reference */ && type.target === globalArrayType; @@ -11378,10 +11926,13 @@ var ts; } return type; } - function getWidenedType(type, supressNoImplicitAnyErrors) { + function getWidenedType(type, suppressNoImplicitAnyErrors) { if (type.flags & (32 /* Undefined */ | 64 /* Null */)) { return anyType; } + if (type.flags & 16384 /* Union */) { + return getWidenedTypeOfUnion(type); + } if (isTypeOfObjectLiteral(type)) { return getWidenedTypeOfObjectLiteral(type); } @@ -11389,8 +11940,11 @@ var ts; return getWidenedTypeOfArrayLiteral(type); } return type; + function getWidenedTypeOfUnion(type) { + return getUnionType(ts.map(type.types, function (t) { return getWidenedType(t, suppressNoImplicitAnyErrors); })); + } function getWidenedTypeOfObjectLiteral(type) { - var properties = getPropertiesOfType(type); + var properties = getPropertiesOfObjectType(type); if (properties.length) { var widenedTypes = []; var propTypeWasWidened = false; @@ -11399,7 +11953,7 @@ var ts; var widenedType = getWidenedType(propType); if (propType !== widenedType) { propTypeWasWidened = true; - if (!supressNoImplicitAnyErrors && program.getCompilerOptions().noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + if (!suppressNoImplicitAnyErrors && compilerOptions.noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { error(p.valueDeclaration, ts.Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(widenedType)); } } @@ -11409,7 +11963,7 @@ var ts; var members = {}; var index = 0; ts.forEach(properties, function (p) { - var symbol = createSymbol(2 /* Property */ | 33554432 /* Transient */, p.name); + var symbol = createSymbol(2 /* Property */ | 33554432 /* Transient */ | p.flags, p.name); symbol.declarations = p.declarations; symbol.parent = p.parent; symbol.type = widenedTypes[index++]; @@ -11431,7 +11985,7 @@ var ts; } function getWidenedTypeOfArrayLiteral(type) { var elementType = type.typeArguments[0]; - var widenedType = getWidenedType(elementType, supressNoImplicitAnyErrors); + var widenedType = getWidenedType(elementType, suppressNoImplicitAnyErrors); type = elementType !== widenedType ? createArrayType(widenedType) : type; return type; } @@ -11462,12 +12016,14 @@ var ts; callback(s, t); } } - function createInferenceContext(typeParameters) { + function createInferenceContext(typeParameters, inferUnionTypes) { var inferences = []; for (var i = 0; i < typeParameters.length; i++) inferences.push([]); return { typeParameters: typeParameters, + inferUnionTypes: inferUnionTypes, + inferenceCount: 0, inferences: inferences, inferredTypes: new Array(typeParameters.length) }; @@ -11502,6 +12058,7 @@ var ts; var typeParameters = context.typeParameters; for (var i = 0; i < typeParameters.length; i++) { if (target === typeParameters[i]) { + context.inferenceCount++; var inferences = context.inferences[i]; if (!ts.contains(inferences, source)) inferences.push(source); @@ -11516,7 +12073,32 @@ var ts; inferFromTypes(sourceTypes[i], targetTypes[i]); } } - else if (source.flags & ts.TypeFlags.ObjectType && (target.flags & (4096 /* Reference */ | 8192 /* Tuple */) || (target.flags & 16384 /* Anonymous */) && target.symbol && target.symbol.flags & (2048 /* Method */ | 512 /* TypeLiteral */))) { + else if (target.flags & 16384 /* Union */) { + var targetTypes = target.types; + var startCount = context.inferenceCount; + var typeParameterCount = 0; + var typeParameter; + for (var i = 0; i < targetTypes.length; i++) { + var t = targetTypes[i]; + if (t.flags & 512 /* TypeParameter */ && ts.contains(context.typeParameters, t)) { + typeParameter = t; + typeParameterCount++; + } + else { + inferFromTypes(source, t); + } + } + if (context.inferenceCount === startCount && typeParameterCount === 1) { + inferFromTypes(source, typeParameter); + } + } + else if (source.flags & 16384 /* Union */) { + var sourceTypes = source.types; + for (var i = 0; i < sourceTypes.length; i++) { + inferFromTypes(sourceTypes[i], target); + } + } + else if (source.flags & ts.TypeFlags.ObjectType && (target.flags & (4096 /* Reference */ | 8192 /* Tuple */) || (target.flags & 32768 /* Anonymous */) && target.symbol && target.symbol.flags & (2048 /* Method */ | 512 /* TypeLiteral */))) { if (!isInProcess(source, target) && isWithinDepthLimit(source, sourceStack) && isWithinDepthLimit(target, targetStack)) { if (depth === 0) { sourceStack = []; @@ -11536,10 +12118,10 @@ var ts; } } function inferFromProperties(source, target) { - var properties = getPropertiesOfType(target); + var properties = getPropertiesOfObjectType(target); for (var i = 0; i < properties.length; i++) { var targetProp = properties[i]; - var sourceProp = getPropertyOfType(source, targetProp.name); + var sourceProp = getPropertyOfObjectType(source, targetProp.name); if (sourceProp) { inferFromTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp)); } @@ -11572,9 +12154,16 @@ var ts; function getInferredType(context, index) { var result = context.inferredTypes[index]; if (!result) { - var commonType = getWidenedType(getBestCommonType(context.inferences[index])); + var inferences = context.inferences[index]; + if (inferences.length) { + var unionOrSuperType = context.inferUnionTypes ? getUnionType(inferences) : getCommonSupertype(inferences); + var inferredType = unionOrSuperType ? getWidenedType(unionOrSuperType) : undefinedType; + } + else { + inferredType = emptyObjectType; + } var constraint = getConstraintOfTypeParameter(context.typeParameters[index]); - var result = constraint && !isTypeAssignableTo(commonType, constraint) ? constraint : commonType; + var result = constraint && !isTypeAssignableTo(inferredType, constraint) ? constraint : inferredType; context.inferredTypes[index] = result; } return result; @@ -11589,37 +12178,244 @@ var ts; function hasAncestor(node, kind) { return ts.getAncestor(node, kind) !== undefined; } - function checkIdentifier(node) { - function isInTypeQuery(node) { - while (node) { - switch (node.kind) { - case 128 /* TypeQuery */: - return true; - case 59 /* Identifier */: - case 116 /* QualifiedName */: - node = node.parent; - continue; - default: - return false; + function getResolvedSymbol(node) { + var links = getNodeLinks(node); + if (!links.resolvedSymbol) { + links.resolvedSymbol = resolveName(node, node.text, ts.SymbolFlags.Value | 524288 /* ExportValue */, ts.Diagnostics.Cannot_find_name_0, ts.identifierToString(node)) || unknownSymbol; + } + return links.resolvedSymbol; + } + function isInTypeQuery(node) { + while (node) { + switch (node.kind) { + case 128 /* TypeQuery */: + return true; + case 59 /* Identifier */: + case 116 /* QualifiedName */: + node = node.parent; + continue; + default: + return false; + } + } + ts.Debug.fail("should not get here"); + } + function subtractPrimitiveTypes(type, subtractMask) { + if (type.flags & 16384 /* Union */) { + var types = type.types; + if (ts.forEach(types, function (t) { return t.flags & subtractMask; })) { + return getUnionType(ts.filter(types, function (t) { return !(t.flags & subtractMask); })); + } + } + return type; + } + function isVariableAssignedWithin(symbol, node) { + var links = getNodeLinks(node); + if (links.assignmentChecks) { + var cachedResult = links.assignmentChecks[symbol.id]; + if (cachedResult !== undefined) { + return cachedResult; + } + } + else { + links.assignmentChecks = {}; + } + return links.assignmentChecks[symbol.id] = isAssignedIn(node); + function isAssignedInBinaryExpression(node) { + if (node.operator >= ts.SyntaxKind.FirstAssignment && node.operator <= ts.SyntaxKind.LastAssignment) { + var n = node.left; + while (n.kind === 142 /* ParenExpression */) { + n = n.expression; + } + if (n.kind === 59 /* Identifier */ && getResolvedSymbol(n) === symbol) { + return true; } } - ts.Debug.fail("should not get here"); + return ts.forEachChild(node, isAssignedIn); } - var symbol = resolveName(node, node.text, ts.SymbolFlags.Value | 524288 /* ExportValue */, ts.Diagnostics.Cannot_find_name_0, ts.identifierToString(node)); - if (!symbol) { - symbol = unknownSymbol; + function isAssignedInVariableDeclaration(node) { + if (getSymbolOfNode(node) === symbol && node.initializer) { + return true; + } + return ts.forEachChild(node, isAssignedIn); } + function isAssignedIn(node) { + switch (node.kind) { + case 147 /* BinaryExpression */: + return isAssignedInBinaryExpression(node); + case 173 /* VariableDeclaration */: + return isAssignedInVariableDeclaration(node); + case 134 /* ArrayLiteral */: + case 135 /* ObjectLiteral */: + case 137 /* PropertyAccess */: + case 138 /* IndexedAccess */: + case 139 /* CallExpression */: + case 140 /* NewExpression */: + case 141 /* TypeAssertion */: + case 142 /* ParenExpression */: + case 145 /* PrefixOperator */: + case 146 /* PostfixOperator */: + case 148 /* ConditionalExpression */: + case 150 /* Block */: + case 151 /* VariableStatement */: + case 153 /* ExpressionStatement */: + case 154 /* IfStatement */: + case 155 /* DoStatement */: + case 156 /* WhileStatement */: + case 157 /* ForStatement */: + case 158 /* ForInStatement */: + case 161 /* ReturnStatement */: + case 162 /* WithStatement */: + case 163 /* SwitchStatement */: + case 164 /* CaseClause */: + case 165 /* DefaultClause */: + case 166 /* LabeledStatement */: + case 167 /* ThrowStatement */: + case 168 /* TryStatement */: + case 169 /* TryBlock */: + case 170 /* CatchBlock */: + case 171 /* FinallyBlock */: + return ts.forEachChild(node, isAssignedIn); + } + return false; + } + } + function getNarrowedTypeOfSymbol(symbol, node) { + var type = getTypeOfSymbol(symbol); + if (symbol.flags & 1 /* Variable */ && type.flags & ts.TypeFlags.Structured) { + while (true) { + var child = node; + node = node.parent; + if (!node || node.kind === 175 /* FunctionBlock */ || node.kind === 180 /* ModuleBlock */) { + break; + } + var narrowedType = type; + switch (node.kind) { + case 154 /* IfStatement */: + if (child !== node.expression) { + narrowedType = narrowType(type, node.expression, child === node.thenStatement); + } + break; + case 148 /* ConditionalExpression */: + if (child !== node.condition) { + narrowedType = narrowType(type, node.condition, child === node.whenTrue); + } + break; + case 147 /* BinaryExpression */: + if (child === node.right) { + if (node.operator === 43 /* AmpersandAmpersandToken */) { + narrowedType = narrowType(type, node.left, true); + } + else if (node.operator === 44 /* BarBarToken */) { + narrowedType = narrowType(type, node.left, false); + } + } + break; + } + if (narrowedType !== type) { + if (isVariableAssignedWithin(symbol, node)) { + break; + } + type = narrowedType; + } + } + } + return type; + function narrowTypeByEquality(type, expr, assumeTrue) { + var left = expr.left; + var right = expr.right; + if (left.kind !== 145 /* PrefixOperator */ || left.operator !== 91 /* TypeOfKeyword */ || left.operand.kind !== 59 /* Identifier */ || right.kind !== 7 /* StringLiteral */ || getResolvedSymbol(left.operand) !== symbol) { + return type; + } + var t = right.text; + var checkType = t === "string" ? stringType : t === "number" ? numberType : t === "boolean" ? booleanType : emptyObjectType; + if (expr.operator === 26 /* ExclamationEqualsEqualsToken */) { + assumeTrue = !assumeTrue; + } + if (assumeTrue) { + return checkType === emptyObjectType ? subtractPrimitiveTypes(type, 2 /* String */ | 4 /* Number */ | 8 /* Boolean */) : checkType; + } + else { + return checkType === emptyObjectType ? type : subtractPrimitiveTypes(type, checkType.flags); + } + } + function narrowTypeByAnd(type, expr, assumeTrue) { + if (assumeTrue) { + return narrowType(narrowType(type, expr.left, true), expr.right, true); + } + else { + return getUnionType([ + narrowType(type, expr.left, false), + narrowType(narrowType(type, expr.left, true), expr.right, false) + ]); + } + } + function narrowTypeByOr(type, expr, assumeTrue) { + if (assumeTrue) { + return getUnionType([ + narrowType(type, expr.left, true), + narrowType(narrowType(type, expr.left, false), expr.right, true) + ]); + } + else { + return narrowType(narrowType(type, expr.left, false), expr.right, false); + } + } + function narrowTypeByInstanceof(type, expr, assumeTrue) { + if (!assumeTrue || expr.left.kind !== 59 /* Identifier */ || getResolvedSymbol(expr.left) !== symbol) { + return type; + } + var rightType = checkExpression(expr.right); + if (!isTypeSubtypeOf(rightType, globalFunctionType)) { + return type; + } + var prototypeProperty = getPropertyOfType(rightType, "prototype"); + if (!prototypeProperty) { + return type; + } + var prototypeType = getTypeOfSymbol(prototypeProperty); + return isTypeSubtypeOf(prototypeType, type) ? prototypeType : type; + } + function narrowType(type, expr, assumeTrue) { + switch (expr.kind) { + case 142 /* ParenExpression */: + return narrowType(type, expr.expression, assumeTrue); + case 147 /* BinaryExpression */: + var operator = expr.operator; + if (operator === 25 /* EqualsEqualsEqualsToken */ || operator === 26 /* ExclamationEqualsEqualsToken */) { + return narrowTypeByEquality(type, expr, assumeTrue); + } + else if (operator === 43 /* AmpersandAmpersandToken */) { + return narrowTypeByAnd(type, expr, assumeTrue); + } + else if (operator === 44 /* BarBarToken */) { + return narrowTypeByOr(type, expr, assumeTrue); + } + else if (operator === 81 /* InstanceOfKeyword */) { + return narrowTypeByInstanceof(type, expr, assumeTrue); + } + break; + case 145 /* PrefixOperator */: + if (expr.operator === 41 /* ExclamationToken */) { + return narrowType(type, expr.operand, !assumeTrue); + } + break; + } + return type; + } + } + function checkIdentifier(node) { + var symbol = getResolvedSymbol(node); if (symbol.flags & 4194304 /* Import */) { getSymbolLinks(symbol).referenced = !isInTypeQuery(node); } - getNodeLinks(node).resolvedSymbol = symbol; checkCollisionWithCapturedSuperVariable(node, node); checkCollisionWithCapturedThisVariable(node, node); checkCollisionWithIndexVariableInGeneratedCode(node, node); - return getTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol)); + return getNarrowedTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol), node); } function captureLexicalThis(node, container) { - var classNode = container.parent && container.parent.kind === 174 /* ClassDeclaration */ ? container.parent : undefined; + var classNode = container.parent && container.parent.kind === 176 /* ClassDeclaration */ ? container.parent : undefined; getNodeLinks(node).flags |= 2 /* LexicalThis */; if (container.kind === 119 /* Property */ || container.kind === 121 /* Constructor */) { getNodeLinks(classNode).flags |= 4 /* CaptureThis */; @@ -11631,15 +12427,15 @@ var ts; function checkThisExpression(node) { var container = ts.getThisContainer(node, true); var needToCaptureLexicalThis = false; - if (container.kind === 142 /* ArrowFunction */) { + if (container.kind === 144 /* ArrowFunction */) { container = ts.getThisContainer(container, false); needToCaptureLexicalThis = true; } switch (container.kind) { - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_module_body); break; - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: error(node, ts.Diagnostics.this_cannot_be_referenced_in_current_location); break; case 121 /* Constructor */: @@ -11656,7 +12452,7 @@ var ts; if (needToCaptureLexicalThis) { captureLexicalThis(node, container); } - var classNode = container.parent && container.parent.kind === 174 /* ClassDeclaration */ ? container.parent : undefined; + var classNode = container.parent && container.parent.kind === 176 /* ClassDeclaration */ ? container.parent : undefined; if (classNode) { var symbol = getSymbolOfNode(classNode); return container.flags & 128 /* Static */ ? getTypeOfSymbol(symbol) : getDeclaredTypeOfSymbol(symbol); @@ -11669,9 +12465,9 @@ var ts; if (!node) return node; switch (node.kind) { - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: case 119 /* Property */: case 120 /* Method */: case 121 /* Constructor */: @@ -11690,8 +12486,8 @@ var ts; return false; } function checkSuperExpression(node) { - var isCallExpression = node.parent.kind === 137 /* CallExpression */ && node.parent.func === node; - var enclosingClass = ts.getAncestor(node, 174 /* ClassDeclaration */); + var isCallExpression = node.parent.kind === 139 /* CallExpression */ && node.parent.func === node; + var enclosingClass = ts.getAncestor(node, 176 /* ClassDeclaration */); var baseClass; if (enclosingClass && enclosingClass.baseType) { var classType = getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClass)); @@ -11709,11 +12505,11 @@ var ts; } else { var needToCaptureLexicalThis = false; - while (container && container.kind === 142 /* ArrowFunction */) { + while (container && container.kind === 144 /* ArrowFunction */) { container = getSuperContainer(container); needToCaptureLexicalThis = true; } - if (container && container.parent && container.parent.kind === 174 /* ClassDeclaration */) { + if (container && container.parent && container.parent.kind === 176 /* ClassDeclaration */) { if (container.flags & 128 /* Static */) { canUseSuperExpression = container.kind === 120 /* Method */ || container.kind === 122 /* GetAccessor */ || container.kind === 123 /* SetAccessor */; } @@ -11752,11 +12548,19 @@ var ts; } function getContextuallyTypedParameterType(parameter) { var func = parameter.parent; - if (func.kind === 141 /* FunctionExpression */ || func.kind === 142 /* ArrowFunction */) { + if (func.kind === 143 /* FunctionExpression */ || func.kind === 144 /* ArrowFunction */) { if (isContextSensitiveExpression(func)) { - var signature = getContextualSignature(func); - if (signature) { - return getTypeAtPosition(signature, ts.indexOf(func.parameters, parameter)); + var contextualSignature = getContextualSignature(func); + if (contextualSignature) { + var funcHasRestParameters = ts.hasRestParameters(func); + var len = func.parameters.length - (funcHasRestParameters ? 1 : 0); + var indexOfParameter = ts.indexOf(func.parameters, parameter); + if (indexOfParameter < len) { + return getTypeAtPosition(contextualSignature, indexOfParameter); + } + if (indexOfParameter === (func.parameters.length - 1) && funcHasRestParameters && contextualSignature.hasRestParameter && func.parameters.length >= contextualSignature.parameters.length) { + return getTypeOfSymbol(contextualSignature.parameters[contextualSignature.parameters.length - 1]); + } } } } @@ -11813,17 +12617,51 @@ var ts; } return undefined; } + function applyToContextualType(type, mapper) { + if (!(type.flags & 16384 /* Union */)) { + return mapper(type); + } + var types = type.types; + var mappedType; + var mappedTypes; + for (var i = 0; i < types.length; i++) { + var t = mapper(types[i]); + if (t) { + if (!mappedType) { + mappedType = t; + } + else if (!mappedTypes) { + mappedTypes = [mappedType, t]; + } + else { + mappedTypes.push(t); + } + } + } + return mappedTypes ? getUnionType(mappedTypes) : mappedType; + } + function getTypeOfPropertyOfContextualType(type, name) { + return applyToContextualType(type, function (t) { + var prop = getPropertyOfObjectType(t, name); + return prop ? getTypeOfSymbol(prop) : undefined; + }); + } + function getIndexTypeOfContextualType(type, kind) { + return applyToContextualType(type, function (t) { return getIndexTypeOfObjectOrUnionType(t, kind); }); + } + function contextualTypeIsTupleType(type) { + return !!(type.flags & 16384 /* Union */ ? ts.forEach(type.types, function (t) { return getPropertyOfObjectType(t, "0"); }) : getPropertyOfObjectType(type, "0")); + } + function contextualTypeHasIndexSignature(type, kind) { + return !!(type.flags & 16384 /* Union */ ? ts.forEach(type.types, function (t) { return getIndexTypeOfObjectOrUnionType(t, kind); }) : getIndexTypeOfObjectOrUnionType(type, kind)); + } function getContextualTypeForPropertyExpression(node) { var declaration = node.parent; var objectLiteral = declaration.parent; var type = getContextualType(objectLiteral); var name = declaration.name.text; if (type && name) { - var prop = getPropertyOfType(type, name); - if (prop) { - return getTypeOfSymbol(prop); - } - return isNumericName(name) && getIndexTypeOfType(type, 1 /* Number */) || getIndexTypeOfType(type, 0 /* String */); + return getTypeOfPropertyOfContextualType(type, name) || isNumericName(name) && getIndexTypeOfContextualType(type, 1 /* Number */) || getIndexTypeOfContextualType(type, 0 /* String */); } return undefined; } @@ -11832,11 +12670,7 @@ var ts; var type = getContextualType(arrayLiteral); if (type) { var index = ts.indexOf(arrayLiteral.elements, node); - var prop = getPropertyOfType(type, "" + index); - if (prop) { - return getTypeOfSymbol(prop); - } - return getIndexTypeOfType(type, 1 /* Number */); + return getTypeOfPropertyOfContextualType(type, "" + index) || getIndexTypeOfContextualType(type, 1 /* Number */); } return undefined; } @@ -11853,70 +12687,78 @@ var ts; } var parent = node.parent; switch (parent.kind) { - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: case 118 /* Parameter */: case 119 /* Property */: return getContextualTypeForInitializerExpression(node); - case 142 /* ArrowFunction */: - case 159 /* ReturnStatement */: + case 144 /* ArrowFunction */: + case 161 /* ReturnStatement */: return getContextualTypeForReturnExpression(node); - case 137 /* CallExpression */: - case 138 /* NewExpression */: + case 139 /* CallExpression */: + case 140 /* NewExpression */: return getContextualTypeForArgument(node); - case 139 /* TypeAssertion */: + case 141 /* TypeAssertion */: return getTypeFromTypeNode(parent.type); - case 145 /* BinaryExpression */: + case 147 /* BinaryExpression */: return getContextualTypeForBinaryOperand(node); - case 134 /* PropertyAssignment */: + case 136 /* PropertyAssignment */: return getContextualTypeForPropertyExpression(node); - case 132 /* ArrayLiteral */: + case 134 /* ArrayLiteral */: return getContextualTypeForElementExpression(node); - case 146 /* ConditionalExpression */: + case 148 /* ConditionalExpression */: return getContextualTypeForConditionalOperand(node); } return undefined; } + function getNonGenericSignature(type) { + var signatures = getSignaturesOfObjectOrUnionType(type, 0 /* Call */); + if (signatures.length === 1) { + var signature = signatures[0]; + if (!signature.typeParameters) { + return signature; + } + } + } function getContextualSignature(node) { var type = getContextualType(node); - if (type) { - var signatures = getSignaturesOfType(type, 0 /* Call */); - if (signatures.length === 1) { - var signature = signatures[0]; - if (!signature.typeParameters) { - return signature; + if (!type) { + return undefined; + } + if (!(type.flags & 16384 /* Union */)) { + return getNonGenericSignature(type); + } + var result; + var types = type.types; + for (var i = 0; i < types.length; i++) { + var signature = getNonGenericSignature(types[i]); + if (signature) { + if (!result) { + result = signature; + } + else if (!compareSignatures(result, signature, true, isTypeIdenticalTo)) { + return undefined; } } } - return undefined; + return result; } function isInferentialContext(mapper) { return mapper && mapper !== identityMapper; } function checkArrayLiteral(node, contextualMapper) { - var contextualType = getContextualType(node); var elements = node.elements; - var elementTypes = []; - var isTupleLiteral = false; - for (var i = 0; i < elements.length; i++) { - if (contextualType && getPropertyOfType(contextualType, "" + i)) { - isTupleLiteral = true; - } - var element = elements[i]; - var type = element.kind !== 147 /* OmittedExpression */ ? checkExpression(element, contextualMapper) : undefinedType; - elementTypes.push(type); + if (!elements.length) { + return createArrayType(undefinedType); } - if (isTupleLiteral) { + var elementTypes = ts.map(elements, function (e) { return checkExpression(e, contextualMapper); }); + var contextualType = getContextualType(node); + if (contextualType && contextualTypeIsTupleType(contextualType)) { return createTupleType(elementTypes); } - var contextualElementType = contextualType && !isInferentialContext(contextualMapper) ? getIndexTypeOfType(contextualType, 1 /* Number */) : undefined; - var elementType = getBestCommonType(ts.uniqueElements(elementTypes), contextualElementType, true); - if (!elementType) { - elementType = elements.length ? emptyObjectType : undefinedType; - } - return createArrayType(elementType); + return createArrayType(getUnionType(elementTypes)); } function isNumericName(name) { - return !isNaN(name); + return (+name).toString() === name; } function checkObjectLiteral(node, contextualMapper) { var members = node.symbol.members; @@ -11927,7 +12769,7 @@ var ts; var member = members[id]; if (member.flags & 2 /* Property */) { var type = checkExpression(member.declarations[0].initializer, contextualMapper); - var prop = createSymbol(2 /* Property */ | 33554432 /* Transient */, member.name); + var prop = createSymbol(2 /* Property */ | 33554432 /* Transient */ | member.flags, member.name); prop.declarations = member.declarations; prop.parent = member.parent; if (member.valueDeclaration) @@ -11953,22 +12795,21 @@ var ts; var numberIndexType = getIndexType(1 /* Number */); return createAnonymousType(node.symbol, properties, emptyArray, emptyArray, stringIndexType, numberIndexType); function getIndexType(kind) { - if (contextualType) { - var indexType = getIndexTypeOfType(contextualType, kind); - if (indexType) { - var propTypes = []; - for (var id in properties) { - if (ts.hasProperty(properties, id)) { - if (kind === 0 /* String */ || isNumericName(id)) { - var type = getTypeOfSymbol(properties[id]); - if (!ts.contains(propTypes, type)) - propTypes.push(type); + if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) { + var propTypes = []; + for (var id in properties) { + if (ts.hasProperty(properties, id)) { + if (kind === 0 /* String */ || isNumericName(id)) { + var type = getTypeOfSymbol(properties[id]); + if (!ts.contains(propTypes, type)) { + propTypes.push(type); } } } - return getBestCommonType(propTypes, isInferentialContext(contextualMapper) ? undefined : indexType); } + return propTypes.length ? getUnionType(propTypes) : undefinedType; } + return undefined; } } function getDeclarationKindFromSymbol(s) { @@ -11982,7 +12823,7 @@ var ts; if (!(flags & (32 /* Private */ | 64 /* Protected */))) { return; } - var enclosingClassDeclaration = ts.getAncestor(node, 174 /* ClassDeclaration */); + var enclosingClassDeclaration = ts.getAncestor(node, 176 /* ClassDeclaration */); var enclosingClass = enclosingClassDeclaration ? getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClassDeclaration)) : undefined; var declaringClass = getDeclaredTypeOfSymbol(prop.parent); if (flags & 32 /* Private */) { @@ -12014,7 +12855,7 @@ var ts; if (apparentType === unknownType) { return unknownType; } - var prop = getPropertyOfApparentType(apparentType, node.right.text); + var prop = getPropertyOfType(apparentType, node.right.text); if (!prop) { if (node.right.text) { error(node.right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.identifierToString(node.right), typeToString(type)); @@ -12034,30 +12875,43 @@ var ts; } return anyType; } + function isValidPropertyAccess(node, propertyName) { + var type = checkExpression(node.left); + if (type !== unknownType && type !== anyType) { + var prop = getPropertyOfType(getWidenedType(type), propertyName); + if (prop && prop.parent && prop.parent.flags & 16 /* Class */) { + if (node.left.kind === 85 /* SuperKeyword */ && getDeclarationKindFromSymbol(prop) !== 120 /* Method */) { + return false; + } + else { + var diagnosticsCount = diagnostics.length; + checkClassPropertyAccess(node, type, prop); + return diagnostics.length === diagnosticsCount; + } + } + } + return true; + } function checkIndexedAccess(node) { - var objectType = checkExpression(node.object); + var objectType = getApparentType(checkExpression(node.object)); var indexType = checkExpression(node.index); if (objectType === unknownType) return unknownType; - var apparentType = getApparentType(objectType); - if (apparentType === unknownType) { - return unknownType; - } if (node.index.kind === 7 /* StringLiteral */ || node.index.kind === 6 /* NumericLiteral */) { var name = node.index.text; - var prop = getPropertyOfApparentType(apparentType, name); + var prop = getPropertyOfType(objectType, name); if (prop) { return getTypeOfSymbol(prop); } } if (indexType.flags & (1 /* Any */ | ts.TypeFlags.StringLike | ts.TypeFlags.NumberLike)) { if (indexType.flags & (1 /* Any */ | ts.TypeFlags.NumberLike)) { - var numberIndexType = getIndexTypeOfType(apparentType, 1 /* Number */); + var numberIndexType = getIndexTypeOfType(objectType, 1 /* Number */); if (numberIndexType) { return numberIndexType; } } - var stringIndexType = getIndexTypeOfType(apparentType, 0 /* String */); + var stringIndexType = getIndexTypeOfType(objectType, 0 /* String */); if (stringIndexType) { return stringIndexType; } @@ -12079,46 +12933,24 @@ var ts; resolveUntypedCall(node); return unknownSignature; } - function isCandidateSignature(node, signature) { - var args = node.arguments || emptyArray; - return args.length >= signature.minArgumentCount && (signature.hasRestParameter || args.length <= signature.parameters.length) && (!node.typeArguments || signature.typeParameters && node.typeArguments.length === signature.typeParameters.length); - } - function collectCandidates(node, signatures) { - var result = []; - var lastParent; - var lastSymbol; - var cutoffPos = 0; - var pos; - for (var i = 0; i < signatures.length; i++) { - var signature = signatures[i]; - if (isCandidateSignature(node, signature)) { - var symbol = signature.declaration && getSymbolOfNode(signature.declaration); - var parent = signature.declaration && signature.declaration.parent; - if (!lastSymbol || symbol === lastSymbol) { - if (lastParent && parent === lastParent) { - pos++; - } - else { - lastParent = parent; - pos = cutoffPos; - } - } - else { - pos = cutoffPos = result.length; - lastParent = parent; - } - lastSymbol = symbol; - for (var j = result.length; j > pos; j--) { - result[j] = result[j - 1]; - } - result[pos] = signature; - } + function signatureHasCorrectArity(node, signature) { + if (!node.arguments) { + return signature.minArgumentCount === 0; } - return result; + var args = node.arguments; + var numberOfArgs = args.hasTrailingComma ? args.length + 1 : args.length; + var hasTooManyArguments = !signature.hasRestParameter && numberOfArgs > signature.parameters.length; + var hasRightNumberOfTypeArguments = !node.typeArguments || (signature.typeParameters && node.typeArguments.length === signature.typeParameters.length); + if (hasTooManyArguments || !hasRightNumberOfTypeArguments) { + return false; + } + var callIsIncomplete = args.end === node.end; + var hasEnoughArguments = numberOfArgs >= signature.minArgumentCount; + return callIsIncomplete || hasEnoughArguments; } function getSingleCallSignature(type) { if (type.flags & ts.TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); + var resolved = resolveObjectOrUnionTypeMembers(type); if (resolved.callSignatures.length === 1 && resolved.constructSignatures.length === 0 && resolved.properties.length === 0 && !resolved.stringIndexType && !resolved.numberIndexType) { return resolved.callSignatures[0]; } @@ -12126,7 +12958,7 @@ var ts; return undefined; } function instantiateSignatureInContextOf(signature, contextualSignature, contextualMapper) { - var context = createInferenceContext(signature.typeParameters); + var context = createInferenceContext(signature.typeParameters, true); forEachMatchingParameterType(contextualSignature, signature, function (source, target) { inferTypes(context, instantiateType(source, contextualMapper), target); }); @@ -12134,9 +12966,12 @@ var ts; } function inferTypeArguments(signature, args, excludeArgument) { var typeParameters = signature.typeParameters; - var context = createInferenceContext(typeParameters); + var context = createInferenceContext(typeParameters, false); var mapper = createInferenceMapper(context); for (var i = 0; i < args.length; i++) { + if (args[i].kind === 149 /* OmittedExpression */) { + continue; + } if (!excludeArgument || excludeArgument[i] === undefined) { var parameterType = getTypeAtPosition(signature, i); inferTypes(context, checkExpressionWithContextualType(args[i], parameterType, mapper), parameterType); @@ -12144,13 +12979,17 @@ var ts; } if (excludeArgument) { for (var i = 0; i < args.length; i++) { + if (args[i].kind === 149 /* OmittedExpression */) { + continue; + } if (excludeArgument[i] === false) { var parameterType = getTypeAtPosition(signature, i); inferTypes(context, checkExpressionWithContextualType(args[i], parameterType, mapper), parameterType); } } } - return getInferredTypes(context); + var inferredTypes = getInferredTypes(context); + return ts.contains(inferredTypes, undefinedType) ? undefined : inferredTypes; } function checkTypeArguments(signature, typeArguments) { var typeParameters = signature.typeParameters; @@ -12170,6 +13009,9 @@ var ts; if (node.arguments) { for (var i = 0; i < node.arguments.length; i++) { var arg = node.arguments[i]; + if (arg.kind === 149 /* OmittedExpression */) { + continue; + } var paramType = getTypeAtPosition(signature, i); var argType = arg.kind === 7 /* StringLiteral */ && !reportErrors ? getStringLiteralType(arg) : checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined); var isValidArgument = checkTypeRelatedTo(argType, paramType, relation, reportErrors ? arg : undefined, ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1, ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1); @@ -12180,9 +13022,10 @@ var ts; } return true; } - function resolveCall(node, signatures) { + function resolveCall(node, signatures, candidatesOutArray) { ts.forEach(node.typeArguments, checkSourceElement); - var candidates = collectCandidates(node, signatures); + var candidates = candidatesOutArray || []; + collectCandidates(); if (!candidates.length) { error(node, ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); return resolveErrorCall(node); @@ -12197,14 +13040,22 @@ var ts; } } var relation = candidates.length === 1 ? assignableRelation : subtypeRelation; + var lastCandidate; while (true) { for (var i = 0; i < candidates.length; i++) { + if (!signatureHasCorrectArity(node, candidates[i])) { + continue; + } while (true) { var candidate = candidates[i]; if (candidate.typeParameters) { var typeArguments = node.typeArguments ? checkTypeArguments(candidate, node.typeArguments) : inferTypeArguments(candidate, args, excludeArgument); + if (!typeArguments) { + break; + } candidate = getSignatureInstantiation(candidate, typeArguments); } + lastCandidate = candidate; if (!checkApplicableSignature(node, candidate, relation, excludeArgument, false)) { break; } @@ -12220,28 +13071,70 @@ var ts; } relation = assignableRelation; } - checkApplicableSignature(node, candidate, relation, undefined, true); + if (lastCandidate) { + checkApplicableSignature(node, lastCandidate, relation, undefined, true); + } + else { + error(node, ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); + } + if (!fullTypeCheck) { + for (var i = 0, n = candidates.length; i < n; i++) { + if (signatureHasCorrectArity(node, candidates[i])) { + return candidates[i]; + } + } + } return resolveErrorCall(node); + function collectCandidates() { + var result = candidates; + var lastParent; + var lastSymbol; + var cutoffPos = 0; + var pos; + ts.Debug.assert(!result.length); + for (var i = 0; i < signatures.length; i++) { + var signature = signatures[i]; + if (true) { + var symbol = signature.declaration && getSymbolOfNode(signature.declaration); + var parent = signature.declaration && signature.declaration.parent; + if (!lastSymbol || symbol === lastSymbol) { + if (lastParent && parent === lastParent) { + pos++; + } + else { + lastParent = parent; + pos = cutoffPos; + } + } + else { + pos = cutoffPos = result.length; + lastParent = parent; + } + lastSymbol = symbol; + for (var j = result.length; j > pos; j--) { + result[j] = result[j - 1]; + } + result[pos] = signature; + } + } + } } - function resolveCallExpression(node) { + function resolveCallExpression(node, candidatesOutArray) { if (node.func.kind === 85 /* SuperKeyword */) { var superType = checkSuperExpression(node.func); if (superType !== unknownType) { - return resolveCall(node, getSignaturesOfType(superType, 1 /* Construct */)); + return resolveCall(node, getSignaturesOfType(superType, 1 /* Construct */), candidatesOutArray); } return resolveUntypedCall(node); } var funcType = checkExpression(node.func); - if (funcType === unknownType) { - return resolveErrorCall(node); - } var apparentType = getApparentType(funcType); if (apparentType === unknownType) { return resolveErrorCall(node); } var callSignatures = getSignaturesOfType(apparentType, 0 /* Call */); var constructSignatures = getSignaturesOfType(apparentType, 1 /* Construct */); - if ((funcType === anyType) || (!callSignatures.length && !constructSignatures.length && isTypeAssignableTo(funcType, globalFunctionType))) { + if (funcType === anyType || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & 16384 /* Union */) && isTypeAssignableTo(funcType, globalFunctionType))) { if (node.typeArguments) { error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); } @@ -12256,13 +13149,10 @@ var ts; } return resolveErrorCall(node); } - return resolveCall(node, callSignatures); + return resolveCall(node, callSignatures, candidatesOutArray); } - function resolveNewExpression(node) { + function resolveNewExpression(node, candidatesOutArray) { var expressionType = checkExpression(node.func); - if (expressionType === unknownType) { - return resolveErrorCall(node); - } if (expressionType === anyType) { if (node.typeArguments) { error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); @@ -12275,11 +13165,11 @@ var ts; } var constructSignatures = getSignaturesOfType(expressionType, 1 /* Construct */); if (constructSignatures.length) { - return resolveCall(node, constructSignatures); + return resolveCall(node, constructSignatures, candidatesOutArray); } var callSignatures = getSignaturesOfType(expressionType, 0 /* Call */); if (callSignatures.length) { - var signature = resolveCall(node, callSignatures); + var signature = resolveCall(node, callSignatures, candidatesOutArray); if (getReturnTypeOfSignature(signature) !== voidType) { error(node, ts.Diagnostics.Only_a_void_function_can_be_called_with_the_new_keyword); } @@ -12288,11 +13178,11 @@ var ts; error(node, ts.Diagnostics.Cannot_use_new_with_an_expression_whose_type_lacks_a_call_or_construct_signature); return resolveErrorCall(node); } - function getResolvedSignature(node) { + function getResolvedSignature(node, candidatesOutArray) { var links = getNodeLinks(node); - if (!links.resolvedSignature) { + if (!links.resolvedSignature || candidatesOutArray) { links.resolvedSignature = anySignature; - links.resolvedSignature = node.kind === 137 /* CallExpression */ ? resolveCallExpression(node) : resolveNewExpression(node); + links.resolvedSignature = node.kind === 139 /* CallExpression */ ? resolveCallExpression(node, candidatesOutArray) : resolveNewExpression(node, candidatesOutArray); } return links.resolvedSignature; } @@ -12301,7 +13191,7 @@ var ts; if (node.func.kind === 85 /* SuperKeyword */) { return voidType; } - if (node.kind === 138 /* NewExpression */) { + if (node.kind === 140 /* NewExpression */) { var declaration = signature.declaration; if (declaration && (declaration.kind !== 121 /* Constructor */ && declaration.kind !== 125 /* ConstructSignature */)) { if (compilerOptions.noImplicitAny) { @@ -12340,23 +13230,24 @@ var ts; } } function getReturnTypeFromBody(func, contextualMapper) { - if (func.body.kind !== 173 /* FunctionBlock */) { + var contextualSignature = getContextualSignature(func); + if (func.body.kind !== 175 /* FunctionBlock */) { var unwidenedType = checkAndMarkExpression(func.body, contextualMapper); var widenedType = getWidenedType(unwidenedType); - if (fullTypeCheck && compilerOptions.noImplicitAny && widenedType !== unwidenedType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + if (fullTypeCheck && compilerOptions.noImplicitAny && !contextualSignature && widenedType !== unwidenedType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { error(func, ts.Diagnostics.Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type, typeToString(widenedType)); } return widenedType; } var types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper); if (types.length > 0) { - var commonType = getBestCommonType(types, undefined, true); + var commonType = contextualSignature ? getUnionType(types) : getCommonSupertype(types); if (!commonType) { error(func, ts.Diagnostics.No_best_common_type_exists_among_return_expressions); return unknownType; } var widenedType = getWidenedType(commonType); - if (fullTypeCheck && compilerOptions.noImplicitAny && widenedType !== commonType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + if (fullTypeCheck && compilerOptions.noImplicitAny && !contextualSignature && widenedType !== commonType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { var typeName = typeToString(widenedType); if (func.name) { error(func, ts.Diagnostics._0_which_lacks_return_type_annotation_implicitly_has_an_1_return_type, ts.identifierToString(func.name), typeName); @@ -12388,7 +13279,7 @@ var ts; }); } function bodyContainsSingleThrowStatement(body) { - return (body.statements.length === 1) && (body.statements[0].kind === 165 /* ThrowStatement */); + return (body.statements.length === 1) && (body.statements[0].kind === 167 /* ThrowStatement */); } function checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(func, returnType) { if (!fullTypeCheck) { @@ -12397,7 +13288,7 @@ var ts; if (returnType === voidType || returnType === anyType) { return; } - if (!func.body || func.body.kind !== 173 /* FunctionBlock */) { + if (!func.body || func.body.kind !== 175 /* FunctionBlock */) { return; } var bodyBlock = func.body; @@ -12441,7 +13332,7 @@ var ts; if (node.type) { checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } - if (node.body.kind === 173 /* FunctionBlock */) { + if (node.body.kind === 175 /* FunctionBlock */) { checkSourceElement(node.body); } else { @@ -12469,12 +13360,12 @@ var ts; case 59 /* Identifier */: var symbol = findSymbol(n); return !symbol || symbol === unknownSymbol || symbol === argumentsSymbol || (symbol.flags & 1 /* Variable */) !== 0; - case 135 /* PropertyAccess */: + case 137 /* PropertyAccess */: var symbol = findSymbol(n); return !symbol || symbol === unknownSymbol || (symbol.flags & ~4 /* EnumMember */) !== 0; - case 136 /* IndexedAccess */: + case 138 /* IndexedAccess */: return true; - case 140 /* ParenExpression */: + case 142 /* ParenExpression */: return isReferenceOrErrorExpression(n.expression); default: return false; @@ -12518,14 +13409,17 @@ var ts; } return numberType; } - function isTypeAnyTypeObjectTypeOrTypeParameter(type) { - return type === anyType || ((type.flags & (ts.TypeFlags.ObjectType | 512 /* TypeParameter */)) !== 0); + function isStructuredType(type) { + if (type.flags & 16384 /* Union */) { + return !ts.forEach(type.types, function (t) { return !isStructuredType(t); }); + } + return (type.flags & ts.TypeFlags.Structured) !== 0; } function checkInstanceOfExpression(node, leftType, rightType) { - if (!isTypeAnyTypeObjectTypeOrTypeParameter(leftType)) { + if (leftType !== unknownType && !isStructuredType(leftType)) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } - if (rightType !== anyType && !isTypeSubtypeOf(rightType, globalFunctionType)) { + if (rightType !== unknownType && rightType !== anyType && !isTypeSubtypeOf(rightType, globalFunctionType)) { error(node.right, ts.Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type); } return booleanType; @@ -12534,7 +13428,7 @@ var ts; if (leftType !== anyType && leftType !== stringType && leftType !== numberType) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_types_any_string_or_number); } - if (!isTypeAnyTypeObjectTypeOrTypeParameter(rightType)) { + if (!isStructuredType(rightType)) { error(node.right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; @@ -12568,10 +13462,16 @@ var ts; leftType = rightType; if (rightType.flags & (32 /* Undefined */ | 64 /* Null */)) rightType = leftType; - var leftOk = checkArithmeticOperandType(node.left, leftType, ts.Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); - var rightOk = checkArithmeticOperandType(node.right, rightType, ts.Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); - if (leftOk && rightOk) { - checkAssignmentOperator(numberType); + var suggestedOperator; + if ((leftType.flags & 8 /* Boolean */) && (rightType.flags & 8 /* Boolean */) && (suggestedOperator = getSuggestedBooleanOperator(node.operator)) !== undefined) { + error(node, ts.Diagnostics.The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead, ts.tokenToString(node.operator), ts.tokenToString(suggestedOperator)); + } + else { + var leftOk = checkArithmeticOperandType(node.left, leftType, ts.Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); + var rightOk = checkArithmeticOperandType(node.right, rightType, ts.Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); + if (leftOk && rightOk) { + checkAssignmentOperator(numberType); + } } return numberType; case 28 /* PlusToken */: @@ -12606,7 +13506,7 @@ var ts; case 20 /* GreaterThanToken */: case 21 /* LessThanEqualsToken */: case 22 /* GreaterThanEqualsToken */: - if (!isTypeSubtypeOf(leftType, rightType) && !isTypeSubtypeOf(rightType, leftType)) { + if (!isTypeAssignableTo(leftType, rightType) && !isTypeAssignableTo(rightType, leftType)) { reportOperatorError(); } return booleanType; @@ -12617,13 +13517,28 @@ var ts; case 43 /* AmpersandAmpersandToken */: return rightType; case 44 /* BarBarToken */: - return getBestCommonType([leftType, rightType], isInferentialContext(contextualMapper) ? undefined : getContextualType(node)); + return getUnionType([leftType, rightType]); case 47 /* EqualsToken */: checkAssignmentOperator(rightType); return rightType; case 18 /* CommaToken */: return rightType; } + function getSuggestedBooleanOperator(operator) { + switch (operator) { + case 39 /* BarToken */: + case 57 /* BarEqualsToken */: + return 44 /* BarBarToken */; + case 40 /* CaretToken */: + case 58 /* CaretEqualsToken */: + return 26 /* ExclamationEqualsEqualsToken */; + case 38 /* AmpersandToken */: + case 56 /* AmpersandEqualsToken */: + return 43 /* AmpersandAmpersandToken */; + default: + return undefined; + } + } function checkAssignmentOperator(valueType) { if (fullTypeCheck && operator >= ts.SyntaxKind.FirstAssignment && operator <= ts.SyntaxKind.LastAssignment) { var ok = checkReferenceExpression(node.left, ts.Diagnostics.Invalid_left_hand_side_of_assignment_expression); @@ -12640,18 +13555,7 @@ var ts; checkExpression(node.condition); var type1 = checkExpression(node.whenTrue, contextualMapper); var type2 = checkExpression(node.whenFalse, contextualMapper); - var contextualType = isInferentialContext(contextualMapper) ? undefined : getContextualType(node); - var resultType = getBestCommonType([type1, type2], contextualType, true); - if (!resultType) { - if (contextualType) { - error(node, ts.Diagnostics.No_best_common_type_exists_between_0_1_and_2, typeToString(contextualType), typeToString(type1), typeToString(type2)); - } - else { - error(node, ts.Diagnostics.No_best_common_type_exists_between_0_and_1, typeToString(type1), typeToString(type2)); - } - resultType = emptyObjectType; - } - return resultType; + return getUnionType([type1, type2]); } function checkExpressionWithContextualType(node, contextualType, contextualMapper) { var saveContextualType = node.contextualType; @@ -12702,32 +13606,34 @@ var ts; return globalRegExpType; case 116 /* QualifiedName */: return checkPropertyAccess(node); - case 132 /* ArrayLiteral */: + case 134 /* ArrayLiteral */: return checkArrayLiteral(node, contextualMapper); - case 133 /* ObjectLiteral */: + case 135 /* ObjectLiteral */: return checkObjectLiteral(node, contextualMapper); - case 135 /* PropertyAccess */: + case 137 /* PropertyAccess */: return checkPropertyAccess(node); - case 136 /* IndexedAccess */: + case 138 /* IndexedAccess */: return checkIndexedAccess(node); - case 137 /* CallExpression */: - case 138 /* NewExpression */: + case 139 /* CallExpression */: + case 140 /* NewExpression */: return checkCallExpression(node); - case 139 /* TypeAssertion */: + case 141 /* TypeAssertion */: return checkTypeAssertion(node); - case 140 /* ParenExpression */: + case 142 /* ParenExpression */: return checkExpression(node.expression); - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: return checkFunctionExpression(node, contextualMapper); - case 143 /* PrefixOperator */: + case 145 /* PrefixOperator */: return checkPrefixExpression(node); - case 144 /* PostfixOperator */: + case 146 /* PostfixOperator */: return checkPostfixExpression(node); - case 145 /* BinaryExpression */: + case 147 /* BinaryExpression */: return checkBinaryExpression(node, contextualMapper); - case 146 /* ConditionalExpression */: + case 148 /* ConditionalExpression */: return checkConditionalExpression(node, contextualMapper); + case 149 /* OmittedExpression */: + return undefinedType; } return unknownType; } @@ -12790,7 +13696,7 @@ var ts; if (fullTypeCheck) { checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); - checkCollistionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkCollisionWithArgumentsInGeneratedCode(node); if (compilerOptions.noImplicitAny && !node.type) { switch (node.kind) { @@ -12806,7 +13712,7 @@ var ts; checkSpecializedSignatureDeclaration(node); } function checkTypeForDuplicateIndexSignatures(node) { - if (node.kind === 175 /* InterfaceDeclaration */) { + if (node.kind === 177 /* InterfaceDeclaration */) { var nodeSymbol = getSymbolOfNode(node); if (nodeSymbol.declarations.length > 0 && nodeSymbol.declarations[0] !== node) { return; @@ -12862,17 +13768,17 @@ var ts; return; } function isSuperCallExpression(n) { - return n.kind === 137 /* CallExpression */ && n.func.kind === 85 /* SuperKeyword */; + return n.kind === 139 /* CallExpression */ && n.func.kind === 85 /* SuperKeyword */; } function containsSuperCall(n) { if (isSuperCallExpression(n)) { return true; } switch (n.kind) { - case 141 /* FunctionExpression */: - case 172 /* FunctionDeclaration */: - case 142 /* ArrowFunction */: - case 133 /* ObjectLiteral */: + case 143 /* FunctionExpression */: + case 174 /* FunctionDeclaration */: + case 144 /* ArrowFunction */: + case 135 /* ObjectLiteral */: return false; default: return ts.forEachChild(n, containsSuperCall); @@ -12882,7 +13788,7 @@ var ts; if (n.kind === 87 /* ThisKeyword */) { error(n, ts.Diagnostics.this_cannot_be_referenced_in_current_location); } - else if (n.kind !== 141 /* FunctionExpression */ && n.kind !== 172 /* FunctionDeclaration */) { + else if (n.kind !== 143 /* FunctionExpression */ && n.kind !== 174 /* FunctionDeclaration */) { ts.forEachChild(n, markThisReferencesAsErrors); } } @@ -12894,7 +13800,7 @@ var ts; var superCallShouldBeFirst = ts.forEach(node.parent.members, isInstancePropertyWithInitializer) || ts.forEach(node.parameters, function (p) { return p.flags & (16 /* Public */ | 32 /* Private */ | 64 /* Protected */); }); if (superCallShouldBeFirst) { var statements = node.body.statements; - if (!statements.length || statements[0].kind !== 151 /* ExpressionStatement */ || !isSuperCallExpression(statements[0].expression)) { + if (!statements.length || statements[0].kind !== 153 /* ExpressionStatement */ || !isSuperCallExpression(statements[0].expression)) { error(node, ts.Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties); } else { @@ -12963,6 +13869,9 @@ var ts; function checkTupleType(node) { ts.forEach(node.elementTypes, checkSourceElement); } + function checkUnionType(node) { + ts.forEach(node.types, checkSourceElement); + } function isPrivateWithinAmbient(node) { return (node.flags & 32 /* Private */) && ts.isInAmbientContext(node); } @@ -12980,7 +13889,7 @@ var ts; } var symbol = getSymbolOfNode(signatureDeclarationNode); var signaturesToCheck; - if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 175 /* InterfaceDeclaration */) { + if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 177 /* InterfaceDeclaration */) { ts.Debug.assert(signatureDeclarationNode.kind === 124 /* CallSignature */ || signatureDeclarationNode.kind === 125 /* ConstructSignature */); var signatureKind = signatureDeclarationNode.kind === 124 /* CallSignature */ ? 0 /* Call */ : 1 /* Construct */; var containingSymbol = getSymbolOfNode(signatureDeclarationNode.parent); @@ -13000,7 +13909,7 @@ var ts; } function getEffectiveDeclarationFlags(n, flagsToCheck) { var flags = n.flags; - if (n.parent.kind !== 175 /* InterfaceDeclaration */ && ts.isInAmbientContext(n)) { + if (n.parent.kind !== 177 /* InterfaceDeclaration */ && ts.isInAmbientContext(n)) { if (!(flags & 2 /* Ambient */)) { flags |= 1 /* Export */; } @@ -13044,6 +13953,9 @@ var ts; var declarations = symbol.declarations; var isConstructor = (symbol.flags & 4096 /* Constructor */) !== 0; function reportImplementationExpectedError(node) { + if (node.name && node.name.kind === 115 /* Missing */) { + return; + } var seen = false; var subsequentNode = ts.forEachChild(node.parent, function (c) { if (seen) { @@ -13078,23 +13990,25 @@ var ts; } } var isExportSymbolInsideModule = symbol.parent && symbol.parent.flags & ts.SymbolFlags.Module; + var duplicateFunctionDeclaration = false; + var multipleConstructorImplementation = false; for (var i = 0; i < declarations.length; i++) { var node = declarations[i]; var inAmbientContext = ts.isInAmbientContext(node); - var inAmbientContextOrInterface = node.parent.kind === 175 /* InterfaceDeclaration */ || node.parent.kind === 129 /* TypeLiteral */ || inAmbientContext; + var inAmbientContextOrInterface = node.parent.kind === 177 /* InterfaceDeclaration */ || node.parent.kind === 129 /* TypeLiteral */ || inAmbientContext; if (inAmbientContextOrInterface) { previousDeclaration = undefined; } - if (node.kind === 172 /* FunctionDeclaration */ || node.kind === 120 /* Method */ || node.kind === 121 /* Constructor */) { + if (node.kind === 174 /* FunctionDeclaration */ || node.kind === 120 /* Method */ || node.kind === 121 /* Constructor */) { var currentNodeFlags = getEffectiveDeclarationFlags(node, flagsToCheck); someNodeFlags |= currentNodeFlags; allNodeFlags &= currentNodeFlags; if (node.body && bodyDeclaration) { if (isConstructor) { - error(node, ts.Diagnostics.Multiple_constructor_implementations_are_not_allowed); + multipleConstructorImplementation = true; } else { - error(node, ts.Diagnostics.Duplicate_function_implementation); + duplicateFunctionDeclaration = true; } } else if (!isExportSymbolInsideModule && previousDeclaration && previousDeclaration.parent === node.parent && previousDeclaration.end !== node.pos) { @@ -13114,6 +14028,16 @@ var ts; } } } + if (multipleConstructorImplementation) { + ts.forEach(declarations, function (declaration) { + error(declaration, ts.Diagnostics.Multiple_constructor_implementations_are_not_allowed); + }); + } + if (duplicateFunctionDeclaration) { + ts.forEach(declarations, function (declaration) { + error(declaration.name, ts.Diagnostics.Duplicate_function_implementation); + }); + } if (!isExportSymbolInsideModule && lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body) { reportImplementationExpectedError(lastSeenNonAmbientDeclaration); } @@ -13169,14 +14093,14 @@ var ts; } function getDeclarationSpaces(d) { switch (d.kind) { - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: return 1048576 /* ExportType */; - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return d.name.kind === 7 /* StringLiteral */ || ts.isInstantiated(d) ? 2097152 /* ExportNamespace */ | 524288 /* ExportValue */ : 2097152 /* ExportNamespace */; - case 174 /* ClassDeclaration */: - case 176 /* EnumDeclaration */: + case 176 /* ClassDeclaration */: + case 178 /* EnumDeclaration */: return 1048576 /* ExportType */ | 524288 /* ExportValue */; - case 179 /* ImportDeclaration */: + case 181 /* ImportDeclaration */: var result = 0; var target = resolveImport(getSymbolOfNode(d)); ts.forEach(target.declarations, function (d) { @@ -13251,10 +14175,10 @@ var ts; return; } switch (current.kind) { - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: case 120 /* Method */: - case 142 /* ArrowFunction */: + case 144 /* ArrowFunction */: case 121 /* Constructor */: if (ts.hasRestParameters(current)) { error(node, ts.Diagnostics.Expression_resolves_to_variable_declaration_i_that_compiler_uses_to_initialize_rest_parameter); @@ -13306,7 +14230,7 @@ var ts; if (!needCollisionCheckForIdentifier(node, name, "_super")) { return; } - var enclosingClass = ts.getAncestor(node, 174 /* ClassDeclaration */); + var enclosingClass = ts.getAncestor(node, 176 /* ClassDeclaration */); if (!enclosingClass || ts.isInAmbientContext(enclosingClass)) { return; } @@ -13320,15 +14244,15 @@ var ts; } } } - function checkCollistionWithRequireExportsInGeneratedCode(node, name) { + function checkCollisionWithRequireExportsInGeneratedCode(node, name) { if (!needCollisionCheckForIdentifier(node, name, "require") && !needCollisionCheckForIdentifier(node, name, "exports")) { return; } - if (node.kind === 177 /* ModuleDeclaration */ && !ts.isInstantiated(node)) { + if (node.kind === 179 /* ModuleDeclaration */ && !ts.isInstantiated(node)) { return; } - var parent = node.kind === 171 /* VariableDeclaration */ ? node.parent.parent : node.parent; - if (parent.kind === 182 /* SourceFile */ && ts.isExternalModule(parent)) { + var parent = node.kind === 173 /* VariableDeclaration */ ? node.parent.parent : node.parent; + if (parent.kind === 184 /* SourceFile */ && ts.isExternalModule(parent)) { error(name, ts.Diagnostics.Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_an_external_module, name.text, name.text); } } @@ -13353,7 +14277,7 @@ var ts; } checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); - checkCollistionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); if (!useTypeFromValueDeclaration) { if (typeOfValueDeclaration !== unknownType && type !== unknownType && !isTypeIdenticalTo(typeOfValueDeclaration, type)) { error(node.name, ts.Diagnostics.Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2, ts.identifierToString(node.name), typeToString(typeOfValueDeclaration), typeToString(type)); @@ -13408,7 +14332,7 @@ var ts; } } var exprType = checkExpression(node.expression); - if (!isTypeAnyTypeObjectTypeOrTypeParameter(exprType) && exprType !== unknownType) { + if (!isStructuredType(exprType) && exprType !== unknownType) { error(node.expression, ts.Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } checkSourceElement(node.statement); @@ -13484,7 +14408,7 @@ var ts; errorNode = indexDeclaration; } else if (type.flags & 2048 /* Interface */) { - var someBaseClassHasBothPropertyAndIndexer = ts.forEach(type.baseTypes, function (base) { return getPropertyOfType(base, prop.name) && getIndexTypeOfType(base, indexKind); }); + var someBaseClassHasBothPropertyAndIndexer = ts.forEach(type.baseTypes, function (base) { return getPropertyOfObjectType(base, prop.name) && getIndexTypeOfType(base, indexKind); }); errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : type.symbol.declarations[0]; } if (errorNode && !isTypeAssignableTo(propertyType, indexType)) { @@ -13497,7 +14421,7 @@ var ts; var stringIndexType = getIndexTypeOfType(type, 0 /* String */); var numberIndexType = getIndexTypeOfType(type, 1 /* Number */); if (stringIndexType || numberIndexType) { - ts.forEach(getPropertiesOfType(type), function (prop) { + ts.forEach(getPropertiesOfObjectType(type), function (prop) { var propType = getTypeOfSymbol(prop); checkIndexConstraintForProperty(prop, propType, declaredStringIndexer, stringIndexType, 0 /* String */); checkIndexConstraintForProperty(prop, propType, declaredNumberIndexer, numberIndexType, 1 /* Number */); @@ -13544,7 +14468,7 @@ var ts; checkTypeNameIsReserved(node.name, ts.Diagnostics.Class_name_cannot_be_0); checkTypeParameters(node.typeParameters); checkCollisionWithCapturedThisVariable(node, node.name); - checkCollistionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); var type = getDeclaredTypeOfSymbol(symbol); @@ -13593,13 +14517,13 @@ var ts; return s.flags & 8388608 /* Instantiated */ ? getSymbolLinks(s).target : s; } function checkKindsOfPropertyMemberOverrides(type, baseType) { - var baseProperties = getPropertiesOfType(baseType); + var baseProperties = getPropertiesOfObjectType(baseType); for (var i = 0, len = baseProperties.length; i < len; ++i) { var base = getTargetSymbol(baseProperties[i]); if (base.flags & 67108864 /* Prototype */) { continue; } - var derived = getTargetSymbol(getPropertyOfType(type, base.name)); + var derived = getTargetSymbol(getPropertyOfObjectType(type, base.name)); if (derived) { var baseDeclarationFlags = getDeclarationFlagsFromSymbol(base); var derivedDeclarationFlags = getDeclarationFlagsFromSymbol(derived); @@ -13669,7 +14593,7 @@ var ts; checkTypeNameIsReserved(node.name, ts.Diagnostics.Interface_name_cannot_be_0); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); - var firstInterfaceDecl = getDeclarationOfKind(symbol, 175 /* InterfaceDeclaration */); + var firstInterfaceDecl = getDeclarationOfKind(symbol, 177 /* InterfaceDeclaration */); if (symbol.declarations.length > 1) { if (node !== firstInterfaceDecl && !areTypeParametersIdentical(firstInterfaceDecl.typeParameters, node.typeParameters)) { error(node.name, ts.Diagnostics.All_declarations_of_an_interface_must_have_identical_type_parameters); @@ -13691,9 +14615,9 @@ var ts; checkTypeForDuplicateIndexSignatures(node); } } - function getConstantValue(node) { + function getConstantValueForExpression(node) { var isNegative = false; - if (node.kind === 143 /* PrefixOperator */) { + if (node.kind === 145 /* PrefixOperator */) { var unaryExpression = node; if (unaryExpression.operator === 29 /* MinusToken */ || unaryExpression.operator === 28 /* PlusToken */) { node = unaryExpression.operand; @@ -13706,38 +14630,49 @@ var ts; } return undefined; } + function computeEnumMemberValues(node) { + var nodeLinks = getNodeLinks(node); + if (!(nodeLinks.flags & 128 /* EnumValuesComputed */)) { + var enumSymbol = getSymbolOfNode(node); + var enumType = getDeclaredTypeOfSymbol(enumSymbol); + var autoValue = 0; + var ambient = ts.isInAmbientContext(node); + ts.forEach(node.members, function (member) { + if (isNumericName(member.name.text)) { + error(member.name, ts.Diagnostics.An_enum_member_cannot_have_a_numeric_name); + } + var initializer = member.initializer; + if (initializer) { + autoValue = getConstantValueForExpression(initializer); + if (autoValue === undefined && !ambient) { + checkTypeAssignableTo(checkExpression(initializer), enumType, initializer, undefined, undefined); + } + } + else if (ambient) { + autoValue = undefined; + } + if (autoValue !== undefined) { + getNodeLinks(member).enumMemberValue = autoValue++; + } + }); + nodeLinks.flags |= 128 /* EnumValuesComputed */; + } + } function checkEnumDeclaration(node) { if (!fullTypeCheck) { return; } checkTypeNameIsReserved(node.name, ts.Diagnostics.Enum_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); - checkCollistionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); + computeEnumMemberValues(node); var enumSymbol = getSymbolOfNode(node); - var enumType = getDeclaredTypeOfSymbol(enumSymbol); - var autoValue = 0; - var ambient = ts.isInAmbientContext(node); - ts.forEach(node.members, function (member) { - var initializer = member.initializer; - if (initializer) { - autoValue = getConstantValue(initializer); - if (autoValue === undefined && !ambient) { - checkTypeAssignableTo(checkExpression(initializer), enumType, initializer, undefined, undefined); - } - } - else if (ambient) { - autoValue = undefined; - } - if (autoValue !== undefined) { - getNodeLinks(member).enumMemberValue = autoValue++; - } - }); var firstDeclaration = getDeclarationOfKind(enumSymbol, node.kind); if (node === firstDeclaration) { var seenEnumMissingInitialInitializer = false; ts.forEach(enumSymbol.declarations, function (declaration) { - if (declaration.kind !== 176 /* EnumDeclaration */) { + if (declaration.kind !== 178 /* EnumDeclaration */) { return false; } var enumDeclaration = declaration; @@ -13760,7 +14695,7 @@ var ts; var declarations = symbol.declarations; for (var i = 0; i < declarations.length; i++) { var declaration = declarations[i]; - if ((declaration.kind === 174 /* ClassDeclaration */ || (declaration.kind === 172 /* FunctionDeclaration */ && declaration.body)) && !ts.isInAmbientContext(declaration)) { + if ((declaration.kind === 176 /* ClassDeclaration */ || (declaration.kind === 174 /* FunctionDeclaration */ && declaration.body)) && !ts.isInAmbientContext(declaration)) { return declaration; } } @@ -13769,7 +14704,7 @@ var ts; function checkModuleDeclaration(node) { if (fullTypeCheck) { checkCollisionWithCapturedThisVariable(node, node.name); - checkCollistionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); if (symbol.flags & 128 /* ValueModule */ && symbol.declarations.length > 1 && !ts.isInAmbientContext(node)) { @@ -13802,7 +14737,7 @@ var ts; } function checkImportDeclaration(node) { checkCollisionWithCapturedThisVariable(node, node.name); - checkCollistionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); var symbol = getSymbolOfNode(node); var target; if (node.entityName) { @@ -13823,10 +14758,10 @@ var ts; } } else { - if (node.parent.kind === 182 /* SourceFile */) { + if (node.parent.kind === 184 /* SourceFile */) { target = resolveImport(symbol); } - else if (node.parent.kind === 178 /* ModuleBlock */ && node.parent.parent.name.kind === 7 /* StringLiteral */) { + else if (node.parent.kind === 180 /* ModuleBlock */ && node.parent.parent.name.kind === 7 /* StringLiteral */) { if (isExternalModuleNameRelative(node.externalModuleName.text)) { error(node, ts.Diagnostics.Import_declaration_in_an_ambient_external_module_declaration_cannot_reference_external_module_through_relative_external_module_name); target = unknownSymbol; @@ -13848,7 +14783,7 @@ var ts; } function checkExportAssignment(node) { var container = node.parent; - if (container.kind !== 182 /* SourceFile */) { + if (container.kind !== 184 /* SourceFile */) { container = container.parent; } checkTypeOfExportAssignmentSymbol(getSymbolOfNode(container)); @@ -13884,62 +14819,66 @@ var ts; return checkArrayType(node); case 131 /* TupleType */: return checkTupleType(node); - case 172 /* FunctionDeclaration */: + case 132 /* UnionType */: + return checkUnionType(node); + case 133 /* ParenType */: + return checkSourceElement(node.type); + case 174 /* FunctionDeclaration */: return checkFunctionDeclaration(node); - case 148 /* Block */: + case 150 /* Block */: return checkBlock(node); - case 173 /* FunctionBlock */: - case 178 /* ModuleBlock */: + case 175 /* FunctionBlock */: + case 180 /* ModuleBlock */: return checkBody(node); - case 149 /* VariableStatement */: + case 151 /* VariableStatement */: return checkVariableStatement(node); - case 151 /* ExpressionStatement */: + case 153 /* ExpressionStatement */: return checkExpressionStatement(node); - case 152 /* IfStatement */: + case 154 /* IfStatement */: return checkIfStatement(node); - case 153 /* DoStatement */: + case 155 /* DoStatement */: return checkDoStatement(node); - case 154 /* WhileStatement */: + case 156 /* WhileStatement */: return checkWhileStatement(node); - case 155 /* ForStatement */: + case 157 /* ForStatement */: return checkForStatement(node); - case 156 /* ForInStatement */: + case 158 /* ForInStatement */: return checkForInStatement(node); - case 157 /* ContinueStatement */: - case 158 /* BreakStatement */: + case 159 /* ContinueStatement */: + case 160 /* BreakStatement */: return checkBreakOrContinueStatement(node); - case 159 /* ReturnStatement */: + case 161 /* ReturnStatement */: return checkReturnStatement(node); - case 160 /* WithStatement */: + case 162 /* WithStatement */: return checkWithStatement(node); - case 161 /* SwitchStatement */: + case 163 /* SwitchStatement */: return checkSwitchStatement(node); - case 164 /* LabeledStatement */: + case 166 /* LabeledStatement */: return checkLabeledStatement(node); - case 165 /* ThrowStatement */: + case 167 /* ThrowStatement */: return checkThrowStatement(node); - case 166 /* TryStatement */: + case 168 /* TryStatement */: return checkTryStatement(node); - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: return ts.Debug.fail("Checker encountered variable declaration"); - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: return checkClassDeclaration(node); - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: return checkInterfaceDeclaration(node); - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: return checkEnumDeclaration(node); - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return checkModuleDeclaration(node); - case 179 /* ImportDeclaration */: + case 181 /* ImportDeclaration */: return checkImportDeclaration(node); - case 180 /* ExportAssignment */: + case 182 /* ExportAssignment */: return checkExportAssignment(node); } } function checkFunctionExpressionBodies(node) { switch (node.kind) { - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: ts.forEach(node.parameters, checkFunctionExpressionBodies); checkFunctionExpressionBody(node); break; @@ -13947,54 +14886,54 @@ var ts; case 121 /* Constructor */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: ts.forEach(node.parameters, checkFunctionExpressionBodies); break; - case 160 /* WithStatement */: + case 162 /* WithStatement */: checkFunctionExpressionBodies(node.expression); break; case 118 /* Parameter */: case 119 /* Property */: - case 132 /* ArrayLiteral */: - case 133 /* ObjectLiteral */: - case 134 /* PropertyAssignment */: - case 135 /* PropertyAccess */: - case 136 /* IndexedAccess */: - case 137 /* CallExpression */: - case 138 /* NewExpression */: - case 139 /* TypeAssertion */: - case 140 /* ParenExpression */: - case 143 /* PrefixOperator */: - case 144 /* PostfixOperator */: - case 145 /* BinaryExpression */: - case 146 /* ConditionalExpression */: - case 148 /* Block */: - case 173 /* FunctionBlock */: - case 178 /* ModuleBlock */: - case 149 /* VariableStatement */: - case 151 /* ExpressionStatement */: - case 152 /* IfStatement */: - case 153 /* DoStatement */: - case 154 /* WhileStatement */: - case 155 /* ForStatement */: - case 156 /* ForInStatement */: - case 157 /* ContinueStatement */: - case 158 /* BreakStatement */: - case 159 /* ReturnStatement */: - case 161 /* SwitchStatement */: - case 162 /* CaseClause */: - case 163 /* DefaultClause */: - case 164 /* LabeledStatement */: - case 165 /* ThrowStatement */: - case 166 /* TryStatement */: - case 167 /* TryBlock */: - case 168 /* CatchBlock */: - case 169 /* FinallyBlock */: - case 171 /* VariableDeclaration */: - case 174 /* ClassDeclaration */: - case 176 /* EnumDeclaration */: - case 181 /* EnumMember */: - case 182 /* SourceFile */: + case 134 /* ArrayLiteral */: + case 135 /* ObjectLiteral */: + case 136 /* PropertyAssignment */: + case 137 /* PropertyAccess */: + case 138 /* IndexedAccess */: + case 139 /* CallExpression */: + case 140 /* NewExpression */: + case 141 /* TypeAssertion */: + case 142 /* ParenExpression */: + case 145 /* PrefixOperator */: + case 146 /* PostfixOperator */: + case 147 /* BinaryExpression */: + case 148 /* ConditionalExpression */: + case 150 /* Block */: + case 175 /* FunctionBlock */: + case 180 /* ModuleBlock */: + case 151 /* VariableStatement */: + case 153 /* ExpressionStatement */: + case 154 /* IfStatement */: + case 155 /* DoStatement */: + case 156 /* WhileStatement */: + case 157 /* ForStatement */: + case 158 /* ForInStatement */: + case 159 /* ContinueStatement */: + case 160 /* BreakStatement */: + case 161 /* ReturnStatement */: + case 163 /* SwitchStatement */: + case 164 /* CaseClause */: + case 165 /* DefaultClause */: + case 166 /* LabeledStatement */: + case 167 /* ThrowStatement */: + case 168 /* TryStatement */: + case 169 /* TryBlock */: + case 170 /* CatchBlock */: + case 171 /* FinallyBlock */: + case 173 /* VariableDeclaration */: + case 176 /* ClassDeclaration */: + case 178 /* EnumDeclaration */: + case 183 /* EnumMember */: + case 184 /* SourceFile */: ts.forEachChild(node, checkFunctionExpressionBodies); break; } @@ -14065,7 +15004,7 @@ var ts; function isInsideWithStatementBody(node) { if (node) { while (node.parent) { - if (node.parent.kind === 160 /* WithStatement */ && node.parent.statement === node) { + if (node.parent.kind === 162 /* WithStatement */ && node.parent.statement === node) { return true; } node = node.parent; @@ -14101,27 +15040,27 @@ var ts; copySymbols(location.locals, meaning); } switch (location.kind) { - case 182 /* SourceFile */: + case 184 /* SourceFile */: if (!ts.isExternalModule(location)) break; - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: copySymbols(getSymbolOfNode(location).exports, meaning & ts.SymbolFlags.ModuleMember); break; - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: copySymbols(getSymbolOfNode(location).exports, meaning & 4 /* EnumMember */); break; - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: if (!(memberFlags & 128 /* Static */)) { copySymbols(getSymbolOfNode(location).members, meaning & ts.SymbolFlags.Type); } break; - case 141 /* FunctionExpression */: + case 143 /* FunctionExpression */: if (location.name) { copySymbol(location.symbol, meaning); } break; - case 168 /* CatchBlock */: + case 170 /* CatchBlock */: if (location.variable.text) { copySymbol(location.symbol, meaning); } @@ -14139,9 +15078,9 @@ var ts; function isTypeDeclaration(node) { switch (node.kind) { case 117 /* TypeParameter */: - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 176 /* EnumDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: return true; } } @@ -14159,21 +15098,21 @@ var ts; case 89 /* TrueKeyword */: case 74 /* FalseKeyword */: case 8 /* RegularExpressionLiteral */: - case 132 /* ArrayLiteral */: - case 133 /* ObjectLiteral */: - case 135 /* PropertyAccess */: - case 136 /* IndexedAccess */: - case 137 /* CallExpression */: - case 138 /* NewExpression */: - case 139 /* TypeAssertion */: - case 140 /* ParenExpression */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: - case 143 /* PrefixOperator */: - case 144 /* PostfixOperator */: - case 145 /* BinaryExpression */: - case 146 /* ConditionalExpression */: - case 147 /* OmittedExpression */: + case 134 /* ArrayLiteral */: + case 135 /* ObjectLiteral */: + case 137 /* PropertyAccess */: + case 138 /* IndexedAccess */: + case 139 /* CallExpression */: + case 140 /* NewExpression */: + case 141 /* TypeAssertion */: + case 142 /* ParenExpression */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: + case 145 /* PrefixOperator */: + case 146 /* PostfixOperator */: + case 147 /* BinaryExpression */: + case 148 /* ConditionalExpression */: + case 149 /* OmittedExpression */: return true; case 116 /* QualifiedName */: while (node.parent.kind === 116 /* QualifiedName */) @@ -14187,28 +15126,28 @@ var ts; case 7 /* StringLiteral */: var parent = node.parent; switch (parent.kind) { - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: case 118 /* Parameter */: case 119 /* Property */: - case 181 /* EnumMember */: - case 134 /* PropertyAssignment */: + case 183 /* EnumMember */: + case 136 /* PropertyAssignment */: return parent.initializer === node; - case 151 /* ExpressionStatement */: - case 152 /* IfStatement */: - case 153 /* DoStatement */: - case 154 /* WhileStatement */: - case 159 /* ReturnStatement */: - case 160 /* WithStatement */: - case 161 /* SwitchStatement */: - case 162 /* CaseClause */: - case 165 /* ThrowStatement */: - case 161 /* SwitchStatement */: + case 153 /* ExpressionStatement */: + case 154 /* IfStatement */: + case 155 /* DoStatement */: + case 156 /* WhileStatement */: + case 161 /* ReturnStatement */: + case 162 /* WithStatement */: + case 163 /* SwitchStatement */: + case 164 /* CaseClause */: + case 167 /* ThrowStatement */: + case 163 /* SwitchStatement */: return parent.expression === node; - case 155 /* ForStatement */: + case 157 /* ForStatement */: return parent.initializer === node || parent.condition === node || parent.iterator === node; - case 156 /* ForInStatement */: + case 158 /* ForInStatement */: return parent.variable === node || parent.expression === node; - case 139 /* TypeAssertion */: + case 141 /* TypeAssertion */: return node === parent.operand; default: if (isExpression(parent)) { @@ -14219,7 +15158,7 @@ var ts; return false; } function isTypeNode(node) { - if (node.kind >= ts.SyntaxKind.FirstTypeNode && node.kind <= ts.SyntaxKind.LastTypeNode) { + if (ts.SyntaxKind.FirstTypeNode <= node.kind && node.kind <= ts.SyntaxKind.LastTypeNode) { return true; } switch (node.kind) { @@ -14229,7 +15168,7 @@ var ts; case 106 /* BooleanKeyword */: return true; case 93 /* VoidKeyword */: - return node.parent.kind !== 143 /* PrefixOperator */; + return node.parent.kind !== 145 /* PrefixOperator */; case 7 /* StringLiteral */: return node.parent.kind === 118 /* Parameter */; case 59 /* Identifier */: @@ -14237,11 +15176,12 @@ var ts; node = node.parent; } case 116 /* QualifiedName */: + ts.Debug.assert(node.kind === 59 /* Identifier */ || node.kind === 116 /* QualifiedName */, "'node' was expected to be a qualified name or identifier in 'isTypeNode'."); var parent = node.parent; if (parent.kind === 128 /* TypeQuery */) { return false; } - if (parent.kind >= ts.SyntaxKind.FirstTypeNode && parent.kind <= ts.SyntaxKind.LastTypeNode) { + if (ts.SyntaxKind.FirstTypeNode <= parent.kind && parent.kind <= ts.SyntaxKind.LastTypeNode) { return true; } switch (parent.kind) { @@ -14249,11 +15189,11 @@ var ts; return node === parent.constraint; case 119 /* Property */: case 118 /* Parameter */: - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: return node === parent.type; - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: case 121 /* Constructor */: case 120 /* Method */: case 122 /* GetAccessor */: @@ -14263,11 +15203,11 @@ var ts; case 125 /* ConstructSignature */: case 126 /* IndexSignature */: return node === parent.type; - case 139 /* TypeAssertion */: + case 141 /* TypeAssertion */: return node === parent.type; - case 137 /* CallExpression */: - case 138 /* NewExpression */: - return parent.typeArguments.indexOf(node) >= 0; + case 139 /* CallExpression */: + case 140 /* NewExpression */: + return parent.typeArguments && parent.typeArguments.indexOf(node) >= 0; } } return false; @@ -14276,22 +15216,22 @@ var ts; while (node.parent.kind === 116 /* QualifiedName */) { node = node.parent; } - if (node.parent.kind === 179 /* ImportDeclaration */) { + if (node.parent.kind === 181 /* ImportDeclaration */) { return node.parent.entityName === node; } - if (node.parent.kind === 180 /* ExportAssignment */) { + if (node.parent.kind === 182 /* ExportAssignment */) { return node.parent.exportName === node; } return false; } function isRightSideOfQualifiedNameOrPropertyAccess(node) { - return (node.parent.kind === 116 /* QualifiedName */ || node.parent.kind === 135 /* PropertyAccess */) && node.parent.right === node; + return (node.parent.kind === 116 /* QualifiedName */ || node.parent.kind === 137 /* PropertyAccess */) && node.parent.right === node; } function getSymbolOfEntityName(entityName) { if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(entityName)) { return getSymbolOfNode(entityName.parent); } - if (entityName.parent.kind === 180 /* ExportAssignment */) { + if (entityName.parent.kind === 182 /* ExportAssignment */) { return resolveEntityName(entityName.parent.parent, entityName, ts.SymbolFlags.Value | ts.SymbolFlags.Type | ts.SymbolFlags.Namespace | 4194304 /* Import */); } if (isInRightSideOfImportOrExportAssignment(entityName)) { @@ -14305,7 +15245,7 @@ var ts; var meaning = ts.SymbolFlags.Value | 4194304 /* Import */; return resolveEntityName(entityName, entityName, meaning); } - else if (entityName.kind === 116 /* QualifiedName */ || entityName.kind === 135 /* PropertyAccess */) { + else if (entityName.kind === 116 /* QualifiedName */ || entityName.kind === 137 /* PropertyAccess */) { var symbol = getNodeLinks(entityName).resolvedSymbol; if (!symbol) { checkPropertyAccess(entityName); @@ -14331,11 +15271,11 @@ var ts; return getSymbolOfNode(node.parent); } if (node.kind === 59 /* Identifier */ && isInRightSideOfImportOrExportAssignment(node)) { - return node.parent.kind === 180 /* ExportAssignment */ ? getSymbolOfEntityName(node) : getSymbolOfPartOfRightHandSideOfImport(node); + return node.parent.kind === 182 /* ExportAssignment */ ? getSymbolOfEntityName(node) : getSymbolOfPartOfRightHandSideOfImport(node); } switch (node.kind) { case 59 /* Identifier */: - case 135 /* PropertyAccess */: + case 137 /* PropertyAccess */: case 116 /* QualifiedName */: return getSymbolOfEntityName(node); case 87 /* ThisKeyword */: @@ -14349,20 +15289,20 @@ var ts; } return undefined; case 7 /* StringLiteral */: - if (node.parent.kind === 179 /* ImportDeclaration */ && node.parent.externalModuleName === node) { + if (node.parent.kind === 181 /* ImportDeclaration */ && node.parent.externalModuleName === node) { var importSymbol = getSymbolOfNode(node.parent); var moduleType = getTypeOfSymbol(importSymbol); return moduleType ? moduleType.symbol : undefined; } case 6 /* NumericLiteral */: - if (node.parent.kind == 136 /* IndexedAccess */ && node.parent.index === node) { + if (node.parent.kind == 138 /* IndexedAccess */ && node.parent.index === node) { var objectType = checkExpression(node.parent.object); if (objectType === unknownType) return undefined; var apparentType = getApparentType(objectType); if (apparentType === unknownType) return undefined; - return getPropertyOfApparentType(apparentType, node.text); + return getPropertyOfType(apparentType, node.text); } break; } @@ -14407,41 +15347,37 @@ var ts; } return checkExpression(expr); } - function getAugmentedPropertiesOfApparentType(type) { - var apparentType = getApparentType(type); - if (apparentType.flags & ts.TypeFlags.ObjectType) { - var propertiesByName = {}; - var results = []; - ts.forEach(getPropertiesOfType(apparentType), function (s) { - propertiesByName[s.name] = s; - results.push(s); - }); - var resolved = resolveObjectTypeMembers(type); - ts.forEachValue(resolved.members, function (s) { - if (symbolIsValue(s) && !propertiesByName[s.name]) { - propertiesByName[s.name] = s; - results.push(s); + function getAugmentedPropertiesOfType(type) { + var type = getApparentType(type); + var propsByName = createSymbolTable(getPropertiesOfType(type)); + if (getSignaturesOfType(type, 0 /* Call */).length || getSignaturesOfType(type, 1 /* Construct */).length) { + ts.forEach(getPropertiesOfType(globalFunctionType), function (p) { + if (!ts.hasProperty(propsByName, p.name)) { + propsByName[p.name] = p; } }); - if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { - ts.forEach(getPropertiesOfType(globalFunctionType), function (s) { - if (!propertiesByName[s.name]) { - propertiesByName[s.name] = s; - results.push(s); - } - }); - } - return results; - } - else { - return getPropertiesOfType(apparentType); } + return getNamedMembers(propsByName); } - function getRootSymbol(symbol) { - return ((symbol.flags & 33554432 /* Transient */) && getSymbolLinks(symbol).target) || symbol; + function getRootSymbols(symbol) { + if (symbol.flags & 134217728 /* UnionProperty */) { + var symbols = []; + var name = symbol.name; + ts.forEach(getSymbolLinks(symbol).unionType.types, function (t) { + symbols.push(getPropertyOfType(t, name)); + }); + return symbols; + } + else if (symbol.flags & 33554432 /* Transient */) { + var target = getSymbolLinks(symbol).target; + if (target) { + return [target]; + } + } + return [symbol]; } function isExternalModuleSymbol(symbol) { - return symbol.flags & 128 /* ValueModule */ && symbol.declarations.length === 1 && symbol.declarations[0].kind === 182 /* SourceFile */; + return symbol.flags & 128 /* ValueModule */ && symbol.declarations.length === 1 && symbol.declarations[0].kind === 184 /* SourceFile */; } function isNodeDescendentOf(node, ancestor) { while (node) { @@ -14467,14 +15403,14 @@ var ts; while (!isUniqueLocalName(ts.escapeIdentifier(prefix + name), container)) { prefix += "_"; } - links.localModuleName = prefix + ts.getSourceTextOfNode(container.name); + links.localModuleName = prefix + ts.getTextOfNode(container.name); } return links.localModuleName; } function getLocalNameForSymbol(symbol, location) { var node = location; while (node) { - if ((node.kind === 177 /* ModuleDeclaration */ || node.kind === 176 /* EnumDeclaration */) && getSymbolOfNode(node) === symbol) { + if ((node.kind === 179 /* ModuleDeclaration */ || node.kind === 178 /* EnumDeclaration */) && getSymbolOfNode(node) === symbol) { return getLocalNameOfContainer(node); } node = node.parent; @@ -14493,22 +15429,12 @@ var ts; } } } - function getPropertyAccessSubstitution(node) { - var symbol = getNodeLinks(node).resolvedSymbol; - if (symbol && (symbol.flags & 4 /* EnumMember */)) { - var declaration = symbol.valueDeclaration; - var constantValue; - if (declaration.kind === 181 /* EnumMember */ && (constantValue = getNodeLinks(declaration).enumMemberValue) !== undefined) { - return constantValue.toString() + " /* " + ts.identifierToString(declaration.name) + " */"; - } - } - } function getExportAssignmentName(node) { var symbol = getExportAssignmentSymbol(getSymbolOfNode(node)); return symbol && symbolIsValue(symbol) ? symbolToString(symbol) : undefined; } function isTopLevelValueImportedViaEntityName(node) { - if (node.parent.kind !== 182 /* SourceFile */ || !node.entityName) { + if (node.parent.kind !== 184 /* SourceFile */ || !node.entityName) { return false; } var symbol = getSymbolOfNode(node); @@ -14543,23 +15469,34 @@ var ts; return getNodeLinks(node).flags; } function getEnumMemberValue(node) { + computeEnumMemberValues(node.parent); return getNodeLinks(node).enumMemberValue; } + function getConstantValue(node) { + var symbol = getNodeLinks(node).resolvedSymbol; + if (symbol && (symbol.flags & 4 /* EnumMember */)) { + var declaration = symbol.valueDeclaration; + var constantValue; + if (declaration.kind === 183 /* EnumMember */ && (constantValue = getNodeLinks(declaration).enumMemberValue) !== undefined) { + return constantValue; + } + } + return undefined; + } function writeTypeAtLocation(location, enclosingDeclaration, flags, writer) { var symbol = getSymbolOfNode(location); var type = symbol && !(symbol.flags & 512 /* TypeLiteral */) ? getTypeOfSymbol(symbol) : getTypeFromTypeNode(location); - writeTypeToTextWriter(type, enclosingDeclaration, flags, writer); + getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); } function writeReturnTypeOfSignatureDeclaration(signatureDeclaration, enclosingDeclaration, flags, writer) { var signature = getSignatureFromDeclaration(signatureDeclaration); - writeTypeToTextWriter(getReturnTypeOfSignature(signature), enclosingDeclaration, flags, writer); + getSymbolDisplayBuilder().buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags); } function invokeEmitter(targetSourceFile) { var resolver = { getProgram: function () { return program; }, getLocalNameOfContainer: getLocalNameOfContainer, getExpressionNamePrefix: getExpressionNamePrefix, - getPropertyAccessSubstitution: getPropertyAccessSubstitution, getExportAssignmentName: getExportAssignmentName, isReferencedImportDeclaration: isReferencedImportDeclaration, getNodeCheckFlags: getNodeCheckFlags, @@ -14570,9 +15507,9 @@ var ts; isImplementationOfOverload: isImplementationOfOverload, writeTypeAtLocation: writeTypeAtLocation, writeReturnTypeOfSignatureDeclaration: writeReturnTypeOfSignatureDeclaration, - writeSymbol: writeSymbolToTextWriter, isSymbolAccessible: isSymbolAccessible, - isImportDeclarationEntityNameReferenceDeclarationVisibile: isImportDeclarationEntityNameReferenceDeclarationVisibile + isImportDeclarationEntityNameReferenceDeclarationVisibile: isImportDeclarationEntityNameReferenceDeclarationVisibile, + getConstantValue: getConstantValue }; checkProgram(); return ts.emitFiles(resolver, targetSourceFile); @@ -15712,7 +16649,6 @@ var __extends = this.__extends || function (d, b) { }; var TypeScript; (function (TypeScript) { - TypeScript.LocalizedDiagnosticMessages = null; var Location = (function () { function Location(fileName, lineMap, start, length) { this._fileName = fileName; @@ -15884,10 +16820,6 @@ var TypeScript; } IntegerUtilities.integerDivide = integerDivide; function integerMultiplyLow32Bits(n1, n2) { - var n1Low16 = n1 & 0x0000ffff; - var n1High16 = n1 >>> 16; - var n2Low16 = n2 & 0x0000ffff; - var n2High16 = n2 >>> 16; var resultLow32 = (((n1 & 0xffff0000) * n2) >>> 0) + (((n1 & 0x0000ffff) * n2) >>> 0) >>> 0; return resultLow32; } @@ -19472,7 +20404,7 @@ var TypeScript; })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { - TypeScript.nodeMetadata = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], ["moduleElements", "endOfFileToken"], ["left", "dotToken", "right"], ["openBraceToken", "typeMembers", "closeBraceToken"], ["typeParameterList", "parameterList", "equalsGreaterThanToken", "type"], ["type", "openBracketToken", "closeBracketToken"], ["newKeyword", "typeParameterList", "parameterList", "equalsGreaterThanToken", "type"], ["name", "typeArgumentList"], ["typeOfKeyword", "name"], ["openBracketToken", "types", "closeBracketToken"], ["modifiers", "interfaceKeyword", "identifier", "typeParameterList", "heritageClauses", "body"], ["modifiers", "functionKeyword", "identifier", "callSignature", "block", "semicolonToken"], ["modifiers", "moduleKeyword", "name", "stringLiteral", "openBraceToken", "moduleElements", "closeBraceToken"], ["modifiers", "classKeyword", "identifier", "typeParameterList", "heritageClauses", "openBraceToken", "classElements", "closeBraceToken"], ["modifiers", "enumKeyword", "identifier", "openBraceToken", "enumElements", "closeBraceToken"], ["modifiers", "importKeyword", "identifier", "equalsToken", "moduleReference", "semicolonToken"], ["exportKeyword", "equalsToken", "identifier", "semicolonToken"], ["modifiers", "propertyName", "callSignature", "block", "semicolonToken"], ["modifiers", "variableDeclarator", "semicolonToken"], ["modifiers", "constructorKeyword", "callSignature", "block", "semicolonToken"], ["modifiers", "indexSignature", "semicolonToken"], ["modifiers", "getKeyword", "propertyName", "callSignature", "block"], ["modifiers", "setKeyword", "propertyName", "callSignature", "block"], ["propertyName", "questionToken", "typeAnnotation"], ["typeParameterList", "parameterList", "typeAnnotation"], ["newKeyword", "callSignature"], ["openBracketToken", "parameters", "closeBracketToken", "typeAnnotation"], ["propertyName", "questionToken", "callSignature"], ["openBraceToken", "statements", "closeBraceToken"], ["ifKeyword", "openParenToken", "condition", "closeParenToken", "statement", "elseClause"], ["modifiers", "variableDeclaration", "semicolonToken"], ["expression", "semicolonToken"], ["returnKeyword", "expression", "semicolonToken"], ["switchKeyword", "openParenToken", "expression", "closeParenToken", "openBraceToken", "switchClauses", "closeBraceToken"], ["breakKeyword", "identifier", "semicolonToken"], ["continueKeyword", "identifier", "semicolonToken"], ["forKeyword", "openParenToken", "variableDeclaration", "initializer", "firstSemicolonToken", "condition", "secondSemicolonToken", "incrementor", "closeParenToken", "statement"], ["forKeyword", "openParenToken", "variableDeclaration", "left", "inKeyword", "expression", "closeParenToken", "statement"], ["semicolonToken"], ["throwKeyword", "expression", "semicolonToken"], ["whileKeyword", "openParenToken", "condition", "closeParenToken", "statement"], ["tryKeyword", "block", "catchClause", "finallyClause"], ["identifier", "colonToken", "statement"], ["doKeyword", "statement", "whileKeyword", "openParenToken", "condition", "closeParenToken", "semicolonToken"], ["debuggerKeyword", "semicolonToken"], ["withKeyword", "openParenToken", "condition", "closeParenToken", "statement"], ["operatorToken", "operand"], ["operatorToken", "operand"], ["operatorToken", "operand"], ["operatorToken", "operand"], ["operatorToken", "operand"], ["operatorToken", "operand"], ["deleteKeyword", "expression"], ["typeOfKeyword", "expression"], ["voidKeyword", "expression"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["condition", "questionToken", "whenTrue", "colonToken", "whenFalse"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["operand", "operatorToken"], ["operand", "operatorToken"], ["expression", "dotToken", "name"], ["expression", "argumentList"], ["openBracketToken", "expressions", "closeBracketToken"], ["openBraceToken", "propertyAssignments", "closeBraceToken"], ["newKeyword", "expression", "argumentList"], ["openParenToken", "expression", "closeParenToken"], ["callSignature", "equalsGreaterThanToken", "block", "expression"], ["parameter", "equalsGreaterThanToken", "block", "expression"], ["lessThanToken", "type", "greaterThanToken", "expression"], ["expression", "openBracketToken", "argumentExpression", "closeBracketToken"], ["functionKeyword", "identifier", "callSignature", "block"], [], ["varKeyword", "variableDeclarators"], ["propertyName", "typeAnnotation", "equalsValueClause"], ["typeArgumentList", "openParenToken", "arguments", "closeParenToken"], ["openParenToken", "parameters", "closeParenToken"], ["lessThanToken", "typeArguments", "greaterThanToken"], ["lessThanToken", "typeParameters", "greaterThanToken"], ["extendsOrImplementsKeyword", "typeNames"], ["extendsOrImplementsKeyword", "typeNames"], ["equalsToken", "value"], ["caseKeyword", "expression", "colonToken", "statements"], ["defaultKeyword", "colonToken", "statements"], ["elseKeyword", "statement"], ["catchKeyword", "openParenToken", "identifier", "typeAnnotation", "closeParenToken", "block"], ["finallyKeyword", "block"], ["identifier", "constraint"], ["extendsKeyword", "typeOrExpression"], ["propertyName", "colonToken", "expression"], ["propertyName", "callSignature", "block"], ["dotDotDotToken", "modifiers", "identifier", "questionToken", "typeAnnotation", "equalsValueClause"], ["propertyName", "equalsValueClause"], ["colonToken", "type"], ["requireKeyword", "openParenToken", "stringLiteral", "closeParenToken"], ["moduleName"], ]; + TypeScript.nodeMetadata = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], ["moduleElements", "endOfFileToken"], ["left", "dotToken", "right"], ["openBraceToken", "typeMembers", "closeBraceToken"], ["typeParameterList", "parameterList", "equalsGreaterThanToken", "type"], ["type", "openBracketToken", "closeBracketToken"], ["newKeyword", "typeParameterList", "parameterList", "equalsGreaterThanToken", "type"], ["name", "typeArgumentList"], ["typeOfKeyword", "name"], ["openBracketToken", "types", "closeBracketToken"], ["modifiers", "interfaceKeyword", "identifier", "typeParameterList", "heritageClauses", "body"], ["modifiers", "functionKeyword", "identifier", "callSignature", "block", "semicolonToken"], ["modifiers", "moduleKeyword", "name", "stringLiteral", "openBraceToken", "moduleElements", "closeBraceToken"], ["modifiers", "classKeyword", "identifier", "typeParameterList", "heritageClauses", "openBraceToken", "classElements", "closeBraceToken"], ["modifiers", "enumKeyword", "identifier", "openBraceToken", "enumElements", "closeBraceToken"], ["modifiers", "importKeyword", "identifier", "equalsToken", "moduleReference", "semicolonToken"], ["exportKeyword", "equalsToken", "identifier", "semicolonToken"], ["modifiers", "propertyName", "callSignature", "block", "semicolonToken"], ["modifiers", "variableDeclarator", "semicolonToken"], ["modifiers", "constructorKeyword", "callSignature", "block", "semicolonToken"], ["modifiers", "indexSignature", "semicolonToken"], ["modifiers", "getKeyword", "propertyName", "callSignature", "block"], ["modifiers", "setKeyword", "propertyName", "callSignature", "block"], ["propertyName", "questionToken", "typeAnnotation"], ["typeParameterList", "parameterList", "typeAnnotation"], ["newKeyword", "callSignature"], ["openBracketToken", "parameters", "closeBracketToken", "typeAnnotation"], ["propertyName", "questionToken", "callSignature"], ["openBraceToken", "statements", "closeBraceToken"], ["ifKeyword", "openParenToken", "condition", "closeParenToken", "statement", "elseClause"], ["modifiers", "variableDeclaration", "semicolonToken"], ["expression", "semicolonToken"], ["returnKeyword", "expression", "semicolonToken"], ["switchKeyword", "openParenToken", "expression", "closeParenToken", "openBraceToken", "switchClauses", "closeBraceToken"], ["breakKeyword", "identifier", "semicolonToken"], ["continueKeyword", "identifier", "semicolonToken"], ["forKeyword", "openParenToken", "variableDeclaration", "initializer", "firstSemicolonToken", "condition", "secondSemicolonToken", "incrementor", "closeParenToken", "statement"], ["forKeyword", "openParenToken", "variableDeclaration", "left", "inKeyword", "expression", "closeParenToken", "statement"], ["semicolonToken"], ["throwKeyword", "expression", "semicolonToken"], ["whileKeyword", "openParenToken", "condition", "closeParenToken", "statement"], ["tryKeyword", "block", "catchClause", "finallyClause"], ["identifier", "colonToken", "statement"], ["doKeyword", "statement", "whileKeyword", "openParenToken", "condition", "closeParenToken", "semicolonToken"], ["debuggerKeyword", "semicolonToken"], ["withKeyword", "openParenToken", "condition", "closeParenToken", "statement"], ["operatorToken", "operand"], ["operatorToken", "operand"], ["operatorToken", "operand"], ["operatorToken", "operand"], ["operatorToken", "operand"], ["operatorToken", "operand"], ["deleteKeyword", "expression"], ["typeOfKeyword", "expression"], ["voidKeyword", "expression"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["condition", "questionToken", "whenTrue", "colonToken", "whenFalse"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["left", "operatorToken", "right"], ["operand", "operatorToken"], ["operand", "operatorToken"], ["expression", "dotToken", "name"], ["expression", "argumentList"], ["openBracketToken", "expressions", "closeBracketToken"], ["openBraceToken", "propertyAssignments", "closeBraceToken"], ["newKeyword", "expression", "argumentList"], ["openParenToken", "expression", "closeParenToken"], ["callSignature", "equalsGreaterThanToken", "block", "expression"], ["parameter", "equalsGreaterThanToken", "block", "expression"], ["lessThanToken", "type", "greaterThanToken", "expression"], ["expression", "openBracketToken", "argumentExpression", "closeBracketToken"], ["functionKeyword", "identifier", "callSignature", "block"], [], ["varKeyword", "variableDeclarators"], ["propertyName", "typeAnnotation", "equalsValueClause"], ["typeArgumentList", "openParenToken", "arguments", "closeParenToken"], ["openParenToken", "parameters", "closeParenToken"], ["lessThanToken", "typeArguments", "greaterThanToken"], ["lessThanToken", "typeParameters", "greaterThanToken"], ["extendsOrImplementsKeyword", "typeNames"], ["extendsOrImplementsKeyword", "typeNames"], ["equalsToken", "value"], ["caseKeyword", "expression", "colonToken", "statements"], ["defaultKeyword", "colonToken", "statements"], ["elseKeyword", "statement"], ["catchKeyword", "openParenToken", "identifier", "typeAnnotation", "closeParenToken", "block"], ["finallyKeyword", "block"], ["identifier", "constraint"], ["extendsKeyword", "typeOrExpression"], ["propertyName", "colonToken", "expression"], ["propertyName", "callSignature", "block"], ["dotDotDotToken", "modifiers", "identifier", "questionToken", "typeAnnotation", "equalsValueClause"], ["propertyName", "equalsValueClause"], ["colonToken", "type"], ["requireKeyword", "openParenToken", "stringLiteral", "closeParenToken"], ["moduleName"],]; })(TypeScript || (TypeScript = {})); var TypeScript; (function (TypeScript) { @@ -24802,7 +25734,6 @@ var TypeScript; return this._languageVersion; }; SyntaxTree.prototype.cacheSyntaxTreeInfo = function () { - var sourceUnit = this.sourceUnit(); var firstToken = firstSyntaxTreeToken(this); var leadingTrivia = firstToken.leadingTrivia(this.text); this._isExternalModule = externalModuleIndicatorSpanWorker(this, firstToken) !== null; @@ -25976,10 +26907,10 @@ var TypeScript; throw TypeScript.Errors.argumentOutOfRange("languageVersion"); } }; - Unicode.unicodeES3IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1610, 1649, 1747, 1749, 1749, 1765, 1766, 1786, 1788, 1808, 1808, 1810, 1836, 1920, 1957, 2309, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2784, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3294, 3294, 3296, 3297, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3424, 3425, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3805, 3840, 3840, 3904, 3911, 3913, 3946, 3976, 3979, 4096, 4129, 4131, 4135, 4137, 4138, 4176, 4181, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6067, 6176, 6263, 6272, 6312, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8319, 8319, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12346, 12353, 12436, 12445, 12446, 12449, 12538, 12540, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65138, 65140, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, ]; - Unicode.unicodeES3IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 768, 846, 864, 866, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1155, 1158, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1441, 1443, 1465, 1467, 1469, 1471, 1471, 1473, 1474, 1476, 1476, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1621, 1632, 1641, 1648, 1747, 1749, 1756, 1759, 1768, 1770, 1773, 1776, 1788, 1808, 1836, 1840, 1866, 1920, 1968, 2305, 2307, 2309, 2361, 2364, 2381, 2384, 2388, 2392, 2403, 2406, 2415, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2492, 2494, 2500, 2503, 2504, 2507, 2509, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2562, 2562, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2649, 2652, 2654, 2654, 2662, 2676, 2689, 2691, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2784, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2876, 2883, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2913, 2918, 2927, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3031, 3031, 3047, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3134, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3168, 3169, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3262, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3297, 3302, 3311, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3390, 3395, 3398, 3400, 3402, 3405, 3415, 3415, 3424, 3425, 3430, 3439, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3805, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3946, 3953, 3972, 3974, 3979, 3984, 3991, 3993, 4028, 4038, 4038, 4096, 4129, 4131, 4135, 4137, 4138, 4140, 4146, 4150, 4153, 4160, 4169, 4176, 4185, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 4969, 4977, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6099, 6112, 6121, 6160, 6169, 6176, 6263, 6272, 6313, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8255, 8256, 8319, 8319, 8400, 8412, 8417, 8417, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12346, 12353, 12436, 12441, 12442, 12445, 12446, 12449, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65056, 65059, 65075, 65076, 65101, 65103, 65136, 65138, 65140, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65381, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, ]; - Unicode.unicodeES5IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 880, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1568, 1610, 1646, 1647, 1649, 1747, 1749, 1749, 1765, 1766, 1774, 1775, 1786, 1788, 1791, 1791, 1808, 1808, 1810, 1839, 1869, 1957, 1969, 1969, 1994, 2026, 2036, 2037, 2042, 2042, 2048, 2069, 2074, 2074, 2084, 2084, 2088, 2088, 2112, 2136, 2208, 2208, 2210, 2220, 2308, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2417, 2423, 2425, 2431, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2493, 2493, 2510, 2510, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2785, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2929, 2929, 2947, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3024, 3024, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3133, 3160, 3161, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3261, 3261, 3294, 3294, 3296, 3297, 3313, 3314, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3389, 3406, 3406, 3424, 3425, 3450, 3455, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3807, 3840, 3840, 3904, 3911, 3913, 3948, 3976, 3980, 4096, 4138, 4159, 4159, 4176, 4181, 4186, 4189, 4193, 4193, 4197, 4198, 4206, 4208, 4213, 4225, 4238, 4238, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5905, 5920, 5937, 5952, 5969, 5984, 5996, 5998, 6000, 6016, 6067, 6103, 6103, 6108, 6108, 6176, 6263, 6272, 6312, 6314, 6314, 6320, 6389, 6400, 6428, 6480, 6509, 6512, 6516, 6528, 6571, 6593, 6599, 6656, 6678, 6688, 6740, 6823, 6823, 6917, 6963, 6981, 6987, 7043, 7072, 7086, 7087, 7098, 7141, 7168, 7203, 7245, 7247, 7258, 7293, 7401, 7404, 7406, 7409, 7413, 7414, 7424, 7615, 7680, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8305, 8305, 8319, 8319, 8336, 8348, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11502, 11506, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11648, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11823, 11823, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12348, 12353, 12438, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42527, 42538, 42539, 42560, 42606, 42623, 42647, 42656, 42735, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43009, 43011, 43013, 43015, 43018, 43020, 43042, 43072, 43123, 43138, 43187, 43250, 43255, 43259, 43259, 43274, 43301, 43312, 43334, 43360, 43388, 43396, 43442, 43471, 43471, 43520, 43560, 43584, 43586, 43588, 43595, 43616, 43638, 43642, 43642, 43648, 43695, 43697, 43697, 43701, 43702, 43705, 43709, 43712, 43712, 43714, 43714, 43739, 43741, 43744, 43754, 43762, 43764, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44002, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, ]; - Unicode.unicodeES5IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 768, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1155, 1159, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1469, 1471, 1471, 1473, 1474, 1476, 1477, 1479, 1479, 1488, 1514, 1520, 1522, 1552, 1562, 1568, 1641, 1646, 1747, 1749, 1756, 1759, 1768, 1770, 1788, 1791, 1791, 1808, 1866, 1869, 1969, 1984, 2037, 2042, 2042, 2048, 2093, 2112, 2139, 2208, 2208, 2210, 2220, 2276, 2302, 2304, 2403, 2406, 2415, 2417, 2423, 2425, 2431, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2500, 2503, 2504, 2507, 2510, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2561, 2563, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2641, 2641, 2649, 2652, 2654, 2654, 2662, 2677, 2689, 2691, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2787, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2876, 2884, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2915, 2918, 2927, 2929, 2929, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3024, 3024, 3031, 3031, 3046, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3160, 3161, 3168, 3171, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3260, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3299, 3302, 3311, 3313, 3314, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3396, 3398, 3400, 3402, 3406, 3415, 3415, 3424, 3427, 3430, 3439, 3450, 3455, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3807, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3948, 3953, 3972, 3974, 3991, 3993, 4028, 4038, 4038, 4096, 4169, 4176, 4253, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4957, 4959, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5908, 5920, 5940, 5952, 5971, 5984, 5996, 5998, 6000, 6002, 6003, 6016, 6099, 6103, 6103, 6108, 6109, 6112, 6121, 6155, 6157, 6160, 6169, 6176, 6263, 6272, 6314, 6320, 6389, 6400, 6428, 6432, 6443, 6448, 6459, 6470, 6509, 6512, 6516, 6528, 6571, 6576, 6601, 6608, 6617, 6656, 6683, 6688, 6750, 6752, 6780, 6783, 6793, 6800, 6809, 6823, 6823, 6912, 6987, 6992, 7001, 7019, 7027, 7040, 7155, 7168, 7223, 7232, 7241, 7245, 7293, 7376, 7378, 7380, 7414, 7424, 7654, 7676, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8204, 8205, 8255, 8256, 8276, 8276, 8305, 8305, 8319, 8319, 8336, 8348, 8400, 8412, 8417, 8417, 8421, 8432, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11647, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11744, 11775, 11823, 11823, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12348, 12353, 12438, 12441, 12442, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42539, 42560, 42607, 42612, 42621, 42623, 42647, 42655, 42737, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43047, 43072, 43123, 43136, 43204, 43216, 43225, 43232, 43255, 43259, 43259, 43264, 43309, 43312, 43347, 43360, 43388, 43392, 43456, 43471, 43481, 43520, 43574, 43584, 43597, 43600, 43609, 43616, 43638, 43642, 43643, 43648, 43714, 43739, 43741, 43744, 43759, 43762, 43766, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44010, 44012, 44013, 44016, 44025, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65024, 65039, 65056, 65062, 65075, 65076, 65101, 65103, 65136, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, ]; + Unicode.unicodeES3IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1610, 1649, 1747, 1749, 1749, 1765, 1766, 1786, 1788, 1808, 1808, 1810, 1836, 1920, 1957, 2309, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2784, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3294, 3294, 3296, 3297, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3424, 3425, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3805, 3840, 3840, 3904, 3911, 3913, 3946, 3976, 3979, 4096, 4129, 4131, 4135, 4137, 4138, 4176, 4181, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6067, 6176, 6263, 6272, 6312, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8319, 8319, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12346, 12353, 12436, 12445, 12446, 12449, 12538, 12540, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65138, 65140, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,]; + Unicode.unicodeES3IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 768, 846, 864, 866, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1155, 1158, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1441, 1443, 1465, 1467, 1469, 1471, 1471, 1473, 1474, 1476, 1476, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1621, 1632, 1641, 1648, 1747, 1749, 1756, 1759, 1768, 1770, 1773, 1776, 1788, 1808, 1836, 1840, 1866, 1920, 1968, 2305, 2307, 2309, 2361, 2364, 2381, 2384, 2388, 2392, 2403, 2406, 2415, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2492, 2494, 2500, 2503, 2504, 2507, 2509, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2562, 2562, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2649, 2652, 2654, 2654, 2662, 2676, 2689, 2691, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2784, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2876, 2883, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2913, 2918, 2927, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3031, 3031, 3047, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3134, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3168, 3169, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3262, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3297, 3302, 3311, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3390, 3395, 3398, 3400, 3402, 3405, 3415, 3415, 3424, 3425, 3430, 3439, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3805, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3946, 3953, 3972, 3974, 3979, 3984, 3991, 3993, 4028, 4038, 4038, 4096, 4129, 4131, 4135, 4137, 4138, 4140, 4146, 4150, 4153, 4160, 4169, 4176, 4185, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 4969, 4977, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6099, 6112, 6121, 6160, 6169, 6176, 6263, 6272, 6313, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8255, 8256, 8319, 8319, 8400, 8412, 8417, 8417, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12346, 12353, 12436, 12441, 12442, 12445, 12446, 12449, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65056, 65059, 65075, 65076, 65101, 65103, 65136, 65138, 65140, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65381, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,]; + Unicode.unicodeES5IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 880, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1568, 1610, 1646, 1647, 1649, 1747, 1749, 1749, 1765, 1766, 1774, 1775, 1786, 1788, 1791, 1791, 1808, 1808, 1810, 1839, 1869, 1957, 1969, 1969, 1994, 2026, 2036, 2037, 2042, 2042, 2048, 2069, 2074, 2074, 2084, 2084, 2088, 2088, 2112, 2136, 2208, 2208, 2210, 2220, 2308, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2417, 2423, 2425, 2431, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2493, 2493, 2510, 2510, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2785, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2929, 2929, 2947, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3024, 3024, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3133, 3160, 3161, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3261, 3261, 3294, 3294, 3296, 3297, 3313, 3314, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3389, 3406, 3406, 3424, 3425, 3450, 3455, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3807, 3840, 3840, 3904, 3911, 3913, 3948, 3976, 3980, 4096, 4138, 4159, 4159, 4176, 4181, 4186, 4189, 4193, 4193, 4197, 4198, 4206, 4208, 4213, 4225, 4238, 4238, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5905, 5920, 5937, 5952, 5969, 5984, 5996, 5998, 6000, 6016, 6067, 6103, 6103, 6108, 6108, 6176, 6263, 6272, 6312, 6314, 6314, 6320, 6389, 6400, 6428, 6480, 6509, 6512, 6516, 6528, 6571, 6593, 6599, 6656, 6678, 6688, 6740, 6823, 6823, 6917, 6963, 6981, 6987, 7043, 7072, 7086, 7087, 7098, 7141, 7168, 7203, 7245, 7247, 7258, 7293, 7401, 7404, 7406, 7409, 7413, 7414, 7424, 7615, 7680, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8305, 8305, 8319, 8319, 8336, 8348, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11502, 11506, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11648, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11823, 11823, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12348, 12353, 12438, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42527, 42538, 42539, 42560, 42606, 42623, 42647, 42656, 42735, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43009, 43011, 43013, 43015, 43018, 43020, 43042, 43072, 43123, 43138, 43187, 43250, 43255, 43259, 43259, 43274, 43301, 43312, 43334, 43360, 43388, 43396, 43442, 43471, 43471, 43520, 43560, 43584, 43586, 43588, 43595, 43616, 43638, 43642, 43642, 43648, 43695, 43697, 43697, 43701, 43702, 43705, 43709, 43712, 43712, 43714, 43714, 43739, 43741, 43744, 43754, 43762, 43764, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44002, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,]; + Unicode.unicodeES5IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 768, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1155, 1159, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1469, 1471, 1471, 1473, 1474, 1476, 1477, 1479, 1479, 1488, 1514, 1520, 1522, 1552, 1562, 1568, 1641, 1646, 1747, 1749, 1756, 1759, 1768, 1770, 1788, 1791, 1791, 1808, 1866, 1869, 1969, 1984, 2037, 2042, 2042, 2048, 2093, 2112, 2139, 2208, 2208, 2210, 2220, 2276, 2302, 2304, 2403, 2406, 2415, 2417, 2423, 2425, 2431, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2500, 2503, 2504, 2507, 2510, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2561, 2563, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2641, 2641, 2649, 2652, 2654, 2654, 2662, 2677, 2689, 2691, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2787, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2876, 2884, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2915, 2918, 2927, 2929, 2929, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3024, 3024, 3031, 3031, 3046, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3160, 3161, 3168, 3171, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3260, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3299, 3302, 3311, 3313, 3314, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3396, 3398, 3400, 3402, 3406, 3415, 3415, 3424, 3427, 3430, 3439, 3450, 3455, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3807, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3948, 3953, 3972, 3974, 3991, 3993, 4028, 4038, 4038, 4096, 4169, 4176, 4253, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4957, 4959, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5908, 5920, 5940, 5952, 5971, 5984, 5996, 5998, 6000, 6002, 6003, 6016, 6099, 6103, 6103, 6108, 6109, 6112, 6121, 6155, 6157, 6160, 6169, 6176, 6263, 6272, 6314, 6320, 6389, 6400, 6428, 6432, 6443, 6448, 6459, 6470, 6509, 6512, 6516, 6528, 6571, 6576, 6601, 6608, 6617, 6656, 6683, 6688, 6750, 6752, 6780, 6783, 6793, 6800, 6809, 6823, 6823, 6912, 6987, 6992, 7001, 7019, 7027, 7040, 7155, 7168, 7223, 7232, 7241, 7245, 7293, 7376, 7378, 7380, 7414, 7424, 7654, 7676, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8204, 8205, 8255, 8256, 8276, 8276, 8305, 8305, 8319, 8319, 8336, 8348, 8400, 8412, 8417, 8417, 8421, 8432, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11647, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11744, 11775, 11823, 11823, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12348, 12353, 12438, 12441, 12442, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42539, 42560, 42607, 42612, 42621, 42623, 42647, 42655, 42737, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43047, 43072, 43123, 43136, 43204, 43216, 43225, 43232, 43255, 43259, 43259, 43264, 43309, 43312, 43347, 43360, 43388, 43392, 43456, 43471, 43481, 43520, 43574, 43584, 43597, 43600, 43609, 43616, 43638, 43642, 43643, 43648, 43714, 43739, 43741, 43744, 43759, 43762, 43766, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44010, 44012, 44013, 44016, 44025, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65024, 65039, 65056, 65062, 65075, 65076, 65101, 65103, 65136, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,]; return Unicode; })(); TypeScript.Unicode = Unicode; @@ -26394,17 +27325,28 @@ var ts; (function (OutliningElementsCollector) { function collectElements(sourceFile) { var elements = []; - function addOutlineRange(hintSpanNode, startElement, endElement) { + var collapseText = "..."; + function addOutliningSpan(hintSpanNode, startElement, endElement, autoCollapse) { if (hintSpanNode && startElement && endElement) { var span = { textSpan: TypeScript.TextSpan.fromBounds(startElement.pos, endElement.end), hintSpan: TypeScript.TextSpan.fromBounds(hintSpanNode.getStart(), hintSpanNode.end), - bannerText: "...", - autoCollapse: false + bannerText: collapseText, + autoCollapse: autoCollapse }; elements.push(span); } } + function autoCollapse(node) { + switch (node.kind) { + case 180 /* ModuleBlock */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: + return false; + } + return true; + } var depth = 0; var maxDepth = 20; function walk(n) { @@ -26412,24 +27354,45 @@ var ts; return; } switch (n.kind) { - case 148 /* Block */: - case 173 /* FunctionBlock */: - case 178 /* ModuleBlock */: - case 167 /* TryBlock */: - case 167 /* TryBlock */: - case 168 /* CatchBlock */: - case 169 /* FinallyBlock */: - var openBrace = ts.forEach(n.getChildren(), function (c) { return c.kind === 9 /* OpenBraceToken */ && c; }); - var closeBrace = ts.forEach(n.getChildren(), function (c) { return c.kind === 10 /* CloseBraceToken */ && c; }); - addOutlineRange(n.parent, openBrace, closeBrace); + case 150 /* Block */: + var parent = n.parent; + var openBrace = ts.findChildOfKind(n, 9 /* OpenBraceToken */, sourceFile); + var closeBrace = ts.findChildOfKind(n, 10 /* CloseBraceToken */, sourceFile); + if (parent.kind === 155 /* DoStatement */ || parent.kind === 158 /* ForInStatement */ || parent.kind === 157 /* ForStatement */ || parent.kind === 154 /* IfStatement */ || parent.kind === 156 /* WhileStatement */ || parent.kind === 162 /* WithStatement */) { + addOutliningSpan(parent, openBrace, closeBrace, autoCollapse(n)); + } + else { + var span = TypeScript.TextSpan.fromBounds(n.getStart(), n.end); + elements.push({ + textSpan: span, + hintSpan: span, + bannerText: collapseText, + autoCollapse: autoCollapse(n) + }); + } break; - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 176 /* EnumDeclaration */: - case 133 /* ObjectLiteral */: - var openBrace = ts.forEach(n.getChildren(), function (c) { return c.kind === 9 /* OpenBraceToken */ && c; }); - var closeBrace = ts.forEach(n.getChildren(), function (c) { return c.kind === 10 /* CloseBraceToken */ && c; }); - addOutlineRange(n, openBrace, closeBrace); + case 175 /* FunctionBlock */: + case 180 /* ModuleBlock */: + case 169 /* TryBlock */: + case 170 /* CatchBlock */: + case 171 /* FinallyBlock */: + var openBrace = ts.findChildOfKind(n, 9 /* OpenBraceToken */, sourceFile); + var closeBrace = ts.findChildOfKind(n, 10 /* CloseBraceToken */, sourceFile); + addOutliningSpan(n.parent, openBrace, closeBrace, autoCollapse(n)); + break; + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: + case 135 /* ObjectLiteral */: + case 163 /* SwitchStatement */: + var openBrace = ts.findChildOfKind(n, 9 /* OpenBraceToken */, sourceFile); + var closeBrace = ts.findChildOfKind(n, 10 /* CloseBraceToken */, sourceFile); + addOutliningSpan(n, openBrace, closeBrace, autoCollapse(n)); + break; + case 134 /* ArrayLiteral */: + var openBracket = ts.findChildOfKind(n, 13 /* OpenBracketToken */, sourceFile); + var closeBracket = ts.findChildOfKind(n, 14 /* CloseBracketToken */, sourceFile); + addOutliningSpan(n, openBracket, closeBracket, autoCollapse(n)); break; } depth++; @@ -26442,96 +27405,117 @@ var ts; OutliningElementsCollector.collectElements = collectElements; })(OutliningElementsCollector = ts.OutliningElementsCollector || (ts.OutliningElementsCollector = {})); })(ts || (ts = {})); -var TypeScript; -(function (TypeScript) { - var Services; - (function (Services) { - var NavigationBarItemGetter = (function () { - function NavigationBarItemGetter() { - this.hasGlobalNode = false; - } - NavigationBarItemGetter.prototype.getIndent = function (node) { - var indent = this.hasGlobalNode ? 1 : 0; +var ts; +(function (ts) { + var NavigationBar; + (function (NavigationBar) { + function getNavigationBarItems(sourceFile) { + var hasGlobalNode = false; + return getItemsWorker(getTopLevelNodes(sourceFile), createTopLevelItem); + function getIndent(node) { + var indent = hasGlobalNode ? 1 : 0; var current = node.parent; - while (current != null) { - if (current.kind() == 131 /* ModuleDeclaration */ || current.kind() === 130 /* FunctionDeclaration */) { - indent++; + while (current) { + switch (current.kind) { + case 179 /* ModuleDeclaration */: + do { + current = current.parent; + } while (current.kind === 179 /* ModuleDeclaration */); + case 176 /* ClassDeclaration */: + case 178 /* EnumDeclaration */: + case 177 /* InterfaceDeclaration */: + case 174 /* FunctionDeclaration */: + indent++; } current = current.parent; } return indent; - }; - NavigationBarItemGetter.prototype.getKindModifiers = function (modifiers) { - var result = []; - for (var i = 0, n = modifiers.length; i < n; i++) { - result.push(modifiers[i].text()); - } - return result.length > 0 ? result.join(',') : ts.ScriptElementKindModifier.none; - }; - NavigationBarItemGetter.prototype.getItems = function (node) { - var _this = this; - return this.getItemsWorker(function () { return _this.getTopLevelNodes(node); }, function (n) { return _this.createTopLevelItem(n); }); - }; - NavigationBarItemGetter.prototype.getChildNodes = function (nodes) { + } + function getChildNodes(nodes) { var childNodes = []; for (var i = 0, n = nodes.length; i < n; i++) { var node = nodes[i]; - if (node.kind() === 130 /* FunctionDeclaration */) { + if (node.kind === 176 /* ClassDeclaration */ || node.kind === 178 /* EnumDeclaration */ || node.kind === 177 /* InterfaceDeclaration */ || node.kind === 179 /* ModuleDeclaration */ || node.kind === 174 /* FunctionDeclaration */) { childNodes.push(node); } - else if (node.kind() === 149 /* VariableStatement */) { - var variableDeclaration = node.variableDeclaration; - childNodes.push.apply(childNodes, variableDeclaration.variableDeclarators); + else if (node.kind === 151 /* VariableStatement */) { + childNodes.push.apply(childNodes, node.declarations); } } - return childNodes; - }; - NavigationBarItemGetter.prototype.getTopLevelNodes = function (node) { + return sortNodes(childNodes); + } + function getTopLevelNodes(node) { var topLevelNodes = []; topLevelNodes.push(node); - this.addTopLevelNodes(node.moduleElements, topLevelNodes); + addTopLevelNodes(node.statements, topLevelNodes); return topLevelNodes; - }; - NavigationBarItemGetter.prototype.addTopLevelNodes = function (nodes, topLevelNodes) { + } + function sortNodes(nodes) { + return nodes.slice(0).sort(function (n1, n2) { + if (n1.name && n2.name) { + return n1.name.text.localeCompare(n2.name.text); + } + else if (n1.name) { + return 1; + } + else if (n2.name) { + -1; + } + else { + return n1.kind - n2.kind; + } + }); + } + function addTopLevelNodes(nodes, topLevelNodes) { + nodes = sortNodes(nodes); for (var i = 0, n = nodes.length; i < n; i++) { var node = nodes[i]; - switch (node.kind()) { - case 132 /* ClassDeclaration */: - case 133 /* EnumDeclaration */: - case 129 /* InterfaceDeclaration */: + switch (node.kind) { + case 176 /* ClassDeclaration */: + case 178 /* EnumDeclaration */: + case 177 /* InterfaceDeclaration */: topLevelNodes.push(node); break; - case 131 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: var moduleDeclaration = node; topLevelNodes.push(node); - this.addTopLevelNodes(moduleDeclaration.moduleElements, topLevelNodes); + addTopLevelNodes(getInnermostModule(moduleDeclaration).body.statements, topLevelNodes); break; - case 130 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: var functionDeclaration = node; - if (this.isTopLevelFunctionDeclaration(functionDeclaration)) { + if (isTopLevelFunctionDeclaration(functionDeclaration)) { topLevelNodes.push(node); - this.addTopLevelNodes(functionDeclaration.block.statements, topLevelNodes); + addTopLevelNodes(functionDeclaration.body.statements, topLevelNodes); } break; } } - }; - NavigationBarItemGetter.prototype.isTopLevelFunctionDeclaration = function (functionDeclaration) { - return functionDeclaration.block && TypeScript.ArrayUtilities.any(functionDeclaration.block.statements, function (s) { return s.kind() === 130 /* FunctionDeclaration */; }); - }; - NavigationBarItemGetter.prototype.getItemsWorker = function (getNodes, createItem) { + } + function isTopLevelFunctionDeclaration(functionDeclaration) { + if (functionDeclaration.kind === 174 /* FunctionDeclaration */) { + if (functionDeclaration.body && functionDeclaration.body.kind === 175 /* FunctionBlock */) { + if (ts.forEach(functionDeclaration.body.statements, function (s) { return s.kind === 174 /* FunctionDeclaration */ && !isEmpty(s.name.text); })) { + return true; + } + if (functionDeclaration.parent.kind !== 175 /* FunctionBlock */) { + return true; + } + } + } + return false; + } + function getItemsWorker(nodes, createItem) { var items = []; - var keyToItem = TypeScript.createIntrinsicsObject(); - var nodes = getNodes(); + var keyToItem = {}; for (var i = 0, n = nodes.length; i < n; i++) { var child = nodes[i]; var item = createItem(child); - if (item != null) { + if (item !== undefined) { if (item.text.length > 0) { - var key = item.text + "-" + item.kind; + var key = item.text + "-" + item.kind + "-" + item.indent; var itemWithSameName = keyToItem[key]; if (itemWithSameName) { - this.merge(itemWithSameName, item); + merge(itemWithSameName, item); } else { keyToItem[key] = item; @@ -26541,8 +27525,8 @@ var TypeScript; } } return items; - }; - NavigationBarItemGetter.prototype.merge = function (target, source) { + } + function merge(target, source) { target.spans.push.apply(target.spans, source.spans); if (source.childItems) { if (!target.childItems) { @@ -26553,206 +27537,154 @@ var TypeScript; for (var j = 0, m = target.childItems.length; j < m; j++) { var targetChild = target.childItems[j]; if (targetChild.text === sourceChild.text && targetChild.kind === sourceChild.kind) { - this.merge(targetChild, sourceChild); + merge(targetChild, sourceChild); continue outer; } } target.childItems.push(sourceChild); } } - }; - NavigationBarItemGetter.prototype.createChildItem = function (node) { - switch (node.kind()) { - case 243 /* Parameter */: - var parameter = node; - if (parameter.modifiers.length === 0) { - return null; - } - return new ts.NavigationBarItem(parameter.identifier.text(), ts.ScriptElementKind.memberVariableElement, this.getKindModifiers(parameter.modifiers), [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))]); - case 136 /* MemberFunctionDeclaration */: - var memberFunction = node; - return new ts.NavigationBarItem(memberFunction.propertyName.text(), ts.ScriptElementKind.memberFunctionElement, this.getKindModifiers(memberFunction.modifiers), [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))]); - case 140 /* GetAccessor */: - var getAccessor = node; - return new ts.NavigationBarItem(getAccessor.propertyName.text(), ts.ScriptElementKind.memberGetAccessorElement, this.getKindModifiers(getAccessor.modifiers), [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))]); - case 141 /* SetAccessor */: - var setAccessor = node; - return new ts.NavigationBarItem(setAccessor.propertyName.text(), ts.ScriptElementKind.memberSetAccessorElement, this.getKindModifiers(setAccessor.modifiers), [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))]); - case 145 /* IndexSignature */: - var indexSignature = node; - return new ts.NavigationBarItem("[]", ts.ScriptElementKind.indexSignatureElement, ts.ScriptElementKindModifier.none, [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))]); - case 244 /* EnumElement */: - var enumElement = node; - return new ts.NavigationBarItem(enumElement.propertyName.text(), ts.ScriptElementKind.memberVariableElement, ts.ScriptElementKindModifier.none, [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))]); - case 143 /* CallSignature */: - var callSignature = node; - return new ts.NavigationBarItem("()", ts.ScriptElementKind.callSignatureElement, ts.ScriptElementKindModifier.none, [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))]); - case 144 /* ConstructSignature */: - var constructSignature = node; - return new ts.NavigationBarItem("new()", ts.ScriptElementKind.constructSignatureElement, ts.ScriptElementKindModifier.none, [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))]); - case 146 /* MethodSignature */: - var methodSignature = node; - return new ts.NavigationBarItem(methodSignature.propertyName.text(), ts.ScriptElementKind.memberFunctionElement, ts.ScriptElementKindModifier.none, [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))]); - case 142 /* PropertySignature */: - var propertySignature = node; - return new ts.NavigationBarItem(propertySignature.propertyName.text(), ts.ScriptElementKind.memberVariableElement, ts.ScriptElementKindModifier.none, [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))]); - case 130 /* FunctionDeclaration */: - var functionDeclaration = node; - if (!this.isTopLevelFunctionDeclaration(functionDeclaration)) { - return new ts.NavigationBarItem(functionDeclaration.identifier.text(), ts.ScriptElementKind.functionElement, this.getKindModifiers(functionDeclaration.modifiers), [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))]); - } - break; - case 137 /* MemberVariableDeclaration */: - var memberVariableDeclaration = node; - return new ts.NavigationBarItem(memberVariableDeclaration.variableDeclarator.propertyName.text(), ts.ScriptElementKind.memberVariableElement, this.getKindModifiers(memberVariableDeclaration.modifiers), [TypeScript.TextSpan.fromBounds(TypeScript.start(memberVariableDeclaration.variableDeclarator), TypeScript.end(memberVariableDeclaration.variableDeclarator))]); - case 226 /* VariableDeclarator */: - var variableDeclarator = node; - return new ts.NavigationBarItem(variableDeclarator.propertyName.text(), ts.ScriptElementKind.variableElement, ts.ScriptElementKindModifier.none, [TypeScript.TextSpan.fromBounds(TypeScript.start(variableDeclarator), TypeScript.end(variableDeclarator))]); - case 138 /* ConstructorDeclaration */: - var constructorDeclaration = node; - return new ts.NavigationBarItem("constructor", ts.ScriptElementKind.constructorImplementationElement, ts.ScriptElementKindModifier.none, [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))]); - } - return null; - }; - NavigationBarItemGetter.prototype.createTopLevelItem = function (node) { - switch (node.kind()) { - case 120 /* SourceUnit */: - return this.createSourceUnitItem(node); - case 132 /* ClassDeclaration */: - return this.createClassItem(node); - case 133 /* EnumDeclaration */: - return this.createEnumItem(node); - case 129 /* InterfaceDeclaration */: - return this.createIterfaceItem(node); - case 131 /* ModuleDeclaration */: - return this.createModuleItem(node); - case 130 /* FunctionDeclaration */: - return this.createFunctionItem(node); - } - return null; - }; - NavigationBarItemGetter.prototype.getModuleNames = function (node) { - var result = []; - if (node.stringLiteral) { - result.push(node.stringLiteral.text()); - } - else { - this.getModuleNamesHelper(node.name, result); - } - return result; - }; - NavigationBarItemGetter.prototype.getModuleNamesHelper = function (name, result) { - if (name.kind() === 121 /* QualifiedName */) { - var qualifiedName = name; - this.getModuleNamesHelper(qualifiedName.left, result); - result.push(qualifiedName.right.text()); - } - else { - result.push(name.text()); - } - }; - NavigationBarItemGetter.prototype.createModuleItem = function (node) { - var _this = this; - var moduleNames = this.getModuleNames(node); - var childItems = this.getItemsWorker(function () { return _this.getChildNodes(node.moduleElements); }, function (n) { return _this.createChildItem(n); }); - return new ts.NavigationBarItem(moduleNames.join("."), ts.ScriptElementKind.moduleElement, this.getKindModifiers(node.modifiers), [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))], childItems, this.getIndent(node)); - }; - NavigationBarItemGetter.prototype.createFunctionItem = function (node) { - var _this = this; - var childItems = this.getItemsWorker(function () { return node.block.statements; }, function (n) { return _this.createChildItem(n); }); - return new ts.NavigationBarItem(node.identifier.text(), ts.ScriptElementKind.functionElement, this.getKindModifiers(node.modifiers), [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))], childItems, this.getIndent(node)); - }; - NavigationBarItemGetter.prototype.createSourceUnitItem = function (node) { - var _this = this; - var childItems = this.getItemsWorker(function () { return _this.getChildNodes(node.moduleElements); }, function (n) { return _this.createChildItem(n); }); - if (childItems === null || childItems.length === 0) { - return null; - } - this.hasGlobalNode = true; - return new ts.NavigationBarItem("", ts.ScriptElementKind.moduleElement, ts.ScriptElementKindModifier.none, [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))], childItems); - }; - NavigationBarItemGetter.prototype.createClassItem = function (node) { - var _this = this; - var constructor = TypeScript.ArrayUtilities.firstOrDefault(node.classElements, function (n) { return n.kind() === 138 /* ConstructorDeclaration */; }); - var nodes = constructor ? constructor.callSignature.parameterList.parameters.concat(node.classElements) : node.classElements; - var childItems = this.getItemsWorker(function () { return nodes; }, function (n) { return _this.createChildItem(n); }); - return new ts.NavigationBarItem(node.identifier.text(), ts.ScriptElementKind.classElement, this.getKindModifiers(node.modifiers), [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))], childItems, this.getIndent(node)); - }; - NavigationBarItemGetter.prototype.createEnumItem = function (node) { - var _this = this; - var childItems = this.getItemsWorker(function () { return node.enumElements; }, function (n) { return _this.createChildItem(n); }); - return new ts.NavigationBarItem(node.identifier.text(), ts.ScriptElementKind.enumElement, this.getKindModifiers(node.modifiers), [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))], childItems, this.getIndent(node)); - }; - NavigationBarItemGetter.prototype.createIterfaceItem = function (node) { - var _this = this; - var childItems = this.getItemsWorker(function () { return node.body.typeMembers; }, function (n) { return _this.createChildItem(n); }); - return new ts.NavigationBarItem(node.identifier.text(), ts.ScriptElementKind.interfaceElement, this.getKindModifiers(node.modifiers), [TypeScript.TextSpan.fromBounds(TypeScript.start(node), TypeScript.end(node))], childItems, this.getIndent(node)); - }; - return NavigationBarItemGetter; - })(); - Services.NavigationBarItemGetter = NavigationBarItemGetter; - })(Services = TypeScript.Services || (TypeScript.Services = {})); -})(TypeScript || (TypeScript = {})); -var TypeScript; -(function (TypeScript) { - var Services; - (function (Services) { - var BraceMatcher = (function () { - function BraceMatcher() { } - BraceMatcher.getMatchSpans = function (syntaxTree, position) { - var result = []; - var token = TypeScript.findToken(syntaxTree.sourceUnit(), position); - if (TypeScript.start(token) === position) { - var matchKind = BraceMatcher.getMatchingTokenKind(token); - if (matchKind !== null) { - var parentElement = token.parent; - for (var i = 0, n = TypeScript.childCount(parentElement); i < n; i++) { - var current = TypeScript.childAt(parentElement, i); - if (current !== null && TypeScript.fullWidth(current) > 0) { - if (current.kind() === matchKind) { - var range1 = new TypeScript.TextSpan(TypeScript.start(token), TypeScript.width(token)); - var range2 = new TypeScript.TextSpan(TypeScript.start(current), TypeScript.width(current)); - if (range1.start() < range2.start()) { - result.push(range1, range2); - } - else { - result.push(range2, range1); - } - break; - } - } + function createChildItem(node) { + switch (node.kind) { + case 118 /* Parameter */: + if ((node.flags & ts.NodeFlags.Modifier) === 0) { + return undefined; } + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); + case 120 /* Method */: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberFunctionElement); + case 122 /* GetAccessor */: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberGetAccessorElement); + case 123 /* SetAccessor */: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberSetAccessorElement); + case 126 /* IndexSignature */: + return createItem(node, "[]", ts.ScriptElementKind.indexSignatureElement); + case 183 /* EnumMember */: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); + case 124 /* CallSignature */: + return createItem(node, "()", ts.ScriptElementKind.callSignatureElement); + case 125 /* ConstructSignature */: + return createItem(node, "new()", ts.ScriptElementKind.constructSignatureElement); + case 119 /* Property */: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); + case 174 /* FunctionDeclaration */: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.functionElement); + case 173 /* VariableDeclaration */: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.variableElement); + case 121 /* Constructor */: + return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); + } + return undefined; + function createItem(node, name, scriptElementKind) { + return getNavigationBarItem(name, scriptElementKind, ts.getNodeModifiers(node), [getNodeSpan(node)]); + } + } + function isEmpty(text) { + return !text || text.trim() === ""; + } + function getNavigationBarItem(text, kind, kindModifiers, spans, childItems, indent) { + if (childItems === void 0) { childItems = []; } + if (indent === void 0) { indent = 0; } + if (isEmpty(text)) { + return undefined; + } + return { + text: text, + kind: kind, + kindModifiers: kindModifiers, + spans: spans, + childItems: childItems, + indent: indent, + bolded: false, + grayed: false + }; + } + function createTopLevelItem(node) { + switch (node.kind) { + case 184 /* SourceFile */: + return createSourceFileItem(node); + case 176 /* ClassDeclaration */: + return createClassItem(node); + case 178 /* EnumDeclaration */: + return createEnumItem(node); + case 177 /* InterfaceDeclaration */: + return createIterfaceItem(node); + case 179 /* ModuleDeclaration */: + return createModuleItem(node); + case 174 /* FunctionDeclaration */: + return createFunctionItem(node); + } + return undefined; + function getModuleName(moduleDeclaration) { + if (moduleDeclaration.name.kind === 7 /* StringLiteral */) { + return getTextOfNode(moduleDeclaration.name); } + var result = []; + result.push(moduleDeclaration.name.text); + while (moduleDeclaration.body && moduleDeclaration.body.kind === 179 /* ModuleDeclaration */) { + moduleDeclaration = moduleDeclaration.body; + result.push(moduleDeclaration.name.text); + } + return result.join("."); } - return result; - }; - BraceMatcher.getMatchingTokenKind = function (token) { - switch (token.kind()) { - case 70 /* OpenBraceToken */: - return 71 /* CloseBraceToken */; - case 72 /* OpenParenToken */: - return 73 /* CloseParenToken */; - case 74 /* OpenBracketToken */: - return 75 /* CloseBracketToken */; - case 80 /* LessThanToken */: - return 81 /* GreaterThanToken */; - case 71 /* CloseBraceToken */: - return 70 /* OpenBraceToken */; - case 73 /* CloseParenToken */: - return 72 /* OpenParenToken */; - case 75 /* CloseBracketToken */: - return 74 /* OpenBracketToken */; - case 81 /* GreaterThanToken */: - return 80 /* LessThanToken */; + function createModuleItem(node) { + var moduleName = getModuleName(node); + var childItems = getItemsWorker(getChildNodes(getInnermostModule(node).body.statements), createChildItem); + return getNavigationBarItem(moduleName, ts.ScriptElementKind.moduleElement, ts.getNodeModifiers(node), [getNodeSpan(node)], childItems, getIndent(node)); } - return null; - }; - return BraceMatcher; - })(); - Services.BraceMatcher = BraceMatcher; - })(Services = TypeScript.Services || (TypeScript.Services = {})); -})(TypeScript || (TypeScript = {})); + function createFunctionItem(node) { + if (node.name && node.body && node.body.kind === 175 /* FunctionBlock */) { + var childItems = getItemsWorker(sortNodes(node.body.statements), createChildItem); + return getNavigationBarItem(node.name.text, ts.ScriptElementKind.functionElement, ts.getNodeModifiers(node), [getNodeSpan(node)], childItems, getIndent(node)); + } + return undefined; + } + function createSourceFileItem(node) { + var childItems = getItemsWorker(getChildNodes(node.statements), createChildItem); + if (childItems === undefined || childItems.length === 0) { + return undefined; + } + hasGlobalNode = true; + var rootName = ts.isExternalModule(node) ? "\"" + ts.escapeString(ts.getBaseFilename(ts.removeFileExtension(ts.normalizePath(node.filename)))) + "\"" : ""; + return getNavigationBarItem(rootName, ts.ScriptElementKind.moduleElement, ts.ScriptElementKindModifier.none, [getNodeSpan(node)], childItems); + } + function createClassItem(node) { + var childItems; + if (node.members) { + var constructor = ts.forEach(node.members, function (member) { + return member.kind === 121 /* Constructor */ && member; + }); + var nodes = constructor ? constructor.parameters.concat(node.members) : node.members; + var childItems = getItemsWorker(sortNodes(nodes), createChildItem); + } + return getNavigationBarItem(node.name.text, ts.ScriptElementKind.classElement, ts.getNodeModifiers(node), [getNodeSpan(node)], childItems, getIndent(node)); + } + function createEnumItem(node) { + var childItems = getItemsWorker(sortNodes(node.members), createChildItem); + return getNavigationBarItem(node.name.text, ts.ScriptElementKind.enumElement, ts.getNodeModifiers(node), [getNodeSpan(node)], childItems, getIndent(node)); + } + function createIterfaceItem(node) { + var childItems = getItemsWorker(sortNodes(node.members), createChildItem); + return getNavigationBarItem(node.name.text, ts.ScriptElementKind.interfaceElement, ts.getNodeModifiers(node), [getNodeSpan(node)], childItems, getIndent(node)); + } + } + function getInnermostModule(node) { + while (node.body.kind === 179 /* ModuleDeclaration */) { + node = node.body; + } + return node; + } + function getNodeSpan(node) { + return node.kind === 184 /* SourceFile */ ? TypeScript.TextSpan.fromBounds(node.getFullStart(), node.getEnd()) : TypeScript.TextSpan.fromBounds(node.getStart(), node.getEnd()); + } + function getTextOfNode(node) { + return ts.getTextOfNodeFromSourceText(sourceFile.text, node); + } + } + NavigationBar.getNavigationBarItems = getNavigationBarItems; + })(NavigationBar = ts.NavigationBar || (ts.NavigationBar = {})); +})(ts || (ts = {})); var TypeScript; (function (TypeScript) { var Services; @@ -27741,6 +28673,353 @@ var TypeScript; Indentation.firstNonWhitespacePosition = firstNonWhitespacePosition; })(Indentation = TypeScript.Indentation || (TypeScript.Indentation = {})); })(TypeScript || (TypeScript = {})); +var ts; +(function (ts) { + var SignatureHelp; + (function (SignatureHelp) { + var emptyArray = []; + function getSignatureHelpItems(sourceFile, position, typeInfoResolver, cancellationToken) { + var startingToken = ts.findTokenOnLeftOfPosition(sourceFile, position); + if (!startingToken) { + return undefined; + } + var argumentInfo = getContainingArgumentInfo(startingToken); + cancellationToken.throwIfCancellationRequested(); + if (!argumentInfo) { + return undefined; + } + var call = argumentInfo.list.parent; + var candidates = []; + var resolvedSignature = typeInfoResolver.getResolvedSignature(call, candidates); + cancellationToken.throwIfCancellationRequested(); + if (!candidates.length) { + return undefined; + } + return createSignatureHelpItems(candidates, resolvedSignature, argumentInfo); + function getImmediatelyContainingArgumentInfo(node) { + if (node.parent.kind !== 139 /* CallExpression */ && node.parent.kind !== 140 /* NewExpression */) { + return undefined; + } + var parent = node.parent; + if (node.kind === 19 /* LessThanToken */ || node.kind === 11 /* OpenParenToken */) { + var list = getChildListThatStartsWithOpenerToken(parent, node, sourceFile); + ts.Debug.assert(list); + return { + list: list, + listItemIndex: 0 + }; + } + if (node.kind === 20 /* GreaterThanToken */ || node.kind === 12 /* CloseParenToken */ || node === parent.func) { + return undefined; + } + return ts.findListItemInfo(node); + } + function getContainingArgumentInfo(node) { + for (var n = node; n.kind !== 184 /* SourceFile */; n = n.parent) { + if (n.kind === 175 /* FunctionBlock */) { + return undefined; + } + if (n.pos < n.parent.pos || n.end > n.parent.end) { + ts.Debug.fail("Node of kind " + ts.SyntaxKind[n.kind] + " is not a subspan of its parent of kind " + ts.SyntaxKind[n.parent.kind]); + } + var argumentInfo = getImmediatelyContainingArgumentInfo(n); + if (argumentInfo) { + return argumentInfo; + } + } + return undefined; + } + function getChildListThatStartsWithOpenerToken(parent, openerToken, sourceFile) { + var children = parent.getChildren(sourceFile); + var indexOfOpenerToken = children.indexOf(openerToken); + ts.Debug.assert(indexOfOpenerToken >= 0 && children.length > indexOfOpenerToken + 1); + return children[indexOfOpenerToken + 1]; + } + function selectBestInvalidOverloadIndex(candidates, argumentCount) { + var maxParamsSignatureIndex = -1; + var maxParams = -1; + for (var i = 0; i < candidates.length; i++) { + var candidate = candidates[i]; + if (candidate.hasRestParameter || candidate.parameters.length >= argumentCount) { + return i; + } + if (candidate.parameters.length > maxParams) { + maxParams = candidate.parameters.length; + maxParamsSignatureIndex = i; + } + } + return maxParamsSignatureIndex; + } + function createSignatureHelpItems(candidates, bestSignature, argumentInfoOrTypeArgumentInfo) { + var argumentListOrTypeArgumentList = argumentInfoOrTypeArgumentInfo.list; + var parent = argumentListOrTypeArgumentList.parent; + var isTypeParameterHelp = parent.typeArguments && parent.typeArguments.pos === argumentListOrTypeArgumentList.pos; + ts.Debug.assert(isTypeParameterHelp || parent.arguments.pos === argumentListOrTypeArgumentList.pos); + var callTargetNode = argumentListOrTypeArgumentList.parent.func; + var callTargetSymbol = typeInfoResolver.getSymbolInfo(callTargetNode); + var callTargetDisplayParts = callTargetSymbol && ts.symbolToDisplayParts(typeInfoResolver, callTargetSymbol, undefined, undefined); + var items = ts.map(candidates, function (candidateSignature) { + var signatureHelpParameters; + var prefixParts = []; + var suffixParts = []; + if (callTargetDisplayParts) { + prefixParts.push.apply(prefixParts, callTargetDisplayParts); + } + if (isTypeParameterHelp) { + prefixParts.push(ts.punctuationPart(19 /* LessThanToken */)); + var typeParameters = candidateSignature.typeParameters; + signatureHelpParameters = typeParameters && typeParameters.length > 0 ? ts.map(typeParameters, createSignatureHelpParameterForTypeParameter) : emptyArray; + suffixParts.push(ts.punctuationPart(20 /* GreaterThanToken */)); + var parameterParts = ts.mapToDisplayParts(function (writer) { return typeInfoResolver.getSymbolDisplayBuilder().buildDisplayForParametersAndDelimiters(candidateSignature.parameters, writer, argumentListOrTypeArgumentList); }); + suffixParts.push.apply(suffixParts, parameterParts); + } + else { + var typeParameterParts = ts.mapToDisplayParts(function (writer) { return typeInfoResolver.getSymbolDisplayBuilder().buildDisplayForTypeParametersAndDelimiters(candidateSignature.typeParameters, writer, argumentListOrTypeArgumentList); }); + prefixParts.push.apply(prefixParts, typeParameterParts); + prefixParts.push(ts.punctuationPart(11 /* OpenParenToken */)); + var parameters = candidateSignature.parameters; + signatureHelpParameters = parameters.length > 0 ? ts.map(parameters, createSignatureHelpParameterForParameter) : emptyArray; + suffixParts.push(ts.punctuationPart(12 /* CloseParenToken */)); + } + var returnTypeParts = ts.mapToDisplayParts(function (writer) { return typeInfoResolver.getSymbolDisplayBuilder().buildReturnTypeDisplay(candidateSignature, writer, argumentListOrTypeArgumentList); }); + suffixParts.push.apply(suffixParts, returnTypeParts); + return { + isVariadic: candidateSignature.hasRestParameter, + prefixDisplayParts: prefixParts, + suffixDisplayParts: suffixParts, + separatorDisplayParts: [ts.punctuationPart(18 /* CommaToken */), ts.spacePart()], + parameters: signatureHelpParameters, + documentation: candidateSignature.getDocumentationComment() + }; + }); + var applicableSpanStart = argumentListOrTypeArgumentList.getFullStart(); + var applicableSpanEnd = ts.skipTrivia(sourceFile.text, argumentListOrTypeArgumentList.end, false); + var applicableSpan = new TypeScript.TextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart); + var argumentIndex = (argumentInfoOrTypeArgumentInfo.listItemIndex + 1) >> 1; + var argumentCount = argumentListOrTypeArgumentList.getChildCount() === 0 ? 0 : 1 + ts.countWhere(argumentListOrTypeArgumentList.getChildren(), function (arg) { return arg.kind === 18 /* CommaToken */; }); + var selectedItemIndex = candidates.indexOf(bestSignature); + if (selectedItemIndex < 0) { + selectedItemIndex = selectBestInvalidOverloadIndex(candidates, argumentCount); + } + return { + items: items, + applicableSpan: applicableSpan, + selectedItemIndex: selectedItemIndex, + argumentIndex: argumentIndex, + argumentCount: argumentCount + }; + function createSignatureHelpParameterForParameter(parameter) { + var displayParts = ts.mapToDisplayParts(function (writer) { return typeInfoResolver.getSymbolDisplayBuilder().buildParameterDisplay(parameter, writer, argumentListOrTypeArgumentList); }); + var isOptional = !!(parameter.valueDeclaration.flags & 4 /* QuestionMark */); + return { + name: parameter.name, + documentation: parameter.getDocumentationComment(), + displayParts: displayParts, + isOptional: isOptional + }; + } + function createSignatureHelpParameterForTypeParameter(typeParameter) { + var displayParts = ts.mapToDisplayParts(function (writer) { return typeInfoResolver.getSymbolDisplayBuilder().buildTypeParameterDisplay(typeParameter, writer, argumentListOrTypeArgumentList); }); + return { + name: typeParameter.symbol.name, + documentation: emptyArray, + displayParts: displayParts, + isOptional: false + }; + } + } + } + SignatureHelp.getSignatureHelpItems = getSignatureHelpItems; + })(SignatureHelp = ts.SignatureHelp || (ts.SignatureHelp = {})); +})(ts || (ts = {})); +var ts; +(function (ts) { + function findListItemInfo(node) { + var syntaxList = findContainingList(node); + var children = syntaxList.getChildren(); + var index = ts.indexOf(children, node); + return { + listItemIndex: index, + list: syntaxList + }; + } + ts.findListItemInfo = findListItemInfo; + function findChildOfKind(n, kind, sourceFile) { + return ts.forEach(n.getChildren(sourceFile), function (c) { return c.kind === kind && c; }); + } + ts.findChildOfKind = findChildOfKind; + function findContainingList(node) { + var syntaxList = ts.forEach(node.parent.getChildren(), function (c) { + if (c.kind === 186 /* SyntaxList */ && c.pos <= node.pos && c.end >= node.end) { + return c; + } + }); + if (!syntaxList) { + ts.Debug.assert(findChildOfKind(node.parent, 186 /* SyntaxList */), "Node of kind " + ts.SyntaxKind[node.parent.kind] + " has no list children"); + } + return syntaxList; + } + ts.findContainingList = findContainingList; + function findListItemIndexContainingPosition(list, position) { + ts.Debug.assert(list.kind === 186 /* SyntaxList */); + var children = list.getChildren(); + for (var i = 0; i < children.length; i++) { + if (children[i].pos <= position && children[i].end > position) { + return i; + } + } + return -1; + } + ts.findListItemIndexContainingPosition = findListItemIndexContainingPosition; + function getTouchingWord(sourceFile, position) { + return getTouchingToken(sourceFile, position, isWord); + } + ts.getTouchingWord = getTouchingWord; + function getTouchingPropertyName(sourceFile, position) { + return getTouchingToken(sourceFile, position, isPropertyName); + } + ts.getTouchingPropertyName = getTouchingPropertyName; + function getTouchingToken(sourceFile, position, includeItemAtEndPosition) { + return getTokenAtPositionWorker(sourceFile, position, false, includeItemAtEndPosition); + } + ts.getTouchingToken = getTouchingToken; + function getTokenAtPosition(sourceFile, position) { + return getTokenAtPositionWorker(sourceFile, position, true, undefined); + } + ts.getTokenAtPosition = getTokenAtPosition; + function getTokenAtPositionWorker(sourceFile, position, allowPositionInLeadingTrivia, includeItemAtEndPosition) { + var current = sourceFile; + outer: while (true) { + if (isToken(current)) { + return current; + } + for (var i = 0, n = current.getChildCount(sourceFile); i < n; i++) { + var child = current.getChildAt(i); + var start = allowPositionInLeadingTrivia ? child.getFullStart() : child.getStart(sourceFile); + if (start <= position) { + if (position < child.getEnd()) { + current = child; + continue outer; + } + else if (includeItemAtEndPosition && child.getEnd() === position) { + var previousToken = findPrecedingToken(position, sourceFile, child); + if (previousToken && includeItemAtEndPosition(previousToken)) { + return previousToken; + } + } + } + } + return current; + } + } + function findTokenOnLeftOfPosition(file, position) { + var tokenAtPosition = getTokenAtPosition(file, position); + if (isToken(tokenAtPosition) && position > tokenAtPosition.getStart(file) && position < tokenAtPosition.getEnd()) { + return tokenAtPosition; + } + return findPrecedingToken(position, file); + } + ts.findTokenOnLeftOfPosition = findTokenOnLeftOfPosition; + function findNextToken(previousToken, parent) { + return find(parent); + function find(n) { + if (isToken(n) && n.pos === previousToken.end) { + return n; + } + var children = n.getChildren(); + for (var i = 0, len = children.length; i < len; ++i) { + var child = children[i]; + var shouldDiveInChildNode = (child.pos <= previousToken.pos && child.end > previousToken.end) || (child.pos === previousToken.end); + if (shouldDiveInChildNode && nodeHasTokens(child)) { + return find(child); + } + } + return undefined; + } + } + ts.findNextToken = findNextToken; + function findPrecedingToken(position, sourceFile, startNode) { + return find(startNode || sourceFile); + function findRightmostToken(n) { + if (isToken(n)) { + return n; + } + var children = n.getChildren(); + var candidate = findRightmostChildNodeWithTokens(children, children.length); + return candidate && findRightmostToken(candidate); + } + function find(n) { + if (isToken(n)) { + return n; + } + var children = n.getChildren(); + for (var i = 0, len = children.length; i < len; ++i) { + var child = children[i]; + if (nodeHasTokens(child)) { + if (position < child.end) { + if (child.getStart(sourceFile) >= position) { + var candidate = findRightmostChildNodeWithTokens(children, i); + return candidate && findRightmostToken(candidate); + } + else { + return find(child); + } + } + } + } + ts.Debug.assert(startNode || n.kind === 184 /* SourceFile */); + if (children.length) { + var candidate = findRightmostChildNodeWithTokens(children, children.length); + return candidate && findRightmostToken(candidate); + } + } + function findRightmostChildNodeWithTokens(children, exclusiveStartPosition) { + for (var i = exclusiveStartPosition - 1; i >= 0; --i) { + if (nodeHasTokens(children[i])) { + return children[i]; + } + } + } + } + ts.findPrecedingToken = findPrecedingToken; + function nodeHasTokens(n) { + if (n.kind === 153 /* ExpressionStatement */) { + return nodeHasTokens(n.expression); + } + if (n.kind === 1 /* EndOfFileToken */ || n.kind === 149 /* OmittedExpression */ || n.kind === 115 /* Missing */) { + return false; + } + return n.kind !== 186 /* SyntaxList */ || n.getChildCount() !== 0; + } + function getTypeArgumentOrTypeParameterList(node) { + if (node.kind === 127 /* TypeReference */ || node.kind === 139 /* CallExpression */) { + return node.typeArguments; + } + if (ts.isAnyFunction(node) || node.kind === 176 /* ClassDeclaration */ || node.kind === 177 /* InterfaceDeclaration */) { + return node.typeParameters; + } + return undefined; + } + ts.getTypeArgumentOrTypeParameterList = getTypeArgumentOrTypeParameterList; + function isToken(n) { + return n.kind >= ts.SyntaxKind.FirstToken && n.kind <= ts.SyntaxKind.LastToken; + } + ts.isToken = isToken; + function isWord(n) { + return n.kind === 59 /* Identifier */ || ts.isKeyword(n.kind); + } + function isPropertyName(n) { + return n.kind === 7 /* StringLiteral */ || n.kind === 6 /* NumericLiteral */ || isWord(n); + } + function isComment(n) { + return n.kind === 2 /* SingleLineCommentTrivia */ || n.kind === 3 /* MultiLineCommentTrivia */; + } + ts.isComment = isComment; + function isPunctuation(n) { + return ts.SyntaxKind.FirstPunctuation <= n.kind && n.kind <= ts.SyntaxKind.LastPunctuation; + } + ts.isPunctuation = isPunctuation; +})(ts || (ts = {})); var TypeScript; (function (TypeScript) { var Services; @@ -28027,8 +29306,10 @@ var TypeScript; var result = []; var formattingEdits = Formatting.Formatter.getEdits(span, this.syntaxTree.sourceUnit(), this.options, true, this.snapshot, this.rulesProvider, formattingRequestKind); formattingEdits.forEach(function (item) { - var edit = new ts.TextChange(new TypeScript.TextSpan(item.position, item.length), item.replaceWith); - result.push(edit); + result.push({ + span: new TypeScript.TextSpan(item.position, item.length), + newText: item.replaceWith + }); }); return result; }; @@ -29632,7 +30913,7 @@ var ts; if (position > sourceFile.text.length) { return 0; } - var precedingToken = findPrecedingToken(position, sourceFile); + var precedingToken = ts.findPrecedingToken(position, sourceFile); if (!precedingToken) { return 0; } @@ -29640,7 +30921,7 @@ var ts; return 0; } var lineAtPosition = sourceFile.getLineAndCharacterFromPosition(position).line; - if (precedingToken.kind === 18 /* CommaToken */ && precedingToken.parent.kind !== 145 /* BinaryExpression */) { + if (precedingToken.kind === 18 /* CommaToken */ && precedingToken.parent.kind !== 147 /* BinaryExpression */) { var actualIndentation = getActualIndentationForListItemBeforeComma(precedingToken, sourceFile, options); if (actualIndentation !== -1) { return actualIndentation; @@ -29695,18 +30976,19 @@ var ts; } SmartIndenter.getIndentation = getIndentation; function getActualIndentationForListItemBeforeComma(commaToken, sourceFile, options) { - var itemInfo = findPrecedingListItem(commaToken); - return deriveActualIndentationFromList(itemInfo.list.getChildren(), itemInfo.listItemIndex, sourceFile, options); + var commaItemInfo = ts.findListItemInfo(commaToken); + ts.Debug.assert(commaItemInfo.listItemIndex > 0); + return deriveActualIndentationFromList(commaItemInfo.list.getChildren(), commaItemInfo.listItemIndex - 1, sourceFile, options); } function getActualIndentationForNode(current, parent, currentLineAndChar, parentAndChildShareLine, sourceFile, options) { - var useActualIndentation = (ts.isDeclaration(current) || ts.isStatement(current)) && (parent.kind === 182 /* SourceFile */ || !parentAndChildShareLine); + var useActualIndentation = (ts.isDeclaration(current) || ts.isStatement(current)) && (parent.kind === 184 /* SourceFile */ || !parentAndChildShareLine); if (!useActualIndentation) { return -1; } return findColumnForFirstNonWhitespaceCharacterInLine(currentLineAndChar, sourceFile, options); } function nextTokenIsCurlyBraceOnSameLineAsCursor(precedingToken, current, lineAtPosition, sourceFile) { - var nextToken = findNextToken(precedingToken, current); + var nextToken = ts.findNextToken(precedingToken, current); if (!nextToken) { return false; } @@ -29722,27 +31004,12 @@ var ts; function getStartLineAndCharacterForNode(n, sourceFile) { return sourceFile.getLineAndCharacterFromPosition(n.getStart(sourceFile)); } - function findPrecedingListItem(commaToken) { - var syntaxList = ts.forEach(commaToken.parent.getChildren(), function (c) { - if (c.kind == 184 /* SyntaxList */ && c.pos <= commaToken.end && c.end >= commaToken.end) { - return c; - } - }); - ts.Debug.assert(syntaxList); - var children = syntaxList.getChildren(); - var commaIndex = ts.indexOf(children, commaToken); - ts.Debug.assert(commaIndex !== -1 && commaIndex !== 0); - return { - listItemIndex: commaIndex - 1, - list: syntaxList - }; - } function positionBelongsToNode(candidate, position, sourceFile) { return candidate.end > position || !isCompletedNode(candidate, sourceFile); } function childStartsOnTheSameLineWithElseInIfStatement(parent, child, childStartLine, sourceFile) { - if (parent.kind === 152 /* IfStatement */ && parent.elseStatement === child) { - var elseKeyword = ts.forEach(parent.getChildren(), function (c) { return c.kind === 70 /* ElseKeyword */ && c; }); + if (parent.kind === 154 /* IfStatement */ && parent.elseStatement === child) { + var elseKeyword = ts.findChildOfKind(parent, 70 /* ElseKeyword */, sourceFile); ts.Debug.assert(elseKeyword); var elseKeywordStartLine = getStartLineAndCharacterForNode(elseKeyword, sourceFile).line; return elseKeywordStartLine === childStartLine; @@ -29756,15 +31023,15 @@ var ts; return getActualIndentationFromList(node.parent.typeArguments); } break; - case 133 /* ObjectLiteral */: + case 135 /* ObjectLiteral */: return getActualIndentationFromList(node.parent.properties); case 129 /* TypeLiteral */: return getActualIndentationFromList(node.parent.members); - case 132 /* ArrayLiteral */: + case 134 /* ArrayLiteral */: return getActualIndentationFromList(node.parent.elements); - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: case 120 /* Method */: case 124 /* CallSignature */: case 125 /* ConstructSignature */: @@ -29772,8 +31039,8 @@ var ts; return getActualIndentationFromList(node.parent.typeParameters); } return getActualIndentationFromList(node.parent.parameters); - case 138 /* NewExpression */: - case 137 /* CallExpression */: + case 140 /* NewExpression */: + case 139 /* CallExpression */: if (node.parent.typeArguments && node.end < node.parent.typeArguments.end) { return getActualIndentationFromList(node.parent.typeArguments); } @@ -29819,119 +31086,47 @@ var ts; } return column; } - function findNextToken(previousToken, parent) { - return find(parent); - function find(n) { - if (isToken(n) && n.pos === previousToken.end) { - return n; - } - var children = n.getChildren(); - for (var i = 0, len = children.length; i < len; ++i) { - var child = children[i]; - var shouldDiveInChildNode = (child.pos <= previousToken.pos && child.end > previousToken.end) || (child.pos === previousToken.end); - if (shouldDiveInChildNode && nodeHasTokens(child)) { - return find(child); - } - } - return undefined; - } - } - function findPrecedingToken(position, sourceFile) { - return find(sourceFile); - function findRightmostToken(n) { - if (isToken(n)) { - return n; - } - var children = n.getChildren(); - var candidate = findRightmostChildNodeWithTokens(children, children.length); - return candidate && findRightmostToken(candidate); - } - function find(n) { - if (isToken(n)) { - return n; - } - var children = n.getChildren(); - for (var i = 0, len = children.length; i < len; ++i) { - var child = children[i]; - if (nodeHasTokens(child)) { - if (position < child.end) { - if (child.getStart(sourceFile) >= position) { - var candidate = findRightmostChildNodeWithTokens(children, i); - return candidate && findRightmostToken(candidate); - } - else { - return find(child); - } - } - } - } - ts.Debug.assert(n.kind === 182 /* SourceFile */); - if (children.length) { - var candidate = findRightmostChildNodeWithTokens(children, children.length); - return candidate && findRightmostToken(candidate); - } - } - function findRightmostChildNodeWithTokens(children, exclusiveStartPosition) { - for (var i = exclusiveStartPosition - 1; i >= 0; --i) { - if (nodeHasTokens(children[i])) { - return children[i]; - } - } - } - } - function nodeHasTokens(n) { - if (n.kind === 151 /* ExpressionStatement */) { - return nodeHasTokens(n.expression); - } - if (n.kind === 1 /* EndOfFileToken */ || n.kind === 147 /* OmittedExpression */ || n.kind === 115 /* Missing */) { - return false; - } - return n.kind !== 184 /* SyntaxList */ || n.getChildCount() !== 0; - } - function isToken(n) { - return n.kind >= ts.SyntaxKind.FirstToken && n.kind <= ts.SyntaxKind.LastToken; - } function nodeContentIsIndented(parent, child) { switch (parent.kind) { - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 176 /* EnumDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: return true; - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return false; - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: case 120 /* Method */: - case 141 /* FunctionExpression */: + case 143 /* FunctionExpression */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: case 121 /* Constructor */: return false; - case 153 /* DoStatement */: - case 154 /* WhileStatement */: - case 156 /* ForInStatement */: - case 155 /* ForStatement */: - return child && child.kind !== 148 /* Block */; - case 152 /* IfStatement */: - return child && child.kind !== 148 /* Block */; - case 166 /* TryStatement */: + case 155 /* DoStatement */: + case 156 /* WhileStatement */: + case 158 /* ForInStatement */: + case 157 /* ForStatement */: + return child && child.kind !== 150 /* Block */; + case 154 /* IfStatement */: + return child && child.kind !== 150 /* Block */; + case 168 /* TryStatement */: return false; - case 132 /* ArrayLiteral */: - case 148 /* Block */: - case 173 /* FunctionBlock */: - case 167 /* TryBlock */: - case 168 /* CatchBlock */: - case 169 /* FinallyBlock */: - case 178 /* ModuleBlock */: - case 133 /* ObjectLiteral */: + case 134 /* ArrayLiteral */: + case 150 /* Block */: + case 175 /* FunctionBlock */: + case 169 /* TryBlock */: + case 170 /* CatchBlock */: + case 171 /* FinallyBlock */: + case 180 /* ModuleBlock */: + case 135 /* ObjectLiteral */: case 129 /* TypeLiteral */: - case 161 /* SwitchStatement */: - case 163 /* DefaultClause */: - case 162 /* CaseClause */: - case 140 /* ParenExpression */: - case 137 /* CallExpression */: - case 138 /* NewExpression */: - case 149 /* VariableStatement */: - case 171 /* VariableDeclaration */: + case 163 /* SwitchStatement */: + case 165 /* DefaultClause */: + case 164 /* CaseClause */: + case 142 /* ParenExpression */: + case 139 /* CallExpression */: + case 140 /* NewExpression */: + case 151 /* VariableStatement */: + case 173 /* VariableDeclaration */: return true; default: return false; @@ -29952,47 +31147,47 @@ var ts; } function isCompletedNode(n, sourceFile) { switch (n.kind) { - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 176 /* EnumDeclaration */: - case 133 /* ObjectLiteral */: - case 148 /* Block */: - case 168 /* CatchBlock */: - case 169 /* FinallyBlock */: - case 173 /* FunctionBlock */: - case 178 /* ModuleBlock */: - case 161 /* SwitchStatement */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: + case 135 /* ObjectLiteral */: + case 150 /* Block */: + case 170 /* CatchBlock */: + case 171 /* FinallyBlock */: + case 175 /* FunctionBlock */: + case 180 /* ModuleBlock */: + case 163 /* SwitchStatement */: return nodeEndsWith(n, 10 /* CloseBraceToken */, sourceFile); - case 140 /* ParenExpression */: + case 142 /* ParenExpression */: case 124 /* CallSignature */: - case 137 /* CallExpression */: + case 139 /* CallExpression */: case 125 /* ConstructSignature */: return nodeEndsWith(n, 12 /* CloseParenToken */, sourceFile); - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: case 120 /* Method */: - case 142 /* ArrowFunction */: + case 144 /* ArrowFunction */: return !n.body || isCompletedNode(n.body, sourceFile); - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return n.body && isCompletedNode(n.body, sourceFile); - case 152 /* IfStatement */: + case 154 /* IfStatement */: if (n.elseStatement) { return isCompletedNode(n.elseStatement, sourceFile); } return isCompletedNode(n.thenStatement, sourceFile); - case 151 /* ExpressionStatement */: + case 153 /* ExpressionStatement */: return isCompletedNode(n.expression, sourceFile); - case 132 /* ArrayLiteral */: + case 134 /* ArrayLiteral */: return nodeEndsWith(n, 14 /* CloseBracketToken */, sourceFile); case 115 /* Missing */: return false; - case 162 /* CaseClause */: - case 163 /* DefaultClause */: + case 164 /* CaseClause */: + case 165 /* DefaultClause */: return false; - case 154 /* WhileStatement */: + case 156 /* WhileStatement */: return isCompletedNode(n.statement, sourceFile); - case 153 /* DoStatement */: - var hasWhileKeyword = ts.forEach(n.getChildren(), function (c) { return c.kind === 94 /* WhileKeyword */ && c; }); + case 155 /* DoStatement */: + var hasWhileKeyword = ts.findChildOfKind(n, 94 /* WhileKeyword */, sourceFile); if (hasWhileKeyword) { return nodeEndsWith(n, 12 /* CloseParenToken */, sourceFile); } @@ -31236,98 +32431,6 @@ var TypeScript; })(ASTHelpers = TypeScript.ASTHelpers || (TypeScript.ASTHelpers = {})); })(TypeScript || (TypeScript = {})); var TypeScript; -(function (TypeScript) { - var MemberName = (function () { - function MemberName() { - this.prefix = ""; - this.suffix = ""; - } - MemberName.prototype.isString = function () { - return false; - }; - MemberName.prototype.isArray = function () { - return false; - }; - MemberName.prototype.isMarker = function () { - return !this.isString() && !this.isArray(); - }; - MemberName.prototype.toString = function () { - return MemberName.memberNameToString(this); - }; - MemberName.memberNameToString = function (memberName, markerInfo, markerBaseLength) { - if (markerBaseLength === void 0) { markerBaseLength = 0; } - var result = memberName.prefix; - if (memberName.isString()) { - result += memberName.text; - } - else if (memberName.isArray()) { - var ar = memberName; - for (var index = 0; index < ar.entries.length; index++) { - if (ar.entries[index].isMarker()) { - if (markerInfo) { - markerInfo.push(markerBaseLength + result.length); - } - continue; - } - result += MemberName.memberNameToString(ar.entries[index], markerInfo, markerBaseLength + result.length); - result += ar.delim; - } - } - result += memberName.suffix; - return result; - }; - MemberName.create = function (arg1, arg2, arg3) { - if (typeof arg1 === "string") { - return new MemberNameString(arg1); - } - else { - var result = new MemberNameArray(); - if (arg2) - result.prefix = arg2; - if (arg3) - result.suffix = arg3; - result.entries.push(arg1); - return result; - } - }; - return MemberName; - })(); - TypeScript.MemberName = MemberName; - var MemberNameString = (function (_super) { - __extends(MemberNameString, _super); - function MemberNameString(text) { - _super.call(this); - this.text = text; - } - MemberNameString.prototype.isString = function () { - return true; - }; - return MemberNameString; - })(MemberName); - TypeScript.MemberNameString = MemberNameString; - var MemberNameArray = (function (_super) { - __extends(MemberNameArray, _super); - function MemberNameArray() { - _super.call(this); - this.delim = ""; - this.entries = []; - } - MemberNameArray.prototype.isArray = function () { - return true; - }; - MemberNameArray.prototype.add = function (entry) { - this.entries.push(entry); - }; - MemberNameArray.prototype.addAll = function (entries) { - for (var i = 0; i < entries.length; i++) { - this.entries.push(entries[i]); - } - }; - return MemberNameArray; - })(MemberName); - TypeScript.MemberNameArray = MemberNameArray; -})(TypeScript || (TypeScript = {})); -var TypeScript; (function (TypeScript) { function stripStartAndEndQuotes(str) { var firstCharCode = str && str.charCodeAt(0); @@ -31506,10 +32609,7 @@ var ts; function NodeObject() { } NodeObject.prototype.getSourceFile = function () { - var node = this; - while (node.kind !== 182 /* SourceFile */) - node = node.parent; - return node; + return ts.getSourceFileOfNode(this); }; NodeObject.prototype.getStart = function (sourceFile) { return ts.getTokenPosOfNode(this, sourceFile); @@ -31543,7 +32643,7 @@ var ts; return pos; }; NodeObject.prototype.createSyntaxList = function (nodes) { - var list = createNode(184 /* SyntaxList */, nodes.pos, nodes.end, 512 /* Synthetic */, this); + var list = createNode(186 /* SyntaxList */, nodes.pos, nodes.end, 512 /* Synthetic */, this); list._children = []; var pos = nodes.pos; for (var i = 0, len = nodes.length; i < len; i++) { @@ -31603,7 +32703,7 @@ var ts; return this._children; }; NodeObject.prototype.getFirstToken = function (sourceFile) { - var children = this.getChildren(sourceFile); + var children = this.getChildren(); for (var i = 0; i < children.length; i++) { var child = children[i]; if (child.kind < 115 /* Missing */) @@ -31638,8 +32738,225 @@ var ts; SymbolObject.prototype.getDeclarations = function () { return this.declarations; }; + SymbolObject.prototype.getDocumentationComment = function () { + if (this.documentationComment === undefined) { + this.documentationComment = getJsDocCommentsFromDeclarations(this.declarations, this.name, !(this.flags & 2 /* Property */)); + } + return this.documentationComment; + }; return SymbolObject; })(); + function getJsDocCommentsFromDeclarations(declarations, name, canUseParsedParamTagComments) { + var documentationComment = []; + var docComments = getJsDocCommentsSeparatedByNewLines(); + ts.forEach(docComments, function (docComment) { + if (documentationComment.length) { + documentationComment.push(lineBreakPart()); + } + documentationComment.push(docComment); + }); + return documentationComment; + function getJsDocCommentsSeparatedByNewLines() { + var paramTag = "@param"; + var jsDocCommentParts = []; + ts.forEach(declarations, function (declaration) { + var sourceFileOfDeclaration = ts.getSourceFileOfNode(declaration); + if (canUseParsedParamTagComments && declaration.kind === 118 /* Parameter */) { + ts.forEach(getJsDocCommentTextRange(declaration.parent, sourceFileOfDeclaration), function (jsDocCommentTextRange) { + var cleanedParamJsDocComment = getCleanedParamJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); + if (cleanedParamJsDocComment) { + jsDocCommentParts.push.apply(jsDocCommentParts, cleanedParamJsDocComment); + } + }); + } + if (declaration.kind === 179 /* ModuleDeclaration */ && declaration.body.kind === 179 /* ModuleDeclaration */) { + return; + } + while (declaration.kind === 179 /* ModuleDeclaration */ && declaration.parent.kind === 179 /* ModuleDeclaration */) { + declaration = declaration.parent; + } + ts.forEach(getJsDocCommentTextRange(declaration.kind === 173 /* VariableDeclaration */ ? declaration.parent : declaration, sourceFileOfDeclaration), function (jsDocCommentTextRange) { + var cleanedJsDocComment = getCleanedJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); + if (cleanedJsDocComment) { + jsDocCommentParts.push.apply(jsDocCommentParts, cleanedJsDocComment); + } + }); + }); + return jsDocCommentParts; + function getJsDocCommentTextRange(node, sourceFile) { + return ts.map(ts.getJsDocComments(node, sourceFile), function (jsDocComment) { + return { + pos: jsDocComment.pos + "/*".length, + end: jsDocComment.end - "*/".length + }; + }); + } + function consumeWhiteSpacesOnTheLine(pos, end, sourceFile, maxSpacesToRemove) { + if (maxSpacesToRemove !== undefined) { + end = Math.min(end, pos + maxSpacesToRemove); + } + for (; pos < end; pos++) { + var ch = sourceFile.text.charCodeAt(pos); + if (!ts.isWhiteSpace(ch) || ts.isLineBreak(ch)) { + return pos; + } + } + return end; + } + function consumeLineBreaks(pos, end, sourceFile) { + while (pos < end && ts.isLineBreak(sourceFile.text.charCodeAt(pos))) { + pos++; + } + return pos; + } + function isName(pos, end, sourceFile, name) { + return pos + name.length < end && sourceFile.text.substr(pos, name.length) === name && ts.isWhiteSpace(sourceFile.text.charCodeAt(pos + name.length)); + } + function isParamTag(pos, end, sourceFile) { + return isName(pos, end, sourceFile, paramTag); + } + function getCleanedJsDocComment(pos, end, sourceFile) { + var spacesToRemoveAfterAsterisk; + var docComments = []; + var isInParamTag = false; + while (pos < end) { + var docCommentTextOfLine = ""; + pos = consumeWhiteSpacesOnTheLine(pos, end, sourceFile); + if (pos < end && sourceFile.text.charCodeAt(pos) === 42 /* asterisk */) { + var lineStartPos = pos + 1; + pos = consumeWhiteSpacesOnTheLine(pos + 1, end, sourceFile, spacesToRemoveAfterAsterisk); + if (spacesToRemoveAfterAsterisk === undefined && pos < end && !ts.isLineBreak(sourceFile.text.charCodeAt(pos))) { + spacesToRemoveAfterAsterisk = pos - lineStartPos; + } + } + else if (spacesToRemoveAfterAsterisk === undefined) { + spacesToRemoveAfterAsterisk = 0; + } + while (pos < end && !ts.isLineBreak(sourceFile.text.charCodeAt(pos))) { + var ch = sourceFile.text.charAt(pos); + if (ch === "@") { + if (isParamTag(pos, end, sourceFile)) { + isInParamTag = true; + pos += paramTag.length; + continue; + } + else { + isInParamTag = false; + } + } + if (!isInParamTag) { + docCommentTextOfLine += ch; + } + pos++; + } + pos = consumeLineBreaks(pos, end, sourceFile); + if (docCommentTextOfLine) { + docComments.push(textPart(docCommentTextOfLine)); + } + } + return docComments; + } + function getCleanedParamJsDocComment(pos, end, sourceFile) { + var paramHelpStringMargin; + var paramDocComments = []; + while (pos < end) { + if (isParamTag(pos, end, sourceFile)) { + pos = consumeWhiteSpaces(pos + paramTag.length); + if (pos >= end) { + break; + } + if (sourceFile.text.charCodeAt(pos) === 123 /* openBrace */) { + pos++; + for (var curlies = 1; pos < end; pos++) { + var charCode = sourceFile.text.charCodeAt(pos); + if (charCode === 123 /* openBrace */) { + curlies++; + continue; + } + if (charCode === 125 /* closeBrace */) { + curlies--; + if (curlies === 0) { + pos++; + break; + } + else { + continue; + } + } + if (charCode === 64 /* at */) { + break; + } + } + pos = consumeWhiteSpaces(pos); + if (pos >= end) { + break; + } + } + if (isName(pos, end, sourceFile, name)) { + pos = consumeWhiteSpaces(pos + name.length); + if (pos >= end) { + break; + } + var paramHelpString = ""; + var firstLineParamHelpStringPos = pos; + while (pos < end) { + var ch = sourceFile.text.charCodeAt(pos); + if (ts.isLineBreak(ch)) { + if (paramHelpString) { + paramDocComments.push(textPart(paramHelpString)); + paramHelpString = ""; + } + setPosForParamHelpStringOnNextLine(firstLineParamHelpStringPos); + continue; + } + if (ch === 64 /* at */) { + break; + } + paramHelpString += sourceFile.text.charAt(pos); + pos++; + } + if (paramHelpString) { + paramDocComments.push(textPart(paramHelpString)); + } + paramHelpStringMargin = undefined; + } + if (sourceFile.text.charCodeAt(pos) === 64 /* at */) { + continue; + } + } + pos++; + } + return paramDocComments; + function consumeWhiteSpaces(pos) { + while (pos < end && ts.isWhiteSpace(sourceFile.text.charCodeAt(pos))) { + pos++; + } + return pos; + } + function setPosForParamHelpStringOnNextLine(firstLineParamHelpStringPos) { + pos = consumeLineBreaks(pos, end, sourceFile); + if (pos >= end) { + return; + } + if (paramHelpStringMargin === undefined) { + paramHelpStringMargin = sourceFile.getLineAndCharacterFromPosition(firstLineParamHelpStringPos).character - 1; + } + var startOfLinePos = pos; + pos = consumeWhiteSpacesOnTheLine(pos, end, sourceFile, paramHelpStringMargin); + if (pos >= end) { + return; + } + var consumedSpaces = pos - startOfLinePos; + if (consumedSpaces < paramHelpStringMargin) { + var ch = sourceFile.text.charCodeAt(pos); + if (ch === 42 /* asterisk */) { + pos = consumeWhiteSpacesOnTheLine(pos + 1, end, sourceFile, paramHelpStringMargin - consumedSpaces - 1); + } + } + } + } + } + } var TypeObject = (function () { function TypeObject(checker, flags) { this.checker = checker; @@ -31658,7 +32975,7 @@ var ts; return this.checker.getPropertyOfType(this, propertyName); }; TypeObject.prototype.getApparentProperties = function () { - return this.checker.getAugmentedPropertiesOfApparentType(this); + return this.checker.getAugmentedPropertiesOfType(this); }; TypeObject.prototype.getCallSignatures = function () { return this.checker.getSignaturesOfType(this, 0 /* Call */); @@ -31690,6 +33007,12 @@ var ts; SignatureObject.prototype.getReturnType = function () { return this.checker.getReturnTypeOfSignature(this); }; + SignatureObject.prototype.getDocumentationComment = function () { + if (this.documentationComment === undefined) { + this.documentationComment = this.declaration ? getJsDocCommentsFromDeclarations([this.declaration], this.declaration.name ? this.declaration.name.text : "", false) : []; + } + return this.documentationComment; + }; return SignatureObject; })(); var incrementalParse = TypeScript.IncrementalParser.parse; @@ -31717,41 +33040,51 @@ var ts; if (!this.namedDeclarations) { var sourceFile = this; var namedDeclarations = []; - var isExternalModule = ts.isExternalModule(sourceFile); ts.forEachChild(sourceFile, function visit(node) { switch (node.kind) { - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 176 /* EnumDeclaration */: - case 177 /* ModuleDeclaration */: - case 179 /* ImportDeclaration */: + case 174 /* FunctionDeclaration */: case 120 /* Method */: - case 172 /* FunctionDeclaration */: - case 121 /* Constructor */: + var functionDeclaration = node; + if (functionDeclaration.name && functionDeclaration.name.kind !== 115 /* Missing */) { + var lastDeclaration = namedDeclarations.length > 0 ? namedDeclarations[namedDeclarations.length - 1] : undefined; + if (lastDeclaration && functionDeclaration.symbol === lastDeclaration.symbol) { + if (functionDeclaration.body && !lastDeclaration.body) { + namedDeclarations[namedDeclarations.length - 1] = functionDeclaration; + } + } + else { + namedDeclarations.push(node); + } + ts.forEachChild(node, visit); + } + break; + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: + case 179 /* ModuleDeclaration */: + case 181 /* ImportDeclaration */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: case 129 /* TypeLiteral */: if (node.name) { namedDeclarations.push(node); } - ts.forEachChild(node, visit); - break; - case 149 /* VariableStatement */: - case 178 /* ModuleBlock */: - case 173 /* FunctionBlock */: + case 121 /* Constructor */: + case 151 /* VariableStatement */: + case 180 /* ModuleBlock */: + case 175 /* FunctionBlock */: ts.forEachChild(node, visit); break; case 118 /* Parameter */: if (!(node.flags & ts.NodeFlags.AccessibilityModifier)) { break; } - case 171 /* VariableDeclaration */: - case 181 /* EnumMember */: + case 173 /* VariableDeclaration */: + case 183 /* EnumMember */: case 119 /* Property */: namedDeclarations.push(node); break; } - return undefined; }); this.namedDeclarations = namedDeclarations; } @@ -31795,192 +33128,37 @@ var ts; }; return SourceFileObject; })(NodeObject); - var ClassificationTypeNames = (function () { - function ClassificationTypeNames() { - } - ClassificationTypeNames.comment = "comment"; - ClassificationTypeNames.identifier = "identifier"; - ClassificationTypeNames.keyword = "keyword"; - ClassificationTypeNames.numericLiteral = "number"; - ClassificationTypeNames.operator = "operator"; - ClassificationTypeNames.stringLiteral = "string"; - ClassificationTypeNames.whiteSpace = "whitespace"; - ClassificationTypeNames.text = "text"; - ClassificationTypeNames.punctuation = "punctuation"; - ClassificationTypeNames.className = "class name"; - ClassificationTypeNames.enumName = "enum name"; - ClassificationTypeNames.interfaceName = "interface name"; - ClassificationTypeNames.moduleName = "module name"; - ClassificationTypeNames.typeParameterName = "type parameter name"; - return ClassificationTypeNames; - })(); - ts.ClassificationTypeNames = ClassificationTypeNames; - var ClassifiedSpan = (function () { - function ClassifiedSpan(textSpan, classificationType) { - this.textSpan = textSpan; - this.classificationType = classificationType; - } - return ClassifiedSpan; - })(); - ts.ClassifiedSpan = ClassifiedSpan; - var NavigationBarItem = (function () { - function NavigationBarItem(text, kind, kindModifiers, spans, childItems, indent, bolded, grayed) { - if (childItems === void 0) { childItems = null; } - if (indent === void 0) { indent = 0; } - if (bolded === void 0) { bolded = false; } - if (grayed === void 0) { grayed = false; } - this.text = text; - this.kind = kind; - this.kindModifiers = kindModifiers; - this.spans = spans; - this.childItems = childItems; - this.indent = indent; - this.bolded = bolded; - this.grayed = grayed; - } - return NavigationBarItem; - })(); - ts.NavigationBarItem = NavigationBarItem; - var TodoCommentDescriptor = (function () { - function TodoCommentDescriptor(text, priority) { - this.text = text; - this.priority = priority; - } - return TodoCommentDescriptor; - })(); - ts.TodoCommentDescriptor = TodoCommentDescriptor; - var TodoComment = (function () { - function TodoComment(descriptor, message, position) { - this.descriptor = descriptor; - this.message = message; - this.position = position; - } - return TodoComment; - })(); - ts.TodoComment = TodoComment; var TextChange = (function () { - function TextChange(span, newText) { - this.span = span; - this.newText = newText; + function TextChange() { } - TextChange.createInsert = function (pos, newText) { - return new TextChange(new TypeScript.TextSpan(pos, 0), newText); - }; - TextChange.createDelete = function (start, end) { - return new TextChange(TypeScript.TextSpan.fromBounds(start, end), ""); - }; - TextChange.createReplace = function (start, end, newText) { - return new TextChange(TypeScript.TextSpan.fromBounds(start, end), newText); - }; return TextChange; })(); ts.TextChange = TextChange; - var ReferenceEntry = (function () { - function ReferenceEntry(fileName, textSpan, isWriteAccess) { - this.fileName = ""; - this.isWriteAccess = false; - this.fileName = fileName; - this.textSpan = textSpan; - this.isWriteAccess = isWriteAccess; - } - return ReferenceEntry; - })(); - ts.ReferenceEntry = ReferenceEntry; - var NavigateToItem = (function () { - function NavigateToItem(name, kind, kindModifiers, matchKind, fileName, textSpan, containerName, containerKind) { - this.name = name; - this.kind = kind; - this.kindModifiers = kindModifiers; - this.matchKind = matchKind; - this.fileName = fileName; - this.textSpan = textSpan; - this.containerName = containerName; - this.containerKind = containerKind; - } - return NavigateToItem; - })(); - ts.NavigateToItem = NavigateToItem; - var DefinitionInfo = (function () { - function DefinitionInfo(fileName, textSpan, kind, name, containerKind, containerName) { - this.fileName = fileName; - this.textSpan = textSpan; - this.kind = kind; - this.name = name; - this.containerKind = containerKind; - this.containerName = containerName; - } - return DefinitionInfo; - })(); - ts.DefinitionInfo = DefinitionInfo; - var TypeInfo = (function () { - function TypeInfo(memberName, docComment, fullSymbolName, kind, textSpan) { - this.memberName = memberName; - this.docComment = docComment; - this.fullSymbolName = fullSymbolName; - this.kind = kind; - this.textSpan = textSpan; - } - return TypeInfo; - })(); - ts.TypeInfo = TypeInfo; - var RenameInfo = (function () { - function RenameInfo(canRename, localizedErrorMessage, displayName, fullDisplayName, kind, kindModifiers, triggerSpan) { - this.canRename = canRename; - this.localizedErrorMessage = localizedErrorMessage; - this.displayName = displayName; - this.fullDisplayName = fullDisplayName; - this.kind = kind; - this.kindModifiers = kindModifiers; - this.triggerSpan = triggerSpan; - } - RenameInfo.CreateError = function (localizedErrorMessage) { - return new RenameInfo(false, localizedErrorMessage, null, null, null, null, null); - }; - RenameInfo.Create = function (displayName, fullDisplayName, kind, kindModifiers, triggerSpan) { - return new RenameInfo(true, null, displayName, fullDisplayName, kind, kindModifiers, triggerSpan); - }; - return RenameInfo; - })(); - ts.RenameInfo = RenameInfo; - var SignatureHelpParameter = (function () { - function SignatureHelpParameter(name, documentation, display, isOptional) { - this.name = name; - this.documentation = documentation; - this.display = display; - this.isOptional = isOptional; - } - return SignatureHelpParameter; - })(); - ts.SignatureHelpParameter = SignatureHelpParameter; - var SignatureHelpItem = (function () { - function SignatureHelpItem(isVariadic, prefix, suffix, separator, parameters, documentation) { - this.isVariadic = isVariadic; - this.prefix = prefix; - this.suffix = suffix; - this.separator = separator; - this.parameters = parameters; - this.documentation = documentation; - } - return SignatureHelpItem; - })(); - ts.SignatureHelpItem = SignatureHelpItem; - var SignatureHelpItems = (function () { - function SignatureHelpItems(items, applicableSpan, selectedItemIndex) { - this.items = items; - this.applicableSpan = applicableSpan; - this.selectedItemIndex = selectedItemIndex; - } - return SignatureHelpItems; - })(); - ts.SignatureHelpItems = SignatureHelpItems; - var SignatureHelpState = (function () { - function SignatureHelpState(argumentIndex, argumentCount) { - this.argumentIndex = argumentIndex; - this.argumentCount = argumentCount; - } - return SignatureHelpState; - })(); - ts.SignatureHelpState = SignatureHelpState; + (function (SymbolDisplayPartKind) { + SymbolDisplayPartKind[SymbolDisplayPartKind["aliasName"] = 0] = "aliasName"; + SymbolDisplayPartKind[SymbolDisplayPartKind["className"] = 1] = "className"; + SymbolDisplayPartKind[SymbolDisplayPartKind["enumName"] = 2] = "enumName"; + SymbolDisplayPartKind[SymbolDisplayPartKind["fieldName"] = 3] = "fieldName"; + SymbolDisplayPartKind[SymbolDisplayPartKind["interfaceName"] = 4] = "interfaceName"; + SymbolDisplayPartKind[SymbolDisplayPartKind["keyword"] = 5] = "keyword"; + SymbolDisplayPartKind[SymbolDisplayPartKind["lineBreak"] = 6] = "lineBreak"; + SymbolDisplayPartKind[SymbolDisplayPartKind["numericLiteral"] = 7] = "numericLiteral"; + SymbolDisplayPartKind[SymbolDisplayPartKind["stringLiteral"] = 8] = "stringLiteral"; + SymbolDisplayPartKind[SymbolDisplayPartKind["localName"] = 9] = "localName"; + SymbolDisplayPartKind[SymbolDisplayPartKind["methodName"] = 10] = "methodName"; + SymbolDisplayPartKind[SymbolDisplayPartKind["moduleName"] = 11] = "moduleName"; + SymbolDisplayPartKind[SymbolDisplayPartKind["operator"] = 12] = "operator"; + SymbolDisplayPartKind[SymbolDisplayPartKind["parameterName"] = 13] = "parameterName"; + SymbolDisplayPartKind[SymbolDisplayPartKind["propertyName"] = 14] = "propertyName"; + SymbolDisplayPartKind[SymbolDisplayPartKind["punctuation"] = 15] = "punctuation"; + SymbolDisplayPartKind[SymbolDisplayPartKind["space"] = 16] = "space"; + SymbolDisplayPartKind[SymbolDisplayPartKind["text"] = 17] = "text"; + SymbolDisplayPartKind[SymbolDisplayPartKind["typeParameterName"] = 18] = "typeParameterName"; + SymbolDisplayPartKind[SymbolDisplayPartKind["enumMemberName"] = 19] = "enumMemberName"; + SymbolDisplayPartKind[SymbolDisplayPartKind["functionName"] = 20] = "functionName"; + SymbolDisplayPartKind[SymbolDisplayPartKind["regularExpressionLiteral"] = 21] = "regularExpressionLiteral"; + })(ts.SymbolDisplayPartKind || (ts.SymbolDisplayPartKind = {})); + var SymbolDisplayPartKind = ts.SymbolDisplayPartKind; (function (OutputFileType) { OutputFileType[OutputFileType["JavaScript"] = 0] = "JavaScript"; OutputFileType[OutputFileType["SourceMap"] = 1] = "SourceMap"; @@ -32032,6 +33210,7 @@ var ts; ScriptElementKind.typeParameterElement = "type parameter"; ScriptElementKind.primitiveType = "primitive type"; ScriptElementKind.label = "label"; + ScriptElementKind.alias = "alias"; return ScriptElementKind; })(); ts.ScriptElementKind = ScriptElementKind; @@ -32041,12 +33220,33 @@ var ts; ScriptElementKindModifier.none = ""; ScriptElementKindModifier.publicMemberModifier = "public"; ScriptElementKindModifier.privateMemberModifier = "private"; + ScriptElementKindModifier.protectedMemberModifier = "protected"; ScriptElementKindModifier.exportedModifier = "export"; ScriptElementKindModifier.ambientModifier = "declare"; ScriptElementKindModifier.staticModifier = "static"; return ScriptElementKindModifier; })(); ts.ScriptElementKindModifier = ScriptElementKindModifier; + var ClassificationTypeNames = (function () { + function ClassificationTypeNames() { + } + ClassificationTypeNames.comment = "comment"; + ClassificationTypeNames.identifier = "identifier"; + ClassificationTypeNames.keyword = "keyword"; + ClassificationTypeNames.numericLiteral = "number"; + ClassificationTypeNames.operator = "operator"; + ClassificationTypeNames.stringLiteral = "string"; + ClassificationTypeNames.whiteSpace = "whitespace"; + ClassificationTypeNames.text = "text"; + ClassificationTypeNames.punctuation = "punctuation"; + ClassificationTypeNames.className = "class name"; + ClassificationTypeNames.enumName = "enum name"; + ClassificationTypeNames.interfaceName = "interface name"; + ClassificationTypeNames.moduleName = "module name"; + ClassificationTypeNames.typeParameterName = "type parameter name"; + return ClassificationTypeNames; + })(); + ts.ClassificationTypeNames = ClassificationTypeNames; var MatchKind; (function (MatchKind) { MatchKind[MatchKind["none"] = 0] = "none"; @@ -32054,6 +33254,177 @@ var ts; MatchKind[MatchKind["substring"] = 2] = "substring"; MatchKind[MatchKind["prefix"] = 3] = "prefix"; })(MatchKind || (MatchKind = {})); + function displayPartsToString(displayParts) { + if (displayParts) { + return ts.map(displayParts, function (displayPart) { return displayPart.text; }).join(""); + } + return ""; + } + ts.displayPartsToString = displayPartsToString; + var displayPartWriter = getDisplayPartWriter(); + function getDisplayPartWriter() { + var displayParts; + var lineStart; + var indent; + resetWriter(); + return { + displayParts: function () { return displayParts; }, + writeKeyword: function (text) { return writeKind(text, 5 /* keyword */); }, + writeOperator: function (text) { return writeKind(text, 12 /* operator */); }, + writePunctuation: function (text) { return writeKind(text, 15 /* punctuation */); }, + writeSpace: function (text) { return writeKind(text, 16 /* space */); }, + writeStringLiteral: function (text) { return writeKind(text, 8 /* stringLiteral */); }, + writeParameter: function (text) { return writeKind(text, 13 /* parameterName */); }, + writeSymbol: writeSymbol, + writeLine: writeLine, + increaseIndent: function () { + indent++; + }, + decreaseIndent: function () { + indent--; + }, + clear: resetWriter, + trackSymbol: function () { + } + }; + function writeIndent() { + if (lineStart) { + displayParts.push(displayPart(ts.getIndentString(indent), 16 /* space */)); + lineStart = false; + } + } + function writeKind(text, kind) { + writeIndent(); + displayParts.push(displayPart(text, kind)); + } + function writeSymbol(text, symbol) { + writeIndent(); + displayParts.push(symbolPart(text, symbol)); + } + function writeLine() { + displayParts.push(lineBreakPart()); + lineStart = true; + } + function resetWriter() { + displayParts = []; + lineStart = true; + indent = 0; + } + } + function displayPart(text, kind, symbol) { + return { + text: text, + kind: SymbolDisplayPartKind[kind] + }; + } + function spacePart() { + return displayPart(" ", 16 /* space */); + } + ts.spacePart = spacePart; + function keywordPart(kind) { + return displayPart(ts.tokenToString(kind), 5 /* keyword */); + } + ts.keywordPart = keywordPart; + function punctuationPart(kind) { + return displayPart(ts.tokenToString(kind), 15 /* punctuation */); + } + ts.punctuationPart = punctuationPart; + function operatorPart(kind) { + return displayPart(ts.tokenToString(kind), 12 /* operator */); + } + ts.operatorPart = operatorPart; + function textPart(text) { + return displayPart(text, 17 /* text */); + } + ts.textPart = textPart; + function lineBreakPart() { + return displayPart("\n", 6 /* lineBreak */); + } + ts.lineBreakPart = lineBreakPart; + function isFirstDeclarationOfSymbolParameter(symbol) { + return symbol.declarations && symbol.declarations.length > 0 && symbol.declarations[0].kind === 118 /* Parameter */; + } + function isLocalVariableOrFunction(symbol) { + if (symbol.parent) { + return false; + } + return ts.forEach(symbol.declarations, function (declaration) { + if (declaration.kind === 143 /* FunctionExpression */) { + return true; + } + if (declaration.kind !== 173 /* VariableDeclaration */ && declaration.kind !== 174 /* FunctionDeclaration */) { + return false; + } + for (var parent = declaration.parent; parent.kind !== 175 /* FunctionBlock */; parent = parent.parent) { + if (parent.kind === 184 /* SourceFile */ || parent.kind === 180 /* ModuleBlock */) { + return false; + } + } + return true; + }); + } + function symbolPart(text, symbol) { + return displayPart(text, displayPartKind(symbol), symbol); + function displayPartKind(symbol) { + var flags = symbol.flags; + if (flags & 1 /* Variable */) { + return isFirstDeclarationOfSymbolParameter(symbol) ? 13 /* parameterName */ : 9 /* localName */; + } + else if (flags & 2 /* Property */) { + return 14 /* propertyName */; + } + else if (flags & 4 /* EnumMember */) { + return 19 /* enumMemberName */; + } + else if (flags & 8 /* Function */) { + return 20 /* functionName */; + } + else if (flags & 16 /* Class */) { + return 1 /* className */; + } + else if (flags & 32 /* Interface */) { + return 4 /* interfaceName */; + } + else if (flags & 64 /* Enum */) { + return 2 /* enumName */; + } + else if (flags & ts.SymbolFlags.Module) { + return 11 /* moduleName */; + } + else if (flags & 2048 /* Method */) { + return 10 /* methodName */; + } + else if (flags & 262144 /* TypeParameter */) { + return 18 /* typeParameterName */; + } + return 17 /* text */; + } + } + ts.symbolPart = symbolPart; + function mapToDisplayParts(writeDisplayParts) { + writeDisplayParts(displayPartWriter); + var result = displayPartWriter.displayParts(); + displayPartWriter.clear(); + return result; + } + ts.mapToDisplayParts = mapToDisplayParts; + function typeToDisplayParts(typechecker, type, enclosingDeclaration, flags) { + return mapToDisplayParts(function (writer) { + typechecker.getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); + }); + } + ts.typeToDisplayParts = typeToDisplayParts; + function symbolToDisplayParts(typeChecker, symbol, enclosingDeclaration, meaning, flags) { + return mapToDisplayParts(function (writer) { + typeChecker.getSymbolDisplayBuilder().buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning, flags); + }); + } + ts.symbolToDisplayParts = symbolToDisplayParts; + function signatureToDisplayParts(typechecker, signature, enclosingDeclaration, flags) { + return mapToDisplayParts(function (writer) { + typechecker.getSymbolDisplayBuilder().buildSignatureDisplay(signature, writer, enclosingDeclaration, flags); + }); + } function getDefaultCompilerOptions() { return { target: 1 /* ES5 */, @@ -32096,6 +33467,7 @@ var ts; CancellationTokenObject.None = new CancellationTokenObject(null); return CancellationTokenObject; })(); + ts.CancellationTokenObject = CancellationTokenObject; var HostCache = (function () { function HostCache(host) { this.host = host; @@ -32343,9 +33715,27 @@ var ts; }; } ts.createDocumentRegistry = createDocumentRegistry; + function getNodeModifiers(node) { + var flags = node.flags; + var result = []; + if (flags & 32 /* Private */) + result.push(ScriptElementKindModifier.privateMemberModifier); + if (flags & 64 /* Protected */) + result.push(ScriptElementKindModifier.protectedMemberModifier); + if (flags & 16 /* Public */) + result.push(ScriptElementKindModifier.publicMemberModifier); + if (flags & 128 /* Static */) + result.push(ScriptElementKindModifier.staticModifier); + if (flags & 1 /* Export */) + result.push(ScriptElementKindModifier.exportedModifier); + if (ts.isInAmbientContext(node)) + result.push(ScriptElementKindModifier.ambientModifier); + return result.length > 0 ? result.join(',') : ScriptElementKindModifier.none; + } + ts.getNodeModifiers = getNodeModifiers; function getTargetLabel(referenceNode, labelName) { while (referenceNode) { - if (referenceNode.kind === 164 /* LabeledStatement */ && referenceNode.label.text === labelName) { + if (referenceNode.kind === 166 /* LabeledStatement */ && referenceNode.label.text === labelName) { return referenceNode.label; } referenceNode = referenceNode.parent; @@ -32353,13 +33743,13 @@ var ts; return undefined; } function isJumpStatementTarget(node) { - return node.kind === 59 /* Identifier */ && (node.parent.kind === 158 /* BreakStatement */ || node.parent.kind === 157 /* ContinueStatement */) && node.parent.label === node; + return node.kind === 59 /* Identifier */ && (node.parent.kind === 160 /* BreakStatement */ || node.parent.kind === 159 /* ContinueStatement */) && node.parent.label === node; } function isLabelOfLabeledStatement(node) { - return node.kind === 59 /* Identifier */ && node.parent.kind === 164 /* LabeledStatement */ && node.parent.label === node; + return node.kind === 59 /* Identifier */ && node.parent.kind === 166 /* LabeledStatement */ && node.parent.label === node; } function isLabeledBy(node, labelName) { - for (var owner = node.parent; owner.kind === 164 /* LabeledStatement */; owner = owner.parent) { + for (var owner = node.parent; owner.kind === 166 /* LabeledStatement */; owner = owner.parent) { if (owner.label.text === labelName) { return true; } @@ -32370,48 +33760,49 @@ var ts; return isLabelOfLabeledStatement(node) || isJumpStatementTarget(node); } function isCallExpressionTarget(node) { - if (node.parent.kind === 135 /* PropertyAccess */ && node.parent.right === node) + if (node.parent.kind === 137 /* PropertyAccess */ && node.parent.right === node) node = node.parent; - return node.parent.kind === 137 /* CallExpression */ && node.parent.func === node; + return node.parent.kind === 139 /* CallExpression */ && node.parent.func === node; } function isNewExpressionTarget(node) { - if (node.parent.kind === 135 /* PropertyAccess */ && node.parent.right === node) + if (node.parent.kind === 137 /* PropertyAccess */ && node.parent.right === node) node = node.parent; - return node.parent.kind === 138 /* NewExpression */ && node.parent.func === node; + return node.parent.kind === 140 /* NewExpression */ && node.parent.func === node; } function isNameOfFunctionDeclaration(node) { return node.kind === 59 /* Identifier */ && ts.isAnyFunction(node.parent) && node.parent.name === node; } function isNameOfPropertyAssignment(node) { - return (node.kind === 59 /* Identifier */ || node.kind === 7 /* StringLiteral */ || node.kind === 6 /* NumericLiteral */) && node.parent.kind === 134 /* PropertyAssignment */ && node.parent.name === node; + return (node.kind === 59 /* Identifier */ || node.kind === 7 /* StringLiteral */ || node.kind === 6 /* NumericLiteral */) && node.parent.kind === 136 /* PropertyAssignment */ && node.parent.name === node; } function isLiteralNameOfPropertyDeclarationOrIndexAccess(node) { if (node.kind === 7 /* StringLiteral */ || node.kind === 6 /* NumericLiteral */) { switch (node.parent.kind) { case 119 /* Property */: - case 134 /* PropertyAssignment */: - case 181 /* EnumMember */: + case 136 /* PropertyAssignment */: + case 183 /* EnumMember */: case 120 /* Method */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return node.parent.name === node; - case 136 /* IndexedAccess */: + case 138 /* IndexedAccess */: return node.parent.index === node; } } return false; } function isNameOfExternalModuleImportOrDeclaration(node) { - return node.kind === 7 /* StringLiteral */ && ((node.parent.kind === 177 /* ModuleDeclaration */ && node.parent.name === node) || (node.parent.kind === 179 /* ImportDeclaration */ && node.parent.externalModuleName === node)); + return node.kind === 7 /* StringLiteral */ && ((node.parent.kind === 179 /* ModuleDeclaration */ && node.parent.name === node) || (node.parent.kind === 181 /* ImportDeclaration */ && node.parent.externalModuleName === node)); } - var SearchMeaning; - (function (SearchMeaning) { - SearchMeaning[SearchMeaning["None"] = 0x0] = "None"; - SearchMeaning[SearchMeaning["Value"] = 0x1] = "Value"; - SearchMeaning[SearchMeaning["Type"] = 0x2] = "Type"; - SearchMeaning[SearchMeaning["Namespace"] = 0x4] = "Namespace"; - })(SearchMeaning || (SearchMeaning = {})); + var SemanticMeaning; + (function (SemanticMeaning) { + SemanticMeaning[SemanticMeaning["None"] = 0x0] = "None"; + SemanticMeaning[SemanticMeaning["Value"] = 0x1] = "Value"; + SemanticMeaning[SemanticMeaning["Type"] = 0x2] = "Type"; + SemanticMeaning[SemanticMeaning["Namespace"] = 0x4] = "Namespace"; + SemanticMeaning[SemanticMeaning["All"] = SemanticMeaning.Value | SemanticMeaning.Type | SemanticMeaning.Namespace] = "All"; + })(SemanticMeaning || (SemanticMeaning = {})); var BreakContinueSearchType; (function (BreakContinueSearchType) { BreakContinueSearchType[BreakContinueSearchType["None"] = 0x0] = "None"; @@ -32440,8 +33831,8 @@ var ts; var cancellationToken = new CancellationTokenObject(host.getCancellationToken()); var activeCompletionSession; var writer = undefined; - if (!TypeScript.LocalizedDiagnosticMessages) { - TypeScript.LocalizedDiagnosticMessages = host.getLocalizedDiagnosticMessages(); + if (!ts.localizedDiagnosticMessages) { + ts.localizedDiagnosticMessages = host.getLocalizedDiagnosticMessages(); } function getSourceFile(filename) { return ts.lookUp(sourceFilesByName, filename); @@ -32573,9 +33964,13 @@ var ts; synchronizeHostData(); return program.getGlobalDiagnostics(); } - function getValidCompletionEntryDisplayName(displayName, target) { + function getValidCompletionEntryDisplayName(symbol, target) { + var displayName = symbol.getName(); if (displayName && displayName.length > 0) { var firstCharCode = displayName.charCodeAt(0); + if ((symbol.flags & ts.SymbolFlags.Namespace) && (firstCharCode === 39 /* singleQuote */ || firstCharCode === 34 /* doubleQuote */)) { + return undefined; + } if (displayName && displayName.length >= 2 && firstCharCode === displayName.charCodeAt(displayName.length - 1) && (firstCharCode === 39 /* singleQuote */ || firstCharCode === 34 /* doubleQuote */)) { displayName = displayName.substring(1, displayName.length - 1); } @@ -32589,22 +33984,21 @@ var ts; } return undefined; } - function createCompletionEntry(symbol) { - var displayName = getValidCompletionEntryDisplayName(symbol.getName(), program.getCompilerOptions().target); + function createCompletionEntry(symbol, typeChecker) { + var displayName = getValidCompletionEntryDisplayName(symbol, program.getCompilerOptions().target); if (!displayName) { return undefined; } - var declarations = symbol.getDeclarations(); return { name: displayName, - kind: getSymbolKind(symbol), - kindModifiers: declarations ? getNodeModifiers(declarations[0]) : ScriptElementKindModifier.none + kind: getSymbolKind(symbol, typeChecker), + kindModifiers: getSymbolModifiers(symbol) }; } function getCompletionsAtPosition(filename, position, isMemberCompletion) { function getCompletionEntriesFromSymbols(symbols, session) { ts.forEach(symbols, function (symbol) { - var entry = createCompletionEntry(symbol); + var entry = createCompletionEntry(symbol, session.typeChecker); if (entry && !ts.lookUp(session.symbols, entry.name)) { session.entries.push(entry); session.symbols[entry.name] = symbol; @@ -32698,21 +34092,13 @@ var ts; function isPunctuation(kind) { return (ts.SyntaxKind.FirstPunctuation <= kind && kind <= ts.SyntaxKind.LastPunctuation); } - function isVisibleWithinClassDeclaration(symbol, containingClass) { - var declaration = symbol.declarations && symbol.declarations[0]; - if (declaration && (declaration.flags & 32 /* Private */)) { - var declarationClass = ts.getAncestor(declaration, 174 /* ClassDeclaration */); - return containingClass === declarationClass; - } - return true; - } function filterContextualMembersList(contextualMemberSymbols, existingMembers) { if (!existingMembers || existingMembers.length === 0) { return contextualMemberSymbols; } var existingMemberNames = {}; ts.forEach(existingMembers, function (m) { - if (m.kind !== 134 /* PropertyAssignment */) { + if (m.kind !== 136 /* PropertyAssignment */) { return; } if (m.getStart() <= position && position <= m.getEnd()) { @@ -32757,9 +34143,16 @@ var ts; isRightOfDot = true; node = node.parent.left; } - var mappedNode = getNodeAtPosition(sourceFile, TypeScript.end(node) - 1); - if (isPunctuation(mappedNode.kind)) { - mappedNode = mappedNode.parent; + var precedingToken = ts.findTokenOnLeftOfPosition(sourceFile, TypeScript.end(node)); + var mappedNode; + if (!precedingToken) { + mappedNode = sourceFile; + } + else if (isPunctuation(precedingToken.kind)) { + mappedNode = precedingToken.parent; + } + else { + mappedNode = precedingToken; } ts.Debug.assert(mappedNode, "Could not map a Fidelity node to an AST node"); activeCompletionSession = { @@ -32772,23 +34165,24 @@ var ts; }; if (isRightOfDot) { var symbols = []; - var containingClass = ts.getAncestor(mappedNode, 174 /* ClassDeclaration */); isMemberCompletion = true; - if (mappedNode.kind === 59 /* Identifier */ || mappedNode.kind === 116 /* QualifiedName */ || mappedNode.kind === 135 /* PropertyAccess */) { + if (mappedNode.kind === 59 /* Identifier */ || mappedNode.kind === 116 /* QualifiedName */ || mappedNode.kind === 137 /* PropertyAccess */) { var symbol = typeInfoResolver.getSymbolInfo(mappedNode); + if (symbol && symbol.flags & 4194304 /* Import */) { + symbol = typeInfoResolver.getAliasedSymbol(symbol); + } if (symbol && symbol.flags & ts.SymbolFlags.HasExports) { ts.forEachValue(symbol.exports, function (symbol) { - if (isVisibleWithinClassDeclaration(symbol, containingClass)) { + if (typeInfoResolver.isValidPropertyAccess((mappedNode.parent), symbol.name)) { symbols.push(symbol); } }); } } var type = typeInfoResolver.getTypeOfNode(mappedNode); - var apparentType = type && typeInfoResolver.getApparentType(type); - if (apparentType) { - ts.forEach(apparentType.getApparentProperties(), function (symbol) { - if (isVisibleWithinClassDeclaration(symbol, containingClass)) { + if (type) { + ts.forEach(type.getApparentProperties(), function (symbol) { + if (typeInfoResolver.isValidPropertyAccess((mappedNode.parent), symbol.name)) { symbols.push(symbol); } }); @@ -32798,7 +34192,7 @@ var ts; else { var containingObjectLiteral = getContainingObjectLiteralApplicableForCompletion(sourceFile.getSyntaxTree().sourceUnit(), position); if (containingObjectLiteral) { - var objectLiteral = (mappedNode.kind === 133 /* ObjectLiteral */ ? mappedNode : ts.getAncestor(mappedNode, 133 /* ObjectLiteral */)); + var objectLiteral = (mappedNode.kind === 135 /* ObjectLiteral */ ? mappedNode : ts.getAncestor(mappedNode, 135 /* ObjectLiteral */)); ts.Debug.assert(objectLiteral); isMemberCompletion = true; var contextualType = typeInfoResolver.getContextualType(objectLiteral); @@ -32813,7 +34207,7 @@ var ts; } else { isMemberCompletion = false; - var symbolMeanings = ts.SymbolFlags.Type | ts.SymbolFlags.Value | ts.SymbolFlags.Namespace; + var symbolMeanings = ts.SymbolFlags.Type | ts.SymbolFlags.Value | ts.SymbolFlags.Namespace | 4194304 /* Import */; var symbols = typeInfoResolver.getSymbolsInScope(mappedNode, symbolMeanings); getCompletionEntriesFromSymbols(symbols, activeCompletionSession); } @@ -32836,14 +34230,14 @@ var ts; if (symbol) { var type = session.typeChecker.getTypeOfSymbol(symbol); ts.Debug.assert(type, "Could not find type for symbol"); - var completionEntry = createCompletionEntry(symbol); + var completionEntry = createCompletionEntry(symbol, session.typeChecker); + var displayPartsDocumentationsAndSymbolKind = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, getSourceFile(filename), session.location, session.typeChecker, session.location, SemanticMeaning.All); return { name: entryName, - kind: completionEntry.kind, + kind: displayPartsDocumentationsAndSymbolKind.symbolKind, kindModifiers: completionEntry.kindModifiers, - type: session.typeChecker.typeToString(type, session.location), - fullSymbolName: typeInfoResolver.symbolToString(symbol, session.location), - docComment: "" + displayParts: displayPartsDocumentationsAndSymbolKind.displayParts, + documentation: displayPartsDocumentationsAndSymbolKind.documentation }; } else { @@ -32851,38 +34245,11 @@ var ts; name: entryName, kind: ScriptElementKind.keyword, kindModifiers: ScriptElementKindModifier.none, - type: undefined, - fullSymbolName: entryName, - docComment: undefined + displayParts: [displayPart(entryName, 5 /* keyword */)], + documentation: undefined }; } } - function getNodeAtPosition(sourceFile, position) { - var current = sourceFile; - outer: while (true) { - for (var i = 0, n = current.getChildCount(); i < n; i++) { - var child = current.getChildAt(i); - if (child.getStart() <= position && position < child.getEnd()) { - current = child; - continue outer; - } - } - return current; - } - } - function getTokenAtPosition(sourceFile, position) { - var current = sourceFile; - outer: while (true) { - for (var i = 0, n = current.getChildCount(); i < n; i++) { - var child = current.getChildAt(i); - if (child.getFullStart() <= position && position < child.getEnd()) { - current = child; - continue outer; - } - } - return current; - } - } function getContainerNode(node) { while (true) { node = node.parent; @@ -32890,54 +34257,80 @@ var ts; return node; } switch (node.kind) { - case 182 /* SourceFile */: + case 184 /* SourceFile */: case 120 /* Method */: - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: case 122 /* GetAccessor */: case 123 /* SetAccessor */: - case 174 /* ClassDeclaration */: - case 175 /* InterfaceDeclaration */: - case 176 /* EnumDeclaration */: - case 177 /* ModuleDeclaration */: + case 176 /* ClassDeclaration */: + case 177 /* InterfaceDeclaration */: + case 178 /* EnumDeclaration */: + case 179 /* ModuleDeclaration */: return node; } } } - function getSymbolKind(symbol) { - var flags = typeInfoResolver.getRootSymbol(symbol).getFlags(); - if (flags & ts.SymbolFlags.Module) - return ScriptElementKind.moduleElement; + function getSymbolKind(symbol, typeResolver) { + var flags = symbol.getFlags(); if (flags & 16 /* Class */) return ScriptElementKind.classElement; - if (flags & 32 /* Interface */) - return ScriptElementKind.interfaceElement; if (flags & 64 /* Enum */) return ScriptElementKind.enumElement; - if (flags & 1 /* Variable */) + if (flags & 32 /* Interface */) + return ScriptElementKind.interfaceElement; + if (flags & 262144 /* TypeParameter */) + return ScriptElementKind.typeParameterElement; + var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, flags, typeResolver); + if (result === ScriptElementKind.unknown) { + if (flags & 262144 /* TypeParameter */) + return ScriptElementKind.typeParameterElement; + if (flags & 4 /* EnumMember */) + return ScriptElementKind.variableElement; + if (flags & 4194304 /* Import */) + return ScriptElementKind.alias; + } + return result; + } + function getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, flags, typeResolver) { + if (typeResolver.isUndefinedSymbol(symbol)) { return ScriptElementKind.variableElement; + } + if (typeResolver.isArgumentsSymbol(symbol)) { + return ScriptElementKind.localVariableElement; + } + if (flags & 1 /* Variable */) { + if (isFirstDeclarationOfSymbolParameter(symbol)) { + return ScriptElementKind.parameterElement; + } + return isLocalVariableOrFunction(symbol) ? ScriptElementKind.localVariableElement : ScriptElementKind.variableElement; + } if (flags & 8 /* Function */) - return ScriptElementKind.functionElement; + return isLocalVariableOrFunction(symbol) ? ScriptElementKind.localFunctionElement : ScriptElementKind.functionElement; if (flags & 8192 /* GetAccessor */) return ScriptElementKind.memberGetAccessorElement; if (flags & 16384 /* SetAccessor */) return ScriptElementKind.memberSetAccessorElement; if (flags & 2048 /* Method */) return ScriptElementKind.memberFunctionElement; - if (flags & 2 /* Property */) - return ScriptElementKind.memberVariableElement; - if (flags & 131072 /* IndexSignature */) - return ScriptElementKind.indexSignatureElement; - if (flags & 65536 /* ConstructSignature */) - return ScriptElementKind.constructSignatureElement; - if (flags & 32768 /* CallSignature */) - return ScriptElementKind.callSignatureElement; if (flags & 4096 /* Constructor */) return ScriptElementKind.constructorImplementationElement; - if (flags & 262144 /* TypeParameter */) - return ScriptElementKind.typeParameterElement; - if (flags & 4 /* EnumMember */) - return ScriptElementKind.variableElement; + if (flags & 2 /* Property */) { + if (flags & 134217728 /* UnionProperty */) { + return ts.forEach(typeInfoResolver.getRootSymbols(symbol), function (rootSymbol) { + var rootSymbolFlags = rootSymbol.getFlags(); + if (rootSymbolFlags & 2 /* Property */) { + return ScriptElementKind.memberVariableElement; + } + if (rootSymbolFlags & 8192 /* GetAccessor */) + return ScriptElementKind.memberVariableElement; + if (rootSymbolFlags & 16384 /* SetAccessor */) + return ScriptElementKind.memberVariableElement; + ts.Debug.assert(rootSymbolFlags & 2048 /* Method */); + }) || ScriptElementKind.memberFunctionElement; + } + return ScriptElementKind.memberVariableElement; + } return ScriptElementKind.unknown; } function getTypeKind(type) { @@ -32958,17 +34351,17 @@ var ts; } function getNodeKind(node) { switch (node.kind) { - case 177 /* ModuleDeclaration */: + case 179 /* ModuleDeclaration */: return ScriptElementKind.moduleElement; - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: return ScriptElementKind.classElement; - case 175 /* InterfaceDeclaration */: + case 177 /* InterfaceDeclaration */: return ScriptElementKind.interfaceElement; - case 176 /* EnumDeclaration */: + case 178 /* EnumDeclaration */: return ScriptElementKind.enumElement; - case 171 /* VariableDeclaration */: + case 173 /* VariableDeclaration */: return ScriptElementKind.variableElement; - case 172 /* FunctionDeclaration */: + case 174 /* FunctionDeclaration */: return ScriptElementKind.functionElement; case 122 /* GetAccessor */: return ScriptElementKind.memberGetAccessorElement; @@ -32988,52 +34381,322 @@ var ts; return ScriptElementKind.constructorImplementationElement; case 117 /* TypeParameter */: return ScriptElementKind.typeParameterElement; - case 181 /* EnumMember */: + case 183 /* EnumMember */: return ScriptElementKind.variableElement; case 118 /* Parameter */: return (node.flags & ts.NodeFlags.AccessibilityModifier) ? ScriptElementKind.memberVariableElement : ScriptElementKind.parameterElement; return ScriptElementKind.unknown; } } - function getNodeModifiers(node) { - var flags = node.flags; - var result = []; - if (flags & 32 /* Private */) - result.push(ScriptElementKindModifier.privateMemberModifier); - if (flags & 16 /* Public */) - result.push(ScriptElementKindModifier.publicMemberModifier); - if (flags & 128 /* Static */) - result.push(ScriptElementKindModifier.staticModifier); - if (flags & 1 /* Export */) - result.push(ScriptElementKindModifier.exportedModifier); - if (ts.isInAmbientContext(node)) - result.push(ScriptElementKindModifier.ambientModifier); - return result.length > 0 ? result.join(',') : ScriptElementKindModifier.none; + function getSymbolModifiers(symbol) { + return symbol && symbol.declarations && symbol.declarations.length > 0 ? getNodeModifiers(symbol.declarations[0]) : ScriptElementKindModifier.none; } - function getTypeAtPosition(fileName, position) { + function getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, sourceFile, enclosingDeclaration, typeResolver, location, semanticMeaning) { + if (semanticMeaning === void 0) { semanticMeaning = getMeaningFromLocation(location); } + var displayParts = []; + var documentation; + var symbolFlags = symbol.flags; + var symbolKind = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, symbolFlags, typeResolver); + var hasAddedSymbolInfo; + if (symbolKind !== ScriptElementKind.unknown || symbolFlags & 16 /* Class */ || symbolFlags & 4194304 /* Import */) { + if (symbolKind === ScriptElementKind.memberGetAccessorElement || symbolKind === ScriptElementKind.memberSetAccessorElement) { + symbolKind = ScriptElementKind.memberVariableElement; + } + var type = typeResolver.getTypeOfSymbol(symbol); + if (type) { + if (isCallExpressionTarget(location) || isNewExpressionTarget(location)) { + var callExpression; + if (location.parent.kind === 137 /* PropertyAccess */ && location.parent.right === location) { + location = location.parent; + } + callExpression = location.parent; + var candidateSignatures = []; + signature = typeResolver.getResolvedSignature(callExpression, candidateSignatures); + if (!signature && candidateSignatures.length) { + signature = candidateSignatures[0]; + } + var useConstructSignatures = callExpression.kind === 140 /* NewExpression */ || callExpression.func.kind === 85 /* SuperKeyword */; + var allSignatures = useConstructSignatures ? type.getConstructSignatures() : type.getCallSignatures(); + if (!ts.contains(allSignatures, signature.target || signature)) { + signature = allSignatures.length ? allSignatures[0] : undefined; + } + if (signature) { + if (useConstructSignatures && (symbolFlags & 16 /* Class */)) { + symbolKind = ScriptElementKind.constructorImplementationElement; + addPrefixForAnyFunctionOrVar(type.symbol, symbolKind); + } + else if (symbolFlags & 4194304 /* Import */) { + symbolKind = ScriptElementKind.alias; + displayParts.push(punctuationPart(11 /* OpenParenToken */)); + displayParts.push(textPart(symbolKind)); + displayParts.push(punctuationPart(12 /* CloseParenToken */)); + displayParts.push(spacePart()); + if (useConstructSignatures) { + displayParts.push(keywordPart(82 /* NewKeyword */)); + displayParts.push(spacePart()); + } + addFullSymbolName(symbol); + } + else { + addPrefixForAnyFunctionOrVar(symbol, symbolKind); + } + switch (symbolKind) { + case ScriptElementKind.memberVariableElement: + case ScriptElementKind.variableElement: + case ScriptElementKind.parameterElement: + case ScriptElementKind.localVariableElement: + displayParts.push(punctuationPart(46 /* ColonToken */)); + displayParts.push(spacePart()); + if (useConstructSignatures) { + displayParts.push(keywordPart(82 /* NewKeyword */)); + displayParts.push(spacePart()); + } + if (!(type.flags & 32768 /* Anonymous */)) { + displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, type.symbol, enclosingDeclaration, undefined, 1 /* WriteTypeParametersOrArguments */)); + } + addSignatureDisplayParts(signature, allSignatures, 8 /* WriteArrowStyleSignature */); + break; + default: + addSignatureDisplayParts(signature, allSignatures); + } + hasAddedSymbolInfo = true; + } + } + else if ((isNameOfFunctionDeclaration(location) && !(symbol.flags & ts.SymbolFlags.Accessor)) || (location.kind === 107 /* ConstructorKeyword */ && location.parent.kind === 121 /* Constructor */)) { + var signature; + var functionDeclaration = location.parent; + var allSignatures = functionDeclaration.kind === 121 /* Constructor */ ? type.getConstructSignatures() : type.getCallSignatures(); + if (!typeResolver.isImplementationOfOverload(functionDeclaration)) { + signature = typeResolver.getSignatureFromDeclaration(functionDeclaration); + } + else { + signature = allSignatures[0]; + } + if (functionDeclaration.kind === 121 /* Constructor */) { + addPrefixForAnyFunctionOrVar(type.symbol, ScriptElementKind.constructorImplementationElement); + } + else { + addPrefixForAnyFunctionOrVar(functionDeclaration.kind === 124 /* CallSignature */ && !(type.symbol.flags & 512 /* TypeLiteral */ || type.symbol.flags & 1024 /* ObjectLiteral */) ? type.symbol : symbol, symbolKind); + } + addSignatureDisplayParts(signature, allSignatures); + hasAddedSymbolInfo = true; + } + } + } + if (symbolFlags & 16 /* Class */ && !hasAddedSymbolInfo) { + displayParts.push(keywordPart(63 /* ClassKeyword */)); + displayParts.push(spacePart()); + addFullSymbolName(symbol); + writeTypeParametersOfSymbol(symbol, sourceFile); + } + if ((symbolFlags & 32 /* Interface */) && (semanticMeaning & 2 /* Type */)) { + addNewLineIfDisplayPartsExist(); + displayParts.push(keywordPart(97 /* InterfaceKeyword */)); + displayParts.push(spacePart()); + addFullSymbolName(symbol); + writeTypeParametersOfSymbol(symbol, sourceFile); + } + if (symbolFlags & 64 /* Enum */) { + addNewLineIfDisplayPartsExist(); + displayParts.push(keywordPart(71 /* EnumKeyword */)); + displayParts.push(spacePart()); + addFullSymbolName(symbol); + } + if (symbolFlags & ts.SymbolFlags.Module) { + addNewLineIfDisplayPartsExist(); + displayParts.push(keywordPart(110 /* ModuleKeyword */)); + displayParts.push(spacePart()); + addFullSymbolName(symbol); + } + if ((symbolFlags & 262144 /* TypeParameter */) && (semanticMeaning & 2 /* Type */)) { + addNewLineIfDisplayPartsExist(); + displayParts.push(punctuationPart(11 /* OpenParenToken */)); + displayParts.push(textPart("type parameter")); + displayParts.push(punctuationPart(12 /* CloseParenToken */)); + displayParts.push(spacePart()); + addFullSymbolName(symbol); + displayParts.push(spacePart()); + displayParts.push(keywordPart(80 /* InKeyword */)); + displayParts.push(spacePart()); + if (symbol.parent) { + addFullSymbolName(symbol.parent, enclosingDeclaration); + writeTypeParametersOfSymbol(symbol.parent, enclosingDeclaration); + } + else { + var signatureDeclaration = ts.getDeclarationOfKind(symbol, 117 /* TypeParameter */).parent; + var signature = typeResolver.getSignatureFromDeclaration(signatureDeclaration); + if (signatureDeclaration.kind === 125 /* ConstructSignature */) { + displayParts.push(keywordPart(82 /* NewKeyword */)); + displayParts.push(spacePart()); + } + else if (signatureDeclaration.kind !== 124 /* CallSignature */ && signatureDeclaration.name) { + addFullSymbolName(signatureDeclaration.symbol); + } + displayParts.push.apply(displayParts, signatureToDisplayParts(typeResolver, signature, sourceFile, 32 /* WriteTypeArgumentsOfSignature */)); + } + } + if (symbolFlags & 4 /* EnumMember */) { + addPrefixForAnyFunctionOrVar(symbol, "enum member"); + var declaration = symbol.declarations[0]; + if (declaration.kind === 183 /* EnumMember */) { + var constantValue = typeResolver.getEnumMemberValue(declaration); + if (constantValue !== undefined) { + displayParts.push(spacePart()); + displayParts.push(operatorPart(47 /* EqualsToken */)); + displayParts.push(spacePart()); + displayParts.push(displayPart(constantValue.toString(), 7 /* numericLiteral */)); + } + } + } + if (symbolFlags & 4194304 /* Import */) { + addNewLineIfDisplayPartsExist(); + displayParts.push(keywordPart(79 /* ImportKeyword */)); + displayParts.push(spacePart()); + addFullSymbolName(symbol); + displayParts.push(spacePart()); + displayParts.push(punctuationPart(47 /* EqualsToken */)); + displayParts.push(spacePart()); + ts.forEach(symbol.declarations, function (declaration) { + if (declaration.kind === 181 /* ImportDeclaration */) { + var importDeclaration = declaration; + if (importDeclaration.externalModuleName) { + displayParts.push(keywordPart(111 /* RequireKeyword */)); + displayParts.push(punctuationPart(11 /* OpenParenToken */)); + displayParts.push(displayPart(ts.getTextOfNode(importDeclaration.externalModuleName), 8 /* stringLiteral */)); + displayParts.push(punctuationPart(12 /* CloseParenToken */)); + } + else { + var internalAliasSymbol = typeResolver.getSymbolInfo(importDeclaration.entityName); + addFullSymbolName(internalAliasSymbol, enclosingDeclaration); + } + return true; + } + }); + } + if (!hasAddedSymbolInfo) { + if (symbolKind !== ScriptElementKind.unknown) { + if (type) { + addPrefixForAnyFunctionOrVar(symbol, symbolKind); + if (symbolKind === ScriptElementKind.memberVariableElement || symbolFlags & 1 /* Variable */ || symbolKind === ScriptElementKind.localVariableElement) { + displayParts.push(punctuationPart(46 /* ColonToken */)); + displayParts.push(spacePart()); + if (type.symbol && type.symbol.flags & 262144 /* TypeParameter */) { + var typeParameterParts = mapToDisplayParts(function (writer) { + typeResolver.getSymbolDisplayBuilder().buildTypeParameterDisplay(type, writer, enclosingDeclaration); + }); + displayParts.push.apply(displayParts, typeParameterParts); + } + else { + displayParts.push.apply(displayParts, typeToDisplayParts(typeResolver, type, enclosingDeclaration)); + } + } + else if (symbolFlags & 8 /* Function */ || symbolFlags & 2048 /* Method */ || symbolFlags & 4096 /* Constructor */ || symbolFlags & ts.SymbolFlags.Signature || symbolFlags & ts.SymbolFlags.Accessor || symbolKind === ScriptElementKind.memberFunctionElement) { + var allSignatures = type.getCallSignatures(); + addSignatureDisplayParts(allSignatures[0], allSignatures); + } + } + } + else { + symbolKind = getSymbolKind(symbol, typeResolver); + } + } + if (!documentation) { + documentation = symbol.getDocumentationComment(); + } + return { displayParts: displayParts, documentation: documentation, symbolKind: symbolKind }; + function addNewLineIfDisplayPartsExist() { + if (displayParts.length) { + displayParts.push(lineBreakPart()); + } + } + function addFullSymbolName(symbol, enclosingDeclaration) { + var fullSymbolDisplayParts = symbolToDisplayParts(typeResolver, symbol, enclosingDeclaration || sourceFile, undefined, 1 /* WriteTypeParametersOrArguments */ | 2 /* UseOnlyExternalAliasing */); + displayParts.push.apply(displayParts, fullSymbolDisplayParts); + } + function addPrefixForAnyFunctionOrVar(symbol, symbolKind) { + addNewLineIfDisplayPartsExist(); + if (symbolKind) { + displayParts.push(punctuationPart(11 /* OpenParenToken */)); + displayParts.push(textPart(symbolKind)); + displayParts.push(punctuationPart(12 /* CloseParenToken */)); + displayParts.push(spacePart()); + addFullSymbolName(symbol); + } + } + function addSignatureDisplayParts(signature, allSignatures, flags) { + displayParts.push.apply(displayParts, signatureToDisplayParts(typeResolver, signature, enclosingDeclaration, flags | 32 /* WriteTypeArgumentsOfSignature */)); + if (allSignatures.length > 1) { + displayParts.push(spacePart()); + displayParts.push(punctuationPart(11 /* OpenParenToken */)); + displayParts.push(operatorPart(28 /* PlusToken */)); + displayParts.push(displayPart((allSignatures.length - 1).toString(), 7 /* numericLiteral */)); + displayParts.push(spacePart()); + displayParts.push(textPart(allSignatures.length === 2 ? "overload" : "overloads")); + displayParts.push(punctuationPart(12 /* CloseParenToken */)); + } + documentation = signature.getDocumentationComment(); + } + function writeTypeParametersOfSymbol(symbol, enclosingDeclaration) { + var typeParameterParts = mapToDisplayParts(function (writer) { + typeResolver.getSymbolDisplayBuilder().buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaration); + }); + displayParts.push.apply(displayParts, typeParameterParts); + } + } + function getQuickInfoAtPosition(fileName, position) { synchronizeHostData(); fileName = TypeScript.switchToForwardSlashes(fileName); var sourceFile = getSourceFile(fileName); - var node = getNodeAtPosition(sourceFile, position); + var node = ts.getTouchingPropertyName(sourceFile, position); if (!node) { return undefined; } var symbol = typeInfoResolver.getSymbolInfo(node); - var type = symbol && typeInfoResolver.getTypeOfSymbol(symbol); - if (type) { - return new TypeInfo(new TypeScript.MemberNameString(typeInfoResolver.typeToString(type)), "", typeInfoResolver.symbolToString(symbol, getContainerNode(node)), getSymbolKind(symbol), TypeScript.TextSpan.fromBounds(node.pos, node.end)); + if (!symbol) { + switch (node.kind) { + case 59 /* Identifier */: + case 137 /* PropertyAccess */: + case 116 /* QualifiedName */: + case 87 /* ThisKeyword */: + case 85 /* SuperKeyword */: + var type = typeInfoResolver.getTypeOfNode(node); + if (type) { + return { + kind: ScriptElementKind.unknown, + kindModifiers: ScriptElementKindModifier.none, + textSpan: new TypeScript.TextSpan(node.getStart(), node.getWidth()), + displayParts: typeToDisplayParts(typeInfoResolver, type, getContainerNode(node)), + documentation: type.symbol ? type.symbol.getDocumentationComment() : undefined + }; + } + } + return undefined; } - return undefined; + var displayPartsDocumentationsAndKind = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, sourceFile, getContainerNode(node), typeInfoResolver, node); + return { + kind: displayPartsDocumentationsAndKind.symbolKind, + kindModifiers: getSymbolModifiers(symbol), + textSpan: new TypeScript.TextSpan(node.getStart(), node.getWidth()), + displayParts: displayPartsDocumentationsAndKind.displayParts, + documentation: displayPartsDocumentationsAndKind.documentation + }; } function getDefinitionAtPosition(filename, position) { function getDefinitionInfo(node, symbolKind, symbolName, containerName) { - return new DefinitionInfo(node.getSourceFile().filename, TypeScript.TextSpan.fromBounds(node.getStart(), node.getEnd()), symbolKind, symbolName, undefined, containerName); + return { + fileName: node.getSourceFile().filename, + textSpan: TypeScript.TextSpan.fromBounds(node.getStart(), node.getEnd()), + kind: symbolKind, + name: symbolName, + containerKind: undefined, + containerName: containerName + }; } function tryAddSignature(signatureDeclarations, selectConstructors, symbolKind, symbolName, containerName, result) { var declarations = []; var definition; ts.forEach(signatureDeclarations, function (d) { - if ((selectConstructors && d.kind === 121 /* Constructor */) || (!selectConstructors && (d.kind === 172 /* FunctionDeclaration */ || d.kind === 120 /* Method */))) { + if ((selectConstructors && d.kind === 121 /* Constructor */) || (!selectConstructors && (d.kind === 174 /* FunctionDeclaration */ || d.kind === 120 /* Method */))) { declarations.push(d); if (d.body) definition = d; @@ -33053,7 +34716,7 @@ var ts; if (isNewExpressionTarget(location) || location.kind === 107 /* ConstructorKeyword */) { if (symbol.flags & 16 /* Class */) { var classDeclaration = symbol.getDeclarations()[0]; - ts.Debug.assert(classDeclaration && classDeclaration.kind === 174 /* ClassDeclaration */); + ts.Debug.assert(classDeclaration && classDeclaration.kind === 176 /* ClassDeclaration */); return tryAddSignature(classDeclaration.members, true, symbolKind, symbolName, containerName, result); } } @@ -33068,7 +34731,7 @@ var ts; synchronizeHostData(); filename = TypeScript.switchToForwardSlashes(filename); var sourceFile = getSourceFile(filename); - var node = getNodeAtPosition(sourceFile, position); + var node = ts.getTouchingPropertyName(sourceFile, position); if (!node) { return undefined; } @@ -33079,23 +34742,30 @@ var ts; } var comment = ts.forEach(sourceFile.referencedFiles, function (r) { return (r.pos <= position && position < r.end) ? r : undefined; }); if (comment) { - var targetFilename = ts.normalizePath(ts.combinePaths(ts.getDirectoryPath(filename), comment.filename)); + var targetFilename = ts.isRootedDiskPath(comment.filename) ? comment.filename : ts.combinePaths(ts.getDirectoryPath(filename), comment.filename); + targetFilename = ts.normalizePath(targetFilename); if (program.getSourceFile(targetFilename)) { - return [new DefinitionInfo(targetFilename, TypeScript.TextSpan.fromBounds(0, 0), ScriptElementKind.scriptElement, comment.filename, undefined, undefined)]; + return [{ + fileName: targetFilename, + textSpan: TypeScript.TextSpan.fromBounds(0, 0), + kind: ScriptElementKind.scriptElement, + name: comment.filename, + containerName: undefined, + containerKind: undefined + }]; } return undefined; } var symbol = typeInfoResolver.getSymbolInfo(node); - if (!symbol || !(symbol.getDeclarations())) { + if (!symbol) { return undefined; } var result = []; var declarations = symbol.getDeclarations(); - var symbolName = typeInfoResolver.symbolToString(symbol, node); - var symbolKind = getSymbolKind(symbol); + var symbolName = typeInfoResolver.symbolToString(symbol); + var symbolKind = getSymbolKind(symbol, typeInfoResolver); var containerSymbol = symbol.parent; var containerName = containerSymbol ? typeInfoResolver.symbolToString(containerSymbol, node) : ""; - var containerKind = containerSymbol ? getSymbolKind(symbol) : ""; if (!tryAddConstructSignature(symbol, node, symbolKind, symbolName, containerName, result) && !tryAddCallSignature(symbol, node, symbolKind, symbolName, containerName, result)) { ts.forEach(declarations, function (declaration) { result.push(getDefinitionInfo(declaration, symbolKind, symbolName, containerName)); @@ -33107,57 +34777,62 @@ var ts; synchronizeHostData(); filename = TypeScript.switchToForwardSlashes(filename); var sourceFile = getSourceFile(filename); - var node = getNodeAtPosition(sourceFile, position); + var node = ts.getTouchingWord(sourceFile, position); if (!node) { return undefined; } if (node.kind === 59 /* Identifier */ || node.kind === 87 /* ThisKeyword */ || node.kind === 85 /* SuperKeyword */ || isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || isNameOfExternalModuleImportOrDeclaration(node)) { - return getReferencesForNode(node, [sourceFile]); + return getReferencesForNode(node, [sourceFile], false, false); } switch (node.kind) { case 78 /* IfKeyword */: case 70 /* ElseKeyword */: - if (hasKind(node.parent, 152 /* IfStatement */)) { + if (hasKind(node.parent, 154 /* IfStatement */)) { return getIfElseOccurrences(node.parent); } break; case 84 /* ReturnKeyword */: - if (hasKind(node.parent, 159 /* ReturnStatement */)) { + if (hasKind(node.parent, 161 /* ReturnStatement */)) { return getReturnOccurrences(node.parent); } break; + case 88 /* ThrowKeyword */: + if (hasKind(node.parent, 167 /* ThrowStatement */)) { + return getThrowOccurrences(node.parent); + } + break; case 90 /* TryKeyword */: case 62 /* CatchKeyword */: case 75 /* FinallyKeyword */: - if (hasKind(parent(parent(node)), 166 /* TryStatement */)) { + if (hasKind(parent(parent(node)), 168 /* TryStatement */)) { return getTryCatchFinallyOccurrences(node.parent.parent); } break; case 86 /* SwitchKeyword */: - if (hasKind(node.parent, 161 /* SwitchStatement */)) { + if (hasKind(node.parent, 163 /* SwitchStatement */)) { return getSwitchCaseDefaultOccurrences(node.parent); } break; case 61 /* CaseKeyword */: case 67 /* DefaultKeyword */: - if (hasKind(parent(parent(node)), 161 /* SwitchStatement */)) { + if (hasKind(parent(parent(node)), 163 /* SwitchStatement */)) { return getSwitchCaseDefaultOccurrences(node.parent.parent); } break; case 60 /* BreakKeyword */: case 65 /* ContinueKeyword */: - if (hasKind(node.parent, 158 /* BreakStatement */) || hasKind(node.parent, 157 /* ContinueStatement */)) { + if (hasKind(node.parent, 160 /* BreakStatement */) || hasKind(node.parent, 159 /* ContinueStatement */)) { return getBreakOrContinueStatementOccurences(node.parent); } break; case 76 /* ForKeyword */: - if (hasKind(node.parent, 155 /* ForStatement */) || hasKind(node.parent, 156 /* ForInStatement */)) { + if (hasKind(node.parent, 157 /* ForStatement */) || hasKind(node.parent, 158 /* ForInStatement */)) { return getLoopBreakContinueOccurrences(node.parent); } break; case 94 /* WhileKeyword */: case 69 /* DoKeyword */: - if (hasKind(node.parent, 154 /* WhileStatement */) || hasKind(node.parent, 153 /* DoStatement */)) { + if (hasKind(node.parent, 156 /* WhileStatement */) || hasKind(node.parent, 155 /* DoStatement */)) { return getLoopBreakContinueOccurrences(node.parent); } break; @@ -33166,11 +34841,16 @@ var ts; return getConstructorOccurrences(node.parent); } break; + case 109 /* GetKeyword */: + case 113 /* SetKeyword */: + if (hasKind(node.parent, 122 /* GetAccessor */) || hasKind(node.parent, 123 /* SetAccessor */)) { + return getGetAndSetOccurrences(node.parent); + } } return undefined; function getIfElseOccurrences(ifStatement) { var keywords = []; - while (hasKind(ifStatement.parent, 152 /* IfStatement */) && ifStatement.parent.elseStatement === ifStatement) { + while (hasKind(ifStatement.parent, 154 /* IfStatement */) && ifStatement.parent.elseStatement === ifStatement) { ifStatement = ifStatement.parent; } while (ifStatement) { @@ -33181,7 +34861,7 @@ var ts; break; } } - if (!hasKind(ifStatement.elseStatement, 152 /* IfStatement */)) { + if (!hasKind(ifStatement.elseStatement, 154 /* IfStatement */)) { break; } ifStatement = ifStatement.elseStatement; @@ -33199,7 +34879,11 @@ var ts; } } if (shouldHighlightNextKeyword) { - result.push(new ReferenceEntry(filename, TypeScript.TextSpan.fromBounds(elseKeyword.getStart(), ifKeyword.end), false)); + result.push({ + fileName: filename, + textSpan: TypeScript.TextSpan.fromBounds(elseKeyword.getStart(), ifKeyword.end), + isWriteAccess: false + }); i++; continue; } @@ -33210,15 +34894,77 @@ var ts; } function getReturnOccurrences(returnStatement) { var func = ts.getContainingFunction(returnStatement); - if (!(func && hasKind(func.body, 173 /* FunctionBlock */))) { + if (!(func && hasKind(func.body, 175 /* FunctionBlock */))) { return undefined; } var keywords = []; ts.forEachReturnStatement(func.body, function (returnStatement) { pushKeywordIf(keywords, returnStatement.getFirstToken(), 84 /* ReturnKeyword */); }); + ts.forEach(aggregateOwnedThrowStatements(func.body), function (throwStatement) { + pushKeywordIf(keywords, throwStatement.getFirstToken(), 88 /* ThrowKeyword */); + }); return ts.map(keywords, getReferenceEntryFromNode); } + function getThrowOccurrences(throwStatement) { + var owner = getThrowStatementOwner(throwStatement); + if (!owner) { + return undefined; + } + var keywords = []; + ts.forEach(aggregateOwnedThrowStatements(owner), function (throwStatement) { + pushKeywordIf(keywords, throwStatement.getFirstToken(), 88 /* ThrowKeyword */); + }); + if (owner.kind === 175 /* FunctionBlock */) { + ts.forEachReturnStatement(owner, function (returnStatement) { + pushKeywordIf(keywords, returnStatement.getFirstToken(), 84 /* ReturnKeyword */); + }); + } + return ts.map(keywords, getReferenceEntryFromNode); + } + function aggregateOwnedThrowStatements(node) { + var statementAccumulator = []; + aggregate(node); + return statementAccumulator; + function aggregate(node) { + if (node.kind === 167 /* ThrowStatement */) { + statementAccumulator.push(node); + } + else if (node.kind === 168 /* TryStatement */) { + var tryStatement = node; + if (tryStatement.catchBlock) { + aggregate(tryStatement.catchBlock); + } + else { + aggregate(tryStatement.tryBlock); + } + if (tryStatement.finallyBlock) { + aggregate(tryStatement.finallyBlock); + } + } + else if (!ts.isAnyFunction(node)) { + ts.forEachChild(node, aggregate); + } + } + ; + } + function getThrowStatementOwner(throwStatement) { + var child = throwStatement; + while (child.parent) { + var parent = child.parent; + if (parent.kind === 175 /* FunctionBlock */ || parent.kind === 184 /* SourceFile */) { + return parent; + } + if (parent.kind === 168 /* TryStatement */) { + var tryStatement = parent; + if (tryStatement.tryBlock === child && tryStatement.catchBlock) { + return child; + } + } + child = parent; + } + return undefined; + } function getTryCatchFinallyOccurrences(tryStatement) { var keywords = []; pushKeywordIf(keywords, tryStatement.getFirstToken(), 90 /* TryKeyword */); @@ -33233,7 +34979,7 @@ var ts; function getLoopBreakContinueOccurrences(loopNode) { var keywords = []; if (pushKeywordIf(keywords, loopNode.getFirstToken(), 76 /* ForKeyword */, 94 /* WhileKeyword */, 69 /* DoKeyword */)) { - if (loopNode.kind === 153 /* DoStatement */) { + if (loopNode.kind === 155 /* DoStatement */) { var loopTokens = loopNode.getChildren(); for (var i = loopTokens.length - 1; i >= 0; i--) { if (pushKeywordIf(keywords, loopTokens[i], 94 /* WhileKeyword */)) { @@ -33269,12 +35015,12 @@ var ts; var owner = getBreakOrContinueOwner(breakOrContinueStatement); if (owner) { switch (owner.kind) { - case 155 /* ForStatement */: - case 156 /* ForInStatement */: - case 153 /* DoStatement */: - case 154 /* WhileStatement */: + case 157 /* ForStatement */: + case 158 /* ForInStatement */: + case 155 /* DoStatement */: + case 156 /* WhileStatement */: return getLoopBreakContinueOccurrences(owner); - case 161 /* SwitchStatement */: + case 163 /* SwitchStatement */: return getSwitchCaseDefaultOccurrences(owner); } } @@ -33285,7 +35031,7 @@ var ts; aggregate(node); return statementAccumulator; function aggregate(node) { - if (node.kind === 158 /* BreakStatement */ || node.kind === 157 /* ContinueStatement */) { + if (node.kind === 160 /* BreakStatement */ || node.kind === 159 /* ContinueStatement */) { statementAccumulator.push(node); } else if (!ts.isAnyFunction(node)) { @@ -33301,14 +35047,14 @@ var ts; function getBreakOrContinueOwner(statement) { for (var node = statement.parent; node; node = node.parent) { switch (node.kind) { - case 161 /* SwitchStatement */: - if (statement.kind === 157 /* ContinueStatement */) { + case 163 /* SwitchStatement */: + if (statement.kind === 159 /* ContinueStatement */) { continue; } - case 155 /* ForStatement */: - case 156 /* ForInStatement */: - case 154 /* WhileStatement */: - case 153 /* DoStatement */: + case 157 /* ForStatement */: + case 158 /* ForInStatement */: + case 156 /* WhileStatement */: + case 155 /* DoStatement */: if (!statement.label || isLabeledBy(node, statement.label.text)) { return node; } @@ -33332,6 +35078,18 @@ var ts; }); return ts.map(keywords, getReferenceEntryFromNode); } + function getGetAndSetOccurrences(accessorDeclaration) { + var keywords = []; + tryPushAccessorKeyword(accessorDeclaration.symbol, 122 /* GetAccessor */); + tryPushAccessorKeyword(accessorDeclaration.symbol, 123 /* SetAccessor */); + return ts.map(keywords, getReferenceEntryFromNode); + function tryPushAccessorKeyword(accessorSymbol, accessorKind) { + var accessor = ts.getDeclarationOfKind(accessorSymbol, accessorKind); + if (accessor) { + ts.forEach(accessor.getChildren(), function (child) { return pushKeywordIf(keywords, child, 109 /* GetKeyword */, 113 /* SetKeyword */); }); + } + } + } function hasKind(node, kind) { return node !== undefined && node.kind === kind; } @@ -33350,20 +35108,27 @@ var ts; return false; } } - function getReferencesAtPosition(filename, position) { + function findRenameLocations(fileName, position, findInStrings, findInComments) { + return findReferences(fileName, position, findInStrings, findInComments); + } + function getReferencesAtPosition(fileName, position) { + return findReferences(fileName, position, false, false); + } + function findReferences(fileName, position, findInStrings, findInComments) { synchronizeHostData(); - filename = TypeScript.switchToForwardSlashes(filename); - var sourceFile = getSourceFile(filename); - var node = getNodeAtPosition(sourceFile, position); + fileName = TypeScript.switchToForwardSlashes(fileName); + var sourceFile = getSourceFile(fileName); + var node = ts.getTouchingPropertyName(sourceFile, position); if (!node) { return undefined; } if (node.kind !== 59 /* Identifier */ && !isLiteralNameOfPropertyDeclarationOrIndexAccess(node) && !isNameOfExternalModuleImportOrDeclaration(node)) { return undefined; } - return getReferencesForNode(node, program.getSourceFiles()); + ts.Debug.assert(node.kind === 59 /* Identifier */ || node.kind === 6 /* NumericLiteral */ || node.kind === 7 /* StringLiteral */); + return getReferencesForNode(node, program.getSourceFiles(), findInStrings, findInComments); } - function getReferencesForNode(node, sourceFiles) { + function getReferencesForNode(node, sourceFiles, findInStrings, findInComments) { if (isLabelName(node)) { if (isJumpStatementTarget(node)) { var labelDefinition = getTargetLabel(node.parent, node.text); @@ -33383,34 +35148,35 @@ var ts; if (!symbol) { return [getReferenceEntryFromNode(node)]; } - if (!symbol.getDeclarations()) { + var declarations = symbol.declarations; + if (!declarations || !declarations.length) { return undefined; } var result; - var searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), symbol.getDeclarations()); - var symbolName = getNormalizedSymbolName(symbol); + var searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), declarations); + var symbolName = getNormalizedSymbolName(symbol.name, declarations); var scope = getSymbolScope(symbol); if (scope) { result = []; - getReferencesInNode(scope, symbol, symbolName, node, searchMeaning, result); + getReferencesInNode(scope, symbol, symbolName, node, searchMeaning, findInStrings, findInComments, result); } else { ts.forEach(sourceFiles, function (sourceFile) { cancellationToken.throwIfCancellationRequested(); if (ts.lookUp(sourceFile.identifiers, symbolName)) { result = result || []; - getReferencesInNode(sourceFile, symbol, symbolName, node, searchMeaning, result); + getReferencesInNode(sourceFile, symbol, symbolName, node, searchMeaning, findInStrings, findInComments, result); } }); } return result; - function getNormalizedSymbolName(symbol) { - var functionExpression = ts.getDeclarationOfKind(symbol, 141 /* FunctionExpression */); + function getNormalizedSymbolName(symbolName, declarations) { + var functionExpression = ts.forEach(declarations, function (d) { return d.kind === 143 /* FunctionExpression */ ? d : undefined; }); if (functionExpression && functionExpression.name) { var name = functionExpression.name.text; } else { - var name = symbol.name; + var name = symbolName; } var length = name.length; if (length >= 2 && name.charCodeAt(0) === 34 /* doubleQuote */ && name.charCodeAt(length - 1) === 34 /* doubleQuote */) { @@ -33431,15 +35197,17 @@ var ts; } var scope = undefined; var declarations = symbol.getDeclarations(); - for (var i = 0, n = declarations.length; i < n; i++) { - var container = getContainerNode(declarations[i]); - if (scope && scope !== container) { - return undefined; + if (declarations) { + for (var i = 0, n = declarations.length; i < n; i++) { + var container = getContainerNode(declarations[i]); + if (scope && scope !== container) { + return undefined; + } + if (container.kind === 184 /* SourceFile */ && !ts.isExternalModule(container)) { + return undefined; + } + scope = container; } - if (container.kind === 182 /* SourceFile */ && !ts.isExternalModule(container)) { - return undefined; - } - scope = container; } return scope; } @@ -33471,7 +35239,7 @@ var ts; var possiblePositions = getPossibleSymbolReferencePositions(sourceFile, labelName, container.getStart(), container.getEnd()); ts.forEach(possiblePositions, function (position) { cancellationToken.throwIfCancellationRequested(); - var node = getNodeAtPosition(sourceFile, position); + var node = ts.getTouchingWord(sourceFile, position); if (!node || node.getWidth() !== labelName.length) { return; } @@ -33500,29 +35268,53 @@ var ts; } return false; } - function getReferencesInNode(container, searchSymbol, searchText, searchLocation, searchMeaning, result) { + function getReferencesInNode(container, searchSymbol, searchText, searchLocation, searchMeaning, findInStrings, findInComments, result) { var sourceFile = container.getSourceFile(); + var tripleSlashDirectivePrefixRegex = /^\/\/\/\s* token.getStart(); + } + function isInComment(position) { + var token = ts.getTokenAtPosition(sourceFile, position); + if (token && position < token.getStart()) { + var commentRanges = ts.getLeadingCommentRanges(sourceFile.text, token.pos); + return ts.forEach(commentRanges, function (c) { + if (c.pos < position && position < c.end) { + var commentText = sourceFile.text.substring(c.pos, c.end); + if (!tripleSlashDirectivePrefixRegex.test(commentText)) { + return true; + } + } + }); + } + return false; + } } function getReferencesForSuperKeyword(superKeyword) { var searchSpaceNode = ts.getSuperContainer(superKeyword); @@ -33547,7 +35339,7 @@ var ts; var possiblePositions = getPossibleSymbolReferencePositions(sourceFile, "super", searchSpaceNode.getStart(), searchSpaceNode.getEnd()); ts.forEach(possiblePositions, function (position) { cancellationToken.throwIfCancellationRequested(); - var node = getNodeAtPosition(sourceFile, position); + var node = ts.getTouchingWord(sourceFile, position); if (!node || node.kind !== 85 /* SuperKeyword */) { return; } @@ -33570,18 +35362,18 @@ var ts; staticFlag &= searchSpaceNode.flags; searchSpaceNode = searchSpaceNode.parent; break; - case 182 /* SourceFile */: + case 184 /* SourceFile */: if (ts.isExternalModule(searchSpaceNode)) { return undefined; } - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: break; default: return undefined; } var result = []; - if (searchSpaceNode.kind === 182 /* SourceFile */) { + if (searchSpaceNode.kind === 184 /* SourceFile */) { ts.forEach(sourceFiles, function (sourceFile) { var possiblePositions = getPossibleSymbolReferencePositions(sourceFile, "this", sourceFile.getStart(), sourceFile.getEnd()); getThisReferencesInFile(sourceFile, sourceFile, possiblePositions, result); @@ -33596,25 +35388,25 @@ var ts; function getThisReferencesInFile(sourceFile, searchSpaceNode, possiblePositions, result) { ts.forEach(possiblePositions, function (position) { cancellationToken.throwIfCancellationRequested(); - var node = getNodeAtPosition(sourceFile, position); + var node = ts.getTouchingWord(sourceFile, position); if (!node || node.kind !== 87 /* ThisKeyword */) { return; } var container = ts.getThisContainer(node, false); switch (searchSpaceNode.kind) { - case 141 /* FunctionExpression */: - case 172 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: + case 174 /* FunctionDeclaration */: if (searchSpaceNode.symbol === container.symbol) { result.push(getReferenceEntryFromNode(node)); } break; - case 174 /* ClassDeclaration */: + case 176 /* ClassDeclaration */: if (container.parent && searchSpaceNode.symbol === container.parent.symbol && (container.flags & 128 /* Static */) === staticFlag) { result.push(getReferenceEntryFromNode(node)); } break; - case 182 /* SourceFile */: - if (container.kind === 182 /* SourceFile */ && !ts.isExternalModule(container)) { + case 184 /* SourceFile */: + if (container.kind === 184 /* SourceFile */ && !ts.isExternalModule(container)) { result.push(getReferenceEntryFromNode(node)); } break; @@ -33624,28 +35416,29 @@ var ts; } function populateSearchSymbolSet(symbol, location) { var result = [symbol]; - var rootSymbol = typeInfoResolver.getRootSymbol(symbol); - if (rootSymbol && rootSymbol !== symbol) { - result.push(rootSymbol); - } if (isNameOfPropertyAssignment(location)) { - var symbolFromContextualType = getPropertySymbolFromContextualType(location); - if (symbolFromContextualType) - result.push(typeInfoResolver.getRootSymbol(symbolFromContextualType)); - } - if (symbol.parent && symbol.parent.flags & (16 /* Class */ | 32 /* Interface */)) { - getPropertySymbolsFromBaseTypes(symbol.parent, symbol.getName(), result); + ts.forEach(getPropertySymbolsFromContextualType(location), function (contextualSymbol) { + result.push.apply(result, typeInfoResolver.getRootSymbols(contextualSymbol)); + }); } + ts.forEach(typeInfoResolver.getRootSymbols(symbol), function (rootSymbol) { + if (rootSymbol !== symbol) { + result.push(rootSymbol); + } + if (rootSymbol.parent && rootSymbol.parent.flags & (16 /* Class */ | 32 /* Interface */)) { + getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getName(), result); + } + }); return result; } function getPropertySymbolsFromBaseTypes(symbol, propertyName, result) { - if (symbol.flags & (16 /* Class */ | 32 /* Interface */)) { + if (symbol && symbol.flags & (16 /* Class */ | 32 /* Interface */)) { ts.forEach(symbol.getDeclarations(), function (declaration) { - if (declaration.kind === 174 /* ClassDeclaration */) { + if (declaration.kind === 176 /* ClassDeclaration */) { getPropertySymbolFromTypeReference(declaration.baseType); ts.forEach(declaration.implementedTypes, getPropertySymbolFromTypeReference); } - else if (declaration.kind === 175 /* InterfaceDeclaration */) { + else if (declaration.kind === 177 /* InterfaceDeclaration */) { ts.forEach(declaration.baseTypes, getPropertySymbolFromTypeReference); } }); @@ -33653,131 +35446,70 @@ var ts; return; function getPropertySymbolFromTypeReference(typeReference) { if (typeReference) { - var typeReferenceSymbol = typeInfoResolver.getSymbolInfo(typeReference.typeName); - if (typeReferenceSymbol) { - var propertySymbol = typeReferenceSymbol.members[propertyName]; - if (propertySymbol) - result.push(typeReferenceSymbol.members[propertyName]); - getPropertySymbolsFromBaseTypes(typeReferenceSymbol, propertyName, result); + var type = typeInfoResolver.getTypeOfNode(typeReference); + if (type) { + var propertySymbol = typeInfoResolver.getPropertyOfType(type, propertyName); + if (propertySymbol) { + result.push(propertySymbol); + } + getPropertySymbolsFromBaseTypes(type.symbol, propertyName, result); } } } } function isRelatableToSearchSet(searchSymbols, referenceSymbol, referenceLocation) { - var referenceSymbolTarget = typeInfoResolver.getRootSymbol(referenceSymbol); - if (searchSymbols.indexOf(referenceSymbolTarget) >= 0) { + if (searchSymbols.indexOf(referenceSymbol) >= 0) { return true; } if (isNameOfPropertyAssignment(referenceLocation)) { - var symbolFromContextualType = getPropertySymbolFromContextualType(referenceLocation); - if (symbolFromContextualType && searchSymbols.indexOf(typeInfoResolver.getRootSymbol(symbolFromContextualType)) >= 0) { + return ts.forEach(getPropertySymbolsFromContextualType(referenceLocation), function (contextualSymbol) { + return ts.forEach(typeInfoResolver.getRootSymbols(contextualSymbol), function (s) { return searchSymbols.indexOf(s) >= 0; }); + }); + } + return ts.forEach(typeInfoResolver.getRootSymbols(referenceSymbol), function (rootSymbol) { + if (searchSymbols.indexOf(rootSymbol) >= 0) { return true; } - } - if (referenceSymbol.parent && referenceSymbol.parent.flags & (16 /* Class */ | 32 /* Interface */)) { - var result = []; - getPropertySymbolsFromBaseTypes(referenceSymbol.parent, referenceSymbol.getName(), result); - return ts.forEach(result, function (s) { return searchSymbols.indexOf(s) >= 0; }); - } - return false; + if (rootSymbol.parent && rootSymbol.parent.flags & (16 /* Class */ | 32 /* Interface */)) { + var result = []; + getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getName(), result); + return ts.forEach(result, function (s) { return searchSymbols.indexOf(s) >= 0; }); + } + return false; + }); } - function getPropertySymbolFromContextualType(node) { + function getPropertySymbolsFromContextualType(node) { if (isNameOfPropertyAssignment(node)) { var objectLiteral = node.parent.parent; var contextualType = typeInfoResolver.getContextualType(objectLiteral); + var name = node.text; if (contextualType) { - return typeInfoResolver.getPropertyOfType(contextualType, node.text); + if (contextualType.flags & 16384 /* Union */) { + var unionProperty = contextualType.getProperty(name); + if (unionProperty) { + return [unionProperty]; + } + else { + var result = []; + ts.forEach(contextualType.types, function (t) { + var symbol = t.getProperty(name); + if (symbol) { + result.push(symbol); + } + }); + return result; + } + } + else { + var symbol = contextualType.getProperty(name); + if (symbol) { + return [symbol]; + } + } } } return undefined; } - function getMeaningFromDeclaration(node) { - switch (node.kind) { - case 118 /* Parameter */: - case 171 /* VariableDeclaration */: - case 119 /* Property */: - case 134 /* PropertyAssignment */: - case 181 /* EnumMember */: - case 120 /* Method */: - case 121 /* Constructor */: - case 122 /* GetAccessor */: - case 123 /* SetAccessor */: - case 172 /* FunctionDeclaration */: - case 141 /* FunctionExpression */: - case 142 /* ArrowFunction */: - case 168 /* CatchBlock */: - return 1 /* Value */; - case 117 /* TypeParameter */: - case 175 /* InterfaceDeclaration */: - case 129 /* TypeLiteral */: - return 2 /* Type */; - case 174 /* ClassDeclaration */: - case 176 /* EnumDeclaration */: - return 1 /* Value */ | 2 /* Type */; - case 177 /* ModuleDeclaration */: - if (node.name.kind === 7 /* StringLiteral */) { - return 4 /* Namespace */ | 1 /* Value */; - } - else if (ts.isInstantiated(node)) { - return 4 /* Namespace */ | 1 /* Value */; - } - else { - return 4 /* Namespace */; - } - break; - case 179 /* ImportDeclaration */: - return 1 /* Value */ | 2 /* Type */ | 4 /* Namespace */; - } - ts.Debug.fail("Unknown declaration type"); - } - function isTypeReference(node) { - if (node.parent.kind === 116 /* QualifiedName */ && node.parent.right === node) - node = node.parent; - return node.parent.kind === 127 /* TypeReference */; - } - function isNamespaceReference(node) { - var root = node; - var isLastClause = true; - if (root.parent.kind === 116 /* QualifiedName */) { - while (root.parent && root.parent.kind === 116 /* QualifiedName */) - root = root.parent; - isLastClause = root.right === node; - } - return root.parent.kind === 127 /* TypeReference */ && !isLastClause; - } - function isInRightSideOfImport(node) { - while (node.parent.kind === 116 /* QualifiedName */) { - node = node.parent; - } - return node.parent.kind === 179 /* ImportDeclaration */ && node.parent.entityName === node; - } - function getMeaningFromRightHandSideOfImport(node) { - ts.Debug.assert(node.kind === 59 /* Identifier */); - if (node.parent.kind === 116 /* QualifiedName */ && node.parent.right === node && node.parent.parent.kind === 179 /* ImportDeclaration */) { - return 1 /* Value */ | 2 /* Type */ | 4 /* Namespace */; - } - return 4 /* Namespace */; - } - function getMeaningFromLocation(node) { - if (node.parent.kind === 180 /* ExportAssignment */) { - return 1 /* Value */ | 2 /* Type */ | 4 /* Namespace */; - } - else if (isInRightSideOfImport(node)) { - return getMeaningFromRightHandSideOfImport(node); - } - else if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { - return getMeaningFromDeclaration(node.parent); - } - else if (isTypeReference(node)) { - return 2 /* Type */; - } - else if (isNamespaceReference(node)) { - return 4 /* Namespace */; - } - else { - return 1 /* Value */; - } - } function getIntersectingMeaningFromDeclarations(meaning, declarations) { if (declarations) { do { @@ -33800,7 +35532,11 @@ var ts; start += 1; end -= 1; } - return new ReferenceEntry(node.getSourceFile().filename, TypeScript.TextSpan.fromBounds(start, end), isWriteAccess(node)); + return { + fileName: node.getSourceFile().filename, + textSpan: TypeScript.TextSpan.fromBounds(start, end), + isWriteAccess: isWriteAccess(node) + }; } function isWriteAccess(node) { if (node.kind === 59 /* Identifier */ && ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { @@ -33808,10 +35544,10 @@ var ts; } var parent = node.parent; if (parent) { - if (parent.kind === 144 /* PostfixOperator */ || parent.kind === 143 /* PrefixOperator */) { + if (parent.kind === 146 /* PostfixOperator */ || parent.kind === 145 /* PrefixOperator */) { return true; } - else if (parent.kind === 145 /* BinaryExpression */ && parent.left === node) { + else if (parent.kind === 147 /* BinaryExpression */ && parent.left === node) { var operator = parent.operator; return ts.SyntaxKind.FirstAssignment <= operator && operator <= ts.SyntaxKind.LastAssignment; } @@ -33886,7 +35622,7 @@ var ts; filename = TypeScript.switchToForwardSlashes(filename); var compilerOptions = program.getCompilerOptions(); var targetSourceFile = program.getSourceFile(filename); - var emitToSingleFile = ts.shouldEmitToOwnFile(targetSourceFile, compilerOptions); + var shouldEmitToOwnFile = ts.shouldEmitToOwnFile(targetSourceFile, compilerOptions); var emitDeclaration = compilerOptions.declaration; var emitOutput = { outputFiles: [], @@ -33902,7 +35638,7 @@ var ts; writer = getEmitOutputWriter; var syntacticDiagnostics = []; var containSyntacticErrors = false; - if (emitToSingleFile) { + if (shouldEmitToOwnFile) { containSyntacticErrors = containErrors(program.getDiagnostics(targetSourceFile)); } else { @@ -33918,11 +35654,152 @@ var ts; writer = undefined; return emitOutput; } - var emitFilesResult = emitToSingleFile ? getFullTypeCheckChecker().emitFiles(targetSourceFile) : getFullTypeCheckChecker().emitFiles(); + var emitFilesResult = getFullTypeCheckChecker().emitFiles(targetSourceFile); emitOutput.emitOutputStatus = emitFilesResult.emitResultStatus; writer = undefined; return emitOutput; } + function getMeaningFromDeclaration(node) { + switch (node.kind) { + case 118 /* Parameter */: + case 173 /* VariableDeclaration */: + case 119 /* Property */: + case 136 /* PropertyAssignment */: + case 183 /* EnumMember */: + case 120 /* Method */: + case 121 /* Constructor */: + case 122 /* GetAccessor */: + case 123 /* SetAccessor */: + case 174 /* FunctionDeclaration */: + case 143 /* FunctionExpression */: + case 144 /* ArrowFunction */: + case 170 /* CatchBlock */: + return 1 /* Value */; + case 117 /* TypeParameter */: + case 177 /* InterfaceDeclaration */: + case 129 /* TypeLiteral */: + return 2 /* Type */; + case 176 /* ClassDeclaration */: + case 178 /* EnumDeclaration */: + return 1 /* Value */ | 2 /* Type */; + case 179 /* ModuleDeclaration */: + if (node.name.kind === 7 /* StringLiteral */) { + return 4 /* Namespace */ | 1 /* Value */; + } + else if (ts.isInstantiated(node)) { + return 4 /* Namespace */ | 1 /* Value */; + } + else { + return 4 /* Namespace */; + } + break; + case 181 /* ImportDeclaration */: + return 1 /* Value */ | 2 /* Type */ | 4 /* Namespace */; + } + ts.Debug.fail("Unknown declaration type"); + } + function isTypeReference(node) { + if (node.parent.kind === 116 /* QualifiedName */ && node.parent.right === node) + node = node.parent; + return node.parent.kind === 127 /* TypeReference */; + } + function isNamespaceReference(node) { + var root = node; + var isLastClause = true; + if (root.parent.kind === 116 /* QualifiedName */) { + while (root.parent && root.parent.kind === 116 /* QualifiedName */) + root = root.parent; + isLastClause = root.right === node; + } + return root.parent.kind === 127 /* TypeReference */ && !isLastClause; + } + function isInRightSideOfImport(node) { + while (node.parent.kind === 116 /* QualifiedName */) { + node = node.parent; + } + return node.parent.kind === 181 /* ImportDeclaration */ && node.parent.entityName === node; + } + function getMeaningFromRightHandSideOfImport(node) { + ts.Debug.assert(node.kind === 59 /* Identifier */); + if (node.parent.kind === 116 /* QualifiedName */ && node.parent.right === node && node.parent.parent.kind === 181 /* ImportDeclaration */) { + return 1 /* Value */ | 2 /* Type */ | 4 /* Namespace */; + } + return 4 /* Namespace */; + } + function getMeaningFromLocation(node) { + if (node.parent.kind === 182 /* ExportAssignment */) { + return 1 /* Value */ | 2 /* Type */ | 4 /* Namespace */; + } + else if (isInRightSideOfImport(node)) { + return getMeaningFromRightHandSideOfImport(node); + } + else if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { + return getMeaningFromDeclaration(node.parent); + } + else if (isTypeReference(node)) { + return 2 /* Type */; + } + else if (isNamespaceReference(node)) { + return 4 /* Namespace */; + } + else { + return 1 /* Value */; + } + } + function getSignatureHelpItems(fileName, position) { + synchronizeHostData(); + fileName = TypeScript.switchToForwardSlashes(fileName); + var sourceFile = getSourceFile(fileName); + return ts.SignatureHelp.getSignatureHelpItems(sourceFile, position, typeInfoResolver, cancellationToken); + } + function getSignatureAtPosition(filename, position) { + var signatureHelpItems = getSignatureHelpItems(filename, position); + if (!signatureHelpItems) { + return undefined; + } + var currentArgumentState = { argumentIndex: signatureHelpItems.argumentIndex, argumentCount: signatureHelpItems.argumentCount }; + var formalSignatures = []; + ts.forEach(signatureHelpItems.items, function (signature) { + var signatureInfoString = displayPartsToString(signature.prefixDisplayParts); + var parameters = []; + if (signature.parameters) { + for (var i = 0, n = signature.parameters.length; i < n; i++) { + var parameter = signature.parameters[i]; + if (i) { + signatureInfoString += displayPartsToString(signature.separatorDisplayParts); + } + var start = signatureInfoString.length; + signatureInfoString += displayPartsToString(parameter.displayParts); + var end = signatureInfoString.length - 1; + parameters.push({ + name: parameter.name, + isVariable: i === n - 1 && signature.isVariadic, + docComment: displayPartsToString(parameter.documentation), + minChar: start, + limChar: end + }); + } + } + signatureInfoString += displayPartsToString(signature.suffixDisplayParts); + formalSignatures.push({ + signatureInfo: signatureInfoString, + docComment: displayPartsToString(signature.documentation), + parameters: parameters, + typeParameters: [] + }); + }); + var actualSignature = { + parameterMinChar: signatureHelpItems.applicableSpan.start(), + parameterLimChar: signatureHelpItems.applicableSpan.end(), + currentParameterIsTypeParameter: false, + currentParameter: currentArgumentState.argumentIndex + }; + return { + actual: actualSignature, + formal: formalSignatures, + activeFormal: 0 + }; + } function getSyntaxTree(filename) { filename = TypeScript.switchToForwardSlashes(filename); return syntaxTreeCache.getCurrentFileSyntaxTree(filename); @@ -33985,8 +35862,7 @@ var ts; } function getNavigationBarItems(filename) { filename = TypeScript.switchToForwardSlashes(filename); - var syntaxTree = getSyntaxTree(filename); - return new TypeScript.Services.NavigationBarItemGetter().getItems(syntaxTree.sourceUnit()); + return ts.NavigationBar.getNavigationBarItems(getCurrentSourceFile(filename)); } function getSemanticClassifications(fileName, span) { synchronizeHostData(); @@ -33995,7 +35871,7 @@ var ts; var result = []; processNode(sourceFile); return result; - function classifySymbol(symbol) { + function classifySymbol(symbol, meaningAtPosition) { var flags = symbol.getFlags(); if (flags & 16 /* Class */) { return ClassificationTypeNames.className; @@ -34003,14 +35879,24 @@ var ts; else if (flags & 64 /* Enum */) { return ClassificationTypeNames.enumName; } - else if (flags & 32 /* Interface */) { - return ClassificationTypeNames.interfaceName; + else if (meaningAtPosition & 2 /* Type */) { + if (flags & 32 /* Interface */) { + return ClassificationTypeNames.interfaceName; + } + else if (flags & 262144 /* TypeParameter */) { + return ClassificationTypeNames.typeParameterName; + } } else if (flags & ts.SymbolFlags.Module) { - return ClassificationTypeNames.moduleName; + if (meaningAtPosition & 4 /* Namespace */ || (meaningAtPosition & 1 /* Value */ && hasValueSideModule(symbol))) { + return ClassificationTypeNames.moduleName; + } } - else if (flags & 262144 /* TypeParameter */) { - return ClassificationTypeNames.typeParameterName; + return undefined; + function hasValueSideModule(symbol) { + return ts.forEach(symbol.declarations, function (declaration) { + return declaration.kind === 179 /* ModuleDeclaration */ && ts.isInstantiated(declaration); + }); } } function processNode(node) { @@ -34018,9 +35904,12 @@ var ts; if (node.kind === 59 /* Identifier */ && node.getWidth() > 0) { var symbol = typeInfoResolver.getSymbolInfo(node); if (symbol) { - var type = classifySymbol(symbol); + var type = classifySymbol(symbol, getMeaningFromLocation(node)); if (type) { - result.push(new ClassifiedSpan(new TypeScript.TextSpan(node.getStart(), node.getWidth()), type)); + result.push({ + textSpan: new TypeScript.TextSpan(node.getStart(), node.getWidth()), + classificationType: type + }); } } } @@ -34032,93 +35921,81 @@ var ts; fileName = TypeScript.switchToForwardSlashes(fileName); var sourceFile = getCurrentSourceFile(fileName); var result = []; - processElement(sourceFile.getSourceUnit()); + processElement(sourceFile); return result; - function classifyTrivia(trivia) { - if (trivia.isComment() && span.intersectsWith(trivia.fullStart(), trivia.fullWidth())) { - result.push(new ClassifiedSpan(new TypeScript.TextSpan(trivia.fullStart(), trivia.fullWidth()), ClassificationTypeNames.comment)); - } - } - function classifyTriviaList(trivia) { - for (var i = 0, n = trivia.count(); i < n; i++) { - classifyTrivia(trivia.syntaxTriviaAt(i)); + function classifyComment(comment) { + var width = comment.end - comment.pos; + if (span.intersectsWith(comment.pos, width)) { + result.push({ + textSpan: new TypeScript.TextSpan(comment.pos, width), + classificationType: ClassificationTypeNames.comment + }); } } function classifyToken(token) { - if (token.hasLeadingComment()) { - classifyTriviaList(token.leadingTrivia()); - } - if (TypeScript.width(token) > 0) { + ts.forEach(ts.getLeadingCommentRanges(sourceFile.text, token.getFullStart()), classifyComment); + if (token.getWidth() > 0) { var type = classifyTokenType(token); if (type) { - result.push(new ClassifiedSpan(new TypeScript.TextSpan(TypeScript.start(token), TypeScript.width(token)), type)); + result.push({ + textSpan: new TypeScript.TextSpan(token.getStart(), token.getWidth()), + classificationType: type + }); } } - if (token.hasTrailingComment()) { - classifyTriviaList(token.trailingTrivia()); - } + ts.forEach(ts.getTrailingCommentRanges(sourceFile.text, token.getEnd()), classifyComment); } function classifyTokenType(token) { - var tokenKind = token.kind(); - if (TypeScript.SyntaxFacts.isAnyKeyword(token.kind())) { + var tokenKind = token.kind; + if (ts.isKeyword(tokenKind)) { return ClassificationTypeNames.keyword; } - if (tokenKind === 80 /* LessThanToken */ || tokenKind === 81 /* GreaterThanToken */) { - var tokenParentKind = token.parent.kind(); - if (tokenParentKind === 229 /* TypeArgumentList */ || tokenParentKind === 230 /* TypeParameterList */) { + if (tokenKind === 19 /* LessThanToken */ || tokenKind === 20 /* GreaterThanToken */) { + if (ts.getTypeArgumentOrTypeParameterList(token.parent)) { return ClassificationTypeNames.punctuation; } } - if (TypeScript.SyntaxFacts.isBinaryExpressionOperatorToken(tokenKind) || TypeScript.SyntaxFacts.isPrefixUnaryExpressionOperatorToken(tokenKind)) { - return ClassificationTypeNames.operator; + if (ts.isPunctuation(token)) { + if (token.parent.kind === 147 /* BinaryExpression */ || token.parent.kind === 173 /* VariableDeclaration */ || token.parent.kind === 145 /* PrefixOperator */ || token.parent.kind === 146 /* PostfixOperator */ || token.parent.kind === 148 /* ConditionalExpression */) { + return ClassificationTypeNames.operator; + } + else { + return ClassificationTypeNames.punctuation; + } } - else if (TypeScript.SyntaxFacts.isAnyPunctuation(tokenKind)) { - return ClassificationTypeNames.punctuation; - } - else if (tokenKind === 13 /* NumericLiteral */) { + else if (tokenKind === 6 /* NumericLiteral */) { return ClassificationTypeNames.numericLiteral; } - else if (tokenKind === 14 /* StringLiteral */) { + else if (tokenKind === 7 /* StringLiteral */) { return ClassificationTypeNames.stringLiteral; } - else if (tokenKind === 12 /* RegularExpressionLiteral */) { + else if (tokenKind === 8 /* RegularExpressionLiteral */) { return ClassificationTypeNames.stringLiteral; } - else if (tokenKind === 11 /* IdentifierName */) { - var current = token; - var parent = token.parent; - while (parent.kind() === 121 /* QualifiedName */) { - current = parent; - parent = parent.parent; - } - switch (parent.kind()) { - case 241 /* SimplePropertyAssignment */: - if (parent.propertyName === token) { - return ClassificationTypeNames.identifier; - } - return; - case 132 /* ClassDeclaration */: - if (parent.identifier === token) { + else if (tokenKind === 59 /* Identifier */) { + switch (token.parent.kind) { + case 176 /* ClassDeclaration */: + if (token.parent.name === token) { return ClassificationTypeNames.className; } return; - case 239 /* TypeParameter */: - if (parent.identifier === token) { + case 117 /* TypeParameter */: + if (token.parent.name === token) { return ClassificationTypeNames.typeParameterName; } return; - case 129 /* InterfaceDeclaration */: - if (parent.identifier === token) { + case 177 /* InterfaceDeclaration */: + if (token.parent.name === token) { return ClassificationTypeNames.interfaceName; } return; - case 133 /* EnumDeclaration */: - if (parent.identifier === token) { + case 178 /* EnumDeclaration */: + if (token.parent.name === token) { return ClassificationTypeNames.enumName; } return; - case 131 /* ModuleDeclaration */: - if (parent.name === current) { + case 179 /* ModuleDeclaration */: + if (token.parent.name === token) { return ClassificationTypeNames.moduleName; } return; @@ -34128,16 +36005,15 @@ var ts; } } function processElement(element) { - if (!TypeScript.isShared(element) && span.intersectsWith(TypeScript.fullStart(element), TypeScript.fullWidth(element))) { - for (var i = 0, n = TypeScript.childCount(element); i < n; i++) { - var child = TypeScript.childAt(element, i); - if (child) { - if (TypeScript.isToken(child)) { - classifyToken(child); - } - else { - processElement(child); - } + if (span.intersectsWith(element.getFullStart(), element.getFullWidth())) { + var children = element.getChildren(); + for (var i = 0, n = children.length; i < n; i++) { + var child = children[i]; + if (ts.isToken(child)) { + classifyToken(child); + } + else { + processElement(child); } } } @@ -34149,9 +36025,52 @@ var ts; return ts.OutliningElementsCollector.collectElements(sourceFile); } function getBraceMatchingAtPosition(filename, position) { - filename = TypeScript.switchToForwardSlashes(filename); - var syntaxTree = getSyntaxTree(filename); - return TypeScript.Services.BraceMatcher.getMatchSpans(syntaxTree, position); + var sourceFile = getCurrentSourceFile(filename); + var result = []; + var token = ts.getTouchingToken(sourceFile, position); + if (token.getStart(sourceFile) === position) { + var matchKind = getMatchingTokenKind(token); + if (matchKind) { + var parentElement = token.parent; + var childNodes = parentElement.getChildren(sourceFile); + for (var i = 0, n = childNodes.length; i < n; i++) { + var current = childNodes[i]; + if (current.kind === matchKind) { + var range1 = new TypeScript.TextSpan(token.getStart(sourceFile), token.getWidth(sourceFile)); + var range2 = new TypeScript.TextSpan(current.getStart(sourceFile), current.getWidth(sourceFile)); + if (range1.start() < range2.start()) { + result.push(range1, range2); + } + else { + result.push(range2, range1); + } + break; + } + } + } + } + return result; + function getMatchingTokenKind(token) { + switch (token.kind) { + case 9 /* OpenBraceToken */: + return 10 /* CloseBraceToken */; + case 11 /* OpenParenToken */: + return 12 /* CloseParenToken */; + case 13 /* OpenBracketToken */: + return 14 /* CloseBracketToken */; + case 19 /* LessThanToken */: + return 20 /* GreaterThanToken */; + case 10 /* CloseBraceToken */: + return 9 /* OpenBraceToken */; + case 12 /* CloseParenToken */: + return 11 /* OpenParenToken */; + case 14 /* CloseBracketToken */: + return 13 /* OpenBracketToken */; + case 20 /* GreaterThanToken */: + return 19 /* LessThanToken */; + } + return undefined; + } } function getIndentationAtPosition(filename, position, editorOptions) { filename = TypeScript.switchToForwardSlashes(filename); @@ -34211,11 +36130,11 @@ var ts; ts.Debug.assert(matchArray.length === descriptors.length + firstDescriptorCaptureIndex); var preamble = matchArray[1]; var matchPosition = matchArray.index + preamble.length; - var token = getTokenAtPosition(sourceFile, matchPosition); + var token = ts.getTokenAtPosition(sourceFile, matchPosition); if (token.getStart() <= matchPosition && matchPosition < token.getEnd()) { continue; } - if (!getContainingComment(ts.getTrailingComments(fileContents, token.getFullStart()), matchPosition) && !getContainingComment(ts.getLeadingComments(fileContents, token.getFullStart()), matchPosition)) { + if (!getContainingComment(ts.getTrailingCommentRanges(fileContents, token.getFullStart()), matchPosition) && !getContainingComment(ts.getLeadingCommentRanges(fileContents, token.getFullStart()), matchPosition)) { continue; } var descriptor = undefined; @@ -34229,7 +36148,11 @@ var ts; continue; } var message = matchArray[2]; - result.push(new TodoComment(descriptor, message, matchPosition)); + result.push({ + descriptor: descriptor, + message: message, + position: matchPosition + }); } } return result; @@ -34267,17 +36190,39 @@ var ts; synchronizeHostData(); fileName = TypeScript.switchToForwardSlashes(fileName); var sourceFile = getSourceFile(fileName); - var node = getNodeAtPosition(sourceFile, position); + var node = ts.getTouchingWord(sourceFile, position); if (node && node.kind === 59 /* Identifier */) { var symbol = typeInfoResolver.getSymbolInfo(node); if (symbol && symbol.getDeclarations() && symbol.getDeclarations().length > 0) { - var kind = getSymbolKind(symbol); + var kind = getSymbolKind(symbol, typeInfoResolver); if (kind) { - return RenameInfo.Create(symbol.name, typeInfoResolver.getFullyQualifiedName(symbol), kind, getNodeModifiers(symbol.getDeclarations()[0]), new TypeScript.TextSpan(node.getStart(), node.getWidth())); + return getRenameInfo(symbol.name, typeInfoResolver.getFullyQualifiedName(symbol), kind, getSymbolModifiers(symbol), new TypeScript.TextSpan(node.getStart(), node.getWidth())); } } } - return RenameInfo.CreateError(ts.getLocaleSpecificMessage(ts.Diagnostics.You_cannot_rename_this_element.key)); + return getRenameInfoError(ts.getLocaleSpecificMessage(ts.Diagnostics.You_cannot_rename_this_element.key)); + function getRenameInfoError(localizedErrorMessage) { + return { + canRename: false, + localizedErrorMessage: ts.getLocaleSpecificMessage(ts.Diagnostics.You_cannot_rename_this_element.key), + displayName: undefined, + fullDisplayName: undefined, + kind: undefined, + kindModifiers: undefined, + triggerSpan: undefined + }; + } + function getRenameInfo(displayName, fullDisplayName, kind, kindModifiers, triggerSpan) { + return { + canRename: true, + localizedErrorMessage: undefined, + displayName: displayName, + fullDisplayName: fullDisplayName, + kind: kind, + kindModifiers: kindModifiers, + triggerSpan: triggerSpan + }; + } } return { dispose: dispose, @@ -34289,9 +36234,8 @@ var ts; getSemanticClassifications: getSemanticClassifications, getCompletionsAtPosition: getCompletionsAtPosition, getCompletionEntryDetails: getCompletionEntryDetails, - getTypeAtPosition: getTypeAtPosition, - getSignatureHelpItems: function (filename, position) { return null; }, - getSignatureHelpCurrentArgumentState: function (fileName, position, applicableSpanStart) { return null; }, + getSignatureHelpItems: getSignatureHelpItems, + getQuickInfoAtPosition: getQuickInfoAtPosition, getDefinitionAtPosition: getDefinitionAtPosition, getReferencesAtPosition: getReferencesAtPosition, getOccurrencesAtPosition: getOccurrencesAtPosition, @@ -34300,6 +36244,7 @@ var ts; getBreakpointStatementAtPosition: getBreakpointStatementAtPosition, getNavigateToItems: getNavigateToItems, getRenameInfo: getRenameInfo, + findRenameLocations: findRenameLocations, getNavigationBarItems: getNavigationBarItems, getOutliningSpans: getOutliningSpans, getTodoComments: getTodoComments, @@ -34308,33 +36253,49 @@ var ts; getFormattingEditsForRange: getFormattingEditsForRange, getFormattingEditsForDocument: getFormattingEditsForDocument, getFormattingEditsAfterKeystroke: getFormattingEditsAfterKeystroke, - getEmitOutput: getEmitOutput + getEmitOutput: getEmitOutput, + getSignatureAtPosition: getSignatureAtPosition }; } ts.createLanguageService = createLanguageService; function createClassifier(host) { - var scanner; - var noRegexTable; - if (!noRegexTable) { - noRegexTable = []; - noRegexTable[59 /* Identifier */] = true; - noRegexTable[7 /* StringLiteral */] = true; - noRegexTable[6 /* NumericLiteral */] = true; - noRegexTable[8 /* RegularExpressionLiteral */] = true; - noRegexTable[87 /* ThisKeyword */] = true; - noRegexTable[33 /* PlusPlusToken */] = true; - noRegexTable[34 /* MinusMinusToken */] = true; - noRegexTable[12 /* CloseParenToken */] = true; - noRegexTable[14 /* CloseBracketToken */] = true; - noRegexTable[10 /* CloseBraceToken */] = true; - noRegexTable[89 /* TrueKeyword */] = true; - noRegexTable[74 /* FalseKeyword */] = true; + var scanner = ts.createScanner(1 /* ES5 */, false); + var noRegexTable = []; + noRegexTable[59 /* Identifier */] = true; + noRegexTable[7 /* StringLiteral */] = true; + noRegexTable[6 /* NumericLiteral */] = true; + noRegexTable[8 /* RegularExpressionLiteral */] = true; + noRegexTable[87 /* ThisKeyword */] = true; + noRegexTable[33 /* PlusPlusToken */] = true; + noRegexTable[34 /* MinusMinusToken */] = true; + noRegexTable[12 /* CloseParenToken */] = true; + noRegexTable[14 /* CloseBracketToken */] = true; + noRegexTable[10 /* CloseBraceToken */] = true; + noRegexTable[89 /* TrueKeyword */] = true; + noRegexTable[74 /* FalseKeyword */] = true; + function isAccessibilityModifier(kind) { + switch (kind) { + case 102 /* PublicKeyword */: + case 100 /* PrivateKeyword */: + case 101 /* ProtectedKeyword */: + return true; + } + return false; + } + function canFollow(keyword1, keyword2) { + if (isAccessibilityModifier(keyword1)) { + if (keyword2 === 109 /* GetKeyword */ || keyword2 === 113 /* SetKeyword */ || keyword2 === 107 /* ConstructorKeyword */ || keyword2 === 103 /* StaticKeyword */) { + return true; + } + return false; + } + return true; } function getClassificationsForLine(text, lexState) { var offset = 0; var lastTokenOrCommentEnd = 0; - var lastToken = 0 /* Unknown */; - var inUnterminatedMultiLineComment = false; + var token = 0 /* Unknown */; + var lastNonTriviaToken = 0 /* Unknown */; switch (lexState) { case 3 /* InDoubleQuoteStringLiteral */: text = '"\\\n' + text; @@ -34349,57 +36310,62 @@ var ts; offset = 3; break; } + scanner.setText(text); var result = { finalLexState: 0 /* Start */, entries: [] }; - scanner = ts.createScanner(1 /* ES5 */, true, text, onError, processComment); - var token = 0 /* Unknown */; + var angleBracketStack = 0; do { token = scanner.scan(); - if ((token === 31 /* SlashToken */ || token === 51 /* SlashEqualsToken */) && !noRegexTable[lastToken]) { - if (scanner.reScanSlashToken() === 8 /* RegularExpressionLiteral */) { - token = 8 /* RegularExpressionLiteral */; + if (!ts.isTrivia(token)) { + if ((token === 31 /* SlashToken */ || token === 51 /* SlashEqualsToken */) && !noRegexTable[lastNonTriviaToken]) { + if (scanner.reScanSlashToken() === 8 /* RegularExpressionLiteral */) { + token = 8 /* RegularExpressionLiteral */; + } } + else if (lastNonTriviaToken === 15 /* DotToken */ && isKeyword(token)) { + token = 59 /* Identifier */; + } + else if (isKeyword(lastNonTriviaToken) && isKeyword(token) && !canFollow(lastNonTriviaToken, token)) { + token = 59 /* Identifier */; + } + else if (lastNonTriviaToken === 59 /* Identifier */ && token === 19 /* LessThanToken */) { + angleBracketStack++; + } + else if (token === 20 /* GreaterThanToken */ && angleBracketStack > 0) { + angleBracketStack--; + } + else if (token === 105 /* AnyKeyword */ || token === 114 /* StringKeyword */ || token === 112 /* NumberKeyword */ || token === 106 /* BooleanKeyword */) { + if (angleBracketStack > 0) { + token = 59 /* Identifier */; + } + } + lastNonTriviaToken = token; } - else if (lastToken === 15 /* DotToken */) { - token = 59 /* Identifier */; - } - lastToken = token; processToken(); } while (token !== 1 /* EndOfFileToken */); return result; - function onError(message) { - inUnterminatedMultiLineComment = message.key === ts.Diagnostics.Asterisk_Slash_expected.key; - } - function processComment(start, end) { - addLeadingWhiteSpace(start, end); - addResult(end - start, 3 /* Comment */); - } function processToken() { var start = scanner.getTokenPos(); var end = scanner.getTextPos(); - addLeadingWhiteSpace(start, end); addResult(end - start, classFromKind(token)); if (end >= text.length) { - if (inUnterminatedMultiLineComment) { - result.finalLexState = 1 /* InMultiLineCommentTrivia */; - } - else if (token === 7 /* StringLiteral */) { + if (token === 7 /* StringLiteral */) { var tokenText = scanner.getTokenText(); if (tokenText.length > 0 && tokenText.charCodeAt(tokenText.length - 1) === 92 /* backslash */) { var quoteChar = tokenText.charCodeAt(0); result.finalLexState = quoteChar === 34 /* doubleQuote */ ? 3 /* InDoubleQuoteStringLiteral */ : 2 /* InSingleQuoteStringLiteral */; } } + else if (token === 3 /* MultiLineCommentTrivia */) { + var tokenText = scanner.getTokenText(); + if (!(tokenText.length > 3 && tokenText.charCodeAt(tokenText.length - 2) === 42 /* asterisk */ && tokenText.charCodeAt(tokenText.length - 1) === 47 /* slash */)) { + result.finalLexState = 1 /* InMultiLineCommentTrivia */; + } + } } } - function addLeadingWhiteSpace(start, end) { - if (start > lastTokenOrCommentEnd) { - addResult(start - lastTokenOrCommentEnd, 4 /* Whitespace */); - } - lastTokenOrCommentEnd = end; - } function addResult(length, classification) { if (length > 0) { if (result.entries.length === 0) { @@ -34485,6 +36451,11 @@ var ts; return 7 /* StringLiteral */; case 8 /* RegularExpressionLiteral */: return 8 /* RegExpLiteral */; + case 3 /* MultiLineCommentTrivia */: + case 2 /* SingleLineCommentTrivia */: + return 3 /* Comment */; + case 5 /* WhitespaceTrivia */: + return 4 /* Whitespace */; case 59 /* Identifier */: default: return 5 /* Identifier */; @@ -34500,7 +36471,7 @@ var ts; getNodeConstructor: function (kind) { function Node() { } - var proto = kind === 182 /* SourceFile */ ? new SourceFileObject() : new NodeObject(); + var proto = kind === 184 /* SourceFile */ ? new SourceFileObject() : new NodeObject(); proto.kind = kind; proto.pos = 0; proto.end = 0; @@ -34641,11 +36612,11 @@ var TypeScript; var debugObjectHost = this; var ts; (function (ts) { - var LanguageVersion; (function (LanguageVersion) { LanguageVersion[LanguageVersion["EcmaScript3"] = 0] = "EcmaScript3"; LanguageVersion[LanguageVersion["EcmaScript5"] = 1] = "EcmaScript5"; - })(LanguageVersion || (LanguageVersion = {})); + })(ts.LanguageVersion || (ts.LanguageVersion = {})); + var LanguageVersion = ts.LanguageVersion; (function (ModuleGenTarget) { ModuleGenTarget[ModuleGenTarget["Unspecified"] = 0] = "Unspecified"; ModuleGenTarget[ModuleGenTarget["Synchronous"] = 1] = "Synchronous"; @@ -34785,7 +36756,6 @@ var ts; return null; } var options = compilationSettingsToCompilerOptions(JSON.parse(settingsJson)); - options.noResolve = true; return options; }; LanguageServiceShimHostAdapter.prototype.getScriptFileNames = function () { @@ -34904,7 +36874,8 @@ var ts; message: diagnostic.messageText, start: diagnostic.start, length: diagnostic.length, - category: ts.DiagnosticCategory[diagnostic.category].toLowerCase() + category: ts.DiagnosticCategory[diagnostic.category].toLowerCase(), + code: diagnostic.code }; }; LanguageServiceShimObject.prototype.realizeDiagnosticWithFileName = function (diagnostic) { @@ -34951,11 +36922,11 @@ var ts; return errors.map(function (d) { return _this.realizeDiagnosticWithFileName(d); }); }); }; - LanguageServiceShimObject.prototype.getTypeAtPosition = function (fileName, position) { + LanguageServiceShimObject.prototype.getQuickInfoAtPosition = function (fileName, position) { var _this = this; - return this.forwardJSONCall("getTypeAtPosition('" + fileName + "', " + position + ")", function () { - var typeInfo = _this.languageService.getTypeAtPosition(fileName, position); - return typeInfo; + return this.forwardJSONCall("getQuickInfoAtPosition('" + fileName + "', " + position + ")", function () { + var quickInfo = _this.languageService.getQuickInfoAtPosition(fileName, position); + return quickInfo; }); }; LanguageServiceShimObject.prototype.getNameOrDottedNameSpan = function (fileName, startPos, endPos) { @@ -34979,11 +36950,10 @@ var ts; return signatureInfo; }); }; - LanguageServiceShimObject.prototype.getSignatureHelpCurrentArgumentState = function (fileName, position, applicableSpanStart) { + LanguageServiceShimObject.prototype.getSignatureAtPosition = function (fileName, position) { var _this = this; - return this.forwardJSONCall("getSignatureHelpCurrentArgumentState('" + fileName + "', " + position + ", " + applicableSpanStart + ")", function () { - var signatureInfo = _this.languageService.getSignatureHelpItems(fileName, position); - return signatureInfo; + return this.forwardJSONCall("getSignatureAtPosition('" + fileName + "', " + position + ")", function () { + return _this.languageService.getSignatureAtPosition(fileName, position); }); }; LanguageServiceShimObject.prototype.getDefinitionAtPosition = function (fileName, position) { @@ -34998,6 +36968,12 @@ var ts; return _this.languageService.getRenameInfo(fileName, position); }); }; + LanguageServiceShimObject.prototype.findRenameLocations = function (fileName, position, findInStrings, findInComments) { + var _this = this; + return this.forwardJSONCall("findRenameLocations('" + fileName + "', " + position + ", " + findInStrings + ", " + findInComments + ")", function () { + return _this.languageService.findRenameLocations(fileName, position, findInStrings, findInComments); + }); + }; LanguageServiceShimObject.prototype.getBraceMatchingAtPosition = function (fileName, position) { var _this = this; return this.forwardJSONCall("getBraceMatchingAtPosition('" + fileName + "', " + position + ")", function () { From e4a20849bba25885218a37f8f403e5f21d00f96b Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 24 Oct 2014 10:14:36 -0700 Subject: [PATCH 61/63] Ensure let and const declarations in labels are parsed correctelly --- src/compiler/parser.ts | 8 ++-- .../letDeclarations-validContexts.errors.txt | 20 ++++++++++ .../letDeclarations-validContexts.js | 37 +++++++++++++++++++ .../compiler/letDeclarations-validContexts.ts | 20 ++++++++++ 4 files changed, 81 insertions(+), 4 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index caa62b7ae9e..79140cff165 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3916,14 +3916,14 @@ module ts { } function parseSourceElement() { - return parseSourceElementOrModuleElement(ModifierContext.SourceElements, /*allowLetAndConstDeclarations*/ false); + return parseSourceElementOrModuleElement(ModifierContext.SourceElements); } function parseModuleElement() { - return parseSourceElementOrModuleElement(ModifierContext.ModuleElements, /*allowLetAndConstDeclarations*/ true); + return parseSourceElementOrModuleElement(ModifierContext.ModuleElements); } - function parseSourceElementOrModuleElement(modifierContext: ModifierContext, allowLetAndConstDeclarations: boolean): Statement { + function parseSourceElementOrModuleElement(modifierContext: ModifierContext): Statement { if (isDeclaration()) { return parseDeclaration(modifierContext); } @@ -3931,7 +3931,7 @@ module ts { var statementStart = scanner.getTokenPos(); var statementFirstTokenLength = scanner.getTextPos() - statementStart; var errorCountBeforeStatement = file.syntacticErrors.length; - var statement = parseStatement(allowLetAndConstDeclarations); + var statement = parseStatement(/*allowLetAndConstDeclarations*/ true); if (inAmbientContext && file.syntacticErrors.length === errorCountBeforeStatement) { grammarErrorAtPos(statementStart, statementFirstTokenLength, Diagnostics.Statements_are_not_allowed_in_ambient_contexts); diff --git a/tests/baselines/reference/letDeclarations-validContexts.errors.txt b/tests/baselines/reference/letDeclarations-validContexts.errors.txt index de6cf7beef4..3f3b7a2634f 100644 --- a/tests/baselines/reference/letDeclarations-validContexts.errors.txt +++ b/tests/baselines/reference/letDeclarations-validContexts.errors.txt @@ -126,4 +126,24 @@ tests/cases/compiler/letDeclarations-validContexts.ts(20,7): error TS2410: All s f2: () => { let l29 = 0; } + } + + // labels + label: let l30 = 0; + { + label2: let l31 = 0; + } + + function f3() { + label: let l32 = 0; + { + label2: let l33 = 0; + } + } + + module m3 { + label: let l34 = 0; + { + label2: let l35 = 0; + } } \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-validContexts.js b/tests/baselines/reference/letDeclarations-validContexts.js index daa25014ab3..13eaafb0712 100644 --- a/tests/baselines/reference/letDeclarations-validContexts.js +++ b/tests/baselines/reference/letDeclarations-validContexts.js @@ -121,6 +121,26 @@ var o = { f2: () => { let l29 = 0; } +} + +// labels +label: let l30 = 0; +{ + label2: let l31 = 0; +} + +function f3() { + label: let l32 = 0; + { + label2: let l33 = 0; + } +} + +module m3 { + label: let l34 = 0; + { + label2: let l35 = 0; + } } //// [letDeclarations-validContexts.js] @@ -227,3 +247,20 @@ var o = { let l29 = 0; } }; +label: let l30 = 0; +{ + label2: let l31 = 0; +} +function f3() { + label: let l32 = 0; + { + label2: let l33 = 0; + } +} +var m3; +(function (m3) { + label: let l34 = 0; + { + label2: let l35 = 0; + } +})(m3 || (m3 = {})); diff --git a/tests/cases/compiler/letDeclarations-validContexts.ts b/tests/cases/compiler/letDeclarations-validContexts.ts index 32801f2d009..baedfa2644c 100644 --- a/tests/cases/compiler/letDeclarations-validContexts.ts +++ b/tests/cases/compiler/letDeclarations-validContexts.ts @@ -121,4 +121,24 @@ var o = { f2: () => { let l29 = 0; } +} + +// labels +label: let l30 = 0; +{ + label2: let l31 = 0; +} + +function f3() { + label: let l32 = 0; + { + label2: let l33 = 0; + } +} + +module m3 { + label: let l34 = 0; + { + label2: let l35 = 0; + } } \ No newline at end of file From 67c78a266206f3d217259a576583f239a87f6afb Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 24 Oct 2014 10:30:40 -0700 Subject: [PATCH 62/63] Only check for collisions with variabels and not properties --- src/compiler/checker.ts | 15 +++++------ ...nstDeclarationShadowedByVarDeclaration3.js | 21 ++++++++++++++++ ...DeclarationShadowedByVarDeclaration3.types | 25 +++++++++++++++++++ ...nstDeclarationShadowedByVarDeclaration3.ts | 9 +++++++ 4 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 tests/baselines/reference/constDeclarationShadowedByVarDeclaration3.js create mode 100644 tests/baselines/reference/constDeclarationShadowedByVarDeclaration3.types create mode 100644 tests/cases/compiler/constDeclarationShadowedByVarDeclaration3.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6ff0d5f268b..b1e256f1300 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6885,7 +6885,7 @@ module ts { } } - function checkCollisionsWithConstDeclarations(node: VariableDeclaration) { + function checkCollisionWithConstDeclarations(node: VariableDeclaration) { // Variable declarations are hoisted to the top of their function scope. They can shadow // block scoped declarations, which bind tighter. this will not be flagged as duplicate definition // by the binder as the declaration scope is different. @@ -6906,10 +6906,12 @@ module ts { // } if (node.initializer && (node.flags & NodeFlags.BlockScoped) === 0) { var symbol = getSymbolOfNode(node); - var localDeclarationSymbol = resolveName(node, node.name.text, SymbolFlags.Variable, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined); - if (localDeclarationSymbol && localDeclarationSymbol !== symbol && localDeclarationSymbol.flags & SymbolFlags.BlockScopedVariable) { - if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & NodeFlags.Const) { - error(node, Diagnostics.Cannot_redeclare_block_scoped_variable_0, symbolToString(localDeclarationSymbol)); + if (symbol.flags & SymbolFlags.FunctionScopedVariable) { + var localDeclarationSymbol = resolveName(node, node.name.text, SymbolFlags.Variable, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined); + if (localDeclarationSymbol && localDeclarationSymbol !== symbol && localDeclarationSymbol.flags & SymbolFlags.BlockScopedVariable) { + if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & NodeFlags.Const) { + error(node, Diagnostics.Cannot_redeclare_block_scoped_variable_0, symbolToString(localDeclarationSymbol)); + } } } } @@ -6938,8 +6940,7 @@ module ts { // Use default messages checkTypeAssignableTo(checkAndMarkExpression(node.initializer), type, node, /*chainedMessage*/ undefined, /*terminalMessage*/ undefined); } - - checkCollisionsWithConstDeclarations(node); + checkCollisionWithConstDeclarations(node); } checkCollisionWithCapturedSuperVariable(node, node.name); diff --git a/tests/baselines/reference/constDeclarationShadowedByVarDeclaration3.js b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration3.js new file mode 100644 index 00000000000..6f5b898c5ff --- /dev/null +++ b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration3.js @@ -0,0 +1,21 @@ +//// [constDeclarationShadowedByVarDeclaration3.ts] +// Ensure only checking for const declarations shadowed by vars +class Rule { + public regex: RegExp = new RegExp(''); + public name: string = ''; + + constructor(name: string) { + this.name = name; + } +} + +//// [constDeclarationShadowedByVarDeclaration3.js] +// Ensure only checking for const declarations shadowed by vars +var Rule = (function () { + function Rule(name) { + this.regex = new RegExp(''); + this.name = ''; + this.name = name; + } + return Rule; +})(); diff --git a/tests/baselines/reference/constDeclarationShadowedByVarDeclaration3.types b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration3.types new file mode 100644 index 00000000000..89490567f14 --- /dev/null +++ b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration3.types @@ -0,0 +1,25 @@ +=== tests/cases/compiler/constDeclarationShadowedByVarDeclaration3.ts === +// Ensure only checking for const declarations shadowed by vars +class Rule { +>Rule : Rule + + public regex: RegExp = new RegExp(''); +>regex : RegExp +>RegExp : RegExp +>new RegExp('') : RegExp +>RegExp : { (pattern: string, flags?: string): RegExp; new (pattern: string, flags?: string): RegExp; $1: string; $2: string; $3: string; $4: string; $5: string; $6: string; $7: string; $8: string; $9: string; lastMatch: string; } + + public name: string = ''; +>name : string + + constructor(name: string) { +>name : string + + this.name = name; +>this.name = name : string +>this.name : string +>this : Rule +>name : string +>name : string + } +} diff --git a/tests/cases/compiler/constDeclarationShadowedByVarDeclaration3.ts b/tests/cases/compiler/constDeclarationShadowedByVarDeclaration3.ts new file mode 100644 index 00000000000..5b4229a8e54 --- /dev/null +++ b/tests/cases/compiler/constDeclarationShadowedByVarDeclaration3.ts @@ -0,0 +1,9 @@ +// Ensure only checking for const declarations shadowed by vars +class Rule { + public regex: RegExp = new RegExp(''); + public name: string = ''; + + constructor(name: string) { + this.name = name; + } +} \ No newline at end of file From a65496fd613c183b049a0caac3d4c1e3448beb40 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Fri, 24 Oct 2014 10:36:02 -0700 Subject: [PATCH 63/63] Update CONTRIBUTING.md --- CONTRIBUTING.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index dfaba0c06ab..a30b2154133 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -26,6 +26,7 @@ Your pull request should: * Include baseline changes with your change * All changed code must have 100% code coverage * Follow the code conventions descriped in [Coding guidlines](https://github.com/Microsoft/TypeScript/wiki/Coding-guidlines) +* To avoid line ending issues, set `autocrlf = input` and `whitespace = cr-at-eol` in your git configuration ## Running the Tests To run all tests, invoke the runtests target using jake: