From 27c1bb8ca55e5e0736c10d354d8e632682b01341 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Sun, 12 Apr 2015 12:12:55 -0700 Subject: [PATCH 1/5] Expose getDefaultLibFileName --- src/compiler/core.ts | 4 ---- src/compiler/program.ts | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 61fe2c7209a18..808400683327a 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -659,10 +659,6 @@ module ts { "\u0085": "\\u0085" // nextLine }; - export function getDefaultLibFileName(options: CompilerOptions): string { - return options.target === ScriptTarget.ES6 ? "lib.es6.d.ts" : "lib.d.ts"; - } - export interface ObjectAllocator { getNodeConstructor(kind: SyntaxKind): new () => Node; getSymbolConstructor(): new (flags: SymbolFlags, name: string) => Symbol; diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 4646647802952..63eb3af784cc1 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -137,6 +137,10 @@ module ts { } } + export function getDefaultLibFileName(options: CompilerOptions): string { + return options.target === ScriptTarget.ES6 ? "lib.es6.d.ts" : "lib.d.ts"; + } + export function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program { let program: Program; let files: SourceFile[] = []; From b6bb4ff67ffe30a783a9ef6a3b644325623427fd Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Sun, 12 Apr 2015 12:30:17 -0700 Subject: [PATCH 2/5] expose text span helpers --- src/compiler/utilities.ts | 430 +++++++++++++++++++------------------- 1 file changed, 214 insertions(+), 216 deletions(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index b0c50fc7f669b..533a8b25e4f81 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -271,7 +271,6 @@ module ts { }; } - /* @internal */ export function getSpanOfTokenAtPosition(sourceFile: SourceFile, pos: number): TextSpan { let scanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/ true, sourceFile.text); scanner.setTextPos(pos); @@ -408,7 +407,6 @@ module ts { export let fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*/ - // Warning: This has the same semantics as the forEach family of functions, // in that traversal terminates in the event that 'visitor' supplies a truthy value. export function forEachReturnStatement(body: Block, visitor: (stmt: ReturnStatement) => T): T { @@ -439,7 +437,6 @@ module ts { } } - /* @internal */ export function isVariableLike(node: Node): boolean { if (node) { switch (node.kind) { @@ -1151,218 +1148,7 @@ module ts { } return false; } - - export function textSpanEnd(span: TextSpan) { - return span.start + span.length - } - - export function textSpanIsEmpty(span: TextSpan) { - return span.length === 0 - } - - export function textSpanContainsPosition(span: TextSpan, position: number) { - return position >= span.start && position < textSpanEnd(span); - } - - // Returns true if 'span' contains 'other'. - export function textSpanContainsTextSpan(span: TextSpan, other: TextSpan) { - return other.start >= span.start && textSpanEnd(other) <= textSpanEnd(span); - } - - export function textSpanOverlapsWith(span: TextSpan, other: TextSpan) { - let overlapStart = Math.max(span.start, other.start); - let overlapEnd = Math.min(textSpanEnd(span), textSpanEnd(other)); - return overlapStart < overlapEnd; - } - - export function textSpanOverlap(span1: TextSpan, span2: TextSpan) { - let overlapStart = Math.max(span1.start, span2.start); - let overlapEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2)); - if (overlapStart < overlapEnd) { - return createTextSpanFromBounds(overlapStart, overlapEnd); - } - return undefined; - } - - export function textSpanIntersectsWithTextSpan(span: TextSpan, other: TextSpan) { - return other.start <= textSpanEnd(span) && textSpanEnd(other) >= span.start - } - - export function textSpanIntersectsWith(span: TextSpan, start: number, length: number) { - let end = start + length; - return start <= textSpanEnd(span) && end >= span.start; - } - - export function textSpanIntersectsWithPosition(span: TextSpan, position: number) { - return position <= textSpanEnd(span) && position >= span.start; - } - - export function textSpanIntersection(span1: TextSpan, span2: TextSpan) { - let intersectStart = Math.max(span1.start, span2.start); - let intersectEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2)); - if (intersectStart <= intersectEnd) { - return createTextSpanFromBounds(intersectStart, intersectEnd); - } - return undefined; - } - - export function createTextSpan(start: number, length: number): TextSpan { - if (start < 0) { - throw new Error("start < 0"); - } - if (length < 0) { - throw new Error("length < 0"); - } - - return { start, length }; - } - - export function createTextSpanFromBounds(start: number, end: number) { - return createTextSpan(start, end - start); - } - - export function textChangeRangeNewSpan(range: TextChangeRange) { - return createTextSpan(range.span.start, range.newLength); - } - - export function textChangeRangeIsUnchanged(range: TextChangeRange) { - return textSpanIsEmpty(range.span) && range.newLength === 0; - } - - export function createTextChangeRange(span: TextSpan, newLength: number): TextChangeRange { - if (newLength < 0) { - throw new Error("newLength < 0"); - } - - return { span, newLength }; - } - - export let unchangedTextChangeRange = createTextChangeRange(createTextSpan(0, 0), 0); - - /** - * Called to merge all the changes that occurred across several versions of a script snapshot - * into a single change. i.e. if a user keeps making successive edits to a script we will - * have a text change from V1 to V2, V2 to V3, ..., Vn. - * - * This function will then merge those changes into a single change range valid between V1 and - * Vn. - */ - export function collapseTextChangeRangesAcrossMultipleVersions(changes: TextChangeRange[]): TextChangeRange { - if (changes.length === 0) { - return unchangedTextChangeRange; - } - - if (changes.length === 1) { - return changes[0]; - } - - // We change from talking about { { oldStart, oldLength }, newLength } to { oldStart, oldEnd, newEnd } - // as it makes things much easier to reason about. - let change0 = changes[0]; - - let oldStartN = change0.span.start; - let oldEndN = textSpanEnd(change0.span); - let newEndN = oldStartN + change0.newLength; - - for (let i = 1; i < changes.length; i++) { - let nextChange = changes[i]; - - // Consider the following case: - // i.e. two edits. The first represents the text change range { { 10, 50 }, 30 }. i.e. The span starting - // at 10, with length 50 is reduced to length 30. The second represents the text change range { { 30, 30 }, 40 }. - // i.e. the span starting at 30 with length 30 is increased to length 40. - // - // 0 10 20 30 40 50 60 70 80 90 100 - // ------------------------------------------------------------------------------------------------------- - // | / - // | /---- - // T1 | /---- - // | /---- - // | /---- - // ------------------------------------------------------------------------------------------------------- - // | \ - // | \ - // T2 | \ - // | \ - // | \ - // ------------------------------------------------------------------------------------------------------- - // - // Merging these turns out to not be too difficult. First, determining the new start of the change is trivial - // it's just the min of the old and new starts. i.e.: - // - // 0 10 20 30 40 50 60 70 80 90 100 - // ------------------------------------------------------------*------------------------------------------ - // | / - // | /---- - // T1 | /---- - // | /---- - // | /---- - // ----------------------------------------$-------------------$------------------------------------------ - // . | \ - // . | \ - // T2 . | \ - // . | \ - // . | \ - // ----------------------------------------------------------------------*-------------------------------- - // - // (Note the dots represent the newly inferrred start. - // Determining the new and old end is also pretty simple. Basically it boils down to paying attention to the - // absolute positions at the asterixes, and the relative change between the dollar signs. Basically, we see - // which if the two $'s precedes the other, and we move that one forward until they line up. in this case that - // means: - // - // 0 10 20 30 40 50 60 70 80 90 100 - // --------------------------------------------------------------------------------*---------------------- - // | / - // | /---- - // T1 | /---- - // | /---- - // | /---- - // ------------------------------------------------------------$------------------------------------------ - // . | \ - // . | \ - // T2 . | \ - // . | \ - // . | \ - // ----------------------------------------------------------------------*-------------------------------- - // - // In other words (in this case), we're recognizing that the second edit happened after where the first edit - // ended with a delta of 20 characters (60 - 40). Thus, if we go back in time to where the first edit started - // that's the same as if we started at char 80 instead of 60. - // - // As it so happens, the same logic applies if the second edit precedes the first edit. In that case rahter - // than pusing the first edit forward to match the second, we'll push the second edit forward to match the - // first. - // - // In this case that means we have { oldStart: 10, oldEnd: 80, newEnd: 70 } or, in TextChangeRange - // semantics: { { start: 10, length: 70 }, newLength: 60 } - // - // The math then works out as follows. - // If we have { oldStart1, oldEnd1, newEnd1 } and { oldStart2, oldEnd2, newEnd2 } then we can compute the - // final result like so: - // - // { - // oldStart3: Min(oldStart1, oldStart2), - // oldEnd3 : Max(oldEnd1, oldEnd1 + (oldEnd2 - newEnd1)), - // newEnd3 : Max(newEnd2, newEnd2 + (newEnd1 - oldEnd2)) - // } - - let oldStart1 = oldStartN; - let oldEnd1 = oldEndN; - let newEnd1 = newEndN; - - let oldStart2 = nextChange.span.start; - let oldEnd2 = textSpanEnd(nextChange.span); - let newEnd2 = oldStart2 + nextChange.newLength; - - oldStartN = Math.min(oldStart1, oldStart2); - oldEndN = Math.max(oldEnd1, oldEnd1 + (oldEnd2 - newEnd1)); - newEndN = Math.max(newEnd2, newEnd2 + (newEnd1 - oldEnd2)); - } - - return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), /*newLength:*/ newEndN - oldStartN); - } - + export function nodeStartsNewLexicalEnvironment(n: Node): boolean { return isFunctionLike(n) || n.kind === SyntaxKind.ModuleDeclaration || n.kind === SyntaxKind.SourceFile; } @@ -1379,7 +1165,6 @@ module ts { return node; } - /* @internal */ export function createDiagnosticCollection(): DiagnosticCollection { let nonFileDiagnostics: Diagnostic[] = []; let fileDiagnostics: Map = {}; @@ -1854,3 +1639,216 @@ module ts { return symbol && symbol.valueDeclaration && (symbol.valueDeclaration.flags & NodeFlags.Default) ? symbol.valueDeclaration.localSymbol : undefined; } } + +module ts { + export function textSpanEnd(span: TextSpan) { + return span.start + span.length + } + + export function textSpanIsEmpty(span: TextSpan) { + return span.length === 0 + } + + export function textSpanContainsPosition(span: TextSpan, position: number) { + return position >= span.start && position < textSpanEnd(span); + } + + // Returns true if 'span' contains 'other'. + export function textSpanContainsTextSpan(span: TextSpan, other: TextSpan) { + return other.start >= span.start && textSpanEnd(other) <= textSpanEnd(span); + } + + export function textSpanOverlapsWith(span: TextSpan, other: TextSpan) { + let overlapStart = Math.max(span.start, other.start); + let overlapEnd = Math.min(textSpanEnd(span), textSpanEnd(other)); + return overlapStart < overlapEnd; + } + + export function textSpanOverlap(span1: TextSpan, span2: TextSpan) { + let overlapStart = Math.max(span1.start, span2.start); + let overlapEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2)); + if (overlapStart < overlapEnd) { + return createTextSpanFromBounds(overlapStart, overlapEnd); + } + return undefined; + } + + export function textSpanIntersectsWithTextSpan(span: TextSpan, other: TextSpan) { + return other.start <= textSpanEnd(span) && textSpanEnd(other) >= span.start + } + + export function textSpanIntersectsWith(span: TextSpan, start: number, length: number) { + let end = start + length; + return start <= textSpanEnd(span) && end >= span.start; + } + + export function textSpanIntersectsWithPosition(span: TextSpan, position: number) { + return position <= textSpanEnd(span) && position >= span.start; + } + + export function textSpanIntersection(span1: TextSpan, span2: TextSpan) { + let intersectStart = Math.max(span1.start, span2.start); + let intersectEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2)); + if (intersectStart <= intersectEnd) { + return createTextSpanFromBounds(intersectStart, intersectEnd); + } + return undefined; + } + + export function createTextSpan(start: number, length: number): TextSpan { + if (start < 0) { + throw new Error("start < 0"); + } + if (length < 0) { + throw new Error("length < 0"); + } + + return { start, length }; + } + + export function createTextSpanFromBounds(start: number, end: number) { + return createTextSpan(start, end - start); + } + + export function textChangeRangeNewSpan(range: TextChangeRange) { + return createTextSpan(range.span.start, range.newLength); + } + + export function textChangeRangeIsUnchanged(range: TextChangeRange) { + return textSpanIsEmpty(range.span) && range.newLength === 0; + } + + export function createTextChangeRange(span: TextSpan, newLength: number): TextChangeRange { + if (newLength < 0) { + throw new Error("newLength < 0"); + } + + return { span, newLength }; + } + + export let unchangedTextChangeRange = createTextChangeRange(createTextSpan(0, 0), 0); + + /** + * Called to merge all the changes that occurred across several versions of a script snapshot + * into a single change. i.e. if a user keeps making successive edits to a script we will + * have a text change from V1 to V2, V2 to V3, ..., Vn. + * + * This function will then merge those changes into a single change range valid between V1 and + * Vn. + */ + export function collapseTextChangeRangesAcrossMultipleVersions(changes: TextChangeRange[]): TextChangeRange { + if (changes.length === 0) { + return unchangedTextChangeRange; + } + + if (changes.length === 1) { + return changes[0]; + } + + // We change from talking about { { oldStart, oldLength }, newLength } to { oldStart, oldEnd, newEnd } + // as it makes things much easier to reason about. + let change0 = changes[0]; + + let oldStartN = change0.span.start; + let oldEndN = textSpanEnd(change0.span); + let newEndN = oldStartN + change0.newLength; + + for (let i = 1; i < changes.length; i++) { + let nextChange = changes[i]; + + // Consider the following case: + // i.e. two edits. The first represents the text change range { { 10, 50 }, 30 }. i.e. The span starting + // at 10, with length 50 is reduced to length 30. The second represents the text change range { { 30, 30 }, 40 }. + // i.e. the span starting at 30 with length 30 is increased to length 40. + // + // 0 10 20 30 40 50 60 70 80 90 100 + // ------------------------------------------------------------------------------------------------------- + // | / + // | /---- + // T1 | /---- + // | /---- + // | /---- + // ------------------------------------------------------------------------------------------------------- + // | \ + // | \ + // T2 | \ + // | \ + // | \ + // ------------------------------------------------------------------------------------------------------- + // + // Merging these turns out to not be too difficult. First, determining the new start of the change is trivial + // it's just the min of the old and new starts. i.e.: + // + // 0 10 20 30 40 50 60 70 80 90 100 + // ------------------------------------------------------------*------------------------------------------ + // | / + // | /---- + // T1 | /---- + // | /---- + // | /---- + // ----------------------------------------$-------------------$------------------------------------------ + // . | \ + // . | \ + // T2 . | \ + // . | \ + // . | \ + // ----------------------------------------------------------------------*-------------------------------- + // + // (Note the dots represent the newly inferrred start. + // Determining the new and old end is also pretty simple. Basically it boils down to paying attention to the + // absolute positions at the asterixes, and the relative change between the dollar signs. Basically, we see + // which if the two $'s precedes the other, and we move that one forward until they line up. in this case that + // means: + // + // 0 10 20 30 40 50 60 70 80 90 100 + // --------------------------------------------------------------------------------*---------------------- + // | / + // | /---- + // T1 | /---- + // | /---- + // | /---- + // ------------------------------------------------------------$------------------------------------------ + // . | \ + // . | \ + // T2 . | \ + // . | \ + // . | \ + // ----------------------------------------------------------------------*-------------------------------- + // + // In other words (in this case), we're recognizing that the second edit happened after where the first edit + // ended with a delta of 20 characters (60 - 40). Thus, if we go back in time to where the first edit started + // that's the same as if we started at char 80 instead of 60. + // + // As it so happens, the same logic applies if the second edit precedes the first edit. In that case rahter + // than pusing the first edit forward to match the second, we'll push the second edit forward to match the + // first. + // + // In this case that means we have { oldStart: 10, oldEnd: 80, newEnd: 70 } or, in TextChangeRange + // semantics: { { start: 10, length: 70 }, newLength: 60 } + // + // The math then works out as follows. + // If we have { oldStart1, oldEnd1, newEnd1 } and { oldStart2, oldEnd2, newEnd2 } then we can compute the + // final result like so: + // + // { + // oldStart3: Min(oldStart1, oldStart2), + // oldEnd3 : Max(oldEnd1, oldEnd1 + (oldEnd2 - newEnd1)), + // newEnd3 : Max(newEnd2, newEnd2 + (newEnd1 - oldEnd2)) + // } + + let oldStart1 = oldStartN; + let oldEnd1 = oldEndN; + let newEnd1 = newEndN; + + let oldStart2 = nextChange.span.start; + let oldEnd2 = textSpanEnd(nextChange.span); + let newEnd2 = oldStart2 + nextChange.newLength; + + oldStartN = Math.min(oldStart1, oldStart2); + oldEndN = Math.max(oldEnd1, oldEnd1 + (oldEnd2 - newEnd1)); + newEndN = Math.max(newEnd2, newEnd2 + (newEnd1 - oldEnd2)); + } + + return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), /*newLength:*/ newEndN - oldStartN); + } +} \ No newline at end of file From 095d11b2a9bfa2e8d5c06945571ab0d1175bb654 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Sun, 12 Apr 2015 12:31:49 -0700 Subject: [PATCH 3/5] Update LKG --- bin/tsc.js | 478 +++++++++++++++-------- bin/tsserver.js | 512 ++++++++++++++++--------- bin/typescript.d.ts | 29 ++ bin/typescript.js | 741 +++++++++++++++++++++++------------- bin/typescriptServices.d.ts | 29 ++ bin/typescriptServices.js | 741 +++++++++++++++++++++++------------- 6 files changed, 1643 insertions(+), 887 deletions(-) diff --git a/bin/tsc.js b/bin/tsc.js index 52ffd2b3b1b79..83be107f8d1f7 100644 --- a/bin/tsc.js +++ b/bin/tsc.js @@ -600,10 +600,6 @@ var ts; "\u2029": "\\u2029", "\u0085": "\\u0085" }; - function getDefaultLibFileName(options) { - return options.target === 2 ? "lib.es6.d.ts" : "lib.d.ts"; - } - ts.getDefaultLibFileName = getDefaultLibFileName; function Symbol(flags, name) { this.flags = flags; this.name = name; @@ -1076,6 +1072,12 @@ var ts; Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided: { code: 1209, category: ts.DiagnosticCategory.Error, key: "Ambient const enums are not allowed when the '--separateCompilation' flag is provided." }, Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode: { code: 1210, category: ts.DiagnosticCategory.Error, key: "Invalid use of '{0}'. Class definitions are automatically in strict mode." }, A_class_declaration_without_the_default_modifier_must_have_a_name: { code: 1211, category: ts.DiagnosticCategory.Error, key: "A class declaration without the 'default' modifier must have a name" }, + Identifier_expected_0_is_a_reserved_word_in_strict_mode: { code: 1212, category: ts.DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode" }, + Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1213, category: ts.DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." }, + Identifier_expected_0_is_a_reserved_word_in_strict_mode_External_Module_is_automatically_in_strict_mode: { code: 1214, category: ts.DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode. External Module is automatically in strict mode." }, + Type_expected_0_is_a_reserved_word_in_strict_mode: { code: 1215, category: ts.DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode" }, + Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1216, category: ts.DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." }, + Type_expected_0_is_a_reserved_word_in_strict_mode_Module_is_automatically_in_strict_mode: { code: 1217, category: ts.DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Module is automatically in strict mode." }, Duplicate_identifier_0: { code: 2300, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: ts.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: ts.DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, @@ -3383,7 +3385,7 @@ var ts; scanner.setTextPos(pos); scanner.scan(); var start = scanner.getTokenPos(); - return createTextSpanFromBounds(start, scanner.getTextPos()); + return ts.createTextSpanFromBounds(start, scanner.getTextPos()); } ts.getSpanOfTokenAtPosition = getSpanOfTokenAtPosition; function getErrorSpanForNode(sourceFile, node) { @@ -3392,7 +3394,7 @@ var ts; case 227: var pos_1 = ts.skipTrivia(sourceFile.text, 0, false); if (pos_1 === sourceFile.text.length) { - return createTextSpan(0, 0); + return ts.createTextSpan(0, 0); } return getSpanOfTokenAtPosition(sourceFile, pos_1); case 198: @@ -3414,7 +3416,7 @@ var ts; var pos = nodeIsMissing(errorNode) ? errorNode.pos : ts.skipTrivia(sourceFile.text, errorNode.pos); - return createTextSpanFromBounds(pos, errorNode.end); + return ts.createTextSpanFromBounds(pos, errorNode.end); } ts.getErrorSpanForNode = getErrorSpanForNode; function isExternalModule(file) { @@ -4136,115 +4138,6 @@ var ts; return false; } ts.isModifier = isModifier; - function textSpanEnd(span) { - return span.start + span.length; - } - ts.textSpanEnd = textSpanEnd; - function textSpanIsEmpty(span) { - return span.length === 0; - } - ts.textSpanIsEmpty = textSpanIsEmpty; - function textSpanContainsPosition(span, position) { - return position >= span.start && position < textSpanEnd(span); - } - ts.textSpanContainsPosition = textSpanContainsPosition; - function textSpanContainsTextSpan(span, other) { - return other.start >= span.start && textSpanEnd(other) <= textSpanEnd(span); - } - ts.textSpanContainsTextSpan = textSpanContainsTextSpan; - function textSpanOverlapsWith(span, other) { - var overlapStart = Math.max(span.start, other.start); - var overlapEnd = Math.min(textSpanEnd(span), textSpanEnd(other)); - return overlapStart < overlapEnd; - } - ts.textSpanOverlapsWith = textSpanOverlapsWith; - function textSpanOverlap(span1, span2) { - var overlapStart = Math.max(span1.start, span2.start); - var overlapEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2)); - if (overlapStart < overlapEnd) { - return createTextSpanFromBounds(overlapStart, overlapEnd); - } - return undefined; - } - ts.textSpanOverlap = textSpanOverlap; - function textSpanIntersectsWithTextSpan(span, other) { - return other.start <= textSpanEnd(span) && textSpanEnd(other) >= span.start; - } - ts.textSpanIntersectsWithTextSpan = textSpanIntersectsWithTextSpan; - function textSpanIntersectsWith(span, start, length) { - var end = start + length; - return start <= textSpanEnd(span) && end >= span.start; - } - ts.textSpanIntersectsWith = textSpanIntersectsWith; - function textSpanIntersectsWithPosition(span, position) { - return position <= textSpanEnd(span) && position >= span.start; - } - ts.textSpanIntersectsWithPosition = textSpanIntersectsWithPosition; - function textSpanIntersection(span1, span2) { - var intersectStart = Math.max(span1.start, span2.start); - var intersectEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2)); - if (intersectStart <= intersectEnd) { - return createTextSpanFromBounds(intersectStart, intersectEnd); - } - return undefined; - } - ts.textSpanIntersection = textSpanIntersection; - function createTextSpan(start, length) { - if (start < 0) { - throw new Error("start < 0"); - } - if (length < 0) { - throw new Error("length < 0"); - } - return { start: start, length: length }; - } - ts.createTextSpan = createTextSpan; - function createTextSpanFromBounds(start, end) { - return createTextSpan(start, end - start); - } - ts.createTextSpanFromBounds = createTextSpanFromBounds; - function textChangeRangeNewSpan(range) { - return createTextSpan(range.span.start, range.newLength); - } - ts.textChangeRangeNewSpan = textChangeRangeNewSpan; - function textChangeRangeIsUnchanged(range) { - return textSpanIsEmpty(range.span) && range.newLength === 0; - } - ts.textChangeRangeIsUnchanged = textChangeRangeIsUnchanged; - function createTextChangeRange(span, newLength) { - if (newLength < 0) { - throw new Error("newLength < 0"); - } - return { span: span, newLength: newLength }; - } - ts.createTextChangeRange = createTextChangeRange; - ts.unchangedTextChangeRange = createTextChangeRange(createTextSpan(0, 0), 0); - function collapseTextChangeRangesAcrossMultipleVersions(changes) { - if (changes.length === 0) { - return ts.unchangedTextChangeRange; - } - if (changes.length === 1) { - return changes[0]; - } - var change0 = changes[0]; - var oldStartN = change0.span.start; - var oldEndN = textSpanEnd(change0.span); - var newEndN = oldStartN + change0.newLength; - for (var i = 1; i < changes.length; i++) { - var nextChange = changes[i]; - var oldStart1 = oldStartN; - var oldEnd1 = oldEndN; - var newEnd1 = newEndN; - var oldStart2 = nextChange.span.start; - var oldEnd2 = textSpanEnd(nextChange.span); - var newEnd2 = oldStart2 + nextChange.newLength; - oldStartN = Math.min(oldStart1, oldStart2); - oldEndN = Math.max(oldEnd1, oldEnd1 + (oldEnd2 - newEnd1)); - newEndN = Math.max(newEnd2, newEnd2 + (newEnd1 - oldEnd2)); - } - return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), newEndN - oldStartN); - } - ts.collapseTextChangeRangesAcrossMultipleVersions = collapseTextChangeRangesAcrossMultipleVersions; function nodeStartsNewLexicalEnvironment(n) { return isFunctionLike(n) || n.kind === 205 || n.kind === 227; } @@ -4641,6 +4534,118 @@ var ts; } ts.getLocalSymbolForExportDefault = getLocalSymbolForExportDefault; })(ts || (ts = {})); +var ts; +(function (ts) { + function textSpanEnd(span) { + return span.start + span.length; + } + ts.textSpanEnd = textSpanEnd; + function textSpanIsEmpty(span) { + return span.length === 0; + } + ts.textSpanIsEmpty = textSpanIsEmpty; + function textSpanContainsPosition(span, position) { + return position >= span.start && position < textSpanEnd(span); + } + ts.textSpanContainsPosition = textSpanContainsPosition; + function textSpanContainsTextSpan(span, other) { + return other.start >= span.start && textSpanEnd(other) <= textSpanEnd(span); + } + ts.textSpanContainsTextSpan = textSpanContainsTextSpan; + function textSpanOverlapsWith(span, other) { + var overlapStart = Math.max(span.start, other.start); + var overlapEnd = Math.min(textSpanEnd(span), textSpanEnd(other)); + return overlapStart < overlapEnd; + } + ts.textSpanOverlapsWith = textSpanOverlapsWith; + function textSpanOverlap(span1, span2) { + var overlapStart = Math.max(span1.start, span2.start); + var overlapEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2)); + if (overlapStart < overlapEnd) { + return createTextSpanFromBounds(overlapStart, overlapEnd); + } + return undefined; + } + ts.textSpanOverlap = textSpanOverlap; + function textSpanIntersectsWithTextSpan(span, other) { + return other.start <= textSpanEnd(span) && textSpanEnd(other) >= span.start; + } + ts.textSpanIntersectsWithTextSpan = textSpanIntersectsWithTextSpan; + function textSpanIntersectsWith(span, start, length) { + var end = start + length; + return start <= textSpanEnd(span) && end >= span.start; + } + ts.textSpanIntersectsWith = textSpanIntersectsWith; + function textSpanIntersectsWithPosition(span, position) { + return position <= textSpanEnd(span) && position >= span.start; + } + ts.textSpanIntersectsWithPosition = textSpanIntersectsWithPosition; + function textSpanIntersection(span1, span2) { + var intersectStart = Math.max(span1.start, span2.start); + var intersectEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2)); + if (intersectStart <= intersectEnd) { + return createTextSpanFromBounds(intersectStart, intersectEnd); + } + return undefined; + } + ts.textSpanIntersection = textSpanIntersection; + function createTextSpan(start, length) { + if (start < 0) { + throw new Error("start < 0"); + } + if (length < 0) { + throw new Error("length < 0"); + } + return { start: start, length: length }; + } + ts.createTextSpan = createTextSpan; + function createTextSpanFromBounds(start, end) { + return createTextSpan(start, end - start); + } + ts.createTextSpanFromBounds = createTextSpanFromBounds; + function textChangeRangeNewSpan(range) { + return createTextSpan(range.span.start, range.newLength); + } + ts.textChangeRangeNewSpan = textChangeRangeNewSpan; + function textChangeRangeIsUnchanged(range) { + return textSpanIsEmpty(range.span) && range.newLength === 0; + } + ts.textChangeRangeIsUnchanged = textChangeRangeIsUnchanged; + function createTextChangeRange(span, newLength) { + if (newLength < 0) { + throw new Error("newLength < 0"); + } + return { span: span, newLength: newLength }; + } + ts.createTextChangeRange = createTextChangeRange; + ts.unchangedTextChangeRange = createTextChangeRange(createTextSpan(0, 0), 0); + function collapseTextChangeRangesAcrossMultipleVersions(changes) { + if (changes.length === 0) { + return ts.unchangedTextChangeRange; + } + if (changes.length === 1) { + return changes[0]; + } + var change0 = changes[0]; + var oldStartN = change0.span.start; + var oldEndN = textSpanEnd(change0.span); + var newEndN = oldStartN + change0.newLength; + for (var i = 1; i < changes.length; i++) { + var nextChange = changes[i]; + var oldStart1 = oldStartN; + var oldEnd1 = oldEndN; + var newEnd1 = newEndN; + var oldStart2 = nextChange.span.start; + var oldEnd2 = textSpanEnd(nextChange.span); + var newEnd2 = oldStart2 + nextChange.newLength; + oldStartN = Math.min(oldStart1, oldStart2); + oldEndN = Math.max(oldEnd1, oldEnd1 + (oldEnd2 - newEnd1)); + newEndN = Math.max(newEnd2, newEnd2 + (newEnd1 - oldEnd2)); + } + return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), newEndN - oldStartN); + } + ts.collapseTextChangeRangesAcrossMultipleVersions = collapseTextChangeRangesAcrossMultipleVersions; +})(ts || (ts = {})); /// /// var ts; @@ -5492,7 +5497,7 @@ var ts; if (token === 111 && inYieldContext()) { return false; } - return inStrictModeContext() ? token > 111 : token > 101; + return token > 101; } function parseExpected(kind, diagnosticMessage) { if (token === kind) { @@ -5586,6 +5591,9 @@ var ts; identifierCount++; if (isIdentifier) { var node = createNode(65); + if (token !== 65) { + node.originalKeywordKind = token; + } node.text = internIdentifier(scanner.getTokenValue()); nextToken(); return finishNode(node); @@ -7716,6 +7724,17 @@ var ts; node.body = parseFunctionBlockOrSemicolon(false); return finishNode(node); } + function isClassMemberModifier(idToken) { + switch (idToken) { + case 109: + case 107: + case 108: + case 110: + return true; + default: + return false; + } + } function isClassMemberStart() { var idToken; if (token === 52) { @@ -7723,6 +7742,9 @@ var ts; } while (ts.isModifier(token)) { idToken = token; + if (isClassMemberModifier(idToken)) { + return true; + } nextToken(); } if (token === 35) { @@ -14170,7 +14192,7 @@ var ts; } function checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper) { ts.Debug.assert(node.kind !== 134 || ts.isObjectLiteralMethod(node)); - var hasGrammarError = checkGrammarFunctionLikeDeclaration(node); + var hasGrammarError = checkGrammarDeclarationNameInStrictMode(node) || checkGrammarFunctionLikeDeclaration(node); if (!hasGrammarError && node.kind === 162) { checkGrammarFunctionName(node.name) || checkGrammarForGenerator(node); } @@ -14207,7 +14229,7 @@ var ts; } function checkFunctionExpressionOrObjectLiteralMethodBody(node) { ts.Debug.assert(node.kind !== 134 || ts.isObjectLiteralMethod(node)); - if (node.type) { + if (node.type && !node.asteriskToken) { checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNodeOrHeritageClauseElement(node.type)); } if (node.body) { @@ -14678,6 +14700,7 @@ var ts; return type; } function checkExpression(node, contextualMapper) { + checkGrammarIdentifierInStrictMode(node); return checkExpressionOrQualifiedName(node, contextualMapper); } function checkExpressionOrQualifiedName(node, contextualMapper) { @@ -14772,6 +14795,7 @@ var ts; return unknownType; } function checkTypeParameter(node) { + checkGrammarDeclarationNameInStrictMode(node); if (node.expression) { grammarErrorOnFirstToken(node.expression, ts.Diagnostics.Type_expected); } @@ -14974,9 +14998,11 @@ var ts; checkDecorators(node); } function checkTypeReferenceNode(node) { + checkGrammarTypeReferenceInStrictMode(node.typeName); return checkTypeReferenceOrHeritageClauseElement(node); } function checkHeritageClauseElement(node) { + checkGrammarHeritageClauseElementInStrictMode(node.expression); return checkTypeReferenceOrHeritageClauseElement(node); } function checkTypeReferenceOrHeritageClauseElement(node) { @@ -15379,6 +15405,7 @@ var ts; } } function checkFunctionLikeDeclaration(node) { + checkGrammarDeclarationNameInStrictMode(node); checkDecorators(node); checkSignatureDeclaration(node); if (node.name && node.name.kind === 127) { @@ -15398,7 +15425,7 @@ var ts; } } checkSourceElement(node.body); - if (node.type && !isAccessor(node.kind)) { + if (node.type && !isAccessor(node.kind) && !node.asteriskToken) { checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNodeOrHeritageClauseElement(node.type)); } if (compilerOptions.noImplicitAny && ts.nodeIsMissing(node.body) && !node.type && !isPrivateWithinAmbient(node)) { @@ -15564,6 +15591,7 @@ var ts; } } function checkVariableLikeDeclaration(node) { + checkGrammarDeclarationNameInStrictMode(node); checkDecorators(node); checkSourceElement(node.type); if (node.name.kind === 127) { @@ -16087,6 +16115,7 @@ var ts; return unknownType; } function checkClassDeclaration(node) { + checkGrammarDeclarationNameInStrictMode(node); if (node.parent.kind !== 206 && node.parent.kind !== 227) { grammarErrorOnNode(node, ts.Diagnostics.class_declarations_are_only_supported_directly_inside_a_module_or_as_a_top_level_declaration); } @@ -16275,7 +16304,7 @@ var ts; return ok; } function checkInterfaceDeclaration(node) { - checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node); + checkGrammarDeclarationNameInStrictMode(node) || checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node); checkTypeParameters(node.typeParameters); if (produceDiagnostics) { checkTypeNameIsReserved(node.name, ts.Diagnostics.Interface_name_cannot_be_0); @@ -16461,7 +16490,7 @@ var ts; if (!produceDiagnostics) { return; } - checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); + checkGrammarDeclarationNameInStrictMode(node) || checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); checkTypeNameIsReserved(node.name, ts.Diagnostics.Enum_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); @@ -16514,7 +16543,7 @@ var ts; } function checkModuleDeclaration(node) { if (produceDiagnostics) { - if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node)) { + if (!checkGrammarDeclarationNameInStrictMode(node) && !checkGrammarDecorators(node) && !checkGrammarModifiers(node)) { if (!ts.isInAmbientContext(node) && node.name.kind === 8) { grammarErrorOnNode(node.name, ts.Diagnostics.Only_ambient_modules_can_use_quoted_names); } @@ -16603,7 +16632,7 @@ var ts; checkAliasSymbol(node); } function checkImportDeclaration(node) { - if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & 499)) { + if (!checkGrammarImportDeclarationNameInStrictMode(node) && !checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & 499)) { grammarErrorOnFirstToken(node, ts.Diagnostics.An_import_declaration_cannot_have_modifiers); } if (checkExternalImportOrExportDeclaration(node)) { @@ -16624,7 +16653,7 @@ var ts; } } function checkImportEqualsDeclaration(node) { - checkGrammarDecorators(node) || checkGrammarModifiers(node); + checkGrammarDeclarationNameInStrictMode(node) || checkGrammarDecorators(node) || checkGrammarModifiers(node); if (ts.isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) { checkImportBinding(node); if (node.flags & 1) { @@ -16925,6 +16954,8 @@ var ts; if (!(links.flags & 1)) { checkGrammarSourceFile(node); emitExtends = false; + emitDecorate = false; + emitParam = false; potentialThisCollisions.length = 0; ts.forEach(node.statements, checkSourceElement); checkFunctionExpressionBodies(node); @@ -17732,6 +17763,105 @@ var ts; } anyArrayType = createArrayType(anyType); } + function isReservedwordInStrictMode(node) { + return (node.parserContextFlags & 1) && + (node.originalKeywordKind >= 103 && node.originalKeywordKind <= 111); + } + function reportStrictModeGrammarErrorInClassDeclaration(identifier, message, arg0, arg1, arg2) { + if (ts.getAncestor(identifier, 201) || ts.getAncestor(identifier, 174)) { + return grammarErrorOnNode(identifier, message, arg0); + } + return false; + } + function checkGrammarImportDeclarationNameInStrictMode(node) { + if (node.importClause) { + var impotClause = node.importClause; + if (impotClause.namedBindings) { + var nameBindings = impotClause.namedBindings; + if (nameBindings.kind === 211) { + var name_11 = nameBindings.name; + if (name_11.originalKeywordKind) { + var nameText = ts.declarationNameToString(name_11); + return grammarErrorOnNode(name_11, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + } + } + else if (nameBindings.kind === 212) { + var reportError = false; + for (var _i = 0, _a = nameBindings.elements; _i < _a.length; _i++) { + var element = _a[_i]; + var name_12 = element.name; + if (name_12.originalKeywordKind) { + var nameText = ts.declarationNameToString(name_12); + reportError = reportError || grammarErrorOnNode(name_12, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + } + } + return reportError; + } + } + } + return false; + } + function checkGrammarDeclarationNameInStrictMode(node) { + var name = node.name; + if (name && name.kind === 65 && isReservedwordInStrictMode(name)) { + var nameText = ts.declarationNameToString(name); + switch (node.kind) { + case 129: + case 198: + case 200: + case 128: + case 152: + case 202: + case 203: + case 204: + return checkGrammarIdentifierInStrictMode(name); + case 201: + return grammarErrorOnNode(name, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText); + case 205: + return grammarErrorOnNode(name, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + case 208: + return grammarErrorOnNode(name, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + } + } + return false; + } + function checkGrammarTypeReferenceInStrictMode(typeName) { + if (typeName.kind === 65) { + checkGrammarTypeNameInStrictMode(typeName); + } + else if (typeName.kind === 126) { + checkGrammarTypeNameInStrictMode(typeName.right); + checkGrammarTypeReferenceInStrictMode(typeName.left); + } + } + function checkGrammarHeritageClauseElementInStrictMode(expression) { + if (expression && expression.kind === 65) { + return checkGrammarIdentifierInStrictMode(expression); + } + else if (expression && expression.kind === 155) { + checkGrammarHeritageClauseElementInStrictMode(expression.expression); + } + } + function checkGrammarIdentifierInStrictMode(node, nameText) { + if (node && node.kind === 65 && isReservedwordInStrictMode(node)) { + if (!nameText) { + nameText = ts.declarationNameToString(node); + } + var errorReport = reportStrictModeGrammarErrorInClassDeclaration(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText) || + grammarErrorOnNode(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + return errorReport; + } + return false; + } + function checkGrammarTypeNameInStrictMode(node) { + if (node && node.kind === 65 && isReservedwordInStrictMode(node)) { + var nameText = ts.declarationNameToString(node); + var errorReport = reportStrictModeGrammarErrorInClassDeclaration(node, ts.Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText) || + grammarErrorOnNode(node, ts.Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode, nameText); + return errorReport; + } + return false; + } function checkGrammarDecorators(node) { if (!node.decorators) { return false; @@ -18101,17 +18231,17 @@ var ts; var inStrictMode = (node.parserContextFlags & 1) !== 0; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; - var name_11 = prop.name; + var name_13 = prop.name; if (prop.kind === 175 || - name_11.kind === 127) { - checkGrammarComputedPropertyName(name_11); + name_13.kind === 127) { + checkGrammarComputedPropertyName(name_13); continue; } var currentKind = void 0; if (prop.kind === 224 || prop.kind === 225) { checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); - if (name_11.kind === 7) { - checkGrammarNumbericLiteral(name_11); + if (name_13.kind === 7) { + checkGrammarNumbericLiteral(name_13); } currentKind = Property; } @@ -18127,26 +18257,26 @@ var ts; else { ts.Debug.fail("Unexpected syntax kind:" + prop.kind); } - if (!ts.hasProperty(seen, name_11.text)) { - seen[name_11.text] = currentKind; + if (!ts.hasProperty(seen, name_13.text)) { + seen[name_13.text] = currentKind; } else { - var existingKind = seen[name_11.text]; + var existingKind = seen[name_13.text]; if (currentKind === Property && existingKind === Property) { if (inStrictMode) { - grammarErrorOnNode(name_11, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); + grammarErrorOnNode(name_13, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); } } else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name_11.text] = currentKind | existingKind; + seen[name_13.text] = currentKind | existingKind; } else { - return grammarErrorOnNode(name_11, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); + return grammarErrorOnNode(name_13, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); } } else { - return grammarErrorOnNode(name_11, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + return grammarErrorOnNode(name_13, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); } } } @@ -18465,12 +18595,11 @@ var ts; var identifier = name; if (contextNode && (contextNode.parserContextFlags & 1) && ts.isEvalOrArgumentsIdentifier(identifier)) { var nameText = ts.declarationNameToString(identifier); - if (ts.getAncestor(name, 201) || ts.getAncestor(name, 174)) { - return grammarErrorOnNode(identifier, ts.Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode, nameText); - } - else { + var reportErrorInClassDeclaration = reportStrictModeGrammarErrorInClassDeclaration(identifier, ts.Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode, nameText); + if (!reportErrorInClassDeclaration) { return grammarErrorOnNode(identifier, ts.Diagnostics.Invalid_use_of_0_in_strict_mode, nameText); } + return reportErrorInClassDeclaration; } } } @@ -18919,9 +19048,9 @@ var ts; } var count = 0; while (true) { - var name_12 = baseName + "_" + (++count); - if (!ts.hasProperty(currentSourceFile.identifiers, name_12)) { - return name_12; + var name_14 = baseName + "_" + (++count); + if (!ts.hasProperty(currentSourceFile.identifiers, name_14)) { + return name_14; } } } @@ -20003,9 +20132,9 @@ var ts; var count = tempFlags & 268435455; tempFlags++; if (count !== 8 && count !== 13) { - var name_13 = count < 26 ? "_" + String.fromCharCode(97 + count) : "_" + (count - 26); - if (isUniqueName(name_13)) { - return name_13; + var name_15 = count < 26 ? "_" + String.fromCharCode(97 + count) : "_" + (count - 26); + if (isUniqueName(name_15)) { + return name_15; } } } @@ -20033,8 +20162,8 @@ var ts; } function generateNameForModuleOrEnum(node) { if (node.name.kind === 65) { - var name_14 = node.name.text; - assignGeneratedName(node, isUniqueLocalName(name_14, node) ? name_14 : makeUniqueName(name_14)); + var name_16 = node.name.text; + assignGeneratedName(node, isUniqueLocalName(name_16, node) ? name_16 : makeUniqueName(name_16)); } } function generateNameForImportOrExportDeclaration(node) { @@ -20214,8 +20343,8 @@ var ts; if (scopeName) { var parentIndex = getSourceMapNameIndex(); if (parentIndex !== -1) { - var name_15 = node.name; - if (!name_15 || name_15.kind !== 127) { + var name_17 = node.name; + if (!name_17 || name_17.kind !== 127) { scopeName = "." + scopeName; } scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; @@ -20242,9 +20371,9 @@ var ts; node.kind === 201 || node.kind === 204) { if (node.name) { - var name_16 = node.name; - scopeName = name_16.kind === 127 - ? ts.getTextOfNode(name_16) + var name_18 = node.name; + scopeName = name_18.kind === 127 + ? ts.getTextOfNode(name_18) : node.name.text; } recordScopeNameStart(scopeName); @@ -20657,6 +20786,7 @@ var ts; default: return -1; } + case 172: case 170: return -1; default: @@ -20828,6 +20958,16 @@ var ts; write("..."); emit(node.expression); } + function emitYieldExpression(node) { + write(ts.tokenToString(111)); + if (node.asteriskToken) { + write("*"); + } + if (node.expression) { + write(" "); + emit(node.expression); + } + } function needsParenthesisForPropertyAccessOrInvocation(node) { switch (node.kind) { case 65: @@ -21069,6 +21209,9 @@ var ts; write("]"); } function emitMethod(node) { + if (languageVersion >= 2 && node.asteriskToken) { + write("*"); + } emit(node.name, false); if (languageVersion < 2) { write(": function "); @@ -22054,12 +22197,12 @@ var ts; function emitParameter(node) { if (languageVersion < 2) { if (ts.isBindingPattern(node.name)) { - var name_17 = createTempVariable(0); + var name_19 = createTempVariable(0); if (!tempParameters) { tempParameters = []; } - tempParameters.push(name_17); - emit(name_17); + tempParameters.push(name_19); + emit(name_19); } else { emit(node.name); @@ -22178,7 +22321,11 @@ var ts; write("default "); } } - write("function "); + write("function"); + if (languageVersion >= 2 && node.asteriskToken) { + write("*"); + } + write(" "); } if (shouldEmitFunctionName(node)) { emitDeclarationName(node); @@ -22510,6 +22657,9 @@ var ts; else if (member.kind === 137) { write("set "); } + if (member.asteriskToken) { + write("*"); + } emit(member.name); emitSignatureAndBody(member); emitEnd(member); @@ -23475,8 +23625,8 @@ var ts; else { for (var _c = 0, _d = node.exportClause.elements; _c < _d.length; _c++) { var specifier = _d[_c]; - var name_18 = (specifier.propertyName || specifier.name).text; - (exportSpecifiers[name_18] || (exportSpecifiers[name_18] = [])).push(specifier); + var name_20 = (specifier.propertyName || specifier.name).text; + (exportSpecifiers[name_20] || (exportSpecifiers[name_20] = [])).push(specifier); } } break; @@ -23787,6 +23937,8 @@ var ts; return emitConditionalExpression(node); case 173: return emitSpreadElementExpression(node); + case 172: + return emitYieldExpression(node); case 175: return; case 179: @@ -24060,7 +24212,7 @@ var ts; } return { getSourceFile: getSourceFile, - getDefaultLibFileName: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), ts.getDefaultLibFileName(options)); }, + getDefaultLibFileName: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), getDefaultLibFileName(options)); }, writeFile: writeFile, getCurrentDirectory: function () { return currentDirectory || (currentDirectory = ts.sys.getCurrentDirectory()); }, useCaseSensitiveFileNames: function () { return ts.sys.useCaseSensitiveFileNames; }, @@ -24100,6 +24252,10 @@ var ts; } } ts.flattenDiagnosticMessageText = flattenDiagnosticMessageText; + function getDefaultLibFileName(options) { + return options.target === 2 ? "lib.es6.d.ts" : "lib.d.ts"; + } + ts.getDefaultLibFileName = getDefaultLibFileName; function createProgram(rootNames, options, host) { var program; var files = []; diff --git a/bin/tsserver.js b/bin/tsserver.js index ba3c349c046d9..e8f4bd1398a31 100644 --- a/bin/tsserver.js +++ b/bin/tsserver.js @@ -600,10 +600,6 @@ var ts; "\u2029": "\\u2029", "\u0085": "\\u0085" }; - function getDefaultLibFileName(options) { - return options.target === 2 ? "lib.es6.d.ts" : "lib.d.ts"; - } - ts.getDefaultLibFileName = getDefaultLibFileName; function Symbol(flags, name) { this.flags = flags; this.name = name; @@ -1076,6 +1072,12 @@ var ts; Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided: { code: 1209, category: ts.DiagnosticCategory.Error, key: "Ambient const enums are not allowed when the '--separateCompilation' flag is provided." }, Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode: { code: 1210, category: ts.DiagnosticCategory.Error, key: "Invalid use of '{0}'. Class definitions are automatically in strict mode." }, A_class_declaration_without_the_default_modifier_must_have_a_name: { code: 1211, category: ts.DiagnosticCategory.Error, key: "A class declaration without the 'default' modifier must have a name" }, + Identifier_expected_0_is_a_reserved_word_in_strict_mode: { code: 1212, category: ts.DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode" }, + Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1213, category: ts.DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." }, + Identifier_expected_0_is_a_reserved_word_in_strict_mode_External_Module_is_automatically_in_strict_mode: { code: 1214, category: ts.DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode. External Module is automatically in strict mode." }, + Type_expected_0_is_a_reserved_word_in_strict_mode: { code: 1215, category: ts.DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode" }, + Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1216, category: ts.DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." }, + Type_expected_0_is_a_reserved_word_in_strict_mode_Module_is_automatically_in_strict_mode: { code: 1217, category: ts.DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Module is automatically in strict mode." }, Duplicate_identifier_0: { code: 2300, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: ts.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: ts.DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, @@ -3217,7 +3219,7 @@ var ts; scanner.setTextPos(pos); scanner.scan(); var start = scanner.getTokenPos(); - return createTextSpanFromBounds(start, scanner.getTextPos()); + return ts.createTextSpanFromBounds(start, scanner.getTextPos()); } ts.getSpanOfTokenAtPosition = getSpanOfTokenAtPosition; function getErrorSpanForNode(sourceFile, node) { @@ -3226,7 +3228,7 @@ var ts; case 227: var pos_1 = ts.skipTrivia(sourceFile.text, 0, false); if (pos_1 === sourceFile.text.length) { - return createTextSpan(0, 0); + return ts.createTextSpan(0, 0); } return getSpanOfTokenAtPosition(sourceFile, pos_1); case 198: @@ -3248,7 +3250,7 @@ var ts; var pos = nodeIsMissing(errorNode) ? errorNode.pos : ts.skipTrivia(sourceFile.text, errorNode.pos); - return createTextSpanFromBounds(pos, errorNode.end); + return ts.createTextSpanFromBounds(pos, errorNode.end); } ts.getErrorSpanForNode = getErrorSpanForNode; function isExternalModule(file) { @@ -3970,115 +3972,6 @@ var ts; return false; } ts.isModifier = isModifier; - function textSpanEnd(span) { - return span.start + span.length; - } - ts.textSpanEnd = textSpanEnd; - function textSpanIsEmpty(span) { - return span.length === 0; - } - ts.textSpanIsEmpty = textSpanIsEmpty; - function textSpanContainsPosition(span, position) { - return position >= span.start && position < textSpanEnd(span); - } - ts.textSpanContainsPosition = textSpanContainsPosition; - function textSpanContainsTextSpan(span, other) { - return other.start >= span.start && textSpanEnd(other) <= textSpanEnd(span); - } - ts.textSpanContainsTextSpan = textSpanContainsTextSpan; - function textSpanOverlapsWith(span, other) { - var overlapStart = Math.max(span.start, other.start); - var overlapEnd = Math.min(textSpanEnd(span), textSpanEnd(other)); - return overlapStart < overlapEnd; - } - ts.textSpanOverlapsWith = textSpanOverlapsWith; - function textSpanOverlap(span1, span2) { - var overlapStart = Math.max(span1.start, span2.start); - var overlapEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2)); - if (overlapStart < overlapEnd) { - return createTextSpanFromBounds(overlapStart, overlapEnd); - } - return undefined; - } - ts.textSpanOverlap = textSpanOverlap; - function textSpanIntersectsWithTextSpan(span, other) { - return other.start <= textSpanEnd(span) && textSpanEnd(other) >= span.start; - } - ts.textSpanIntersectsWithTextSpan = textSpanIntersectsWithTextSpan; - function textSpanIntersectsWith(span, start, length) { - var end = start + length; - return start <= textSpanEnd(span) && end >= span.start; - } - ts.textSpanIntersectsWith = textSpanIntersectsWith; - function textSpanIntersectsWithPosition(span, position) { - return position <= textSpanEnd(span) && position >= span.start; - } - ts.textSpanIntersectsWithPosition = textSpanIntersectsWithPosition; - function textSpanIntersection(span1, span2) { - var intersectStart = Math.max(span1.start, span2.start); - var intersectEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2)); - if (intersectStart <= intersectEnd) { - return createTextSpanFromBounds(intersectStart, intersectEnd); - } - return undefined; - } - ts.textSpanIntersection = textSpanIntersection; - function createTextSpan(start, length) { - if (start < 0) { - throw new Error("start < 0"); - } - if (length < 0) { - throw new Error("length < 0"); - } - return { start: start, length: length }; - } - ts.createTextSpan = createTextSpan; - function createTextSpanFromBounds(start, end) { - return createTextSpan(start, end - start); - } - ts.createTextSpanFromBounds = createTextSpanFromBounds; - function textChangeRangeNewSpan(range) { - return createTextSpan(range.span.start, range.newLength); - } - ts.textChangeRangeNewSpan = textChangeRangeNewSpan; - function textChangeRangeIsUnchanged(range) { - return textSpanIsEmpty(range.span) && range.newLength === 0; - } - ts.textChangeRangeIsUnchanged = textChangeRangeIsUnchanged; - function createTextChangeRange(span, newLength) { - if (newLength < 0) { - throw new Error("newLength < 0"); - } - return { span: span, newLength: newLength }; - } - ts.createTextChangeRange = createTextChangeRange; - ts.unchangedTextChangeRange = createTextChangeRange(createTextSpan(0, 0), 0); - function collapseTextChangeRangesAcrossMultipleVersions(changes) { - if (changes.length === 0) { - return ts.unchangedTextChangeRange; - } - if (changes.length === 1) { - return changes[0]; - } - var change0 = changes[0]; - var oldStartN = change0.span.start; - var oldEndN = textSpanEnd(change0.span); - var newEndN = oldStartN + change0.newLength; - for (var i = 1; i < changes.length; i++) { - var nextChange = changes[i]; - var oldStart1 = oldStartN; - var oldEnd1 = oldEndN; - var newEnd1 = newEndN; - var oldStart2 = nextChange.span.start; - var oldEnd2 = textSpanEnd(nextChange.span); - var newEnd2 = oldStart2 + nextChange.newLength; - oldStartN = Math.min(oldStart1, oldStart2); - oldEndN = Math.max(oldEnd1, oldEnd1 + (oldEnd2 - newEnd1)); - newEndN = Math.max(newEnd2, newEnd2 + (newEnd1 - oldEnd2)); - } - return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), newEndN - oldStartN); - } - ts.collapseTextChangeRangesAcrossMultipleVersions = collapseTextChangeRangesAcrossMultipleVersions; function nodeStartsNewLexicalEnvironment(n) { return isFunctionLike(n) || n.kind === 205 || n.kind === 227; } @@ -4475,6 +4368,118 @@ var ts; } ts.getLocalSymbolForExportDefault = getLocalSymbolForExportDefault; })(ts || (ts = {})); +var ts; +(function (ts) { + function textSpanEnd(span) { + return span.start + span.length; + } + ts.textSpanEnd = textSpanEnd; + function textSpanIsEmpty(span) { + return span.length === 0; + } + ts.textSpanIsEmpty = textSpanIsEmpty; + function textSpanContainsPosition(span, position) { + return position >= span.start && position < textSpanEnd(span); + } + ts.textSpanContainsPosition = textSpanContainsPosition; + function textSpanContainsTextSpan(span, other) { + return other.start >= span.start && textSpanEnd(other) <= textSpanEnd(span); + } + ts.textSpanContainsTextSpan = textSpanContainsTextSpan; + function textSpanOverlapsWith(span, other) { + var overlapStart = Math.max(span.start, other.start); + var overlapEnd = Math.min(textSpanEnd(span), textSpanEnd(other)); + return overlapStart < overlapEnd; + } + ts.textSpanOverlapsWith = textSpanOverlapsWith; + function textSpanOverlap(span1, span2) { + var overlapStart = Math.max(span1.start, span2.start); + var overlapEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2)); + if (overlapStart < overlapEnd) { + return createTextSpanFromBounds(overlapStart, overlapEnd); + } + return undefined; + } + ts.textSpanOverlap = textSpanOverlap; + function textSpanIntersectsWithTextSpan(span, other) { + return other.start <= textSpanEnd(span) && textSpanEnd(other) >= span.start; + } + ts.textSpanIntersectsWithTextSpan = textSpanIntersectsWithTextSpan; + function textSpanIntersectsWith(span, start, length) { + var end = start + length; + return start <= textSpanEnd(span) && end >= span.start; + } + ts.textSpanIntersectsWith = textSpanIntersectsWith; + function textSpanIntersectsWithPosition(span, position) { + return position <= textSpanEnd(span) && position >= span.start; + } + ts.textSpanIntersectsWithPosition = textSpanIntersectsWithPosition; + function textSpanIntersection(span1, span2) { + var intersectStart = Math.max(span1.start, span2.start); + var intersectEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2)); + if (intersectStart <= intersectEnd) { + return createTextSpanFromBounds(intersectStart, intersectEnd); + } + return undefined; + } + ts.textSpanIntersection = textSpanIntersection; + function createTextSpan(start, length) { + if (start < 0) { + throw new Error("start < 0"); + } + if (length < 0) { + throw new Error("length < 0"); + } + return { start: start, length: length }; + } + ts.createTextSpan = createTextSpan; + function createTextSpanFromBounds(start, end) { + return createTextSpan(start, end - start); + } + ts.createTextSpanFromBounds = createTextSpanFromBounds; + function textChangeRangeNewSpan(range) { + return createTextSpan(range.span.start, range.newLength); + } + ts.textChangeRangeNewSpan = textChangeRangeNewSpan; + function textChangeRangeIsUnchanged(range) { + return textSpanIsEmpty(range.span) && range.newLength === 0; + } + ts.textChangeRangeIsUnchanged = textChangeRangeIsUnchanged; + function createTextChangeRange(span, newLength) { + if (newLength < 0) { + throw new Error("newLength < 0"); + } + return { span: span, newLength: newLength }; + } + ts.createTextChangeRange = createTextChangeRange; + ts.unchangedTextChangeRange = createTextChangeRange(createTextSpan(0, 0), 0); + function collapseTextChangeRangesAcrossMultipleVersions(changes) { + if (changes.length === 0) { + return ts.unchangedTextChangeRange; + } + if (changes.length === 1) { + return changes[0]; + } + var change0 = changes[0]; + var oldStartN = change0.span.start; + var oldEndN = textSpanEnd(change0.span); + var newEndN = oldStartN + change0.newLength; + for (var i = 1; i < changes.length; i++) { + var nextChange = changes[i]; + var oldStart1 = oldStartN; + var oldEnd1 = oldEndN; + var newEnd1 = newEndN; + var oldStart2 = nextChange.span.start; + var oldEnd2 = textSpanEnd(nextChange.span); + var newEnd2 = oldStart2 + nextChange.newLength; + oldStartN = Math.min(oldStart1, oldStart2); + oldEndN = Math.max(oldEnd1, oldEnd1 + (oldEnd2 - newEnd1)); + newEndN = Math.max(newEnd2, newEnd2 + (newEnd1 - oldEnd2)); + } + return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), newEndN - oldStartN); + } + ts.collapseTextChangeRangesAcrossMultipleVersions = collapseTextChangeRangesAcrossMultipleVersions; +})(ts || (ts = {})); /// /// var ts; @@ -5326,7 +5331,7 @@ var ts; if (token === 111 && inYieldContext()) { return false; } - return inStrictModeContext() ? token > 111 : token > 101; + return token > 101; } function parseExpected(kind, diagnosticMessage) { if (token === kind) { @@ -5420,6 +5425,9 @@ var ts; identifierCount++; if (isIdentifier) { var node = createNode(65); + if (token !== 65) { + node.originalKeywordKind = token; + } node.text = internIdentifier(scanner.getTokenValue()); nextToken(); return finishNode(node); @@ -7550,6 +7558,17 @@ var ts; node.body = parseFunctionBlockOrSemicolon(false); return finishNode(node); } + function isClassMemberModifier(idToken) { + switch (idToken) { + case 109: + case 107: + case 108: + case 110: + return true; + default: + return false; + } + } function isClassMemberStart() { var idToken; if (token === 52) { @@ -7557,6 +7576,9 @@ var ts; } while (ts.isModifier(token)) { idToken = token; + if (isClassMemberModifier(idToken)) { + return true; + } nextToken(); } if (token === 35) { @@ -14513,7 +14535,7 @@ var ts; } function checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper) { ts.Debug.assert(node.kind !== 134 || ts.isObjectLiteralMethod(node)); - var hasGrammarError = checkGrammarFunctionLikeDeclaration(node); + var hasGrammarError = checkGrammarDeclarationNameInStrictMode(node) || checkGrammarFunctionLikeDeclaration(node); if (!hasGrammarError && node.kind === 162) { checkGrammarFunctionName(node.name) || checkGrammarForGenerator(node); } @@ -14550,7 +14572,7 @@ var ts; } function checkFunctionExpressionOrObjectLiteralMethodBody(node) { ts.Debug.assert(node.kind !== 134 || ts.isObjectLiteralMethod(node)); - if (node.type) { + if (node.type && !node.asteriskToken) { checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNodeOrHeritageClauseElement(node.type)); } if (node.body) { @@ -15021,6 +15043,7 @@ var ts; return type; } function checkExpression(node, contextualMapper) { + checkGrammarIdentifierInStrictMode(node); return checkExpressionOrQualifiedName(node, contextualMapper); } function checkExpressionOrQualifiedName(node, contextualMapper) { @@ -15115,6 +15138,7 @@ var ts; return unknownType; } function checkTypeParameter(node) { + checkGrammarDeclarationNameInStrictMode(node); if (node.expression) { grammarErrorOnFirstToken(node.expression, ts.Diagnostics.Type_expected); } @@ -15317,9 +15341,11 @@ var ts; checkDecorators(node); } function checkTypeReferenceNode(node) { + checkGrammarTypeReferenceInStrictMode(node.typeName); return checkTypeReferenceOrHeritageClauseElement(node); } function checkHeritageClauseElement(node) { + checkGrammarHeritageClauseElementInStrictMode(node.expression); return checkTypeReferenceOrHeritageClauseElement(node); } function checkTypeReferenceOrHeritageClauseElement(node) { @@ -15722,6 +15748,7 @@ var ts; } } function checkFunctionLikeDeclaration(node) { + checkGrammarDeclarationNameInStrictMode(node); checkDecorators(node); checkSignatureDeclaration(node); if (node.name && node.name.kind === 127) { @@ -15741,7 +15768,7 @@ var ts; } } checkSourceElement(node.body); - if (node.type && !isAccessor(node.kind)) { + if (node.type && !isAccessor(node.kind) && !node.asteriskToken) { checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNodeOrHeritageClauseElement(node.type)); } if (compilerOptions.noImplicitAny && ts.nodeIsMissing(node.body) && !node.type && !isPrivateWithinAmbient(node)) { @@ -15907,6 +15934,7 @@ var ts; } } function checkVariableLikeDeclaration(node) { + checkGrammarDeclarationNameInStrictMode(node); checkDecorators(node); checkSourceElement(node.type); if (node.name.kind === 127) { @@ -16430,6 +16458,7 @@ var ts; return unknownType; } function checkClassDeclaration(node) { + checkGrammarDeclarationNameInStrictMode(node); if (node.parent.kind !== 206 && node.parent.kind !== 227) { grammarErrorOnNode(node, ts.Diagnostics.class_declarations_are_only_supported_directly_inside_a_module_or_as_a_top_level_declaration); } @@ -16618,7 +16647,7 @@ var ts; return ok; } function checkInterfaceDeclaration(node) { - checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node); + checkGrammarDeclarationNameInStrictMode(node) || checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node); checkTypeParameters(node.typeParameters); if (produceDiagnostics) { checkTypeNameIsReserved(node.name, ts.Diagnostics.Interface_name_cannot_be_0); @@ -16804,7 +16833,7 @@ var ts; if (!produceDiagnostics) { return; } - checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); + checkGrammarDeclarationNameInStrictMode(node) || checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); checkTypeNameIsReserved(node.name, ts.Diagnostics.Enum_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); @@ -16857,7 +16886,7 @@ var ts; } function checkModuleDeclaration(node) { if (produceDiagnostics) { - if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node)) { + if (!checkGrammarDeclarationNameInStrictMode(node) && !checkGrammarDecorators(node) && !checkGrammarModifiers(node)) { if (!ts.isInAmbientContext(node) && node.name.kind === 8) { grammarErrorOnNode(node.name, ts.Diagnostics.Only_ambient_modules_can_use_quoted_names); } @@ -16946,7 +16975,7 @@ var ts; checkAliasSymbol(node); } function checkImportDeclaration(node) { - if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & 499)) { + if (!checkGrammarImportDeclarationNameInStrictMode(node) && !checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & 499)) { grammarErrorOnFirstToken(node, ts.Diagnostics.An_import_declaration_cannot_have_modifiers); } if (checkExternalImportOrExportDeclaration(node)) { @@ -16967,7 +16996,7 @@ var ts; } } function checkImportEqualsDeclaration(node) { - checkGrammarDecorators(node) || checkGrammarModifiers(node); + checkGrammarDeclarationNameInStrictMode(node) || checkGrammarDecorators(node) || checkGrammarModifiers(node); if (ts.isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) { checkImportBinding(node); if (node.flags & 1) { @@ -17268,6 +17297,8 @@ var ts; if (!(links.flags & 1)) { checkGrammarSourceFile(node); emitExtends = false; + emitDecorate = false; + emitParam = false; potentialThisCollisions.length = 0; ts.forEach(node.statements, checkSourceElement); checkFunctionExpressionBodies(node); @@ -18075,6 +18106,105 @@ var ts; } anyArrayType = createArrayType(anyType); } + function isReservedwordInStrictMode(node) { + return (node.parserContextFlags & 1) && + (node.originalKeywordKind >= 103 && node.originalKeywordKind <= 111); + } + function reportStrictModeGrammarErrorInClassDeclaration(identifier, message, arg0, arg1, arg2) { + if (ts.getAncestor(identifier, 201) || ts.getAncestor(identifier, 174)) { + return grammarErrorOnNode(identifier, message, arg0); + } + return false; + } + function checkGrammarImportDeclarationNameInStrictMode(node) { + if (node.importClause) { + var impotClause = node.importClause; + if (impotClause.namedBindings) { + var nameBindings = impotClause.namedBindings; + if (nameBindings.kind === 211) { + var name_11 = nameBindings.name; + if (name_11.originalKeywordKind) { + var nameText = ts.declarationNameToString(name_11); + return grammarErrorOnNode(name_11, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + } + } + else if (nameBindings.kind === 212) { + var reportError = false; + for (var _i = 0, _a = nameBindings.elements; _i < _a.length; _i++) { + var element = _a[_i]; + var name_12 = element.name; + if (name_12.originalKeywordKind) { + var nameText = ts.declarationNameToString(name_12); + reportError = reportError || grammarErrorOnNode(name_12, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + } + } + return reportError; + } + } + } + return false; + } + function checkGrammarDeclarationNameInStrictMode(node) { + var name = node.name; + if (name && name.kind === 65 && isReservedwordInStrictMode(name)) { + var nameText = ts.declarationNameToString(name); + switch (node.kind) { + case 129: + case 198: + case 200: + case 128: + case 152: + case 202: + case 203: + case 204: + return checkGrammarIdentifierInStrictMode(name); + case 201: + return grammarErrorOnNode(name, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText); + case 205: + return grammarErrorOnNode(name, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + case 208: + return grammarErrorOnNode(name, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + } + } + return false; + } + function checkGrammarTypeReferenceInStrictMode(typeName) { + if (typeName.kind === 65) { + checkGrammarTypeNameInStrictMode(typeName); + } + else if (typeName.kind === 126) { + checkGrammarTypeNameInStrictMode(typeName.right); + checkGrammarTypeReferenceInStrictMode(typeName.left); + } + } + function checkGrammarHeritageClauseElementInStrictMode(expression) { + if (expression && expression.kind === 65) { + return checkGrammarIdentifierInStrictMode(expression); + } + else if (expression && expression.kind === 155) { + checkGrammarHeritageClauseElementInStrictMode(expression.expression); + } + } + function checkGrammarIdentifierInStrictMode(node, nameText) { + if (node && node.kind === 65 && isReservedwordInStrictMode(node)) { + if (!nameText) { + nameText = ts.declarationNameToString(node); + } + var errorReport = reportStrictModeGrammarErrorInClassDeclaration(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText) || + grammarErrorOnNode(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + return errorReport; + } + return false; + } + function checkGrammarTypeNameInStrictMode(node) { + if (node && node.kind === 65 && isReservedwordInStrictMode(node)) { + var nameText = ts.declarationNameToString(node); + var errorReport = reportStrictModeGrammarErrorInClassDeclaration(node, ts.Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText) || + grammarErrorOnNode(node, ts.Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode, nameText); + return errorReport; + } + return false; + } function checkGrammarDecorators(node) { if (!node.decorators) { return false; @@ -18444,17 +18574,17 @@ var ts; var inStrictMode = (node.parserContextFlags & 1) !== 0; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; - var name_11 = prop.name; + var name_13 = prop.name; if (prop.kind === 175 || - name_11.kind === 127) { - checkGrammarComputedPropertyName(name_11); + name_13.kind === 127) { + checkGrammarComputedPropertyName(name_13); continue; } var currentKind = void 0; if (prop.kind === 224 || prop.kind === 225) { checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); - if (name_11.kind === 7) { - checkGrammarNumbericLiteral(name_11); + if (name_13.kind === 7) { + checkGrammarNumbericLiteral(name_13); } currentKind = Property; } @@ -18470,26 +18600,26 @@ var ts; else { ts.Debug.fail("Unexpected syntax kind:" + prop.kind); } - if (!ts.hasProperty(seen, name_11.text)) { - seen[name_11.text] = currentKind; + if (!ts.hasProperty(seen, name_13.text)) { + seen[name_13.text] = currentKind; } else { - var existingKind = seen[name_11.text]; + var existingKind = seen[name_13.text]; if (currentKind === Property && existingKind === Property) { if (inStrictMode) { - grammarErrorOnNode(name_11, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); + grammarErrorOnNode(name_13, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); } } else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name_11.text] = currentKind | existingKind; + seen[name_13.text] = currentKind | existingKind; } else { - return grammarErrorOnNode(name_11, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); + return grammarErrorOnNode(name_13, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); } } else { - return grammarErrorOnNode(name_11, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + return grammarErrorOnNode(name_13, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); } } } @@ -18808,12 +18938,11 @@ var ts; var identifier = name; if (contextNode && (contextNode.parserContextFlags & 1) && ts.isEvalOrArgumentsIdentifier(identifier)) { var nameText = ts.declarationNameToString(identifier); - if (ts.getAncestor(name, 201) || ts.getAncestor(name, 174)) { - return grammarErrorOnNode(identifier, ts.Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode, nameText); - } - else { + var reportErrorInClassDeclaration = reportStrictModeGrammarErrorInClassDeclaration(identifier, ts.Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode, nameText); + if (!reportErrorInClassDeclaration) { return grammarErrorOnNode(identifier, ts.Diagnostics.Invalid_use_of_0_in_strict_mode, nameText); } + return reportErrorInClassDeclaration; } } } @@ -19262,9 +19391,9 @@ var ts; } var count = 0; while (true) { - var name_12 = baseName + "_" + (++count); - if (!ts.hasProperty(currentSourceFile.identifiers, name_12)) { - return name_12; + var name_14 = baseName + "_" + (++count); + if (!ts.hasProperty(currentSourceFile.identifiers, name_14)) { + return name_14; } } } @@ -20346,9 +20475,9 @@ var ts; var count = tempFlags & 268435455; tempFlags++; if (count !== 8 && count !== 13) { - var name_13 = count < 26 ? "_" + String.fromCharCode(97 + count) : "_" + (count - 26); - if (isUniqueName(name_13)) { - return name_13; + var name_15 = count < 26 ? "_" + String.fromCharCode(97 + count) : "_" + (count - 26); + if (isUniqueName(name_15)) { + return name_15; } } } @@ -20376,8 +20505,8 @@ var ts; } function generateNameForModuleOrEnum(node) { if (node.name.kind === 65) { - var name_14 = node.name.text; - assignGeneratedName(node, isUniqueLocalName(name_14, node) ? name_14 : makeUniqueName(name_14)); + var name_16 = node.name.text; + assignGeneratedName(node, isUniqueLocalName(name_16, node) ? name_16 : makeUniqueName(name_16)); } } function generateNameForImportOrExportDeclaration(node) { @@ -20557,8 +20686,8 @@ var ts; if (scopeName) { var parentIndex = getSourceMapNameIndex(); if (parentIndex !== -1) { - var name_15 = node.name; - if (!name_15 || name_15.kind !== 127) { + var name_17 = node.name; + if (!name_17 || name_17.kind !== 127) { scopeName = "." + scopeName; } scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; @@ -20585,9 +20714,9 @@ var ts; node.kind === 201 || node.kind === 204) { if (node.name) { - var name_16 = node.name; - scopeName = name_16.kind === 127 - ? ts.getTextOfNode(name_16) + var name_18 = node.name; + scopeName = name_18.kind === 127 + ? ts.getTextOfNode(name_18) : node.name.text; } recordScopeNameStart(scopeName); @@ -21000,6 +21129,7 @@ var ts; default: return -1; } + case 172: case 170: return -1; default: @@ -21171,6 +21301,16 @@ var ts; write("..."); emit(node.expression); } + function emitYieldExpression(node) { + write(ts.tokenToString(111)); + if (node.asteriskToken) { + write("*"); + } + if (node.expression) { + write(" "); + emit(node.expression); + } + } function needsParenthesisForPropertyAccessOrInvocation(node) { switch (node.kind) { case 65: @@ -21412,6 +21552,9 @@ var ts; write("]"); } function emitMethod(node) { + if (languageVersion >= 2 && node.asteriskToken) { + write("*"); + } emit(node.name, false); if (languageVersion < 2) { write(": function "); @@ -22397,12 +22540,12 @@ var ts; function emitParameter(node) { if (languageVersion < 2) { if (ts.isBindingPattern(node.name)) { - var name_17 = createTempVariable(0); + var name_19 = createTempVariable(0); if (!tempParameters) { tempParameters = []; } - tempParameters.push(name_17); - emit(name_17); + tempParameters.push(name_19); + emit(name_19); } else { emit(node.name); @@ -22521,7 +22664,11 @@ var ts; write("default "); } } - write("function "); + write("function"); + if (languageVersion >= 2 && node.asteriskToken) { + write("*"); + } + write(" "); } if (shouldEmitFunctionName(node)) { emitDeclarationName(node); @@ -22853,6 +23000,9 @@ var ts; else if (member.kind === 137) { write("set "); } + if (member.asteriskToken) { + write("*"); + } emit(member.name); emitSignatureAndBody(member); emitEnd(member); @@ -23818,8 +23968,8 @@ var ts; else { for (var _c = 0, _d = node.exportClause.elements; _c < _d.length; _c++) { var specifier = _d[_c]; - var name_18 = (specifier.propertyName || specifier.name).text; - (exportSpecifiers[name_18] || (exportSpecifiers[name_18] = [])).push(specifier); + var name_20 = (specifier.propertyName || specifier.name).text; + (exportSpecifiers[name_20] || (exportSpecifiers[name_20] = [])).push(specifier); } } break; @@ -24130,6 +24280,8 @@ var ts; return emitConditionalExpression(node); case 173: return emitSpreadElementExpression(node); + case 172: + return emitYieldExpression(node); case 175: return; case 179: @@ -24403,7 +24555,7 @@ var ts; } return { getSourceFile: getSourceFile, - getDefaultLibFileName: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), ts.getDefaultLibFileName(options)); }, + getDefaultLibFileName: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), getDefaultLibFileName(options)); }, writeFile: writeFile, getCurrentDirectory: function () { return currentDirectory || (currentDirectory = ts.sys.getCurrentDirectory()); }, useCaseSensitiveFileNames: function () { return ts.sys.useCaseSensitiveFileNames; }, @@ -24443,6 +24595,10 @@ var ts; } } ts.flattenDiagnosticMessageText = flattenDiagnosticMessageText; + function getDefaultLibFileName(options) { + return options.target === 2 ? "lib.es6.d.ts" : "lib.d.ts"; + } + ts.getDefaultLibFileName = getDefaultLibFileName; function createProgram(rootNames, options, host) { var program; var files = []; @@ -25670,9 +25826,9 @@ var ts; case 198: case 152: var variableDeclarationNode; - var name_19; + var name_21; if (node.kind === 152) { - name_19 = node.name; + name_21 = node.name; variableDeclarationNode = node; while (variableDeclarationNode && variableDeclarationNode.kind !== 198) { variableDeclarationNode = variableDeclarationNode.parent; @@ -25682,16 +25838,16 @@ var ts; else { ts.Debug.assert(!ts.isBindingPattern(node.name)); variableDeclarationNode = node; - name_19 = node.name; + name_21 = node.name; } if (ts.isConst(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_19), ts.ScriptElementKind.constElement); + return createItem(node, getTextOfNode(name_21), ts.ScriptElementKind.constElement); } else if (ts.isLet(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_19), ts.ScriptElementKind.letElement); + return createItem(node, getTextOfNode(name_21), ts.ScriptElementKind.letElement); } else { - return createItem(node, getTextOfNode(name_19), ts.ScriptElementKind.variableElement); + return createItem(node, getTextOfNode(name_21), ts.ScriptElementKind.variableElement); } case 135: return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); @@ -27639,9 +27795,9 @@ var ts; } Rules.prototype.getRuleName = function (rule) { var o = this; - for (var name_20 in o) { - if (o[name_20] === rule) { - return name_20; + for (var name_22 in o) { + if (o[name_22] === rule) { + return name_22; } } throw new Error("Unknown rule"); @@ -31293,10 +31449,10 @@ var ts; for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) { var sourceFile = _a[_i]; var nameTable = getNameTable(sourceFile); - for (var name_21 in nameTable) { - if (!allNames[name_21]) { - allNames[name_21] = name_21; - var displayName = getCompletionEntryDisplayName(name_21, target, true); + for (var name_23 in nameTable) { + if (!allNames[name_23]) { + allNames[name_23] = name_23; + var displayName = getCompletionEntryDisplayName(name_23, target, true); if (displayName) { var entry = { name: displayName, @@ -32935,17 +33091,17 @@ var ts; if (isNameOfPropertyAssignment(node)) { var objectLiteral = node.parent.parent; var contextualType = typeInfoResolver.getContextualType(objectLiteral); - var name_22 = node.text; + var name_24 = node.text; if (contextualType) { if (contextualType.flags & 16384) { - var unionProperty = contextualType.getProperty(name_22); + var unionProperty = contextualType.getProperty(name_24); if (unionProperty) { return [unionProperty]; } else { var result_3 = []; ts.forEach(contextualType.types, function (t) { - var symbol = t.getProperty(name_22); + var symbol = t.getProperty(name_24); if (symbol) { result_3.push(symbol); } @@ -32954,7 +33110,7 @@ var ts; } } else { - var symbol_1 = contextualType.getProperty(name_22); + var symbol_1 = contextualType.getProperty(name_24); if (symbol_1) { return [symbol_1]; } diff --git a/bin/typescript.d.ts b/bin/typescript.d.ts index a16bff2a86223..1439f0de59773 100644 --- a/bin/typescript.d.ts +++ b/bin/typescript.d.ts @@ -310,6 +310,7 @@ declare module "typescript" { } interface Identifier extends PrimaryExpression { text: string; + originalKeywordKind?: SyntaxKind; } interface QualifiedName extends Node { left: EntityName; @@ -1181,6 +1182,33 @@ declare module "typescript" { function isIdentifierStart(ch: number, languageVersion: ScriptTarget): boolean; function isIdentifierPart(ch: number, languageVersion: ScriptTarget): boolean; } +declare module "typescript" { + function textSpanEnd(span: TextSpan): number; + function textSpanIsEmpty(span: TextSpan): boolean; + function textSpanContainsPosition(span: TextSpan, position: number): boolean; + function textSpanContainsTextSpan(span: TextSpan, other: TextSpan): boolean; + function textSpanOverlapsWith(span: TextSpan, other: TextSpan): boolean; + function textSpanOverlap(span1: TextSpan, span2: TextSpan): TextSpan; + function textSpanIntersectsWithTextSpan(span: TextSpan, other: TextSpan): boolean; + function textSpanIntersectsWith(span: TextSpan, start: number, length: number): boolean; + function textSpanIntersectsWithPosition(span: TextSpan, position: number): boolean; + function textSpanIntersection(span1: TextSpan, span2: TextSpan): TextSpan; + function createTextSpan(start: number, length: number): TextSpan; + function createTextSpanFromBounds(start: number, end: number): TextSpan; + function textChangeRangeNewSpan(range: TextChangeRange): TextSpan; + function textChangeRangeIsUnchanged(range: TextChangeRange): boolean; + function createTextChangeRange(span: TextSpan, newLength: number): TextChangeRange; + let unchangedTextChangeRange: TextChangeRange; + /** + * Called to merge all the changes that occurred across several versions of a script snapshot + * into a single change. i.e. if a user keeps making successive edits to a script we will + * have a text change from V1 to V2, V2 to V3, ..., Vn. + * + * This function will then merge those changes into a single change range valid between V1 and + * Vn. + */ + function collapseTextChangeRangesAcrossMultipleVersions(changes: TextChangeRange[]): TextChangeRange; +} declare module "typescript" { function getNodeConstructor(kind: SyntaxKind): new () => Node; function createNode(kind: SyntaxKind): Node; @@ -1199,6 +1227,7 @@ declare module "typescript" { function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; function getPreEmitDiagnostics(program: Program): Diagnostic[]; function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; + function getDefaultLibFileName(options: CompilerOptions): string; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; } declare module "typescript" { diff --git a/bin/typescript.js b/bin/typescript.js index 1c749f0d94a03..4544cc24ec174 100644 --- a/bin/typescript.js +++ b/bin/typescript.js @@ -1308,10 +1308,6 @@ var ts; "\u2029": "\\u2029", "\u0085": "\\u0085" // nextLine }; - function getDefaultLibFileName(options) { - return options.target === 2 /* ES6 */ ? "lib.es6.d.ts" : "lib.d.ts"; - } - ts.getDefaultLibFileName = getDefaultLibFileName; function Symbol(flags, name) { this.flags = flags; this.name = name; @@ -1809,6 +1805,12 @@ var ts; Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided: { code: 1209, category: ts.DiagnosticCategory.Error, key: "Ambient const enums are not allowed when the '--separateCompilation' flag is provided." }, Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode: { code: 1210, category: ts.DiagnosticCategory.Error, key: "Invalid use of '{0}'. Class definitions are automatically in strict mode." }, A_class_declaration_without_the_default_modifier_must_have_a_name: { code: 1211, category: ts.DiagnosticCategory.Error, key: "A class declaration without the 'default' modifier must have a name" }, + Identifier_expected_0_is_a_reserved_word_in_strict_mode: { code: 1212, category: ts.DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode" }, + Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1213, category: ts.DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." }, + Identifier_expected_0_is_a_reserved_word_in_strict_mode_External_Module_is_automatically_in_strict_mode: { code: 1214, category: ts.DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode. External Module is automatically in strict mode." }, + Type_expected_0_is_a_reserved_word_in_strict_mode: { code: 1215, category: ts.DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode" }, + Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1216, category: ts.DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." }, + Type_expected_0_is_a_reserved_word_in_strict_mode_Module_is_automatically_in_strict_mode: { code: 1217, category: ts.DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Module is automatically in strict mode." }, Duplicate_identifier_0: { code: 2300, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: ts.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: ts.DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, @@ -4331,13 +4333,12 @@ var ts; }; } ts.createDiagnosticForNodeFromMessageChain = createDiagnosticForNodeFromMessageChain; - /* @internal */ function getSpanOfTokenAtPosition(sourceFile, pos) { var scanner = ts.createScanner(sourceFile.languageVersion, true, sourceFile.text); scanner.setTextPos(pos); scanner.scan(); var start = scanner.getTokenPos(); - return createTextSpanFromBounds(start, scanner.getTextPos()); + return ts.createTextSpanFromBounds(start, scanner.getTextPos()); } ts.getSpanOfTokenAtPosition = getSpanOfTokenAtPosition; function getErrorSpanForNode(sourceFile, node) { @@ -4347,7 +4348,7 @@ var ts; var pos_1 = ts.skipTrivia(sourceFile.text, 0, false); if (pos_1 === sourceFile.text.length) { // file is empty - return span for the beginning of the file - return createTextSpan(0, 0); + return ts.createTextSpan(0, 0); } return getSpanOfTokenAtPosition(sourceFile, pos_1); // This list is a work in progress. Add missing node kinds to improve their error @@ -4373,7 +4374,7 @@ var ts; var pos = nodeIsMissing(errorNode) ? errorNode.pos : ts.skipTrivia(sourceFile.text, errorNode.pos); - return createTextSpanFromBounds(pos, errorNode.end); + return ts.createTextSpanFromBounds(pos, errorNode.end); } ts.getErrorSpanForNode = getErrorSpanForNode; function isExternalModule(file) { @@ -4482,7 +4483,6 @@ var ts; } } ts.forEachReturnStatement = forEachReturnStatement; - /* @internal */ function isVariableLike(node) { if (node) { switch (node.kind) { @@ -5170,205 +5170,6 @@ var ts; return false; } ts.isModifier = isModifier; - function textSpanEnd(span) { - return span.start + span.length; - } - ts.textSpanEnd = textSpanEnd; - function textSpanIsEmpty(span) { - return span.length === 0; - } - ts.textSpanIsEmpty = textSpanIsEmpty; - function textSpanContainsPosition(span, position) { - return position >= span.start && position < textSpanEnd(span); - } - ts.textSpanContainsPosition = textSpanContainsPosition; - // Returns true if 'span' contains 'other'. - function textSpanContainsTextSpan(span, other) { - return other.start >= span.start && textSpanEnd(other) <= textSpanEnd(span); - } - ts.textSpanContainsTextSpan = textSpanContainsTextSpan; - function textSpanOverlapsWith(span, other) { - var overlapStart = Math.max(span.start, other.start); - var overlapEnd = Math.min(textSpanEnd(span), textSpanEnd(other)); - return overlapStart < overlapEnd; - } - ts.textSpanOverlapsWith = textSpanOverlapsWith; - function textSpanOverlap(span1, span2) { - var overlapStart = Math.max(span1.start, span2.start); - var overlapEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2)); - if (overlapStart < overlapEnd) { - return createTextSpanFromBounds(overlapStart, overlapEnd); - } - return undefined; - } - ts.textSpanOverlap = textSpanOverlap; - function textSpanIntersectsWithTextSpan(span, other) { - return other.start <= textSpanEnd(span) && textSpanEnd(other) >= span.start; - } - ts.textSpanIntersectsWithTextSpan = textSpanIntersectsWithTextSpan; - function textSpanIntersectsWith(span, start, length) { - var end = start + length; - return start <= textSpanEnd(span) && end >= span.start; - } - ts.textSpanIntersectsWith = textSpanIntersectsWith; - function textSpanIntersectsWithPosition(span, position) { - return position <= textSpanEnd(span) && position >= span.start; - } - ts.textSpanIntersectsWithPosition = textSpanIntersectsWithPosition; - function textSpanIntersection(span1, span2) { - var intersectStart = Math.max(span1.start, span2.start); - var intersectEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2)); - if (intersectStart <= intersectEnd) { - return createTextSpanFromBounds(intersectStart, intersectEnd); - } - return undefined; - } - ts.textSpanIntersection = textSpanIntersection; - function createTextSpan(start, length) { - if (start < 0) { - throw new Error("start < 0"); - } - if (length < 0) { - throw new Error("length < 0"); - } - return { start: start, length: length }; - } - ts.createTextSpan = createTextSpan; - function createTextSpanFromBounds(start, end) { - return createTextSpan(start, end - start); - } - ts.createTextSpanFromBounds = createTextSpanFromBounds; - function textChangeRangeNewSpan(range) { - return createTextSpan(range.span.start, range.newLength); - } - ts.textChangeRangeNewSpan = textChangeRangeNewSpan; - function textChangeRangeIsUnchanged(range) { - return textSpanIsEmpty(range.span) && range.newLength === 0; - } - ts.textChangeRangeIsUnchanged = textChangeRangeIsUnchanged; - function createTextChangeRange(span, newLength) { - if (newLength < 0) { - throw new Error("newLength < 0"); - } - return { span: span, newLength: newLength }; - } - ts.createTextChangeRange = createTextChangeRange; - ts.unchangedTextChangeRange = createTextChangeRange(createTextSpan(0, 0), 0); - /** - * Called to merge all the changes that occurred across several versions of a script snapshot - * into a single change. i.e. if a user keeps making successive edits to a script we will - * have a text change from V1 to V2, V2 to V3, ..., Vn. - * - * This function will then merge those changes into a single change range valid between V1 and - * Vn. - */ - function collapseTextChangeRangesAcrossMultipleVersions(changes) { - if (changes.length === 0) { - return ts.unchangedTextChangeRange; - } - if (changes.length === 1) { - return changes[0]; - } - // We change from talking about { { oldStart, oldLength }, newLength } to { oldStart, oldEnd, newEnd } - // as it makes things much easier to reason about. - var change0 = changes[0]; - var oldStartN = change0.span.start; - var oldEndN = textSpanEnd(change0.span); - var newEndN = oldStartN + change0.newLength; - for (var i = 1; i < changes.length; i++) { - var nextChange = changes[i]; - // Consider the following case: - // i.e. two edits. The first represents the text change range { { 10, 50 }, 30 }. i.e. The span starting - // at 10, with length 50 is reduced to length 30. The second represents the text change range { { 30, 30 }, 40 }. - // i.e. the span starting at 30 with length 30 is increased to length 40. - // - // 0 10 20 30 40 50 60 70 80 90 100 - // ------------------------------------------------------------------------------------------------------- - // | / - // | /---- - // T1 | /---- - // | /---- - // | /---- - // ------------------------------------------------------------------------------------------------------- - // | \ - // | \ - // T2 | \ - // | \ - // | \ - // ------------------------------------------------------------------------------------------------------- - // - // Merging these turns out to not be too difficult. First, determining the new start of the change is trivial - // it's just the min of the old and new starts. i.e.: - // - // 0 10 20 30 40 50 60 70 80 90 100 - // ------------------------------------------------------------*------------------------------------------ - // | / - // | /---- - // T1 | /---- - // | /---- - // | /---- - // ----------------------------------------$-------------------$------------------------------------------ - // . | \ - // . | \ - // T2 . | \ - // . | \ - // . | \ - // ----------------------------------------------------------------------*-------------------------------- - // - // (Note the dots represent the newly inferrred start. - // Determining the new and old end is also pretty simple. Basically it boils down to paying attention to the - // absolute positions at the asterixes, and the relative change between the dollar signs. Basically, we see - // which if the two $'s precedes the other, and we move that one forward until they line up. in this case that - // means: - // - // 0 10 20 30 40 50 60 70 80 90 100 - // --------------------------------------------------------------------------------*---------------------- - // | / - // | /---- - // T1 | /---- - // | /---- - // | /---- - // ------------------------------------------------------------$------------------------------------------ - // . | \ - // . | \ - // T2 . | \ - // . | \ - // . | \ - // ----------------------------------------------------------------------*-------------------------------- - // - // In other words (in this case), we're recognizing that the second edit happened after where the first edit - // ended with a delta of 20 characters (60 - 40). Thus, if we go back in time to where the first edit started - // that's the same as if we started at char 80 instead of 60. - // - // As it so happens, the same logic applies if the second edit precedes the first edit. In that case rahter - // than pusing the first edit forward to match the second, we'll push the second edit forward to match the - // first. - // - // In this case that means we have { oldStart: 10, oldEnd: 80, newEnd: 70 } or, in TextChangeRange - // semantics: { { start: 10, length: 70 }, newLength: 60 } - // - // The math then works out as follows. - // If we have { oldStart1, oldEnd1, newEnd1 } and { oldStart2, oldEnd2, newEnd2 } then we can compute the - // final result like so: - // - // { - // oldStart3: Min(oldStart1, oldStart2), - // oldEnd3 : Max(oldEnd1, oldEnd1 + (oldEnd2 - newEnd1)), - // newEnd3 : Max(newEnd2, newEnd2 + (newEnd1 - oldEnd2)) - // } - var oldStart1 = oldStartN; - var oldEnd1 = oldEndN; - var newEnd1 = newEndN; - var oldStart2 = nextChange.span.start; - var oldEnd2 = textSpanEnd(nextChange.span); - var newEnd2 = oldStart2 + nextChange.newLength; - oldStartN = Math.min(oldStart1, oldStart2); - oldEndN = Math.max(oldEnd1, oldEnd1 + (oldEnd2 - newEnd1)); - newEndN = Math.max(newEnd2, newEnd2 + (newEnd1 - oldEnd2)); - } - return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), newEndN - oldStartN); - } - ts.collapseTextChangeRangesAcrossMultipleVersions = collapseTextChangeRangesAcrossMultipleVersions; function nodeStartsNewLexicalEnvironment(n) { return isFunctionLike(n) || n.kind === 205 /* ModuleDeclaration */ || n.kind === 227 /* SourceFile */; } @@ -5385,7 +5186,6 @@ var ts; return node; } ts.createSynthesizedNode = createSynthesizedNode; - /* @internal */ function createDiagnosticCollection() { var nonFileDiagnostics = []; var fileDiagnostics = {}; @@ -5807,6 +5607,208 @@ var ts; } ts.getLocalSymbolForExportDefault = getLocalSymbolForExportDefault; })(ts || (ts = {})); +var ts; +(function (ts) { + function textSpanEnd(span) { + return span.start + span.length; + } + ts.textSpanEnd = textSpanEnd; + function textSpanIsEmpty(span) { + return span.length === 0; + } + ts.textSpanIsEmpty = textSpanIsEmpty; + function textSpanContainsPosition(span, position) { + return position >= span.start && position < textSpanEnd(span); + } + ts.textSpanContainsPosition = textSpanContainsPosition; + // Returns true if 'span' contains 'other'. + function textSpanContainsTextSpan(span, other) { + return other.start >= span.start && textSpanEnd(other) <= textSpanEnd(span); + } + ts.textSpanContainsTextSpan = textSpanContainsTextSpan; + function textSpanOverlapsWith(span, other) { + var overlapStart = Math.max(span.start, other.start); + var overlapEnd = Math.min(textSpanEnd(span), textSpanEnd(other)); + return overlapStart < overlapEnd; + } + ts.textSpanOverlapsWith = textSpanOverlapsWith; + function textSpanOverlap(span1, span2) { + var overlapStart = Math.max(span1.start, span2.start); + var overlapEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2)); + if (overlapStart < overlapEnd) { + return createTextSpanFromBounds(overlapStart, overlapEnd); + } + return undefined; + } + ts.textSpanOverlap = textSpanOverlap; + function textSpanIntersectsWithTextSpan(span, other) { + return other.start <= textSpanEnd(span) && textSpanEnd(other) >= span.start; + } + ts.textSpanIntersectsWithTextSpan = textSpanIntersectsWithTextSpan; + function textSpanIntersectsWith(span, start, length) { + var end = start + length; + return start <= textSpanEnd(span) && end >= span.start; + } + ts.textSpanIntersectsWith = textSpanIntersectsWith; + function textSpanIntersectsWithPosition(span, position) { + return position <= textSpanEnd(span) && position >= span.start; + } + ts.textSpanIntersectsWithPosition = textSpanIntersectsWithPosition; + function textSpanIntersection(span1, span2) { + var intersectStart = Math.max(span1.start, span2.start); + var intersectEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2)); + if (intersectStart <= intersectEnd) { + return createTextSpanFromBounds(intersectStart, intersectEnd); + } + return undefined; + } + ts.textSpanIntersection = textSpanIntersection; + function createTextSpan(start, length) { + if (start < 0) { + throw new Error("start < 0"); + } + if (length < 0) { + throw new Error("length < 0"); + } + return { start: start, length: length }; + } + ts.createTextSpan = createTextSpan; + function createTextSpanFromBounds(start, end) { + return createTextSpan(start, end - start); + } + ts.createTextSpanFromBounds = createTextSpanFromBounds; + function textChangeRangeNewSpan(range) { + return createTextSpan(range.span.start, range.newLength); + } + ts.textChangeRangeNewSpan = textChangeRangeNewSpan; + function textChangeRangeIsUnchanged(range) { + return textSpanIsEmpty(range.span) && range.newLength === 0; + } + ts.textChangeRangeIsUnchanged = textChangeRangeIsUnchanged; + function createTextChangeRange(span, newLength) { + if (newLength < 0) { + throw new Error("newLength < 0"); + } + return { span: span, newLength: newLength }; + } + ts.createTextChangeRange = createTextChangeRange; + ts.unchangedTextChangeRange = createTextChangeRange(createTextSpan(0, 0), 0); + /** + * Called to merge all the changes that occurred across several versions of a script snapshot + * into a single change. i.e. if a user keeps making successive edits to a script we will + * have a text change from V1 to V2, V2 to V3, ..., Vn. + * + * This function will then merge those changes into a single change range valid between V1 and + * Vn. + */ + function collapseTextChangeRangesAcrossMultipleVersions(changes) { + if (changes.length === 0) { + return ts.unchangedTextChangeRange; + } + if (changes.length === 1) { + return changes[0]; + } + // We change from talking about { { oldStart, oldLength }, newLength } to { oldStart, oldEnd, newEnd } + // as it makes things much easier to reason about. + var change0 = changes[0]; + var oldStartN = change0.span.start; + var oldEndN = textSpanEnd(change0.span); + var newEndN = oldStartN + change0.newLength; + for (var i = 1; i < changes.length; i++) { + var nextChange = changes[i]; + // Consider the following case: + // i.e. two edits. The first represents the text change range { { 10, 50 }, 30 }. i.e. The span starting + // at 10, with length 50 is reduced to length 30. The second represents the text change range { { 30, 30 }, 40 }. + // i.e. the span starting at 30 with length 30 is increased to length 40. + // + // 0 10 20 30 40 50 60 70 80 90 100 + // ------------------------------------------------------------------------------------------------------- + // | / + // | /---- + // T1 | /---- + // | /---- + // | /---- + // ------------------------------------------------------------------------------------------------------- + // | \ + // | \ + // T2 | \ + // | \ + // | \ + // ------------------------------------------------------------------------------------------------------- + // + // Merging these turns out to not be too difficult. First, determining the new start of the change is trivial + // it's just the min of the old and new starts. i.e.: + // + // 0 10 20 30 40 50 60 70 80 90 100 + // ------------------------------------------------------------*------------------------------------------ + // | / + // | /---- + // T1 | /---- + // | /---- + // | /---- + // ----------------------------------------$-------------------$------------------------------------------ + // . | \ + // . | \ + // T2 . | \ + // . | \ + // . | \ + // ----------------------------------------------------------------------*-------------------------------- + // + // (Note the dots represent the newly inferrred start. + // Determining the new and old end is also pretty simple. Basically it boils down to paying attention to the + // absolute positions at the asterixes, and the relative change between the dollar signs. Basically, we see + // which if the two $'s precedes the other, and we move that one forward until they line up. in this case that + // means: + // + // 0 10 20 30 40 50 60 70 80 90 100 + // --------------------------------------------------------------------------------*---------------------- + // | / + // | /---- + // T1 | /---- + // | /---- + // | /---- + // ------------------------------------------------------------$------------------------------------------ + // . | \ + // . | \ + // T2 . | \ + // . | \ + // . | \ + // ----------------------------------------------------------------------*-------------------------------- + // + // In other words (in this case), we're recognizing that the second edit happened after where the first edit + // ended with a delta of 20 characters (60 - 40). Thus, if we go back in time to where the first edit started + // that's the same as if we started at char 80 instead of 60. + // + // As it so happens, the same logic applies if the second edit precedes the first edit. In that case rahter + // than pusing the first edit forward to match the second, we'll push the second edit forward to match the + // first. + // + // In this case that means we have { oldStart: 10, oldEnd: 80, newEnd: 70 } or, in TextChangeRange + // semantics: { { start: 10, length: 70 }, newLength: 60 } + // + // The math then works out as follows. + // If we have { oldStart1, oldEnd1, newEnd1 } and { oldStart2, oldEnd2, newEnd2 } then we can compute the + // final result like so: + // + // { + // oldStart3: Min(oldStart1, oldStart2), + // oldEnd3 : Max(oldEnd1, oldEnd1 + (oldEnd2 - newEnd1)), + // newEnd3 : Max(newEnd2, newEnd2 + (newEnd1 - oldEnd2)) + // } + var oldStart1 = oldStartN; + var oldEnd1 = oldEndN; + var newEnd1 = newEndN; + var oldStart2 = nextChange.span.start; + var oldEnd2 = textSpanEnd(nextChange.span); + var newEnd2 = oldStart2 + nextChange.newLength; + oldStartN = Math.min(oldStart1, oldStart2); + oldEndN = Math.max(oldEnd1, oldEnd1 + (oldEnd2 - newEnd1)); + newEndN = Math.max(newEnd2, newEnd2 + (newEnd1 - oldEnd2)); + } + return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), newEndN - oldStartN); + } + ts.collapseTextChangeRangesAcrossMultipleVersions = collapseTextChangeRangesAcrossMultipleVersions; +})(ts || (ts = {})); /// /// var ts; @@ -6995,6 +6997,7 @@ var ts; function tryParse(callback) { return speculationHelper(callback, false); } + // Ignore strict mode flag because we will report an error in type checker instead. function isIdentifier() { if (token === 65 /* Identifier */) { return true; @@ -7004,7 +7007,7 @@ var ts; if (token === 111 /* YieldKeyword */ && inYieldContext()) { return false; } - return inStrictModeContext() ? token > 111 /* LastFutureReservedWord */ : token > 101 /* LastReservedWord */; + return token > 101 /* LastReservedWord */; } function parseExpected(kind, diagnosticMessage) { if (token === kind) { @@ -7108,6 +7111,10 @@ var ts; identifierCount++; if (isIdentifier) { var node = createNode(65 /* Identifier */); + // Store original token kind if it is not just an Identifier so we can report appropriate error later in type checker + if (token !== 65 /* Identifier */) { + node.originalKeywordKind = token; + } node.text = internIdentifier(scanner.getTokenValue()); nextToken(); return finishNode(node); @@ -9823,6 +9830,17 @@ var ts; node.body = parseFunctionBlockOrSemicolon(false); return finishNode(node); } + function isClassMemberModifier(idToken) { + switch (idToken) { + case 109 /* PublicKeyword */: + case 107 /* PrivateKeyword */: + case 108 /* ProtectedKeyword */: + case 110 /* StaticKeyword */: + return true; + default: + return false; + } + } function isClassMemberStart() { var idToken; if (token === 52 /* AtToken */) { @@ -9831,6 +9849,15 @@ var ts; // Eat up all modifiers, but hold on to the last one in case it is actually an identifier. while (ts.isModifier(token)) { idToken = token; + // If the idToken is a class modifier (protected, private, public, and static), it is + // certain that we are starting to parse class member. This allows better error recovery + // Example: + // public foo() ... // true + // public @dec blah ... // true; we will then report an error later + // export public ... // true; we will then report an error later + if (isClassMemberModifier(idToken)) { + return true; + } nextToken(); } if (token === 35 /* AsteriskToken */) { @@ -17230,7 +17257,7 @@ var ts; function checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper) { ts.Debug.assert(node.kind !== 134 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node)); // Grammar checking - var hasGrammarError = checkGrammarFunctionLikeDeclaration(node); + var hasGrammarError = checkGrammarDeclarationNameInStrictMode(node) || checkGrammarFunctionLikeDeclaration(node); if (!hasGrammarError && node.kind === 162 /* FunctionExpression */) { checkGrammarFunctionName(node.name) || checkGrammarForGenerator(node); } @@ -17272,7 +17299,7 @@ var ts; } function checkFunctionExpressionOrObjectLiteralMethodBody(node) { ts.Debug.assert(node.kind !== 134 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node)); - if (node.type) { + if (node.type && !node.asteriskToken) { checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNodeOrHeritageClauseElement(node.type)); } if (node.body) { @@ -17834,6 +17861,7 @@ var ts; return type; } function checkExpression(node, contextualMapper) { + checkGrammarIdentifierInStrictMode(node); return checkExpressionOrQualifiedName(node, contextualMapper); } // Checks an expression and returns its type. The contextualMapper parameter serves two purposes: When @@ -17941,6 +17969,7 @@ var ts; } // DECLARATION AND STATEMENT TYPE CHECKING function checkTypeParameter(node) { + checkGrammarDeclarationNameInStrictMode(node); // Grammar Checking if (node.expression) { grammarErrorOnFirstToken(node.expression, ts.Diagnostics.Type_expected); @@ -18172,9 +18201,11 @@ var ts; checkDecorators(node); } function checkTypeReferenceNode(node) { + checkGrammarTypeReferenceInStrictMode(node.typeName); return checkTypeReferenceOrHeritageClauseElement(node); } function checkHeritageClauseElement(node) { + checkGrammarHeritageClauseElementInStrictMode(node.expression); return checkTypeReferenceOrHeritageClauseElement(node); } function checkTypeReferenceOrHeritageClauseElement(node) { @@ -18648,6 +18679,7 @@ var ts; } } function checkFunctionLikeDeclaration(node) { + checkGrammarDeclarationNameInStrictMode(node); checkDecorators(node); checkSignatureDeclaration(node); // Do not use hasDynamicName here, because that returns false for well known symbols. @@ -18678,7 +18710,7 @@ var ts; } } checkSourceElement(node.body); - if (node.type && !isAccessor(node.kind)) { + if (node.type && !isAccessor(node.kind) && !node.asteriskToken) { checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNodeOrHeritageClauseElement(node.type)); } // Report an implicit any error if there is no body, no explicit return type, and node is not a private method @@ -18891,6 +18923,7 @@ var ts; } // Check variable, parameter, or property declaration function checkVariableLikeDeclaration(node) { + checkGrammarDeclarationNameInStrictMode(node); checkDecorators(node); checkSourceElement(node.type); // For a computed property, just check the initializer and exit @@ -19521,6 +19554,7 @@ var ts; return unknownType; } function checkClassDeclaration(node) { + checkGrammarDeclarationNameInStrictMode(node); // Grammar checking if (node.parent.kind !== 206 /* ModuleBlock */ && node.parent.kind !== 227 /* SourceFile */) { grammarErrorOnNode(node, ts.Diagnostics.class_declarations_are_only_supported_directly_inside_a_module_or_as_a_top_level_declaration); @@ -19721,7 +19755,7 @@ var ts; } function checkInterfaceDeclaration(node) { // Grammar checking - checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node); + checkGrammarDeclarationNameInStrictMode(node) || checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node); checkTypeParameters(node.typeParameters); if (produceDiagnostics) { checkTypeNameIsReserved(node.name, ts.Diagnostics.Interface_name_cannot_be_0); @@ -19921,7 +19955,7 @@ var ts; return; } // Grammar checking - checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); + checkGrammarDeclarationNameInStrictMode(node) || checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); checkTypeNameIsReserved(node.name, ts.Diagnostics.Enum_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); @@ -19983,7 +20017,7 @@ var ts; function checkModuleDeclaration(node) { if (produceDiagnostics) { // Grammar checking - if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node)) { + if (!checkGrammarDeclarationNameInStrictMode(node) && !checkGrammarDecorators(node) && !checkGrammarModifiers(node)) { if (!ts.isInAmbientContext(node) && node.name.kind === 8 /* StringLiteral */) { grammarErrorOnNode(node.name, ts.Diagnostics.Only_ambient_modules_can_use_quoted_names); } @@ -20078,7 +20112,7 @@ var ts; checkAliasSymbol(node); } function checkImportDeclaration(node) { - if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & 499 /* Modifier */)) { + if (!checkGrammarImportDeclarationNameInStrictMode(node) && !checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & 499 /* Modifier */)) { grammarErrorOnFirstToken(node, ts.Diagnostics.An_import_declaration_cannot_have_modifiers); } if (checkExternalImportOrExportDeclaration(node)) { @@ -20099,7 +20133,7 @@ var ts; } } function checkImportEqualsDeclaration(node) { - checkGrammarDecorators(node) || checkGrammarModifiers(node); + checkGrammarDeclarationNameInStrictMode(node) || checkGrammarDecorators(node) || checkGrammarModifiers(node); if (ts.isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) { checkImportBinding(node); if (node.flags & 1 /* Export */) { @@ -20418,6 +20452,8 @@ var ts; // Grammar checking checkGrammarSourceFile(node); emitExtends = false; + emitDecorate = false; + emitParam = false; potentialThisCollisions.length = 0; ts.forEach(node.statements, checkSourceElement); checkFunctionExpressionBodies(node); @@ -21346,6 +21382,137 @@ var ts; anyArrayType = createArrayType(anyType); } // GRAMMAR CHECKING + function isReservedwordInStrictMode(node) { + // Check that originalKeywordKind is less than LastFurtureReservedWord to see if an Identifier is a strict-mode reserved word + return (node.parserContextFlags & 1 /* StrictMode */) && + (node.originalKeywordKind >= 103 /* FirstFutureReservedWord */ && node.originalKeywordKind <= 111 /* LastFutureReservedWord */); + } + function reportStrictModeGrammarErrorInClassDeclaration(identifier, message, arg0, arg1, arg2) { + // We are checking if this name is inside class declaration or class expression (which are under class definitions inside ES6 spec.) + // if so, we would like to give more explicit invalid usage error. + if (ts.getAncestor(identifier, 201 /* ClassDeclaration */) || ts.getAncestor(identifier, 174 /* ClassExpression */)) { + return grammarErrorOnNode(identifier, message, arg0); + } + return false; + } + function checkGrammarImportDeclarationNameInStrictMode(node) { + // Check if the import declaration used strict-mode reserved word in its names bindings + if (node.importClause) { + var impotClause = node.importClause; + if (impotClause.namedBindings) { + var nameBindings = impotClause.namedBindings; + if (nameBindings.kind === 211 /* NamespaceImport */) { + var name_11 = nameBindings.name; + if (name_11.originalKeywordKind) { + var nameText = ts.declarationNameToString(name_11); + return grammarErrorOnNode(name_11, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + } + } + else if (nameBindings.kind === 212 /* NamedImports */) { + var reportError = false; + for (var _i = 0, _a = nameBindings.elements; _i < _a.length; _i++) { + var element = _a[_i]; + var name_12 = element.name; + if (name_12.originalKeywordKind) { + var nameText = ts.declarationNameToString(name_12); + reportError = reportError || grammarErrorOnNode(name_12, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + } + } + return reportError; + } + } + } + return false; + } + function checkGrammarDeclarationNameInStrictMode(node) { + var name = node.name; + if (name && name.kind === 65 /* Identifier */ && isReservedwordInStrictMode(name)) { + var nameText = ts.declarationNameToString(name); + switch (node.kind) { + case 129 /* Parameter */: + case 198 /* VariableDeclaration */: + case 200 /* FunctionDeclaration */: + case 128 /* TypeParameter */: + case 152 /* BindingElement */: + case 202 /* InterfaceDeclaration */: + case 203 /* TypeAliasDeclaration */: + case 204 /* EnumDeclaration */: + return checkGrammarIdentifierInStrictMode(name); + case 201 /* ClassDeclaration */: + // Report an error if the class declaration uses strict-mode reserved word. + return grammarErrorOnNode(name, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText); + case 205 /* ModuleDeclaration */: + // Report an error if the module declaration uses strict-mode reserved word. + // TODO(yuisu): fix this when having external module in strict mode + return grammarErrorOnNode(name, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + case 208 /* ImportEqualsDeclaration */: + // TODO(yuisu): fix this when having external module in strict mode + return grammarErrorOnNode(name, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + } + } + return false; + } + function checkGrammarTypeReferenceInStrictMode(typeName) { + // Check if the type reference is using strict mode keyword + // Example: + // class C { + // foo(x: public){} // Error. + // } + if (typeName.kind === 65 /* Identifier */) { + checkGrammarTypeNameInStrictMode(typeName); + } + else if (typeName.kind === 126 /* QualifiedName */) { + // Walk from right to left and report a possible error at each Identifier in QualifiedName + // Example: + // x1: public.private.package // error at public and private + checkGrammarTypeNameInStrictMode(typeName.right); + checkGrammarTypeReferenceInStrictMode(typeName.left); + } + } + // This function will report an error for every identifier in property access expression + // whether it violates strict mode reserved words. + // Example: + // public // error at public + // public.private.package // error at public + // B.private.B // no error + function checkGrammarHeritageClauseElementInStrictMode(expression) { + // Example: + // class C extends public // error at public + if (expression && expression.kind === 65 /* Identifier */) { + return checkGrammarIdentifierInStrictMode(expression); + } + else if (expression && expression.kind === 155 /* PropertyAccessExpression */) { + // Walk from left to right in PropertyAccessExpression until we are at the left most expression + // in PropertyAccessExpression. According to grammar production of MemberExpression, + // the left component expression is a PrimaryExpression (i.e. Identifier) while the other + // component after dots can be IdentifierName. + checkGrammarHeritageClauseElementInStrictMode(expression.expression); + } + } + // The function takes an identifier itself or an expression which has SyntaxKind.Identifier. + function checkGrammarIdentifierInStrictMode(node, nameText) { + if (node && node.kind === 65 /* Identifier */ && isReservedwordInStrictMode(node)) { + if (!nameText) { + nameText = ts.declarationNameToString(node); + } + // TODO (yuisu): Fix when module is a strict mode + var errorReport = reportStrictModeGrammarErrorInClassDeclaration(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText) || + grammarErrorOnNode(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + return errorReport; + } + return false; + } + // The function takes an identifier when uses as a typeName in TypeReferenceNode + function checkGrammarTypeNameInStrictMode(node) { + if (node && node.kind === 65 /* Identifier */ && isReservedwordInStrictMode(node)) { + var nameText = ts.declarationNameToString(node); + // TODO (yuisu): Fix when module is a strict mode + var errorReport = reportStrictModeGrammarErrorInClassDeclaration(node, ts.Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText) || + grammarErrorOnNode(node, ts.Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode, nameText); + return errorReport; + } + return false; + } function checkGrammarDecorators(node) { if (!node.decorators) { return false; @@ -21721,11 +21888,11 @@ var ts; var inStrictMode = (node.parserContextFlags & 1 /* StrictMode */) !== 0; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; - var name_11 = prop.name; + var name_13 = prop.name; if (prop.kind === 175 /* OmittedExpression */ || - name_11.kind === 127 /* ComputedPropertyName */) { + name_13.kind === 127 /* ComputedPropertyName */) { // If the name is not a ComputedPropertyName, the grammar checking will skip it - checkGrammarComputedPropertyName(name_11); + checkGrammarComputedPropertyName(name_13); continue; } // ECMA-262 11.1.5 Object Initialiser @@ -21740,8 +21907,8 @@ var ts; if (prop.kind === 224 /* PropertyAssignment */ || prop.kind === 225 /* ShorthandPropertyAssignment */) { // Grammar checking for computedPropertName and shorthandPropertyAssignment checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); - if (name_11.kind === 7 /* NumericLiteral */) { - checkGrammarNumbericLiteral(name_11); + if (name_13.kind === 7 /* NumericLiteral */) { + checkGrammarNumbericLiteral(name_13); } currentKind = Property; } @@ -21757,26 +21924,26 @@ var ts; else { ts.Debug.fail("Unexpected syntax kind:" + prop.kind); } - if (!ts.hasProperty(seen, name_11.text)) { - seen[name_11.text] = currentKind; + if (!ts.hasProperty(seen, name_13.text)) { + seen[name_13.text] = currentKind; } else { - var existingKind = seen[name_11.text]; + var existingKind = seen[name_13.text]; if (currentKind === Property && existingKind === Property) { if (inStrictMode) { - grammarErrorOnNode(name_11, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); + grammarErrorOnNode(name_13, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); } } else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name_11.text] = currentKind | existingKind; + seen[name_13.text] = currentKind | existingKind; } else { - return grammarErrorOnNode(name_11, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); + return grammarErrorOnNode(name_13, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); } } else { - return grammarErrorOnNode(name_11, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + return grammarErrorOnNode(name_13, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); } } } @@ -22124,15 +22291,14 @@ var ts; var identifier = name; if (contextNode && (contextNode.parserContextFlags & 1 /* StrictMode */) && ts.isEvalOrArgumentsIdentifier(identifier)) { var nameText = ts.declarationNameToString(identifier); - // We are checking if this name is inside class declaration or class expression (which are under class definitions inside ES6 spec.) - // if so, we would like to give more explicit invalid usage error. - // This will be particularly helpful in the case of "arguments" as such case is very common mistake. - if (ts.getAncestor(name, 201 /* ClassDeclaration */) || ts.getAncestor(name, 174 /* ClassExpression */)) { - return grammarErrorOnNode(identifier, ts.Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode, nameText); - } - else { + // We check first if the name is inside class declaration or class expression; if so give explicit message + // otherwise report generic error message. + // reportGrammarErrorInClassDeclaration only return true if grammar error is successfully reported and false otherwise + var reportErrorInClassDeclaration = reportStrictModeGrammarErrorInClassDeclaration(identifier, ts.Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode, nameText); + if (!reportErrorInClassDeclaration) { return grammarErrorOnNode(identifier, ts.Diagnostics.Invalid_use_of_0_in_strict_mode, nameText); } + return reportErrorInClassDeclaration; } } } @@ -22631,9 +22797,9 @@ var ts; } var count = 0; while (true) { - var name_12 = baseName + "_" + (++count); - if (!ts.hasProperty(currentSourceFile.identifiers, name_12)) { - return name_12; + var name_14 = baseName + "_" + (++count); + if (!ts.hasProperty(currentSourceFile.identifiers, name_14)) { + return name_14; } } } @@ -23835,9 +24001,9 @@ var ts; tempFlags++; // Skip over 'i' and 'n' if (count !== 8 && count !== 13) { - var name_13 = count < 26 ? "_" + String.fromCharCode(97 /* a */ + count) : "_" + (count - 26); - if (isUniqueName(name_13)) { - return name_13; + var name_15 = count < 26 ? "_" + String.fromCharCode(97 /* a */ + count) : "_" + (count - 26); + if (isUniqueName(name_15)) { + return name_15; } } } @@ -23870,9 +24036,9 @@ var ts; } function generateNameForModuleOrEnum(node) { if (node.name.kind === 65 /* Identifier */) { - var name_14 = node.name.text; + var name_16 = node.name.text; // Use module/enum name itself if it is unique, otherwise make a unique variation - assignGeneratedName(node, isUniqueLocalName(name_14, node) ? name_14 : makeUniqueName(name_14)); + assignGeneratedName(node, isUniqueLocalName(name_16, node) ? name_16 : makeUniqueName(name_16)); } } function generateNameForImportOrExportDeclaration(node) { @@ -24085,8 +24251,8 @@ var ts; // Child scopes are always shown with a dot (even if they have no name), // unless it is a computed property. Then it is shown with brackets, // but the brackets are included in the name. - var name_15 = node.name; - if (!name_15 || name_15.kind !== 127 /* ComputedPropertyName */) { + var name_17 = node.name; + if (!name_17 || name_17.kind !== 127 /* ComputedPropertyName */) { scopeName = "." + scopeName; } scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; @@ -24115,10 +24281,10 @@ var ts; node.kind === 204 /* EnumDeclaration */) { // Declaration and has associated name use it if (node.name) { - var name_16 = node.name; + var name_18 = node.name; // For computed property names, the text will include the brackets - scopeName = name_16.kind === 127 /* ComputedPropertyName */ - ? ts.getTextOfNode(name_16) + scopeName = name_18.kind === 127 /* ComputedPropertyName */ + ? ts.getTextOfNode(name_18) : node.name.text; } recordScopeNameStart(scopeName); @@ -24592,6 +24758,7 @@ var ts; default: return -1 /* LessThan */; } + case 172 /* YieldExpression */: case 170 /* ConditionalExpression */: return -1 /* LessThan */; default: @@ -24779,6 +24946,16 @@ var ts; write("..."); emit(node.expression); } + function emitYieldExpression(node) { + write(ts.tokenToString(111 /* YieldKeyword */)); + if (node.asteriskToken) { + write("*"); + } + if (node.expression) { + write(" "); + emit(node.expression); + } + } function needsParenthesisForPropertyAccessOrInvocation(node) { switch (node.kind) { case 65 /* Identifier */: @@ -25037,6 +25214,9 @@ var ts; write("]"); } function emitMethod(node) { + if (languageVersion >= 2 /* ES6 */ && node.asteriskToken) { + write("*"); + } emit(node.name, false); if (languageVersion < 2 /* ES6 */) { write(": function "); @@ -26140,12 +26320,12 @@ var ts; function emitParameter(node) { if (languageVersion < 2 /* ES6 */) { if (ts.isBindingPattern(node.name)) { - var name_17 = createTempVariable(0 /* Auto */); + var name_19 = createTempVariable(0 /* Auto */); if (!tempParameters) { tempParameters = []; } - tempParameters.push(name_17); - emit(name_17); + tempParameters.push(name_19); + emit(name_19); } else { emit(node.name); @@ -26269,7 +26449,11 @@ var ts; write("default "); } } - write("function "); + write("function"); + if (languageVersion >= 2 /* ES6 */ && node.asteriskToken) { + write("*"); + } + write(" "); } if (shouldEmitFunctionName(node)) { emitDeclarationName(node); @@ -26616,6 +26800,9 @@ var ts; else if (member.kind === 137 /* SetAccessor */) { write("set "); } + if (member.asteriskToken) { + write("*"); + } emit(member.name); emitSignatureAndBody(member); emitEnd(member); @@ -27761,8 +27948,8 @@ var ts; // export { x, y } for (var _c = 0, _d = node.exportClause.elements; _c < _d.length; _c++) { var specifier = _d[_c]; - var name_18 = (specifier.propertyName || specifier.name).text; - (exportSpecifiers[name_18] || (exportSpecifiers[name_18] = [])).push(specifier); + var name_20 = (specifier.propertyName || specifier.name).text; + (exportSpecifiers[name_20] || (exportSpecifiers[name_20] = [])).push(specifier); } } break; @@ -28094,6 +28281,8 @@ var ts; return emitConditionalExpression(node); case 173 /* SpreadElementExpression */: return emitSpreadElementExpression(node); + case 172 /* YieldExpression */: + return emitYieldExpression(node); case 175 /* OmittedExpression */: return; case 179 /* Block */: @@ -28393,7 +28582,7 @@ var ts; } return { getSourceFile: getSourceFile, - getDefaultLibFileName: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), ts.getDefaultLibFileName(options)); }, + getDefaultLibFileName: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), getDefaultLibFileName(options)); }, writeFile: writeFile, getCurrentDirectory: function () { return currentDirectory || (currentDirectory = ts.sys.getCurrentDirectory()); }, useCaseSensitiveFileNames: function () { return ts.sys.useCaseSensitiveFileNames; }, @@ -28433,6 +28622,10 @@ var ts; } } ts.flattenDiagnosticMessageText = flattenDiagnosticMessageText; + function getDefaultLibFileName(options) { + return options.target === 2 /* ES6 */ ? "lib.es6.d.ts" : "lib.d.ts"; + } + ts.getDefaultLibFileName = getDefaultLibFileName; function createProgram(rootNames, options, host) { var program; var files = []; @@ -29753,9 +29946,9 @@ var ts; case 198 /* VariableDeclaration */: case 152 /* BindingElement */: var variableDeclarationNode; - var name_19; + var name_21; if (node.kind === 152 /* BindingElement */) { - name_19 = node.name; + name_21 = node.name; variableDeclarationNode = node; // binding elements are added only for variable declarations // bubble up to the containing variable declaration @@ -29767,16 +29960,16 @@ var ts; else { ts.Debug.assert(!ts.isBindingPattern(node.name)); variableDeclarationNode = node; - name_19 = node.name; + name_21 = node.name; } if (ts.isConst(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_19), ts.ScriptElementKind.constElement); + return createItem(node, getTextOfNode(name_21), ts.ScriptElementKind.constElement); } else if (ts.isLet(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_19), ts.ScriptElementKind.letElement); + return createItem(node, getTextOfNode(name_21), ts.ScriptElementKind.letElement); } else { - return createItem(node, getTextOfNode(name_19), ts.ScriptElementKind.variableElement); + return createItem(node, getTextOfNode(name_21), ts.ScriptElementKind.variableElement); } case 135 /* Constructor */: return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); @@ -32316,9 +32509,9 @@ var ts; } Rules.prototype.getRuleName = function (rule) { var o = this; - for (var name_20 in o) { - if (o[name_20] === rule) { - return name_20; + for (var name_22 in o) { + if (o[name_22] === rule) { + return name_22; } } throw new Error("Unknown rule"); @@ -36528,10 +36721,10 @@ var ts; for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) { var sourceFile = _a[_i]; var nameTable = getNameTable(sourceFile); - for (var name_21 in nameTable) { - if (!allNames[name_21]) { - allNames[name_21] = name_21; - var displayName = getCompletionEntryDisplayName(name_21, target, true); + for (var name_23 in nameTable) { + if (!allNames[name_23]) { + allNames[name_23] = name_23; + var displayName = getCompletionEntryDisplayName(name_23, target, true); if (displayName) { var entry = { name: displayName, @@ -38363,19 +38556,19 @@ var ts; if (isNameOfPropertyAssignment(node)) { var objectLiteral = node.parent.parent; var contextualType = typeInfoResolver.getContextualType(objectLiteral); - var name_22 = node.text; + var name_24 = node.text; if (contextualType) { if (contextualType.flags & 16384 /* Union */) { // This is a union type, first see if the property we are looking for is a union property (i.e. exists in all types) // if not, search the constituent types for the property - var unionProperty = contextualType.getProperty(name_22); + var unionProperty = contextualType.getProperty(name_24); if (unionProperty) { return [unionProperty]; } else { var result_3 = []; ts.forEach(contextualType.types, function (t) { - var symbol = t.getProperty(name_22); + var symbol = t.getProperty(name_24); if (symbol) { result_3.push(symbol); } @@ -38384,7 +38577,7 @@ var ts; } } else { - var symbol_1 = contextualType.getProperty(name_22); + var symbol_1 = contextualType.getProperty(name_24); if (symbol_1) { return [symbol_1]; } diff --git a/bin/typescriptServices.d.ts b/bin/typescriptServices.d.ts index d988810fd3b9f..9e9df4fdc784d 100644 --- a/bin/typescriptServices.d.ts +++ b/bin/typescriptServices.d.ts @@ -310,6 +310,7 @@ declare module ts { } interface Identifier extends PrimaryExpression { text: string; + originalKeywordKind?: SyntaxKind; } interface QualifiedName extends Node { left: EntityName; @@ -1181,6 +1182,33 @@ declare module ts { function isIdentifierStart(ch: number, languageVersion: ScriptTarget): boolean; function isIdentifierPart(ch: number, languageVersion: ScriptTarget): boolean; } +declare module ts { + function textSpanEnd(span: TextSpan): number; + function textSpanIsEmpty(span: TextSpan): boolean; + function textSpanContainsPosition(span: TextSpan, position: number): boolean; + function textSpanContainsTextSpan(span: TextSpan, other: TextSpan): boolean; + function textSpanOverlapsWith(span: TextSpan, other: TextSpan): boolean; + function textSpanOverlap(span1: TextSpan, span2: TextSpan): TextSpan; + function textSpanIntersectsWithTextSpan(span: TextSpan, other: TextSpan): boolean; + function textSpanIntersectsWith(span: TextSpan, start: number, length: number): boolean; + function textSpanIntersectsWithPosition(span: TextSpan, position: number): boolean; + function textSpanIntersection(span1: TextSpan, span2: TextSpan): TextSpan; + function createTextSpan(start: number, length: number): TextSpan; + function createTextSpanFromBounds(start: number, end: number): TextSpan; + function textChangeRangeNewSpan(range: TextChangeRange): TextSpan; + function textChangeRangeIsUnchanged(range: TextChangeRange): boolean; + function createTextChangeRange(span: TextSpan, newLength: number): TextChangeRange; + let unchangedTextChangeRange: TextChangeRange; + /** + * Called to merge all the changes that occurred across several versions of a script snapshot + * into a single change. i.e. if a user keeps making successive edits to a script we will + * have a text change from V1 to V2, V2 to V3, ..., Vn. + * + * This function will then merge those changes into a single change range valid between V1 and + * Vn. + */ + function collapseTextChangeRangesAcrossMultipleVersions(changes: TextChangeRange[]): TextChangeRange; +} declare module ts { function getNodeConstructor(kind: SyntaxKind): new () => Node; function createNode(kind: SyntaxKind): Node; @@ -1199,6 +1227,7 @@ declare module ts { function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; function getPreEmitDiagnostics(program: Program): Diagnostic[]; function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; + function getDefaultLibFileName(options: CompilerOptions): string; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; } declare module ts { diff --git a/bin/typescriptServices.js b/bin/typescriptServices.js index 1c749f0d94a03..4544cc24ec174 100644 --- a/bin/typescriptServices.js +++ b/bin/typescriptServices.js @@ -1308,10 +1308,6 @@ var ts; "\u2029": "\\u2029", "\u0085": "\\u0085" // nextLine }; - function getDefaultLibFileName(options) { - return options.target === 2 /* ES6 */ ? "lib.es6.d.ts" : "lib.d.ts"; - } - ts.getDefaultLibFileName = getDefaultLibFileName; function Symbol(flags, name) { this.flags = flags; this.name = name; @@ -1809,6 +1805,12 @@ var ts; Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided: { code: 1209, category: ts.DiagnosticCategory.Error, key: "Ambient const enums are not allowed when the '--separateCompilation' flag is provided." }, Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode: { code: 1210, category: ts.DiagnosticCategory.Error, key: "Invalid use of '{0}'. Class definitions are automatically in strict mode." }, A_class_declaration_without_the_default_modifier_must_have_a_name: { code: 1211, category: ts.DiagnosticCategory.Error, key: "A class declaration without the 'default' modifier must have a name" }, + Identifier_expected_0_is_a_reserved_word_in_strict_mode: { code: 1212, category: ts.DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode" }, + Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1213, category: ts.DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." }, + Identifier_expected_0_is_a_reserved_word_in_strict_mode_External_Module_is_automatically_in_strict_mode: { code: 1214, category: ts.DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode. External Module is automatically in strict mode." }, + Type_expected_0_is_a_reserved_word_in_strict_mode: { code: 1215, category: ts.DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode" }, + Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1216, category: ts.DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." }, + Type_expected_0_is_a_reserved_word_in_strict_mode_Module_is_automatically_in_strict_mode: { code: 1217, category: ts.DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Module is automatically in strict mode." }, Duplicate_identifier_0: { code: 2300, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: ts.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: ts.DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, @@ -4331,13 +4333,12 @@ var ts; }; } ts.createDiagnosticForNodeFromMessageChain = createDiagnosticForNodeFromMessageChain; - /* @internal */ function getSpanOfTokenAtPosition(sourceFile, pos) { var scanner = ts.createScanner(sourceFile.languageVersion, true, sourceFile.text); scanner.setTextPos(pos); scanner.scan(); var start = scanner.getTokenPos(); - return createTextSpanFromBounds(start, scanner.getTextPos()); + return ts.createTextSpanFromBounds(start, scanner.getTextPos()); } ts.getSpanOfTokenAtPosition = getSpanOfTokenAtPosition; function getErrorSpanForNode(sourceFile, node) { @@ -4347,7 +4348,7 @@ var ts; var pos_1 = ts.skipTrivia(sourceFile.text, 0, false); if (pos_1 === sourceFile.text.length) { // file is empty - return span for the beginning of the file - return createTextSpan(0, 0); + return ts.createTextSpan(0, 0); } return getSpanOfTokenAtPosition(sourceFile, pos_1); // This list is a work in progress. Add missing node kinds to improve their error @@ -4373,7 +4374,7 @@ var ts; var pos = nodeIsMissing(errorNode) ? errorNode.pos : ts.skipTrivia(sourceFile.text, errorNode.pos); - return createTextSpanFromBounds(pos, errorNode.end); + return ts.createTextSpanFromBounds(pos, errorNode.end); } ts.getErrorSpanForNode = getErrorSpanForNode; function isExternalModule(file) { @@ -4482,7 +4483,6 @@ var ts; } } ts.forEachReturnStatement = forEachReturnStatement; - /* @internal */ function isVariableLike(node) { if (node) { switch (node.kind) { @@ -5170,205 +5170,6 @@ var ts; return false; } ts.isModifier = isModifier; - function textSpanEnd(span) { - return span.start + span.length; - } - ts.textSpanEnd = textSpanEnd; - function textSpanIsEmpty(span) { - return span.length === 0; - } - ts.textSpanIsEmpty = textSpanIsEmpty; - function textSpanContainsPosition(span, position) { - return position >= span.start && position < textSpanEnd(span); - } - ts.textSpanContainsPosition = textSpanContainsPosition; - // Returns true if 'span' contains 'other'. - function textSpanContainsTextSpan(span, other) { - return other.start >= span.start && textSpanEnd(other) <= textSpanEnd(span); - } - ts.textSpanContainsTextSpan = textSpanContainsTextSpan; - function textSpanOverlapsWith(span, other) { - var overlapStart = Math.max(span.start, other.start); - var overlapEnd = Math.min(textSpanEnd(span), textSpanEnd(other)); - return overlapStart < overlapEnd; - } - ts.textSpanOverlapsWith = textSpanOverlapsWith; - function textSpanOverlap(span1, span2) { - var overlapStart = Math.max(span1.start, span2.start); - var overlapEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2)); - if (overlapStart < overlapEnd) { - return createTextSpanFromBounds(overlapStart, overlapEnd); - } - return undefined; - } - ts.textSpanOverlap = textSpanOverlap; - function textSpanIntersectsWithTextSpan(span, other) { - return other.start <= textSpanEnd(span) && textSpanEnd(other) >= span.start; - } - ts.textSpanIntersectsWithTextSpan = textSpanIntersectsWithTextSpan; - function textSpanIntersectsWith(span, start, length) { - var end = start + length; - return start <= textSpanEnd(span) && end >= span.start; - } - ts.textSpanIntersectsWith = textSpanIntersectsWith; - function textSpanIntersectsWithPosition(span, position) { - return position <= textSpanEnd(span) && position >= span.start; - } - ts.textSpanIntersectsWithPosition = textSpanIntersectsWithPosition; - function textSpanIntersection(span1, span2) { - var intersectStart = Math.max(span1.start, span2.start); - var intersectEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2)); - if (intersectStart <= intersectEnd) { - return createTextSpanFromBounds(intersectStart, intersectEnd); - } - return undefined; - } - ts.textSpanIntersection = textSpanIntersection; - function createTextSpan(start, length) { - if (start < 0) { - throw new Error("start < 0"); - } - if (length < 0) { - throw new Error("length < 0"); - } - return { start: start, length: length }; - } - ts.createTextSpan = createTextSpan; - function createTextSpanFromBounds(start, end) { - return createTextSpan(start, end - start); - } - ts.createTextSpanFromBounds = createTextSpanFromBounds; - function textChangeRangeNewSpan(range) { - return createTextSpan(range.span.start, range.newLength); - } - ts.textChangeRangeNewSpan = textChangeRangeNewSpan; - function textChangeRangeIsUnchanged(range) { - return textSpanIsEmpty(range.span) && range.newLength === 0; - } - ts.textChangeRangeIsUnchanged = textChangeRangeIsUnchanged; - function createTextChangeRange(span, newLength) { - if (newLength < 0) { - throw new Error("newLength < 0"); - } - return { span: span, newLength: newLength }; - } - ts.createTextChangeRange = createTextChangeRange; - ts.unchangedTextChangeRange = createTextChangeRange(createTextSpan(0, 0), 0); - /** - * Called to merge all the changes that occurred across several versions of a script snapshot - * into a single change. i.e. if a user keeps making successive edits to a script we will - * have a text change from V1 to V2, V2 to V3, ..., Vn. - * - * This function will then merge those changes into a single change range valid between V1 and - * Vn. - */ - function collapseTextChangeRangesAcrossMultipleVersions(changes) { - if (changes.length === 0) { - return ts.unchangedTextChangeRange; - } - if (changes.length === 1) { - return changes[0]; - } - // We change from talking about { { oldStart, oldLength }, newLength } to { oldStart, oldEnd, newEnd } - // as it makes things much easier to reason about. - var change0 = changes[0]; - var oldStartN = change0.span.start; - var oldEndN = textSpanEnd(change0.span); - var newEndN = oldStartN + change0.newLength; - for (var i = 1; i < changes.length; i++) { - var nextChange = changes[i]; - // Consider the following case: - // i.e. two edits. The first represents the text change range { { 10, 50 }, 30 }. i.e. The span starting - // at 10, with length 50 is reduced to length 30. The second represents the text change range { { 30, 30 }, 40 }. - // i.e. the span starting at 30 with length 30 is increased to length 40. - // - // 0 10 20 30 40 50 60 70 80 90 100 - // ------------------------------------------------------------------------------------------------------- - // | / - // | /---- - // T1 | /---- - // | /---- - // | /---- - // ------------------------------------------------------------------------------------------------------- - // | \ - // | \ - // T2 | \ - // | \ - // | \ - // ------------------------------------------------------------------------------------------------------- - // - // Merging these turns out to not be too difficult. First, determining the new start of the change is trivial - // it's just the min of the old and new starts. i.e.: - // - // 0 10 20 30 40 50 60 70 80 90 100 - // ------------------------------------------------------------*------------------------------------------ - // | / - // | /---- - // T1 | /---- - // | /---- - // | /---- - // ----------------------------------------$-------------------$------------------------------------------ - // . | \ - // . | \ - // T2 . | \ - // . | \ - // . | \ - // ----------------------------------------------------------------------*-------------------------------- - // - // (Note the dots represent the newly inferrred start. - // Determining the new and old end is also pretty simple. Basically it boils down to paying attention to the - // absolute positions at the asterixes, and the relative change between the dollar signs. Basically, we see - // which if the two $'s precedes the other, and we move that one forward until they line up. in this case that - // means: - // - // 0 10 20 30 40 50 60 70 80 90 100 - // --------------------------------------------------------------------------------*---------------------- - // | / - // | /---- - // T1 | /---- - // | /---- - // | /---- - // ------------------------------------------------------------$------------------------------------------ - // . | \ - // . | \ - // T2 . | \ - // . | \ - // . | \ - // ----------------------------------------------------------------------*-------------------------------- - // - // In other words (in this case), we're recognizing that the second edit happened after where the first edit - // ended with a delta of 20 characters (60 - 40). Thus, if we go back in time to where the first edit started - // that's the same as if we started at char 80 instead of 60. - // - // As it so happens, the same logic applies if the second edit precedes the first edit. In that case rahter - // than pusing the first edit forward to match the second, we'll push the second edit forward to match the - // first. - // - // In this case that means we have { oldStart: 10, oldEnd: 80, newEnd: 70 } or, in TextChangeRange - // semantics: { { start: 10, length: 70 }, newLength: 60 } - // - // The math then works out as follows. - // If we have { oldStart1, oldEnd1, newEnd1 } and { oldStart2, oldEnd2, newEnd2 } then we can compute the - // final result like so: - // - // { - // oldStart3: Min(oldStart1, oldStart2), - // oldEnd3 : Max(oldEnd1, oldEnd1 + (oldEnd2 - newEnd1)), - // newEnd3 : Max(newEnd2, newEnd2 + (newEnd1 - oldEnd2)) - // } - var oldStart1 = oldStartN; - var oldEnd1 = oldEndN; - var newEnd1 = newEndN; - var oldStart2 = nextChange.span.start; - var oldEnd2 = textSpanEnd(nextChange.span); - var newEnd2 = oldStart2 + nextChange.newLength; - oldStartN = Math.min(oldStart1, oldStart2); - oldEndN = Math.max(oldEnd1, oldEnd1 + (oldEnd2 - newEnd1)); - newEndN = Math.max(newEnd2, newEnd2 + (newEnd1 - oldEnd2)); - } - return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), newEndN - oldStartN); - } - ts.collapseTextChangeRangesAcrossMultipleVersions = collapseTextChangeRangesAcrossMultipleVersions; function nodeStartsNewLexicalEnvironment(n) { return isFunctionLike(n) || n.kind === 205 /* ModuleDeclaration */ || n.kind === 227 /* SourceFile */; } @@ -5385,7 +5186,6 @@ var ts; return node; } ts.createSynthesizedNode = createSynthesizedNode; - /* @internal */ function createDiagnosticCollection() { var nonFileDiagnostics = []; var fileDiagnostics = {}; @@ -5807,6 +5607,208 @@ var ts; } ts.getLocalSymbolForExportDefault = getLocalSymbolForExportDefault; })(ts || (ts = {})); +var ts; +(function (ts) { + function textSpanEnd(span) { + return span.start + span.length; + } + ts.textSpanEnd = textSpanEnd; + function textSpanIsEmpty(span) { + return span.length === 0; + } + ts.textSpanIsEmpty = textSpanIsEmpty; + function textSpanContainsPosition(span, position) { + return position >= span.start && position < textSpanEnd(span); + } + ts.textSpanContainsPosition = textSpanContainsPosition; + // Returns true if 'span' contains 'other'. + function textSpanContainsTextSpan(span, other) { + return other.start >= span.start && textSpanEnd(other) <= textSpanEnd(span); + } + ts.textSpanContainsTextSpan = textSpanContainsTextSpan; + function textSpanOverlapsWith(span, other) { + var overlapStart = Math.max(span.start, other.start); + var overlapEnd = Math.min(textSpanEnd(span), textSpanEnd(other)); + return overlapStart < overlapEnd; + } + ts.textSpanOverlapsWith = textSpanOverlapsWith; + function textSpanOverlap(span1, span2) { + var overlapStart = Math.max(span1.start, span2.start); + var overlapEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2)); + if (overlapStart < overlapEnd) { + return createTextSpanFromBounds(overlapStart, overlapEnd); + } + return undefined; + } + ts.textSpanOverlap = textSpanOverlap; + function textSpanIntersectsWithTextSpan(span, other) { + return other.start <= textSpanEnd(span) && textSpanEnd(other) >= span.start; + } + ts.textSpanIntersectsWithTextSpan = textSpanIntersectsWithTextSpan; + function textSpanIntersectsWith(span, start, length) { + var end = start + length; + return start <= textSpanEnd(span) && end >= span.start; + } + ts.textSpanIntersectsWith = textSpanIntersectsWith; + function textSpanIntersectsWithPosition(span, position) { + return position <= textSpanEnd(span) && position >= span.start; + } + ts.textSpanIntersectsWithPosition = textSpanIntersectsWithPosition; + function textSpanIntersection(span1, span2) { + var intersectStart = Math.max(span1.start, span2.start); + var intersectEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2)); + if (intersectStart <= intersectEnd) { + return createTextSpanFromBounds(intersectStart, intersectEnd); + } + return undefined; + } + ts.textSpanIntersection = textSpanIntersection; + function createTextSpan(start, length) { + if (start < 0) { + throw new Error("start < 0"); + } + if (length < 0) { + throw new Error("length < 0"); + } + return { start: start, length: length }; + } + ts.createTextSpan = createTextSpan; + function createTextSpanFromBounds(start, end) { + return createTextSpan(start, end - start); + } + ts.createTextSpanFromBounds = createTextSpanFromBounds; + function textChangeRangeNewSpan(range) { + return createTextSpan(range.span.start, range.newLength); + } + ts.textChangeRangeNewSpan = textChangeRangeNewSpan; + function textChangeRangeIsUnchanged(range) { + return textSpanIsEmpty(range.span) && range.newLength === 0; + } + ts.textChangeRangeIsUnchanged = textChangeRangeIsUnchanged; + function createTextChangeRange(span, newLength) { + if (newLength < 0) { + throw new Error("newLength < 0"); + } + return { span: span, newLength: newLength }; + } + ts.createTextChangeRange = createTextChangeRange; + ts.unchangedTextChangeRange = createTextChangeRange(createTextSpan(0, 0), 0); + /** + * Called to merge all the changes that occurred across several versions of a script snapshot + * into a single change. i.e. if a user keeps making successive edits to a script we will + * have a text change from V1 to V2, V2 to V3, ..., Vn. + * + * This function will then merge those changes into a single change range valid between V1 and + * Vn. + */ + function collapseTextChangeRangesAcrossMultipleVersions(changes) { + if (changes.length === 0) { + return ts.unchangedTextChangeRange; + } + if (changes.length === 1) { + return changes[0]; + } + // We change from talking about { { oldStart, oldLength }, newLength } to { oldStart, oldEnd, newEnd } + // as it makes things much easier to reason about. + var change0 = changes[0]; + var oldStartN = change0.span.start; + var oldEndN = textSpanEnd(change0.span); + var newEndN = oldStartN + change0.newLength; + for (var i = 1; i < changes.length; i++) { + var nextChange = changes[i]; + // Consider the following case: + // i.e. two edits. The first represents the text change range { { 10, 50 }, 30 }. i.e. The span starting + // at 10, with length 50 is reduced to length 30. The second represents the text change range { { 30, 30 }, 40 }. + // i.e. the span starting at 30 with length 30 is increased to length 40. + // + // 0 10 20 30 40 50 60 70 80 90 100 + // ------------------------------------------------------------------------------------------------------- + // | / + // | /---- + // T1 | /---- + // | /---- + // | /---- + // ------------------------------------------------------------------------------------------------------- + // | \ + // | \ + // T2 | \ + // | \ + // | \ + // ------------------------------------------------------------------------------------------------------- + // + // Merging these turns out to not be too difficult. First, determining the new start of the change is trivial + // it's just the min of the old and new starts. i.e.: + // + // 0 10 20 30 40 50 60 70 80 90 100 + // ------------------------------------------------------------*------------------------------------------ + // | / + // | /---- + // T1 | /---- + // | /---- + // | /---- + // ----------------------------------------$-------------------$------------------------------------------ + // . | \ + // . | \ + // T2 . | \ + // . | \ + // . | \ + // ----------------------------------------------------------------------*-------------------------------- + // + // (Note the dots represent the newly inferrred start. + // Determining the new and old end is also pretty simple. Basically it boils down to paying attention to the + // absolute positions at the asterixes, and the relative change between the dollar signs. Basically, we see + // which if the two $'s precedes the other, and we move that one forward until they line up. in this case that + // means: + // + // 0 10 20 30 40 50 60 70 80 90 100 + // --------------------------------------------------------------------------------*---------------------- + // | / + // | /---- + // T1 | /---- + // | /---- + // | /---- + // ------------------------------------------------------------$------------------------------------------ + // . | \ + // . | \ + // T2 . | \ + // . | \ + // . | \ + // ----------------------------------------------------------------------*-------------------------------- + // + // In other words (in this case), we're recognizing that the second edit happened after where the first edit + // ended with a delta of 20 characters (60 - 40). Thus, if we go back in time to where the first edit started + // that's the same as if we started at char 80 instead of 60. + // + // As it so happens, the same logic applies if the second edit precedes the first edit. In that case rahter + // than pusing the first edit forward to match the second, we'll push the second edit forward to match the + // first. + // + // In this case that means we have { oldStart: 10, oldEnd: 80, newEnd: 70 } or, in TextChangeRange + // semantics: { { start: 10, length: 70 }, newLength: 60 } + // + // The math then works out as follows. + // If we have { oldStart1, oldEnd1, newEnd1 } and { oldStart2, oldEnd2, newEnd2 } then we can compute the + // final result like so: + // + // { + // oldStart3: Min(oldStart1, oldStart2), + // oldEnd3 : Max(oldEnd1, oldEnd1 + (oldEnd2 - newEnd1)), + // newEnd3 : Max(newEnd2, newEnd2 + (newEnd1 - oldEnd2)) + // } + var oldStart1 = oldStartN; + var oldEnd1 = oldEndN; + var newEnd1 = newEndN; + var oldStart2 = nextChange.span.start; + var oldEnd2 = textSpanEnd(nextChange.span); + var newEnd2 = oldStart2 + nextChange.newLength; + oldStartN = Math.min(oldStart1, oldStart2); + oldEndN = Math.max(oldEnd1, oldEnd1 + (oldEnd2 - newEnd1)); + newEndN = Math.max(newEnd2, newEnd2 + (newEnd1 - oldEnd2)); + } + return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), newEndN - oldStartN); + } + ts.collapseTextChangeRangesAcrossMultipleVersions = collapseTextChangeRangesAcrossMultipleVersions; +})(ts || (ts = {})); /// /// var ts; @@ -6995,6 +6997,7 @@ var ts; function tryParse(callback) { return speculationHelper(callback, false); } + // Ignore strict mode flag because we will report an error in type checker instead. function isIdentifier() { if (token === 65 /* Identifier */) { return true; @@ -7004,7 +7007,7 @@ var ts; if (token === 111 /* YieldKeyword */ && inYieldContext()) { return false; } - return inStrictModeContext() ? token > 111 /* LastFutureReservedWord */ : token > 101 /* LastReservedWord */; + return token > 101 /* LastReservedWord */; } function parseExpected(kind, diagnosticMessage) { if (token === kind) { @@ -7108,6 +7111,10 @@ var ts; identifierCount++; if (isIdentifier) { var node = createNode(65 /* Identifier */); + // Store original token kind if it is not just an Identifier so we can report appropriate error later in type checker + if (token !== 65 /* Identifier */) { + node.originalKeywordKind = token; + } node.text = internIdentifier(scanner.getTokenValue()); nextToken(); return finishNode(node); @@ -9823,6 +9830,17 @@ var ts; node.body = parseFunctionBlockOrSemicolon(false); return finishNode(node); } + function isClassMemberModifier(idToken) { + switch (idToken) { + case 109 /* PublicKeyword */: + case 107 /* PrivateKeyword */: + case 108 /* ProtectedKeyword */: + case 110 /* StaticKeyword */: + return true; + default: + return false; + } + } function isClassMemberStart() { var idToken; if (token === 52 /* AtToken */) { @@ -9831,6 +9849,15 @@ var ts; // Eat up all modifiers, but hold on to the last one in case it is actually an identifier. while (ts.isModifier(token)) { idToken = token; + // If the idToken is a class modifier (protected, private, public, and static), it is + // certain that we are starting to parse class member. This allows better error recovery + // Example: + // public foo() ... // true + // public @dec blah ... // true; we will then report an error later + // export public ... // true; we will then report an error later + if (isClassMemberModifier(idToken)) { + return true; + } nextToken(); } if (token === 35 /* AsteriskToken */) { @@ -17230,7 +17257,7 @@ var ts; function checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper) { ts.Debug.assert(node.kind !== 134 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node)); // Grammar checking - var hasGrammarError = checkGrammarFunctionLikeDeclaration(node); + var hasGrammarError = checkGrammarDeclarationNameInStrictMode(node) || checkGrammarFunctionLikeDeclaration(node); if (!hasGrammarError && node.kind === 162 /* FunctionExpression */) { checkGrammarFunctionName(node.name) || checkGrammarForGenerator(node); } @@ -17272,7 +17299,7 @@ var ts; } function checkFunctionExpressionOrObjectLiteralMethodBody(node) { ts.Debug.assert(node.kind !== 134 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node)); - if (node.type) { + if (node.type && !node.asteriskToken) { checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNodeOrHeritageClauseElement(node.type)); } if (node.body) { @@ -17834,6 +17861,7 @@ var ts; return type; } function checkExpression(node, contextualMapper) { + checkGrammarIdentifierInStrictMode(node); return checkExpressionOrQualifiedName(node, contextualMapper); } // Checks an expression and returns its type. The contextualMapper parameter serves two purposes: When @@ -17941,6 +17969,7 @@ var ts; } // DECLARATION AND STATEMENT TYPE CHECKING function checkTypeParameter(node) { + checkGrammarDeclarationNameInStrictMode(node); // Grammar Checking if (node.expression) { grammarErrorOnFirstToken(node.expression, ts.Diagnostics.Type_expected); @@ -18172,9 +18201,11 @@ var ts; checkDecorators(node); } function checkTypeReferenceNode(node) { + checkGrammarTypeReferenceInStrictMode(node.typeName); return checkTypeReferenceOrHeritageClauseElement(node); } function checkHeritageClauseElement(node) { + checkGrammarHeritageClauseElementInStrictMode(node.expression); return checkTypeReferenceOrHeritageClauseElement(node); } function checkTypeReferenceOrHeritageClauseElement(node) { @@ -18648,6 +18679,7 @@ var ts; } } function checkFunctionLikeDeclaration(node) { + checkGrammarDeclarationNameInStrictMode(node); checkDecorators(node); checkSignatureDeclaration(node); // Do not use hasDynamicName here, because that returns false for well known symbols. @@ -18678,7 +18710,7 @@ var ts; } } checkSourceElement(node.body); - if (node.type && !isAccessor(node.kind)) { + if (node.type && !isAccessor(node.kind) && !node.asteriskToken) { checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNodeOrHeritageClauseElement(node.type)); } // Report an implicit any error if there is no body, no explicit return type, and node is not a private method @@ -18891,6 +18923,7 @@ var ts; } // Check variable, parameter, or property declaration function checkVariableLikeDeclaration(node) { + checkGrammarDeclarationNameInStrictMode(node); checkDecorators(node); checkSourceElement(node.type); // For a computed property, just check the initializer and exit @@ -19521,6 +19554,7 @@ var ts; return unknownType; } function checkClassDeclaration(node) { + checkGrammarDeclarationNameInStrictMode(node); // Grammar checking if (node.parent.kind !== 206 /* ModuleBlock */ && node.parent.kind !== 227 /* SourceFile */) { grammarErrorOnNode(node, ts.Diagnostics.class_declarations_are_only_supported_directly_inside_a_module_or_as_a_top_level_declaration); @@ -19721,7 +19755,7 @@ var ts; } function checkInterfaceDeclaration(node) { // Grammar checking - checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node); + checkGrammarDeclarationNameInStrictMode(node) || checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node); checkTypeParameters(node.typeParameters); if (produceDiagnostics) { checkTypeNameIsReserved(node.name, ts.Diagnostics.Interface_name_cannot_be_0); @@ -19921,7 +19955,7 @@ var ts; return; } // Grammar checking - checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); + checkGrammarDeclarationNameInStrictMode(node) || checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); checkTypeNameIsReserved(node.name, ts.Diagnostics.Enum_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); @@ -19983,7 +20017,7 @@ var ts; function checkModuleDeclaration(node) { if (produceDiagnostics) { // Grammar checking - if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node)) { + if (!checkGrammarDeclarationNameInStrictMode(node) && !checkGrammarDecorators(node) && !checkGrammarModifiers(node)) { if (!ts.isInAmbientContext(node) && node.name.kind === 8 /* StringLiteral */) { grammarErrorOnNode(node.name, ts.Diagnostics.Only_ambient_modules_can_use_quoted_names); } @@ -20078,7 +20112,7 @@ var ts; checkAliasSymbol(node); } function checkImportDeclaration(node) { - if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & 499 /* Modifier */)) { + if (!checkGrammarImportDeclarationNameInStrictMode(node) && !checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & 499 /* Modifier */)) { grammarErrorOnFirstToken(node, ts.Diagnostics.An_import_declaration_cannot_have_modifiers); } if (checkExternalImportOrExportDeclaration(node)) { @@ -20099,7 +20133,7 @@ var ts; } } function checkImportEqualsDeclaration(node) { - checkGrammarDecorators(node) || checkGrammarModifiers(node); + checkGrammarDeclarationNameInStrictMode(node) || checkGrammarDecorators(node) || checkGrammarModifiers(node); if (ts.isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) { checkImportBinding(node); if (node.flags & 1 /* Export */) { @@ -20418,6 +20452,8 @@ var ts; // Grammar checking checkGrammarSourceFile(node); emitExtends = false; + emitDecorate = false; + emitParam = false; potentialThisCollisions.length = 0; ts.forEach(node.statements, checkSourceElement); checkFunctionExpressionBodies(node); @@ -21346,6 +21382,137 @@ var ts; anyArrayType = createArrayType(anyType); } // GRAMMAR CHECKING + function isReservedwordInStrictMode(node) { + // Check that originalKeywordKind is less than LastFurtureReservedWord to see if an Identifier is a strict-mode reserved word + return (node.parserContextFlags & 1 /* StrictMode */) && + (node.originalKeywordKind >= 103 /* FirstFutureReservedWord */ && node.originalKeywordKind <= 111 /* LastFutureReservedWord */); + } + function reportStrictModeGrammarErrorInClassDeclaration(identifier, message, arg0, arg1, arg2) { + // We are checking if this name is inside class declaration or class expression (which are under class definitions inside ES6 spec.) + // if so, we would like to give more explicit invalid usage error. + if (ts.getAncestor(identifier, 201 /* ClassDeclaration */) || ts.getAncestor(identifier, 174 /* ClassExpression */)) { + return grammarErrorOnNode(identifier, message, arg0); + } + return false; + } + function checkGrammarImportDeclarationNameInStrictMode(node) { + // Check if the import declaration used strict-mode reserved word in its names bindings + if (node.importClause) { + var impotClause = node.importClause; + if (impotClause.namedBindings) { + var nameBindings = impotClause.namedBindings; + if (nameBindings.kind === 211 /* NamespaceImport */) { + var name_11 = nameBindings.name; + if (name_11.originalKeywordKind) { + var nameText = ts.declarationNameToString(name_11); + return grammarErrorOnNode(name_11, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + } + } + else if (nameBindings.kind === 212 /* NamedImports */) { + var reportError = false; + for (var _i = 0, _a = nameBindings.elements; _i < _a.length; _i++) { + var element = _a[_i]; + var name_12 = element.name; + if (name_12.originalKeywordKind) { + var nameText = ts.declarationNameToString(name_12); + reportError = reportError || grammarErrorOnNode(name_12, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + } + } + return reportError; + } + } + } + return false; + } + function checkGrammarDeclarationNameInStrictMode(node) { + var name = node.name; + if (name && name.kind === 65 /* Identifier */ && isReservedwordInStrictMode(name)) { + var nameText = ts.declarationNameToString(name); + switch (node.kind) { + case 129 /* Parameter */: + case 198 /* VariableDeclaration */: + case 200 /* FunctionDeclaration */: + case 128 /* TypeParameter */: + case 152 /* BindingElement */: + case 202 /* InterfaceDeclaration */: + case 203 /* TypeAliasDeclaration */: + case 204 /* EnumDeclaration */: + return checkGrammarIdentifierInStrictMode(name); + case 201 /* ClassDeclaration */: + // Report an error if the class declaration uses strict-mode reserved word. + return grammarErrorOnNode(name, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText); + case 205 /* ModuleDeclaration */: + // Report an error if the module declaration uses strict-mode reserved word. + // TODO(yuisu): fix this when having external module in strict mode + return grammarErrorOnNode(name, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + case 208 /* ImportEqualsDeclaration */: + // TODO(yuisu): fix this when having external module in strict mode + return grammarErrorOnNode(name, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + } + } + return false; + } + function checkGrammarTypeReferenceInStrictMode(typeName) { + // Check if the type reference is using strict mode keyword + // Example: + // class C { + // foo(x: public){} // Error. + // } + if (typeName.kind === 65 /* Identifier */) { + checkGrammarTypeNameInStrictMode(typeName); + } + else if (typeName.kind === 126 /* QualifiedName */) { + // Walk from right to left and report a possible error at each Identifier in QualifiedName + // Example: + // x1: public.private.package // error at public and private + checkGrammarTypeNameInStrictMode(typeName.right); + checkGrammarTypeReferenceInStrictMode(typeName.left); + } + } + // This function will report an error for every identifier in property access expression + // whether it violates strict mode reserved words. + // Example: + // public // error at public + // public.private.package // error at public + // B.private.B // no error + function checkGrammarHeritageClauseElementInStrictMode(expression) { + // Example: + // class C extends public // error at public + if (expression && expression.kind === 65 /* Identifier */) { + return checkGrammarIdentifierInStrictMode(expression); + } + else if (expression && expression.kind === 155 /* PropertyAccessExpression */) { + // Walk from left to right in PropertyAccessExpression until we are at the left most expression + // in PropertyAccessExpression. According to grammar production of MemberExpression, + // the left component expression is a PrimaryExpression (i.e. Identifier) while the other + // component after dots can be IdentifierName. + checkGrammarHeritageClauseElementInStrictMode(expression.expression); + } + } + // The function takes an identifier itself or an expression which has SyntaxKind.Identifier. + function checkGrammarIdentifierInStrictMode(node, nameText) { + if (node && node.kind === 65 /* Identifier */ && isReservedwordInStrictMode(node)) { + if (!nameText) { + nameText = ts.declarationNameToString(node); + } + // TODO (yuisu): Fix when module is a strict mode + var errorReport = reportStrictModeGrammarErrorInClassDeclaration(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText) || + grammarErrorOnNode(node, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + return errorReport; + } + return false; + } + // The function takes an identifier when uses as a typeName in TypeReferenceNode + function checkGrammarTypeNameInStrictMode(node) { + if (node && node.kind === 65 /* Identifier */ && isReservedwordInStrictMode(node)) { + var nameText = ts.declarationNameToString(node); + // TODO (yuisu): Fix when module is a strict mode + var errorReport = reportStrictModeGrammarErrorInClassDeclaration(node, ts.Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText) || + grammarErrorOnNode(node, ts.Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode, nameText); + return errorReport; + } + return false; + } function checkGrammarDecorators(node) { if (!node.decorators) { return false; @@ -21721,11 +21888,11 @@ var ts; var inStrictMode = (node.parserContextFlags & 1 /* StrictMode */) !== 0; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; - var name_11 = prop.name; + var name_13 = prop.name; if (prop.kind === 175 /* OmittedExpression */ || - name_11.kind === 127 /* ComputedPropertyName */) { + name_13.kind === 127 /* ComputedPropertyName */) { // If the name is not a ComputedPropertyName, the grammar checking will skip it - checkGrammarComputedPropertyName(name_11); + checkGrammarComputedPropertyName(name_13); continue; } // ECMA-262 11.1.5 Object Initialiser @@ -21740,8 +21907,8 @@ var ts; if (prop.kind === 224 /* PropertyAssignment */ || prop.kind === 225 /* ShorthandPropertyAssignment */) { // Grammar checking for computedPropertName and shorthandPropertyAssignment checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); - if (name_11.kind === 7 /* NumericLiteral */) { - checkGrammarNumbericLiteral(name_11); + if (name_13.kind === 7 /* NumericLiteral */) { + checkGrammarNumbericLiteral(name_13); } currentKind = Property; } @@ -21757,26 +21924,26 @@ var ts; else { ts.Debug.fail("Unexpected syntax kind:" + prop.kind); } - if (!ts.hasProperty(seen, name_11.text)) { - seen[name_11.text] = currentKind; + if (!ts.hasProperty(seen, name_13.text)) { + seen[name_13.text] = currentKind; } else { - var existingKind = seen[name_11.text]; + var existingKind = seen[name_13.text]; if (currentKind === Property && existingKind === Property) { if (inStrictMode) { - grammarErrorOnNode(name_11, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); + grammarErrorOnNode(name_13, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); } } else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name_11.text] = currentKind | existingKind; + seen[name_13.text] = currentKind | existingKind; } else { - return grammarErrorOnNode(name_11, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); + return grammarErrorOnNode(name_13, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); } } else { - return grammarErrorOnNode(name_11, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + return grammarErrorOnNode(name_13, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); } } } @@ -22124,15 +22291,14 @@ var ts; var identifier = name; if (contextNode && (contextNode.parserContextFlags & 1 /* StrictMode */) && ts.isEvalOrArgumentsIdentifier(identifier)) { var nameText = ts.declarationNameToString(identifier); - // We are checking if this name is inside class declaration or class expression (which are under class definitions inside ES6 spec.) - // if so, we would like to give more explicit invalid usage error. - // This will be particularly helpful in the case of "arguments" as such case is very common mistake. - if (ts.getAncestor(name, 201 /* ClassDeclaration */) || ts.getAncestor(name, 174 /* ClassExpression */)) { - return grammarErrorOnNode(identifier, ts.Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode, nameText); - } - else { + // We check first if the name is inside class declaration or class expression; if so give explicit message + // otherwise report generic error message. + // reportGrammarErrorInClassDeclaration only return true if grammar error is successfully reported and false otherwise + var reportErrorInClassDeclaration = reportStrictModeGrammarErrorInClassDeclaration(identifier, ts.Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode, nameText); + if (!reportErrorInClassDeclaration) { return grammarErrorOnNode(identifier, ts.Diagnostics.Invalid_use_of_0_in_strict_mode, nameText); } + return reportErrorInClassDeclaration; } } } @@ -22631,9 +22797,9 @@ var ts; } var count = 0; while (true) { - var name_12 = baseName + "_" + (++count); - if (!ts.hasProperty(currentSourceFile.identifiers, name_12)) { - return name_12; + var name_14 = baseName + "_" + (++count); + if (!ts.hasProperty(currentSourceFile.identifiers, name_14)) { + return name_14; } } } @@ -23835,9 +24001,9 @@ var ts; tempFlags++; // Skip over 'i' and 'n' if (count !== 8 && count !== 13) { - var name_13 = count < 26 ? "_" + String.fromCharCode(97 /* a */ + count) : "_" + (count - 26); - if (isUniqueName(name_13)) { - return name_13; + var name_15 = count < 26 ? "_" + String.fromCharCode(97 /* a */ + count) : "_" + (count - 26); + if (isUniqueName(name_15)) { + return name_15; } } } @@ -23870,9 +24036,9 @@ var ts; } function generateNameForModuleOrEnum(node) { if (node.name.kind === 65 /* Identifier */) { - var name_14 = node.name.text; + var name_16 = node.name.text; // Use module/enum name itself if it is unique, otherwise make a unique variation - assignGeneratedName(node, isUniqueLocalName(name_14, node) ? name_14 : makeUniqueName(name_14)); + assignGeneratedName(node, isUniqueLocalName(name_16, node) ? name_16 : makeUniqueName(name_16)); } } function generateNameForImportOrExportDeclaration(node) { @@ -24085,8 +24251,8 @@ var ts; // Child scopes are always shown with a dot (even if they have no name), // unless it is a computed property. Then it is shown with brackets, // but the brackets are included in the name. - var name_15 = node.name; - if (!name_15 || name_15.kind !== 127 /* ComputedPropertyName */) { + var name_17 = node.name; + if (!name_17 || name_17.kind !== 127 /* ComputedPropertyName */) { scopeName = "." + scopeName; } scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; @@ -24115,10 +24281,10 @@ var ts; node.kind === 204 /* EnumDeclaration */) { // Declaration and has associated name use it if (node.name) { - var name_16 = node.name; + var name_18 = node.name; // For computed property names, the text will include the brackets - scopeName = name_16.kind === 127 /* ComputedPropertyName */ - ? ts.getTextOfNode(name_16) + scopeName = name_18.kind === 127 /* ComputedPropertyName */ + ? ts.getTextOfNode(name_18) : node.name.text; } recordScopeNameStart(scopeName); @@ -24592,6 +24758,7 @@ var ts; default: return -1 /* LessThan */; } + case 172 /* YieldExpression */: case 170 /* ConditionalExpression */: return -1 /* LessThan */; default: @@ -24779,6 +24946,16 @@ var ts; write("..."); emit(node.expression); } + function emitYieldExpression(node) { + write(ts.tokenToString(111 /* YieldKeyword */)); + if (node.asteriskToken) { + write("*"); + } + if (node.expression) { + write(" "); + emit(node.expression); + } + } function needsParenthesisForPropertyAccessOrInvocation(node) { switch (node.kind) { case 65 /* Identifier */: @@ -25037,6 +25214,9 @@ var ts; write("]"); } function emitMethod(node) { + if (languageVersion >= 2 /* ES6 */ && node.asteriskToken) { + write("*"); + } emit(node.name, false); if (languageVersion < 2 /* ES6 */) { write(": function "); @@ -26140,12 +26320,12 @@ var ts; function emitParameter(node) { if (languageVersion < 2 /* ES6 */) { if (ts.isBindingPattern(node.name)) { - var name_17 = createTempVariable(0 /* Auto */); + var name_19 = createTempVariable(0 /* Auto */); if (!tempParameters) { tempParameters = []; } - tempParameters.push(name_17); - emit(name_17); + tempParameters.push(name_19); + emit(name_19); } else { emit(node.name); @@ -26269,7 +26449,11 @@ var ts; write("default "); } } - write("function "); + write("function"); + if (languageVersion >= 2 /* ES6 */ && node.asteriskToken) { + write("*"); + } + write(" "); } if (shouldEmitFunctionName(node)) { emitDeclarationName(node); @@ -26616,6 +26800,9 @@ var ts; else if (member.kind === 137 /* SetAccessor */) { write("set "); } + if (member.asteriskToken) { + write("*"); + } emit(member.name); emitSignatureAndBody(member); emitEnd(member); @@ -27761,8 +27948,8 @@ var ts; // export { x, y } for (var _c = 0, _d = node.exportClause.elements; _c < _d.length; _c++) { var specifier = _d[_c]; - var name_18 = (specifier.propertyName || specifier.name).text; - (exportSpecifiers[name_18] || (exportSpecifiers[name_18] = [])).push(specifier); + var name_20 = (specifier.propertyName || specifier.name).text; + (exportSpecifiers[name_20] || (exportSpecifiers[name_20] = [])).push(specifier); } } break; @@ -28094,6 +28281,8 @@ var ts; return emitConditionalExpression(node); case 173 /* SpreadElementExpression */: return emitSpreadElementExpression(node); + case 172 /* YieldExpression */: + return emitYieldExpression(node); case 175 /* OmittedExpression */: return; case 179 /* Block */: @@ -28393,7 +28582,7 @@ var ts; } return { getSourceFile: getSourceFile, - getDefaultLibFileName: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), ts.getDefaultLibFileName(options)); }, + getDefaultLibFileName: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), getDefaultLibFileName(options)); }, writeFile: writeFile, getCurrentDirectory: function () { return currentDirectory || (currentDirectory = ts.sys.getCurrentDirectory()); }, useCaseSensitiveFileNames: function () { return ts.sys.useCaseSensitiveFileNames; }, @@ -28433,6 +28622,10 @@ var ts; } } ts.flattenDiagnosticMessageText = flattenDiagnosticMessageText; + function getDefaultLibFileName(options) { + return options.target === 2 /* ES6 */ ? "lib.es6.d.ts" : "lib.d.ts"; + } + ts.getDefaultLibFileName = getDefaultLibFileName; function createProgram(rootNames, options, host) { var program; var files = []; @@ -29753,9 +29946,9 @@ var ts; case 198 /* VariableDeclaration */: case 152 /* BindingElement */: var variableDeclarationNode; - var name_19; + var name_21; if (node.kind === 152 /* BindingElement */) { - name_19 = node.name; + name_21 = node.name; variableDeclarationNode = node; // binding elements are added only for variable declarations // bubble up to the containing variable declaration @@ -29767,16 +29960,16 @@ var ts; else { ts.Debug.assert(!ts.isBindingPattern(node.name)); variableDeclarationNode = node; - name_19 = node.name; + name_21 = node.name; } if (ts.isConst(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_19), ts.ScriptElementKind.constElement); + return createItem(node, getTextOfNode(name_21), ts.ScriptElementKind.constElement); } else if (ts.isLet(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_19), ts.ScriptElementKind.letElement); + return createItem(node, getTextOfNode(name_21), ts.ScriptElementKind.letElement); } else { - return createItem(node, getTextOfNode(name_19), ts.ScriptElementKind.variableElement); + return createItem(node, getTextOfNode(name_21), ts.ScriptElementKind.variableElement); } case 135 /* Constructor */: return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); @@ -32316,9 +32509,9 @@ var ts; } Rules.prototype.getRuleName = function (rule) { var o = this; - for (var name_20 in o) { - if (o[name_20] === rule) { - return name_20; + for (var name_22 in o) { + if (o[name_22] === rule) { + return name_22; } } throw new Error("Unknown rule"); @@ -36528,10 +36721,10 @@ var ts; for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) { var sourceFile = _a[_i]; var nameTable = getNameTable(sourceFile); - for (var name_21 in nameTable) { - if (!allNames[name_21]) { - allNames[name_21] = name_21; - var displayName = getCompletionEntryDisplayName(name_21, target, true); + for (var name_23 in nameTable) { + if (!allNames[name_23]) { + allNames[name_23] = name_23; + var displayName = getCompletionEntryDisplayName(name_23, target, true); if (displayName) { var entry = { name: displayName, @@ -38363,19 +38556,19 @@ var ts; if (isNameOfPropertyAssignment(node)) { var objectLiteral = node.parent.parent; var contextualType = typeInfoResolver.getContextualType(objectLiteral); - var name_22 = node.text; + var name_24 = node.text; if (contextualType) { if (contextualType.flags & 16384 /* Union */) { // This is a union type, first see if the property we are looking for is a union property (i.e. exists in all types) // if not, search the constituent types for the property - var unionProperty = contextualType.getProperty(name_22); + var unionProperty = contextualType.getProperty(name_24); if (unionProperty) { return [unionProperty]; } else { var result_3 = []; ts.forEach(contextualType.types, function (t) { - var symbol = t.getProperty(name_22); + var symbol = t.getProperty(name_24); if (symbol) { result_3.push(symbol); } @@ -38384,7 +38577,7 @@ var ts; } } else { - var symbol_1 = contextualType.getProperty(name_22); + var symbol_1 = contextualType.getProperty(name_24); if (symbol_1) { return [symbol_1]; } From 27b79ff99ac9e9f00dd95fb4f5140aa59bab7532 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 14 Apr 2015 22:57:06 -0700 Subject: [PATCH 4/5] respond to code review commment --- src/compiler/program.ts | 4 ---- src/compiler/utilities.ts | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 63eb3af784cc1..4646647802952 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -137,10 +137,6 @@ module ts { } } - export function getDefaultLibFileName(options: CompilerOptions): string { - return options.target === ScriptTarget.ES6 ? "lib.es6.d.ts" : "lib.d.ts"; - } - export function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program { let program: Program; let files: SourceFile[] = []; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 533a8b25e4f81..8a34d2f315b51 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1641,6 +1641,10 @@ module ts { } module ts { + export function getDefaultLibFileName(options: CompilerOptions): string { + return options.target === ScriptTarget.ES6 ? "lib.es6.d.ts" : "lib.d.ts"; + } + export function textSpanEnd(span: TextSpan) { return span.start + span.length } From a8e4803fcdc0db2bb8adc1685edfe5447501ade4 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 14 Apr 2015 23:10:07 -0700 Subject: [PATCH 5/5] Update LKG --- bin/tsc.js | 188 +++++---- bin/tsserver.js | 794 ++++++++++++++++++++---------------- bin/typescript.d.ts | 27 +- bin/typescript.js | 764 +++++++++++++++++++--------------- bin/typescriptServices.d.ts | 27 +- bin/typescriptServices.js | 764 +++++++++++++++++++--------------- 6 files changed, 1417 insertions(+), 1147 deletions(-) diff --git a/bin/tsc.js b/bin/tsc.js index 83be107f8d1f7..b6cb0edc12cc8 100644 --- a/bin/tsc.js +++ b/bin/tsc.js @@ -1445,7 +1445,7 @@ var ts; (function (ts) { var textToToken = { "any": 112, - "as": 102, + "as": 111, "boolean": 113, "break": 66, "case": 67, @@ -1470,24 +1470,24 @@ var ts; "function": 83, "get": 116, "if": 84, - "implements": 103, + "implements": 102, "import": 85, "in": 86, "instanceof": 87, - "interface": 104, - "let": 105, + "interface": 103, + "let": 104, "module": 117, "new": 88, "null": 89, "number": 119, - "package": 106, - "private": 107, - "protected": 108, - "public": 109, + "package": 105, + "private": 106, + "protected": 107, + "public": 108, "require": 118, "return": 90, "set": 120, - "static": 110, + "static": 109, "string": 121, "super": 91, "switch": 92, @@ -1502,7 +1502,7 @@ var ts; "void": 99, "while": 100, "with": 101, - "yield": 111, + "yield": 110, "of": 125, "{": 14, "}": 15, @@ -4010,7 +4010,7 @@ var ts; } ts.getClassExtendsHeritageClauseElement = getClassExtendsHeritageClauseElement; function getClassImplementsHeritageClauseElements(node) { - var heritageClause = getHeritageClause(node.heritageClauses, 103); + var heritageClause = getHeritageClause(node.heritageClauses, 102); return heritageClause ? heritageClause.types : undefined; } ts.getClassImplementsHeritageClauseElements = getClassImplementsHeritageClauseElements; @@ -4125,10 +4125,10 @@ var ts; ts.isESSymbolIdentifier = isESSymbolIdentifier; function isModifier(token) { switch (token) { - case 109: - case 107: case 108: - case 110: + case 106: + case 107: + case 109: case 78: case 115: case 70: @@ -4536,6 +4536,10 @@ var ts; })(ts || (ts = {})); var ts; (function (ts) { + function getDefaultLibFileName(options) { + return options.target === 2 ? "lib.es6.d.ts" : "lib.d.ts"; + } + ts.getDefaultLibFileName = getDefaultLibFileName; function textSpanEnd(span) { return span.start + span.length; } @@ -4984,10 +4988,10 @@ var ts; ; function modifierToFlag(token) { switch (token) { - case 110: return 128; - case 109: return 16; - case 108: return 64; - case 107: return 32; + case 109: return 128; + case 108: return 16; + case 107: return 64; + case 106: return 32; case 78: return 1; case 115: return 2; case 70: return 8192; @@ -5494,7 +5498,7 @@ var ts; if (token === 65) { return true; } - if (token === 111 && inYieldContext()) { + if (token === 110 && inYieldContext()) { return false; } return token > 101; @@ -5730,7 +5734,7 @@ var ts; ts.Debug.assert(token === 14); if (nextToken() === 15) { var next = nextToken(); - return next === 23 || next === 14 || next === 79 || next === 103; + return next === 23 || next === 14 || next === 79 || next === 102; } return true; } @@ -5739,7 +5743,7 @@ var ts; return isIdentifier(); } function isHeritageClauseExtendsOrImplementsKeyword() { - if (token === 103 || + if (token === 102 || token === 79) { return lookAhead(nextTokenIsStartOfExpression); } @@ -5767,11 +5771,11 @@ var ts; case 4: return token === 15 || token === 67 || token === 73; case 8: - return token === 14 || token === 79 || token === 103; + return token === 14 || token === 79 || token === 102; case 9: return isVariableDeclaratorListTerminator(); case 16: - return token === 25 || token === 16 || token === 14 || token === 79 || token === 103; + return token === 25 || token === 16 || token === 14 || token === 79 || token === 102; case 12: return token === 17 || token === 22; case 14: @@ -6575,7 +6579,7 @@ var ts; case 38: case 39: case 24: - case 111: + case 110: return true; default: if (isBinaryOperator()) { @@ -6645,7 +6649,7 @@ var ts; return parseConditionalExpressionRest(expr); } function isYieldExpression() { - if (token === 111) { + if (token === 110) { if (inYieldContext()) { return true; } @@ -7270,7 +7274,7 @@ var ts; parseExpected(16); var initializer = undefined; if (token !== 22) { - if (token === 98 || token === 105 || token === 70) { + if (token === 98 || token === 104 || token === 70) { initializer = parseVariableDeclarationList(true); } else { @@ -7431,7 +7435,7 @@ var ts; return !inErrorRecovery; case 14: case 98: - case 105: + case 104: case 83: case 69: case 84: @@ -7452,17 +7456,17 @@ var ts; case 70: var isConstEnum = lookAhead(nextTokenIsEnumKeyword); return !isConstEnum; - case 104: + case 103: case 117: case 77: case 123: if (isDeclarationStart()) { return false; } - case 109: - case 107: case 108: - case 110: + case 106: + case 107: + case 109: if (lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine)) { return false; } @@ -7517,7 +7521,7 @@ var ts; return parseTryStatement(); case 72: return parseDebuggerStatement(); - case 105: + case 104: if (isLetDeclaration()) { return parseVariableStatement(scanner.getStartPos(), undefined, undefined); } @@ -7542,7 +7546,7 @@ var ts; return undefined; } return parseVariableStatement(start, decorators, modifiers); - case 105: + case 104: if (!isLetDeclaration()) { return undefined; } @@ -7627,7 +7631,7 @@ var ts; switch (token) { case 98: break; - case 105: + case 104: node.flags |= 4096; break; case 70: @@ -7726,10 +7730,10 @@ var ts; } function isClassMemberModifier(idToken) { switch (idToken) { - case 109: - case 107: case 108: - case 110: + case 106: + case 107: + case 109: return true; default: return false; @@ -7892,7 +7896,7 @@ var ts; return parseList(19, false, parseHeritageClause); } function parseHeritageClause() { - if (token === 79 || token === 103) { + if (token === 79 || token === 102) { var node = createNode(222); node.token = token; nextToken(); @@ -7910,7 +7914,7 @@ var ts; return finishNode(node); } function isHeritageClause() { - return token === 79 || token === 103; + return token === 79 || token === 102; } function parseClassMembers() { return parseList(6, false, parseClassElement); @@ -7919,7 +7923,7 @@ var ts; var node = createNode(202, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(104); + parseExpected(103); node.name = parseIdentifier(); node.typeParameters = parseTypeParameters(); node.heritageClauses = parseHeritageClauses(false); @@ -8076,7 +8080,7 @@ var ts; function parseNamespaceImport() { var namespaceImport = createNode(211); parseExpected(35); - parseExpected(102); + parseExpected(111); namespaceImport.name = parseIdentifier(); return finishNode(namespaceImport); } @@ -8097,9 +8101,9 @@ var ts; var checkIdentifierStart = scanner.getTokenPos(); var checkIdentifierEnd = scanner.getTextPos(); var identifierName = parseIdentifierName(); - if (token === 102) { + if (token === 111) { node.propertyName = identifierName; - parseExpected(102); + parseExpected(111); checkIdentifierIsKeyword = ts.isKeyword(token) && !isIdentifier(); checkIdentifierStart = scanner.getTokenPos(); checkIdentifierEnd = scanner.getTextPos(); @@ -8153,10 +8157,10 @@ var ts; case 70: case 83: return true; - case 105: + case 104: return isLetDeclaration(); case 69: - case 104: + case 103: case 77: case 123: return lookAhead(nextTokenIsIdentifierOrKeyword); @@ -8167,10 +8171,10 @@ var ts; case 78: return lookAhead(nextTokenCanFollowExportKeyword); case 115: - case 109: - case 107: case 108: - case 110: + case 106: + case 107: + case 109: return lookAhead(nextTokenIsDeclarationStart); case 52: return !followsModifier; @@ -8202,7 +8206,7 @@ var ts; return isDeclarationStart(true); } function nextTokenIsAsKeyword() { - return nextToken() === 102; + return nextToken() === 111; } function parseDeclaration() { var fullStart = getNodePos(); @@ -8219,14 +8223,14 @@ var ts; } switch (token) { case 98: - case 105: + case 104: case 70: return parseVariableStatement(fullStart, decorators, modifiers); case 83: return parseFunctionDeclaration(fullStart, decorators, modifiers); case 69: return parseClassDeclaration(fullStart, decorators, modifiers); - case 104: + case 103: return parseInterfaceDeclaration(fullStart, decorators, modifiers); case 123: return parseTypeAliasDeclaration(fullStart, decorators, modifiers); @@ -10732,12 +10736,13 @@ var ts; return result; } function getPropertiesOfType(type) { - if (type.flags & 16384) { - return getPropertiesOfUnionType(type); - } - return getPropertiesOfObjectType(getApparentType(type)); + type = getApparentType(type); + return type.flags & 16384 ? getPropertiesOfUnionType(type) : getPropertiesOfObjectType(type); } function getApparentType(type) { + if (type.flags & 16384) { + type = getReducedTypeOfUnionType(type); + } if (type.flags & 512) { do { type = getConstraintOfTypeParameter(type); @@ -10806,28 +10811,27 @@ var ts; return property; } function getPropertyOfType(type, name) { - if (type.flags & 16384) { - return getPropertyOfUnionType(type, name); - } - if (!(type.flags & 48128)) { - type = getApparentType(type); - if (!(type.flags & 48128)) { - return undefined; + type = getApparentType(type); + if (type.flags & 48128) { + var resolved = resolveObjectOrUnionTypeMembers(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 = getPropertyOfObjectType(globalFunctionType, name); + if (symbol) { + return symbol; + } } + return getPropertyOfObjectType(globalObjectType, name); } - if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { - var symbol = getPropertyOfObjectType(globalFunctionType, name); - if (symbol) - return symbol; + if (type.flags & 16384) { + return getPropertyOfUnionType(type, name); } - return getPropertyOfObjectType(globalObjectType, name); + return undefined; } function getSignaturesOfObjectOrUnionType(type, kind) { if (type.flags & (48128 | 16384)) { @@ -11333,9 +11337,16 @@ var ts; if (!type) { type = unionTypes[id] = createObjectType(16384 | getWideningFlagsOfTypes(sortedTypes)); type.types = sortedTypes; + type.reducedType = noSubtypeReduction ? undefined : type; } return type; } + function getReducedTypeOfUnionType(type) { + if (!type.reducedType) { + type.reducedType = getUnionType(type.types, false); + } + return type.reducedType; + } function getTypeFromUnionTypeNode(node) { var links = getNodeLinks(node); if (!links.resolvedType) { @@ -15776,7 +15787,10 @@ var ts; return checkElementTypeOfArrayOrString(inputType, errorNode); } if (isArrayLikeType(inputType)) { - return getIndexTypeOfType(inputType, 1); + var indexType = getIndexTypeOfType(inputType, 1); + if (indexType) { + return indexType; + } } error(errorNode, ts.Diagnostics.Type_0_is_not_an_array_type, typeToString(inputType)); return unknownType; @@ -17765,7 +17779,7 @@ var ts; } function isReservedwordInStrictMode(node) { return (node.parserContextFlags & 1) && - (node.originalKeywordKind >= 103 && node.originalKeywordKind <= 111); + (node.originalKeywordKind >= 102 && node.originalKeywordKind <= 110); } function reportStrictModeGrammarErrorInClassDeclaration(identifier, message, arg0, arg1, arg2) { if (ts.getAncestor(identifier, 201) || ts.getAncestor(identifier, 174)) { @@ -17914,14 +17928,14 @@ var ts; for (var _i = 0, _a = node.modifiers; _i < _a.length; _i++) { var modifier = _a[_i]; switch (modifier.kind) { - case 109: case 108: case 107: + case 106: var text = void 0; - if (modifier.kind === 109) { + if (modifier.kind === 108) { text = "public"; } - else if (modifier.kind === 108) { + else if (modifier.kind === 107) { text = "protected"; lastProtected = modifier; } @@ -17940,7 +17954,7 @@ var ts; } flags |= ts.modifierToFlag(modifier.kind); break; - case 110: + case 109: if (flags & 128) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "static"); } @@ -18170,7 +18184,7 @@ var ts; seenExtendsClause = true; } else { - ts.Debug.assert(heritageClause.token === 103); + ts.Debug.assert(heritageClause.token === 102); if (seenImplementsClause) { return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.implements_clause_already_seen); } @@ -18192,7 +18206,7 @@ var ts; seenExtendsClause = true; } else { - ts.Debug.assert(heritageClause.token === 103); + ts.Debug.assert(heritageClause.token === 102); return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.Interface_declaration_cannot_have_implements_clause); } checkGrammarHeritageClause(heritageClause); @@ -20959,7 +20973,7 @@ var ts; emit(node.expression); } function emitYieldExpression(node) { - write(ts.tokenToString(111)); + write(ts.tokenToString(110)); if (node.asteriskToken) { write("*"); } @@ -21583,7 +21597,7 @@ var ts; var tokenKind = 98; if (decl && languageVersion >= 2) { if (ts.isLet(decl)) { - tokenKind = 105; + tokenKind = 104; } else if (ts.isConst(decl)) { tokenKind = 70; @@ -21596,7 +21610,7 @@ var ts; switch (tokenKind) { case 98: return write("var "); - case 105: + case 104: return write("let "); case 70: return write("const "); @@ -24212,7 +24226,7 @@ var ts; } return { getSourceFile: getSourceFile, - getDefaultLibFileName: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), getDefaultLibFileName(options)); }, + getDefaultLibFileName: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), ts.getDefaultLibFileName(options)); }, writeFile: writeFile, getCurrentDirectory: function () { return currentDirectory || (currentDirectory = ts.sys.getCurrentDirectory()); }, useCaseSensitiveFileNames: function () { return ts.sys.useCaseSensitiveFileNames; }, @@ -24252,10 +24266,6 @@ var ts; } } ts.flattenDiagnosticMessageText = flattenDiagnosticMessageText; - function getDefaultLibFileName(options) { - return options.target === 2 ? "lib.es6.d.ts" : "lib.d.ts"; - } - ts.getDefaultLibFileName = getDefaultLibFileName; function createProgram(rootNames, options, host) { var program; var files = []; diff --git a/bin/tsserver.js b/bin/tsserver.js index e8f4bd1398a31..1067c4f315008 100644 --- a/bin/tsserver.js +++ b/bin/tsserver.js @@ -1445,7 +1445,7 @@ var ts; (function (ts) { var textToToken = { "any": 112, - "as": 102, + "as": 111, "boolean": 113, "break": 66, "case": 67, @@ -1470,24 +1470,24 @@ var ts; "function": 83, "get": 116, "if": 84, - "implements": 103, + "implements": 102, "import": 85, "in": 86, "instanceof": 87, - "interface": 104, - "let": 105, + "interface": 103, + "let": 104, "module": 117, "new": 88, "null": 89, "number": 119, - "package": 106, - "private": 107, - "protected": 108, - "public": 109, + "package": 105, + "private": 106, + "protected": 107, + "public": 108, "require": 118, "return": 90, "set": 120, - "static": 110, + "static": 109, "string": 121, "super": 91, "switch": 92, @@ -1502,7 +1502,7 @@ var ts; "void": 99, "while": 100, "with": 101, - "yield": 111, + "yield": 110, "of": 125, "{": 14, "}": 15, @@ -3844,7 +3844,7 @@ var ts; } ts.getClassExtendsHeritageClauseElement = getClassExtendsHeritageClauseElement; function getClassImplementsHeritageClauseElements(node) { - var heritageClause = getHeritageClause(node.heritageClauses, 103); + var heritageClause = getHeritageClause(node.heritageClauses, 102); return heritageClause ? heritageClause.types : undefined; } ts.getClassImplementsHeritageClauseElements = getClassImplementsHeritageClauseElements; @@ -3959,10 +3959,10 @@ var ts; ts.isESSymbolIdentifier = isESSymbolIdentifier; function isModifier(token) { switch (token) { - case 109: - case 107: case 108: - case 110: + case 106: + case 107: + case 109: case 78: case 115: case 70: @@ -4370,6 +4370,10 @@ var ts; })(ts || (ts = {})); var ts; (function (ts) { + function getDefaultLibFileName(options) { + return options.target === 2 ? "lib.es6.d.ts" : "lib.d.ts"; + } + ts.getDefaultLibFileName = getDefaultLibFileName; function textSpanEnd(span) { return span.start + span.length; } @@ -4818,10 +4822,10 @@ var ts; ; function modifierToFlag(token) { switch (token) { - case 110: return 128; - case 109: return 16; - case 108: return 64; - case 107: return 32; + case 109: return 128; + case 108: return 16; + case 107: return 64; + case 106: return 32; case 78: return 1; case 115: return 2; case 70: return 8192; @@ -5328,7 +5332,7 @@ var ts; if (token === 65) { return true; } - if (token === 111 && inYieldContext()) { + if (token === 110 && inYieldContext()) { return false; } return token > 101; @@ -5564,7 +5568,7 @@ var ts; ts.Debug.assert(token === 14); if (nextToken() === 15) { var next = nextToken(); - return next === 23 || next === 14 || next === 79 || next === 103; + return next === 23 || next === 14 || next === 79 || next === 102; } return true; } @@ -5573,7 +5577,7 @@ var ts; return isIdentifier(); } function isHeritageClauseExtendsOrImplementsKeyword() { - if (token === 103 || + if (token === 102 || token === 79) { return lookAhead(nextTokenIsStartOfExpression); } @@ -5601,11 +5605,11 @@ var ts; case 4: return token === 15 || token === 67 || token === 73; case 8: - return token === 14 || token === 79 || token === 103; + return token === 14 || token === 79 || token === 102; case 9: return isVariableDeclaratorListTerminator(); case 16: - return token === 25 || token === 16 || token === 14 || token === 79 || token === 103; + return token === 25 || token === 16 || token === 14 || token === 79 || token === 102; case 12: return token === 17 || token === 22; case 14: @@ -6409,7 +6413,7 @@ var ts; case 38: case 39: case 24: - case 111: + case 110: return true; default: if (isBinaryOperator()) { @@ -6479,7 +6483,7 @@ var ts; return parseConditionalExpressionRest(expr); } function isYieldExpression() { - if (token === 111) { + if (token === 110) { if (inYieldContext()) { return true; } @@ -7104,7 +7108,7 @@ var ts; parseExpected(16); var initializer = undefined; if (token !== 22) { - if (token === 98 || token === 105 || token === 70) { + if (token === 98 || token === 104 || token === 70) { initializer = parseVariableDeclarationList(true); } else { @@ -7265,7 +7269,7 @@ var ts; return !inErrorRecovery; case 14: case 98: - case 105: + case 104: case 83: case 69: case 84: @@ -7286,17 +7290,17 @@ var ts; case 70: var isConstEnum = lookAhead(nextTokenIsEnumKeyword); return !isConstEnum; - case 104: + case 103: case 117: case 77: case 123: if (isDeclarationStart()) { return false; } - case 109: - case 107: case 108: - case 110: + case 106: + case 107: + case 109: if (lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine)) { return false; } @@ -7351,7 +7355,7 @@ var ts; return parseTryStatement(); case 72: return parseDebuggerStatement(); - case 105: + case 104: if (isLetDeclaration()) { return parseVariableStatement(scanner.getStartPos(), undefined, undefined); } @@ -7376,7 +7380,7 @@ var ts; return undefined; } return parseVariableStatement(start, decorators, modifiers); - case 105: + case 104: if (!isLetDeclaration()) { return undefined; } @@ -7461,7 +7465,7 @@ var ts; switch (token) { case 98: break; - case 105: + case 104: node.flags |= 4096; break; case 70: @@ -7560,10 +7564,10 @@ var ts; } function isClassMemberModifier(idToken) { switch (idToken) { - case 109: - case 107: case 108: - case 110: + case 106: + case 107: + case 109: return true; default: return false; @@ -7726,7 +7730,7 @@ var ts; return parseList(19, false, parseHeritageClause); } function parseHeritageClause() { - if (token === 79 || token === 103) { + if (token === 79 || token === 102) { var node = createNode(222); node.token = token; nextToken(); @@ -7744,7 +7748,7 @@ var ts; return finishNode(node); } function isHeritageClause() { - return token === 79 || token === 103; + return token === 79 || token === 102; } function parseClassMembers() { return parseList(6, false, parseClassElement); @@ -7753,7 +7757,7 @@ var ts; var node = createNode(202, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(104); + parseExpected(103); node.name = parseIdentifier(); node.typeParameters = parseTypeParameters(); node.heritageClauses = parseHeritageClauses(false); @@ -7910,7 +7914,7 @@ var ts; function parseNamespaceImport() { var namespaceImport = createNode(211); parseExpected(35); - parseExpected(102); + parseExpected(111); namespaceImport.name = parseIdentifier(); return finishNode(namespaceImport); } @@ -7931,9 +7935,9 @@ var ts; var checkIdentifierStart = scanner.getTokenPos(); var checkIdentifierEnd = scanner.getTextPos(); var identifierName = parseIdentifierName(); - if (token === 102) { + if (token === 111) { node.propertyName = identifierName; - parseExpected(102); + parseExpected(111); checkIdentifierIsKeyword = ts.isKeyword(token) && !isIdentifier(); checkIdentifierStart = scanner.getTokenPos(); checkIdentifierEnd = scanner.getTextPos(); @@ -7987,10 +7991,10 @@ var ts; case 70: case 83: return true; - case 105: + case 104: return isLetDeclaration(); case 69: - case 104: + case 103: case 77: case 123: return lookAhead(nextTokenIsIdentifierOrKeyword); @@ -8001,10 +8005,10 @@ var ts; case 78: return lookAhead(nextTokenCanFollowExportKeyword); case 115: - case 109: - case 107: case 108: - case 110: + case 106: + case 107: + case 109: return lookAhead(nextTokenIsDeclarationStart); case 52: return !followsModifier; @@ -8036,7 +8040,7 @@ var ts; return isDeclarationStart(true); } function nextTokenIsAsKeyword() { - return nextToken() === 102; + return nextToken() === 111; } function parseDeclaration() { var fullStart = getNodePos(); @@ -8053,14 +8057,14 @@ var ts; } switch (token) { case 98: - case 105: + case 104: case 70: return parseVariableStatement(fullStart, decorators, modifiers); case 83: return parseFunctionDeclaration(fullStart, decorators, modifiers); case 69: return parseClassDeclaration(fullStart, decorators, modifiers); - case 104: + case 103: return parseInterfaceDeclaration(fullStart, decorators, modifiers); case 123: return parseTypeAliasDeclaration(fullStart, decorators, modifiers); @@ -11075,12 +11079,13 @@ var ts; return result; } function getPropertiesOfType(type) { - if (type.flags & 16384) { - return getPropertiesOfUnionType(type); - } - return getPropertiesOfObjectType(getApparentType(type)); + type = getApparentType(type); + return type.flags & 16384 ? getPropertiesOfUnionType(type) : getPropertiesOfObjectType(type); } function getApparentType(type) { + if (type.flags & 16384) { + type = getReducedTypeOfUnionType(type); + } if (type.flags & 512) { do { type = getConstraintOfTypeParameter(type); @@ -11149,28 +11154,27 @@ var ts; return property; } function getPropertyOfType(type, name) { - if (type.flags & 16384) { - return getPropertyOfUnionType(type, name); - } - if (!(type.flags & 48128)) { - type = getApparentType(type); - if (!(type.flags & 48128)) { - return undefined; + type = getApparentType(type); + if (type.flags & 48128) { + var resolved = resolveObjectOrUnionTypeMembers(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 = getPropertyOfObjectType(globalFunctionType, name); + if (symbol) { + return symbol; + } } + return getPropertyOfObjectType(globalObjectType, name); } - if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { - var symbol = getPropertyOfObjectType(globalFunctionType, name); - if (symbol) - return symbol; + if (type.flags & 16384) { + return getPropertyOfUnionType(type, name); } - return getPropertyOfObjectType(globalObjectType, name); + return undefined; } function getSignaturesOfObjectOrUnionType(type, kind) { if (type.flags & (48128 | 16384)) { @@ -11676,9 +11680,16 @@ var ts; if (!type) { type = unionTypes[id] = createObjectType(16384 | getWideningFlagsOfTypes(sortedTypes)); type.types = sortedTypes; + type.reducedType = noSubtypeReduction ? undefined : type; } return type; } + function getReducedTypeOfUnionType(type) { + if (!type.reducedType) { + type.reducedType = getUnionType(type.types, false); + } + return type.reducedType; + } function getTypeFromUnionTypeNode(node) { var links = getNodeLinks(node); if (!links.resolvedType) { @@ -16119,7 +16130,10 @@ var ts; return checkElementTypeOfArrayOrString(inputType, errorNode); } if (isArrayLikeType(inputType)) { - return getIndexTypeOfType(inputType, 1); + var indexType = getIndexTypeOfType(inputType, 1); + if (indexType) { + return indexType; + } } error(errorNode, ts.Diagnostics.Type_0_is_not_an_array_type, typeToString(inputType)); return unknownType; @@ -18108,7 +18122,7 @@ var ts; } function isReservedwordInStrictMode(node) { return (node.parserContextFlags & 1) && - (node.originalKeywordKind >= 103 && node.originalKeywordKind <= 111); + (node.originalKeywordKind >= 102 && node.originalKeywordKind <= 110); } function reportStrictModeGrammarErrorInClassDeclaration(identifier, message, arg0, arg1, arg2) { if (ts.getAncestor(identifier, 201) || ts.getAncestor(identifier, 174)) { @@ -18257,14 +18271,14 @@ var ts; for (var _i = 0, _a = node.modifiers; _i < _a.length; _i++) { var modifier = _a[_i]; switch (modifier.kind) { - case 109: case 108: case 107: + case 106: var text = void 0; - if (modifier.kind === 109) { + if (modifier.kind === 108) { text = "public"; } - else if (modifier.kind === 108) { + else if (modifier.kind === 107) { text = "protected"; lastProtected = modifier; } @@ -18283,7 +18297,7 @@ var ts; } flags |= ts.modifierToFlag(modifier.kind); break; - case 110: + case 109: if (flags & 128) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "static"); } @@ -18513,7 +18527,7 @@ var ts; seenExtendsClause = true; } else { - ts.Debug.assert(heritageClause.token === 103); + ts.Debug.assert(heritageClause.token === 102); if (seenImplementsClause) { return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.implements_clause_already_seen); } @@ -18535,7 +18549,7 @@ var ts; seenExtendsClause = true; } else { - ts.Debug.assert(heritageClause.token === 103); + ts.Debug.assert(heritageClause.token === 102); return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.Interface_declaration_cannot_have_implements_clause); } checkGrammarHeritageClause(heritageClause); @@ -21302,7 +21316,7 @@ var ts; emit(node.expression); } function emitYieldExpression(node) { - write(ts.tokenToString(111)); + write(ts.tokenToString(110)); if (node.asteriskToken) { write("*"); } @@ -21926,7 +21940,7 @@ var ts; var tokenKind = 98; if (decl && languageVersion >= 2) { if (ts.isLet(decl)) { - tokenKind = 105; + tokenKind = 104; } else if (ts.isConst(decl)) { tokenKind = 70; @@ -21939,7 +21953,7 @@ var ts; switch (tokenKind) { case 98: return write("var "); - case 105: + case 104: return write("let "); case 70: return write("const "); @@ -24555,7 +24569,7 @@ var ts; } return { getSourceFile: getSourceFile, - getDefaultLibFileName: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), getDefaultLibFileName(options)); }, + getDefaultLibFileName: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), ts.getDefaultLibFileName(options)); }, writeFile: writeFile, getCurrentDirectory: function () { return currentDirectory || (currentDirectory = ts.sys.getCurrentDirectory()); }, useCaseSensitiveFileNames: function () { return ts.sys.useCaseSensitiveFileNames; }, @@ -24595,10 +24609,6 @@ var ts; } } ts.flattenDiagnosticMessageText = flattenDiagnosticMessageText; - function getDefaultLibFileName(options) { - return options.target === 2 ? "lib.es6.d.ts" : "lib.d.ts"; - } - ts.getDefaultLibFileName = getDefaultLibFileName; function createProgram(rootNames, options, host) { var program; var files = []; @@ -25464,28 +25474,30 @@ var ts; var rawItems = []; ts.forEach(program.getSourceFiles(), function (sourceFile) { cancellationToken.throwIfCancellationRequested(); - var declarations = sourceFile.getNamedDeclarations(); - for (var _i = 0; _i < declarations.length; _i++) { - var declaration = declarations[_i]; - var name = getDeclarationName(declaration); - if (name !== undefined) { - var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name); + var nameToDeclarations = sourceFile.getNamedDeclarations(); + for (var name_21 in nameToDeclarations) { + var declarations = ts.getProperty(nameToDeclarations, name_21); + if (declarations) { + var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_21); if (!matches) { continue; } - if (patternMatcher.patternContainsDots) { - var containers = getContainers(declaration); - if (!containers) { - return undefined; - } - matches = patternMatcher.getMatches(containers, name); - if (!matches) { - continue; + for (var _i = 0; _i < declarations.length; _i++) { + var declaration = declarations[_i]; + if (patternMatcher.patternContainsDots) { + var containers = getContainers(declaration); + if (!containers) { + return undefined; + } + matches = patternMatcher.getMatches(containers, name_21); + if (!matches) { + continue; + } } + var fileName = sourceFile.fileName; + var matchKind = bestMatchKind(matches); + rawItems.push({ name: name_21, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); } - var fileName = sourceFile.fileName; - var matchKind = bestMatchKind(matches); - rawItems.push({ name: name, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); } } }); @@ -25505,25 +25517,13 @@ var ts; } return true; } - function getDeclarationName(declaration) { - var result = getTextOfIdentifierOrLiteral(declaration.name); - if (result !== undefined) { - return result; - } - if (declaration.name.kind === 127) { - var expr = declaration.name.expression; - if (expr.kind === 155) { - return expr.name.text; - } - return getTextOfIdentifierOrLiteral(expr); - } - return undefined; - } function getTextOfIdentifierOrLiteral(node) { - if (node.kind === 65 || - node.kind === 8 || - node.kind === 7) { - return node.text; + if (node) { + if (node.kind === 65 || + node.kind === 8 || + node.kind === 7) { + return node.text; + } } return undefined; } @@ -25826,9 +25826,9 @@ var ts; case 198: case 152: var variableDeclarationNode; - var name_21; + var name_22; if (node.kind === 152) { - name_21 = node.name; + name_22 = node.name; variableDeclarationNode = node; while (variableDeclarationNode && variableDeclarationNode.kind !== 198) { variableDeclarationNode = variableDeclarationNode.parent; @@ -25838,16 +25838,16 @@ var ts; else { ts.Debug.assert(!ts.isBindingPattern(node.name)); variableDeclarationNode = node; - name_21 = node.name; + name_22 = node.name; } if (ts.isConst(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_21), ts.ScriptElementKind.constElement); + return createItem(node, getTextOfNode(name_22), ts.ScriptElementKind.constElement); } else if (ts.isLet(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_21), ts.ScriptElementKind.letElement); + return createItem(node, getTextOfNode(name_22), ts.ScriptElementKind.letElement); } else { - return createItem(node, getTextOfNode(name_21), ts.ScriptElementKind.variableElement); + return createItem(node, getTextOfNode(name_22), ts.ScriptElementKind.variableElement); } case 135: return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); @@ -26439,7 +26439,8 @@ var ts; var SignatureHelp; (function (SignatureHelp) { var emptyArray = []; - function getSignatureHelpItems(sourceFile, position, typeInfoResolver, cancellationToken) { + function getSignatureHelpItems(program, sourceFile, position, cancellationToken) { + var typeChecker = program.getTypeChecker(); var startingToken = ts.findTokenOnLeftOfPosition(sourceFile, position); if (!startingToken) { return undefined; @@ -26451,12 +26452,51 @@ var ts; } var call = argumentInfo.invocation; var candidates = []; - var resolvedSignature = typeInfoResolver.getResolvedSignature(call, candidates); + var resolvedSignature = typeChecker.getResolvedSignature(call, candidates); cancellationToken.throwIfCancellationRequested(); if (!candidates.length) { + if (ts.isJavaScript(sourceFile.fileName)) { + return createJavaScriptSignatureHelpItems(argumentInfo); + } return undefined; } return createSignatureHelpItems(candidates, resolvedSignature, argumentInfo); + function createJavaScriptSignatureHelpItems(argumentInfo) { + if (argumentInfo.invocation.kind !== 157) { + return undefined; + } + var callExpression = argumentInfo.invocation; + var expression = callExpression.expression; + var name = expression.kind === 65 + ? expression + : expression.kind === 155 + ? expression.name + : undefined; + if (!name || !name.text) { + return undefined; + } + var typeChecker = program.getTypeChecker(); + for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) { + var sourceFile_1 = _a[_i]; + var nameToDeclarations = sourceFile_1.getNamedDeclarations(); + var declarations = ts.getProperty(nameToDeclarations, name.text); + if (declarations) { + for (var _b = 0; _b < declarations.length; _b++) { + var declaration = declarations[_b]; + var symbol = declaration.symbol; + if (symbol) { + var type = typeChecker.getTypeOfSymbolAtLocation(symbol, declaration); + if (type) { + var callSignatures = type.getCallSignatures(); + if (callSignatures && callSignatures.length) { + return createSignatureHelpItems(callSignatures, callSignatures[0], argumentInfo); + } + } + } + } + } + } + } function getImmediatelyContainingArgumentInfo(node) { if (node.parent.kind === 157 || node.parent.kind === 158) { var callExpression = node.parent; @@ -26618,8 +26658,8 @@ var ts; var isTypeParameterList = argumentListInfo.kind === 0; var invocation = argumentListInfo.invocation; var callTarget = ts.getInvokedExpression(invocation); - var callTargetSymbol = typeInfoResolver.getSymbolAtLocation(callTarget); - var callTargetDisplayParts = callTargetSymbol && ts.symbolToDisplayParts(typeInfoResolver, callTargetSymbol, undefined, undefined); + var callTargetSymbol = typeChecker.getSymbolAtLocation(callTarget); + var callTargetDisplayParts = callTargetSymbol && ts.symbolToDisplayParts(typeChecker, callTargetSymbol, undefined, undefined); var items = ts.map(candidates, function (candidateSignature) { var signatureHelpParameters; var prefixDisplayParts = []; @@ -26633,13 +26673,13 @@ var ts; signatureHelpParameters = typeParameters && typeParameters.length > 0 ? ts.map(typeParameters, createSignatureHelpParameterForTypeParameter) : emptyArray; suffixDisplayParts.push(ts.punctuationPart(25)); var parameterParts = ts.mapToDisplayParts(function (writer) { - return typeInfoResolver.getSymbolDisplayBuilder().buildDisplayForParametersAndDelimiters(candidateSignature.parameters, writer, invocation); + return typeChecker.getSymbolDisplayBuilder().buildDisplayForParametersAndDelimiters(candidateSignature.parameters, writer, invocation); }); suffixDisplayParts.push.apply(suffixDisplayParts, parameterParts); } else { var typeParameterParts = ts.mapToDisplayParts(function (writer) { - return typeInfoResolver.getSymbolDisplayBuilder().buildDisplayForTypeParametersAndDelimiters(candidateSignature.typeParameters, writer, invocation); + return typeChecker.getSymbolDisplayBuilder().buildDisplayForTypeParametersAndDelimiters(candidateSignature.typeParameters, writer, invocation); }); prefixDisplayParts.push.apply(prefixDisplayParts, typeParameterParts); prefixDisplayParts.push(ts.punctuationPart(16)); @@ -26648,7 +26688,7 @@ var ts; suffixDisplayParts.push(ts.punctuationPart(17)); } var returnTypeParts = ts.mapToDisplayParts(function (writer) { - return typeInfoResolver.getSymbolDisplayBuilder().buildReturnTypeDisplay(candidateSignature, writer, invocation); + return typeChecker.getSymbolDisplayBuilder().buildReturnTypeDisplay(candidateSignature, writer, invocation); }); suffixDisplayParts.push.apply(suffixDisplayParts, returnTypeParts); return { @@ -26676,7 +26716,7 @@ var ts; }; function createSignatureHelpParameterForParameter(parameter) { var displayParts = ts.mapToDisplayParts(function (writer) { - return typeInfoResolver.getSymbolDisplayBuilder().buildParameterDisplay(parameter, writer, invocation); + return typeChecker.getSymbolDisplayBuilder().buildParameterDisplay(parameter, writer, invocation); }); var isOptional = ts.hasQuestionToken(parameter.valueDeclaration); return { @@ -26688,7 +26728,7 @@ var ts; } function createSignatureHelpParameterForTypeParameter(typeParameter) { var displayParts = ts.mapToDisplayParts(function (writer) { - return typeInfoResolver.getSymbolDisplayBuilder().buildTypeParameterDisplay(typeParameter, writer, invocation); + return typeChecker.getSymbolDisplayBuilder().buildTypeParameterDisplay(typeParameter, writer, invocation); }); return { name: typeParameter.symbol.name, @@ -27074,9 +27114,9 @@ var ts; ts.isInsideTemplateLiteral = isInsideTemplateLiteral; function isAccessibilityModifier(kind) { switch (kind) { - case 109: - case 107: case 108: + case 106: + case 107: return true; } return false; @@ -27266,6 +27306,10 @@ var ts; }); } ts.signatureToDisplayParts = signatureToDisplayParts; + function isJavaScript(fileName) { + return ts.fileExtensionIs(fileName, ".js"); + } + ts.isJavaScript = isJavaScript; })(ts || (ts = {})); /// /// @@ -27694,7 +27738,7 @@ var ts; this.SpaceAfterSubtractWhenFollowedByPredecrement = new formatting.Rule(formatting.RuleDescriptor.create1(34, 39), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2)); this.NoSpaceBeforeComma = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 23), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); this.SpaceAfterCertainKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([98, 94, 88, 74, 90, 97]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); - this.SpaceAfterLetConstInVariableDeclaration = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([105, 70]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), 2)); + this.SpaceAfterLetConstInVariableDeclaration = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([104, 70]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), 2)); this.NoSpaceBeforeOpenParenInFuncCall = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 16), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsFunctionCallOrNewContext, Rules.IsPreviousTokenNotComma), 8)); this.SpaceAfterFunctionInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create3(83, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2)); this.NoSpaceBeforeOpenParenInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 16), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsFunctionDeclContext), 8)); @@ -27707,8 +27751,8 @@ var ts; this.SpaceAfterBinaryKeywordOperator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.BinaryKeywordOperators, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2)); this.NoSpaceAfterConstructor = new formatting.Rule(formatting.RuleDescriptor.create1(114, 16), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); this.NoSpaceAfterModuleImport = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([117, 118]), 16), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); - this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([69, 115, 77, 78, 79, 116, 103, 85, 104, 117, 107, 109, 120, 110]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); - this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([79, 103])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); + this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([69, 115, 77, 78, 79, 116, 102, 85, 103, 117, 106, 108, 120, 109]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); + this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([79, 102])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); this.SpaceAfterModuleName = new formatting.Rule(formatting.RuleDescriptor.create1(8, 14), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsModuleDeclContext), 2)); this.SpaceAfterArrow = new formatting.Rule(formatting.RuleDescriptor.create3(32, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); this.NoSpaceAfterEllipsis = new formatting.Rule(formatting.RuleDescriptor.create1(21, 65), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); @@ -27721,7 +27765,7 @@ var ts; this.NoSpaceBetweenEmptyInterfaceBraceBrackets = new formatting.Rule(formatting.RuleDescriptor.create1(14, 15), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsObjectTypeContext), 8)); this.SpaceBeforeAt = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 52), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); this.NoSpaceAfterAt = new formatting.Rule(formatting.RuleDescriptor.create3(52, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); - this.SpaceAfterDecorator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([65, 78, 73, 69, 110, 109, 107, 108, 116, 120, 18, 35])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsEndOfDecoratorContextOnSameLine), 2)); + this.SpaceAfterDecorator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([65, 78, 73, 69, 109, 108, 106, 107, 116, 120, 18, 35])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsEndOfDecoratorContextOnSameLine), 2)); this.HighPriorityCommonRules = [ this.IgnoreBeforeComment, this.IgnoreAfterLineComment, @@ -27795,9 +27839,9 @@ var ts; } Rules.prototype.getRuleName = function (rule) { var o = this; - for (var name_22 in o) { - if (o[name_22] === rule) { - return name_22; + for (var name_23 in o) { + if (o[name_23] === rule) { + return name_23; } } throw new Error("Unknown rule"); @@ -28609,7 +28653,7 @@ var ts; } switch (node.kind) { case 201: return 69; - case 202: return 104; + case 202: return 103; case 200: return 83; case 204: return 204; case 136: return 116; @@ -29928,26 +29972,62 @@ var ts; return this.namedDeclarations; }; SourceFileObject.prototype.computeNamedDeclarations = function () { - var namedDeclarations = []; + var result = {}; ts.forEachChild(this, visit); - return namedDeclarations; + return result; + function addDeclaration(declaration) { + var name = getDeclarationName(declaration); + if (name) { + var declarations = getDeclarations(name); + declarations.push(declaration); + } + } + function getDeclarations(name) { + return ts.getProperty(result, name) || (result[name] = []); + } + function getDeclarationName(declaration) { + if (declaration.name) { + var result_2 = getTextOfIdentifierOrLiteral(declaration.name); + if (result_2 !== undefined) { + return result_2; + } + if (declaration.name.kind === 127) { + var expr = declaration.name.expression; + if (expr.kind === 155) { + return expr.name.text; + } + return getTextOfIdentifierOrLiteral(expr); + } + } + return undefined; + } + function getTextOfIdentifierOrLiteral(node) { + if (node) { + if (node.kind === 65 || + node.kind === 8 || + node.kind === 7) { + return node.text; + } + } + return undefined; + } function visit(node) { switch (node.kind) { case 200: case 134: case 133: var functionDeclaration = node; - if (functionDeclaration.name && functionDeclaration.name.getFullWidth() > 0) { - var lastDeclaration = namedDeclarations.length > 0 ? - namedDeclarations[namedDeclarations.length - 1] : - undefined; - if (lastDeclaration && functionDeclaration.symbol === lastDeclaration.symbol) { + var declarationName = getDeclarationName(functionDeclaration); + if (declarationName) { + var declarations = getDeclarations(declarationName); + var lastDeclaration = ts.lastOrUndefined(declarations); + if (lastDeclaration && functionDeclaration.parent === lastDeclaration.parent && functionDeclaration.symbol === lastDeclaration.symbol) { if (functionDeclaration.body && !lastDeclaration.body) { - namedDeclarations[namedDeclarations.length - 1] = functionDeclaration; + declarations[declarations.length - 1] = functionDeclaration; } } else { - namedDeclarations.push(functionDeclaration); + declarations.push(functionDeclaration); } ts.forEachChild(node, visit); } @@ -29966,9 +30046,7 @@ var ts; case 136: case 137: case 145: - if (node.name) { - namedDeclarations.push(node); - } + addDeclaration(node); case 135: case 180: case 199: @@ -29995,7 +30073,7 @@ var ts; case 226: case 132: case 131: - namedDeclarations.push(node); + addDeclaration(node); break; case 215: if (node.exportClause) { @@ -30006,11 +30084,11 @@ var ts; var importClause = node.importClause; if (importClause) { if (importClause.name) { - namedDeclarations.push(importClause); + addDeclaration(importClause); } if (importClause.namedBindings) { if (importClause.namedBindings.kind === 211) { - namedDeclarations.push(importClause.namedBindings); + addDeclaration(importClause.namedBindings); } else { ts.forEach(importClause.namedBindings.elements, visit); @@ -30496,7 +30574,7 @@ var ts; } else if (token === 35) { token = scanner.scan(); - if (token === 102) { + if (token === 111) { token = scanner.scan(); if (token === 65) { token = scanner.scan(); @@ -30734,7 +30812,6 @@ var ts; var syntaxTreeCache = new SyntaxTreeCache(host); var ruleProvider; var program; - var typeInfoResolver; var useCaseSensitivefileNames = false; var cancellationToken = new CancellationTokenObject(host.getCancellationToken && host.getCancellationToken()); if (!ts.localizedDiagnosticMessages && host.getLocalizedDiagnosticMessages) { @@ -30792,7 +30869,7 @@ var ts; } } program = newProgram; - typeInfoResolver = program.getTypeChecker(); + program.getTypeChecker(); return; function getOrCreateSourceFile(fileName) { var hostFileInformation = hostCache.getOrCreateEntry(fileName); @@ -30832,9 +30909,6 @@ var ts; return program; } function cleanupSemanticCache() { - if (program) { - typeInfoResolver = program.getTypeChecker(); - } } function dispose() { if (program) { @@ -30847,13 +30921,10 @@ var ts; synchronizeHostData(); return program.getSyntacticDiagnostics(getValidSourceFile(fileName)); } - function isJavaScript(fileName) { - return ts.fileExtensionIs(fileName, ".js"); - } function getSemanticDiagnostics(fileName) { synchronizeHostData(); var targetSourceFile = getValidSourceFile(fileName); - if (isJavaScript(fileName)) { + if (ts.isJavaScript(fileName)) { return getJavaScriptSemanticDiagnostics(targetSourceFile); } var semanticDiagnostics = program.getSemanticDiagnostics(targetSourceFile); @@ -30887,7 +30958,7 @@ var ts; break; case 222: var heritageClause = node; - if (heritageClause.token === 103) { + if (heritageClause.token === 102) { diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.implements_clauses_can_only_be_used_in_a_ts_file)); return true; } @@ -30990,13 +31061,13 @@ var ts; for (var _i = 0; _i < modifiers.length; _i++) { var modifier = modifiers[_i]; switch (modifier.kind) { - case 109: - case 107: case 108: + case 106: + case 107: case 115: diagnostics.push(ts.createDiagnosticForNode(modifier, ts.Diagnostics._0_can_only_be_used_in_a_ts_file, ts.tokenToString(modifier.kind))); return true; - case 110: + case 109: case 78: case 70: case 73: @@ -31051,19 +31122,8 @@ var ts; } return ts.unescapeIdentifier(displayName); } - function createCompletionEntry(symbol, typeChecker, location) { - var displayName = getCompletionEntryDisplayNameForSymbol(symbol, program.getCompilerOptions().target, true); - if (!displayName) { - return undefined; - } - return { - name: displayName, - kind: getSymbolKind(symbol, typeChecker, location), - kindModifiers: getSymbolModifiers(symbol), - sortText: "0" - }; - } function getCompletionData(fileName, position) { + var typeChecker = program.getTypeChecker(); var syntacticStart = new Date().getTime(); var sourceFile = getValidSourceFile(fileName); var start = new Date().getTime(); @@ -31119,23 +31179,23 @@ var ts; isMemberCompletion = true; isNewIdentifierLocation = false; if (node.kind === 65 || node.kind === 126 || node.kind === 155) { - var symbol = typeInfoResolver.getSymbolAtLocation(node); + var symbol = typeChecker.getSymbolAtLocation(node); if (symbol && symbol.flags & 8388608) { - symbol = typeInfoResolver.getAliasedSymbol(symbol); + symbol = typeChecker.getAliasedSymbol(symbol); } if (symbol && symbol.flags & 1952) { - var exportedSymbols = typeInfoResolver.getExportsOfModule(symbol); + var exportedSymbols = typeChecker.getExportsOfModule(symbol); ts.forEach(exportedSymbols, function (symbol) { - if (typeInfoResolver.isValidPropertyAccess((node.parent), symbol.name)) { + if (typeChecker.isValidPropertyAccess((node.parent), symbol.name)) { symbols.push(symbol); } }); } } - var type = typeInfoResolver.getTypeAtLocation(node); + var type = typeChecker.getTypeAtLocation(node); if (type) { ts.forEach(type.getApparentProperties(), function (symbol) { - if (typeInfoResolver.isValidPropertyAccess((node.parent), symbol.name)) { + if (typeChecker.isValidPropertyAccess((node.parent), symbol.name)) { symbols.push(symbol); } }); @@ -31146,11 +31206,11 @@ var ts; if (containingObjectLiteral) { isMemberCompletion = true; isNewIdentifierLocation = true; - var contextualType = typeInfoResolver.getContextualType(containingObjectLiteral); + var contextualType = typeChecker.getContextualType(containingObjectLiteral); if (!contextualType) { return false; } - var contextualTypeMembers = typeInfoResolver.getPropertiesOfType(contextualType); + var contextualTypeMembers = typeChecker.getPropertiesOfType(contextualType); if (contextualTypeMembers && contextualTypeMembers.length > 0) { symbols = filterContextualMembersList(contextualTypeMembers, containingObjectLiteral.properties); } @@ -31163,9 +31223,9 @@ var ts; ts.Debug.assert(importDeclaration !== undefined); var exports_2; if (importDeclaration.moduleSpecifier) { - var moduleSpecifierSymbol = typeInfoResolver.getSymbolAtLocation(importDeclaration.moduleSpecifier); + var moduleSpecifierSymbol = typeChecker.getSymbolAtLocation(importDeclaration.moduleSpecifier); if (moduleSpecifierSymbol) { - exports_2 = typeInfoResolver.getExportsOfModule(moduleSpecifierSymbol); + exports_2 = typeChecker.getExportsOfModule(moduleSpecifierSymbol); } } symbols = exports_2 ? filterModuleExports(exports_2, importDeclaration) : emptyArray; @@ -31182,7 +31242,7 @@ var ts; position; var scopeNode = getScopeNode(contextToken, adjustedPosition, sourceFile) || sourceFile; var symbolMeanings = 793056 | 107455 | 1536 | 8388608; - symbols = typeInfoResolver.getSymbolsInScope(scopeNode, symbolMeanings); + symbols = typeChecker.getSymbolsInScope(scopeNode, symbolMeanings); } return true; } @@ -31239,9 +31299,9 @@ var ts; return containingNodeKind === 171; case 12: return containingNodeKind === 176; - case 109: - case 107: case 108: + case 106: + case 107: return containingNodeKind === 132; } switch (previousToken.getText()) { @@ -31328,6 +31388,7 @@ var ts; containingNodeKind === 150; case 22: return containingNodeKind === 131 && + previousToken.parent && previousToken.parent.parent && (previousToken.parent.parent.kind === 202 || previousToken.parent.parent.kind === 145); case 24: @@ -31335,27 +31396,28 @@ var ts; containingNodeKind === 200 || containingNodeKind === 202 || isFunction(containingNodeKind); - case 110: + case 109: return containingNodeKind === 132; case 21: return containingNodeKind === 129 || containingNodeKind === 135 || - (previousToken.parent.parent.kind === 151); - case 109: - case 107: + (previousToken.parent && previousToken.parent.parent && + previousToken.parent.parent.kind === 151); case 108: + case 106: + case 107: return containingNodeKind === 129; case 69: case 77: - case 104: + case 103: case 83: case 98: case 116: case 120: case 85: - case 105: + case 104: case 70: - case 111: + case 110: return true; } switch (previousToken.getText()) { @@ -31428,7 +31490,7 @@ var ts; } var symbols = completionData.symbols, isMemberCompletion = completionData.isMemberCompletion, isNewIdentifierLocation = completionData.isNewIdentifierLocation, location = completionData.location, isRightOfDot = completionData.isRightOfDot; var entries; - if (isRightOfDot && isJavaScript(fileName)) { + if (isRightOfDot && ts.isJavaScript(fileName)) { entries = getCompletionEntriesFromSymbols(symbols); ts.addRange(entries, getJavaScriptCompletionEntries()); } @@ -31449,10 +31511,10 @@ var ts; for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) { var sourceFile = _a[_i]; var nameTable = getNameTable(sourceFile); - for (var name_23 in nameTable) { - if (!allNames[name_23]) { - allNames[name_23] = name_23; - var displayName = getCompletionEntryDisplayName(name_23, target, true); + for (var name_24 in nameTable) { + if (!allNames[name_24]) { + allNames[name_24] = name_24; + var displayName = getCompletionEntryDisplayName(name_24, target, true); if (displayName) { var entry = { name: displayName, @@ -31467,6 +31529,18 @@ var ts; } return entries; } + function createCompletionEntry(symbol, location) { + var displayName = getCompletionEntryDisplayNameForSymbol(symbol, program.getCompilerOptions().target, true); + if (!displayName) { + return undefined; + } + return { + name: displayName, + kind: getSymbolKind(symbol, location), + kindModifiers: getSymbolModifiers(symbol), + sortText: "0" + }; + } function getCompletionEntriesFromSymbols(symbols) { var start = new Date().getTime(); var entries = []; @@ -31474,7 +31548,7 @@ var ts; var nameToSymbol = {}; for (var _i = 0; _i < symbols.length; _i++) { var symbol = symbols[_i]; - var entry = createCompletionEntry(symbol, typeInfoResolver, location); + var entry = createCompletionEntry(symbol, location); if (entry) { var id = ts.escapeIdentifier(entry.name); if (!ts.lookUp(nameToSymbol, id)) { @@ -31496,7 +31570,7 @@ var ts; var target = program.getCompilerOptions().target; var symbol = ts.forEach(symbols, function (s) { return getCompletionEntryDisplayNameForSymbol(s, target, false) === entryName ? s : undefined; }); if (symbol) { - var displayPartsDocumentationsAndSymbolKind = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, getValidSourceFile(fileName), location_2, typeInfoResolver, location_2, 7); + var displayPartsDocumentationsAndSymbolKind = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, getValidSourceFile(fileName), location_2, location_2, 7); return { name: entryName, kind: displayPartsDocumentationsAndSymbolKind.symbolKind, @@ -31518,7 +31592,7 @@ var ts; } return undefined; } - function getSymbolKind(symbol, typeResolver, location) { + function getSymbolKind(symbol, location) { var flags = symbol.getFlags(); if (flags & 32) return ScriptElementKind.classElement; @@ -31530,7 +31604,7 @@ var ts; return ScriptElementKind.interfaceElement; if (flags & 262144) return ScriptElementKind.typeParameterElement; - var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, flags, typeResolver, location); + var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, flags, location); if (result === ScriptElementKind.unknown) { if (flags & 262144) return ScriptElementKind.typeParameterElement; @@ -31543,11 +31617,12 @@ var ts; } return result; } - function getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, flags, typeResolver, location) { - if (typeResolver.isUndefinedSymbol(symbol)) { + function getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, flags, location) { + var typeChecker = program.getTypeChecker(); + if (typeChecker.isUndefinedSymbol(symbol)) { return ScriptElementKind.variableElement; } - if (typeResolver.isArgumentsSymbol(symbol)) { + if (typeChecker.isArgumentsSymbol(symbol)) { return ScriptElementKind.localVariableElement; } if (flags & 3) { @@ -31574,7 +31649,7 @@ var ts; return ScriptElementKind.constructorImplementationElement; if (flags & 4) { if (flags & 268435456) { - var unionPropertyKind = ts.forEach(typeInfoResolver.getRootSymbols(symbol), function (rootSymbol) { + var unionPropertyKind = ts.forEach(typeChecker.getRootSymbols(symbol), function (rootSymbol) { var rootSymbolFlags = rootSymbol.getFlags(); if (rootSymbolFlags & (98308 | 3)) { return ScriptElementKind.memberVariableElement; @@ -31582,7 +31657,7 @@ var ts; ts.Debug.assert(!!(rootSymbolFlags & 8192)); }); if (!unionPropertyKind) { - var typeOfUnionProperty = typeInfoResolver.getTypeOfSymbolAtLocation(symbol, location); + var typeOfUnionProperty = typeChecker.getTypeOfSymbolAtLocation(symbol, location); if (typeOfUnionProperty.getCallSignatures().length) { return ScriptElementKind.memberFunctionElement; } @@ -31615,12 +31690,13 @@ var ts; ? ts.getNodeModifiers(symbol.declarations[0]) : ScriptElementKindModifier.none; } - function getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, sourceFile, enclosingDeclaration, typeResolver, location, semanticMeaning) { + function getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, sourceFile, enclosingDeclaration, location, semanticMeaning) { if (semanticMeaning === void 0) { semanticMeaning = getMeaningFromLocation(location); } + var typeChecker = program.getTypeChecker(); var displayParts = []; var documentation; var symbolFlags = symbol.flags; - var symbolKind = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, symbolFlags, typeResolver, location); + var symbolKind = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, symbolFlags, location); var hasAddedSymbolInfo; var type; if (symbolKind !== ScriptElementKind.unknown || symbolFlags & 32 || symbolFlags & 8388608) { @@ -31628,7 +31704,7 @@ var ts; symbolKind = ScriptElementKind.memberVariableElement; } var signature; - type = typeResolver.getTypeOfSymbolAtLocation(symbol, location); + type = typeChecker.getTypeOfSymbolAtLocation(symbol, location); if (type) { if (location.parent && location.parent.kind === 155) { var right = location.parent.name; @@ -31645,7 +31721,7 @@ var ts; } if (callExpression) { var candidateSignatures = []; - signature = typeResolver.getResolvedSignature(callExpression, candidateSignatures); + signature = typeChecker.getResolvedSignature(callExpression, candidateSignatures); if (!signature && candidateSignatures.length) { signature = candidateSignatures[0]; } @@ -31686,7 +31762,7 @@ var ts; displayParts.push(ts.spacePart()); } if (!(type.flags & 32768)) { - displayParts.push.apply(displayParts, ts.symbolToDisplayParts(typeResolver, type.symbol, enclosingDeclaration, undefined, 1)); + displayParts.push.apply(displayParts, ts.symbolToDisplayParts(typeChecker, type.symbol, enclosingDeclaration, undefined, 1)); } addSignatureDisplayParts(signature, allSignatures, 8); break; @@ -31700,8 +31776,8 @@ var ts; (location.kind === 114 && location.parent.kind === 135)) { var functionDeclaration = location.parent; var allSignatures = functionDeclaration.kind === 135 ? type.getConstructSignatures() : type.getCallSignatures(); - if (!typeResolver.isImplementationOfOverload(functionDeclaration)) { - signature = typeResolver.getSignatureFromDeclaration(functionDeclaration); + if (!typeChecker.isImplementationOfOverload(functionDeclaration)) { + signature = typeChecker.getSignatureFromDeclaration(functionDeclaration); } else { signature = allSignatures[0]; @@ -31727,7 +31803,7 @@ var ts; } if ((symbolFlags & 64) && (semanticMeaning & 2)) { addNewLineIfDisplayPartsExist(); - displayParts.push(ts.keywordPart(104)); + displayParts.push(ts.keywordPart(103)); displayParts.push(ts.spacePart()); addFullSymbolName(symbol); writeTypeParametersOfSymbol(symbol, sourceFile); @@ -31740,7 +31816,7 @@ var ts; displayParts.push(ts.spacePart()); displayParts.push(ts.operatorPart(53)); displayParts.push(ts.spacePart()); - displayParts.push.apply(displayParts, ts.typeToDisplayParts(typeResolver, typeResolver.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration)); + displayParts.push.apply(displayParts, ts.typeToDisplayParts(typeChecker, typeChecker.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration)); } if (symbolFlags & 384) { addNewLineIfDisplayPartsExist(); @@ -31774,7 +31850,7 @@ var ts; } else { var signatureDeclaration = ts.getDeclarationOfKind(symbol, 128).parent; - var signature = typeResolver.getSignatureFromDeclaration(signatureDeclaration); + var signature = typeChecker.getSignatureFromDeclaration(signatureDeclaration); if (signatureDeclaration.kind === 139) { displayParts.push(ts.keywordPart(88)); displayParts.push(ts.spacePart()); @@ -31782,14 +31858,14 @@ var ts; else if (signatureDeclaration.kind !== 138 && signatureDeclaration.name) { addFullSymbolName(signatureDeclaration.symbol); } - displayParts.push.apply(displayParts, ts.signatureToDisplayParts(typeResolver, signature, sourceFile, 32)); + displayParts.push.apply(displayParts, ts.signatureToDisplayParts(typeChecker, signature, sourceFile, 32)); } } if (symbolFlags & 8) { addPrefixForAnyFunctionOrVar(symbol, "enum member"); var declaration = symbol.declarations[0]; if (declaration.kind === 226) { - var constantValue = typeResolver.getConstantValue(declaration); + var constantValue = typeChecker.getConstantValue(declaration); if (constantValue !== undefined) { displayParts.push(ts.spacePart()); displayParts.push(ts.operatorPart(53)); @@ -31816,7 +31892,7 @@ var ts; displayParts.push(ts.punctuationPart(17)); } else { - var internalAliasSymbol = typeResolver.getSymbolAtLocation(importEqualsDeclaration.moduleReference); + var internalAliasSymbol = typeChecker.getSymbolAtLocation(importEqualsDeclaration.moduleReference); if (internalAliasSymbol) { displayParts.push(ts.spacePart()); displayParts.push(ts.operatorPart(53)); @@ -31839,12 +31915,12 @@ var ts; displayParts.push(ts.spacePart()); if (type.symbol && type.symbol.flags & 262144) { var typeParameterParts = ts.mapToDisplayParts(function (writer) { - typeResolver.getSymbolDisplayBuilder().buildTypeParameterDisplay(type, writer, enclosingDeclaration); + typeChecker.getSymbolDisplayBuilder().buildTypeParameterDisplay(type, writer, enclosingDeclaration); }); displayParts.push.apply(displayParts, typeParameterParts); } else { - displayParts.push.apply(displayParts, ts.typeToDisplayParts(typeResolver, type, enclosingDeclaration)); + displayParts.push.apply(displayParts, ts.typeToDisplayParts(typeChecker, type, enclosingDeclaration)); } } else if (symbolFlags & 16 || @@ -31859,7 +31935,7 @@ var ts; } } else { - symbolKind = getSymbolKind(symbol, typeResolver, location); + symbolKind = getSymbolKind(symbol, location); } } if (!documentation) { @@ -31872,7 +31948,7 @@ var ts; } } function addFullSymbolName(symbol, enclosingDeclaration) { - var fullSymbolDisplayParts = ts.symbolToDisplayParts(typeResolver, symbol, enclosingDeclaration || sourceFile, undefined, 1 | 2); + var fullSymbolDisplayParts = ts.symbolToDisplayParts(typeChecker, symbol, enclosingDeclaration || sourceFile, undefined, 1 | 2); displayParts.push.apply(displayParts, fullSymbolDisplayParts); } function addPrefixForAnyFunctionOrVar(symbol, symbolKind) { @@ -31900,7 +31976,7 @@ var ts; } } function addSignatureDisplayParts(signature, allSignatures, flags) { - displayParts.push.apply(displayParts, ts.signatureToDisplayParts(typeResolver, signature, enclosingDeclaration, flags | 32)); + displayParts.push.apply(displayParts, ts.signatureToDisplayParts(typeChecker, signature, enclosingDeclaration, flags | 32)); if (allSignatures.length > 1) { displayParts.push(ts.spacePart()); displayParts.push(ts.punctuationPart(16)); @@ -31914,7 +31990,7 @@ var ts; } function writeTypeParametersOfSymbol(symbol, enclosingDeclaration) { var typeParameterParts = ts.mapToDisplayParts(function (writer) { - typeResolver.getSymbolDisplayBuilder().buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaration); + typeChecker.getSymbolDisplayBuilder().buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaration); }); displayParts.push.apply(displayParts, typeParameterParts); } @@ -31926,7 +32002,11 @@ var ts; if (!node) { return undefined; } - var symbol = typeInfoResolver.getSymbolAtLocation(node); + if (isLabelName(node)) { + return undefined; + } + var typeChecker = program.getTypeChecker(); + var symbol = typeChecker.getSymbolAtLocation(node); if (!symbol) { switch (node.kind) { case 65: @@ -31934,20 +32014,20 @@ var ts; case 126: case 93: case 91: - var type = typeInfoResolver.getTypeAtLocation(node); + var type = typeChecker.getTypeAtLocation(node); if (type) { return { kind: ScriptElementKind.unknown, kindModifiers: ScriptElementKindModifier.none, textSpan: ts.createTextSpan(node.getStart(), node.getWidth()), - displayParts: ts.typeToDisplayParts(typeInfoResolver, type, getContainerNode(node)), + displayParts: ts.typeToDisplayParts(typeChecker, type, getContainerNode(node)), documentation: type.symbol ? type.symbol.getDocumentationComment() : undefined }; } } return undefined; } - var displayPartsDocumentationsAndKind = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, sourceFile, getContainerNode(node), typeInfoResolver, node); + var displayPartsDocumentationsAndKind = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, sourceFile, getContainerNode(node), node); return { kind: displayPartsDocumentationsAndKind.symbolKind, kindModifiers: getSymbolModifiers(symbol), @@ -31993,33 +32073,34 @@ var ts; } return undefined; } - var symbol = typeInfoResolver.getSymbolAtLocation(node); + var typeChecker = program.getTypeChecker(); + var symbol = typeChecker.getSymbolAtLocation(node); if (!symbol) { return undefined; } if (symbol.flags & 8388608) { var declaration = symbol.declarations[0]; if (node.kind === 65 && node.parent === declaration) { - symbol = typeInfoResolver.getAliasedSymbol(symbol); + symbol = typeChecker.getAliasedSymbol(symbol); } } if (node.parent.kind === 225) { - var shorthandSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(symbol.valueDeclaration); + var shorthandSymbol = typeChecker.getShorthandAssignmentValueSymbol(symbol.valueDeclaration); if (!shorthandSymbol) { return []; } var shorthandDeclarations = shorthandSymbol.getDeclarations(); - var shorthandSymbolKind = getSymbolKind(shorthandSymbol, typeInfoResolver, node); - var shorthandSymbolName = typeInfoResolver.symbolToString(shorthandSymbol); - var shorthandContainerName = typeInfoResolver.symbolToString(symbol.parent, node); + var shorthandSymbolKind = getSymbolKind(shorthandSymbol, node); + var shorthandSymbolName = typeChecker.symbolToString(shorthandSymbol); + var shorthandContainerName = typeChecker.symbolToString(symbol.parent, node); return ts.map(shorthandDeclarations, function (declaration) { return createDefinitionInfo(declaration, shorthandSymbolKind, shorthandSymbolName, shorthandContainerName); }); } var result = []; var declarations = symbol.getDeclarations(); - var symbolName = typeInfoResolver.symbolToString(symbol); - var symbolKind = getSymbolKind(symbol, typeInfoResolver, node); + var symbolName = typeChecker.symbolToString(symbol); + var symbolKind = getSymbolKind(symbol, node); var containerSymbol = symbol.parent; - var containerName = containerSymbol ? typeInfoResolver.symbolToString(containerSymbol, node) : ""; + var containerName = containerSymbol ? typeChecker.symbolToString(containerSymbol, node) : ""; if (!tryAddConstructSignature(symbol, node, symbolKind, symbolName, containerName, result) && !tryAddCallSignature(symbol, node, symbolKind, symbolName, containerName, result)) { ts.forEach(declarations, function (declaration) { @@ -32069,7 +32150,7 @@ var ts; var results = getOccurrencesAtPositionCore(fileName, position); if (results) { var sourceFile = getCanonicalFileName(ts.normalizeSlashes(fileName)); - results = ts.filter(results, function (r) { return r.fileName === fileName; }); + results = ts.filter(results, function (r) { return getCanonicalFileName(ts.normalizeSlashes(r.fileName)) === sourceFile; }); } return results; } @@ -32314,7 +32395,7 @@ var ts; return undefined; } } - else if (modifier === 110) { + else if (modifier === 109) { if (container.kind !== 201) { return undefined; } @@ -32360,13 +32441,13 @@ var ts; return ts.map(keywords, getHighlightSpanForNode); function getFlagFromModifier(modifier) { switch (modifier) { - case 109: + case 108: return 16; - case 107: + case 106: return 32; - case 108: + case 107: return 64; - case 110: + case 109: return 128; case 78: return 1; @@ -32609,6 +32690,7 @@ var ts; return getReferencedSymbolsForNodes(node, program.getSourceFiles(), findInStrings, findInComments); } function getReferencedSymbolsForNodes(node, sourceFiles, findInStrings, findInComments) { + var typeChecker = program.getTypeChecker(); if (isLabelName(node)) { if (isJumpStatementTarget(node)) { var labelDefinition = getTargetLabel(node.parent, node.text); @@ -32624,7 +32706,7 @@ var ts; if (node.kind === 91) { return getReferencesForSuperKeyword(node); } - var symbol = typeInfoResolver.getSymbolAtLocation(node); + var symbol = typeChecker.getSymbolAtLocation(node); if (!symbol) { return undefined; } @@ -32655,7 +32737,7 @@ var ts; } return result; function getDefinition(symbol) { - var info = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, node.getSourceFile(), getContainerNode(node), typeInfoResolver, node); + var info = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, node.getSourceFile(), getContainerNode(node), node); var name = ts.map(info.displayParts, function (p) { return p.text; }).join(""); var declarations = symbol.declarations; if (!declarations || declarations.length === 0) { @@ -32689,7 +32771,7 @@ var ts; if (isImportOrExportSpecifierName(location)) { return location.getText(); } - name = typeInfoResolver.symbolToString(symbol); + name = typeChecker.symbolToString(symbol); return stripQuotes(name); } function getInternedName(symbol, location, declarations) { @@ -32837,10 +32919,10 @@ var ts; if (!(getMeaningFromLocation(referenceLocation) & searchMeaning)) { return; } - var referenceSymbol = typeInfoResolver.getSymbolAtLocation(referenceLocation); + var referenceSymbol = typeChecker.getSymbolAtLocation(referenceLocation); if (referenceSymbol) { var referenceSymbolDeclaration = referenceSymbol.valueDeclaration; - var shorthandValueSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(referenceSymbolDeclaration); + var shorthandValueSymbol = typeChecker.getShorthandAssignmentValueSymbol(referenceSymbolDeclaration); var relatedSymbol = getRelatedSymbol(searchSymbols, referenceSymbol, referenceLocation); if (relatedSymbol) { var referencedSymbol = getReferencedSymbol(relatedSymbol); @@ -33013,18 +33095,18 @@ var ts; function populateSearchSymbolSet(symbol, location) { var result = [symbol]; if (isImportOrExportSpecifierImportSymbol(symbol)) { - result.push(typeInfoResolver.getAliasedSymbol(symbol)); + result.push(typeChecker.getAliasedSymbol(symbol)); } if (isNameOfPropertyAssignment(location)) { ts.forEach(getPropertySymbolsFromContextualType(location), function (contextualSymbol) { - result.push.apply(result, typeInfoResolver.getRootSymbols(contextualSymbol)); + result.push.apply(result, typeChecker.getRootSymbols(contextualSymbol)); }); - var shorthandValueSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(location.parent); + var shorthandValueSymbol = typeChecker.getShorthandAssignmentValueSymbol(location.parent); if (shorthandValueSymbol) { result.push(shorthandValueSymbol); } } - ts.forEach(typeInfoResolver.getRootSymbols(symbol), function (rootSymbol) { + ts.forEach(typeChecker.getRootSymbols(symbol), function (rootSymbol) { if (rootSymbol !== symbol) { result.push(rootSymbol); } @@ -33049,9 +33131,9 @@ var ts; return; function getPropertySymbolFromTypeReference(typeReference) { if (typeReference) { - var type = typeInfoResolver.getTypeAtLocation(typeReference); + var type = typeChecker.getTypeAtLocation(typeReference); if (type) { - var propertySymbol = typeInfoResolver.getPropertyOfType(type, propertyName); + var propertySymbol = typeChecker.getPropertyOfType(type, propertyName); if (propertySymbol) { result.push(propertySymbol); } @@ -33065,24 +33147,24 @@ var ts; return referenceSymbol; } if (isImportOrExportSpecifierImportSymbol(referenceSymbol)) { - var aliasedSymbol = typeInfoResolver.getAliasedSymbol(referenceSymbol); + var aliasedSymbol = typeChecker.getAliasedSymbol(referenceSymbol); if (searchSymbols.indexOf(aliasedSymbol) >= 0) { return aliasedSymbol; } } if (isNameOfPropertyAssignment(referenceLocation)) { return ts.forEach(getPropertySymbolsFromContextualType(referenceLocation), function (contextualSymbol) { - return ts.forEach(typeInfoResolver.getRootSymbols(contextualSymbol), function (s) { return searchSymbols.indexOf(s) >= 0 ? s : undefined; }); + return ts.forEach(typeChecker.getRootSymbols(contextualSymbol), function (s) { return searchSymbols.indexOf(s) >= 0 ? s : undefined; }); }); } - return ts.forEach(typeInfoResolver.getRootSymbols(referenceSymbol), function (rootSymbol) { + return ts.forEach(typeChecker.getRootSymbols(referenceSymbol), function (rootSymbol) { if (searchSymbols.indexOf(rootSymbol) >= 0) { return rootSymbol; } if (rootSymbol.parent && rootSymbol.parent.flags & (32 | 64)) { - var result_2 = []; - getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getName(), result_2); - return ts.forEach(result_2, function (s) { return searchSymbols.indexOf(s) >= 0 ? s : undefined; }); + var result_3 = []; + getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getName(), result_3); + return ts.forEach(result_3, function (s) { return searchSymbols.indexOf(s) >= 0 ? s : undefined; }); } return undefined; }); @@ -33090,27 +33172,27 @@ var ts; function getPropertySymbolsFromContextualType(node) { if (isNameOfPropertyAssignment(node)) { var objectLiteral = node.parent.parent; - var contextualType = typeInfoResolver.getContextualType(objectLiteral); - var name_24 = node.text; + var contextualType = typeChecker.getContextualType(objectLiteral); + var name_25 = node.text; if (contextualType) { if (contextualType.flags & 16384) { - var unionProperty = contextualType.getProperty(name_24); + var unionProperty = contextualType.getProperty(name_25); if (unionProperty) { return [unionProperty]; } else { - var result_3 = []; + var result_4 = []; ts.forEach(contextualType.types, function (t) { - var symbol = t.getProperty(name_24); + var symbol = t.getProperty(name_25); if (symbol) { - result_3.push(symbol); + result_4.push(symbol); } }); - return result_3; + return result_4; } } else { - var symbol_1 = contextualType.getProperty(name_24); + var symbol_1 = contextualType.getProperty(name_25); if (symbol_1) { return [symbol_1]; } @@ -33260,7 +33342,7 @@ var ts; } if (!isLastClause && root.parent.kind === 177 && root.parent.parent.kind === 222) { var decl = root.parent.parent.parent; - return (decl.kind === 201 && root.parent.parent.token === 103) || + return (decl.kind === 201 && root.parent.parent.token === 102) || (decl.kind === 202 && root.parent.parent.token === 79); } return false; @@ -33314,7 +33396,7 @@ var ts; function getSignatureHelpItems(fileName, position) { synchronizeHostData(); var sourceFile = getValidSourceFile(fileName); - return ts.SignatureHelp.getSignatureHelpItems(sourceFile, position, typeInfoResolver, cancellationToken); + return ts.SignatureHelp.getSignatureHelpItems(program, sourceFile, position, cancellationToken); } function getSourceFile(fileName) { return syntaxTreeCache.getCurrentSourceFile(fileName); @@ -33370,6 +33452,7 @@ var ts; function getSemanticClassifications(fileName, span) { synchronizeHostData(); var sourceFile = getValidSourceFile(fileName); + var typeChecker = program.getTypeChecker(); var result = []; processNode(sourceFile); return result; @@ -33408,7 +33491,7 @@ var ts; function processNode(node) { if (node && ts.textSpanIntersectsWith(span, node.getStart(), node.getWidth())) { if (node.kind === 65 && node.getWidth() > 0) { - var symbol = typeInfoResolver.getSymbolAtLocation(node); + var symbol = typeChecker.getSymbolAtLocation(node); if (symbol) { var type = classifySymbol(symbol, getMeaningFromLocation(node)); if (type) { @@ -33732,9 +33815,10 @@ var ts; function getRenameInfo(fileName, position) { synchronizeHostData(); var sourceFile = getValidSourceFile(fileName); + var typeChecker = program.getTypeChecker(); var node = ts.getTouchingWord(sourceFile, position); if (node && node.kind === 65) { - var symbol = typeInfoResolver.getSymbolAtLocation(node); + var symbol = typeChecker.getSymbolAtLocation(node); if (symbol) { var declarations = symbol.getDeclarations(); if (declarations && declarations.length > 0) { @@ -33742,19 +33826,19 @@ var ts; if (defaultLibFileName) { for (var _i = 0; _i < declarations.length; _i++) { var current = declarations[_i]; - var sourceFile_1 = current.getSourceFile(); - if (sourceFile_1 && getCanonicalFileName(ts.normalizePath(sourceFile_1.fileName)) === getCanonicalFileName(ts.normalizePath(defaultLibFileName))) { + var sourceFile_2 = current.getSourceFile(); + if (sourceFile_2 && getCanonicalFileName(ts.normalizePath(sourceFile_2.fileName)) === getCanonicalFileName(ts.normalizePath(defaultLibFileName))) { return getRenameInfoError(ts.getLocaleSpecificMessage(ts.Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library.key)); } } } - var kind = getSymbolKind(symbol, typeInfoResolver, node); + var kind = getSymbolKind(symbol, node); if (kind) { return { canRename: true, localizedErrorMessage: undefined, displayName: symbol.name, - fullDisplayName: typeInfoResolver.getFullyQualifiedName(symbol), + fullDisplayName: typeChecker.getFullyQualifiedName(symbol), kind: kind, kindModifiers: getSymbolModifiers(symbol), triggerSpan: ts.createTextSpan(node.getStart(), node.getWidth()) @@ -33868,7 +33952,7 @@ var ts; if (keyword2 === 116 || keyword2 === 120 || keyword2 === 114 || - keyword2 === 110) { + keyword2 === 109) { return true; } return false; @@ -34386,8 +34470,7 @@ var ts; this.errorTimer = setTimeout(checkOne, ms); } }; - Session.prototype.getDefinition = function (_a) { - var line = _a.line, offset = _a.offset, fileName = _a.file; + Session.prototype.getDefinition = function (line, offset, fileName) { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -34405,8 +34488,7 @@ var ts; end: compilerService.host.positionToLineOffset(def.fileName, ts.textSpanEnd(def.textSpan)) }); }); }; - Session.prototype.getOccurrences = function (_a) { - var line = _a.line, offset = _a.offset, fileName = _a.file; + Session.prototype.getOccurrences = function (line, offset, fileName) { fileName = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(fileName); if (!project) { @@ -34430,8 +34512,7 @@ var ts; }; }); }; - Session.prototype.getRenameLocations = function (_a) { - var line = _a.line, offset = _a.offset, fileName = _a.file, findInComments = _a.findInComments, findInStrings = _a.findInStrings; + Session.prototype.getRenameLocations = function (line, offset, fileName, findInComments, findInStrings) { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -34492,8 +34573,7 @@ var ts; }, []); return { info: renameInfo, locs: bakedRenameLocs }; }; - Session.prototype.getReferences = function (_a) { - var line = _a.line, offset = _a.offset, fileName = _a.file; + Session.prototype.getReferences = function (line, offset, fileName) { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -34533,13 +34613,11 @@ var ts; symbolDisplayString: displayString }; }; - Session.prototype.openClientFile = function (_a) { - var fileName = _a.file; + Session.prototype.openClientFile = function (fileName) { var file = ts.normalizePath(fileName); this.projectService.openClientFile(file); }; - Session.prototype.getQuickInfo = function (_a) { - var line = _a.line, offset = _a.offset, fileName = _a.file; + Session.prototype.getQuickInfo = function (line, offset, fileName) { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -34562,8 +34640,7 @@ var ts; documentation: docString }; }; - Session.prototype.getFormattingEditsForRange = function (_a) { - var line = _a.line, offset = _a.offset, endLine = _a.endLine, endOffset = _a.endOffset, fileName = _a.file; + Session.prototype.getFormattingEditsForRange = function (line, offset, endLine, endOffset, fileName) { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -34584,8 +34661,7 @@ var ts; }; }); }; - Session.prototype.getFormattingEditsAfterKeystroke = function (_a) { - var line = _a.line, offset = _a.offset, key = _a.key, fileName = _a.file; + Session.prototype.getFormattingEditsAfterKeystroke = function (line, offset, key, fileName) { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -34642,8 +34718,7 @@ var ts; }; }); }; - Session.prototype.getCompletions = function (_a) { - var line = _a.line, offset = _a.offset, prefix = _a.prefix, fileName = _a.file; + Session.prototype.getCompletions = function (line, offset, prefix, fileName) { if (!prefix) { prefix = ""; } @@ -34665,8 +34740,7 @@ var ts; return result; }, []).sort(function (a, b) { return a.name.localeCompare(b.name); }); }; - Session.prototype.getCompletionEntryDetails = function (_a) { - var line = _a.line, offset = _a.offset, entryNames = _a.entryNames, fileName = _a.file; + Session.prototype.getCompletionEntryDetails = function (line, offset, entryNames, fileName) { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -34682,8 +34756,7 @@ var ts; return accum; }, []); }; - Session.prototype.getSignatureHelpItems = function (_a) { - var line = _a.line, offset = _a.offset, fileName = _a.file; + Session.prototype.getSignatureHelpItems = function (line, offset, fileName) { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -34708,9 +34781,8 @@ var ts; }; return result; }; - Session.prototype.getDiagnostics = function (_a) { + Session.prototype.getDiagnostics = function (delay, fileNames) { var _this = this; - var delay = _a.delay, fileNames = _a.files; var checkList = fileNames.reduce(function (accum, fileName) { fileName = ts.normalizePath(fileName); var project = _this.projectService.getProjectForFile(fileName); @@ -34723,9 +34795,8 @@ var ts; this.updateErrorCheck(checkList, this.changeSeq, function (n) { return n == _this.changeSeq; }, delay); } }; - Session.prototype.change = function (_a) { + Session.prototype.change = function (line, offset, endLine, endOffset, insertString, fileName) { var _this = this; - var line = _a.line, offset = _a.offset, endLine = _a.endLine, endOffset = _a.endOffset, insertString = _a.insertString, fileName = _a.file; var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (project) { @@ -34739,9 +34810,8 @@ var ts; this.updateProjectStructure(this.changeSeq, function (n) { return n == _this.changeSeq; }); } }; - Session.prototype.reload = function (_a, reqSeq) { + Session.prototype.reload = function (fileName, tempFileName, reqSeq) { var _this = this; - var fileName = _a.file, tempFileName = _a.tmpfile; if (reqSeq === void 0) { reqSeq = 0; } var file = ts.normalizePath(fileName); var tmpfile = ts.normalizePath(tempFileName); @@ -34753,8 +34823,7 @@ var ts; }); } }; - Session.prototype.saveToTmp = function (_a) { - var fileName = _a.file, tempFileName = _a.tmpfile; + Session.prototype.saveToTmp = function (fileName, tempFileName) { var file = ts.normalizePath(fileName); var tmpfile = ts.normalizePath(tempFileName); var project = this.projectService.getProjectForFile(file); @@ -34762,8 +34831,7 @@ var ts; project.compilerService.host.saveTo(file, tmpfile); } }; - Session.prototype.closeClientFile = function (_a) { - var fileName = _a.file; + Session.prototype.closeClientFile = function (fileName) { var file = ts.normalizePath(fileName); this.projectService.closeClientFile(file); }; @@ -34784,8 +34852,7 @@ var ts; childItems: _this.decorateNavigationBarItem(project, fileName, item.childItems) }); }); }; - Session.prototype.getNavigationBarItems = function (_a) { - var fileName = _a.file; + Session.prototype.getNavigationBarItems = function (fileName) { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -34798,8 +34865,7 @@ var ts; } return this.decorateNavigationBarItem(project, fileName, items); }; - Session.prototype.getNavigateToItems = function (_a) { - var searchValue = _a.searchValue, fileName = _a.file, maxResultCount = _a.maxResultCount; + Session.prototype.getNavigateToItems = function (searchValue, fileName, maxResultCount) { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -34835,8 +34901,7 @@ var ts; return bakedItem; }); }; - Session.prototype.getBraceMatching = function (_a) { - var line = _a.line, offset = _a.offset, fileName = _a.file; + Session.prototype.getBraceMatching = function (line, offset, fileName) { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -34872,91 +34937,112 @@ var ts; break; } case CommandNames.Definition: { - response = this.getDefinition(request.arguments); + var defArgs = request.arguments; + response = this.getDefinition(defArgs.line, defArgs.offset, defArgs.file); break; } case CommandNames.References: { - response = this.getReferences(request.arguments); + var refArgs = request.arguments; + response = this.getReferences(refArgs.line, refArgs.offset, refArgs.file); break; } case CommandNames.Rename: { - response = this.getRenameLocations(request.arguments); + var renameArgs = request.arguments; + response = this.getRenameLocations(renameArgs.line, renameArgs.offset, renameArgs.file, renameArgs.findInComments, renameArgs.findInStrings); break; } case CommandNames.Open: { - this.openClientFile(request.arguments); + var openArgs = request.arguments; + this.openClientFile(openArgs.file); responseRequired = false; break; } case CommandNames.Quickinfo: { - response = this.getQuickInfo(request.arguments); + var quickinfoArgs = request.arguments; + response = this.getQuickInfo(quickinfoArgs.line, quickinfoArgs.offset, quickinfoArgs.file); break; } case CommandNames.Format: { - response = this.getFormattingEditsForRange(request.arguments); + var formatArgs = request.arguments; + response = this.getFormattingEditsForRange(formatArgs.line, formatArgs.offset, formatArgs.endLine, formatArgs.endOffset, formatArgs.file); break; } case CommandNames.Formatonkey: { - response = this.getFormattingEditsAfterKeystroke(request.arguments); + var formatOnKeyArgs = request.arguments; + response = this.getFormattingEditsAfterKeystroke(formatOnKeyArgs.line, formatOnKeyArgs.offset, formatOnKeyArgs.key, formatOnKeyArgs.file); break; } case CommandNames.Completions: { - response = this.getCompletions(request.arguments); + var completionsArgs = request.arguments; + response = this.getCompletions(completionsArgs.line, completionsArgs.offset, completionsArgs.prefix, completionsArgs.file); break; } case CommandNames.CompletionDetails: { - response = this.getCompletionEntryDetails(request.arguments); + var completionDetailsArgs = request.arguments; + response = + this.getCompletionEntryDetails(completionDetailsArgs.line, completionDetailsArgs.offset, completionDetailsArgs.entryNames, completionDetailsArgs.file); break; } case CommandNames.SignatureHelp: { - response = this.getSignatureHelpItems(request.arguments); + var signatureHelpArgs = request.arguments; + response = this.getSignatureHelpItems(signatureHelpArgs.line, signatureHelpArgs.offset, signatureHelpArgs.file); break; } case CommandNames.Geterr: { - this.getDiagnostics(request.arguments); + var geterrArgs = request.arguments; + response = this.getDiagnostics(geterrArgs.delay, geterrArgs.files); responseRequired = false; break; } case CommandNames.Change: { - this.change(request.arguments); + var changeArgs = request.arguments; + this.change(changeArgs.line, changeArgs.offset, changeArgs.endLine, changeArgs.endOffset, changeArgs.insertString, changeArgs.file); responseRequired = false; break; } case CommandNames.Configure: { - this.projectService.setHostConfiguration(request.arguments); + var configureArgs = request.arguments; + this.projectService.setHostConfiguration(configureArgs); this.output(undefined, CommandNames.Configure, request.seq); responseRequired = false; break; } case CommandNames.Reload: { - this.reload(request.arguments); + var reloadArgs = request.arguments; + this.reload(reloadArgs.file, reloadArgs.tmpfile, request.seq); responseRequired = false; break; } case CommandNames.Saveto: { - this.saveToTmp(request.arguments); + var savetoArgs = request.arguments; + this.saveToTmp(savetoArgs.file, savetoArgs.tmpfile); responseRequired = false; break; } case CommandNames.Close: { - this.closeClientFile(request.arguments); + var closeArgs = request.arguments; + this.closeClientFile(closeArgs.file); responseRequired = false; break; } case CommandNames.Navto: { - response = this.getNavigateToItems(request.arguments); + var navtoArgs = request.arguments; + response = this.getNavigateToItems(navtoArgs.searchValue, navtoArgs.file, navtoArgs.maxResultCount); break; } case CommandNames.Brace: { - response = this.getBraceMatching(request.arguments); + var braceArguments = request.arguments; + response = this.getBraceMatching(braceArguments.line, braceArguments.offset, braceArguments.file); break; } case CommandNames.NavBar: { - response = this.getNavigationBarItems(request.arguments); + var navBarArgs = request.arguments; + response = this.getNavigationBarItems(navBarArgs.file); break; } case CommandNames.Occurrences: { - response = this.getOccurrences(request.arguments); + var _a = request.arguments, line = _a.line, offset = _a.offset, fileName = _a.file; + response = this.getOccurrences(line, offset, fileName); break; } default: { diff --git a/bin/typescript.d.ts b/bin/typescript.d.ts index 1439f0de59773..19f7ff11b4f77 100644 --- a/bin/typescript.d.ts +++ b/bin/typescript.d.ts @@ -124,16 +124,16 @@ declare module "typescript" { VoidKeyword = 99, WhileKeyword = 100, WithKeyword = 101, - AsKeyword = 102, - ImplementsKeyword = 103, - InterfaceKeyword = 104, - LetKeyword = 105, - PackageKeyword = 106, - PrivateKeyword = 107, - ProtectedKeyword = 108, - PublicKeyword = 109, - StaticKeyword = 110, - YieldKeyword = 111, + ImplementsKeyword = 102, + InterfaceKeyword = 103, + LetKeyword = 104, + PackageKeyword = 105, + PrivateKeyword = 106, + ProtectedKeyword = 107, + PublicKeyword = 108, + StaticKeyword = 109, + YieldKeyword = 110, + AsKeyword = 111, AnyKeyword = 112, BooleanKeyword = 113, ConstructorKeyword = 114, @@ -258,8 +258,8 @@ declare module "typescript" { LastReservedWord = 101, FirstKeyword = 66, LastKeyword = 125, - FirstFutureReservedWord = 103, - LastFutureReservedWord = 111, + FirstFutureReservedWord = 102, + LastFutureReservedWord = 110, FirstTypeNode = 141, LastTypeNode = 149, FirstPunctuation = 14, @@ -1183,6 +1183,7 @@ declare module "typescript" { function isIdentifierPart(ch: number, languageVersion: ScriptTarget): boolean; } declare module "typescript" { + function getDefaultLibFileName(options: CompilerOptions): string; function textSpanEnd(span: TextSpan): number; function textSpanIsEmpty(span: TextSpan): boolean; function textSpanContainsPosition(span: TextSpan, position: number): boolean; @@ -1227,7 +1228,6 @@ declare module "typescript" { function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; function getPreEmitDiagnostics(program: Program): Diagnostic[]; function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; - function getDefaultLibFileName(options: CompilerOptions): string; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; } declare module "typescript" { @@ -1289,7 +1289,6 @@ declare module "typescript" { getDocumentationComment(): SymbolDisplayPart[]; } interface SourceFile { - getNamedDeclarations(): Declaration[]; getLineAndCharacterOfPosition(pos: number): LineAndCharacter; getLineStarts(): number[]; getPositionOfLineAndCharacter(line: number, character: number): number; diff --git a/bin/typescript.js b/bin/typescript.js index 4544cc24ec174..57271ad41ac68 100644 --- a/bin/typescript.js +++ b/bin/typescript.js @@ -128,17 +128,17 @@ var ts; SyntaxKind[SyntaxKind["WhileKeyword"] = 100] = "WhileKeyword"; SyntaxKind[SyntaxKind["WithKeyword"] = 101] = "WithKeyword"; // Strict mode reserved words - SyntaxKind[SyntaxKind["AsKeyword"] = 102] = "AsKeyword"; - SyntaxKind[SyntaxKind["ImplementsKeyword"] = 103] = "ImplementsKeyword"; - SyntaxKind[SyntaxKind["InterfaceKeyword"] = 104] = "InterfaceKeyword"; - SyntaxKind[SyntaxKind["LetKeyword"] = 105] = "LetKeyword"; - SyntaxKind[SyntaxKind["PackageKeyword"] = 106] = "PackageKeyword"; - SyntaxKind[SyntaxKind["PrivateKeyword"] = 107] = "PrivateKeyword"; - SyntaxKind[SyntaxKind["ProtectedKeyword"] = 108] = "ProtectedKeyword"; - SyntaxKind[SyntaxKind["PublicKeyword"] = 109] = "PublicKeyword"; - SyntaxKind[SyntaxKind["StaticKeyword"] = 110] = "StaticKeyword"; - SyntaxKind[SyntaxKind["YieldKeyword"] = 111] = "YieldKeyword"; + SyntaxKind[SyntaxKind["ImplementsKeyword"] = 102] = "ImplementsKeyword"; + SyntaxKind[SyntaxKind["InterfaceKeyword"] = 103] = "InterfaceKeyword"; + SyntaxKind[SyntaxKind["LetKeyword"] = 104] = "LetKeyword"; + SyntaxKind[SyntaxKind["PackageKeyword"] = 105] = "PackageKeyword"; + SyntaxKind[SyntaxKind["PrivateKeyword"] = 106] = "PrivateKeyword"; + SyntaxKind[SyntaxKind["ProtectedKeyword"] = 107] = "ProtectedKeyword"; + SyntaxKind[SyntaxKind["PublicKeyword"] = 108] = "PublicKeyword"; + SyntaxKind[SyntaxKind["StaticKeyword"] = 109] = "StaticKeyword"; + SyntaxKind[SyntaxKind["YieldKeyword"] = 110] = "YieldKeyword"; // Contextual keywords + SyntaxKind[SyntaxKind["AsKeyword"] = 111] = "AsKeyword"; SyntaxKind[SyntaxKind["AnyKeyword"] = 112] = "AnyKeyword"; SyntaxKind[SyntaxKind["BooleanKeyword"] = 113] = "BooleanKeyword"; SyntaxKind[SyntaxKind["ConstructorKeyword"] = 114] = "ConstructorKeyword"; @@ -280,8 +280,8 @@ var ts; SyntaxKind[SyntaxKind["LastReservedWord"] = 101] = "LastReservedWord"; SyntaxKind[SyntaxKind["FirstKeyword"] = 66] = "FirstKeyword"; SyntaxKind[SyntaxKind["LastKeyword"] = 125] = "LastKeyword"; - SyntaxKind[SyntaxKind["FirstFutureReservedWord"] = 103] = "FirstFutureReservedWord"; - SyntaxKind[SyntaxKind["LastFutureReservedWord"] = 111] = "LastFutureReservedWord"; + SyntaxKind[SyntaxKind["FirstFutureReservedWord"] = 102] = "FirstFutureReservedWord"; + SyntaxKind[SyntaxKind["LastFutureReservedWord"] = 110] = "LastFutureReservedWord"; SyntaxKind[SyntaxKind["FirstTypeNode"] = 141] = "FirstTypeNode"; SyntaxKind[SyntaxKind["LastTypeNode"] = 149] = "LastTypeNode"; SyntaxKind[SyntaxKind["FirstPunctuation"] = 14] = "FirstPunctuation"; @@ -2178,7 +2178,7 @@ var ts; (function (ts) { var textToToken = { "any": 112 /* AnyKeyword */, - "as": 102 /* AsKeyword */, + "as": 111 /* AsKeyword */, "boolean": 113 /* BooleanKeyword */, "break": 66 /* BreakKeyword */, "case": 67 /* CaseKeyword */, @@ -2203,24 +2203,24 @@ var ts; "function": 83 /* FunctionKeyword */, "get": 116 /* GetKeyword */, "if": 84 /* IfKeyword */, - "implements": 103 /* ImplementsKeyword */, + "implements": 102 /* ImplementsKeyword */, "import": 85 /* ImportKeyword */, "in": 86 /* InKeyword */, "instanceof": 87 /* InstanceOfKeyword */, - "interface": 104 /* InterfaceKeyword */, - "let": 105 /* LetKeyword */, + "interface": 103 /* InterfaceKeyword */, + "let": 104 /* LetKeyword */, "module": 117 /* ModuleKeyword */, "new": 88 /* NewKeyword */, "null": 89 /* NullKeyword */, "number": 119 /* NumberKeyword */, - "package": 106 /* PackageKeyword */, - "private": 107 /* PrivateKeyword */, - "protected": 108 /* ProtectedKeyword */, - "public": 109 /* PublicKeyword */, + "package": 105 /* PackageKeyword */, + "private": 106 /* PrivateKeyword */, + "protected": 107 /* ProtectedKeyword */, + "public": 108 /* PublicKeyword */, "require": 118 /* RequireKeyword */, "return": 90 /* ReturnKeyword */, "set": 120 /* SetKeyword */, - "static": 110 /* StaticKeyword */, + "static": 109 /* StaticKeyword */, "string": 121 /* StringKeyword */, "super": 91 /* SuperKeyword */, "switch": 92 /* SwitchKeyword */, @@ -2235,7 +2235,7 @@ var ts; "void": 99 /* VoidKeyword */, "while": 100 /* WhileKeyword */, "with": 101 /* WithKeyword */, - "yield": 111 /* YieldKeyword */, + "yield": 110 /* YieldKeyword */, "of": 125 /* OfKeyword */, "{": 14 /* OpenBraceToken */, "}": 15 /* CloseBraceToken */, @@ -5027,7 +5027,7 @@ var ts; } ts.getClassExtendsHeritageClauseElement = getClassExtendsHeritageClauseElement; function getClassImplementsHeritageClauseElements(node) { - var heritageClause = getHeritageClause(node.heritageClauses, 103 /* ImplementsKeyword */); + var heritageClause = getHeritageClause(node.heritageClauses, 102 /* ImplementsKeyword */); return heritageClause ? heritageClause.types : undefined; } ts.getClassImplementsHeritageClauseElements = getClassImplementsHeritageClauseElements; @@ -5157,10 +5157,10 @@ var ts; ts.isESSymbolIdentifier = isESSymbolIdentifier; function isModifier(token) { switch (token) { - case 109 /* PublicKeyword */: - case 107 /* PrivateKeyword */: - case 108 /* ProtectedKeyword */: - case 110 /* StaticKeyword */: + case 108 /* PublicKeyword */: + case 106 /* PrivateKeyword */: + case 107 /* ProtectedKeyword */: + case 109 /* StaticKeyword */: case 78 /* ExportKeyword */: case 115 /* DeclareKeyword */: case 70 /* ConstKeyword */: @@ -5609,6 +5609,10 @@ var ts; })(ts || (ts = {})); var ts; (function (ts) { + function getDefaultLibFileName(options) { + return options.target === 2 /* ES6 */ ? "lib.es6.d.ts" : "lib.d.ts"; + } + ts.getDefaultLibFileName = getDefaultLibFileName; function textSpanEnd(span) { return span.start + span.length; } @@ -6185,10 +6189,10 @@ var ts; ; function modifierToFlag(token) { switch (token) { - case 110 /* StaticKeyword */: return 128 /* Static */; - case 109 /* PublicKeyword */: return 16 /* Public */; - case 108 /* ProtectedKeyword */: return 64 /* Protected */; - case 107 /* PrivateKeyword */: return 32 /* Private */; + case 109 /* StaticKeyword */: return 128 /* Static */; + case 108 /* PublicKeyword */: return 16 /* Public */; + case 107 /* ProtectedKeyword */: return 64 /* Protected */; + case 106 /* PrivateKeyword */: return 32 /* Private */; case 78 /* ExportKeyword */: return 1 /* Export */; case 115 /* DeclareKeyword */: return 2 /* Ambient */; case 70 /* ConstKeyword */: return 8192 /* Const */; @@ -7004,7 +7008,7 @@ var ts; } // If we have a 'yield' keyword, and we're in the [yield] context, then 'yield' is // considered a keyword and is not an identifier. - if (token === 111 /* YieldKeyword */ && inYieldContext()) { + if (token === 110 /* YieldKeyword */ && inYieldContext()) { return false; } return token > 101 /* LastReservedWord */; @@ -7282,7 +7286,7 @@ var ts; // extends {} extends // extends {} implements var next = nextToken(); - return next === 23 /* CommaToken */ || next === 14 /* OpenBraceToken */ || next === 79 /* ExtendsKeyword */ || next === 103 /* ImplementsKeyword */; + return next === 23 /* CommaToken */ || next === 14 /* OpenBraceToken */ || next === 79 /* ExtendsKeyword */ || next === 102 /* ImplementsKeyword */; } return true; } @@ -7291,7 +7295,7 @@ var ts; return isIdentifier(); } function isHeritageClauseExtendsOrImplementsKeyword() { - if (token === 103 /* ImplementsKeyword */ || + if (token === 102 /* ImplementsKeyword */ || token === 79 /* ExtendsKeyword */) { return lookAhead(nextTokenIsStartOfExpression); } @@ -7321,12 +7325,12 @@ var ts; case 4 /* SwitchClauseStatements */: return token === 15 /* CloseBraceToken */ || token === 67 /* CaseKeyword */ || token === 73 /* DefaultKeyword */; case 8 /* HeritageClauseElement */: - return token === 14 /* OpenBraceToken */ || token === 79 /* ExtendsKeyword */ || token === 103 /* ImplementsKeyword */; + return token === 14 /* OpenBraceToken */ || token === 79 /* ExtendsKeyword */ || token === 102 /* ImplementsKeyword */; case 9 /* VariableDeclarations */: return isVariableDeclaratorListTerminator(); case 16 /* TypeParameters */: // Tokens other than '>' are here for better error recovery - return token === 25 /* GreaterThanToken */ || token === 16 /* OpenParenToken */ || token === 14 /* OpenBraceToken */ || token === 79 /* ExtendsKeyword */ || token === 103 /* ImplementsKeyword */; + return token === 25 /* GreaterThanToken */ || token === 16 /* OpenParenToken */ || token === 14 /* OpenBraceToken */ || token === 79 /* ExtendsKeyword */ || token === 102 /* ImplementsKeyword */; case 12 /* ArgumentExpressions */: // Tokens other than ')' are here for better error recovery return token === 17 /* CloseParenToken */ || token === 22 /* SemicolonToken */; @@ -8363,7 +8367,7 @@ var ts; case 38 /* PlusPlusToken */: case 39 /* MinusMinusToken */: case 24 /* LessThanToken */: - case 111 /* YieldKeyword */: + case 110 /* YieldKeyword */: // Yield always starts an expression. Either it is an identifier (in which case // it is definitely an expression). Or it's a keyword (either because we're in // a generator, or in strict mode (or both)) and it started a yield expression. @@ -8478,7 +8482,7 @@ var ts; return parseConditionalExpressionRest(expr); } function isYieldExpression() { - if (token === 111 /* YieldKeyword */) { + if (token === 110 /* YieldKeyword */) { // If we have a 'yield' keyword, and htis is a context where yield expressions are // allowed, then definitely parse out a yield expression. if (inYieldContext()) { @@ -9319,7 +9323,7 @@ var ts; parseExpected(16 /* OpenParenToken */); var initializer = undefined; if (token !== 22 /* SemicolonToken */) { - if (token === 98 /* VarKeyword */ || token === 105 /* LetKeyword */ || token === 70 /* ConstKeyword */) { + if (token === 98 /* VarKeyword */ || token === 104 /* LetKeyword */ || token === 70 /* ConstKeyword */) { initializer = parseVariableDeclarationList(true); } else { @@ -9503,7 +9507,7 @@ var ts; return !inErrorRecovery; case 14 /* OpenBraceToken */: case 98 /* VarKeyword */: - case 105 /* LetKeyword */: + case 104 /* LetKeyword */: case 83 /* FunctionKeyword */: case 69 /* ClassKeyword */: case 84 /* IfKeyword */: @@ -9529,7 +9533,7 @@ var ts; // In ES 6 'enum' is a future reserved keyword, so it should not be used as identifier var isConstEnum = lookAhead(nextTokenIsEnumKeyword); return !isConstEnum; - case 104 /* InterfaceKeyword */: + case 103 /* InterfaceKeyword */: case 117 /* ModuleKeyword */: case 77 /* EnumKeyword */: case 123 /* TypeKeyword */: @@ -9538,10 +9542,10 @@ var ts; if (isDeclarationStart()) { return false; } - case 109 /* PublicKeyword */: - case 107 /* PrivateKeyword */: - case 108 /* ProtectedKeyword */: - case 110 /* StaticKeyword */: + case 108 /* PublicKeyword */: + case 106 /* PrivateKeyword */: + case 107 /* ProtectedKeyword */: + case 109 /* StaticKeyword */: // When followed by an identifier or keyword, these do not start a statement but // might instead be following type members if (lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine)) { @@ -9600,7 +9604,7 @@ var ts; return parseTryStatement(); case 72 /* DebuggerKeyword */: return parseDebuggerStatement(); - case 105 /* LetKeyword */: + case 104 /* LetKeyword */: // If let follows identifier on the same line, it is declaration parse it as variable statement if (isLetDeclaration()) { return parseVariableStatement(scanner.getStartPos(), undefined, undefined); @@ -9635,7 +9639,7 @@ var ts; return undefined; } return parseVariableStatement(start, decorators, modifiers); - case 105 /* LetKeyword */: + case 104 /* LetKeyword */: if (!isLetDeclaration()) { return undefined; } @@ -9722,7 +9726,7 @@ var ts; switch (token) { case 98 /* VarKeyword */: break; - case 105 /* LetKeyword */: + case 104 /* LetKeyword */: node.flags |= 4096 /* Let */; break; case 70 /* ConstKeyword */: @@ -9832,10 +9836,10 @@ var ts; } function isClassMemberModifier(idToken) { switch (idToken) { - case 109 /* PublicKeyword */: - case 107 /* PrivateKeyword */: - case 108 /* ProtectedKeyword */: - case 110 /* StaticKeyword */: + case 108 /* PublicKeyword */: + case 106 /* PrivateKeyword */: + case 107 /* ProtectedKeyword */: + case 109 /* StaticKeyword */: return true; default: return false; @@ -10028,7 +10032,7 @@ var ts; return parseList(19 /* HeritageClauses */, false, parseHeritageClause); } function parseHeritageClause() { - if (token === 79 /* ExtendsKeyword */ || token === 103 /* ImplementsKeyword */) { + if (token === 79 /* ExtendsKeyword */ || token === 102 /* ImplementsKeyword */) { var node = createNode(222 /* HeritageClause */); node.token = token; nextToken(); @@ -10046,7 +10050,7 @@ var ts; return finishNode(node); } function isHeritageClause() { - return token === 79 /* ExtendsKeyword */ || token === 103 /* ImplementsKeyword */; + return token === 79 /* ExtendsKeyword */ || token === 102 /* ImplementsKeyword */; } function parseClassMembers() { return parseList(6 /* ClassMembers */, false, parseClassElement); @@ -10055,7 +10059,7 @@ var ts; var node = createNode(202 /* InterfaceDeclaration */, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(104 /* InterfaceKeyword */); + parseExpected(103 /* InterfaceKeyword */); node.name = parseIdentifier(); node.typeParameters = parseTypeParameters(); node.heritageClauses = parseHeritageClauses(false); @@ -10234,7 +10238,7 @@ var ts; // * as ImportedBinding var namespaceImport = createNode(211 /* NamespaceImport */); parseExpected(35 /* AsteriskToken */); - parseExpected(102 /* AsKeyword */); + parseExpected(111 /* AsKeyword */); namespaceImport.name = parseIdentifier(); return finishNode(namespaceImport); } @@ -10268,9 +10272,9 @@ var ts; var checkIdentifierStart = scanner.getTokenPos(); var checkIdentifierEnd = scanner.getTextPos(); var identifierName = parseIdentifierName(); - if (token === 102 /* AsKeyword */) { + if (token === 111 /* AsKeyword */) { node.propertyName = identifierName; - parseExpected(102 /* AsKeyword */); + parseExpected(111 /* AsKeyword */); checkIdentifierIsKeyword = ts.isKeyword(token) && !isIdentifier(); checkIdentifierStart = scanner.getTokenPos(); checkIdentifierEnd = scanner.getTextPos(); @@ -10327,10 +10331,10 @@ var ts; case 70 /* ConstKeyword */: case 83 /* FunctionKeyword */: return true; - case 105 /* LetKeyword */: + case 104 /* LetKeyword */: return isLetDeclaration(); case 69 /* ClassKeyword */: - case 104 /* InterfaceKeyword */: + case 103 /* InterfaceKeyword */: case 77 /* EnumKeyword */: case 123 /* TypeKeyword */: // Not true keywords so ensure an identifier follows @@ -10345,10 +10349,10 @@ var ts; // Check for export assignment or modifier on source element return lookAhead(nextTokenCanFollowExportKeyword); case 115 /* DeclareKeyword */: - case 109 /* PublicKeyword */: - case 107 /* PrivateKeyword */: - case 108 /* ProtectedKeyword */: - case 110 /* StaticKeyword */: + case 108 /* PublicKeyword */: + case 106 /* PrivateKeyword */: + case 107 /* ProtectedKeyword */: + case 109 /* StaticKeyword */: // Check for modifier on source element return lookAhead(nextTokenIsDeclarationStart); case 52 /* AtToken */: @@ -10383,7 +10387,7 @@ var ts; return isDeclarationStart(true); } function nextTokenIsAsKeyword() { - return nextToken() === 102 /* AsKeyword */; + return nextToken() === 111 /* AsKeyword */; } function parseDeclaration() { var fullStart = getNodePos(); @@ -10400,14 +10404,14 @@ var ts; } switch (token) { case 98 /* VarKeyword */: - case 105 /* LetKeyword */: + case 104 /* LetKeyword */: case 70 /* ConstKeyword */: return parseVariableStatement(fullStart, decorators, modifiers); case 83 /* FunctionKeyword */: return parseFunctionDeclaration(fullStart, decorators, modifiers); case 69 /* ClassKeyword */: return parseClassDeclaration(fullStart, decorators, modifiers); - case 104 /* InterfaceKeyword */: + case 103 /* InterfaceKeyword */: return parseInterfaceDeclaration(fullStart, decorators, modifiers); case 123 /* TypeKeyword */: return parseTypeAliasDeclaration(fullStart, decorators, modifiers); @@ -13228,15 +13232,16 @@ var ts; return result; } function getPropertiesOfType(type) { - if (type.flags & 16384 /* Union */) { - return getPropertiesOfUnionType(type); - } - return getPropertiesOfObjectType(getApparentType(type)); + type = getApparentType(type); + return type.flags & 16384 /* Union */ ? getPropertiesOfUnionType(type) : getPropertiesOfObjectType(type); } // For a type parameter, return the base constraint of the type parameter. For the string, number, // boolean, and symbol primitive types, return the corresponding object types. Otherwise return the // type itself. Note that the apparent type of a union type is the union type itself. function getApparentType(type) { + if (type.flags & 16384 /* Union */) { + type = getReducedTypeOfUnionType(type); + } if (type.flags & 512 /* TypeParameter */) { do { type = getConstraintOfTypeParameter(type); @@ -13308,28 +13313,27 @@ var ts; // necessary, maps primitive types and type parameters are to their apparent types, and augments with properties from // Object and Function as appropriate. function getPropertyOfType(type, name) { - if (type.flags & 16384 /* Union */) { - return getPropertyOfUnionType(type, name); - } - if (!(type.flags & 48128 /* ObjectType */)) { - type = getApparentType(type); - if (!(type.flags & 48128 /* ObjectType */)) { - return undefined; + type = getApparentType(type); + if (type.flags & 48128 /* ObjectType */) { + var resolved = resolveObjectOrUnionTypeMembers(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 = getPropertyOfObjectType(globalFunctionType, name); + if (symbol) { + return symbol; + } } + return getPropertyOfObjectType(globalObjectType, name); } - if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { - var symbol = getPropertyOfObjectType(globalFunctionType, name); - if (symbol) - return symbol; + if (type.flags & 16384 /* Union */) { + return getPropertyOfUnionType(type, name); } - return getPropertyOfObjectType(globalObjectType, name); + return undefined; } function getSignaturesOfObjectOrUnionType(type, kind) { if (type.flags & (48128 /* ObjectType */ | 16384 /* Union */)) { @@ -13852,6 +13856,10 @@ var ts; } } } + // The noSubtypeReduction flag is there because it isn't possible to always do subtype reduction. The flag + // is true when creating a union type from a type node and when instantiating a union type. In both of those + // cases subtype reduction has to be deferred to properly support recursive union types. For example, a + // type alias of the form "type Item = string | (() => Item)" cannot be reduced during its declaration. function getUnionType(types, noSubtypeReduction) { if (types.length === 0) { return emptyObjectType; @@ -13876,9 +13884,17 @@ var ts; if (!type) { type = unionTypes[id] = createObjectType(16384 /* Union */ | getWideningFlagsOfTypes(sortedTypes)); type.types = sortedTypes; + type.reducedType = noSubtypeReduction ? undefined : type; } return type; } + function getReducedTypeOfUnionType(type) { + // If union type was created without subtype reduction, perform the deferred reduction now + if (!type.reducedType) { + type.reducedType = getUnionType(type.types, false); + } + return type.reducedType; + } function getTypeFromUnionTypeNode(node) { var links = getNodeLinks(node); if (!links.resolvedType) { @@ -19153,7 +19169,10 @@ var ts; return checkElementTypeOfArrayOrString(inputType, errorNode); } if (isArrayLikeType(inputType)) { - return getIndexTypeOfType(inputType, 1 /* Number */); + var indexType = getIndexTypeOfType(inputType, 1 /* Number */); + if (indexType) { + return indexType; + } } error(errorNode, ts.Diagnostics.Type_0_is_not_an_array_type, typeToString(inputType)); return unknownType; @@ -21385,7 +21404,7 @@ var ts; function isReservedwordInStrictMode(node) { // Check that originalKeywordKind is less than LastFurtureReservedWord to see if an Identifier is a strict-mode reserved word return (node.parserContextFlags & 1 /* StrictMode */) && - (node.originalKeywordKind >= 103 /* FirstFutureReservedWord */ && node.originalKeywordKind <= 111 /* LastFutureReservedWord */); + (node.originalKeywordKind >= 102 /* FirstFutureReservedWord */ && node.originalKeywordKind <= 110 /* LastFutureReservedWord */); } function reportStrictModeGrammarErrorInClassDeclaration(identifier, message, arg0, arg1, arg2) { // We are checking if this name is inside class declaration or class expression (which are under class definitions inside ES6 spec.) @@ -21565,14 +21584,14 @@ var ts; for (var _i = 0, _a = node.modifiers; _i < _a.length; _i++) { var modifier = _a[_i]; switch (modifier.kind) { - case 109 /* PublicKeyword */: - case 108 /* ProtectedKeyword */: - case 107 /* PrivateKeyword */: + case 108 /* PublicKeyword */: + case 107 /* ProtectedKeyword */: + case 106 /* PrivateKeyword */: var text = void 0; - if (modifier.kind === 109 /* PublicKeyword */) { + if (modifier.kind === 108 /* PublicKeyword */) { text = "public"; } - else if (modifier.kind === 108 /* ProtectedKeyword */) { + else if (modifier.kind === 107 /* ProtectedKeyword */) { text = "protected"; lastProtected = modifier; } @@ -21591,7 +21610,7 @@ var ts; } flags |= ts.modifierToFlag(modifier.kind); break; - case 110 /* StaticKeyword */: + case 109 /* StaticKeyword */: if (flags & 128 /* Static */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "static"); } @@ -21823,7 +21842,7 @@ var ts; seenExtendsClause = true; } else { - ts.Debug.assert(heritageClause.token === 103 /* ImplementsKeyword */); + ts.Debug.assert(heritageClause.token === 102 /* ImplementsKeyword */); if (seenImplementsClause) { return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.implements_clause_already_seen); } @@ -21846,7 +21865,7 @@ var ts; seenExtendsClause = true; } else { - ts.Debug.assert(heritageClause.token === 103 /* ImplementsKeyword */); + ts.Debug.assert(heritageClause.token === 102 /* ImplementsKeyword */); return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.Interface_declaration_cannot_have_implements_clause); } // Grammar checking heritageClause inside class declaration @@ -24947,7 +24966,7 @@ var ts; emit(node.expression); } function emitYieldExpression(node) { - write(ts.tokenToString(111 /* YieldKeyword */)); + write(ts.tokenToString(110 /* YieldKeyword */)); if (node.asteriskToken) { write("*"); } @@ -25638,7 +25657,7 @@ var ts; var tokenKind = 98 /* VarKeyword */; if (decl && languageVersion >= 2 /* ES6 */) { if (ts.isLet(decl)) { - tokenKind = 105 /* LetKeyword */; + tokenKind = 104 /* LetKeyword */; } else if (ts.isConst(decl)) { tokenKind = 70 /* ConstKeyword */; @@ -25651,7 +25670,7 @@ var ts; switch (tokenKind) { case 98 /* VarKeyword */: return write("var "); - case 105 /* LetKeyword */: + case 104 /* LetKeyword */: return write("let "); case 70 /* ConstKeyword */: return write("const "); @@ -28582,7 +28601,7 @@ var ts; } return { getSourceFile: getSourceFile, - getDefaultLibFileName: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), getDefaultLibFileName(options)); }, + getDefaultLibFileName: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), ts.getDefaultLibFileName(options)); }, writeFile: writeFile, getCurrentDirectory: function () { return currentDirectory || (currentDirectory = ts.sys.getCurrentDirectory()); }, useCaseSensitiveFileNames: function () { return ts.sys.useCaseSensitiveFileNames; }, @@ -28622,10 +28641,6 @@ var ts; } } ts.flattenDiagnosticMessageText = flattenDiagnosticMessageText; - function getDefaultLibFileName(options) { - return options.target === 2 /* ES6 */ ? "lib.es6.d.ts" : "lib.d.ts"; - } - ts.getDefaultLibFileName = getDefaultLibFileName; function createProgram(rootNames, options, host) { var program; var files = []; @@ -29527,32 +29542,34 @@ var ts; // Search the declarations in all files and output matched NavigateToItem into array of NavigateToItem[] ts.forEach(program.getSourceFiles(), function (sourceFile) { cancellationToken.throwIfCancellationRequested(); - var declarations = sourceFile.getNamedDeclarations(); - for (var _i = 0; _i < declarations.length; _i++) { - var declaration = declarations[_i]; - var name = getDeclarationName(declaration); - if (name !== undefined) { + var nameToDeclarations = sourceFile.getNamedDeclarations(); + for (var name_21 in nameToDeclarations) { + var declarations = ts.getProperty(nameToDeclarations, name_21); + if (declarations) { // First do a quick check to see if the name of the declaration matches the // last portion of the (possibly) dotted name they're searching for. - var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name); + var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_21); if (!matches) { continue; } - // It was a match! If the pattern has dots in it, then also see if the - // declaration container matches as well. - if (patternMatcher.patternContainsDots) { - var containers = getContainers(declaration); - if (!containers) { - return undefined; - } - matches = patternMatcher.getMatches(containers, name); - if (!matches) { - continue; + for (var _i = 0; _i < declarations.length; _i++) { + var declaration = declarations[_i]; + // It was a match! If the pattern has dots in it, then also see if the + // declaration container matches as well. + if (patternMatcher.patternContainsDots) { + var containers = getContainers(declaration); + if (!containers) { + return undefined; + } + matches = patternMatcher.getMatches(containers, name_21); + if (!matches) { + continue; + } } + var fileName = sourceFile.fileName; + var matchKind = bestMatchKind(matches); + rawItems.push({ name: name_21, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); } - var fileName = sourceFile.fileName; - var matchKind = bestMatchKind(matches); - rawItems.push({ name: name, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); } } }); @@ -29573,25 +29590,13 @@ var ts; } return true; } - function getDeclarationName(declaration) { - var result = getTextOfIdentifierOrLiteral(declaration.name); - if (result !== undefined) { - return result; - } - if (declaration.name.kind === 127 /* ComputedPropertyName */) { - var expr = declaration.name.expression; - if (expr.kind === 155 /* PropertyAccessExpression */) { - return expr.name.text; - } - return getTextOfIdentifierOrLiteral(expr); - } - return undefined; - } function getTextOfIdentifierOrLiteral(node) { - if (node.kind === 65 /* Identifier */ || - node.kind === 8 /* StringLiteral */ || - node.kind === 7 /* NumericLiteral */) { - return node.text; + if (node) { + if (node.kind === 65 /* Identifier */ || + node.kind === 8 /* StringLiteral */ || + node.kind === 7 /* NumericLiteral */) { + return node.text; + } } return undefined; } @@ -29946,9 +29951,9 @@ var ts; case 198 /* VariableDeclaration */: case 152 /* BindingElement */: var variableDeclarationNode; - var name_21; + var name_22; if (node.kind === 152 /* BindingElement */) { - name_21 = node.name; + name_22 = node.name; variableDeclarationNode = node; // binding elements are added only for variable declarations // bubble up to the containing variable declaration @@ -29960,16 +29965,16 @@ var ts; else { ts.Debug.assert(!ts.isBindingPattern(node.name)); variableDeclarationNode = node; - name_21 = node.name; + name_22 = node.name; } if (ts.isConst(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_21), ts.ScriptElementKind.constElement); + return createItem(node, getTextOfNode(name_22), ts.ScriptElementKind.constElement); } else if (ts.isLet(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_21), ts.ScriptElementKind.letElement); + return createItem(node, getTextOfNode(name_22), ts.ScriptElementKind.letElement); } else { - return createItem(node, getTextOfNode(name_21), ts.ScriptElementKind.variableElement); + return createItem(node, getTextOfNode(name_22), ts.ScriptElementKind.variableElement); } case 135 /* Constructor */: return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); @@ -30868,7 +30873,8 @@ var ts; ArgumentListKind[ArgumentListKind["CallArguments"] = 1] = "CallArguments"; ArgumentListKind[ArgumentListKind["TaggedTemplateArguments"] = 2] = "TaggedTemplateArguments"; })(ArgumentListKind || (ArgumentListKind = {})); - function getSignatureHelpItems(sourceFile, position, typeInfoResolver, cancellationToken) { + function getSignatureHelpItems(program, sourceFile, position, cancellationToken) { + var typeChecker = program.getTypeChecker(); // Decide whether to show signature help var startingToken = ts.findTokenOnLeftOfPosition(sourceFile, position); if (!startingToken) { @@ -30883,12 +30889,54 @@ var ts; } var call = argumentInfo.invocation; var candidates = []; - var resolvedSignature = typeInfoResolver.getResolvedSignature(call, candidates); + var resolvedSignature = typeChecker.getResolvedSignature(call, candidates); cancellationToken.throwIfCancellationRequested(); if (!candidates.length) { + // We didn't have any sig help items produced by the TS compiler. If this is a JS + // file, then see if we can figure out anything better. + if (ts.isJavaScript(sourceFile.fileName)) { + return createJavaScriptSignatureHelpItems(argumentInfo); + } return undefined; } return createSignatureHelpItems(candidates, resolvedSignature, argumentInfo); + function createJavaScriptSignatureHelpItems(argumentInfo) { + if (argumentInfo.invocation.kind !== 157 /* CallExpression */) { + return undefined; + } + // See if we can find some symbol with the call expression name that has call signatures. + var callExpression = argumentInfo.invocation; + var expression = callExpression.expression; + var name = expression.kind === 65 /* Identifier */ + ? expression + : expression.kind === 155 /* PropertyAccessExpression */ + ? expression.name + : undefined; + if (!name || !name.text) { + return undefined; + } + var typeChecker = program.getTypeChecker(); + for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) { + var sourceFile_1 = _a[_i]; + var nameToDeclarations = sourceFile_1.getNamedDeclarations(); + var declarations = ts.getProperty(nameToDeclarations, name.text); + if (declarations) { + for (var _b = 0; _b < declarations.length; _b++) { + var declaration = declarations[_b]; + var symbol = declaration.symbol; + if (symbol) { + var type = typeChecker.getTypeOfSymbolAtLocation(symbol, declaration); + if (type) { + var callSignatures = type.getCallSignatures(); + if (callSignatures && callSignatures.length) { + return createSignatureHelpItems(callSignatures, callSignatures[0], argumentInfo); + } + } + } + } + } + } + } /** * Returns relevant information for the argument list and the current argument if we are * in the argument of an invocation; returns undefined otherwise. @@ -31142,8 +31190,8 @@ var ts; var isTypeParameterList = argumentListInfo.kind === 0 /* TypeArguments */; var invocation = argumentListInfo.invocation; var callTarget = ts.getInvokedExpression(invocation); - var callTargetSymbol = typeInfoResolver.getSymbolAtLocation(callTarget); - var callTargetDisplayParts = callTargetSymbol && ts.symbolToDisplayParts(typeInfoResolver, callTargetSymbol, undefined, undefined); + var callTargetSymbol = typeChecker.getSymbolAtLocation(callTarget); + var callTargetDisplayParts = callTargetSymbol && ts.symbolToDisplayParts(typeChecker, callTargetSymbol, undefined, undefined); var items = ts.map(candidates, function (candidateSignature) { var signatureHelpParameters; var prefixDisplayParts = []; @@ -31157,13 +31205,13 @@ var ts; signatureHelpParameters = typeParameters && typeParameters.length > 0 ? ts.map(typeParameters, createSignatureHelpParameterForTypeParameter) : emptyArray; suffixDisplayParts.push(ts.punctuationPart(25 /* GreaterThanToken */)); var parameterParts = ts.mapToDisplayParts(function (writer) { - return typeInfoResolver.getSymbolDisplayBuilder().buildDisplayForParametersAndDelimiters(candidateSignature.parameters, writer, invocation); + return typeChecker.getSymbolDisplayBuilder().buildDisplayForParametersAndDelimiters(candidateSignature.parameters, writer, invocation); }); suffixDisplayParts.push.apply(suffixDisplayParts, parameterParts); } else { var typeParameterParts = ts.mapToDisplayParts(function (writer) { - return typeInfoResolver.getSymbolDisplayBuilder().buildDisplayForTypeParametersAndDelimiters(candidateSignature.typeParameters, writer, invocation); + return typeChecker.getSymbolDisplayBuilder().buildDisplayForTypeParametersAndDelimiters(candidateSignature.typeParameters, writer, invocation); }); prefixDisplayParts.push.apply(prefixDisplayParts, typeParameterParts); prefixDisplayParts.push(ts.punctuationPart(16 /* OpenParenToken */)); @@ -31172,7 +31220,7 @@ var ts; suffixDisplayParts.push(ts.punctuationPart(17 /* CloseParenToken */)); } var returnTypeParts = ts.mapToDisplayParts(function (writer) { - return typeInfoResolver.getSymbolDisplayBuilder().buildReturnTypeDisplay(candidateSignature, writer, invocation); + return typeChecker.getSymbolDisplayBuilder().buildReturnTypeDisplay(candidateSignature, writer, invocation); }); suffixDisplayParts.push.apply(suffixDisplayParts, returnTypeParts); return { @@ -31201,7 +31249,7 @@ var ts; }; function createSignatureHelpParameterForParameter(parameter) { var displayParts = ts.mapToDisplayParts(function (writer) { - return typeInfoResolver.getSymbolDisplayBuilder().buildParameterDisplay(parameter, writer, invocation); + return typeChecker.getSymbolDisplayBuilder().buildParameterDisplay(parameter, writer, invocation); }); var isOptional = ts.hasQuestionToken(parameter.valueDeclaration); return { @@ -31213,7 +31261,7 @@ var ts; } function createSignatureHelpParameterForTypeParameter(typeParameter) { var displayParts = ts.mapToDisplayParts(function (writer) { - return typeInfoResolver.getSymbolDisplayBuilder().buildTypeParameterDisplay(typeParameter, writer, invocation); + return typeChecker.getSymbolDisplayBuilder().buildTypeParameterDisplay(typeParameter, writer, invocation); }); return { name: typeParameter.symbol.name, @@ -31661,9 +31709,9 @@ var ts; ts.isInsideTemplateLiteral = isInsideTemplateLiteral; function isAccessibilityModifier(kind) { switch (kind) { - case 109 /* PublicKeyword */: - case 107 /* PrivateKeyword */: - case 108 /* ProtectedKeyword */: + case 108 /* PublicKeyword */: + case 106 /* PrivateKeyword */: + case 107 /* ProtectedKeyword */: return true; } return false; @@ -31855,6 +31903,10 @@ var ts; }); } ts.signatureToDisplayParts = signatureToDisplayParts; + function isJavaScript(fileName) { + return ts.fileExtensionIs(fileName, ".js"); + } + ts.isJavaScript = isJavaScript; })(ts || (ts = {})); /// /// @@ -32376,7 +32428,7 @@ var ts; this.SpaceAfterSubtractWhenFollowedByPredecrement = new formatting.Rule(formatting.RuleDescriptor.create1(34 /* MinusToken */, 39 /* MinusMinusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); this.NoSpaceBeforeComma = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 23 /* CommaToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); this.SpaceAfterCertainKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([98 /* VarKeyword */, 94 /* ThrowKeyword */, 88 /* NewKeyword */, 74 /* DeleteKeyword */, 90 /* ReturnKeyword */, 97 /* TypeOfKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); - this.SpaceAfterLetConstInVariableDeclaration = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([105 /* LetKeyword */, 70 /* ConstKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), 2 /* Space */)); + this.SpaceAfterLetConstInVariableDeclaration = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([104 /* LetKeyword */, 70 /* ConstKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), 2 /* Space */)); this.NoSpaceBeforeOpenParenInFuncCall = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 16 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsFunctionCallOrNewContext, Rules.IsPreviousTokenNotComma), 8 /* Delete */)); this.SpaceAfterFunctionInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create3(83 /* FunctionKeyword */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2 /* Space */)); this.NoSpaceBeforeOpenParenInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 16 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsFunctionDeclContext), 8 /* Delete */)); @@ -32399,8 +32451,8 @@ var ts; // Use of module as a function call. e.g.: import m2 = module("m2"); this.NoSpaceAfterModuleImport = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([117 /* ModuleKeyword */, 118 /* RequireKeyword */]), 16 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); // Add a space around certain TypeScript keywords - this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([69 /* ClassKeyword */, 115 /* DeclareKeyword */, 77 /* EnumKeyword */, 78 /* ExportKeyword */, 79 /* ExtendsKeyword */, 116 /* GetKeyword */, 103 /* ImplementsKeyword */, 85 /* ImportKeyword */, 104 /* InterfaceKeyword */, 117 /* ModuleKeyword */, 107 /* PrivateKeyword */, 109 /* PublicKeyword */, 120 /* SetKeyword */, 110 /* StaticKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); - this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([79 /* ExtendsKeyword */, 103 /* ImplementsKeyword */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); + this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([69 /* ClassKeyword */, 115 /* DeclareKeyword */, 77 /* EnumKeyword */, 78 /* ExportKeyword */, 79 /* ExtendsKeyword */, 116 /* GetKeyword */, 102 /* ImplementsKeyword */, 85 /* ImportKeyword */, 103 /* InterfaceKeyword */, 117 /* ModuleKeyword */, 106 /* PrivateKeyword */, 108 /* PublicKeyword */, 120 /* SetKeyword */, 109 /* StaticKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); + this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([79 /* ExtendsKeyword */, 102 /* ImplementsKeyword */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); // Treat string literals in module names as identifiers, and add a space between the literal and the opening Brace braces, e.g.: module "m2" { this.SpaceAfterModuleName = new formatting.Rule(formatting.RuleDescriptor.create1(8 /* StringLiteral */, 14 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsModuleDeclContext), 2 /* Space */)); // Lambda expressions @@ -32419,7 +32471,7 @@ var ts; // decorators this.SpaceBeforeAt = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 52 /* AtToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); this.NoSpaceAfterAt = new formatting.Rule(formatting.RuleDescriptor.create3(52 /* AtToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); - this.SpaceAfterDecorator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([65 /* Identifier */, 78 /* ExportKeyword */, 73 /* DefaultKeyword */, 69 /* ClassKeyword */, 110 /* StaticKeyword */, 109 /* PublicKeyword */, 107 /* PrivateKeyword */, 108 /* ProtectedKeyword */, 116 /* GetKeyword */, 120 /* SetKeyword */, 18 /* OpenBracketToken */, 35 /* AsteriskToken */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsEndOfDecoratorContextOnSameLine), 2 /* Space */)); + this.SpaceAfterDecorator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([65 /* Identifier */, 78 /* ExportKeyword */, 73 /* DefaultKeyword */, 69 /* ClassKeyword */, 109 /* StaticKeyword */, 108 /* PublicKeyword */, 106 /* PrivateKeyword */, 107 /* ProtectedKeyword */, 116 /* GetKeyword */, 120 /* SetKeyword */, 18 /* OpenBracketToken */, 35 /* AsteriskToken */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsEndOfDecoratorContextOnSameLine), 2 /* Space */)); // These rules are higher in priority than user-configurable rules. this.HighPriorityCommonRules = [ @@ -32509,9 +32561,9 @@ var ts; } Rules.prototype.getRuleName = function (rule) { var o = this; - for (var name_22 in o) { - if (o[name_22] === rule) { - return name_22; + for (var name_23 in o) { + if (o[name_23] === rule) { + return name_23; } } throw new Error("Unknown rule"); @@ -33436,7 +33488,7 @@ var ts; } switch (node.kind) { case 201 /* ClassDeclaration */: return 69 /* ClassKeyword */; - case 202 /* InterfaceDeclaration */: return 104 /* InterfaceKeyword */; + case 202 /* InterfaceDeclaration */: return 103 /* InterfaceKeyword */; case 200 /* FunctionDeclaration */: return 83 /* FunctionKeyword */; case 204 /* EnumDeclaration */: return 204 /* EnumDeclaration */; case 136 /* GetAccessor */: return 116 /* GetKeyword */; @@ -34909,29 +34961,65 @@ var ts; return this.namedDeclarations; }; SourceFileObject.prototype.computeNamedDeclarations = function () { - var namedDeclarations = []; + var result = {}; ts.forEachChild(this, visit); - return namedDeclarations; + return result; + function addDeclaration(declaration) { + var name = getDeclarationName(declaration); + if (name) { + var declarations = getDeclarations(name); + declarations.push(declaration); + } + } + function getDeclarations(name) { + return ts.getProperty(result, name) || (result[name] = []); + } + function getDeclarationName(declaration) { + if (declaration.name) { + var result_2 = getTextOfIdentifierOrLiteral(declaration.name); + if (result_2 !== undefined) { + return result_2; + } + if (declaration.name.kind === 127 /* ComputedPropertyName */) { + var expr = declaration.name.expression; + if (expr.kind === 155 /* PropertyAccessExpression */) { + return expr.name.text; + } + return getTextOfIdentifierOrLiteral(expr); + } + } + return undefined; + } + function getTextOfIdentifierOrLiteral(node) { + if (node) { + if (node.kind === 65 /* Identifier */ || + node.kind === 8 /* StringLiteral */ || + node.kind === 7 /* NumericLiteral */) { + return node.text; + } + } + return undefined; + } function visit(node) { switch (node.kind) { case 200 /* FunctionDeclaration */: case 134 /* MethodDeclaration */: case 133 /* MethodSignature */: var functionDeclaration = node; - if (functionDeclaration.name && functionDeclaration.name.getFullWidth() > 0) { - var lastDeclaration = namedDeclarations.length > 0 ? - namedDeclarations[namedDeclarations.length - 1] : - undefined; + var declarationName = getDeclarationName(functionDeclaration); + if (declarationName) { + var declarations = getDeclarations(declarationName); + var lastDeclaration = ts.lastOrUndefined(declarations); // Check whether this declaration belongs to an "overload group". - if (lastDeclaration && functionDeclaration.symbol === lastDeclaration.symbol) { + if (lastDeclaration && functionDeclaration.parent === lastDeclaration.parent && functionDeclaration.symbol === lastDeclaration.symbol) { // Overwrite the last declaration if it was an overload // and this one is an implementation. if (functionDeclaration.body && !lastDeclaration.body) { - namedDeclarations[namedDeclarations.length - 1] = functionDeclaration; + declarations[declarations.length - 1] = functionDeclaration; } } else { - namedDeclarations.push(functionDeclaration); + declarations.push(functionDeclaration); } ts.forEachChild(node, visit); } @@ -34950,9 +35038,7 @@ var ts; case 136 /* GetAccessor */: case 137 /* SetAccessor */: case 145 /* TypeLiteral */: - if (node.name) { - namedDeclarations.push(node); - } + addDeclaration(node); // fall through case 135 /* Constructor */: case 180 /* VariableStatement */: @@ -34982,7 +35068,7 @@ var ts; case 226 /* EnumMember */: case 132 /* PropertyDeclaration */: case 131 /* PropertySignature */: - namedDeclarations.push(node); + addDeclaration(node); break; case 215 /* ExportDeclaration */: // Handle named exports case e.g.: @@ -34997,14 +35083,14 @@ var ts; // Handle default import case e.g.: // import d from "mod"; if (importClause.name) { - namedDeclarations.push(importClause); + addDeclaration(importClause); } // Handle named bindings in imports e.g.: // import * as NS from "mod"; // import {a, b as B} from "mod"; if (importClause.namedBindings) { if (importClause.namedBindings.kind === 211 /* NamespaceImport */) { - namedDeclarations.push(importClause.namedBindings); + addDeclaration(importClause.namedBindings); } else { ts.forEach(importClause.namedBindings.elements, visit); @@ -35593,7 +35679,7 @@ var ts; } else if (token === 35 /* AsteriskToken */) { token = scanner.scan(); - if (token === 102 /* AsKeyword */) { + if (token === 111 /* AsKeyword */) { token = scanner.scan(); if (token === 65 /* Identifier */) { token = scanner.scan(); @@ -35864,8 +35950,6 @@ var ts; var syntaxTreeCache = new SyntaxTreeCache(host); var ruleProvider; var program; - // this checker is used to answer all LS questions except errors - var typeInfoResolver; var useCaseSensitivefileNames = false; var cancellationToken = new CancellationTokenObject(host.getCancellationToken && host.getCancellationToken()); // Check if the localized messages json is set, otherwise query the host for it @@ -35935,7 +36019,9 @@ var ts; } } program = newProgram; - typeInfoResolver = program.getTypeChecker(); + // Make sure all the nodes in the program are both bound, and have their parent + // pointers set property. + program.getTypeChecker(); return; function getOrCreateSourceFile(fileName) { // The program is asking for this file, check first if the host can locate it. @@ -36007,15 +36093,8 @@ var ts; synchronizeHostData(); return program; } - /** - * Clean up any semantic caches that are not needed. - * The host can call this method if it wants to jettison unused memory. - * We will just dump the typeChecker and recreate a new one. this should have the effect of destroying all the semantic caches. - */ function cleanupSemanticCache() { - if (program) { - typeInfoResolver = program.getTypeChecker(); - } + // TODO: Should we jettison the program (or it's type checker) here? } function dispose() { if (program) { @@ -36029,9 +36108,6 @@ var ts; synchronizeHostData(); return program.getSyntacticDiagnostics(getValidSourceFile(fileName)); } - function isJavaScript(fileName) { - return ts.fileExtensionIs(fileName, ".js"); - } /** * getSemanticDiagnostiscs return array of Diagnostics. If '-d' is not enabled, only report semantic errors * If '-d' enabled, report both semantic and emitter errors @@ -36042,7 +36118,7 @@ var ts; // For JavaScript files, we don't want to report the normal typescript semantic errors. // Instead, we just report errors for using TypeScript-only constructs from within a // JavaScript file. - if (isJavaScript(fileName)) { + if (ts.isJavaScript(fileName)) { return getJavaScriptSemanticDiagnostics(targetSourceFile); } // Only perform the action per file regardless of '-out' flag as LanguageServiceHost is expected to call this function per file. @@ -36079,7 +36155,7 @@ var ts; break; case 222 /* HeritageClause */: var heritageClause = node; - if (heritageClause.token === 103 /* ImplementsKeyword */) { + if (heritageClause.token === 102 /* ImplementsKeyword */) { diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.implements_clauses_can_only_be_used_in_a_ts_file)); return true; } @@ -36182,14 +36258,14 @@ var ts; for (var _i = 0; _i < modifiers.length; _i++) { var modifier = modifiers[_i]; switch (modifier.kind) { - case 109 /* PublicKeyword */: - case 107 /* PrivateKeyword */: - case 108 /* ProtectedKeyword */: + case 108 /* PublicKeyword */: + case 106 /* PrivateKeyword */: + case 107 /* ProtectedKeyword */: case 115 /* DeclareKeyword */: diagnostics.push(ts.createDiagnosticForNode(modifier, ts.Diagnostics._0_can_only_be_used_in_a_ts_file, ts.tokenToString(modifier.kind))); return true; // These are all legal modifiers. - case 110 /* StaticKeyword */: + case 109 /* StaticKeyword */: case 78 /* ExportKeyword */: case 70 /* ConstKeyword */: case 73 /* DefaultKeyword */: @@ -36251,29 +36327,8 @@ var ts; } return ts.unescapeIdentifier(displayName); } - function createCompletionEntry(symbol, typeChecker, location) { - // Try to get a valid display name for this symbol, if we could not find one, then ignore it. - // We would like to only show things that can be added after a dot, so for instance numeric properties can - // not be accessed with a dot (a.1 <- invalid) - var displayName = getCompletionEntryDisplayNameForSymbol(symbol, program.getCompilerOptions().target, true); - if (!displayName) { - return undefined; - } - // TODO(drosen): Right now we just permit *all* semantic meanings when calling - // 'getSymbolKind' which is permissible given that it is backwards compatible; but - // really we should consider passing the meaning for the node so that we don't report - // that a suggestion for a value is an interface. We COULD also just do what - // 'getSymbolModifiers' does, which is to use the first declaration. - // Use a 'sortText' of 0' so that all symbol completion entries come before any other - // entries (like JavaScript identifier entries). - return { - name: displayName, - kind: getSymbolKind(symbol, typeChecker, location), - kindModifiers: getSymbolModifiers(symbol), - sortText: "0" - }; - } function getCompletionData(fileName, position) { + var typeChecker = program.getTypeChecker(); var syntacticStart = new Date().getTime(); var sourceFile = getValidSourceFile(fileName); var start = new Date().getTime(); @@ -36342,26 +36397,26 @@ var ts; isMemberCompletion = true; isNewIdentifierLocation = false; if (node.kind === 65 /* Identifier */ || node.kind === 126 /* QualifiedName */ || node.kind === 155 /* PropertyAccessExpression */) { - var symbol = typeInfoResolver.getSymbolAtLocation(node); + var symbol = typeChecker.getSymbolAtLocation(node); // This is an alias, follow what it aliases if (symbol && symbol.flags & 8388608 /* Alias */) { - symbol = typeInfoResolver.getAliasedSymbol(symbol); + symbol = typeChecker.getAliasedSymbol(symbol); } if (symbol && symbol.flags & 1952 /* HasExports */) { // Extract module or enum members - var exportedSymbols = typeInfoResolver.getExportsOfModule(symbol); + var exportedSymbols = typeChecker.getExportsOfModule(symbol); ts.forEach(exportedSymbols, function (symbol) { - if (typeInfoResolver.isValidPropertyAccess((node.parent), symbol.name)) { + if (typeChecker.isValidPropertyAccess((node.parent), symbol.name)) { symbols.push(symbol); } }); } } - var type = typeInfoResolver.getTypeAtLocation(node); + var type = typeChecker.getTypeAtLocation(node); if (type) { // Filter private properties ts.forEach(type.getApparentProperties(), function (symbol) { - if (typeInfoResolver.isValidPropertyAccess((node.parent), symbol.name)) { + if (typeChecker.isValidPropertyAccess((node.parent), symbol.name)) { symbols.push(symbol); } }); @@ -36373,11 +36428,11 @@ var ts; // Object literal expression, look up possible property names from contextual type isMemberCompletion = true; isNewIdentifierLocation = true; - var contextualType = typeInfoResolver.getContextualType(containingObjectLiteral); + var contextualType = typeChecker.getContextualType(containingObjectLiteral); if (!contextualType) { return false; } - var contextualTypeMembers = typeInfoResolver.getPropertiesOfType(contextualType); + var contextualTypeMembers = typeChecker.getPropertiesOfType(contextualType); if (contextualTypeMembers && contextualTypeMembers.length > 0) { // Add filtered items to the completion list symbols = filterContextualMembersList(contextualTypeMembers, containingObjectLiteral.properties); @@ -36393,9 +36448,9 @@ var ts; ts.Debug.assert(importDeclaration !== undefined); var exports; if (importDeclaration.moduleSpecifier) { - var moduleSpecifierSymbol = typeInfoResolver.getSymbolAtLocation(importDeclaration.moduleSpecifier); + var moduleSpecifierSymbol = typeChecker.getSymbolAtLocation(importDeclaration.moduleSpecifier); if (moduleSpecifierSymbol) { - exports = typeInfoResolver.getExportsOfModule(moduleSpecifierSymbol); + exports = typeChecker.getExportsOfModule(moduleSpecifierSymbol); } } //let exports = typeInfoResolver.getExportsOfImportDeclaration(importDeclaration); @@ -36440,7 +36495,7 @@ var ts; var scopeNode = getScopeNode(contextToken, adjustedPosition, sourceFile) || sourceFile; /// TODO filter meaning based on the current context var symbolMeanings = 793056 /* Type */ | 107455 /* Value */ | 1536 /* Namespace */ | 8388608 /* Alias */; - symbols = typeInfoResolver.getSymbolsInScope(scopeNode, symbolMeanings); + symbols = typeChecker.getSymbolsInScope(scopeNode, symbolMeanings); } return true; } @@ -36503,9 +36558,9 @@ var ts; return containingNodeKind === 171 /* TemplateExpression */; // `aa ${| case 12 /* TemplateMiddle */: return containingNodeKind === 176 /* TemplateSpan */; // `aa ${10} dd ${| - case 109 /* PublicKeyword */: - case 107 /* PrivateKeyword */: - case 108 /* ProtectedKeyword */: + case 108 /* PublicKeyword */: + case 106 /* PrivateKeyword */: + case 107 /* ProtectedKeyword */: return containingNodeKind === 132 /* PropertyDeclaration */; // class A{ public | } // Previous token may have been a keyword that was converted to an identifier. @@ -36595,6 +36650,7 @@ var ts; containingNodeKind === 150 /* ObjectBindingPattern */; // function func({ x| case 22 /* SemicolonToken */: return containingNodeKind === 131 /* PropertySignature */ && + previousToken.parent && previousToken.parent.parent && (previousToken.parent.parent.kind === 202 /* InterfaceDeclaration */ || previousToken.parent.parent.kind === 145 /* TypeLiteral */); // let x : { a; | case 24 /* LessThanToken */: @@ -36602,27 +36658,28 @@ var ts; containingNodeKind === 200 /* FunctionDeclaration */ || containingNodeKind === 202 /* InterfaceDeclaration */ || isFunction(containingNodeKind); - case 110 /* StaticKeyword */: + case 109 /* StaticKeyword */: return containingNodeKind === 132 /* PropertyDeclaration */; case 21 /* DotDotDotToken */: return containingNodeKind === 129 /* Parameter */ || containingNodeKind === 135 /* Constructor */ || - (previousToken.parent.parent.kind === 151 /* ArrayBindingPattern */); // var [ ...z| - case 109 /* PublicKeyword */: - case 107 /* PrivateKeyword */: - case 108 /* ProtectedKeyword */: + (previousToken.parent && previousToken.parent.parent && + previousToken.parent.parent.kind === 151 /* ArrayBindingPattern */); // var [ ...z| + case 108 /* PublicKeyword */: + case 106 /* PrivateKeyword */: + case 107 /* ProtectedKeyword */: return containingNodeKind === 129 /* Parameter */; case 69 /* ClassKeyword */: case 77 /* EnumKeyword */: - case 104 /* InterfaceKeyword */: + case 103 /* InterfaceKeyword */: case 83 /* FunctionKeyword */: case 98 /* VarKeyword */: case 116 /* GetKeyword */: case 120 /* SetKeyword */: case 85 /* ImportKeyword */: - case 105 /* LetKeyword */: + case 104 /* LetKeyword */: case 70 /* ConstKeyword */: - case 111 /* YieldKeyword */: + case 110 /* YieldKeyword */: return true; } // Previous token may have been a keyword that was converted to an identifier. @@ -36699,7 +36756,7 @@ var ts; } var symbols = completionData.symbols, isMemberCompletion = completionData.isMemberCompletion, isNewIdentifierLocation = completionData.isNewIdentifierLocation, location = completionData.location, isRightOfDot = completionData.isRightOfDot; var entries; - if (isRightOfDot && isJavaScript(fileName)) { + if (isRightOfDot && ts.isJavaScript(fileName)) { entries = getCompletionEntriesFromSymbols(symbols); ts.addRange(entries, getJavaScriptCompletionEntries()); } @@ -36721,10 +36778,10 @@ var ts; for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) { var sourceFile = _a[_i]; var nameTable = getNameTable(sourceFile); - for (var name_23 in nameTable) { - if (!allNames[name_23]) { - allNames[name_23] = name_23; - var displayName = getCompletionEntryDisplayName(name_23, target, true); + for (var name_24 in nameTable) { + if (!allNames[name_24]) { + allNames[name_24] = name_24; + var displayName = getCompletionEntryDisplayName(name_24, target, true); if (displayName) { var entry = { name: displayName, @@ -36739,6 +36796,28 @@ var ts; } return entries; } + function createCompletionEntry(symbol, location) { + // Try to get a valid display name for this symbol, if we could not find one, then ignore it. + // We would like to only show things that can be added after a dot, so for instance numeric properties can + // not be accessed with a dot (a.1 <- invalid) + var displayName = getCompletionEntryDisplayNameForSymbol(symbol, program.getCompilerOptions().target, true); + if (!displayName) { + return undefined; + } + // TODO(drosen): Right now we just permit *all* semantic meanings when calling + // 'getSymbolKind' which is permissible given that it is backwards compatible; but + // really we should consider passing the meaning for the node so that we don't report + // that a suggestion for a value is an interface. We COULD also just do what + // 'getSymbolModifiers' does, which is to use the first declaration. + // Use a 'sortText' of 0' so that all symbol completion entries come before any other + // entries (like JavaScript identifier entries). + return { + name: displayName, + kind: getSymbolKind(symbol, location), + kindModifiers: getSymbolModifiers(symbol), + sortText: "0" + }; + } function getCompletionEntriesFromSymbols(symbols) { var start = new Date().getTime(); var entries = []; @@ -36746,7 +36825,7 @@ var ts; var nameToSymbol = {}; for (var _i = 0; _i < symbols.length; _i++) { var symbol = symbols[_i]; - var entry = createCompletionEntry(symbol, typeInfoResolver, location); + var entry = createCompletionEntry(symbol, location); if (entry) { var id = ts.escapeIdentifier(entry.name); if (!ts.lookUp(nameToSymbol, id)) { @@ -36773,7 +36852,7 @@ var ts; // completion entry. var symbol = ts.forEach(symbols, function (s) { return getCompletionEntryDisplayNameForSymbol(s, target, false) === entryName ? s : undefined; }); if (symbol) { - var displayPartsDocumentationsAndSymbolKind = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, getValidSourceFile(fileName), location_2, typeInfoResolver, location_2, 7 /* All */); + var displayPartsDocumentationsAndSymbolKind = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, getValidSourceFile(fileName), location_2, location_2, 7 /* All */); return { name: entryName, kind: displayPartsDocumentationsAndSymbolKind.symbolKind, @@ -36797,7 +36876,7 @@ var ts; return undefined; } // TODO(drosen): use contextual SemanticMeaning. - function getSymbolKind(symbol, typeResolver, location) { + function getSymbolKind(symbol, location) { var flags = symbol.getFlags(); if (flags & 32 /* Class */) return ScriptElementKind.classElement; @@ -36809,7 +36888,7 @@ var ts; return ScriptElementKind.interfaceElement; if (flags & 262144 /* TypeParameter */) return ScriptElementKind.typeParameterElement; - var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, flags, typeResolver, location); + var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, flags, location); if (result === ScriptElementKind.unknown) { if (flags & 262144 /* TypeParameter */) return ScriptElementKind.typeParameterElement; @@ -36822,11 +36901,12 @@ var ts; } return result; } - function getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, flags, typeResolver, location) { - if (typeResolver.isUndefinedSymbol(symbol)) { + function getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, flags, location) { + var typeChecker = program.getTypeChecker(); + if (typeChecker.isUndefinedSymbol(symbol)) { return ScriptElementKind.variableElement; } - if (typeResolver.isArgumentsSymbol(symbol)) { + if (typeChecker.isArgumentsSymbol(symbol)) { return ScriptElementKind.localVariableElement; } if (flags & 3 /* Variable */) { @@ -36854,7 +36934,7 @@ var ts; if (flags & 4 /* Property */) { if (flags & 268435456 /* UnionProperty */) { // If union property is result of union of non method (property/accessors/variables), it is labeled as property - var unionPropertyKind = ts.forEach(typeInfoResolver.getRootSymbols(symbol), function (rootSymbol) { + var unionPropertyKind = ts.forEach(typeChecker.getRootSymbols(symbol), function (rootSymbol) { var rootSymbolFlags = rootSymbol.getFlags(); if (rootSymbolFlags & (98308 /* PropertyOrAccessor */ | 3 /* Variable */)) { return ScriptElementKind.memberVariableElement; @@ -36864,7 +36944,7 @@ var ts; if (!unionPropertyKind) { // If this was union of all methods, //make sure it has call signatures before we can label it as method - var typeOfUnionProperty = typeInfoResolver.getTypeOfSymbolAtLocation(symbol, location); + var typeOfUnionProperty = typeChecker.getTypeOfSymbolAtLocation(symbol, location); if (typeOfUnionProperty.getCallSignatures().length) { return ScriptElementKind.memberFunctionElement; } @@ -36897,14 +36977,14 @@ var ts; ? ts.getNodeModifiers(symbol.declarations[0]) : ScriptElementKindModifier.none; } - function getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, sourceFile, enclosingDeclaration, typeResolver, location, - // TODO(drosen): Currently completion entry details passes the SemanticMeaning.All instead of using semanticMeaning of location - semanticMeaning) { + // TODO(drosen): Currently completion entry details passes the SemanticMeaning.All instead of using semanticMeaning of location + function getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, sourceFile, enclosingDeclaration, location, semanticMeaning) { if (semanticMeaning === void 0) { semanticMeaning = getMeaningFromLocation(location); } + var typeChecker = program.getTypeChecker(); var displayParts = []; var documentation; var symbolFlags = symbol.flags; - var symbolKind = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, symbolFlags, typeResolver, location); + var symbolKind = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, symbolFlags, location); var hasAddedSymbolInfo; var type; // Class at constructor site need to be shown as constructor apart from property,method, vars @@ -36914,7 +36994,7 @@ var ts; symbolKind = ScriptElementKind.memberVariableElement; } var signature; - type = typeResolver.getTypeOfSymbolAtLocation(symbol, location); + type = typeChecker.getTypeOfSymbolAtLocation(symbol, location); if (type) { if (location.parent && location.parent.kind === 155 /* PropertyAccessExpression */) { var right = location.parent.name; @@ -36933,7 +37013,7 @@ var ts; } if (callExpression) { var candidateSignatures = []; - signature = typeResolver.getResolvedSignature(callExpression, candidateSignatures); + signature = typeChecker.getResolvedSignature(callExpression, candidateSignatures); if (!signature && candidateSignatures.length) { // Use the first candidate: signature = candidateSignatures[0]; @@ -36978,7 +37058,7 @@ var ts; displayParts.push(ts.spacePart()); } if (!(type.flags & 32768 /* Anonymous */)) { - displayParts.push.apply(displayParts, ts.symbolToDisplayParts(typeResolver, type.symbol, enclosingDeclaration, undefined, 1 /* WriteTypeParametersOrArguments */)); + displayParts.push.apply(displayParts, ts.symbolToDisplayParts(typeChecker, type.symbol, enclosingDeclaration, undefined, 1 /* WriteTypeParametersOrArguments */)); } addSignatureDisplayParts(signature, allSignatures, 8 /* WriteArrowStyleSignature */); break; @@ -36994,8 +37074,8 @@ var ts; // get the signature from the declaration and write it var functionDeclaration = location.parent; var allSignatures = functionDeclaration.kind === 135 /* Constructor */ ? type.getConstructSignatures() : type.getCallSignatures(); - if (!typeResolver.isImplementationOfOverload(functionDeclaration)) { - signature = typeResolver.getSignatureFromDeclaration(functionDeclaration); + if (!typeChecker.isImplementationOfOverload(functionDeclaration)) { + signature = typeChecker.getSignatureFromDeclaration(functionDeclaration); } else { signature = allSignatures[0]; @@ -37023,7 +37103,7 @@ var ts; } if ((symbolFlags & 64 /* Interface */) && (semanticMeaning & 2 /* Type */)) { addNewLineIfDisplayPartsExist(); - displayParts.push(ts.keywordPart(104 /* InterfaceKeyword */)); + displayParts.push(ts.keywordPart(103 /* InterfaceKeyword */)); displayParts.push(ts.spacePart()); addFullSymbolName(symbol); writeTypeParametersOfSymbol(symbol, sourceFile); @@ -37036,7 +37116,7 @@ var ts; displayParts.push(ts.spacePart()); displayParts.push(ts.operatorPart(53 /* EqualsToken */)); displayParts.push(ts.spacePart()); - displayParts.push.apply(displayParts, ts.typeToDisplayParts(typeResolver, typeResolver.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration)); + displayParts.push.apply(displayParts, ts.typeToDisplayParts(typeChecker, typeChecker.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration)); } if (symbolFlags & 384 /* Enum */) { addNewLineIfDisplayPartsExist(); @@ -37072,7 +37152,7 @@ var ts; else { // Method/function type parameter var signatureDeclaration = ts.getDeclarationOfKind(symbol, 128 /* TypeParameter */).parent; - var signature = typeResolver.getSignatureFromDeclaration(signatureDeclaration); + var signature = typeChecker.getSignatureFromDeclaration(signatureDeclaration); if (signatureDeclaration.kind === 139 /* ConstructSignature */) { displayParts.push(ts.keywordPart(88 /* NewKeyword */)); displayParts.push(ts.spacePart()); @@ -37080,14 +37160,14 @@ var ts; else if (signatureDeclaration.kind !== 138 /* CallSignature */ && signatureDeclaration.name) { addFullSymbolName(signatureDeclaration.symbol); } - displayParts.push.apply(displayParts, ts.signatureToDisplayParts(typeResolver, signature, sourceFile, 32 /* WriteTypeArgumentsOfSignature */)); + displayParts.push.apply(displayParts, ts.signatureToDisplayParts(typeChecker, signature, sourceFile, 32 /* WriteTypeArgumentsOfSignature */)); } } if (symbolFlags & 8 /* EnumMember */) { addPrefixForAnyFunctionOrVar(symbol, "enum member"); var declaration = symbol.declarations[0]; if (declaration.kind === 226 /* EnumMember */) { - var constantValue = typeResolver.getConstantValue(declaration); + var constantValue = typeChecker.getConstantValue(declaration); if (constantValue !== undefined) { displayParts.push(ts.spacePart()); displayParts.push(ts.operatorPart(53 /* EqualsToken */)); @@ -37114,7 +37194,7 @@ var ts; displayParts.push(ts.punctuationPart(17 /* CloseParenToken */)); } else { - var internalAliasSymbol = typeResolver.getSymbolAtLocation(importEqualsDeclaration.moduleReference); + var internalAliasSymbol = typeChecker.getSymbolAtLocation(importEqualsDeclaration.moduleReference); if (internalAliasSymbol) { displayParts.push(ts.spacePart()); displayParts.push(ts.operatorPart(53 /* EqualsToken */)); @@ -37139,12 +37219,12 @@ var ts; // If the type is type parameter, format it specially if (type.symbol && type.symbol.flags & 262144 /* TypeParameter */) { var typeParameterParts = ts.mapToDisplayParts(function (writer) { - typeResolver.getSymbolDisplayBuilder().buildTypeParameterDisplay(type, writer, enclosingDeclaration); + typeChecker.getSymbolDisplayBuilder().buildTypeParameterDisplay(type, writer, enclosingDeclaration); }); displayParts.push.apply(displayParts, typeParameterParts); } else { - displayParts.push.apply(displayParts, ts.typeToDisplayParts(typeResolver, type, enclosingDeclaration)); + displayParts.push.apply(displayParts, ts.typeToDisplayParts(typeChecker, type, enclosingDeclaration)); } } else if (symbolFlags & 16 /* Function */ || @@ -37159,7 +37239,7 @@ var ts; } } else { - symbolKind = getSymbolKind(symbol, typeResolver, location); + symbolKind = getSymbolKind(symbol, location); } } if (!documentation) { @@ -37172,7 +37252,7 @@ var ts; } } function addFullSymbolName(symbol, enclosingDeclaration) { - var fullSymbolDisplayParts = ts.symbolToDisplayParts(typeResolver, symbol, enclosingDeclaration || sourceFile, undefined, 1 /* WriteTypeParametersOrArguments */ | 2 /* UseOnlyExternalAliasing */); + var fullSymbolDisplayParts = ts.symbolToDisplayParts(typeChecker, symbol, enclosingDeclaration || sourceFile, undefined, 1 /* WriteTypeParametersOrArguments */ | 2 /* UseOnlyExternalAliasing */); displayParts.push.apply(displayParts, fullSymbolDisplayParts); } function addPrefixForAnyFunctionOrVar(symbol, symbolKind) { @@ -37200,7 +37280,7 @@ var ts; } } function addSignatureDisplayParts(signature, allSignatures, flags) { - displayParts.push.apply(displayParts, ts.signatureToDisplayParts(typeResolver, signature, enclosingDeclaration, flags | 32 /* WriteTypeArgumentsOfSignature */)); + displayParts.push.apply(displayParts, ts.signatureToDisplayParts(typeChecker, signature, enclosingDeclaration, flags | 32 /* WriteTypeArgumentsOfSignature */)); if (allSignatures.length > 1) { displayParts.push(ts.spacePart()); displayParts.push(ts.punctuationPart(16 /* OpenParenToken */)); @@ -37214,7 +37294,7 @@ var ts; } function writeTypeParametersOfSymbol(symbol, enclosingDeclaration) { var typeParameterParts = ts.mapToDisplayParts(function (writer) { - typeResolver.getSymbolDisplayBuilder().buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaration); + typeChecker.getSymbolDisplayBuilder().buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaration); }); displayParts.push.apply(displayParts, typeParameterParts); } @@ -37226,7 +37306,11 @@ var ts; if (!node) { return undefined; } - var symbol = typeInfoResolver.getSymbolAtLocation(node); + if (isLabelName(node)) { + return undefined; + } + var typeChecker = program.getTypeChecker(); + var symbol = typeChecker.getSymbolAtLocation(node); if (!symbol) { // Try getting just type at this position and show switch (node.kind) { @@ -37236,20 +37320,20 @@ var ts; case 93 /* ThisKeyword */: case 91 /* SuperKeyword */: // For the identifiers/this/super etc get the type at position - var type = typeInfoResolver.getTypeAtLocation(node); + var type = typeChecker.getTypeAtLocation(node); if (type) { return { kind: ScriptElementKind.unknown, kindModifiers: ScriptElementKindModifier.none, textSpan: ts.createTextSpan(node.getStart(), node.getWidth()), - displayParts: ts.typeToDisplayParts(typeInfoResolver, type, getContainerNode(node)), + displayParts: ts.typeToDisplayParts(typeChecker, type, getContainerNode(node)), documentation: type.symbol ? type.symbol.getDocumentationComment() : undefined }; } } return undefined; } - var displayPartsDocumentationsAndKind = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, sourceFile, getContainerNode(node), typeInfoResolver, node); + var displayPartsDocumentationsAndKind = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, sourceFile, getContainerNode(node), node); return { kind: displayPartsDocumentationsAndKind.symbolKind, kindModifiers: getSymbolModifiers(symbol), @@ -37298,7 +37382,8 @@ var ts; } return undefined; } - var symbol = typeInfoResolver.getSymbolAtLocation(node); + var typeChecker = program.getTypeChecker(); + var symbol = typeChecker.getSymbolAtLocation(node); // Could not find a symbol e.g. node is string or number keyword, // or the symbol was an internal symbol and does not have a declaration e.g. undefined symbol if (!symbol) { @@ -37311,7 +37396,7 @@ var ts; if (symbol.flags & 8388608 /* Alias */) { var declaration = symbol.declarations[0]; if (node.kind === 65 /* Identifier */ && node.parent === declaration) { - symbol = typeInfoResolver.getAliasedSymbol(symbol); + symbol = typeChecker.getAliasedSymbol(symbol); } } // Because name in short-hand property assignment has two different meanings: property name and property value, @@ -37320,22 +37405,22 @@ var ts; // is performed at the location of property access, we would like to go to definition of the property in the short-hand // assignment. This case and others are handled by the following code. if (node.parent.kind === 225 /* ShorthandPropertyAssignment */) { - var shorthandSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(symbol.valueDeclaration); + var shorthandSymbol = typeChecker.getShorthandAssignmentValueSymbol(symbol.valueDeclaration); if (!shorthandSymbol) { return []; } var shorthandDeclarations = shorthandSymbol.getDeclarations(); - var shorthandSymbolKind = getSymbolKind(shorthandSymbol, typeInfoResolver, node); - var shorthandSymbolName = typeInfoResolver.symbolToString(shorthandSymbol); - var shorthandContainerName = typeInfoResolver.symbolToString(symbol.parent, node); + var shorthandSymbolKind = getSymbolKind(shorthandSymbol, node); + var shorthandSymbolName = typeChecker.symbolToString(shorthandSymbol); + var shorthandContainerName = typeChecker.symbolToString(symbol.parent, node); return ts.map(shorthandDeclarations, function (declaration) { return createDefinitionInfo(declaration, shorthandSymbolKind, shorthandSymbolName, shorthandContainerName); }); } var result = []; var declarations = symbol.getDeclarations(); - var symbolName = typeInfoResolver.symbolToString(symbol); // Do not get scoped name, just the name of the symbol - var symbolKind = getSymbolKind(symbol, typeInfoResolver, node); + var symbolName = typeChecker.symbolToString(symbol); // Do not get scoped name, just the name of the symbol + var symbolKind = getSymbolKind(symbol, node); var containerSymbol = symbol.parent; - var containerName = containerSymbol ? typeInfoResolver.symbolToString(containerSymbol, node) : ""; + var containerName = containerSymbol ? typeChecker.symbolToString(containerSymbol, node) : ""; if (!tryAddConstructSignature(symbol, node, symbolKind, symbolName, containerName, result) && !tryAddCallSignature(symbol, node, symbolKind, symbolName, containerName, result)) { // Just add all the declarations. @@ -37390,7 +37475,7 @@ var ts; var sourceFile = getCanonicalFileName(ts.normalizeSlashes(fileName)); // Get occurrences only supports reporting occurrences for the file queried. So // filter down to that list. - results = ts.filter(results, function (r) { return r.fileName === fileName; }); + results = ts.filter(results, function (r) { return getCanonicalFileName(ts.normalizeSlashes(r.fileName)) === sourceFile; }); } return results; } @@ -37653,7 +37738,7 @@ var ts; return undefined; } } - else if (modifier === 110 /* StaticKeyword */) { + else if (modifier === 109 /* StaticKeyword */) { if (container.kind !== 201 /* ClassDeclaration */) { return undefined; } @@ -37702,13 +37787,13 @@ var ts; return ts.map(keywords, getHighlightSpanForNode); function getFlagFromModifier(modifier) { switch (modifier) { - case 109 /* PublicKeyword */: + case 108 /* PublicKeyword */: return 16 /* Public */; - case 107 /* PrivateKeyword */: + case 106 /* PrivateKeyword */: return 32 /* Private */; - case 108 /* ProtectedKeyword */: + case 107 /* ProtectedKeyword */: return 64 /* Protected */; - case 110 /* StaticKeyword */: + case 109 /* StaticKeyword */: return 128 /* Static */; case 78 /* ExportKeyword */: return 1 /* Export */; @@ -37969,6 +38054,7 @@ var ts; return getReferencedSymbolsForNodes(node, program.getSourceFiles(), findInStrings, findInComments); } function getReferencedSymbolsForNodes(node, sourceFiles, findInStrings, findInComments) { + var typeChecker = program.getTypeChecker(); // Labels if (isLabelName(node)) { if (isJumpStatementTarget(node)) { @@ -37988,7 +38074,7 @@ var ts; if (node.kind === 91 /* SuperKeyword */) { return getReferencesForSuperKeyword(node); } - var symbol = typeInfoResolver.getSymbolAtLocation(node); + var symbol = typeChecker.getSymbolAtLocation(node); // Could not find a symbol e.g. unknown identifier if (!symbol) { // Can't have references to something that we have no symbol for. @@ -38027,7 +38113,7 @@ var ts; } return result; function getDefinition(symbol) { - var info = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, node.getSourceFile(), getContainerNode(node), typeInfoResolver, node); + var info = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, node.getSourceFile(), getContainerNode(node), node); var name = ts.map(info.displayParts, function (p) { return p.text; }).join(""); var declarations = symbol.declarations; if (!declarations || declarations.length === 0) { @@ -38070,7 +38156,7 @@ var ts; if (isImportOrExportSpecifierName(location)) { return location.getText(); } - name = typeInfoResolver.symbolToString(symbol); + name = typeChecker.symbolToString(symbol); return stripQuotes(name); } function getInternedName(symbol, location, declarations) { @@ -38258,10 +38344,10 @@ var ts; if (!(getMeaningFromLocation(referenceLocation) & searchMeaning)) { return; } - var referenceSymbol = typeInfoResolver.getSymbolAtLocation(referenceLocation); + var referenceSymbol = typeChecker.getSymbolAtLocation(referenceLocation); if (referenceSymbol) { var referenceSymbolDeclaration = referenceSymbol.valueDeclaration; - var shorthandValueSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(referenceSymbolDeclaration); + var shorthandValueSymbol = typeChecker.getShorthandAssignmentValueSymbol(referenceSymbolDeclaration); var relatedSymbol = getRelatedSymbol(searchSymbols, referenceSymbol, referenceLocation); if (relatedSymbol) { var referencedSymbol = getReferencedSymbol(relatedSymbol); @@ -38450,14 +38536,14 @@ var ts; var result = [symbol]; // If the symbol is an alias, add what it alaises to the list if (isImportOrExportSpecifierImportSymbol(symbol)) { - result.push(typeInfoResolver.getAliasedSymbol(symbol)); + result.push(typeChecker.getAliasedSymbol(symbol)); } // If the location is in a context sensitive location (i.e. in an object literal) try // to get a contextual type for it, and add the property symbol from the contextual // type to the search set if (isNameOfPropertyAssignment(location)) { ts.forEach(getPropertySymbolsFromContextualType(location), function (contextualSymbol) { - result.push.apply(result, typeInfoResolver.getRootSymbols(contextualSymbol)); + result.push.apply(result, typeChecker.getRootSymbols(contextualSymbol)); }); /* Because in short-hand property assignment, location has two meaning : property name and as value of the property * When we do findAllReference at the position of the short-hand property assignment, we would want to have references to position of @@ -38470,14 +38556,14 @@ var ts; * so that when matching with potential reference symbol, both symbols from property declaration and variable declaration * will be included correctly. */ - var shorthandValueSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(location.parent); + var shorthandValueSymbol = typeChecker.getShorthandAssignmentValueSymbol(location.parent); if (shorthandValueSymbol) { result.push(shorthandValueSymbol); } } // If this is a union property, add all the symbols from all its source symbols in all unioned types. // If the symbol is an instantiation from a another symbol (e.g. widened symbol) , add the root the list - ts.forEach(typeInfoResolver.getRootSymbols(symbol), function (rootSymbol) { + ts.forEach(typeChecker.getRootSymbols(symbol), function (rootSymbol) { if (rootSymbol !== symbol) { result.push(rootSymbol); } @@ -38503,9 +38589,9 @@ var ts; return; function getPropertySymbolFromTypeReference(typeReference) { if (typeReference) { - var type = typeInfoResolver.getTypeAtLocation(typeReference); + var type = typeChecker.getTypeAtLocation(typeReference); if (type) { - var propertySymbol = typeInfoResolver.getPropertyOfType(type, propertyName); + var propertySymbol = typeChecker.getPropertyOfType(type, propertyName); if (propertySymbol) { result.push(propertySymbol); } @@ -38522,7 +38608,7 @@ var ts; // If the reference symbol is an alias, check if what it is aliasing is one of the search // symbols. if (isImportOrExportSpecifierImportSymbol(referenceSymbol)) { - var aliasedSymbol = typeInfoResolver.getAliasedSymbol(referenceSymbol); + var aliasedSymbol = typeChecker.getAliasedSymbol(referenceSymbol); if (searchSymbols.indexOf(aliasedSymbol) >= 0) { return aliasedSymbol; } @@ -38532,12 +38618,12 @@ var ts; // compare to our searchSymbol if (isNameOfPropertyAssignment(referenceLocation)) { return ts.forEach(getPropertySymbolsFromContextualType(referenceLocation), function (contextualSymbol) { - return ts.forEach(typeInfoResolver.getRootSymbols(contextualSymbol), function (s) { return searchSymbols.indexOf(s) >= 0 ? s : undefined; }); + return ts.forEach(typeChecker.getRootSymbols(contextualSymbol), function (s) { return searchSymbols.indexOf(s) >= 0 ? s : undefined; }); }); } // Unwrap symbols to get to the root (e.g. transient symbols as a result of widening) // Or a union property, use its underlying unioned symbols - return ts.forEach(typeInfoResolver.getRootSymbols(referenceSymbol), function (rootSymbol) { + return ts.forEach(typeChecker.getRootSymbols(referenceSymbol), function (rootSymbol) { // if it is in the list, then we are done if (searchSymbols.indexOf(rootSymbol) >= 0) { return rootSymbol; @@ -38545,9 +38631,9 @@ var ts; // Finally, try all properties with the same name in any type the containing type extended or implemented, and // see if any is in the list if (rootSymbol.parent && rootSymbol.parent.flags & (32 /* Class */ | 64 /* Interface */)) { - var result_2 = []; - getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getName(), result_2); - return ts.forEach(result_2, function (s) { return searchSymbols.indexOf(s) >= 0 ? s : undefined; }); + var result_3 = []; + getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getName(), result_3); + return ts.forEach(result_3, function (s) { return searchSymbols.indexOf(s) >= 0 ? s : undefined; }); } return undefined; }); @@ -38555,29 +38641,29 @@ var ts; function getPropertySymbolsFromContextualType(node) { if (isNameOfPropertyAssignment(node)) { var objectLiteral = node.parent.parent; - var contextualType = typeInfoResolver.getContextualType(objectLiteral); - var name_24 = node.text; + var contextualType = typeChecker.getContextualType(objectLiteral); + var name_25 = node.text; if (contextualType) { if (contextualType.flags & 16384 /* Union */) { // This is a union type, first see if the property we are looking for is a union property (i.e. exists in all types) // if not, search the constituent types for the property - var unionProperty = contextualType.getProperty(name_24); + var unionProperty = contextualType.getProperty(name_25); if (unionProperty) { return [unionProperty]; } else { - var result_3 = []; + var result_4 = []; ts.forEach(contextualType.types, function (t) { - var symbol = t.getProperty(name_24); + var symbol = t.getProperty(name_25); if (symbol) { - result_3.push(symbol); + result_4.push(symbol); } }); - return result_3; + return result_4; } } else { - var symbol_1 = contextualType.getProperty(name_24); + var symbol_1 = contextualType.getProperty(name_25); if (symbol_1) { return [symbol_1]; } @@ -38742,7 +38828,7 @@ var ts; } if (!isLastClause && root.parent.kind === 177 /* HeritageClauseElement */ && root.parent.parent.kind === 222 /* HeritageClause */) { var decl = root.parent.parent.parent; - return (decl.kind === 201 /* ClassDeclaration */ && root.parent.parent.token === 103 /* ImplementsKeyword */) || + return (decl.kind === 201 /* ClassDeclaration */ && root.parent.parent.token === 102 /* ImplementsKeyword */) || (decl.kind === 202 /* InterfaceDeclaration */ && root.parent.parent.token === 79 /* ExtendsKeyword */); } return false; @@ -38803,7 +38889,7 @@ var ts; function getSignatureHelpItems(fileName, position) { synchronizeHostData(); var sourceFile = getValidSourceFile(fileName); - return ts.SignatureHelp.getSignatureHelpItems(sourceFile, position, typeInfoResolver, cancellationToken); + return ts.SignatureHelp.getSignatureHelpItems(program, sourceFile, position, cancellationToken); } /// Syntactic features function getSourceFile(fileName) { @@ -38870,6 +38956,7 @@ var ts; function getSemanticClassifications(fileName, span) { synchronizeHostData(); var sourceFile = getValidSourceFile(fileName); + var typeChecker = program.getTypeChecker(); var result = []; processNode(sourceFile); return result; @@ -38915,7 +39002,7 @@ var ts; // Only walk into nodes that intersect the requested span. if (node && ts.textSpanIntersectsWith(span, node.getStart(), node.getWidth())) { if (node.kind === 65 /* Identifier */ && node.getWidth() > 0) { - var symbol = typeInfoResolver.getSymbolAtLocation(node); + var symbol = typeChecker.getSymbolAtLocation(node); if (symbol) { var type = classifySymbol(symbol, getMeaningFromLocation(node)); if (type) { @@ -39327,10 +39414,11 @@ var ts; function getRenameInfo(fileName, position) { synchronizeHostData(); var sourceFile = getValidSourceFile(fileName); + var typeChecker = program.getTypeChecker(); var node = ts.getTouchingWord(sourceFile, position); // Can only rename an identifier. if (node && node.kind === 65 /* Identifier */) { - var symbol = typeInfoResolver.getSymbolAtLocation(node); + var symbol = typeChecker.getSymbolAtLocation(node); // Only allow a symbol to be renamed if it actually has at least one declaration. if (symbol) { var declarations = symbol.getDeclarations(); @@ -39340,19 +39428,19 @@ var ts; if (defaultLibFileName) { for (var _i = 0; _i < declarations.length; _i++) { var current = declarations[_i]; - var sourceFile_1 = current.getSourceFile(); - if (sourceFile_1 && getCanonicalFileName(ts.normalizePath(sourceFile_1.fileName)) === getCanonicalFileName(ts.normalizePath(defaultLibFileName))) { + var sourceFile_2 = current.getSourceFile(); + if (sourceFile_2 && getCanonicalFileName(ts.normalizePath(sourceFile_2.fileName)) === getCanonicalFileName(ts.normalizePath(defaultLibFileName))) { return getRenameInfoError(ts.getLocaleSpecificMessage(ts.Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library.key)); } } } - var kind = getSymbolKind(symbol, typeInfoResolver, node); + var kind = getSymbolKind(symbol, node); if (kind) { return { canRename: true, localizedErrorMessage: undefined, displayName: symbol.name, - fullDisplayName: typeInfoResolver.getFullyQualifiedName(symbol), + fullDisplayName: typeChecker.getFullyQualifiedName(symbol), kind: kind, kindModifiers: getSymbolModifiers(symbol), triggerSpan: ts.createTextSpan(node.getStart(), node.getWidth()) @@ -39497,7 +39585,7 @@ var ts; if (keyword2 === 116 /* GetKeyword */ || keyword2 === 120 /* SetKeyword */ || keyword2 === 114 /* ConstructorKeyword */ || - keyword2 === 110 /* StaticKeyword */) { + keyword2 === 109 /* StaticKeyword */) { // Allow things like "public get", "public constructor" and "public static". // These are all legal. return true; diff --git a/bin/typescriptServices.d.ts b/bin/typescriptServices.d.ts index 9e9df4fdc784d..8903e33391b40 100644 --- a/bin/typescriptServices.d.ts +++ b/bin/typescriptServices.d.ts @@ -124,16 +124,16 @@ declare module ts { VoidKeyword = 99, WhileKeyword = 100, WithKeyword = 101, - AsKeyword = 102, - ImplementsKeyword = 103, - InterfaceKeyword = 104, - LetKeyword = 105, - PackageKeyword = 106, - PrivateKeyword = 107, - ProtectedKeyword = 108, - PublicKeyword = 109, - StaticKeyword = 110, - YieldKeyword = 111, + ImplementsKeyword = 102, + InterfaceKeyword = 103, + LetKeyword = 104, + PackageKeyword = 105, + PrivateKeyword = 106, + ProtectedKeyword = 107, + PublicKeyword = 108, + StaticKeyword = 109, + YieldKeyword = 110, + AsKeyword = 111, AnyKeyword = 112, BooleanKeyword = 113, ConstructorKeyword = 114, @@ -258,8 +258,8 @@ declare module ts { LastReservedWord = 101, FirstKeyword = 66, LastKeyword = 125, - FirstFutureReservedWord = 103, - LastFutureReservedWord = 111, + FirstFutureReservedWord = 102, + LastFutureReservedWord = 110, FirstTypeNode = 141, LastTypeNode = 149, FirstPunctuation = 14, @@ -1183,6 +1183,7 @@ declare module ts { function isIdentifierPart(ch: number, languageVersion: ScriptTarget): boolean; } declare module ts { + function getDefaultLibFileName(options: CompilerOptions): string; function textSpanEnd(span: TextSpan): number; function textSpanIsEmpty(span: TextSpan): boolean; function textSpanContainsPosition(span: TextSpan, position: number): boolean; @@ -1227,7 +1228,6 @@ declare module ts { function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; function getPreEmitDiagnostics(program: Program): Diagnostic[]; function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; - function getDefaultLibFileName(options: CompilerOptions): string; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; } declare module ts { @@ -1289,7 +1289,6 @@ declare module ts { getDocumentationComment(): SymbolDisplayPart[]; } interface SourceFile { - getNamedDeclarations(): Declaration[]; getLineAndCharacterOfPosition(pos: number): LineAndCharacter; getLineStarts(): number[]; getPositionOfLineAndCharacter(line: number, character: number): number; diff --git a/bin/typescriptServices.js b/bin/typescriptServices.js index 4544cc24ec174..57271ad41ac68 100644 --- a/bin/typescriptServices.js +++ b/bin/typescriptServices.js @@ -128,17 +128,17 @@ var ts; SyntaxKind[SyntaxKind["WhileKeyword"] = 100] = "WhileKeyword"; SyntaxKind[SyntaxKind["WithKeyword"] = 101] = "WithKeyword"; // Strict mode reserved words - SyntaxKind[SyntaxKind["AsKeyword"] = 102] = "AsKeyword"; - SyntaxKind[SyntaxKind["ImplementsKeyword"] = 103] = "ImplementsKeyword"; - SyntaxKind[SyntaxKind["InterfaceKeyword"] = 104] = "InterfaceKeyword"; - SyntaxKind[SyntaxKind["LetKeyword"] = 105] = "LetKeyword"; - SyntaxKind[SyntaxKind["PackageKeyword"] = 106] = "PackageKeyword"; - SyntaxKind[SyntaxKind["PrivateKeyword"] = 107] = "PrivateKeyword"; - SyntaxKind[SyntaxKind["ProtectedKeyword"] = 108] = "ProtectedKeyword"; - SyntaxKind[SyntaxKind["PublicKeyword"] = 109] = "PublicKeyword"; - SyntaxKind[SyntaxKind["StaticKeyword"] = 110] = "StaticKeyword"; - SyntaxKind[SyntaxKind["YieldKeyword"] = 111] = "YieldKeyword"; + SyntaxKind[SyntaxKind["ImplementsKeyword"] = 102] = "ImplementsKeyword"; + SyntaxKind[SyntaxKind["InterfaceKeyword"] = 103] = "InterfaceKeyword"; + SyntaxKind[SyntaxKind["LetKeyword"] = 104] = "LetKeyword"; + SyntaxKind[SyntaxKind["PackageKeyword"] = 105] = "PackageKeyword"; + SyntaxKind[SyntaxKind["PrivateKeyword"] = 106] = "PrivateKeyword"; + SyntaxKind[SyntaxKind["ProtectedKeyword"] = 107] = "ProtectedKeyword"; + SyntaxKind[SyntaxKind["PublicKeyword"] = 108] = "PublicKeyword"; + SyntaxKind[SyntaxKind["StaticKeyword"] = 109] = "StaticKeyword"; + SyntaxKind[SyntaxKind["YieldKeyword"] = 110] = "YieldKeyword"; // Contextual keywords + SyntaxKind[SyntaxKind["AsKeyword"] = 111] = "AsKeyword"; SyntaxKind[SyntaxKind["AnyKeyword"] = 112] = "AnyKeyword"; SyntaxKind[SyntaxKind["BooleanKeyword"] = 113] = "BooleanKeyword"; SyntaxKind[SyntaxKind["ConstructorKeyword"] = 114] = "ConstructorKeyword"; @@ -280,8 +280,8 @@ var ts; SyntaxKind[SyntaxKind["LastReservedWord"] = 101] = "LastReservedWord"; SyntaxKind[SyntaxKind["FirstKeyword"] = 66] = "FirstKeyword"; SyntaxKind[SyntaxKind["LastKeyword"] = 125] = "LastKeyword"; - SyntaxKind[SyntaxKind["FirstFutureReservedWord"] = 103] = "FirstFutureReservedWord"; - SyntaxKind[SyntaxKind["LastFutureReservedWord"] = 111] = "LastFutureReservedWord"; + SyntaxKind[SyntaxKind["FirstFutureReservedWord"] = 102] = "FirstFutureReservedWord"; + SyntaxKind[SyntaxKind["LastFutureReservedWord"] = 110] = "LastFutureReservedWord"; SyntaxKind[SyntaxKind["FirstTypeNode"] = 141] = "FirstTypeNode"; SyntaxKind[SyntaxKind["LastTypeNode"] = 149] = "LastTypeNode"; SyntaxKind[SyntaxKind["FirstPunctuation"] = 14] = "FirstPunctuation"; @@ -2178,7 +2178,7 @@ var ts; (function (ts) { var textToToken = { "any": 112 /* AnyKeyword */, - "as": 102 /* AsKeyword */, + "as": 111 /* AsKeyword */, "boolean": 113 /* BooleanKeyword */, "break": 66 /* BreakKeyword */, "case": 67 /* CaseKeyword */, @@ -2203,24 +2203,24 @@ var ts; "function": 83 /* FunctionKeyword */, "get": 116 /* GetKeyword */, "if": 84 /* IfKeyword */, - "implements": 103 /* ImplementsKeyword */, + "implements": 102 /* ImplementsKeyword */, "import": 85 /* ImportKeyword */, "in": 86 /* InKeyword */, "instanceof": 87 /* InstanceOfKeyword */, - "interface": 104 /* InterfaceKeyword */, - "let": 105 /* LetKeyword */, + "interface": 103 /* InterfaceKeyword */, + "let": 104 /* LetKeyword */, "module": 117 /* ModuleKeyword */, "new": 88 /* NewKeyword */, "null": 89 /* NullKeyword */, "number": 119 /* NumberKeyword */, - "package": 106 /* PackageKeyword */, - "private": 107 /* PrivateKeyword */, - "protected": 108 /* ProtectedKeyword */, - "public": 109 /* PublicKeyword */, + "package": 105 /* PackageKeyword */, + "private": 106 /* PrivateKeyword */, + "protected": 107 /* ProtectedKeyword */, + "public": 108 /* PublicKeyword */, "require": 118 /* RequireKeyword */, "return": 90 /* ReturnKeyword */, "set": 120 /* SetKeyword */, - "static": 110 /* StaticKeyword */, + "static": 109 /* StaticKeyword */, "string": 121 /* StringKeyword */, "super": 91 /* SuperKeyword */, "switch": 92 /* SwitchKeyword */, @@ -2235,7 +2235,7 @@ var ts; "void": 99 /* VoidKeyword */, "while": 100 /* WhileKeyword */, "with": 101 /* WithKeyword */, - "yield": 111 /* YieldKeyword */, + "yield": 110 /* YieldKeyword */, "of": 125 /* OfKeyword */, "{": 14 /* OpenBraceToken */, "}": 15 /* CloseBraceToken */, @@ -5027,7 +5027,7 @@ var ts; } ts.getClassExtendsHeritageClauseElement = getClassExtendsHeritageClauseElement; function getClassImplementsHeritageClauseElements(node) { - var heritageClause = getHeritageClause(node.heritageClauses, 103 /* ImplementsKeyword */); + var heritageClause = getHeritageClause(node.heritageClauses, 102 /* ImplementsKeyword */); return heritageClause ? heritageClause.types : undefined; } ts.getClassImplementsHeritageClauseElements = getClassImplementsHeritageClauseElements; @@ -5157,10 +5157,10 @@ var ts; ts.isESSymbolIdentifier = isESSymbolIdentifier; function isModifier(token) { switch (token) { - case 109 /* PublicKeyword */: - case 107 /* PrivateKeyword */: - case 108 /* ProtectedKeyword */: - case 110 /* StaticKeyword */: + case 108 /* PublicKeyword */: + case 106 /* PrivateKeyword */: + case 107 /* ProtectedKeyword */: + case 109 /* StaticKeyword */: case 78 /* ExportKeyword */: case 115 /* DeclareKeyword */: case 70 /* ConstKeyword */: @@ -5609,6 +5609,10 @@ var ts; })(ts || (ts = {})); var ts; (function (ts) { + function getDefaultLibFileName(options) { + return options.target === 2 /* ES6 */ ? "lib.es6.d.ts" : "lib.d.ts"; + } + ts.getDefaultLibFileName = getDefaultLibFileName; function textSpanEnd(span) { return span.start + span.length; } @@ -6185,10 +6189,10 @@ var ts; ; function modifierToFlag(token) { switch (token) { - case 110 /* StaticKeyword */: return 128 /* Static */; - case 109 /* PublicKeyword */: return 16 /* Public */; - case 108 /* ProtectedKeyword */: return 64 /* Protected */; - case 107 /* PrivateKeyword */: return 32 /* Private */; + case 109 /* StaticKeyword */: return 128 /* Static */; + case 108 /* PublicKeyword */: return 16 /* Public */; + case 107 /* ProtectedKeyword */: return 64 /* Protected */; + case 106 /* PrivateKeyword */: return 32 /* Private */; case 78 /* ExportKeyword */: return 1 /* Export */; case 115 /* DeclareKeyword */: return 2 /* Ambient */; case 70 /* ConstKeyword */: return 8192 /* Const */; @@ -7004,7 +7008,7 @@ var ts; } // If we have a 'yield' keyword, and we're in the [yield] context, then 'yield' is // considered a keyword and is not an identifier. - if (token === 111 /* YieldKeyword */ && inYieldContext()) { + if (token === 110 /* YieldKeyword */ && inYieldContext()) { return false; } return token > 101 /* LastReservedWord */; @@ -7282,7 +7286,7 @@ var ts; // extends {} extends // extends {} implements var next = nextToken(); - return next === 23 /* CommaToken */ || next === 14 /* OpenBraceToken */ || next === 79 /* ExtendsKeyword */ || next === 103 /* ImplementsKeyword */; + return next === 23 /* CommaToken */ || next === 14 /* OpenBraceToken */ || next === 79 /* ExtendsKeyword */ || next === 102 /* ImplementsKeyword */; } return true; } @@ -7291,7 +7295,7 @@ var ts; return isIdentifier(); } function isHeritageClauseExtendsOrImplementsKeyword() { - if (token === 103 /* ImplementsKeyword */ || + if (token === 102 /* ImplementsKeyword */ || token === 79 /* ExtendsKeyword */) { return lookAhead(nextTokenIsStartOfExpression); } @@ -7321,12 +7325,12 @@ var ts; case 4 /* SwitchClauseStatements */: return token === 15 /* CloseBraceToken */ || token === 67 /* CaseKeyword */ || token === 73 /* DefaultKeyword */; case 8 /* HeritageClauseElement */: - return token === 14 /* OpenBraceToken */ || token === 79 /* ExtendsKeyword */ || token === 103 /* ImplementsKeyword */; + return token === 14 /* OpenBraceToken */ || token === 79 /* ExtendsKeyword */ || token === 102 /* ImplementsKeyword */; case 9 /* VariableDeclarations */: return isVariableDeclaratorListTerminator(); case 16 /* TypeParameters */: // Tokens other than '>' are here for better error recovery - return token === 25 /* GreaterThanToken */ || token === 16 /* OpenParenToken */ || token === 14 /* OpenBraceToken */ || token === 79 /* ExtendsKeyword */ || token === 103 /* ImplementsKeyword */; + return token === 25 /* GreaterThanToken */ || token === 16 /* OpenParenToken */ || token === 14 /* OpenBraceToken */ || token === 79 /* ExtendsKeyword */ || token === 102 /* ImplementsKeyword */; case 12 /* ArgumentExpressions */: // Tokens other than ')' are here for better error recovery return token === 17 /* CloseParenToken */ || token === 22 /* SemicolonToken */; @@ -8363,7 +8367,7 @@ var ts; case 38 /* PlusPlusToken */: case 39 /* MinusMinusToken */: case 24 /* LessThanToken */: - case 111 /* YieldKeyword */: + case 110 /* YieldKeyword */: // Yield always starts an expression. Either it is an identifier (in which case // it is definitely an expression). Or it's a keyword (either because we're in // a generator, or in strict mode (or both)) and it started a yield expression. @@ -8478,7 +8482,7 @@ var ts; return parseConditionalExpressionRest(expr); } function isYieldExpression() { - if (token === 111 /* YieldKeyword */) { + if (token === 110 /* YieldKeyword */) { // If we have a 'yield' keyword, and htis is a context where yield expressions are // allowed, then definitely parse out a yield expression. if (inYieldContext()) { @@ -9319,7 +9323,7 @@ var ts; parseExpected(16 /* OpenParenToken */); var initializer = undefined; if (token !== 22 /* SemicolonToken */) { - if (token === 98 /* VarKeyword */ || token === 105 /* LetKeyword */ || token === 70 /* ConstKeyword */) { + if (token === 98 /* VarKeyword */ || token === 104 /* LetKeyword */ || token === 70 /* ConstKeyword */) { initializer = parseVariableDeclarationList(true); } else { @@ -9503,7 +9507,7 @@ var ts; return !inErrorRecovery; case 14 /* OpenBraceToken */: case 98 /* VarKeyword */: - case 105 /* LetKeyword */: + case 104 /* LetKeyword */: case 83 /* FunctionKeyword */: case 69 /* ClassKeyword */: case 84 /* IfKeyword */: @@ -9529,7 +9533,7 @@ var ts; // In ES 6 'enum' is a future reserved keyword, so it should not be used as identifier var isConstEnum = lookAhead(nextTokenIsEnumKeyword); return !isConstEnum; - case 104 /* InterfaceKeyword */: + case 103 /* InterfaceKeyword */: case 117 /* ModuleKeyword */: case 77 /* EnumKeyword */: case 123 /* TypeKeyword */: @@ -9538,10 +9542,10 @@ var ts; if (isDeclarationStart()) { return false; } - case 109 /* PublicKeyword */: - case 107 /* PrivateKeyword */: - case 108 /* ProtectedKeyword */: - case 110 /* StaticKeyword */: + case 108 /* PublicKeyword */: + case 106 /* PrivateKeyword */: + case 107 /* ProtectedKeyword */: + case 109 /* StaticKeyword */: // When followed by an identifier or keyword, these do not start a statement but // might instead be following type members if (lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine)) { @@ -9600,7 +9604,7 @@ var ts; return parseTryStatement(); case 72 /* DebuggerKeyword */: return parseDebuggerStatement(); - case 105 /* LetKeyword */: + case 104 /* LetKeyword */: // If let follows identifier on the same line, it is declaration parse it as variable statement if (isLetDeclaration()) { return parseVariableStatement(scanner.getStartPos(), undefined, undefined); @@ -9635,7 +9639,7 @@ var ts; return undefined; } return parseVariableStatement(start, decorators, modifiers); - case 105 /* LetKeyword */: + case 104 /* LetKeyword */: if (!isLetDeclaration()) { return undefined; } @@ -9722,7 +9726,7 @@ var ts; switch (token) { case 98 /* VarKeyword */: break; - case 105 /* LetKeyword */: + case 104 /* LetKeyword */: node.flags |= 4096 /* Let */; break; case 70 /* ConstKeyword */: @@ -9832,10 +9836,10 @@ var ts; } function isClassMemberModifier(idToken) { switch (idToken) { - case 109 /* PublicKeyword */: - case 107 /* PrivateKeyword */: - case 108 /* ProtectedKeyword */: - case 110 /* StaticKeyword */: + case 108 /* PublicKeyword */: + case 106 /* PrivateKeyword */: + case 107 /* ProtectedKeyword */: + case 109 /* StaticKeyword */: return true; default: return false; @@ -10028,7 +10032,7 @@ var ts; return parseList(19 /* HeritageClauses */, false, parseHeritageClause); } function parseHeritageClause() { - if (token === 79 /* ExtendsKeyword */ || token === 103 /* ImplementsKeyword */) { + if (token === 79 /* ExtendsKeyword */ || token === 102 /* ImplementsKeyword */) { var node = createNode(222 /* HeritageClause */); node.token = token; nextToken(); @@ -10046,7 +10050,7 @@ var ts; return finishNode(node); } function isHeritageClause() { - return token === 79 /* ExtendsKeyword */ || token === 103 /* ImplementsKeyword */; + return token === 79 /* ExtendsKeyword */ || token === 102 /* ImplementsKeyword */; } function parseClassMembers() { return parseList(6 /* ClassMembers */, false, parseClassElement); @@ -10055,7 +10059,7 @@ var ts; var node = createNode(202 /* InterfaceDeclaration */, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(104 /* InterfaceKeyword */); + parseExpected(103 /* InterfaceKeyword */); node.name = parseIdentifier(); node.typeParameters = parseTypeParameters(); node.heritageClauses = parseHeritageClauses(false); @@ -10234,7 +10238,7 @@ var ts; // * as ImportedBinding var namespaceImport = createNode(211 /* NamespaceImport */); parseExpected(35 /* AsteriskToken */); - parseExpected(102 /* AsKeyword */); + parseExpected(111 /* AsKeyword */); namespaceImport.name = parseIdentifier(); return finishNode(namespaceImport); } @@ -10268,9 +10272,9 @@ var ts; var checkIdentifierStart = scanner.getTokenPos(); var checkIdentifierEnd = scanner.getTextPos(); var identifierName = parseIdentifierName(); - if (token === 102 /* AsKeyword */) { + if (token === 111 /* AsKeyword */) { node.propertyName = identifierName; - parseExpected(102 /* AsKeyword */); + parseExpected(111 /* AsKeyword */); checkIdentifierIsKeyword = ts.isKeyword(token) && !isIdentifier(); checkIdentifierStart = scanner.getTokenPos(); checkIdentifierEnd = scanner.getTextPos(); @@ -10327,10 +10331,10 @@ var ts; case 70 /* ConstKeyword */: case 83 /* FunctionKeyword */: return true; - case 105 /* LetKeyword */: + case 104 /* LetKeyword */: return isLetDeclaration(); case 69 /* ClassKeyword */: - case 104 /* InterfaceKeyword */: + case 103 /* InterfaceKeyword */: case 77 /* EnumKeyword */: case 123 /* TypeKeyword */: // Not true keywords so ensure an identifier follows @@ -10345,10 +10349,10 @@ var ts; // Check for export assignment or modifier on source element return lookAhead(nextTokenCanFollowExportKeyword); case 115 /* DeclareKeyword */: - case 109 /* PublicKeyword */: - case 107 /* PrivateKeyword */: - case 108 /* ProtectedKeyword */: - case 110 /* StaticKeyword */: + case 108 /* PublicKeyword */: + case 106 /* PrivateKeyword */: + case 107 /* ProtectedKeyword */: + case 109 /* StaticKeyword */: // Check for modifier on source element return lookAhead(nextTokenIsDeclarationStart); case 52 /* AtToken */: @@ -10383,7 +10387,7 @@ var ts; return isDeclarationStart(true); } function nextTokenIsAsKeyword() { - return nextToken() === 102 /* AsKeyword */; + return nextToken() === 111 /* AsKeyword */; } function parseDeclaration() { var fullStart = getNodePos(); @@ -10400,14 +10404,14 @@ var ts; } switch (token) { case 98 /* VarKeyword */: - case 105 /* LetKeyword */: + case 104 /* LetKeyword */: case 70 /* ConstKeyword */: return parseVariableStatement(fullStart, decorators, modifiers); case 83 /* FunctionKeyword */: return parseFunctionDeclaration(fullStart, decorators, modifiers); case 69 /* ClassKeyword */: return parseClassDeclaration(fullStart, decorators, modifiers); - case 104 /* InterfaceKeyword */: + case 103 /* InterfaceKeyword */: return parseInterfaceDeclaration(fullStart, decorators, modifiers); case 123 /* TypeKeyword */: return parseTypeAliasDeclaration(fullStart, decorators, modifiers); @@ -13228,15 +13232,16 @@ var ts; return result; } function getPropertiesOfType(type) { - if (type.flags & 16384 /* Union */) { - return getPropertiesOfUnionType(type); - } - return getPropertiesOfObjectType(getApparentType(type)); + type = getApparentType(type); + return type.flags & 16384 /* Union */ ? getPropertiesOfUnionType(type) : getPropertiesOfObjectType(type); } // For a type parameter, return the base constraint of the type parameter. For the string, number, // boolean, and symbol primitive types, return the corresponding object types. Otherwise return the // type itself. Note that the apparent type of a union type is the union type itself. function getApparentType(type) { + if (type.flags & 16384 /* Union */) { + type = getReducedTypeOfUnionType(type); + } if (type.flags & 512 /* TypeParameter */) { do { type = getConstraintOfTypeParameter(type); @@ -13308,28 +13313,27 @@ var ts; // necessary, maps primitive types and type parameters are to their apparent types, and augments with properties from // Object and Function as appropriate. function getPropertyOfType(type, name) { - if (type.flags & 16384 /* Union */) { - return getPropertyOfUnionType(type, name); - } - if (!(type.flags & 48128 /* ObjectType */)) { - type = getApparentType(type); - if (!(type.flags & 48128 /* ObjectType */)) { - return undefined; + type = getApparentType(type); + if (type.flags & 48128 /* ObjectType */) { + var resolved = resolveObjectOrUnionTypeMembers(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 = getPropertyOfObjectType(globalFunctionType, name); + if (symbol) { + return symbol; + } } + return getPropertyOfObjectType(globalObjectType, name); } - if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { - var symbol = getPropertyOfObjectType(globalFunctionType, name); - if (symbol) - return symbol; + if (type.flags & 16384 /* Union */) { + return getPropertyOfUnionType(type, name); } - return getPropertyOfObjectType(globalObjectType, name); + return undefined; } function getSignaturesOfObjectOrUnionType(type, kind) { if (type.flags & (48128 /* ObjectType */ | 16384 /* Union */)) { @@ -13852,6 +13856,10 @@ var ts; } } } + // The noSubtypeReduction flag is there because it isn't possible to always do subtype reduction. The flag + // is true when creating a union type from a type node and when instantiating a union type. In both of those + // cases subtype reduction has to be deferred to properly support recursive union types. For example, a + // type alias of the form "type Item = string | (() => Item)" cannot be reduced during its declaration. function getUnionType(types, noSubtypeReduction) { if (types.length === 0) { return emptyObjectType; @@ -13876,9 +13884,17 @@ var ts; if (!type) { type = unionTypes[id] = createObjectType(16384 /* Union */ | getWideningFlagsOfTypes(sortedTypes)); type.types = sortedTypes; + type.reducedType = noSubtypeReduction ? undefined : type; } return type; } + function getReducedTypeOfUnionType(type) { + // If union type was created without subtype reduction, perform the deferred reduction now + if (!type.reducedType) { + type.reducedType = getUnionType(type.types, false); + } + return type.reducedType; + } function getTypeFromUnionTypeNode(node) { var links = getNodeLinks(node); if (!links.resolvedType) { @@ -19153,7 +19169,10 @@ var ts; return checkElementTypeOfArrayOrString(inputType, errorNode); } if (isArrayLikeType(inputType)) { - return getIndexTypeOfType(inputType, 1 /* Number */); + var indexType = getIndexTypeOfType(inputType, 1 /* Number */); + if (indexType) { + return indexType; + } } error(errorNode, ts.Diagnostics.Type_0_is_not_an_array_type, typeToString(inputType)); return unknownType; @@ -21385,7 +21404,7 @@ var ts; function isReservedwordInStrictMode(node) { // Check that originalKeywordKind is less than LastFurtureReservedWord to see if an Identifier is a strict-mode reserved word return (node.parserContextFlags & 1 /* StrictMode */) && - (node.originalKeywordKind >= 103 /* FirstFutureReservedWord */ && node.originalKeywordKind <= 111 /* LastFutureReservedWord */); + (node.originalKeywordKind >= 102 /* FirstFutureReservedWord */ && node.originalKeywordKind <= 110 /* LastFutureReservedWord */); } function reportStrictModeGrammarErrorInClassDeclaration(identifier, message, arg0, arg1, arg2) { // We are checking if this name is inside class declaration or class expression (which are under class definitions inside ES6 spec.) @@ -21565,14 +21584,14 @@ var ts; for (var _i = 0, _a = node.modifiers; _i < _a.length; _i++) { var modifier = _a[_i]; switch (modifier.kind) { - case 109 /* PublicKeyword */: - case 108 /* ProtectedKeyword */: - case 107 /* PrivateKeyword */: + case 108 /* PublicKeyword */: + case 107 /* ProtectedKeyword */: + case 106 /* PrivateKeyword */: var text = void 0; - if (modifier.kind === 109 /* PublicKeyword */) { + if (modifier.kind === 108 /* PublicKeyword */) { text = "public"; } - else if (modifier.kind === 108 /* ProtectedKeyword */) { + else if (modifier.kind === 107 /* ProtectedKeyword */) { text = "protected"; lastProtected = modifier; } @@ -21591,7 +21610,7 @@ var ts; } flags |= ts.modifierToFlag(modifier.kind); break; - case 110 /* StaticKeyword */: + case 109 /* StaticKeyword */: if (flags & 128 /* Static */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "static"); } @@ -21823,7 +21842,7 @@ var ts; seenExtendsClause = true; } else { - ts.Debug.assert(heritageClause.token === 103 /* ImplementsKeyword */); + ts.Debug.assert(heritageClause.token === 102 /* ImplementsKeyword */); if (seenImplementsClause) { return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.implements_clause_already_seen); } @@ -21846,7 +21865,7 @@ var ts; seenExtendsClause = true; } else { - ts.Debug.assert(heritageClause.token === 103 /* ImplementsKeyword */); + ts.Debug.assert(heritageClause.token === 102 /* ImplementsKeyword */); return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.Interface_declaration_cannot_have_implements_clause); } // Grammar checking heritageClause inside class declaration @@ -24947,7 +24966,7 @@ var ts; emit(node.expression); } function emitYieldExpression(node) { - write(ts.tokenToString(111 /* YieldKeyword */)); + write(ts.tokenToString(110 /* YieldKeyword */)); if (node.asteriskToken) { write("*"); } @@ -25638,7 +25657,7 @@ var ts; var tokenKind = 98 /* VarKeyword */; if (decl && languageVersion >= 2 /* ES6 */) { if (ts.isLet(decl)) { - tokenKind = 105 /* LetKeyword */; + tokenKind = 104 /* LetKeyword */; } else if (ts.isConst(decl)) { tokenKind = 70 /* ConstKeyword */; @@ -25651,7 +25670,7 @@ var ts; switch (tokenKind) { case 98 /* VarKeyword */: return write("var "); - case 105 /* LetKeyword */: + case 104 /* LetKeyword */: return write("let "); case 70 /* ConstKeyword */: return write("const "); @@ -28582,7 +28601,7 @@ var ts; } return { getSourceFile: getSourceFile, - getDefaultLibFileName: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), getDefaultLibFileName(options)); }, + getDefaultLibFileName: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), ts.getDefaultLibFileName(options)); }, writeFile: writeFile, getCurrentDirectory: function () { return currentDirectory || (currentDirectory = ts.sys.getCurrentDirectory()); }, useCaseSensitiveFileNames: function () { return ts.sys.useCaseSensitiveFileNames; }, @@ -28622,10 +28641,6 @@ var ts; } } ts.flattenDiagnosticMessageText = flattenDiagnosticMessageText; - function getDefaultLibFileName(options) { - return options.target === 2 /* ES6 */ ? "lib.es6.d.ts" : "lib.d.ts"; - } - ts.getDefaultLibFileName = getDefaultLibFileName; function createProgram(rootNames, options, host) { var program; var files = []; @@ -29527,32 +29542,34 @@ var ts; // Search the declarations in all files and output matched NavigateToItem into array of NavigateToItem[] ts.forEach(program.getSourceFiles(), function (sourceFile) { cancellationToken.throwIfCancellationRequested(); - var declarations = sourceFile.getNamedDeclarations(); - for (var _i = 0; _i < declarations.length; _i++) { - var declaration = declarations[_i]; - var name = getDeclarationName(declaration); - if (name !== undefined) { + var nameToDeclarations = sourceFile.getNamedDeclarations(); + for (var name_21 in nameToDeclarations) { + var declarations = ts.getProperty(nameToDeclarations, name_21); + if (declarations) { // First do a quick check to see if the name of the declaration matches the // last portion of the (possibly) dotted name they're searching for. - var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name); + var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_21); if (!matches) { continue; } - // It was a match! If the pattern has dots in it, then also see if the - // declaration container matches as well. - if (patternMatcher.patternContainsDots) { - var containers = getContainers(declaration); - if (!containers) { - return undefined; - } - matches = patternMatcher.getMatches(containers, name); - if (!matches) { - continue; + for (var _i = 0; _i < declarations.length; _i++) { + var declaration = declarations[_i]; + // It was a match! If the pattern has dots in it, then also see if the + // declaration container matches as well. + if (patternMatcher.patternContainsDots) { + var containers = getContainers(declaration); + if (!containers) { + return undefined; + } + matches = patternMatcher.getMatches(containers, name_21); + if (!matches) { + continue; + } } + var fileName = sourceFile.fileName; + var matchKind = bestMatchKind(matches); + rawItems.push({ name: name_21, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); } - var fileName = sourceFile.fileName; - var matchKind = bestMatchKind(matches); - rawItems.push({ name: name, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); } } }); @@ -29573,25 +29590,13 @@ var ts; } return true; } - function getDeclarationName(declaration) { - var result = getTextOfIdentifierOrLiteral(declaration.name); - if (result !== undefined) { - return result; - } - if (declaration.name.kind === 127 /* ComputedPropertyName */) { - var expr = declaration.name.expression; - if (expr.kind === 155 /* PropertyAccessExpression */) { - return expr.name.text; - } - return getTextOfIdentifierOrLiteral(expr); - } - return undefined; - } function getTextOfIdentifierOrLiteral(node) { - if (node.kind === 65 /* Identifier */ || - node.kind === 8 /* StringLiteral */ || - node.kind === 7 /* NumericLiteral */) { - return node.text; + if (node) { + if (node.kind === 65 /* Identifier */ || + node.kind === 8 /* StringLiteral */ || + node.kind === 7 /* NumericLiteral */) { + return node.text; + } } return undefined; } @@ -29946,9 +29951,9 @@ var ts; case 198 /* VariableDeclaration */: case 152 /* BindingElement */: var variableDeclarationNode; - var name_21; + var name_22; if (node.kind === 152 /* BindingElement */) { - name_21 = node.name; + name_22 = node.name; variableDeclarationNode = node; // binding elements are added only for variable declarations // bubble up to the containing variable declaration @@ -29960,16 +29965,16 @@ var ts; else { ts.Debug.assert(!ts.isBindingPattern(node.name)); variableDeclarationNode = node; - name_21 = node.name; + name_22 = node.name; } if (ts.isConst(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_21), ts.ScriptElementKind.constElement); + return createItem(node, getTextOfNode(name_22), ts.ScriptElementKind.constElement); } else if (ts.isLet(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_21), ts.ScriptElementKind.letElement); + return createItem(node, getTextOfNode(name_22), ts.ScriptElementKind.letElement); } else { - return createItem(node, getTextOfNode(name_21), ts.ScriptElementKind.variableElement); + return createItem(node, getTextOfNode(name_22), ts.ScriptElementKind.variableElement); } case 135 /* Constructor */: return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); @@ -30868,7 +30873,8 @@ var ts; ArgumentListKind[ArgumentListKind["CallArguments"] = 1] = "CallArguments"; ArgumentListKind[ArgumentListKind["TaggedTemplateArguments"] = 2] = "TaggedTemplateArguments"; })(ArgumentListKind || (ArgumentListKind = {})); - function getSignatureHelpItems(sourceFile, position, typeInfoResolver, cancellationToken) { + function getSignatureHelpItems(program, sourceFile, position, cancellationToken) { + var typeChecker = program.getTypeChecker(); // Decide whether to show signature help var startingToken = ts.findTokenOnLeftOfPosition(sourceFile, position); if (!startingToken) { @@ -30883,12 +30889,54 @@ var ts; } var call = argumentInfo.invocation; var candidates = []; - var resolvedSignature = typeInfoResolver.getResolvedSignature(call, candidates); + var resolvedSignature = typeChecker.getResolvedSignature(call, candidates); cancellationToken.throwIfCancellationRequested(); if (!candidates.length) { + // We didn't have any sig help items produced by the TS compiler. If this is a JS + // file, then see if we can figure out anything better. + if (ts.isJavaScript(sourceFile.fileName)) { + return createJavaScriptSignatureHelpItems(argumentInfo); + } return undefined; } return createSignatureHelpItems(candidates, resolvedSignature, argumentInfo); + function createJavaScriptSignatureHelpItems(argumentInfo) { + if (argumentInfo.invocation.kind !== 157 /* CallExpression */) { + return undefined; + } + // See if we can find some symbol with the call expression name that has call signatures. + var callExpression = argumentInfo.invocation; + var expression = callExpression.expression; + var name = expression.kind === 65 /* Identifier */ + ? expression + : expression.kind === 155 /* PropertyAccessExpression */ + ? expression.name + : undefined; + if (!name || !name.text) { + return undefined; + } + var typeChecker = program.getTypeChecker(); + for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) { + var sourceFile_1 = _a[_i]; + var nameToDeclarations = sourceFile_1.getNamedDeclarations(); + var declarations = ts.getProperty(nameToDeclarations, name.text); + if (declarations) { + for (var _b = 0; _b < declarations.length; _b++) { + var declaration = declarations[_b]; + var symbol = declaration.symbol; + if (symbol) { + var type = typeChecker.getTypeOfSymbolAtLocation(symbol, declaration); + if (type) { + var callSignatures = type.getCallSignatures(); + if (callSignatures && callSignatures.length) { + return createSignatureHelpItems(callSignatures, callSignatures[0], argumentInfo); + } + } + } + } + } + } + } /** * Returns relevant information for the argument list and the current argument if we are * in the argument of an invocation; returns undefined otherwise. @@ -31142,8 +31190,8 @@ var ts; var isTypeParameterList = argumentListInfo.kind === 0 /* TypeArguments */; var invocation = argumentListInfo.invocation; var callTarget = ts.getInvokedExpression(invocation); - var callTargetSymbol = typeInfoResolver.getSymbolAtLocation(callTarget); - var callTargetDisplayParts = callTargetSymbol && ts.symbolToDisplayParts(typeInfoResolver, callTargetSymbol, undefined, undefined); + var callTargetSymbol = typeChecker.getSymbolAtLocation(callTarget); + var callTargetDisplayParts = callTargetSymbol && ts.symbolToDisplayParts(typeChecker, callTargetSymbol, undefined, undefined); var items = ts.map(candidates, function (candidateSignature) { var signatureHelpParameters; var prefixDisplayParts = []; @@ -31157,13 +31205,13 @@ var ts; signatureHelpParameters = typeParameters && typeParameters.length > 0 ? ts.map(typeParameters, createSignatureHelpParameterForTypeParameter) : emptyArray; suffixDisplayParts.push(ts.punctuationPart(25 /* GreaterThanToken */)); var parameterParts = ts.mapToDisplayParts(function (writer) { - return typeInfoResolver.getSymbolDisplayBuilder().buildDisplayForParametersAndDelimiters(candidateSignature.parameters, writer, invocation); + return typeChecker.getSymbolDisplayBuilder().buildDisplayForParametersAndDelimiters(candidateSignature.parameters, writer, invocation); }); suffixDisplayParts.push.apply(suffixDisplayParts, parameterParts); } else { var typeParameterParts = ts.mapToDisplayParts(function (writer) { - return typeInfoResolver.getSymbolDisplayBuilder().buildDisplayForTypeParametersAndDelimiters(candidateSignature.typeParameters, writer, invocation); + return typeChecker.getSymbolDisplayBuilder().buildDisplayForTypeParametersAndDelimiters(candidateSignature.typeParameters, writer, invocation); }); prefixDisplayParts.push.apply(prefixDisplayParts, typeParameterParts); prefixDisplayParts.push(ts.punctuationPart(16 /* OpenParenToken */)); @@ -31172,7 +31220,7 @@ var ts; suffixDisplayParts.push(ts.punctuationPart(17 /* CloseParenToken */)); } var returnTypeParts = ts.mapToDisplayParts(function (writer) { - return typeInfoResolver.getSymbolDisplayBuilder().buildReturnTypeDisplay(candidateSignature, writer, invocation); + return typeChecker.getSymbolDisplayBuilder().buildReturnTypeDisplay(candidateSignature, writer, invocation); }); suffixDisplayParts.push.apply(suffixDisplayParts, returnTypeParts); return { @@ -31201,7 +31249,7 @@ var ts; }; function createSignatureHelpParameterForParameter(parameter) { var displayParts = ts.mapToDisplayParts(function (writer) { - return typeInfoResolver.getSymbolDisplayBuilder().buildParameterDisplay(parameter, writer, invocation); + return typeChecker.getSymbolDisplayBuilder().buildParameterDisplay(parameter, writer, invocation); }); var isOptional = ts.hasQuestionToken(parameter.valueDeclaration); return { @@ -31213,7 +31261,7 @@ var ts; } function createSignatureHelpParameterForTypeParameter(typeParameter) { var displayParts = ts.mapToDisplayParts(function (writer) { - return typeInfoResolver.getSymbolDisplayBuilder().buildTypeParameterDisplay(typeParameter, writer, invocation); + return typeChecker.getSymbolDisplayBuilder().buildTypeParameterDisplay(typeParameter, writer, invocation); }); return { name: typeParameter.symbol.name, @@ -31661,9 +31709,9 @@ var ts; ts.isInsideTemplateLiteral = isInsideTemplateLiteral; function isAccessibilityModifier(kind) { switch (kind) { - case 109 /* PublicKeyword */: - case 107 /* PrivateKeyword */: - case 108 /* ProtectedKeyword */: + case 108 /* PublicKeyword */: + case 106 /* PrivateKeyword */: + case 107 /* ProtectedKeyword */: return true; } return false; @@ -31855,6 +31903,10 @@ var ts; }); } ts.signatureToDisplayParts = signatureToDisplayParts; + function isJavaScript(fileName) { + return ts.fileExtensionIs(fileName, ".js"); + } + ts.isJavaScript = isJavaScript; })(ts || (ts = {})); /// /// @@ -32376,7 +32428,7 @@ var ts; this.SpaceAfterSubtractWhenFollowedByPredecrement = new formatting.Rule(formatting.RuleDescriptor.create1(34 /* MinusToken */, 39 /* MinusMinusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); this.NoSpaceBeforeComma = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 23 /* CommaToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); this.SpaceAfterCertainKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([98 /* VarKeyword */, 94 /* ThrowKeyword */, 88 /* NewKeyword */, 74 /* DeleteKeyword */, 90 /* ReturnKeyword */, 97 /* TypeOfKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); - this.SpaceAfterLetConstInVariableDeclaration = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([105 /* LetKeyword */, 70 /* ConstKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), 2 /* Space */)); + this.SpaceAfterLetConstInVariableDeclaration = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([104 /* LetKeyword */, 70 /* ConstKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), 2 /* Space */)); this.NoSpaceBeforeOpenParenInFuncCall = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 16 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsFunctionCallOrNewContext, Rules.IsPreviousTokenNotComma), 8 /* Delete */)); this.SpaceAfterFunctionInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create3(83 /* FunctionKeyword */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2 /* Space */)); this.NoSpaceBeforeOpenParenInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 16 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsFunctionDeclContext), 8 /* Delete */)); @@ -32399,8 +32451,8 @@ var ts; // Use of module as a function call. e.g.: import m2 = module("m2"); this.NoSpaceAfterModuleImport = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([117 /* ModuleKeyword */, 118 /* RequireKeyword */]), 16 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); // Add a space around certain TypeScript keywords - this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([69 /* ClassKeyword */, 115 /* DeclareKeyword */, 77 /* EnumKeyword */, 78 /* ExportKeyword */, 79 /* ExtendsKeyword */, 116 /* GetKeyword */, 103 /* ImplementsKeyword */, 85 /* ImportKeyword */, 104 /* InterfaceKeyword */, 117 /* ModuleKeyword */, 107 /* PrivateKeyword */, 109 /* PublicKeyword */, 120 /* SetKeyword */, 110 /* StaticKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); - this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([79 /* ExtendsKeyword */, 103 /* ImplementsKeyword */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); + this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([69 /* ClassKeyword */, 115 /* DeclareKeyword */, 77 /* EnumKeyword */, 78 /* ExportKeyword */, 79 /* ExtendsKeyword */, 116 /* GetKeyword */, 102 /* ImplementsKeyword */, 85 /* ImportKeyword */, 103 /* InterfaceKeyword */, 117 /* ModuleKeyword */, 106 /* PrivateKeyword */, 108 /* PublicKeyword */, 120 /* SetKeyword */, 109 /* StaticKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); + this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([79 /* ExtendsKeyword */, 102 /* ImplementsKeyword */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); // Treat string literals in module names as identifiers, and add a space between the literal and the opening Brace braces, e.g.: module "m2" { this.SpaceAfterModuleName = new formatting.Rule(formatting.RuleDescriptor.create1(8 /* StringLiteral */, 14 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsModuleDeclContext), 2 /* Space */)); // Lambda expressions @@ -32419,7 +32471,7 @@ var ts; // decorators this.SpaceBeforeAt = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 52 /* AtToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); this.NoSpaceAfterAt = new formatting.Rule(formatting.RuleDescriptor.create3(52 /* AtToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); - this.SpaceAfterDecorator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([65 /* Identifier */, 78 /* ExportKeyword */, 73 /* DefaultKeyword */, 69 /* ClassKeyword */, 110 /* StaticKeyword */, 109 /* PublicKeyword */, 107 /* PrivateKeyword */, 108 /* ProtectedKeyword */, 116 /* GetKeyword */, 120 /* SetKeyword */, 18 /* OpenBracketToken */, 35 /* AsteriskToken */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsEndOfDecoratorContextOnSameLine), 2 /* Space */)); + this.SpaceAfterDecorator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([65 /* Identifier */, 78 /* ExportKeyword */, 73 /* DefaultKeyword */, 69 /* ClassKeyword */, 109 /* StaticKeyword */, 108 /* PublicKeyword */, 106 /* PrivateKeyword */, 107 /* ProtectedKeyword */, 116 /* GetKeyword */, 120 /* SetKeyword */, 18 /* OpenBracketToken */, 35 /* AsteriskToken */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsEndOfDecoratorContextOnSameLine), 2 /* Space */)); // These rules are higher in priority than user-configurable rules. this.HighPriorityCommonRules = [ @@ -32509,9 +32561,9 @@ var ts; } Rules.prototype.getRuleName = function (rule) { var o = this; - for (var name_22 in o) { - if (o[name_22] === rule) { - return name_22; + for (var name_23 in o) { + if (o[name_23] === rule) { + return name_23; } } throw new Error("Unknown rule"); @@ -33436,7 +33488,7 @@ var ts; } switch (node.kind) { case 201 /* ClassDeclaration */: return 69 /* ClassKeyword */; - case 202 /* InterfaceDeclaration */: return 104 /* InterfaceKeyword */; + case 202 /* InterfaceDeclaration */: return 103 /* InterfaceKeyword */; case 200 /* FunctionDeclaration */: return 83 /* FunctionKeyword */; case 204 /* EnumDeclaration */: return 204 /* EnumDeclaration */; case 136 /* GetAccessor */: return 116 /* GetKeyword */; @@ -34909,29 +34961,65 @@ var ts; return this.namedDeclarations; }; SourceFileObject.prototype.computeNamedDeclarations = function () { - var namedDeclarations = []; + var result = {}; ts.forEachChild(this, visit); - return namedDeclarations; + return result; + function addDeclaration(declaration) { + var name = getDeclarationName(declaration); + if (name) { + var declarations = getDeclarations(name); + declarations.push(declaration); + } + } + function getDeclarations(name) { + return ts.getProperty(result, name) || (result[name] = []); + } + function getDeclarationName(declaration) { + if (declaration.name) { + var result_2 = getTextOfIdentifierOrLiteral(declaration.name); + if (result_2 !== undefined) { + return result_2; + } + if (declaration.name.kind === 127 /* ComputedPropertyName */) { + var expr = declaration.name.expression; + if (expr.kind === 155 /* PropertyAccessExpression */) { + return expr.name.text; + } + return getTextOfIdentifierOrLiteral(expr); + } + } + return undefined; + } + function getTextOfIdentifierOrLiteral(node) { + if (node) { + if (node.kind === 65 /* Identifier */ || + node.kind === 8 /* StringLiteral */ || + node.kind === 7 /* NumericLiteral */) { + return node.text; + } + } + return undefined; + } function visit(node) { switch (node.kind) { case 200 /* FunctionDeclaration */: case 134 /* MethodDeclaration */: case 133 /* MethodSignature */: var functionDeclaration = node; - if (functionDeclaration.name && functionDeclaration.name.getFullWidth() > 0) { - var lastDeclaration = namedDeclarations.length > 0 ? - namedDeclarations[namedDeclarations.length - 1] : - undefined; + var declarationName = getDeclarationName(functionDeclaration); + if (declarationName) { + var declarations = getDeclarations(declarationName); + var lastDeclaration = ts.lastOrUndefined(declarations); // Check whether this declaration belongs to an "overload group". - if (lastDeclaration && functionDeclaration.symbol === lastDeclaration.symbol) { + if (lastDeclaration && functionDeclaration.parent === lastDeclaration.parent && functionDeclaration.symbol === lastDeclaration.symbol) { // Overwrite the last declaration if it was an overload // and this one is an implementation. if (functionDeclaration.body && !lastDeclaration.body) { - namedDeclarations[namedDeclarations.length - 1] = functionDeclaration; + declarations[declarations.length - 1] = functionDeclaration; } } else { - namedDeclarations.push(functionDeclaration); + declarations.push(functionDeclaration); } ts.forEachChild(node, visit); } @@ -34950,9 +35038,7 @@ var ts; case 136 /* GetAccessor */: case 137 /* SetAccessor */: case 145 /* TypeLiteral */: - if (node.name) { - namedDeclarations.push(node); - } + addDeclaration(node); // fall through case 135 /* Constructor */: case 180 /* VariableStatement */: @@ -34982,7 +35068,7 @@ var ts; case 226 /* EnumMember */: case 132 /* PropertyDeclaration */: case 131 /* PropertySignature */: - namedDeclarations.push(node); + addDeclaration(node); break; case 215 /* ExportDeclaration */: // Handle named exports case e.g.: @@ -34997,14 +35083,14 @@ var ts; // Handle default import case e.g.: // import d from "mod"; if (importClause.name) { - namedDeclarations.push(importClause); + addDeclaration(importClause); } // Handle named bindings in imports e.g.: // import * as NS from "mod"; // import {a, b as B} from "mod"; if (importClause.namedBindings) { if (importClause.namedBindings.kind === 211 /* NamespaceImport */) { - namedDeclarations.push(importClause.namedBindings); + addDeclaration(importClause.namedBindings); } else { ts.forEach(importClause.namedBindings.elements, visit); @@ -35593,7 +35679,7 @@ var ts; } else if (token === 35 /* AsteriskToken */) { token = scanner.scan(); - if (token === 102 /* AsKeyword */) { + if (token === 111 /* AsKeyword */) { token = scanner.scan(); if (token === 65 /* Identifier */) { token = scanner.scan(); @@ -35864,8 +35950,6 @@ var ts; var syntaxTreeCache = new SyntaxTreeCache(host); var ruleProvider; var program; - // this checker is used to answer all LS questions except errors - var typeInfoResolver; var useCaseSensitivefileNames = false; var cancellationToken = new CancellationTokenObject(host.getCancellationToken && host.getCancellationToken()); // Check if the localized messages json is set, otherwise query the host for it @@ -35935,7 +36019,9 @@ var ts; } } program = newProgram; - typeInfoResolver = program.getTypeChecker(); + // Make sure all the nodes in the program are both bound, and have their parent + // pointers set property. + program.getTypeChecker(); return; function getOrCreateSourceFile(fileName) { // The program is asking for this file, check first if the host can locate it. @@ -36007,15 +36093,8 @@ var ts; synchronizeHostData(); return program; } - /** - * Clean up any semantic caches that are not needed. - * The host can call this method if it wants to jettison unused memory. - * We will just dump the typeChecker and recreate a new one. this should have the effect of destroying all the semantic caches. - */ function cleanupSemanticCache() { - if (program) { - typeInfoResolver = program.getTypeChecker(); - } + // TODO: Should we jettison the program (or it's type checker) here? } function dispose() { if (program) { @@ -36029,9 +36108,6 @@ var ts; synchronizeHostData(); return program.getSyntacticDiagnostics(getValidSourceFile(fileName)); } - function isJavaScript(fileName) { - return ts.fileExtensionIs(fileName, ".js"); - } /** * getSemanticDiagnostiscs return array of Diagnostics. If '-d' is not enabled, only report semantic errors * If '-d' enabled, report both semantic and emitter errors @@ -36042,7 +36118,7 @@ var ts; // For JavaScript files, we don't want to report the normal typescript semantic errors. // Instead, we just report errors for using TypeScript-only constructs from within a // JavaScript file. - if (isJavaScript(fileName)) { + if (ts.isJavaScript(fileName)) { return getJavaScriptSemanticDiagnostics(targetSourceFile); } // Only perform the action per file regardless of '-out' flag as LanguageServiceHost is expected to call this function per file. @@ -36079,7 +36155,7 @@ var ts; break; case 222 /* HeritageClause */: var heritageClause = node; - if (heritageClause.token === 103 /* ImplementsKeyword */) { + if (heritageClause.token === 102 /* ImplementsKeyword */) { diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.implements_clauses_can_only_be_used_in_a_ts_file)); return true; } @@ -36182,14 +36258,14 @@ var ts; for (var _i = 0; _i < modifiers.length; _i++) { var modifier = modifiers[_i]; switch (modifier.kind) { - case 109 /* PublicKeyword */: - case 107 /* PrivateKeyword */: - case 108 /* ProtectedKeyword */: + case 108 /* PublicKeyword */: + case 106 /* PrivateKeyword */: + case 107 /* ProtectedKeyword */: case 115 /* DeclareKeyword */: diagnostics.push(ts.createDiagnosticForNode(modifier, ts.Diagnostics._0_can_only_be_used_in_a_ts_file, ts.tokenToString(modifier.kind))); return true; // These are all legal modifiers. - case 110 /* StaticKeyword */: + case 109 /* StaticKeyword */: case 78 /* ExportKeyword */: case 70 /* ConstKeyword */: case 73 /* DefaultKeyword */: @@ -36251,29 +36327,8 @@ var ts; } return ts.unescapeIdentifier(displayName); } - function createCompletionEntry(symbol, typeChecker, location) { - // Try to get a valid display name for this symbol, if we could not find one, then ignore it. - // We would like to only show things that can be added after a dot, so for instance numeric properties can - // not be accessed with a dot (a.1 <- invalid) - var displayName = getCompletionEntryDisplayNameForSymbol(symbol, program.getCompilerOptions().target, true); - if (!displayName) { - return undefined; - } - // TODO(drosen): Right now we just permit *all* semantic meanings when calling - // 'getSymbolKind' which is permissible given that it is backwards compatible; but - // really we should consider passing the meaning for the node so that we don't report - // that a suggestion for a value is an interface. We COULD also just do what - // 'getSymbolModifiers' does, which is to use the first declaration. - // Use a 'sortText' of 0' so that all symbol completion entries come before any other - // entries (like JavaScript identifier entries). - return { - name: displayName, - kind: getSymbolKind(symbol, typeChecker, location), - kindModifiers: getSymbolModifiers(symbol), - sortText: "0" - }; - } function getCompletionData(fileName, position) { + var typeChecker = program.getTypeChecker(); var syntacticStart = new Date().getTime(); var sourceFile = getValidSourceFile(fileName); var start = new Date().getTime(); @@ -36342,26 +36397,26 @@ var ts; isMemberCompletion = true; isNewIdentifierLocation = false; if (node.kind === 65 /* Identifier */ || node.kind === 126 /* QualifiedName */ || node.kind === 155 /* PropertyAccessExpression */) { - var symbol = typeInfoResolver.getSymbolAtLocation(node); + var symbol = typeChecker.getSymbolAtLocation(node); // This is an alias, follow what it aliases if (symbol && symbol.flags & 8388608 /* Alias */) { - symbol = typeInfoResolver.getAliasedSymbol(symbol); + symbol = typeChecker.getAliasedSymbol(symbol); } if (symbol && symbol.flags & 1952 /* HasExports */) { // Extract module or enum members - var exportedSymbols = typeInfoResolver.getExportsOfModule(symbol); + var exportedSymbols = typeChecker.getExportsOfModule(symbol); ts.forEach(exportedSymbols, function (symbol) { - if (typeInfoResolver.isValidPropertyAccess((node.parent), symbol.name)) { + if (typeChecker.isValidPropertyAccess((node.parent), symbol.name)) { symbols.push(symbol); } }); } } - var type = typeInfoResolver.getTypeAtLocation(node); + var type = typeChecker.getTypeAtLocation(node); if (type) { // Filter private properties ts.forEach(type.getApparentProperties(), function (symbol) { - if (typeInfoResolver.isValidPropertyAccess((node.parent), symbol.name)) { + if (typeChecker.isValidPropertyAccess((node.parent), symbol.name)) { symbols.push(symbol); } }); @@ -36373,11 +36428,11 @@ var ts; // Object literal expression, look up possible property names from contextual type isMemberCompletion = true; isNewIdentifierLocation = true; - var contextualType = typeInfoResolver.getContextualType(containingObjectLiteral); + var contextualType = typeChecker.getContextualType(containingObjectLiteral); if (!contextualType) { return false; } - var contextualTypeMembers = typeInfoResolver.getPropertiesOfType(contextualType); + var contextualTypeMembers = typeChecker.getPropertiesOfType(contextualType); if (contextualTypeMembers && contextualTypeMembers.length > 0) { // Add filtered items to the completion list symbols = filterContextualMembersList(contextualTypeMembers, containingObjectLiteral.properties); @@ -36393,9 +36448,9 @@ var ts; ts.Debug.assert(importDeclaration !== undefined); var exports; if (importDeclaration.moduleSpecifier) { - var moduleSpecifierSymbol = typeInfoResolver.getSymbolAtLocation(importDeclaration.moduleSpecifier); + var moduleSpecifierSymbol = typeChecker.getSymbolAtLocation(importDeclaration.moduleSpecifier); if (moduleSpecifierSymbol) { - exports = typeInfoResolver.getExportsOfModule(moduleSpecifierSymbol); + exports = typeChecker.getExportsOfModule(moduleSpecifierSymbol); } } //let exports = typeInfoResolver.getExportsOfImportDeclaration(importDeclaration); @@ -36440,7 +36495,7 @@ var ts; var scopeNode = getScopeNode(contextToken, adjustedPosition, sourceFile) || sourceFile; /// TODO filter meaning based on the current context var symbolMeanings = 793056 /* Type */ | 107455 /* Value */ | 1536 /* Namespace */ | 8388608 /* Alias */; - symbols = typeInfoResolver.getSymbolsInScope(scopeNode, symbolMeanings); + symbols = typeChecker.getSymbolsInScope(scopeNode, symbolMeanings); } return true; } @@ -36503,9 +36558,9 @@ var ts; return containingNodeKind === 171 /* TemplateExpression */; // `aa ${| case 12 /* TemplateMiddle */: return containingNodeKind === 176 /* TemplateSpan */; // `aa ${10} dd ${| - case 109 /* PublicKeyword */: - case 107 /* PrivateKeyword */: - case 108 /* ProtectedKeyword */: + case 108 /* PublicKeyword */: + case 106 /* PrivateKeyword */: + case 107 /* ProtectedKeyword */: return containingNodeKind === 132 /* PropertyDeclaration */; // class A{ public | } // Previous token may have been a keyword that was converted to an identifier. @@ -36595,6 +36650,7 @@ var ts; containingNodeKind === 150 /* ObjectBindingPattern */; // function func({ x| case 22 /* SemicolonToken */: return containingNodeKind === 131 /* PropertySignature */ && + previousToken.parent && previousToken.parent.parent && (previousToken.parent.parent.kind === 202 /* InterfaceDeclaration */ || previousToken.parent.parent.kind === 145 /* TypeLiteral */); // let x : { a; | case 24 /* LessThanToken */: @@ -36602,27 +36658,28 @@ var ts; containingNodeKind === 200 /* FunctionDeclaration */ || containingNodeKind === 202 /* InterfaceDeclaration */ || isFunction(containingNodeKind); - case 110 /* StaticKeyword */: + case 109 /* StaticKeyword */: return containingNodeKind === 132 /* PropertyDeclaration */; case 21 /* DotDotDotToken */: return containingNodeKind === 129 /* Parameter */ || containingNodeKind === 135 /* Constructor */ || - (previousToken.parent.parent.kind === 151 /* ArrayBindingPattern */); // var [ ...z| - case 109 /* PublicKeyword */: - case 107 /* PrivateKeyword */: - case 108 /* ProtectedKeyword */: + (previousToken.parent && previousToken.parent.parent && + previousToken.parent.parent.kind === 151 /* ArrayBindingPattern */); // var [ ...z| + case 108 /* PublicKeyword */: + case 106 /* PrivateKeyword */: + case 107 /* ProtectedKeyword */: return containingNodeKind === 129 /* Parameter */; case 69 /* ClassKeyword */: case 77 /* EnumKeyword */: - case 104 /* InterfaceKeyword */: + case 103 /* InterfaceKeyword */: case 83 /* FunctionKeyword */: case 98 /* VarKeyword */: case 116 /* GetKeyword */: case 120 /* SetKeyword */: case 85 /* ImportKeyword */: - case 105 /* LetKeyword */: + case 104 /* LetKeyword */: case 70 /* ConstKeyword */: - case 111 /* YieldKeyword */: + case 110 /* YieldKeyword */: return true; } // Previous token may have been a keyword that was converted to an identifier. @@ -36699,7 +36756,7 @@ var ts; } var symbols = completionData.symbols, isMemberCompletion = completionData.isMemberCompletion, isNewIdentifierLocation = completionData.isNewIdentifierLocation, location = completionData.location, isRightOfDot = completionData.isRightOfDot; var entries; - if (isRightOfDot && isJavaScript(fileName)) { + if (isRightOfDot && ts.isJavaScript(fileName)) { entries = getCompletionEntriesFromSymbols(symbols); ts.addRange(entries, getJavaScriptCompletionEntries()); } @@ -36721,10 +36778,10 @@ var ts; for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) { var sourceFile = _a[_i]; var nameTable = getNameTable(sourceFile); - for (var name_23 in nameTable) { - if (!allNames[name_23]) { - allNames[name_23] = name_23; - var displayName = getCompletionEntryDisplayName(name_23, target, true); + for (var name_24 in nameTable) { + if (!allNames[name_24]) { + allNames[name_24] = name_24; + var displayName = getCompletionEntryDisplayName(name_24, target, true); if (displayName) { var entry = { name: displayName, @@ -36739,6 +36796,28 @@ var ts; } return entries; } + function createCompletionEntry(symbol, location) { + // Try to get a valid display name for this symbol, if we could not find one, then ignore it. + // We would like to only show things that can be added after a dot, so for instance numeric properties can + // not be accessed with a dot (a.1 <- invalid) + var displayName = getCompletionEntryDisplayNameForSymbol(symbol, program.getCompilerOptions().target, true); + if (!displayName) { + return undefined; + } + // TODO(drosen): Right now we just permit *all* semantic meanings when calling + // 'getSymbolKind' which is permissible given that it is backwards compatible; but + // really we should consider passing the meaning for the node so that we don't report + // that a suggestion for a value is an interface. We COULD also just do what + // 'getSymbolModifiers' does, which is to use the first declaration. + // Use a 'sortText' of 0' so that all symbol completion entries come before any other + // entries (like JavaScript identifier entries). + return { + name: displayName, + kind: getSymbolKind(symbol, location), + kindModifiers: getSymbolModifiers(symbol), + sortText: "0" + }; + } function getCompletionEntriesFromSymbols(symbols) { var start = new Date().getTime(); var entries = []; @@ -36746,7 +36825,7 @@ var ts; var nameToSymbol = {}; for (var _i = 0; _i < symbols.length; _i++) { var symbol = symbols[_i]; - var entry = createCompletionEntry(symbol, typeInfoResolver, location); + var entry = createCompletionEntry(symbol, location); if (entry) { var id = ts.escapeIdentifier(entry.name); if (!ts.lookUp(nameToSymbol, id)) { @@ -36773,7 +36852,7 @@ var ts; // completion entry. var symbol = ts.forEach(symbols, function (s) { return getCompletionEntryDisplayNameForSymbol(s, target, false) === entryName ? s : undefined; }); if (symbol) { - var displayPartsDocumentationsAndSymbolKind = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, getValidSourceFile(fileName), location_2, typeInfoResolver, location_2, 7 /* All */); + var displayPartsDocumentationsAndSymbolKind = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, getValidSourceFile(fileName), location_2, location_2, 7 /* All */); return { name: entryName, kind: displayPartsDocumentationsAndSymbolKind.symbolKind, @@ -36797,7 +36876,7 @@ var ts; return undefined; } // TODO(drosen): use contextual SemanticMeaning. - function getSymbolKind(symbol, typeResolver, location) { + function getSymbolKind(symbol, location) { var flags = symbol.getFlags(); if (flags & 32 /* Class */) return ScriptElementKind.classElement; @@ -36809,7 +36888,7 @@ var ts; return ScriptElementKind.interfaceElement; if (flags & 262144 /* TypeParameter */) return ScriptElementKind.typeParameterElement; - var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, flags, typeResolver, location); + var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, flags, location); if (result === ScriptElementKind.unknown) { if (flags & 262144 /* TypeParameter */) return ScriptElementKind.typeParameterElement; @@ -36822,11 +36901,12 @@ var ts; } return result; } - function getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, flags, typeResolver, location) { - if (typeResolver.isUndefinedSymbol(symbol)) { + function getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, flags, location) { + var typeChecker = program.getTypeChecker(); + if (typeChecker.isUndefinedSymbol(symbol)) { return ScriptElementKind.variableElement; } - if (typeResolver.isArgumentsSymbol(symbol)) { + if (typeChecker.isArgumentsSymbol(symbol)) { return ScriptElementKind.localVariableElement; } if (flags & 3 /* Variable */) { @@ -36854,7 +36934,7 @@ var ts; if (flags & 4 /* Property */) { if (flags & 268435456 /* UnionProperty */) { // If union property is result of union of non method (property/accessors/variables), it is labeled as property - var unionPropertyKind = ts.forEach(typeInfoResolver.getRootSymbols(symbol), function (rootSymbol) { + var unionPropertyKind = ts.forEach(typeChecker.getRootSymbols(symbol), function (rootSymbol) { var rootSymbolFlags = rootSymbol.getFlags(); if (rootSymbolFlags & (98308 /* PropertyOrAccessor */ | 3 /* Variable */)) { return ScriptElementKind.memberVariableElement; @@ -36864,7 +36944,7 @@ var ts; if (!unionPropertyKind) { // If this was union of all methods, //make sure it has call signatures before we can label it as method - var typeOfUnionProperty = typeInfoResolver.getTypeOfSymbolAtLocation(symbol, location); + var typeOfUnionProperty = typeChecker.getTypeOfSymbolAtLocation(symbol, location); if (typeOfUnionProperty.getCallSignatures().length) { return ScriptElementKind.memberFunctionElement; } @@ -36897,14 +36977,14 @@ var ts; ? ts.getNodeModifiers(symbol.declarations[0]) : ScriptElementKindModifier.none; } - function getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, sourceFile, enclosingDeclaration, typeResolver, location, - // TODO(drosen): Currently completion entry details passes the SemanticMeaning.All instead of using semanticMeaning of location - semanticMeaning) { + // TODO(drosen): Currently completion entry details passes the SemanticMeaning.All instead of using semanticMeaning of location + function getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, sourceFile, enclosingDeclaration, location, semanticMeaning) { if (semanticMeaning === void 0) { semanticMeaning = getMeaningFromLocation(location); } + var typeChecker = program.getTypeChecker(); var displayParts = []; var documentation; var symbolFlags = symbol.flags; - var symbolKind = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, symbolFlags, typeResolver, location); + var symbolKind = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, symbolFlags, location); var hasAddedSymbolInfo; var type; // Class at constructor site need to be shown as constructor apart from property,method, vars @@ -36914,7 +36994,7 @@ var ts; symbolKind = ScriptElementKind.memberVariableElement; } var signature; - type = typeResolver.getTypeOfSymbolAtLocation(symbol, location); + type = typeChecker.getTypeOfSymbolAtLocation(symbol, location); if (type) { if (location.parent && location.parent.kind === 155 /* PropertyAccessExpression */) { var right = location.parent.name; @@ -36933,7 +37013,7 @@ var ts; } if (callExpression) { var candidateSignatures = []; - signature = typeResolver.getResolvedSignature(callExpression, candidateSignatures); + signature = typeChecker.getResolvedSignature(callExpression, candidateSignatures); if (!signature && candidateSignatures.length) { // Use the first candidate: signature = candidateSignatures[0]; @@ -36978,7 +37058,7 @@ var ts; displayParts.push(ts.spacePart()); } if (!(type.flags & 32768 /* Anonymous */)) { - displayParts.push.apply(displayParts, ts.symbolToDisplayParts(typeResolver, type.symbol, enclosingDeclaration, undefined, 1 /* WriteTypeParametersOrArguments */)); + displayParts.push.apply(displayParts, ts.symbolToDisplayParts(typeChecker, type.symbol, enclosingDeclaration, undefined, 1 /* WriteTypeParametersOrArguments */)); } addSignatureDisplayParts(signature, allSignatures, 8 /* WriteArrowStyleSignature */); break; @@ -36994,8 +37074,8 @@ var ts; // get the signature from the declaration and write it var functionDeclaration = location.parent; var allSignatures = functionDeclaration.kind === 135 /* Constructor */ ? type.getConstructSignatures() : type.getCallSignatures(); - if (!typeResolver.isImplementationOfOverload(functionDeclaration)) { - signature = typeResolver.getSignatureFromDeclaration(functionDeclaration); + if (!typeChecker.isImplementationOfOverload(functionDeclaration)) { + signature = typeChecker.getSignatureFromDeclaration(functionDeclaration); } else { signature = allSignatures[0]; @@ -37023,7 +37103,7 @@ var ts; } if ((symbolFlags & 64 /* Interface */) && (semanticMeaning & 2 /* Type */)) { addNewLineIfDisplayPartsExist(); - displayParts.push(ts.keywordPart(104 /* InterfaceKeyword */)); + displayParts.push(ts.keywordPart(103 /* InterfaceKeyword */)); displayParts.push(ts.spacePart()); addFullSymbolName(symbol); writeTypeParametersOfSymbol(symbol, sourceFile); @@ -37036,7 +37116,7 @@ var ts; displayParts.push(ts.spacePart()); displayParts.push(ts.operatorPart(53 /* EqualsToken */)); displayParts.push(ts.spacePart()); - displayParts.push.apply(displayParts, ts.typeToDisplayParts(typeResolver, typeResolver.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration)); + displayParts.push.apply(displayParts, ts.typeToDisplayParts(typeChecker, typeChecker.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration)); } if (symbolFlags & 384 /* Enum */) { addNewLineIfDisplayPartsExist(); @@ -37072,7 +37152,7 @@ var ts; else { // Method/function type parameter var signatureDeclaration = ts.getDeclarationOfKind(symbol, 128 /* TypeParameter */).parent; - var signature = typeResolver.getSignatureFromDeclaration(signatureDeclaration); + var signature = typeChecker.getSignatureFromDeclaration(signatureDeclaration); if (signatureDeclaration.kind === 139 /* ConstructSignature */) { displayParts.push(ts.keywordPart(88 /* NewKeyword */)); displayParts.push(ts.spacePart()); @@ -37080,14 +37160,14 @@ var ts; else if (signatureDeclaration.kind !== 138 /* CallSignature */ && signatureDeclaration.name) { addFullSymbolName(signatureDeclaration.symbol); } - displayParts.push.apply(displayParts, ts.signatureToDisplayParts(typeResolver, signature, sourceFile, 32 /* WriteTypeArgumentsOfSignature */)); + displayParts.push.apply(displayParts, ts.signatureToDisplayParts(typeChecker, signature, sourceFile, 32 /* WriteTypeArgumentsOfSignature */)); } } if (symbolFlags & 8 /* EnumMember */) { addPrefixForAnyFunctionOrVar(symbol, "enum member"); var declaration = symbol.declarations[0]; if (declaration.kind === 226 /* EnumMember */) { - var constantValue = typeResolver.getConstantValue(declaration); + var constantValue = typeChecker.getConstantValue(declaration); if (constantValue !== undefined) { displayParts.push(ts.spacePart()); displayParts.push(ts.operatorPart(53 /* EqualsToken */)); @@ -37114,7 +37194,7 @@ var ts; displayParts.push(ts.punctuationPart(17 /* CloseParenToken */)); } else { - var internalAliasSymbol = typeResolver.getSymbolAtLocation(importEqualsDeclaration.moduleReference); + var internalAliasSymbol = typeChecker.getSymbolAtLocation(importEqualsDeclaration.moduleReference); if (internalAliasSymbol) { displayParts.push(ts.spacePart()); displayParts.push(ts.operatorPart(53 /* EqualsToken */)); @@ -37139,12 +37219,12 @@ var ts; // If the type is type parameter, format it specially if (type.symbol && type.symbol.flags & 262144 /* TypeParameter */) { var typeParameterParts = ts.mapToDisplayParts(function (writer) { - typeResolver.getSymbolDisplayBuilder().buildTypeParameterDisplay(type, writer, enclosingDeclaration); + typeChecker.getSymbolDisplayBuilder().buildTypeParameterDisplay(type, writer, enclosingDeclaration); }); displayParts.push.apply(displayParts, typeParameterParts); } else { - displayParts.push.apply(displayParts, ts.typeToDisplayParts(typeResolver, type, enclosingDeclaration)); + displayParts.push.apply(displayParts, ts.typeToDisplayParts(typeChecker, type, enclosingDeclaration)); } } else if (symbolFlags & 16 /* Function */ || @@ -37159,7 +37239,7 @@ var ts; } } else { - symbolKind = getSymbolKind(symbol, typeResolver, location); + symbolKind = getSymbolKind(symbol, location); } } if (!documentation) { @@ -37172,7 +37252,7 @@ var ts; } } function addFullSymbolName(symbol, enclosingDeclaration) { - var fullSymbolDisplayParts = ts.symbolToDisplayParts(typeResolver, symbol, enclosingDeclaration || sourceFile, undefined, 1 /* WriteTypeParametersOrArguments */ | 2 /* UseOnlyExternalAliasing */); + var fullSymbolDisplayParts = ts.symbolToDisplayParts(typeChecker, symbol, enclosingDeclaration || sourceFile, undefined, 1 /* WriteTypeParametersOrArguments */ | 2 /* UseOnlyExternalAliasing */); displayParts.push.apply(displayParts, fullSymbolDisplayParts); } function addPrefixForAnyFunctionOrVar(symbol, symbolKind) { @@ -37200,7 +37280,7 @@ var ts; } } function addSignatureDisplayParts(signature, allSignatures, flags) { - displayParts.push.apply(displayParts, ts.signatureToDisplayParts(typeResolver, signature, enclosingDeclaration, flags | 32 /* WriteTypeArgumentsOfSignature */)); + displayParts.push.apply(displayParts, ts.signatureToDisplayParts(typeChecker, signature, enclosingDeclaration, flags | 32 /* WriteTypeArgumentsOfSignature */)); if (allSignatures.length > 1) { displayParts.push(ts.spacePart()); displayParts.push(ts.punctuationPart(16 /* OpenParenToken */)); @@ -37214,7 +37294,7 @@ var ts; } function writeTypeParametersOfSymbol(symbol, enclosingDeclaration) { var typeParameterParts = ts.mapToDisplayParts(function (writer) { - typeResolver.getSymbolDisplayBuilder().buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaration); + typeChecker.getSymbolDisplayBuilder().buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaration); }); displayParts.push.apply(displayParts, typeParameterParts); } @@ -37226,7 +37306,11 @@ var ts; if (!node) { return undefined; } - var symbol = typeInfoResolver.getSymbolAtLocation(node); + if (isLabelName(node)) { + return undefined; + } + var typeChecker = program.getTypeChecker(); + var symbol = typeChecker.getSymbolAtLocation(node); if (!symbol) { // Try getting just type at this position and show switch (node.kind) { @@ -37236,20 +37320,20 @@ var ts; case 93 /* ThisKeyword */: case 91 /* SuperKeyword */: // For the identifiers/this/super etc get the type at position - var type = typeInfoResolver.getTypeAtLocation(node); + var type = typeChecker.getTypeAtLocation(node); if (type) { return { kind: ScriptElementKind.unknown, kindModifiers: ScriptElementKindModifier.none, textSpan: ts.createTextSpan(node.getStart(), node.getWidth()), - displayParts: ts.typeToDisplayParts(typeInfoResolver, type, getContainerNode(node)), + displayParts: ts.typeToDisplayParts(typeChecker, type, getContainerNode(node)), documentation: type.symbol ? type.symbol.getDocumentationComment() : undefined }; } } return undefined; } - var displayPartsDocumentationsAndKind = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, sourceFile, getContainerNode(node), typeInfoResolver, node); + var displayPartsDocumentationsAndKind = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, sourceFile, getContainerNode(node), node); return { kind: displayPartsDocumentationsAndKind.symbolKind, kindModifiers: getSymbolModifiers(symbol), @@ -37298,7 +37382,8 @@ var ts; } return undefined; } - var symbol = typeInfoResolver.getSymbolAtLocation(node); + var typeChecker = program.getTypeChecker(); + var symbol = typeChecker.getSymbolAtLocation(node); // Could not find a symbol e.g. node is string or number keyword, // or the symbol was an internal symbol and does not have a declaration e.g. undefined symbol if (!symbol) { @@ -37311,7 +37396,7 @@ var ts; if (symbol.flags & 8388608 /* Alias */) { var declaration = symbol.declarations[0]; if (node.kind === 65 /* Identifier */ && node.parent === declaration) { - symbol = typeInfoResolver.getAliasedSymbol(symbol); + symbol = typeChecker.getAliasedSymbol(symbol); } } // Because name in short-hand property assignment has two different meanings: property name and property value, @@ -37320,22 +37405,22 @@ var ts; // is performed at the location of property access, we would like to go to definition of the property in the short-hand // assignment. This case and others are handled by the following code. if (node.parent.kind === 225 /* ShorthandPropertyAssignment */) { - var shorthandSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(symbol.valueDeclaration); + var shorthandSymbol = typeChecker.getShorthandAssignmentValueSymbol(symbol.valueDeclaration); if (!shorthandSymbol) { return []; } var shorthandDeclarations = shorthandSymbol.getDeclarations(); - var shorthandSymbolKind = getSymbolKind(shorthandSymbol, typeInfoResolver, node); - var shorthandSymbolName = typeInfoResolver.symbolToString(shorthandSymbol); - var shorthandContainerName = typeInfoResolver.symbolToString(symbol.parent, node); + var shorthandSymbolKind = getSymbolKind(shorthandSymbol, node); + var shorthandSymbolName = typeChecker.symbolToString(shorthandSymbol); + var shorthandContainerName = typeChecker.symbolToString(symbol.parent, node); return ts.map(shorthandDeclarations, function (declaration) { return createDefinitionInfo(declaration, shorthandSymbolKind, shorthandSymbolName, shorthandContainerName); }); } var result = []; var declarations = symbol.getDeclarations(); - var symbolName = typeInfoResolver.symbolToString(symbol); // Do not get scoped name, just the name of the symbol - var symbolKind = getSymbolKind(symbol, typeInfoResolver, node); + var symbolName = typeChecker.symbolToString(symbol); // Do not get scoped name, just the name of the symbol + var symbolKind = getSymbolKind(symbol, node); var containerSymbol = symbol.parent; - var containerName = containerSymbol ? typeInfoResolver.symbolToString(containerSymbol, node) : ""; + var containerName = containerSymbol ? typeChecker.symbolToString(containerSymbol, node) : ""; if (!tryAddConstructSignature(symbol, node, symbolKind, symbolName, containerName, result) && !tryAddCallSignature(symbol, node, symbolKind, symbolName, containerName, result)) { // Just add all the declarations. @@ -37390,7 +37475,7 @@ var ts; var sourceFile = getCanonicalFileName(ts.normalizeSlashes(fileName)); // Get occurrences only supports reporting occurrences for the file queried. So // filter down to that list. - results = ts.filter(results, function (r) { return r.fileName === fileName; }); + results = ts.filter(results, function (r) { return getCanonicalFileName(ts.normalizeSlashes(r.fileName)) === sourceFile; }); } return results; } @@ -37653,7 +37738,7 @@ var ts; return undefined; } } - else if (modifier === 110 /* StaticKeyword */) { + else if (modifier === 109 /* StaticKeyword */) { if (container.kind !== 201 /* ClassDeclaration */) { return undefined; } @@ -37702,13 +37787,13 @@ var ts; return ts.map(keywords, getHighlightSpanForNode); function getFlagFromModifier(modifier) { switch (modifier) { - case 109 /* PublicKeyword */: + case 108 /* PublicKeyword */: return 16 /* Public */; - case 107 /* PrivateKeyword */: + case 106 /* PrivateKeyword */: return 32 /* Private */; - case 108 /* ProtectedKeyword */: + case 107 /* ProtectedKeyword */: return 64 /* Protected */; - case 110 /* StaticKeyword */: + case 109 /* StaticKeyword */: return 128 /* Static */; case 78 /* ExportKeyword */: return 1 /* Export */; @@ -37969,6 +38054,7 @@ var ts; return getReferencedSymbolsForNodes(node, program.getSourceFiles(), findInStrings, findInComments); } function getReferencedSymbolsForNodes(node, sourceFiles, findInStrings, findInComments) { + var typeChecker = program.getTypeChecker(); // Labels if (isLabelName(node)) { if (isJumpStatementTarget(node)) { @@ -37988,7 +38074,7 @@ var ts; if (node.kind === 91 /* SuperKeyword */) { return getReferencesForSuperKeyword(node); } - var symbol = typeInfoResolver.getSymbolAtLocation(node); + var symbol = typeChecker.getSymbolAtLocation(node); // Could not find a symbol e.g. unknown identifier if (!symbol) { // Can't have references to something that we have no symbol for. @@ -38027,7 +38113,7 @@ var ts; } return result; function getDefinition(symbol) { - var info = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, node.getSourceFile(), getContainerNode(node), typeInfoResolver, node); + var info = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, node.getSourceFile(), getContainerNode(node), node); var name = ts.map(info.displayParts, function (p) { return p.text; }).join(""); var declarations = symbol.declarations; if (!declarations || declarations.length === 0) { @@ -38070,7 +38156,7 @@ var ts; if (isImportOrExportSpecifierName(location)) { return location.getText(); } - name = typeInfoResolver.symbolToString(symbol); + name = typeChecker.symbolToString(symbol); return stripQuotes(name); } function getInternedName(symbol, location, declarations) { @@ -38258,10 +38344,10 @@ var ts; if (!(getMeaningFromLocation(referenceLocation) & searchMeaning)) { return; } - var referenceSymbol = typeInfoResolver.getSymbolAtLocation(referenceLocation); + var referenceSymbol = typeChecker.getSymbolAtLocation(referenceLocation); if (referenceSymbol) { var referenceSymbolDeclaration = referenceSymbol.valueDeclaration; - var shorthandValueSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(referenceSymbolDeclaration); + var shorthandValueSymbol = typeChecker.getShorthandAssignmentValueSymbol(referenceSymbolDeclaration); var relatedSymbol = getRelatedSymbol(searchSymbols, referenceSymbol, referenceLocation); if (relatedSymbol) { var referencedSymbol = getReferencedSymbol(relatedSymbol); @@ -38450,14 +38536,14 @@ var ts; var result = [symbol]; // If the symbol is an alias, add what it alaises to the list if (isImportOrExportSpecifierImportSymbol(symbol)) { - result.push(typeInfoResolver.getAliasedSymbol(symbol)); + result.push(typeChecker.getAliasedSymbol(symbol)); } // If the location is in a context sensitive location (i.e. in an object literal) try // to get a contextual type for it, and add the property symbol from the contextual // type to the search set if (isNameOfPropertyAssignment(location)) { ts.forEach(getPropertySymbolsFromContextualType(location), function (contextualSymbol) { - result.push.apply(result, typeInfoResolver.getRootSymbols(contextualSymbol)); + result.push.apply(result, typeChecker.getRootSymbols(contextualSymbol)); }); /* Because in short-hand property assignment, location has two meaning : property name and as value of the property * When we do findAllReference at the position of the short-hand property assignment, we would want to have references to position of @@ -38470,14 +38556,14 @@ var ts; * so that when matching with potential reference symbol, both symbols from property declaration and variable declaration * will be included correctly. */ - var shorthandValueSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(location.parent); + var shorthandValueSymbol = typeChecker.getShorthandAssignmentValueSymbol(location.parent); if (shorthandValueSymbol) { result.push(shorthandValueSymbol); } } // If this is a union property, add all the symbols from all its source symbols in all unioned types. // If the symbol is an instantiation from a another symbol (e.g. widened symbol) , add the root the list - ts.forEach(typeInfoResolver.getRootSymbols(symbol), function (rootSymbol) { + ts.forEach(typeChecker.getRootSymbols(symbol), function (rootSymbol) { if (rootSymbol !== symbol) { result.push(rootSymbol); } @@ -38503,9 +38589,9 @@ var ts; return; function getPropertySymbolFromTypeReference(typeReference) { if (typeReference) { - var type = typeInfoResolver.getTypeAtLocation(typeReference); + var type = typeChecker.getTypeAtLocation(typeReference); if (type) { - var propertySymbol = typeInfoResolver.getPropertyOfType(type, propertyName); + var propertySymbol = typeChecker.getPropertyOfType(type, propertyName); if (propertySymbol) { result.push(propertySymbol); } @@ -38522,7 +38608,7 @@ var ts; // If the reference symbol is an alias, check if what it is aliasing is one of the search // symbols. if (isImportOrExportSpecifierImportSymbol(referenceSymbol)) { - var aliasedSymbol = typeInfoResolver.getAliasedSymbol(referenceSymbol); + var aliasedSymbol = typeChecker.getAliasedSymbol(referenceSymbol); if (searchSymbols.indexOf(aliasedSymbol) >= 0) { return aliasedSymbol; } @@ -38532,12 +38618,12 @@ var ts; // compare to our searchSymbol if (isNameOfPropertyAssignment(referenceLocation)) { return ts.forEach(getPropertySymbolsFromContextualType(referenceLocation), function (contextualSymbol) { - return ts.forEach(typeInfoResolver.getRootSymbols(contextualSymbol), function (s) { return searchSymbols.indexOf(s) >= 0 ? s : undefined; }); + return ts.forEach(typeChecker.getRootSymbols(contextualSymbol), function (s) { return searchSymbols.indexOf(s) >= 0 ? s : undefined; }); }); } // Unwrap symbols to get to the root (e.g. transient symbols as a result of widening) // Or a union property, use its underlying unioned symbols - return ts.forEach(typeInfoResolver.getRootSymbols(referenceSymbol), function (rootSymbol) { + return ts.forEach(typeChecker.getRootSymbols(referenceSymbol), function (rootSymbol) { // if it is in the list, then we are done if (searchSymbols.indexOf(rootSymbol) >= 0) { return rootSymbol; @@ -38545,9 +38631,9 @@ var ts; // Finally, try all properties with the same name in any type the containing type extended or implemented, and // see if any is in the list if (rootSymbol.parent && rootSymbol.parent.flags & (32 /* Class */ | 64 /* Interface */)) { - var result_2 = []; - getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getName(), result_2); - return ts.forEach(result_2, function (s) { return searchSymbols.indexOf(s) >= 0 ? s : undefined; }); + var result_3 = []; + getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getName(), result_3); + return ts.forEach(result_3, function (s) { return searchSymbols.indexOf(s) >= 0 ? s : undefined; }); } return undefined; }); @@ -38555,29 +38641,29 @@ var ts; function getPropertySymbolsFromContextualType(node) { if (isNameOfPropertyAssignment(node)) { var objectLiteral = node.parent.parent; - var contextualType = typeInfoResolver.getContextualType(objectLiteral); - var name_24 = node.text; + var contextualType = typeChecker.getContextualType(objectLiteral); + var name_25 = node.text; if (contextualType) { if (contextualType.flags & 16384 /* Union */) { // This is a union type, first see if the property we are looking for is a union property (i.e. exists in all types) // if not, search the constituent types for the property - var unionProperty = contextualType.getProperty(name_24); + var unionProperty = contextualType.getProperty(name_25); if (unionProperty) { return [unionProperty]; } else { - var result_3 = []; + var result_4 = []; ts.forEach(contextualType.types, function (t) { - var symbol = t.getProperty(name_24); + var symbol = t.getProperty(name_25); if (symbol) { - result_3.push(symbol); + result_4.push(symbol); } }); - return result_3; + return result_4; } } else { - var symbol_1 = contextualType.getProperty(name_24); + var symbol_1 = contextualType.getProperty(name_25); if (symbol_1) { return [symbol_1]; } @@ -38742,7 +38828,7 @@ var ts; } if (!isLastClause && root.parent.kind === 177 /* HeritageClauseElement */ && root.parent.parent.kind === 222 /* HeritageClause */) { var decl = root.parent.parent.parent; - return (decl.kind === 201 /* ClassDeclaration */ && root.parent.parent.token === 103 /* ImplementsKeyword */) || + return (decl.kind === 201 /* ClassDeclaration */ && root.parent.parent.token === 102 /* ImplementsKeyword */) || (decl.kind === 202 /* InterfaceDeclaration */ && root.parent.parent.token === 79 /* ExtendsKeyword */); } return false; @@ -38803,7 +38889,7 @@ var ts; function getSignatureHelpItems(fileName, position) { synchronizeHostData(); var sourceFile = getValidSourceFile(fileName); - return ts.SignatureHelp.getSignatureHelpItems(sourceFile, position, typeInfoResolver, cancellationToken); + return ts.SignatureHelp.getSignatureHelpItems(program, sourceFile, position, cancellationToken); } /// Syntactic features function getSourceFile(fileName) { @@ -38870,6 +38956,7 @@ var ts; function getSemanticClassifications(fileName, span) { synchronizeHostData(); var sourceFile = getValidSourceFile(fileName); + var typeChecker = program.getTypeChecker(); var result = []; processNode(sourceFile); return result; @@ -38915,7 +39002,7 @@ var ts; // Only walk into nodes that intersect the requested span. if (node && ts.textSpanIntersectsWith(span, node.getStart(), node.getWidth())) { if (node.kind === 65 /* Identifier */ && node.getWidth() > 0) { - var symbol = typeInfoResolver.getSymbolAtLocation(node); + var symbol = typeChecker.getSymbolAtLocation(node); if (symbol) { var type = classifySymbol(symbol, getMeaningFromLocation(node)); if (type) { @@ -39327,10 +39414,11 @@ var ts; function getRenameInfo(fileName, position) { synchronizeHostData(); var sourceFile = getValidSourceFile(fileName); + var typeChecker = program.getTypeChecker(); var node = ts.getTouchingWord(sourceFile, position); // Can only rename an identifier. if (node && node.kind === 65 /* Identifier */) { - var symbol = typeInfoResolver.getSymbolAtLocation(node); + var symbol = typeChecker.getSymbolAtLocation(node); // Only allow a symbol to be renamed if it actually has at least one declaration. if (symbol) { var declarations = symbol.getDeclarations(); @@ -39340,19 +39428,19 @@ var ts; if (defaultLibFileName) { for (var _i = 0; _i < declarations.length; _i++) { var current = declarations[_i]; - var sourceFile_1 = current.getSourceFile(); - if (sourceFile_1 && getCanonicalFileName(ts.normalizePath(sourceFile_1.fileName)) === getCanonicalFileName(ts.normalizePath(defaultLibFileName))) { + var sourceFile_2 = current.getSourceFile(); + if (sourceFile_2 && getCanonicalFileName(ts.normalizePath(sourceFile_2.fileName)) === getCanonicalFileName(ts.normalizePath(defaultLibFileName))) { return getRenameInfoError(ts.getLocaleSpecificMessage(ts.Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library.key)); } } } - var kind = getSymbolKind(symbol, typeInfoResolver, node); + var kind = getSymbolKind(symbol, node); if (kind) { return { canRename: true, localizedErrorMessage: undefined, displayName: symbol.name, - fullDisplayName: typeInfoResolver.getFullyQualifiedName(symbol), + fullDisplayName: typeChecker.getFullyQualifiedName(symbol), kind: kind, kindModifiers: getSymbolModifiers(symbol), triggerSpan: ts.createTextSpan(node.getStart(), node.getWidth()) @@ -39497,7 +39585,7 @@ var ts; if (keyword2 === 116 /* GetKeyword */ || keyword2 === 120 /* SetKeyword */ || keyword2 === 114 /* ConstructorKeyword */ || - keyword2 === 110 /* StaticKeyword */) { + keyword2 === 109 /* StaticKeyword */) { // Allow things like "public get", "public constructor" and "public static". // These are all legal. return true;