From 785c281fd6ce68f6ae5a97bb2cd6b62be6494723 Mon Sep 17 00:00:00 2001 From: Chuck Jazdzewski Date: Fri, 21 Apr 2017 15:20:55 -0700 Subject: [PATCH 01/23] Allow plugins to provide a list of external files. The list of the plugin's external files and request made to a file in the list will be routed to an instance of the plugin. --- src/server/project.ts | 27 +++++++++++++++++++++++---- src/server/utilities.ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/server/project.ts b/src/server/project.ts index 09c8d74c8c7..df51f8aefcc 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -112,6 +112,7 @@ namespace ts.server { private rootFiles: ScriptInfo[] = []; private rootFilesMap: FileMap = createFileMap(); private program: ts.Program; + private externalFiles: SortedReadonlyArray; private cachedUnresolvedImportsPerFile = new UnresolvedImportsMap(); private lastCachedUnresolvedImportsList: SortedReadonlyArray; @@ -267,8 +268,8 @@ namespace ts.server { abstract getProjectRootPath(): string | undefined; abstract getTypeAcquisition(): TypeAcquisition; - getExternalFiles(): string[] { - return []; + getExternalFiles(): SortedReadonlyArray { + return emptyArray as SortedReadonlyArray; } getSourceFile(path: Path) { @@ -567,6 +568,24 @@ namespace ts.server { } } } + + const oldExternalFiles = this.externalFiles || emptyArray as SortedReadonlyArray; + this.externalFiles = this.getExternalFiles(); + enumerateInsertsAndDeletes(this.externalFiles, oldExternalFiles, + // Ensure a ScriptInfo is created for new external files. This is performed indirectly + // by the LSHost for files in the program when the program is retrieved above but + // the program doesn't contain external files so this must be done explicitly. + inserted => { + const scriptInfo = this.projectService.getOrCreateScriptInfo(inserted, /*openedByClient*/ false); + scriptInfo.attachToProject(this); + }, + removed => { + const scriptInfoToDetach = this.projectService.getScriptInfo(removed); + if (scriptInfoToDetach) { + scriptInfoToDetach.detachFromProject(this); + } + }); + return hasChanges; } @@ -947,7 +966,7 @@ namespace ts.server { return this.typeAcquisition; } - getExternalFiles(): string[] { + getExternalFiles(): SortedReadonlyArray { const items: string[] = []; for (const plugin of this.plugins) { if (typeof plugin.getExternalFiles === "function") { @@ -959,7 +978,7 @@ namespace ts.server { } } } - return items; + return toSortedReadonlyArray(items); } watchConfigFile(callback: (project: ConfiguredProject) => void) { diff --git a/src/server/utilities.ts b/src/server/utilities.ts index ffc09f29ccd..0c3e960eff3 100644 --- a/src/server/utilities.ts +++ b/src/server/utilities.ts @@ -192,6 +192,37 @@ namespace ts.server { return arr; } + export function enumerateInsertsAndDeletes(a: SortedReadonlyArray, b: SortedReadonlyArray, inserted: (item: T) => void, deleted: (item: T) => void, compare?: (a: T, b: T) => Comparison) { + compare = compare || ts.compareValues; + let aIndex = 0; + let bIndex = 0; + const aLen = a.length; + const bLen = b.length; + while (aIndex < aLen && bIndex < bLen) { + const aItem = a[aIndex]; + const bItem = b[bIndex]; + const compareResult = compare(aItem, bItem); + if (compareResult === Comparison.LessThan) { + inserted(aItem); + aIndex++; + } + else if (compareResult === Comparison.GreaterThan) { + deleted(bItem); + bIndex++; + } + else { + aIndex++; + bIndex++; + } + } + while (aIndex < aLen) { + inserted(a[aIndex++]); + } + while (bIndex < bLen) { + deleted(b[bIndex++]); + } + } + export class ThrottledOperations { private pendingTimeouts: Map = createMap(); constructor(private readonly host: ServerHost) { From 420279b99d436d4652c44c33c0d7706fe66c047c Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Tue, 23 May 2017 11:34:37 -0700 Subject: [PATCH 02/23] add missing method --- src/compiler/diagnosticMessages.json | 6 ++- src/services/codefixes/fixAddMissingMember.ts | 27 +++++++++---- src/services/codefixes/helpers.ts | 40 +++++++++++++++++++ 3 files changed, 64 insertions(+), 9 deletions(-) diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index a7b6db70e5e..3803a9fbc23 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3583,7 +3583,11 @@ "category": "Message", "code": 90022 }, - + "Add declaration for missing method '{0}'.": { + "category": "Message", + "code": 90023 + }, + "Convert function to an ES2015 class": { "category": "Message", "code": 95001 diff --git a/src/services/codefixes/fixAddMissingMember.ts b/src/services/codefixes/fixAddMissingMember.ts index 64e7e560094..64f1618a675 100644 --- a/src/services/codefixes/fixAddMissingMember.ts +++ b/src/services/codefixes/fixAddMissingMember.ts @@ -2,7 +2,7 @@ namespace ts.codefix { registerCodeFix({ errorCodes: [Diagnostics.Property_0_does_not_exist_on_type_1.code, - Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2.code], + Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2.code], getCodeActions: getActionsForAddMissingMember }); @@ -79,20 +79,31 @@ namespace ts.codefix { } function getActionsForAddMissingMemberInTypeScriptFile(): CodeAction[] | undefined { - let typeNode: TypeNode; + const openBrace = getOpenBraceOfClassLike(classDeclaration, sourceFile); + const tokenName = token.getText(sourceFile); + let actions: CodeAction[]; + if (token.parent.parent.kind === SyntaxKind.CallExpression) { + const callExpression = token.parent.parent; + const methodDeclaration = createMethodFromCallExpression(callExpression, tokenName); + + const methodDeclarationChangeTracker = textChanges.ChangeTracker.fromCodeFixContext(context); + methodDeclarationChangeTracker.insertNodeAfter(sourceFile, openBrace, methodDeclaration, { suffix: context.newLineCharacter }); + actions = [{ + description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Add_declaration_for_missing_method_0), [tokenName]), + changes: methodDeclarationChangeTracker.getChanges() + }]; + } + + let typeNode: TypeNode; if (token.parent.parent.kind === SyntaxKind.BinaryExpression) { const binaryExpression = token.parent.parent as BinaryExpression; - const checker = context.program.getTypeChecker(); const widenedType = checker.getWidenedType(checker.getBaseTypeOfLiteralType(checker.getTypeAtLocation(binaryExpression.right))); typeNode = checker.typeToTypeNode(widenedType, classDeclaration); } - typeNode = typeNode || createKeywordTypeNode(SyntaxKind.AnyKeyword); - const openBrace = getOpenBraceOfClassLike(classDeclaration, sourceFile); - const property = createProperty( /*decorators*/undefined, /*modifiers*/ isStatic ? [createToken(SyntaxKind.StaticKeyword)] : undefined, @@ -103,10 +114,10 @@ namespace ts.codefix { const propertyChangeTracker = textChanges.ChangeTracker.fromCodeFixContext(context); propertyChangeTracker.insertNodeAfter(sourceFile, openBrace, property, { suffix: context.newLineCharacter }); - const actions = [{ + (actions || (actions = [])).push({ description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Add_declaration_for_missing_property_0), [token.getText()]), changes: propertyChangeTracker.getChanges() - }]; + }); if (!isStatic) { const stringTypeNode = createKeywordTypeNode(SyntaxKind.StringKeyword); diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts index 39d8e13dde9..dc51129736d 100644 --- a/src/services/codefixes/helpers.ts +++ b/src/services/codefixes/helpers.ts @@ -142,6 +142,46 @@ namespace ts.codefix { } } + export function createMethodFromCallExpression(callExpression: CallExpression, methodName: string): MethodDeclaration { + const argCount = callExpression.arguments.length; + const parameters: ParameterDeclaration[] = []; + for (let i = 0; i < argCount; i++) { + const typeNode = createKeywordTypeNode(SyntaxKind.AnyKeyword); + const newParameter = createParameter( + /*decorators*/ undefined, + /*modifiers*/ undefined, + /*dotDotDotToken*/ undefined, + `arg${i}`, + /*questionToken*/ undefined, + typeNode, + /*initializer*/ undefined); + parameters.push(newParameter); + } + + const typeArgCount = callExpression.typeArguments ? callExpression.typeArguments.length : 0; + let typeParameters: TypeParameterDeclaration[]; + for (let i = 0; i < typeArgCount; i++) { + const name = typeArgCount < 8 ? String.fromCharCode(CharacterCodes.T + i) : `T${i}`; + const typeParameter = createTypeParameterDeclaration(name, /*constraint*/ undefined, /*defaultType*/ undefined); + + (typeParameters ? typeParameters : typeParameters = []).push(typeParameter); + } + + const newMethod = createMethod( + /*decorators*/ undefined, + /*modifiers*/ undefined, + /*asteriskToken*/ undefined, + methodName, + /*questionToken*/ undefined, + typeParameters, + parameters, + /*type*/ undefined, + createStubbedMethodBody() + ) + + return newMethod; + } + function createMethodImplementingSignatures(signatures: Signature[], name: PropertyName, optional: boolean, modifiers: Modifier[] | undefined): MethodDeclaration { /** This is *a* signature with the maximal number of arguments, * such that if there is a "maximal" signature without rest arguments, From 15c029189c36f6cc835403c5307e274e14d49277 Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Tue, 23 May 2017 13:32:41 -0700 Subject: [PATCH 03/23] testing --- src/compiler/types.ts | 1 - src/harness/fourslash.ts | 65 ++++++++++++------- src/services/codefixes/helpers.ts | 2 +- .../fourslash/codeFixUndeclaredMethod.ts | 27 ++++++++ tests/cases/fourslash/fourslash.ts | 4 +- 5 files changed, 73 insertions(+), 26 deletions(-) create mode 100644 tests/cases/fourslash/codeFixUndeclaredMethod.ts diff --git a/src/compiler/types.ts b/src/compiler/types.ts index a8da09a11c5..7aa8890d73d 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2522,7 +2522,6 @@ namespace ts { getNonNullableType(type: Type): Type; /** Note that the resulting nodes cannot be checked. */ - typeToTypeNode(type: Type, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): TypeNode; /** Note that the resulting nodes cannot be checked. */ signatureToSignatureDeclaration(signature: Signature, kind: SyntaxKind, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): SignatureDeclaration; diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 8f19b83c7ad..a021a4d5660 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2275,6 +2275,34 @@ namespace FourSlash { }); } + /** + * Finds and applies a code action corresponding to the supplied parameters. + * If index is undefined, applies the unique code action available. + * @param errorCode The error code that generated the code action. + * @param index The nth (0-index-based) codeaction available generated by errorCode. + */ + public getAndApplyCodeActions(errorCode?: number, index?: number) { + const fileName = this.activeFile.fileName; + this.applyCodeActions(fileName, this.getCodeFixActions(fileName, errorCode), index); + } + + public verifyRangeIs(expectedText: string, includeWhiteSpace?: boolean) { + const ranges = this.getRanges(); + if (ranges.length !== 1) { + this.raiseError("Exactly one range should be specified in the testfile."); + } + + const actualText = this.normalizeNewlines(this.rangeText(ranges[0])); + + const result = includeWhiteSpace + ? actualText === this.normalizeNewlines(expectedText) + : this.removeWhitespace(actualText) === this.removeWhitespace(expectedText); + + if (!result) { + this.raiseError(`Actual text doesn't match expected text. Actual:\n'${actualText}'\nExpected:\n'${expectedText}'`); + } + } + /** * Compares expected text to the text that would be in the sole range * (ie: [|...|]) in the file after applying the codefix sole codefix @@ -2284,24 +2312,8 @@ namespace FourSlash { * to apply this more than once (consider a refactoring across files). */ public verifyRangeAfterCodeFix(expectedText: string, includeWhiteSpace?: boolean, errorCode?: number, index?: number) { - const ranges = this.getRanges(); - if (ranges.length !== 1) { - this.raiseError("Exactly one range should be specified in the testfile."); - } - - const fileName = this.activeFile.fileName; - - this.applyCodeAction(fileName, this.getCodeFixActions(fileName, errorCode), index); - - const actualText = this.rangeText(ranges[0]); - - const result = includeWhiteSpace - ? normalizeNewLines(actualText) === normalizeNewLines(expectedText) - : this.removeWhitespace(actualText) === this.removeWhitespace(expectedText); - - if (!result) { - this.raiseError(`Actual text doesn't match expected text. Actual:\n'${actualText}'\nExpected:\n'${expectedText}'`); - } + this.getAndApplyCodeActions(errorCode, index); + this.verifyRangeIs(expectedText, includeWhiteSpace); } /** @@ -2316,7 +2328,7 @@ namespace FourSlash { public verifyFileAfterCodeFix(expectedContents: string, fileName?: string) { fileName = fileName ? fileName : this.activeFile.fileName; - this.applyCodeAction(fileName, this.getCodeFixActions(fileName)); + this.applyCodeActions(fileName, this.getCodeFixActions(fileName)); const actualContents: string = this.getFileContent(fileName); if (this.removeWhitespace(actualContents) !== this.removeWhitespace(expectedContents)) { @@ -2354,11 +2366,10 @@ namespace FourSlash { return actions; } - private applyCodeAction(fileName: string, actions: ts.CodeAction[], index?: number): void { + private applyCodeActions(fileName: string, actions: ts.CodeAction[], index?: number): void { if (index === undefined) { if (!(actions && actions.length === 1)) { - const actionText = (actions && actions.length) ? JSON.stringify(actions) : "none"; - this.raiseError(`Should find exactly one codefix, but found ${actionText}`); + this.raiseError(`Should find exactly one codefix, but ${actions ? actions.length : "none"} found.`); } index = 0; } @@ -2758,7 +2769,7 @@ namespace FourSlash { const codeActions = this.languageService.getRefactorCodeActions(this.activeFile.fileName, formattingOptions, markerPos, refactorNameToApply); - this.applyCodeAction(this.activeFile.fileName, codeActions); + this.applyCodeActions(this.activeFile.fileName, codeActions); const actualContent = this.getFileContent(this.activeFile.fileName); if (this.normalizeNewlines(actualContent) !== this.normalizeNewlines(expectedContent)) { @@ -3805,6 +3816,14 @@ namespace FourSlashInterface { this.state.verifyFileAfterApplyingRefactorAtMarker(markerName, expectedContent, refactorNameToApply, formattingOptions); } + public rangeIs(expectedText: string, includeWhiteSpace?: boolean): void { + this.state.verifyRangeIs(expectedText, includeWhiteSpace); + } + + public applyCodeFix(errorCode?: number, index?: number): void { + this.state.getAndApplyCodeActions(errorCode, index); + } + public importFixAtPosition(expectedTextArray: string[], errorCode?: number): void { this.state.verifyImportFixAtPosition(expectedTextArray, errorCode); } diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts index dc51129736d..5b81f71b6c9 100644 --- a/src/services/codefixes/helpers.ts +++ b/src/services/codefixes/helpers.ts @@ -177,7 +177,7 @@ namespace ts.codefix { parameters, /*type*/ undefined, createStubbedMethodBody() - ) + ); return newMethod; } diff --git a/tests/cases/fourslash/codeFixUndeclaredMethod.ts b/tests/cases/fourslash/codeFixUndeclaredMethod.ts new file mode 100644 index 00000000000..b595a09c6a7 --- /dev/null +++ b/tests/cases/fourslash/codeFixUndeclaredMethod.ts @@ -0,0 +1,27 @@ +/// + +//// class A {[| +//// |]constructor() { +//// this.foo1(1,2,3); +//// // 7 type args +//// this.foo2<1,2,3,4,5,6,7>(); +//// // 8 type args +//// this.foo3<1,2,3,4,5,6,7,8>(); +//// } +//// } + +verify.applyCodeFix(/*errorCode*/undefined, 0); +verify.applyCodeFix(/*errorCode*/undefined, 0); +verify.applyCodeFix(/*errorCode*/undefined, 0); + +verify.rangeIs(` + foo3() { + throw new Error("Method not implemented."); + } + foo2() { + throw new Error("Method not implemented."); + } + foo1(arg0: any, arg1: any, arg2: any) { + throw new Error("Method not implemented."); + } +`); \ No newline at end of file diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 3fada673f35..b0f731dcdea 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -236,7 +236,9 @@ declare namespace FourSlashInterface { noMatchingBracePositionInCurrentFile(bracePosition: number): void; DocCommentTemplate(expectedText: string, expectedOffset: number, empty?: boolean): void; noDocCommentTemplate(): void; - rangeAfterCodeFix(expectedText: string, includeWhiteSpace?: boolean, errorCode?: number, index?: number): void; + rangeAfterCodeFix(expectedText: string, includeWhiteSpace?: boolean, errorCode?: number, index?: number): void + applyCodeFix(errorCode?: number, index?: number): void; + rangeIs(expectedText: string, includeWhiteSpace?: boolean): void; fileAfterApplyingRefactorAtMarker(markerName: string, expectedContent: string, refactorNameToApply: string, formattingOptions?: FormatCodeOptions): void; importFixAtPosition(expectedTextArray: string[], errorCode?: number): void; From 1939c65fc694421e4e2f33958cc5d9d1cad2385f Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Tue, 23 May 2017 13:37:53 -0700 Subject: [PATCH 04/23] rename helper --- src/harness/fourslash.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index a021a4d5660..ee7329102b2 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2283,7 +2283,7 @@ namespace FourSlash { */ public getAndApplyCodeActions(errorCode?: number, index?: number) { const fileName = this.activeFile.fileName; - this.applyCodeActions(fileName, this.getCodeFixActions(fileName, errorCode), index); + this.applyCodeAction(fileName, this.getCodeFixActions(fileName, errorCode), index); } public verifyRangeIs(expectedText: string, includeWhiteSpace?: boolean) { @@ -2328,7 +2328,7 @@ namespace FourSlash { public verifyFileAfterCodeFix(expectedContents: string, fileName?: string) { fileName = fileName ? fileName : this.activeFile.fileName; - this.applyCodeActions(fileName, this.getCodeFixActions(fileName)); + this.applyCodeAction(fileName, this.getCodeFixActions(fileName)); const actualContents: string = this.getFileContent(fileName); if (this.removeWhitespace(actualContents) !== this.removeWhitespace(expectedContents)) { @@ -2366,7 +2366,7 @@ namespace FourSlash { return actions; } - private applyCodeActions(fileName: string, actions: ts.CodeAction[], index?: number): void { + private applyCodeAction(fileName: string, actions: ts.CodeAction[], index?: number): void { if (index === undefined) { if (!(actions && actions.length === 1)) { this.raiseError(`Should find exactly one codefix, but ${actions ? actions.length : "none"} found.`); @@ -2769,7 +2769,7 @@ namespace FourSlash { const codeActions = this.languageService.getRefactorCodeActions(this.activeFile.fileName, formattingOptions, markerPos, refactorNameToApply); - this.applyCodeActions(this.activeFile.fileName, codeActions); + this.applyCodeAction(this.activeFile.fileName, codeActions); const actualContent = this.getFileContent(this.activeFile.fileName); if (this.normalizeNewlines(actualContent) !== this.normalizeNewlines(expectedContent)) { From f56be99b114a643f8c4ca1ec1623f9717fb95448 Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Tue, 23 May 2017 13:47:53 -0700 Subject: [PATCH 05/23] cleanup --- src/harness/fourslash.ts | 4 ++-- src/services/codefixes/fixAddMissingMember.ts | 20 +++++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index ee7329102b2..92886cb7603 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2292,10 +2292,10 @@ namespace FourSlash { this.raiseError("Exactly one range should be specified in the testfile."); } - const actualText = this.normalizeNewlines(this.rangeText(ranges[0])); + const actualText = this.rangeText(ranges[0]); const result = includeWhiteSpace - ? actualText === this.normalizeNewlines(expectedText) + ? normalizeNewLines(actualText) === normalizeNewLines(expectedText) : this.removeWhitespace(actualText) === this.removeWhitespace(expectedText); if (!result) { diff --git a/src/services/codefixes/fixAddMissingMember.ts b/src/services/codefixes/fixAddMissingMember.ts index 64f1618a675..231e320c93b 100644 --- a/src/services/codefixes/fixAddMissingMember.ts +++ b/src/services/codefixes/fixAddMissingMember.ts @@ -2,7 +2,7 @@ namespace ts.codefix { registerCodeFix({ errorCodes: [Diagnostics.Property_0_does_not_exist_on_type_1.code, - Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2.code], + Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2.code], getCodeActions: getActionsForAddMissingMember }); @@ -33,13 +33,12 @@ namespace ts.codefix { return undefined; } + const tokenName = token.getText(sourceFile); const isStatic = hasModifier(classMemberDeclaration, ModifierFlags.Static); return isInJavaScriptFile(sourceFile) ? getActionsForAddMissingMemberInJavaScriptFile() : getActionsForAddMissingMemberInTypeScriptFile(); function getActionsForAddMissingMemberInJavaScriptFile(): CodeAction[] | undefined { - const memberName = token.getText(); - if (isStatic) { if (classDeclaration.kind === SyntaxKind.ClassExpression) { return undefined; @@ -48,12 +47,12 @@ namespace ts.codefix { const className = classDeclaration.name.getText(); return [{ - description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Initialize_static_property_0), [memberName]), + description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Initialize_static_property_0), [tokenName]), changes: [{ fileName: sourceFile.fileName, textChanges: [{ span: { start: classDeclaration.getEnd(), length: 0 }, - newText: `${context.newLineCharacter}${className}.${memberName} = undefined;${context.newLineCharacter}` + newText: `${context.newLineCharacter}${className}.${tokenName} = undefined;${context.newLineCharacter}` }] }] }]; @@ -66,12 +65,12 @@ namespace ts.codefix { } return [{ - description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Initialize_property_0_in_the_constructor), [memberName]), + description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Initialize_property_0_in_the_constructor), [tokenName]), changes: [{ fileName: sourceFile.fileName, textChanges: [{ span: { start: classConstructor.body.getEnd() - 1, length: 0 }, - newText: `this.${memberName} = undefined;${context.newLineCharacter}` + newText: `this.${tokenName} = undefined;${context.newLineCharacter}` }] }] }]; @@ -80,7 +79,6 @@ namespace ts.codefix { function getActionsForAddMissingMemberInTypeScriptFile(): CodeAction[] | undefined { const openBrace = getOpenBraceOfClassLike(classDeclaration, sourceFile); - const tokenName = token.getText(sourceFile); let actions: CodeAction[]; if (token.parent.parent.kind === SyntaxKind.CallExpression) { @@ -107,7 +105,7 @@ namespace ts.codefix { const property = createProperty( /*decorators*/undefined, /*modifiers*/ isStatic ? [createToken(SyntaxKind.StaticKeyword)] : undefined, - token.getText(sourceFile), + tokenName, /*questionToken*/ undefined, typeNode, /*initializer*/ undefined); @@ -115,7 +113,7 @@ namespace ts.codefix { propertyChangeTracker.insertNodeAfter(sourceFile, openBrace, property, { suffix: context.newLineCharacter }); (actions || (actions = [])).push({ - description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Add_declaration_for_missing_property_0), [token.getText()]), + description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Add_declaration_for_missing_property_0), [tokenName]), changes: propertyChangeTracker.getChanges() }); @@ -139,7 +137,7 @@ namespace ts.codefix { indexSignatureChangeTracker.insertNodeAfter(sourceFile, openBrace, indexSignature, { suffix: context.newLineCharacter }); actions.push({ - description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Add_index_signature_for_missing_property_0), [token.getText()]), + description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Add_index_signature_for_missing_property_0), [tokenName]), changes: indexSignatureChangeTracker.getChanges() }); } From f19c3121c2ebd95f316a76be6b4571cfe6df235e Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Wed, 31 May 2017 17:17:58 -0700 Subject: [PATCH 06/23] Apply codefixes across files --- src/harness/fourslash.ts | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 92886cb7603..0cbf98cebf7 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2283,7 +2283,7 @@ namespace FourSlash { */ public getAndApplyCodeActions(errorCode?: number, index?: number) { const fileName = this.activeFile.fileName; - this.applyCodeAction(fileName, this.getCodeFixActions(fileName, errorCode), index); + this.applyCodeActions(this.getCodeFixActions(fileName, errorCode), index); } public verifyRangeIs(expectedText: string, includeWhiteSpace?: boolean) { @@ -2307,9 +2307,6 @@ namespace FourSlash { * Compares expected text to the text that would be in the sole range * (ie: [|...|]) in the file after applying the codefix sole codefix * in the source file. - * - * Because codefixes are only applied on the working file, it is unsafe - * to apply this more than once (consider a refactoring across files). */ public verifyRangeAfterCodeFix(expectedText: string, includeWhiteSpace?: boolean, errorCode?: number, index?: number) { this.getAndApplyCodeActions(errorCode, index); @@ -2328,7 +2325,7 @@ namespace FourSlash { public verifyFileAfterCodeFix(expectedContents: string, fileName?: string) { fileName = fileName ? fileName : this.activeFile.fileName; - this.applyCodeAction(fileName, this.getCodeFixActions(fileName)); + this.applyCodeActions(this.getCodeFixActions(fileName)); const actualContents: string = this.getFileContent(fileName); if (this.removeWhitespace(actualContents) !== this.removeWhitespace(expectedContents)) { @@ -2366,7 +2363,7 @@ namespace FourSlash { return actions; } - private applyCodeAction(fileName: string, actions: ts.CodeAction[], index?: number): void { + private applyCodeActions(actions: ts.CodeAction[], index?: number): void { if (index === undefined) { if (!(actions && actions.length === 1)) { this.raiseError(`Should find exactly one codefix, but ${actions ? actions.length : "none"} found.`); @@ -2379,12 +2376,11 @@ namespace FourSlash { } } - const fileChanges = ts.find(actions[index].changes, change => change.fileName === fileName); - if (!fileChanges) { - this.raiseError("The CodeFix found doesn't provide any changes in this file."); - } + const changes = actions[index].changes; - this.applyEdits(fileChanges.fileName, fileChanges.textChanges, /*isFormattingEdit*/ false); + for (const change of changes) { + this.applyEdits(change.fileName, change.textChanges, /*isFormattingEdit*/ false); + } } public verifyImportFixAtPosition(expectedTextArray: string[], errorCode?: number) { @@ -2769,7 +2765,7 @@ namespace FourSlash { const codeActions = this.languageService.getRefactorCodeActions(this.activeFile.fileName, formattingOptions, markerPos, refactorNameToApply); - this.applyCodeAction(this.activeFile.fileName, codeActions); + this.applyCodeActions(codeActions); const actualContent = this.getFileContent(this.activeFile.fileName); if (this.normalizeNewlines(actualContent) !== this.normalizeNewlines(expectedContent)) { From c125f080a43a60706cff8dec6a6b548014480d43 Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Wed, 31 May 2017 17:18:36 -0700 Subject: [PATCH 07/23] add tests --- .../codeFixUndeclaredAcrossFiles1.ts | 34 ++++++++++++++ .../codeFixUndeclaredAcrossFiles2.ts | 40 +++++++++++++++++ .../codeFixUndeclaredInStaticMethod.ts | 44 +++++++++++++++++++ .../fourslash/codeFixUndeclaredMethod.ts | 6 +-- .../codeFixUndeclaredPropertyAccesses.ts | 17 +++++++ 5 files changed, 138 insertions(+), 3 deletions(-) create mode 100644 tests/cases/fourslash/codeFixUndeclaredAcrossFiles1.ts create mode 100644 tests/cases/fourslash/codeFixUndeclaredAcrossFiles2.ts create mode 100644 tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts create mode 100644 tests/cases/fourslash/codeFixUndeclaredPropertyAccesses.ts diff --git a/tests/cases/fourslash/codeFixUndeclaredAcrossFiles1.ts b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles1.ts new file mode 100644 index 00000000000..830259e3ca7 --- /dev/null +++ b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles1.ts @@ -0,0 +1,34 @@ +/// + +// @allowJs: true +// @checkJs: true + +// @Filename: f2.js +//// import * as X from "./f1"; +//// X.C.m0(1, "", []); +//// X.C.x; +//// let c = new X.C; +//// c.m1(); +//// c.y = {}; + +// @Filename: f1.ts +//// export class C {[| +//// |]x: number; +//// static y: string; +//// } + +verify.applyCodeFix(/*errorCode*/undefined, 0); +verify.applyCodeFix(/*errorCode*/undefined, 0); +verify.applyCodeFix(/*errorCode*/undefined, 0); +verify.applyCodeFix(/*errorCode*/undefined, 0); + +verify.rangeIs(` + y: { [x: string]: any; }; + m1(): any { + throw new Error("Method not implemented."); + } + static x: any; + static m0(arg0: any, arg1: any, arg2: any): any { + throw new Error("Method not implemented."); + } +`); \ No newline at end of file diff --git a/tests/cases/fourslash/codeFixUndeclaredAcrossFiles2.ts b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles2.ts new file mode 100644 index 00000000000..cc01f8d50ee --- /dev/null +++ b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles2.ts @@ -0,0 +1,40 @@ +/// + +// @allowJs: true +// @checkJs: true + +// @Filename: f2.ts +//// import * as X from "./f1"; +//// X.C.m0(1, "", []); +//// X.C.x; +//// let c = new X.C; +//// c.m1(); +//// c.y = {}; + +// @Filename: f1.js +//// [|export class C { +//// x: number; +//// static y: string; +//// constructor() { } +//// }|] + +verify.applyCodeFix(/*errorCode*/undefined, 0); +verify.applyCodeFix(/*errorCode*/undefined, 0); +verify.applyCodeFix(/*errorCode*/undefined, 0); +verify.applyCodeFix(/*errorCode*/undefined, 0); + +verify.rangeIs(` +export class C { + m1() { + throw new Error("Method not implemented."); + } + static m0(arg0, arg1, arg2) { + throw new Error("Method not implemented."); + } + x: number; + static y: string; + constructor() { + this.y = undefined; + } +} +`); \ No newline at end of file diff --git a/tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts b/tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts new file mode 100644 index 00000000000..94ad3f77615 --- /dev/null +++ b/tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts @@ -0,0 +1,44 @@ +/// + +//// class A {[| +//// |]static foo0() { +//// this.m1(1,2,3); +//// A.m2(1,2); +//// this.prop1 = 10; +//// A.prop2 = "asdf"; +//// } +//// } + +verify.applyCodeFix(/*errorCode*/undefined, 0); +verify.applyCodeFix(/*errorCode*/undefined, 0); +verify.applyCodeFix(/*errorCode*/undefined, 0); +verify.applyCodeFix(/*errorCode*/undefined, 0); + +verify.rangeIs(` + static prop2: string; + static prop1: number; + static m2(arg0: any, arg1: any): any { + throw new Error("Method not implemented."); + } + static m1(arg0: any, arg1: any, arg2: any): any { + throw new Error("Method not implemented."); + } +`); + +// class A { +// static prop2: string; +// static prop1: number; +// static m2(arg0: any, arg1: any): any { +// throw new Error("Method not implemented."); +// } +// static m1(arg0: any, arg1: any, arg2: any): any { +// throw new Error("Method not implemented."); +// } +// static foo0() { +// this.m1(1,2,3); +// A.m2(1,2); +// this.prop1 = 10; +// A.prop2 = "asdf"; +// } +// } + diff --git a/tests/cases/fourslash/codeFixUndeclaredMethod.ts b/tests/cases/fourslash/codeFixUndeclaredMethod.ts index b595a09c6a7..1f842a5bcf1 100644 --- a/tests/cases/fourslash/codeFixUndeclaredMethod.ts +++ b/tests/cases/fourslash/codeFixUndeclaredMethod.ts @@ -15,13 +15,13 @@ verify.applyCodeFix(/*errorCode*/undefined, 0); verify.applyCodeFix(/*errorCode*/undefined, 0); verify.rangeIs(` - foo3() { + foo3(): any { throw new Error("Method not implemented."); } - foo2() { + foo2(): any { throw new Error("Method not implemented."); } - foo1(arg0: any, arg1: any, arg2: any) { + foo1(arg0: any, arg1: any, arg2: any): any { throw new Error("Method not implemented."); } `); \ No newline at end of file diff --git a/tests/cases/fourslash/codeFixUndeclaredPropertyAccesses.ts b/tests/cases/fourslash/codeFixUndeclaredPropertyAccesses.ts new file mode 100644 index 00000000000..ee05d2c0a9c --- /dev/null +++ b/tests/cases/fourslash/codeFixUndeclaredPropertyAccesses.ts @@ -0,0 +1,17 @@ +/// + +//// interface I { x: number; } +//// let i: I; +//// i.y; +//// i.foo(); +//// enum E { a,b } +//// let e: typeof E; +//// e.a; +//// e.c; +//// let obj = { a: 1, b: "asdf"}; +//// obj.c; +//// type T = I | U; +//// let t: T; +//// t.x; + +verify.not.codeFixAvailable(); \ No newline at end of file From 21fc30f69bdb10aa3ef2a67ac528a68103983c27 Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Wed, 31 May 2017 17:41:35 -0700 Subject: [PATCH 08/23] Add support across files and static, js methods --- src/compiler/checker.ts | 7 +- src/compiler/diagnosticMessages.json | 10 +- src/compiler/types.ts | 1 + src/compiler/utilities.ts | 4 + src/services/codefixes/fixAddMissingMember.ts | 132 ++++++++++++------ src/services/codefixes/helpers.ts | 66 ++++----- .../codeFixUndeclaredAcrossFiles2.ts | 4 +- 7 files changed, 137 insertions(+), 87 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9ff1c4b41b9..e9b197f2863 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -110,6 +110,7 @@ namespace ts { getParameterType: getTypeAtPosition, getReturnTypeOfSignature, getNonNullableType, + getBaseTypeVariableOfClass, typeToTypeNode: nodeBuilder.typeToTypeNode, indexInfoToIndexSignatureDeclaration: nodeBuilder.indexInfoToIndexSignatureDeclaration, signatureToSignatureDeclaration: nodeBuilder.signatureToSignatureDeclaration, @@ -681,10 +682,6 @@ namespace ts { return nodeLinks[nodeId] || (nodeLinks[nodeId] = { flags: 0 }); } - function getObjectFlags(type: Type): ObjectFlags { - return type.flags & TypeFlags.Object ? (type).objectFlags : 0; - } - function isGlobalSourceFile(node: Node) { return node.kind === SyntaxKind.SourceFile && !isExternalOrCommonJsModule(node); } @@ -2282,7 +2279,7 @@ namespace ts { function typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string { const typeNode = nodeBuilder.typeToTypeNode(type, enclosingDeclaration, toNodeBuilderFlags(flags) | NodeBuilderFlags.IgnoreErrors | NodeBuilderFlags.WriteTypeParametersInQualifiedName); - Debug.assert(typeNode !== undefined, "should always get typenode?"); + Debug.assert(typeNode !== undefined, "should always get typenode"); const options = { removeComments: true }; const writer = createTextWriter(""); const printer = createPrinter(options, writer); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 3803a9fbc23..f0b33ac9fdf 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3555,11 +3555,11 @@ "category": "Message", "code": 90015 }, - "Add declaration for missing property '{0}'.": { + "Declare property '{0}'.": { "category": "Message", "code": 90016 }, - "Add index signature for missing property '{0}'.": { + "Add index signature for property '{0}'.": { "category": "Message", "code": 90017 }, @@ -3583,10 +3583,14 @@ "category": "Message", "code": 90022 }, - "Add declaration for missing method '{0}'.": { + "Declare method '{0}'.": { "category": "Message", "code": 90023 }, + "Declare static method '{0}'.": { + "category": "Message", + "code": 90024 + }, "Convert function to an ES2015 class": { "category": "Message", diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 561d84b5d71..ee02d37addb 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2530,6 +2530,7 @@ namespace ts { */ /* @internal */ getParameterType(signature: Signature, parameterIndex: number): Type; getNonNullableType(type: Type): Type; + /* @internal */ getBaseTypeVariableOfClass(symbol: Symbol): Type | undefined; /** Note that the resulting nodes cannot be checked. */ typeToTypeNode(type: Type, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): TypeNode; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 506d2728ffd..187d90559f1 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -733,6 +733,10 @@ namespace ts { return false; } + export function getObjectFlags(type: Type): ObjectFlags { + return type.flags & TypeFlags.Object ? (type).objectFlags : 0; + } + export function isChildOfNodeWithKind(node: Node, kind: SyntaxKind): boolean { while (node) { if (node.kind === kind) { diff --git a/src/services/codefixes/fixAddMissingMember.ts b/src/services/codefixes/fixAddMissingMember.ts index 231e320c93b..358c2255789 100644 --- a/src/services/codefixes/fixAddMissingMember.ts +++ b/src/services/codefixes/fixAddMissingMember.ts @@ -8,116 +8,151 @@ namespace ts.codefix { function getActionsForAddMissingMember(context: CodeFixContext): CodeAction[] | undefined { - const sourceFile = context.sourceFile; + const tokenSourceFile = context.sourceFile; const start = context.span.start; - // This is the identifier of the missing property. eg: + // The identifier of the missing property. eg: // this.missing = 1; // ^^^^^^^ - const token = getTokenAtPosition(sourceFile, start, /*includeJsDocComment*/ false); + const token = getTokenAtPosition(tokenSourceFile, start, /*includeJsDocComment*/ false); if (token.kind !== SyntaxKind.Identifier) { return undefined; } - if (!isPropertyAccessExpression(token.parent) || token.parent.expression.kind !== SyntaxKind.ThisKeyword) { + if (!isPropertyAccessExpression(token.parent)) { return undefined; } - const classMemberDeclaration = getThisContainer(token, /*includeArrowFunctions*/ false); - if (!isClassElement(classMemberDeclaration)) { - return undefined; + const tokenName = token.getText(tokenSourceFile); + + let makeStatic = false; + let classDeclaration: ClassLikeDeclaration; + + if (token.parent.expression.kind === SyntaxKind.ThisKeyword) { + const containingClassMemberDeclaration = getThisContainer(token, /*includeArrowFunctions*/ false); + if (!isClassElement(containingClassMemberDeclaration)) { + return undefined; + } + + classDeclaration = containingClassMemberDeclaration.parent; + + // Property accesses on `this` in a static method are accesses of a static member. + makeStatic = classDeclaration && hasModifier(containingClassMemberDeclaration, ModifierFlags.Static); + } + else { + + const checker = context.program.getTypeChecker(); + const leftExpression = token.parent.expression; + const leftExpressionType = checker.getTypeAtLocation(leftExpression); + + if (leftExpressionType.flags & TypeFlags.Object) { + const symbol = leftExpressionType.symbol; + if (symbol.flags & SymbolFlags.Class) { + classDeclaration = symbol.declarations && symbol.declarations[0]; + if (getObjectFlags(leftExpressionType) & ObjectFlags.Anonymous && symbol.flags & SymbolFlags.Class && !checker.getBaseTypeVariableOfClass(symbol)) { + makeStatic = true; + } + } + } } - const classDeclaration = classMemberDeclaration.parent; if (!classDeclaration || !isClassLike(classDeclaration)) { return undefined; } - const tokenName = token.getText(sourceFile); - const isStatic = hasModifier(classMemberDeclaration, ModifierFlags.Static); + const classDeclarationSourceFile = getSourceFileOfNode(classDeclaration); + const classOpenBrace = getOpenBraceOfClassLike(classDeclaration, classDeclarationSourceFile); - return isInJavaScriptFile(sourceFile) ? getActionsForAddMissingMemberInJavaScriptFile() : getActionsForAddMissingMemberInTypeScriptFile(); + return isInJavaScriptFile(classDeclarationSourceFile) ? + getActionsForAddMissingMemberInJavaScriptFile(classDeclaration, makeStatic) : + getActionsForAddMissingMemberInTypeScriptFile(classDeclaration, makeStatic); - function getActionsForAddMissingMemberInJavaScriptFile(): CodeAction[] | undefined { - if (isStatic) { + function getActionsForAddMissingMemberInJavaScriptFile(classDeclaration: ClassLikeDeclaration, makeStatic: boolean): CodeAction[] | undefined { + let actions: CodeAction[]; + + const methodCodeAction = getActionForMethodDeclaration(); + if (methodCodeAction) { + actions = [methodCodeAction]; + } + + if (makeStatic) { if (classDeclaration.kind === SyntaxKind.ClassExpression) { - return undefined; + return actions; } const className = classDeclaration.name.getText(); - return [{ + const initializeStaticAction = { description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Initialize_static_property_0), [tokenName]), changes: [{ - fileName: sourceFile.fileName, + fileName: classDeclarationSourceFile.fileName, textChanges: [{ span: { start: classDeclaration.getEnd(), length: 0 }, newText: `${context.newLineCharacter}${className}.${tokenName} = undefined;${context.newLineCharacter}` }] }] - }]; + }; + (actions || (actions = [])).push(initializeStaticAction); + return actions; } else { const classConstructor = getFirstConstructorWithBody(classDeclaration); if (!classConstructor) { - return undefined; + return actions; } - return [{ + const initializeAction = { description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Initialize_property_0_in_the_constructor), [tokenName]), changes: [{ - fileName: sourceFile.fileName, + fileName: classDeclarationSourceFile.fileName, textChanges: [{ span: { start: classConstructor.body.getEnd() - 1, length: 0 }, newText: `this.${tokenName} = undefined;${context.newLineCharacter}` }] }] - }]; + }; + + (actions || (actions = [])).push(initializeAction); + return actions; } } - function getActionsForAddMissingMemberInTypeScriptFile(): CodeAction[] | undefined { - const openBrace = getOpenBraceOfClassLike(classDeclaration, sourceFile); + function getActionsForAddMissingMemberInTypeScriptFile(classDeclaration: ClassLikeDeclaration, makeStatic: boolean): CodeAction[] | undefined { let actions: CodeAction[]; - if (token.parent.parent.kind === SyntaxKind.CallExpression) { - const callExpression = token.parent.parent; - const methodDeclaration = createMethodFromCallExpression(callExpression, tokenName); - - const methodDeclarationChangeTracker = textChanges.ChangeTracker.fromCodeFixContext(context); - methodDeclarationChangeTracker.insertNodeAfter(sourceFile, openBrace, methodDeclaration, { suffix: context.newLineCharacter }); - actions = [{ - description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Add_declaration_for_missing_method_0), [tokenName]), - changes: methodDeclarationChangeTracker.getChanges() - }]; + const methodCodeAction = getActionForMethodDeclaration(); + if (methodCodeAction) { + actions = [methodCodeAction]; } let typeNode: TypeNode; if (token.parent.parent.kind === SyntaxKind.BinaryExpression) { const binaryExpression = token.parent.parent as BinaryExpression; + const otherExpression = token.parent === binaryExpression.left ? binaryExpression.right : binaryExpression.left; const checker = context.program.getTypeChecker(); - const widenedType = checker.getWidenedType(checker.getBaseTypeOfLiteralType(checker.getTypeAtLocation(binaryExpression.right))); + const widenedType = checker.getWidenedType(checker.getBaseTypeOfLiteralType(checker.getTypeAtLocation(otherExpression))); typeNode = checker.typeToTypeNode(widenedType, classDeclaration); } typeNode = typeNode || createKeywordTypeNode(SyntaxKind.AnyKeyword); const property = createProperty( /*decorators*/undefined, - /*modifiers*/ isStatic ? [createToken(SyntaxKind.StaticKeyword)] : undefined, + /*modifiers*/ makeStatic ? [createToken(SyntaxKind.StaticKeyword)] : undefined, tokenName, /*questionToken*/ undefined, typeNode, /*initializer*/ undefined); const propertyChangeTracker = textChanges.ChangeTracker.fromCodeFixContext(context); - propertyChangeTracker.insertNodeAfter(sourceFile, openBrace, property, { suffix: context.newLineCharacter }); + propertyChangeTracker.insertNodeAfter(classDeclarationSourceFile, classOpenBrace, property, { suffix: context.newLineCharacter }); (actions || (actions = [])).push({ - description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Add_declaration_for_missing_property_0), [tokenName]), + description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Declare_property_0), [tokenName]), changes: propertyChangeTracker.getChanges() }); - if (!isStatic) { + if (!makeStatic) { + // Index signatures cannot have the static modifier. const stringTypeNode = createKeywordTypeNode(SyntaxKind.StringKeyword); const indexingParameter = createParameter( /*decorators*/ undefined, @@ -134,15 +169,32 @@ namespace ts.codefix { typeNode); const indexSignatureChangeTracker = textChanges.ChangeTracker.fromCodeFixContext(context); - indexSignatureChangeTracker.insertNodeAfter(sourceFile, openBrace, indexSignature, { suffix: context.newLineCharacter }); + indexSignatureChangeTracker.insertNodeAfter(classDeclarationSourceFile, classOpenBrace, indexSignature, { suffix: context.newLineCharacter }); actions.push({ - description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Add_index_signature_for_missing_property_0), [tokenName]), + description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Add_index_signature_for_property_0), [tokenName]), changes: indexSignatureChangeTracker.getChanges() }); } return actions; } + + function getActionForMethodDeclaration(): CodeAction | undefined { + if (token.parent.parent.kind === SyntaxKind.CallExpression) { + const callExpression = token.parent.parent; + const methodDeclaration = createMethodFromCallExpression(callExpression, tokenName, /*includeTypeScriptSyntax*/ true, makeStatic); + + const methodDeclarationChangeTracker = textChanges.ChangeTracker.fromCodeFixContext(context); + methodDeclarationChangeTracker.insertNodeAfter(classDeclarationSourceFile, classOpenBrace, methodDeclaration, { suffix: context.newLineCharacter }); + return { + description: formatStringFromArgs(getLocaleSpecificMessage(makeStatic ? + Diagnostics.Declare_method_0 : + Diagnostics.Declare_static_method_0), + [tokenName]), + changes: methodDeclarationChangeTracker.getChanges() + }; + } + } } } diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts index 5b81f71b6c9..c2c51d5c788 100644 --- a/src/services/codefixes/helpers.ts +++ b/src/services/codefixes/helpers.ts @@ -142,46 +142,50 @@ namespace ts.codefix { } } - export function createMethodFromCallExpression(callExpression: CallExpression, methodName: string): MethodDeclaration { - const argCount = callExpression.arguments.length; - const parameters: ParameterDeclaration[] = []; - for (let i = 0; i < argCount; i++) { - const typeNode = createKeywordTypeNode(SyntaxKind.AnyKeyword); - const newParameter = createParameter( - /*decorators*/ undefined, - /*modifiers*/ undefined, - /*dotDotDotToken*/ undefined, - `arg${i}`, - /*questionToken*/ undefined, - typeNode, - /*initializer*/ undefined); - parameters.push(newParameter); - } + export function createMethodFromCallExpression(callExpression: CallExpression, methodName: string, includeTypeScriptSyntax: boolean, makeStatic: boolean): MethodDeclaration { + const parameters = createDummyParameters(callExpression.arguments.length, /*names*/ undefined, /*minArgumentCount*/ undefined, includeTypeScriptSyntax); - const typeArgCount = callExpression.typeArguments ? callExpression.typeArguments.length : 0; let typeParameters: TypeParameterDeclaration[]; - for (let i = 0; i < typeArgCount; i++) { - const name = typeArgCount < 8 ? String.fromCharCode(CharacterCodes.T + i) : `T${i}`; - const typeParameter = createTypeParameterDeclaration(name, /*constraint*/ undefined, /*defaultType*/ undefined); - - (typeParameters ? typeParameters : typeParameters = []).push(typeParameter); + if (includeTypeScriptSyntax) { + const typeArgCount = callExpression.typeArguments ? callExpression.typeArguments.length : 0; + for (let i = 0; i < typeArgCount; i++) { + const name = typeArgCount < 8 ? String.fromCharCode(CharacterCodes.T + i) : `T${i}`; + const typeParameter = createTypeParameterDeclaration(name, /*constraint*/ undefined, /*defaultType*/ undefined); + (typeParameters ? typeParameters : typeParameters = []).push(typeParameter); + } } const newMethod = createMethod( /*decorators*/ undefined, - /*modifiers*/ undefined, + /*modifiers*/ makeStatic ? [createToken(SyntaxKind.StaticKeyword)] : undefined, /*asteriskToken*/ undefined, methodName, /*questionToken*/ undefined, typeParameters, parameters, - /*type*/ undefined, + /*type*/ includeTypeScriptSyntax ? createKeywordTypeNode(SyntaxKind.AnyKeyword) : undefined, createStubbedMethodBody() ); - return newMethod; } + function createDummyParameters(argCount: number, names: string[] | undefined, minArgumentCount: number | undefined, addAnyType: boolean) { + const parameters: ParameterDeclaration[] = []; + for (let i = 0; i < argCount; i++) { + const newParameter = createParameter( + /*decorators*/ undefined, + /*modifiers*/ undefined, + /*dotDotDotToken*/ undefined, + /*name*/ names && names[i] || `arg${i}`, + /*questionToken*/ minArgumentCount !== undefined && i >= minArgumentCount ? createToken(SyntaxKind.QuestionToken) : undefined, + /*type*/ addAnyType ? createKeywordTypeNode(SyntaxKind.AnyKeyword) : undefined, + /*initializer*/ undefined); + parameters.push(newParameter); + } + + return parameters; + } + function createMethodImplementingSignatures(signatures: Signature[], name: PropertyName, optional: boolean, modifiers: Modifier[] | undefined): MethodDeclaration { /** This is *a* signature with the maximal number of arguments, * such that if there is a "maximal" signature without rest arguments, @@ -203,19 +207,7 @@ namespace ts.codefix { const maxNonRestArgs = maxArgsSignature.parameters.length - (maxArgsSignature.hasRestParameter ? 1 : 0); const maxArgsParameterSymbolNames = maxArgsSignature.parameters.map(symbol => symbol.getName()); - const parameters: ParameterDeclaration[] = []; - for (let i = 0; i < maxNonRestArgs; i++) { - const anyType = createKeywordTypeNode(SyntaxKind.AnyKeyword); - const newParameter = createParameter( - /*decorators*/ undefined, - /*modifiers*/ undefined, - /*dotDotDotToken*/ undefined, - maxArgsParameterSymbolNames[i], - /*questionToken*/ i >= minArgumentCount ? createToken(SyntaxKind.QuestionToken) : undefined, - anyType, - /*initializer*/ undefined); - parameters.push(newParameter); - } + const parameters = createDummyParameters(maxNonRestArgs, maxArgsParameterSymbolNames, minArgumentCount, /*addAnyType*/ true); if (someSigHasRestParameter) { const anyArrayType = createArrayTypeNode(createKeywordTypeNode(SyntaxKind.AnyKeyword)); diff --git a/tests/cases/fourslash/codeFixUndeclaredAcrossFiles2.ts b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles2.ts index cc01f8d50ee..6064ee5ae30 100644 --- a/tests/cases/fourslash/codeFixUndeclaredAcrossFiles2.ts +++ b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles2.ts @@ -25,10 +25,10 @@ verify.applyCodeFix(/*errorCode*/undefined, 0); verify.rangeIs(` export class C { - m1() { + m1(): any { throw new Error("Method not implemented."); } - static m0(arg0, arg1, arg2) { + static m0(arg0: any, arg1: any, arg2: any): any { throw new Error("Method not implemented."); } x: number; From e6bcef7dc59a7bf826783453e08f2e2cf2fc1cb4 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 1 Jun 2017 09:19:34 -0700 Subject: [PATCH 09/23] Combining unknown type+value symbol->unknownSymbol Previously, when getExternalModuleMember tried to combine unknownSymbol from a type and unknownSymbol from a value, it combineValueAndTypeSymbol would create a new franken-symbol that was no longer equal to unknownSymbol. --- src/compiler/checker.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cfe2c5a6bf2..11bb737e986 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1364,6 +1364,9 @@ namespace ts { // An 'import { Point } from "graphics"' needs to create a symbol that combines the value side 'Point' // property with the type/namespace side interface 'Point'. function combineValueAndTypeSymbols(valueSymbol: Symbol, typeSymbol: Symbol): Symbol { + if (valueSymbol === unknownSymbol && typeSymbol === unknownSymbol) { + return unknownSymbol; + } if (valueSymbol.flags & (SymbolFlags.Type | SymbolFlags.Namespace)) { return valueSymbol; } From 9bcbeffcc7ab1d96caf9bb01738514171531e056 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 1 Jun 2017 09:21:31 -0700 Subject: [PATCH 10/23] Test reexport of a missing alias --- .../reexportedMissingAlias.errors.txt | 18 ++++++++++ .../reference/reexportedMissingAlias.js | 34 +++++++++++++++++++ .../cases/compiler/reexportedMissingAlias.ts | 9 +++++ 3 files changed, 61 insertions(+) create mode 100644 tests/baselines/reference/reexportedMissingAlias.errors.txt create mode 100644 tests/baselines/reference/reexportedMissingAlias.js create mode 100644 tests/cases/compiler/reexportedMissingAlias.ts diff --git a/tests/baselines/reference/reexportedMissingAlias.errors.txt b/tests/baselines/reference/reexportedMissingAlias.errors.txt new file mode 100644 index 00000000000..c22bf2da9d0 --- /dev/null +++ b/tests/baselines/reference/reexportedMissingAlias.errors.txt @@ -0,0 +1,18 @@ +tests/cases/compiler/second.d.ts(2,27): error TS2304: Cannot find name 'CompletelyMissing'. +tests/cases/compiler/second.d.ts(2,27): error TS2503: Cannot find namespace 'CompletelyMissing'. + + +==== tests/cases/compiler/second.d.ts (2 errors) ==== + // Fixes #15094 + export import Component = CompletelyMissing; + ~~~~~~~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'CompletelyMissing'. + ~~~~~~~~~~~~~~~~~ +!!! error TS2503: Cannot find namespace 'CompletelyMissing'. +==== tests/cases/compiler/first.d.ts (0 errors) ==== + import * as Second from './second'; + export = Second; +==== tests/cases/compiler/crash.ts (0 errors) ==== + import { Component } from './first'; + class C extends Component { } + \ No newline at end of file diff --git a/tests/baselines/reference/reexportedMissingAlias.js b/tests/baselines/reference/reexportedMissingAlias.js new file mode 100644 index 00000000000..792ea3eb5c2 --- /dev/null +++ b/tests/baselines/reference/reexportedMissingAlias.js @@ -0,0 +1,34 @@ +//// [tests/cases/compiler/reexportedMissingAlias.ts] //// + +//// [second.d.ts] +// Fixes #15094 +export import Component = CompletelyMissing; +//// [first.d.ts] +import * as Second from './second'; +export = Second; +//// [crash.ts] +import { Component } from './first'; +class C extends Component { } + + +//// [crash.js] +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +exports.__esModule = true; +var first_1 = require("./first"); +var C = (function (_super) { + __extends(C, _super); + function C() { + return _super !== null && _super.apply(this, arguments) || this; + } + return C; +}(first_1.Component)); diff --git a/tests/cases/compiler/reexportedMissingAlias.ts b/tests/cases/compiler/reexportedMissingAlias.ts new file mode 100644 index 00000000000..b430cd526c8 --- /dev/null +++ b/tests/cases/compiler/reexportedMissingAlias.ts @@ -0,0 +1,9 @@ +// Fixes #15094 +// @Filename: second.d.ts +export import Component = CompletelyMissing; +// @Filename: first.d.ts +import * as Second from './second'; +export = Second; +// @Filename: crash.ts +import { Component } from './first'; +class C extends Component { } From 5030d0f468f7dcfd4bbc2f0031e9787e933ef5b6 Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Thu, 1 Jun 2017 10:49:08 -0700 Subject: [PATCH 11/23] Use factory for all fixes --- src/services/codefixes/fixAddMissingMember.ts | 37 ++++++++++++------- .../fourslash/codeFixAddMissingMember5.ts | 6 ++- .../fourslash/codeFixAddMissingMember7.ts | 6 ++- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/services/codefixes/fixAddMissingMember.ts b/src/services/codefixes/fixAddMissingMember.ts index 358c2255789..0859500e2d2 100644 --- a/src/services/codefixes/fixAddMissingMember.ts +++ b/src/services/codefixes/fixAddMissingMember.ts @@ -82,15 +82,19 @@ namespace ts.codefix { const className = classDeclaration.name.getText(); + const staticInitialization = createStatement(createAssignment( + createPropertyAccess(createIdentifier(className), tokenName), + createIdentifier("undefined"))); + + const staticInitializationChangeTracker = textChanges.ChangeTracker.fromCodeFixContext(context); + staticInitializationChangeTracker.insertNodeAfter( + classDeclarationSourceFile, + classDeclaration, + staticInitialization, + { suffix: context.newLineCharacter }); const initializeStaticAction = { description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Initialize_static_property_0), [tokenName]), - changes: [{ - fileName: classDeclarationSourceFile.fileName, - textChanges: [{ - span: { start: classDeclaration.getEnd(), length: 0 }, - newText: `${context.newLineCharacter}${className}.${tokenName} = undefined;${context.newLineCharacter}` - }] - }] + changes: staticInitializationChangeTracker.getChanges() }; (actions || (actions = [])).push(initializeStaticAction); @@ -102,15 +106,20 @@ namespace ts.codefix { return actions; } + const propertyInitialization = createStatement(createAssignment( + createPropertyAccess(createThis(), tokenName), + createIdentifier("undefined"))); + + const propertyInitializationChangeTracker = textChanges.ChangeTracker.fromCodeFixContext(context); + propertyInitializationChangeTracker.insertNodeAt( + classDeclarationSourceFile, + classConstructor.body.getEnd() - 1, + propertyInitialization, + { prefix: context.newLineCharacter, suffix: context.newLineCharacter }); + const initializeAction = { description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Initialize_property_0_in_the_constructor), [tokenName]), - changes: [{ - fileName: classDeclarationSourceFile.fileName, - textChanges: [{ - span: { start: classConstructor.body.getEnd() - 1, length: 0 }, - newText: `this.${tokenName} = undefined;${context.newLineCharacter}` - }] - }] + changes: propertyInitializationChangeTracker.getChanges() }; (actions || (actions = [])).push(initializeAction); diff --git a/tests/cases/fourslash/codeFixAddMissingMember5.ts b/tests/cases/fourslash/codeFixAddMissingMember5.ts index cbabc0ba6c5..53d47e9a8d3 100644 --- a/tests/cases/fourslash/codeFixAddMissingMember5.ts +++ b/tests/cases/fourslash/codeFixAddMissingMember5.ts @@ -11,9 +11,11 @@ ////} ////|] -verify.rangeAfterCodeFix(`class C { +verify.applyCodeFix(/*errorCode*/ undefined, /*index*/ 0); +verify.currentFileContentIs(`class C { static method() { ()=>{ this.foo === 10 }; } } -C.foo = undefined;`, /*includeWhiteSpace*/false, /*errorCode*/ undefined, /*index*/ 0); \ No newline at end of file +C.foo = undefined; +`); \ No newline at end of file diff --git a/tests/cases/fourslash/codeFixAddMissingMember7.ts b/tests/cases/fourslash/codeFixAddMissingMember7.ts index 0e937a3ab6e..04c3efc86b8 100644 --- a/tests/cases/fourslash/codeFixAddMissingMember7.ts +++ b/tests/cases/fourslash/codeFixAddMissingMember7.ts @@ -9,7 +9,9 @@ ////} ////|] -verify.rangeAfterCodeFix(`class C { +verify.applyCodeFix(/*errorCode*/ undefined, /*index*/ 2) +verify.currentFileContentIs(`class C { static p = ()=>{ this.foo === 10 }; } -C.foo = undefined;`, /*includeWhiteSpace*/false, /*errorCode*/ undefined, /*index*/ 2); \ No newline at end of file +C.foo = undefined; +`); From f9123aa5cc7a748299877db134da383949d0dd1e Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Thu, 1 Jun 2017 11:01:00 -0700 Subject: [PATCH 12/23] rename fourslash method --- src/harness/fourslash.ts | 2 +- tests/cases/fourslash/codeFixAddMissingMember5.ts | 2 +- tests/cases/fourslash/codeFixAddMissingMember7.ts | 2 +- tests/cases/fourslash/codeFixUndeclaredAcrossFiles1.ts | 8 ++++---- tests/cases/fourslash/codeFixUndeclaredAcrossFiles2.ts | 8 ++++---- tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts | 8 ++++---- tests/cases/fourslash/codeFixUndeclaredMethod.ts | 6 +++--- tests/cases/fourslash/fourslash.ts | 2 +- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 0cbf98cebf7..f1146919e49 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -3816,7 +3816,7 @@ namespace FourSlashInterface { this.state.verifyRangeIs(expectedText, includeWhiteSpace); } - public applyCodeFix(errorCode?: number, index?: number): void { + public getAndApplyCodeFix(errorCode?: number, index?: number): void { this.state.getAndApplyCodeActions(errorCode, index); } diff --git a/tests/cases/fourslash/codeFixAddMissingMember5.ts b/tests/cases/fourslash/codeFixAddMissingMember5.ts index 53d47e9a8d3..db893cb61d3 100644 --- a/tests/cases/fourslash/codeFixAddMissingMember5.ts +++ b/tests/cases/fourslash/codeFixAddMissingMember5.ts @@ -11,7 +11,7 @@ ////} ////|] -verify.applyCodeFix(/*errorCode*/ undefined, /*index*/ 0); +verify.getAndApplyCodeFix(/*errorCode*/ undefined, /*index*/ 0); verify.currentFileContentIs(`class C { static method() { ()=>{ this.foo === 10 }; diff --git a/tests/cases/fourslash/codeFixAddMissingMember7.ts b/tests/cases/fourslash/codeFixAddMissingMember7.ts index 04c3efc86b8..8ac7f2b5aff 100644 --- a/tests/cases/fourslash/codeFixAddMissingMember7.ts +++ b/tests/cases/fourslash/codeFixAddMissingMember7.ts @@ -9,7 +9,7 @@ ////} ////|] -verify.applyCodeFix(/*errorCode*/ undefined, /*index*/ 2) +verify.getAndApplyCodeFix(/*errorCode*/ undefined, /*index*/ 2) verify.currentFileContentIs(`class C { static p = ()=>{ this.foo === 10 }; } diff --git a/tests/cases/fourslash/codeFixUndeclaredAcrossFiles1.ts b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles1.ts index 830259e3ca7..435b78ba3fa 100644 --- a/tests/cases/fourslash/codeFixUndeclaredAcrossFiles1.ts +++ b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles1.ts @@ -17,10 +17,10 @@ //// static y: string; //// } -verify.applyCodeFix(/*errorCode*/undefined, 0); -verify.applyCodeFix(/*errorCode*/undefined, 0); -verify.applyCodeFix(/*errorCode*/undefined, 0); -verify.applyCodeFix(/*errorCode*/undefined, 0); +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); verify.rangeIs(` y: { [x: string]: any; }; diff --git a/tests/cases/fourslash/codeFixUndeclaredAcrossFiles2.ts b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles2.ts index 6064ee5ae30..9f40c967658 100644 --- a/tests/cases/fourslash/codeFixUndeclaredAcrossFiles2.ts +++ b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles2.ts @@ -18,10 +18,10 @@ //// constructor() { } //// }|] -verify.applyCodeFix(/*errorCode*/undefined, 0); -verify.applyCodeFix(/*errorCode*/undefined, 0); -verify.applyCodeFix(/*errorCode*/undefined, 0); -verify.applyCodeFix(/*errorCode*/undefined, 0); +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); verify.rangeIs(` export class C { diff --git a/tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts b/tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts index 94ad3f77615..0669a9ee462 100644 --- a/tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts +++ b/tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts @@ -9,10 +9,10 @@ //// } //// } -verify.applyCodeFix(/*errorCode*/undefined, 0); -verify.applyCodeFix(/*errorCode*/undefined, 0); -verify.applyCodeFix(/*errorCode*/undefined, 0); -verify.applyCodeFix(/*errorCode*/undefined, 0); +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); verify.rangeIs(` static prop2: string; diff --git a/tests/cases/fourslash/codeFixUndeclaredMethod.ts b/tests/cases/fourslash/codeFixUndeclaredMethod.ts index 1f842a5bcf1..6a61f8421aa 100644 --- a/tests/cases/fourslash/codeFixUndeclaredMethod.ts +++ b/tests/cases/fourslash/codeFixUndeclaredMethod.ts @@ -10,9 +10,9 @@ //// } //// } -verify.applyCodeFix(/*errorCode*/undefined, 0); -verify.applyCodeFix(/*errorCode*/undefined, 0); -verify.applyCodeFix(/*errorCode*/undefined, 0); +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); verify.rangeIs(` foo3(): any { diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index b0f731dcdea..3e80b005625 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -237,7 +237,7 @@ declare namespace FourSlashInterface { DocCommentTemplate(expectedText: string, expectedOffset: number, empty?: boolean): void; noDocCommentTemplate(): void; rangeAfterCodeFix(expectedText: string, includeWhiteSpace?: boolean, errorCode?: number, index?: number): void - applyCodeFix(errorCode?: number, index?: number): void; + getAndApplyCodeFix(errorCode?: number, index?: number): void; rangeIs(expectedText: string, includeWhiteSpace?: boolean): void; fileAfterApplyingRefactorAtMarker(markerName: string, expectedContent: string, refactorNameToApply: string, formattingOptions?: FormatCodeOptions): void; importFixAtPosition(expectedTextArray: string[], errorCode?: number): void; From f2163fecbd2d8b988f1f1897f8646e28af2742ba Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Thu, 1 Jun 2017 11:09:08 -0700 Subject: [PATCH 13/23] use length helper --- src/services/codefixes/helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts index c2c51d5c788..81aae4c0e5e 100644 --- a/src/services/codefixes/helpers.ts +++ b/src/services/codefixes/helpers.ts @@ -147,7 +147,7 @@ namespace ts.codefix { let typeParameters: TypeParameterDeclaration[]; if (includeTypeScriptSyntax) { - const typeArgCount = callExpression.typeArguments ? callExpression.typeArguments.length : 0; + const typeArgCount = length(callExpression.typeArguments); for (let i = 0; i < typeArgCount; i++) { const name = typeArgCount < 8 ? String.fromCharCode(CharacterCodes.T + i) : `T${i}`; const typeParameter = createTypeParameterDeclaration(name, /*constraint*/ undefined, /*defaultType*/ undefined); From 6742f9dcd8ddabdfbbdb9df98f6ef65a45ba042d Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Thu, 1 Jun 2017 11:17:24 -0700 Subject: [PATCH 14/23] remove comment --- .../codeFixUndeclaredInStaticMethod.ts | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts b/tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts index 0669a9ee462..75be5420e43 100644 --- a/tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts +++ b/tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts @@ -24,21 +24,3 @@ verify.rangeIs(` throw new Error("Method not implemented."); } `); - -// class A { -// static prop2: string; -// static prop1: number; -// static m2(arg0: any, arg1: any): any { -// throw new Error("Method not implemented."); -// } -// static m1(arg0: any, arg1: any, arg2: any): any { -// throw new Error("Method not implemented."); -// } -// static foo0() { -// this.m1(1,2,3); -// A.m2(1,2); -// this.prop1 = 10; -// A.prop2 = "asdf"; -// } -// } - From c1d466a716eef632ecbc44a2fb53b6bdc92694bc Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Thu, 1 Jun 2017 14:12:25 -0700 Subject: [PATCH 15/23] suppress type annotations in js file --- src/services/codefixes/fixAddMissingMember.ts | 8 ++++---- .../fourslash/codeFixUndeclaredAcrossFiles2.ts | 13 ++++++------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/services/codefixes/fixAddMissingMember.ts b/src/services/codefixes/fixAddMissingMember.ts index 0859500e2d2..80dd16c5f58 100644 --- a/src/services/codefixes/fixAddMissingMember.ts +++ b/src/services/codefixes/fixAddMissingMember.ts @@ -70,7 +70,7 @@ namespace ts.codefix { function getActionsForAddMissingMemberInJavaScriptFile(classDeclaration: ClassLikeDeclaration, makeStatic: boolean): CodeAction[] | undefined { let actions: CodeAction[]; - const methodCodeAction = getActionForMethodDeclaration(); + const methodCodeAction = getActionForMethodDeclaration(/*includeTypeScriptSyntax*/ false); if (methodCodeAction) { actions = [methodCodeAction]; } @@ -130,7 +130,7 @@ namespace ts.codefix { function getActionsForAddMissingMemberInTypeScriptFile(classDeclaration: ClassLikeDeclaration, makeStatic: boolean): CodeAction[] | undefined { let actions: CodeAction[]; - const methodCodeAction = getActionForMethodDeclaration(); + const methodCodeAction = getActionForMethodDeclaration(/*includeTypeScriptSyntax*/ true); if (methodCodeAction) { actions = [methodCodeAction]; } @@ -189,10 +189,10 @@ namespace ts.codefix { return actions; } - function getActionForMethodDeclaration(): CodeAction | undefined { + function getActionForMethodDeclaration(includeTypeScriptSyntax: boolean): CodeAction | undefined { if (token.parent.parent.kind === SyntaxKind.CallExpression) { const callExpression = token.parent.parent; - const methodDeclaration = createMethodFromCallExpression(callExpression, tokenName, /*includeTypeScriptSyntax*/ true, makeStatic); + const methodDeclaration = createMethodFromCallExpression(callExpression, tokenName, includeTypeScriptSyntax, makeStatic); const methodDeclarationChangeTracker = textChanges.ChangeTracker.fromCodeFixContext(context); methodDeclarationChangeTracker.insertNodeAfter(classDeclarationSourceFile, classOpenBrace, methodDeclaration, { suffix: context.newLineCharacter }); diff --git a/tests/cases/fourslash/codeFixUndeclaredAcrossFiles2.ts b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles2.ts index 9f40c967658..04e2afc667c 100644 --- a/tests/cases/fourslash/codeFixUndeclaredAcrossFiles2.ts +++ b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles2.ts @@ -13,10 +13,10 @@ // @Filename: f1.js //// [|export class C { -//// x: number; -//// static y: string; //// constructor() { } -//// }|] +//// } +//// +//// |] verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); @@ -25,16 +25,15 @@ verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); verify.rangeIs(` export class C { - m1(): any { + m1() { throw new Error("Method not implemented."); } - static m0(arg0: any, arg1: any, arg2: any): any { + static m0(arg0, arg1, arg2) { throw new Error("Method not implemented."); } - x: number; - static y: string; constructor() { this.y = undefined; } } +C.x = undefined; `); \ No newline at end of file From 2fb9ab798c2c3615bb51dba22b6855fe41eea4bc Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Thu, 1 Jun 2017 16:03:11 -0700 Subject: [PATCH 16/23] repond to feedback --- src/compiler/checker.ts | 1 - src/compiler/types.ts | 1 - src/services/codefixes/fixAddMissingMember.ts | 3 ++- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e9b197f2863..f7450bb6da6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -110,7 +110,6 @@ namespace ts { getParameterType: getTypeAtPosition, getReturnTypeOfSignature, getNonNullableType, - getBaseTypeVariableOfClass, typeToTypeNode: nodeBuilder.typeToTypeNode, indexInfoToIndexSignatureDeclaration: nodeBuilder.indexInfoToIndexSignatureDeclaration, signatureToSignatureDeclaration: nodeBuilder.signatureToSignatureDeclaration, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index ee02d37addb..561d84b5d71 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2530,7 +2530,6 @@ namespace ts { */ /* @internal */ getParameterType(signature: Signature, parameterIndex: number): Type; getNonNullableType(type: Type): Type; - /* @internal */ getBaseTypeVariableOfClass(symbol: Symbol): Type | undefined; /** Note that the resulting nodes cannot be checked. */ typeToTypeNode(type: Type, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): TypeNode; diff --git a/src/services/codefixes/fixAddMissingMember.ts b/src/services/codefixes/fixAddMissingMember.ts index 80dd16c5f58..1587b47c01b 100644 --- a/src/services/codefixes/fixAddMissingMember.ts +++ b/src/services/codefixes/fixAddMissingMember.ts @@ -49,7 +49,8 @@ namespace ts.codefix { const symbol = leftExpressionType.symbol; if (symbol.flags & SymbolFlags.Class) { classDeclaration = symbol.declarations && symbol.declarations[0]; - if (getObjectFlags(leftExpressionType) & ObjectFlags.Anonymous && symbol.flags & SymbolFlags.Class && !checker.getBaseTypeVariableOfClass(symbol)) { + if (leftExpressionType !== checker.getDeclaredTypeOfSymbol(symbol)) { + // The expression is a class symbol but the type is not the instance-side. makeStatic = true; } } From 40f22ec6e29323890c834594ead2b63ff30a39b7 Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Thu, 1 Jun 2017 16:41:46 -0700 Subject: [PATCH 17/23] respond to comment --- src/compiler/checker.ts | 4 ++++ src/compiler/utilities.ts | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f7450bb6da6..cb9c44afdbb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -681,6 +681,10 @@ namespace ts { return nodeLinks[nodeId] || (nodeLinks[nodeId] = { flags: 0 }); } + function getObjectFlags(type: Type): ObjectFlags { + return type.flags & TypeFlags.Object ? (type).objectFlags : 0; + } + function isGlobalSourceFile(node: Node) { return node.kind === SyntaxKind.SourceFile && !isExternalOrCommonJsModule(node); } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 187d90559f1..506d2728ffd 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -733,10 +733,6 @@ namespace ts { return false; } - export function getObjectFlags(type: Type): ObjectFlags { - return type.flags & TypeFlags.Object ? (type).objectFlags : 0; - } - export function isChildOfNodeWithKind(node: Node, kind: SyntaxKind): boolean { while (node) { if (node.kind === kind) { From ccc60c8b3b75476c4b11abb6ab4d2e6f06214f8f Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 5 Jun 2017 10:49:20 -0700 Subject: [PATCH 18/23] Revert "[Master] wip-dynamic import" (#16264) --- src/compiler/binder.ts | 6 +- src/compiler/checker.ts | 70 +-------- src/compiler/commandLineParser.ts | 3 +- src/compiler/diagnosticMessages.json | 36 +---- src/compiler/emitter.ts | 1 - src/compiler/parser.ts | 67 ++++----- src/compiler/program.ts | 13 +- src/compiler/transformer.ts | 1 - src/compiler/transformers/module/module.ts | 137 ++---------------- src/compiler/transformers/module/system.ts | 74 ++++------ src/compiler/types.ts | 43 ++---- src/compiler/utilities.ts | 4 - src/harness/harness.ts | 1 - src/harness/unittests/commandLineParsing.ts | 2 +- .../convertCompilerOptionsFromJson.ts | 2 +- src/services/services.ts | 3 +- .../reference/importCallExpression1ESNext.js | 27 ---- .../importCallExpression1ESNext.symbols | 28 ---- .../importCallExpression1ESNext.types | 39 ----- .../reference/importCallExpression2ESNext.js | 29 ---- .../importCallExpression2ESNext.symbols | 33 ----- .../importCallExpression2ESNext.types | 45 ------ .../reference/importCallExpression3ESNext.js | 27 ---- .../importCallExpression3ESNext.symbols | 29 ---- .../importCallExpression3ESNext.types | 37 ----- .../reference/importCallExpression4ESNext.js | 49 ------- .../importCallExpression4ESNext.symbols | 61 -------- .../importCallExpression4ESNext.types | 83 ----------- .../importCallExpression5ESNext.errors.txt | 31 ---- .../reference/importCallExpression5ESNext.js | 33 ----- .../importCallExpression6ESNext.errors.txt | 25 ---- .../reference/importCallExpression6ESNext.js | 33 ----- ...tCallExpressionCheckReturntype1.errors.txt | 30 ---- .../importCallExpressionCheckReturntype1.js | 35 ----- .../importCallExpressionDeclarationEmit1.js | 35 ----- ...portCallExpressionDeclarationEmit1.symbols | 36 ----- ...importCallExpressionDeclarationEmit1.types | 47 ------ ...tCallExpressionDeclarationEmit2.errors.txt | 10 -- .../importCallExpressionDeclarationEmit2.js | 16 -- .../importCallExpressionDeclarationEmit3.js | 31 ---- ...portCallExpressionDeclarationEmit3.symbols | 28 ---- ...importCallExpressionDeclarationEmit3.types | 37 ----- .../reference/importCallExpressionES5AMD.js | 35 ----- .../importCallExpressionES5AMD.symbols | 28 ---- .../importCallExpressionES5AMD.types | 39 ----- .../reference/importCallExpressionES5CJS.js | 30 ---- .../importCallExpressionES5CJS.symbols | 28 ---- .../importCallExpressionES5CJS.types | 39 ----- .../importCallExpressionES5System.js | 46 ------ .../importCallExpressionES5System.symbols | 28 ---- .../importCallExpressionES5System.types | 39 ----- .../reference/importCallExpressionES5UMD.js | 52 ------- .../importCallExpressionES5UMD.symbols | 28 ---- .../importCallExpressionES5UMD.types | 39 ----- ...portCallExpressionErrorInES2015.errors.txt | 24 --- .../importCallExpressionErrorInES2015.js | 27 ---- ...mportCallExpressionGrammarError.errors.txt | 34 ----- .../importCallExpressionGrammarError.js | 19 --- .../reference/importCallExpressionInAMD1.js | 35 ----- .../importCallExpressionInAMD1.symbols | 28 ---- .../importCallExpressionInAMD1.types | 39 ----- .../reference/importCallExpressionInAMD2.js | 39 ----- .../importCallExpressionInAMD2.symbols | 34 ----- .../importCallExpressionInAMD2.types | 46 ------ .../reference/importCallExpressionInAMD3.js | 35 ----- .../importCallExpressionInAMD3.symbols | 29 ---- .../importCallExpressionInAMD3.types | 37 ----- .../reference/importCallExpressionInAMD4.js | 63 -------- .../importCallExpressionInAMD4.symbols | 61 -------- .../importCallExpressionInAMD4.types | 83 ----------- .../reference/importCallExpressionInCJS1.js | 30 ---- .../importCallExpressionInCJS1.symbols | 28 ---- .../importCallExpressionInCJS1.types | 39 ----- .../reference/importCallExpressionInCJS2.js | 40 ----- .../importCallExpressionInCJS2.symbols | 34 ----- .../importCallExpressionInCJS2.types | 51 ------- .../reference/importCallExpressionInCJS3.js | 34 ----- .../importCallExpressionInCJS3.symbols | 34 ----- .../importCallExpressionInCJS3.types | 46 ------ .../reference/importCallExpressionInCJS4.js | 30 ---- .../importCallExpressionInCJS4.symbols | 29 ---- .../importCallExpressionInCJS4.types | 37 ----- .../reference/importCallExpressionInCJS5.js | 56 ------- .../importCallExpressionInCJS5.symbols | 61 -------- .../importCallExpressionInCJS5.types | 83 ----------- .../importCallExpressionInScriptContext1.js | 17 --- ...portCallExpressionInScriptContext1.symbols | 11 -- ...importCallExpressionInScriptContext1.types | 14 -- ...tCallExpressionInScriptContext2.errors.txt | 12 -- .../importCallExpressionInScriptContext2.js | 19 --- .../importCallExpressionInSystem1.js | 46 ------ .../importCallExpressionInSystem1.symbols | 28 ---- .../importCallExpressionInSystem1.types | 39 ----- .../importCallExpressionInSystem2.js | 50 ------- .../importCallExpressionInSystem2.symbols | 34 ----- .../importCallExpressionInSystem2.types | 46 ------ .../importCallExpressionInSystem3.js | 46 ------ .../importCallExpressionInSystem3.symbols | 29 ---- .../importCallExpressionInSystem3.types | 37 ----- .../importCallExpressionInSystem4.js | 80 ---------- .../importCallExpressionInSystem4.symbols | 61 -------- .../importCallExpressionInSystem4.types | 83 ----------- .../reference/importCallExpressionInUMD1.js | 52 ------- .../importCallExpressionInUMD1.symbols | 28 ---- .../importCallExpressionInUMD1.types | 39 ----- .../reference/importCallExpressionInUMD2.js | 56 ------- .../importCallExpressionInUMD2.symbols | 34 ----- .../importCallExpressionInUMD2.types | 46 ------ .../reference/importCallExpressionInUMD3.js | 52 ------- .../importCallExpressionInUMD3.symbols | 29 ---- .../importCallExpressionInUMD3.types | 37 ----- .../reference/importCallExpressionInUMD4.js | 88 ----------- .../importCallExpressionInUMD4.symbols | 61 -------- .../importCallExpressionInUMD4.types | 83 ----------- .../importCallExpressionReturnPromiseOfAny.js | 61 -------- ...rtCallExpressionReturnPromiseOfAny.symbols | 89 ------------ ...portCallExpressionReturnPromiseOfAny.types | 118 --------------- ...sionSpecifierNotStringTypeError.errors.txt | 31 ---- ...llExpressionSpecifierNotStringTypeError.js | 25 ---- ...tCallExpressionWithTypeArgument.errors.txt | 18 --- .../importCallExpressionWithTypeArgument.js | 22 --- ...ons module-kind is out-of-range.errors.txt | 4 +- ...s target-script is out-of-range.errors.txt | 4 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../importCallExpression1ESNext.ts | 15 -- .../importCallExpression2ESNext.ts | 16 -- .../importCallExpression3ESNext.ts | 14 -- .../importCallExpression4ESNext.ts | 26 ---- .../importCallExpression5ESNext.ts | 20 --- .../importCallExpression6ESNext.ts | 19 --- .../importCallExpressionCheckReturntype1.ts | 17 --- .../importCallExpressionDeclarationEmit1.ts | 19 --- .../importCallExpressionDeclarationEmit2.ts | 9 -- .../importCallExpressionDeclarationEmit3.ts | 15 -- .../importCallExpressionES5AMD.ts | 16 -- .../importCallExpressionES5CJS.ts | 16 -- .../importCallExpressionES5System.ts | 16 -- .../importCallExpressionES5UMD.ts | 16 -- .../importCallExpressionErrorInES2015.ts | 15 -- .../importCallExpressionGrammarError.ts | 14 -- .../importCallExpressionInAMD1.ts | 15 -- .../importCallExpressionInAMD2.ts | 17 --- .../importCallExpressionInAMD3.ts | 14 -- .../importCallExpressionInAMD4.ts | 26 ---- .../importCallExpressionInCJS1.ts | 15 -- .../importCallExpressionInCJS2.ts | 19 --- .../importCallExpressionInCJS3.ts | 17 --- .../importCallExpressionInCJS4.ts | 14 -- .../importCallExpressionInCJS5.ts | 26 ---- .../importCallExpressionInScriptContext1.ts | 10 -- .../importCallExpressionInScriptContext2.ts | 11 -- .../importCallExpressionInSystem1.ts | 15 -- .../importCallExpressionInSystem2.ts | 17 --- .../importCallExpressionInSystem3.ts | 14 -- .../importCallExpressionInSystem4.ts | 26 ---- .../importCallExpressionInUMD1.ts | 15 -- .../importCallExpressionInUMD2.ts | 17 --- .../importCallExpressionInUMD3.ts | 14 -- .../importCallExpressionInUMD4.ts | 26 ---- .../importCallExpressionReturnPromiseOfAny.ts | 34 ----- ...llExpressionSpecifierNotStringTypeError.ts | 17 --- .../importCallExpressionWithTypeArgument.ts | 14 -- 169 files changed, 103 insertions(+), 5271 deletions(-) delete mode 100644 tests/baselines/reference/importCallExpression1ESNext.js delete mode 100644 tests/baselines/reference/importCallExpression1ESNext.symbols delete mode 100644 tests/baselines/reference/importCallExpression1ESNext.types delete mode 100644 tests/baselines/reference/importCallExpression2ESNext.js delete mode 100644 tests/baselines/reference/importCallExpression2ESNext.symbols delete mode 100644 tests/baselines/reference/importCallExpression2ESNext.types delete mode 100644 tests/baselines/reference/importCallExpression3ESNext.js delete mode 100644 tests/baselines/reference/importCallExpression3ESNext.symbols delete mode 100644 tests/baselines/reference/importCallExpression3ESNext.types delete mode 100644 tests/baselines/reference/importCallExpression4ESNext.js delete mode 100644 tests/baselines/reference/importCallExpression4ESNext.symbols delete mode 100644 tests/baselines/reference/importCallExpression4ESNext.types delete mode 100644 tests/baselines/reference/importCallExpression5ESNext.errors.txt delete mode 100644 tests/baselines/reference/importCallExpression5ESNext.js delete mode 100644 tests/baselines/reference/importCallExpression6ESNext.errors.txt delete mode 100644 tests/baselines/reference/importCallExpression6ESNext.js delete mode 100644 tests/baselines/reference/importCallExpressionCheckReturntype1.errors.txt delete mode 100644 tests/baselines/reference/importCallExpressionCheckReturntype1.js delete mode 100644 tests/baselines/reference/importCallExpressionDeclarationEmit1.js delete mode 100644 tests/baselines/reference/importCallExpressionDeclarationEmit1.symbols delete mode 100644 tests/baselines/reference/importCallExpressionDeclarationEmit1.types delete mode 100644 tests/baselines/reference/importCallExpressionDeclarationEmit2.errors.txt delete mode 100644 tests/baselines/reference/importCallExpressionDeclarationEmit2.js delete mode 100644 tests/baselines/reference/importCallExpressionDeclarationEmit3.js delete mode 100644 tests/baselines/reference/importCallExpressionDeclarationEmit3.symbols delete mode 100644 tests/baselines/reference/importCallExpressionDeclarationEmit3.types delete mode 100644 tests/baselines/reference/importCallExpressionES5AMD.js delete mode 100644 tests/baselines/reference/importCallExpressionES5AMD.symbols delete mode 100644 tests/baselines/reference/importCallExpressionES5AMD.types delete mode 100644 tests/baselines/reference/importCallExpressionES5CJS.js delete mode 100644 tests/baselines/reference/importCallExpressionES5CJS.symbols delete mode 100644 tests/baselines/reference/importCallExpressionES5CJS.types delete mode 100644 tests/baselines/reference/importCallExpressionES5System.js delete mode 100644 tests/baselines/reference/importCallExpressionES5System.symbols delete mode 100644 tests/baselines/reference/importCallExpressionES5System.types delete mode 100644 tests/baselines/reference/importCallExpressionES5UMD.js delete mode 100644 tests/baselines/reference/importCallExpressionES5UMD.symbols delete mode 100644 tests/baselines/reference/importCallExpressionES5UMD.types delete mode 100644 tests/baselines/reference/importCallExpressionErrorInES2015.errors.txt delete mode 100644 tests/baselines/reference/importCallExpressionErrorInES2015.js delete mode 100644 tests/baselines/reference/importCallExpressionGrammarError.errors.txt delete mode 100644 tests/baselines/reference/importCallExpressionGrammarError.js delete mode 100644 tests/baselines/reference/importCallExpressionInAMD1.js delete mode 100644 tests/baselines/reference/importCallExpressionInAMD1.symbols delete mode 100644 tests/baselines/reference/importCallExpressionInAMD1.types delete mode 100644 tests/baselines/reference/importCallExpressionInAMD2.js delete mode 100644 tests/baselines/reference/importCallExpressionInAMD2.symbols delete mode 100644 tests/baselines/reference/importCallExpressionInAMD2.types delete mode 100644 tests/baselines/reference/importCallExpressionInAMD3.js delete mode 100644 tests/baselines/reference/importCallExpressionInAMD3.symbols delete mode 100644 tests/baselines/reference/importCallExpressionInAMD3.types delete mode 100644 tests/baselines/reference/importCallExpressionInAMD4.js delete mode 100644 tests/baselines/reference/importCallExpressionInAMD4.symbols delete mode 100644 tests/baselines/reference/importCallExpressionInAMD4.types delete mode 100644 tests/baselines/reference/importCallExpressionInCJS1.js delete mode 100644 tests/baselines/reference/importCallExpressionInCJS1.symbols delete mode 100644 tests/baselines/reference/importCallExpressionInCJS1.types delete mode 100644 tests/baselines/reference/importCallExpressionInCJS2.js delete mode 100644 tests/baselines/reference/importCallExpressionInCJS2.symbols delete mode 100644 tests/baselines/reference/importCallExpressionInCJS2.types delete mode 100644 tests/baselines/reference/importCallExpressionInCJS3.js delete mode 100644 tests/baselines/reference/importCallExpressionInCJS3.symbols delete mode 100644 tests/baselines/reference/importCallExpressionInCJS3.types delete mode 100644 tests/baselines/reference/importCallExpressionInCJS4.js delete mode 100644 tests/baselines/reference/importCallExpressionInCJS4.symbols delete mode 100644 tests/baselines/reference/importCallExpressionInCJS4.types delete mode 100644 tests/baselines/reference/importCallExpressionInCJS5.js delete mode 100644 tests/baselines/reference/importCallExpressionInCJS5.symbols delete mode 100644 tests/baselines/reference/importCallExpressionInCJS5.types delete mode 100644 tests/baselines/reference/importCallExpressionInScriptContext1.js delete mode 100644 tests/baselines/reference/importCallExpressionInScriptContext1.symbols delete mode 100644 tests/baselines/reference/importCallExpressionInScriptContext1.types delete mode 100644 tests/baselines/reference/importCallExpressionInScriptContext2.errors.txt delete mode 100644 tests/baselines/reference/importCallExpressionInScriptContext2.js delete mode 100644 tests/baselines/reference/importCallExpressionInSystem1.js delete mode 100644 tests/baselines/reference/importCallExpressionInSystem1.symbols delete mode 100644 tests/baselines/reference/importCallExpressionInSystem1.types delete mode 100644 tests/baselines/reference/importCallExpressionInSystem2.js delete mode 100644 tests/baselines/reference/importCallExpressionInSystem2.symbols delete mode 100644 tests/baselines/reference/importCallExpressionInSystem2.types delete mode 100644 tests/baselines/reference/importCallExpressionInSystem3.js delete mode 100644 tests/baselines/reference/importCallExpressionInSystem3.symbols delete mode 100644 tests/baselines/reference/importCallExpressionInSystem3.types delete mode 100644 tests/baselines/reference/importCallExpressionInSystem4.js delete mode 100644 tests/baselines/reference/importCallExpressionInSystem4.symbols delete mode 100644 tests/baselines/reference/importCallExpressionInSystem4.types delete mode 100644 tests/baselines/reference/importCallExpressionInUMD1.js delete mode 100644 tests/baselines/reference/importCallExpressionInUMD1.symbols delete mode 100644 tests/baselines/reference/importCallExpressionInUMD1.types delete mode 100644 tests/baselines/reference/importCallExpressionInUMD2.js delete mode 100644 tests/baselines/reference/importCallExpressionInUMD2.symbols delete mode 100644 tests/baselines/reference/importCallExpressionInUMD2.types delete mode 100644 tests/baselines/reference/importCallExpressionInUMD3.js delete mode 100644 tests/baselines/reference/importCallExpressionInUMD3.symbols delete mode 100644 tests/baselines/reference/importCallExpressionInUMD3.types delete mode 100644 tests/baselines/reference/importCallExpressionInUMD4.js delete mode 100644 tests/baselines/reference/importCallExpressionInUMD4.symbols delete mode 100644 tests/baselines/reference/importCallExpressionInUMD4.types delete mode 100644 tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js delete mode 100644 tests/baselines/reference/importCallExpressionReturnPromiseOfAny.symbols delete mode 100644 tests/baselines/reference/importCallExpressionReturnPromiseOfAny.types delete mode 100644 tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.errors.txt delete mode 100644 tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js delete mode 100644 tests/baselines/reference/importCallExpressionWithTypeArgument.errors.txt delete mode 100644 tests/baselines/reference/importCallExpressionWithTypeArgument.js delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpression1ESNext.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpression2ESNext.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpression3ESNext.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpression4ESNext.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpression5ESNext.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpression6ESNext.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionCheckReturntype1.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit1.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit2.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit3.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionES5AMD.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionES5CJS.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionES5System.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionES5UMD.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionErrorInES2015.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionInAMD1.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionInAMD2.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionInAMD3.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionInAMD4.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionInCJS1.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionInCJS2.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionInCJS3.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionInCJS4.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionInCJS5.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionInScriptContext1.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionInScriptContext2.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionInSystem1.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionInSystem2.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionInSystem3.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionInSystem4.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionInUMD1.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionInUMD2.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionInUMD3.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionInUMD4.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionReturnPromiseOfAny.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts delete mode 100644 tests/cases/conformance/dynamicImport/importCallExpressionWithTypeArgument.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 22209e2e41e..d55f3650c10 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2333,7 +2333,7 @@ namespace ts { // A common practice in node modules is to set 'export = module.exports = {}', this ensures that 'exports' // is still pointing to 'module.exports'. // We do not want to consider this as 'export=' since a module can have only one of these. - // Similarly we do not want to treat 'module.exports = exports' as an 'export='. + // Similarlly we do not want to treat 'module.exports = exports' as an 'export='. const assignedExpression = getRightMostAssignedExpression(node.right); if (isEmptyObjectLiteral(assignedExpression) || isExportsOrModuleExportsOrAlias(assignedExpression)) { // Mark it as a module in case there are no other exports in the file @@ -2741,10 +2741,6 @@ namespace ts { transformFlags |= TransformFlags.AssertES2015; } - if (expression.kind === SyntaxKind.ImportKeyword) { - transformFlags |= TransformFlags.ContainsDynamicImport; - } - node.transformFlags = transformFlags | TransformFlags.HasComputedFlags; return transformFlags & ~TransformFlags.ArrayLiteralOrCallOrNewExcludes; } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7bcdc419b5b..1b3084f9cbd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8356,12 +8356,6 @@ namespace ts { /** * This is *not* a bi-directional relationship. * If one needs to check both directions for comparability, use a second call to this function or 'checkTypeComparableTo'. - * - * A type S is comparable to a type T if some (but not necessarily all) of the possible values of S are also possible values of T. - * It is used to check following cases: - * - the types of the left and right sides of equality/inequality operators (`===`, `!==`, `==`, `!=`). - * - the types of `case` clause expressions and their respective `switch` expressions. - * - the type of an expression in a type assertion with the type being asserted. */ function isTypeComparableTo(source: Type, target: Type): boolean { return isTypeRelatedTo(source, target, comparableRelation); @@ -16164,35 +16158,6 @@ namespace ts { return getReturnTypeOfSignature(signature); } - function checkImportCallExpression(node: ImportCall): Type { - // Check grammar of dynamic import - checkGrammarArguments(node, node.arguments) || checkGrammarImportCallExpression(node); - - if (node.arguments.length === 0) { - return createPromiseReturnType(node, anyType); - } - const specifier = node.arguments[0]; - const specifierType = checkExpressionCached(specifier); - // Even though multiple arugments is grammatically incorrect, type-check extra arguments for completion - for (let i = 1; i < node.arguments.length; ++i) { - checkExpressionCached(node.arguments[i]); - } - - if (specifierType.flags & TypeFlags.Undefined || specifierType.flags & TypeFlags.Null || !isTypeAssignableTo(specifierType, stringType)) { - error(specifier, Diagnostics.Dynamic_import_s_specifier_must_be_of_type_string_but_here_has_type_0, typeToString(specifierType)); - } - - // resolveExternalModuleName will return undefined if the moduleReferenceExpression is not a string literal - const moduleSymbol = resolveExternalModuleName(node, specifier); - if (moduleSymbol) { - const esModuleSymbol = resolveESModuleSymbol(moduleSymbol, specifier, /*dontRecursivelyResolve*/ true); - if (esModuleSymbol) { - return createPromiseReturnType(node, getTypeOfSymbol(esModuleSymbol)); - } - } - return createPromiseReturnType(node, anyType); - } - function isCommonJsRequire(node: Node) { if (!isRequireCall(node, /*checkArgumentIsStringLiteral*/ true)) { return false; @@ -16399,18 +16364,14 @@ namespace ts { return emptyObjectType; } - function createPromiseReturnType(func: FunctionLikeDeclaration | ImportCall, promisedType: Type) { + function createPromiseReturnType(func: FunctionLikeDeclaration, promisedType: Type) { const promiseType = createPromiseType(promisedType); if (promiseType === emptyObjectType) { - error(func, isImportCall(func) ? - Diagnostics.A_dynamic_import_call_returns_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option : - Diagnostics.An_async_function_or_method_must_return_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option); + error(func, Diagnostics.An_async_function_or_method_must_return_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option); return unknownType; } else if (!getGlobalPromiseConstructorSymbol(/*reportErrors*/ true)) { - error(func, isImportCall(func) ? - Diagnostics.A_dynamic_import_call_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option : - Diagnostics.An_async_function_or_method_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option); + error(func, Diagnostics.An_async_function_or_method_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option); } return promiseType; @@ -17769,10 +17730,6 @@ namespace ts { case SyntaxKind.ElementAccessExpression: return checkIndexedAccess(node); case SyntaxKind.CallExpression: - if ((node).expression.kind === SyntaxKind.ImportKeyword) { - return checkImportCallExpression(node); - } - /* falls through */ case SyntaxKind.NewExpression: return checkCallExpression(node); case SyntaxKind.TaggedTemplateExpression: @@ -24698,27 +24655,6 @@ namespace ts { }); return result; } - - function checkGrammarImportCallExpression(node: ImportCall): boolean { - if (modulekind === ModuleKind.ES2015) { - return grammarErrorOnNode(node, Diagnostics.Dynamic_import_cannot_be_used_when_targeting_ECMAScript_2015_modules); - } - - if (node.typeArguments) { - return grammarErrorOnNode(node, Diagnostics.Dynamic_import_cannot_have_type_arguments); - } - - const arguments = node.arguments; - if (arguments.length !== 1) { - return grammarErrorOnNode(node, Diagnostics.Dynamic_import_must_have_one_specifier_as_an_argument); - } - - // see: parseArgumentOrArrayLiteralElement...we use this function which parse arguments of callExpression to parse specifier for dynamic import. - // parseArgumentOrArrayLiteralElement allows spread element to be in an argument list which is not allowed as specifier in dynamic import. - if (isSpreadElement(arguments[0])) { - return grammarErrorOnNode(arguments[0], Diagnostics.Specifier_of_dynamic_import_cannot_be_spread_element); - } - } } /** Like 'isDeclarationName', but returns true for LHS of `import { x as y }` or `export { x as y }`. */ diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 23efd047e46..fa0c8140bb6 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -100,12 +100,11 @@ namespace ts { "umd": ModuleKind.UMD, "es6": ModuleKind.ES2015, "es2015": ModuleKind.ES2015, - "esnext": ModuleKind.ESNext }), paramType: Diagnostics.KIND, showInSimplifiedHelpView: true, category: Diagnostics.Basic_Options, - description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_es2015_or_ESNext, + description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015, }, { name: "lib", diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 34f25009190..e8ad8a033ff 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -883,23 +883,6 @@ "category": "Error", "code": 1322 }, - "Dynamic import cannot be used when targeting ECMAScript 2015 modules.": { - "category": "Error", - "code": 1323 - }, - "Dynamic import must have one specifier as an argument.": { - "category": "Error", - "code": 1324 - }, - "Specifier of dynamic import cannot be spread element.": { - "category": "Error", - "code": 1325 - }, - "Dynamic import cannot have type arguments": { - "category": "Error", - "code": 1326 - }, - "Duplicate identifier '{0}'.": { "category": "Error", "code": 2300 @@ -1944,6 +1927,10 @@ "category": "Error", "code": 2649 }, + "Cannot emit namespaced JSX elements in React.": { + "category": "Error", + "code": 2650 + }, "A member initializer in a enum declaration cannot reference members declared after it, including members defined in other enums.": { "category": "Error", "code": 2651 @@ -2176,14 +2163,6 @@ "category": "Error", "code": 2710 }, - "A dynamic import call returns a 'Promise'. Make sure you have a declaration for 'Promise' or include 'ES2015' in your `--lib` option.": { - "category": "Error", - "code": 2711 - }, - "A dynamic import call in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your `--lib` option.": { - "category": "Error", - "code": 2712 - }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", @@ -2650,7 +2629,7 @@ "category": "Message", "code": 6015 }, - "Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'.": { + "Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'.": { "category": "Message", "code": 6016 }, @@ -3386,11 +3365,6 @@ "category": "Error", "code": 7035 }, - "Dynamic import's specifier must be of type 'string', but here has type '{0}'.": { - "category": "Error", - "code": 7036 - }, - "You cannot rename this element.": { "category": "Error", "code": 8000 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 1e6cc3b12db..1d2f75fcd60 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -676,7 +676,6 @@ namespace ts { case SyntaxKind.SuperKeyword: case SyntaxKind.TrueKeyword: case SyntaxKind.ThisKeyword: - case SyntaxKind.ImportKeyword: writeTokenNode(node); return; diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index a3f440fd6c0..849f97bbbaf 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -46,16 +46,10 @@ namespace ts { } } - /** - * Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes - * stored in properties. If a 'cbNodes' callback is specified, it is invoked for embedded arrays; otherwise, - * embedded arrays are flattened and the 'cbNode' callback is invoked for each element. If a callback returns - * a truthy value, iteration stops and that value is returned. Otherwise, undefined is returned. - * - * @param node a given node to visit its children - * @param cbNode a callback to be invoked for all child nodes - * @param cbNodeArray a callback to be invoked for embedded array - */ + // Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes + // stored in properties. If a 'cbNodes' callback is specified, it is invoked for embedded arrays; otherwise, + // embedded arrays are flattened and the 'cbNode' callback is invoked for each element. If a callback returns + // a truthy value, iteration stops and that value is returned. Otherwise, undefined is returned. export function forEachChild(node: Node, cbNode: (node: Node) => T | undefined, cbNodeArray?: (nodes: NodeArray) => T | undefined): T | undefined { if (!node) { return; @@ -2415,7 +2409,7 @@ namespace ts { if (token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken) { return parseSignatureMember(SyntaxKind.CallSignature); } - if (token() === SyntaxKind.NewKeyword && lookAhead(nextTokenIsOpenParenOrLessThan)) { + if (token() === SyntaxKind.NewKeyword && lookAhead(isStartOfConstructSignature)) { return parseSignatureMember(SyntaxKind.ConstructSignature); } const fullStart = getNodePos(); @@ -2426,7 +2420,7 @@ namespace ts { return parsePropertyOrMethodSignature(fullStart, modifiers); } - function nextTokenIsOpenParenOrLessThan() { + function isStartOfConstructSignature() { nextToken(); return token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken; } @@ -2782,7 +2776,6 @@ namespace ts { case SyntaxKind.SlashToken: case SyntaxKind.SlashEqualsToken: case SyntaxKind.Identifier: - case SyntaxKind.ImportKeyword: return true; default: return isIdentifier(); @@ -3516,10 +3509,10 @@ namespace ts { * 5) --UnaryExpression[?Yield] */ if (isUpdateExpression()) { - const updateExpression = parseUpdateExpression(); + const incrementExpression = parseIncrementExpression(); return token() === SyntaxKind.AsteriskAsteriskToken ? - parseBinaryExpressionRest(getBinaryOperatorPrecedence(), updateExpression) : - updateExpression; + parseBinaryExpressionRest(getBinaryOperatorPrecedence(), incrementExpression) : + incrementExpression; } /** @@ -3585,7 +3578,7 @@ namespace ts { } // falls through default: - return parseUpdateExpression(); + return parseIncrementExpression(); } } @@ -3601,7 +3594,7 @@ namespace ts { */ function isUpdateExpression(): boolean { // This function is called inside parseUnaryExpression to decide - // whether to call parseSimpleUnaryExpression or call parseUpdateExpression directly + // whether to call parseSimpleUnaryExpression or call parseIncrementExpression directly switch (token()) { case SyntaxKind.PlusToken: case SyntaxKind.MinusToken: @@ -3625,9 +3618,9 @@ namespace ts { } /** - * Parse ES7 UpdateExpression. UpdateExpression is used instead of ES6's PostFixExpression. + * Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression. * - * ES7 UpdateExpression[yield]: + * ES7 IncrementExpression[yield]: * 1) LeftHandSideExpression[?yield] * 2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++ * 3) LeftHandSideExpression[?yield] [[no LineTerminator here]]-- @@ -3635,7 +3628,7 @@ namespace ts { * 5) --LeftHandSideExpression[?yield] * In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression */ - function parseUpdateExpression(): UpdateExpression { + function parseIncrementExpression(): IncrementExpression { if (token() === SyntaxKind.PlusPlusToken || token() === SyntaxKind.MinusMinusToken) { const node = createNode(SyntaxKind.PrefixUnaryExpression); node.operator = token(); @@ -3685,27 +3678,17 @@ namespace ts { // CallExpression Arguments // CallExpression[Expression] // CallExpression.IdentifierName - // import (AssignmentExpression) - // super Arguments + // super ( ArgumentListopt ) // super.IdentifierName // - // Because of the recursion in these calls, we need to bottom out first. There are three - // bottom out states we can run into: 1) We see 'super' which must start either of - // the last two CallExpression productions. 2) We see 'import' which must start import call. - // 3)we have a MemberExpression which either completes the LeftHandSideExpression, - // or starts the beginning of the first four CallExpression productions. - let expression: MemberExpression; - if (token() === SyntaxKind.ImportKeyword && lookAhead(nextTokenIsOpenParenOrLessThan)) { - // We don't want to eagerly consume all import keyword as import call expression so we look a head to find "(" - // For example: - // var foo3 = require("subfolder - // import * as foo1 from "module-from-node -> we want this import to be a statement rather than import call expression - sourceFile.flags |= NodeFlags.PossiblyContainDynamicImport; - expression = parseTokenNode(); - } - else { - expression = token() === SyntaxKind.SuperKeyword ? parseSuperExpression() : parseMemberExpressionOrHigher(); - } + // Because of the recursion in these calls, we need to bottom out first. There are two + // bottom out states we can run into. Either we see 'super' which must start either of + // the last two CallExpression productions. Or we have a MemberExpression which either + // completes the LeftHandSideExpression, or starts the beginning of the first four + // CallExpression productions. + const expression = token() === SyntaxKind.SuperKeyword + ? parseSuperExpression() + : parseMemberExpressionOrHigher(); // Now, we *may* be complete. However, we might have consumed the start of a // CallExpression. As such, we need to consume the rest of it here to be complete. @@ -3713,7 +3696,7 @@ namespace ts { } function parseMemberExpressionOrHigher(): MemberExpression { - // Note: to make our lives simpler, we decompose the NewExpression productions and + // Note: to make our lives simpler, we decompose the the NewExpression productions and // place ObjectCreationExpression and FunctionExpression into PrimaryExpression. // like so: // @@ -4807,11 +4790,11 @@ namespace ts { // however, we say they are here so that we may gracefully parse them and error later. case SyntaxKind.CatchKeyword: case SyntaxKind.FinallyKeyword: - case SyntaxKind.ImportKeyword: return true; case SyntaxKind.ConstKeyword: case SyntaxKind.ExportKeyword: + case SyntaxKind.ImportKeyword: return isStartOfDeclaration(); case SyntaxKind.AsyncKeyword: diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 4b9c81d4239..834122b3584 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1366,7 +1366,6 @@ namespace ts { const isJavaScriptFile = isSourceFileJavaScript(file); const isExternalModuleFile = isExternalModule(file); - // file.imports may not be undefined if there exists dynamic import let imports: LiteralExpression[]; let moduleAugmentations: LiteralExpression[]; let ambientModules: string[]; @@ -1386,8 +1385,8 @@ namespace ts { for (const node of file.statements) { collectModuleReferences(node, /*inAmbientModule*/ false); - if ((file.flags & NodeFlags.PossiblyContainDynamicImport) || isJavaScriptFile) { - collectDynamicImportOrRequireCalls(node); + if (isJavaScriptFile) { + collectRequireCalls(node); } } @@ -1450,16 +1449,12 @@ namespace ts { } } - function collectDynamicImportOrRequireCalls(node: Node): void { + function collectRequireCalls(node: Node): void { if (isRequireCall(node, /*checkArgumentIsStringLiteral*/ true)) { (imports || (imports = [])).push((node).arguments[0]); } - // we have to check the argument list has length of 1. We will still have to process these even though we have parsing error. - else if (isImportCall(node) && node.arguments.length === 1 && node.arguments[0].kind === SyntaxKind.StringLiteral) { - (imports || (imports = [])).push((node).arguments[0]); - } else { - forEachChild(node, collectDynamicImportOrRequireCalls); + forEachChild(node, collectRequireCalls); } } } diff --git a/src/compiler/transformer.ts b/src/compiler/transformer.ts index f0c827d8396..75f9c43c6fe 100644 --- a/src/compiler/transformer.ts +++ b/src/compiler/transformer.ts @@ -15,7 +15,6 @@ namespace ts { function getModuleTransformer(moduleKind: ModuleKind): TransformerFactory { switch (moduleKind) { - case ModuleKind.ESNext: case ModuleKind.ES2015: return transformES2015Module; case ModuleKind.System: diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index b2e1c1c70a9..b3e544a3f8b 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -46,7 +46,6 @@ namespace ts { let currentSourceFile: SourceFile; // The current file. let currentModuleInfo: ExternalModuleInfo; // The ExternalModuleInfo for the current file. let noSubstitution: boolean[]; // Set of nodes for which substitution rules should be ignored. - let needUMDDynamicImportHelper: boolean; return transformSourceFile; @@ -56,7 +55,7 @@ namespace ts { * @param node The SourceFile node. */ function transformSourceFile(node: SourceFile) { - if (node.isDeclarationFile || !(isExternalModule(node) || compilerOptions.isolatedModules || node.transformFlags & TransformFlags.ContainsDynamicImport)) { + if (node.isDeclarationFile || !(isExternalModule(node) || compilerOptions.isolatedModules)) { return node; } @@ -67,9 +66,9 @@ namespace ts { // Perform the transformation. const transformModule = getTransformModuleDelegate(moduleKind); const updated = transformModule(node); + currentSourceFile = undefined; currentModuleInfo = undefined; - needUMDDynamicImportHelper = false; return aggregateTransformFlags(updated); } @@ -108,7 +107,6 @@ namespace ts { // we need to inform the emitter to add the __export helper. addEmitHelper(updated, exportStarHelper); } - addEmitHelpers(updated, context.readEmitHelpers()); return updated; } @@ -413,9 +411,6 @@ namespace ts { // we need to inform the emitter to add the __export helper. addEmitHelper(body, exportStarHelper); } - if (needUMDDynamicImportHelper) { - addEmitHelper(body, dynamicImportUMDHelper); - } return body; } @@ -493,110 +488,12 @@ namespace ts { return visitEndOfDeclarationMarker(node); default: - return visitEachChild(node, importCallExpressionVisitor, context); + // This visitor does not descend into the tree, as export/import statements + // are only transformed at the top level of a file. + return node; } } - function importCallExpressionVisitor(node: Node): VisitResult { - // This visitor does not need to descend into the tree if there is no dynamic import, - // as export/import statements are only transformed at the top level of a file. - if (!(node.transformFlags & TransformFlags.ContainsDynamicImport)) { - return node; - } - - if (isImportCall(node)) { - return visitImportCallExpression(node); - } - else { - return visitEachChild(node, importCallExpressionVisitor, context); - } - } - - function visitImportCallExpression(node: ImportCall): Expression { - switch (compilerOptions.module) { - case ModuleKind.CommonJS: - return transformImportCallExpressionCommonJS(node); - case ModuleKind.AMD: - return transformImportCallExpressionAMD(node); - case ModuleKind.UMD: - return transformImportCallExpressionUMD(node); - } - Debug.fail("All supported module kind in this transformation step should have been handled"); - } - - function transformImportCallExpressionUMD(node: ImportCall): Expression { - // (function (factory) { - // ... (regular UMD) - // } - // })(function (require, exports, useSyncRequire) { - // "use strict"; - // Object.defineProperty(exports, "__esModule", { value: true }); - // var __syncRequire = typeof module === "object" && typeof module.exports === "object"; - // var __resolved = new Promise(function (resolve) { resolve(); }); - // ..... - // __syncRequire - // ? __resolved.then(function () { return require(x); }) /*CommonJs Require*/ - // : new Promise(function (_a, _b) { require([x], _a, _b); }); /*Amd Require*/ - // }); - needUMDDynamicImportHelper = true; - return createConditional( - /*condition*/ createIdentifier("__syncRequire"), - /*whenTrue*/ transformImportCallExpressionCommonJS(node), - /*whenFalse*/ transformImportCallExpressionAMD(node) - ); - } - - function transformImportCallExpressionAMD(node: ImportCall): Expression { - // improt("./blah") - // emit as - // define(["require", "exports", "blah"], function (require, exports) { - // ... - // new Promise(function (_a, _b) { require([x], _a, _b); }); /*Amd Require*/ - // }); - const resolve = createUniqueName("resolve"); - const reject = createUniqueName("reject"); - return createNew( - createIdentifier("Promise"), - /*typeArguments*/ undefined, - [createFunctionExpression( - /*modifiers*/ undefined, - /*asteriskToken*/ undefined, - /*name*/ undefined, - /*typeParameters*/ undefined, - [createParameter(/*decorator*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, /*name*/ resolve), - createParameter(/*decorator*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, /*name*/ reject)], - /*type*/ undefined, - createBlock([createStatement( - createCall( - createIdentifier("require"), - /*typeArguments*/ undefined, - [createArrayLiteral([firstOrUndefined(node.arguments) || createOmittedExpression()]), resolve, reject] - ))]) - )]); - } - - function transformImportCallExpressionCommonJS(node: ImportCall): Expression { - // import("./blah") - // emit as - // Promise.resolve().then(function () { return require(x); }) /*CommonJs Require*/ - // We have to wrap require in then callback so that require is done in asynchronously - // if we simply do require in resolve callback in Promise constructor. We will execute the loading immediately - return createCall( - createPropertyAccess( - createCall(createPropertyAccess(createIdentifier("Promise"), "resolve"), /*typeArguments*/ undefined, /*argumentsArray*/ []), - "then"), - /*typeArguments*/ undefined, - [createFunctionExpression( - /*modifiers*/ undefined, - /*asteriskToken*/ undefined, - /*name*/ undefined, - /*typeParameters*/ undefined, - /*parameters*/ undefined, - /*type*/ undefined, - createBlock([createReturn(createCall(createIdentifier("require"), /*typeArguments*/ undefined, node.arguments))]) - )]); - } - /** * Visits an ImportDeclaration node. * @@ -889,9 +786,9 @@ namespace ts { node.asteriskToken, getDeclarationName(node, /*allowComments*/ true, /*allowSourceMaps*/ true), /*typeParameters*/ undefined, - visitNodes(node.parameters, importCallExpressionVisitor), + node.parameters, /*type*/ undefined, - visitEachChild(node.body, importCallExpressionVisitor, context) + node.body ), /*location*/ node ), @@ -900,7 +797,7 @@ namespace ts { ); } else { - statements = append(statements, visitEachChild(node, importCallExpressionVisitor, context)); + statements = append(statements, node); } if (hasAssociatedEndOfDeclarationMarker(node)) { @@ -931,7 +828,7 @@ namespace ts { visitNodes(node.modifiers, modifierVisitor, isModifier), getDeclarationName(node, /*allowComments*/ true, /*allowSourceMaps*/ true), /*typeParameters*/ undefined, - visitNodes(node.heritageClauses, importCallExpressionVisitor), + node.heritageClauses, node.members ), node @@ -941,7 +838,7 @@ namespace ts { ); } else { - statements = append(statements, visitEachChild(node, importCallExpressionVisitor, context)); + statements = append(statements, node); } if (hasAssociatedEndOfDeclarationMarker(node)) { @@ -993,7 +890,7 @@ namespace ts { } } else { - statements = append(statements, visitEachChild(node, importCallExpressionVisitor, context)); + statements = append(statements, node); } if (hasAssociatedEndOfDeclarationMarker(node)) { @@ -1016,7 +913,7 @@ namespace ts { function transformInitializedVariable(node: VariableDeclaration): Expression { if (isBindingPattern(node.name)) { return flattenDestructuringAssignment( - visitNode(node, importCallExpressionVisitor), + node, /*visitor*/ undefined, context, FlattenLevel.All, @@ -1033,7 +930,7 @@ namespace ts { ), /*location*/ node.name ), - visitNode(node.initializer, importCallExpressionVisitor) + node.initializer ); } } @@ -1600,12 +1497,4 @@ namespace ts { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; }` }; - - // emit helper for dynamic import - const dynamicImportUMDHelper: EmitHelper = { - name: "typescript:dynamicimport-sync-require", - scoped: true, - text: ` - var __syncRequire = typeof module === "object" && typeof module.exports === "object";` - }; } diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index fa126d1faa7..e6351c0965e 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -50,7 +50,7 @@ namespace ts { * @param node The SourceFile node. */ function transformSourceFile(node: SourceFile) { - if (node.isDeclarationFile || !(isEffectiveExternalModule(node, compilerOptions) || node.transformFlags & TransformFlags.ContainsDynamicImport)) { + if (node.isDeclarationFile || !(isExternalModule(node) || compilerOptions.isolatedModules)) { return node; } @@ -646,7 +646,7 @@ namespace ts { return undefined; } - const expression = visitNode(node.expression, destructuringAndImportCallVisitor, isExpression); + const expression = visitNode(node.expression, destructuringVisitor, isExpression); const original = node.original; if (original && hasAssociatedEndOfDeclarationMarker(original)) { // Defer exports until we encounter an EndOfDeclarationMarker node @@ -673,12 +673,12 @@ namespace ts { node.asteriskToken, getDeclarationName(node, /*allowComments*/ true, /*allowSourceMaps*/ true), /*typeParameters*/ undefined, - visitNodes(node.parameters, destructuringAndImportCallVisitor, isParameterDeclaration), + visitNodes(node.parameters, destructuringVisitor, isParameterDeclaration), /*type*/ undefined, - visitNode(node.body, destructuringAndImportCallVisitor, isBlock))); + visitNode(node.body, destructuringVisitor, isBlock))); } else { - hoistedStatements = append(hoistedStatements, visitEachChild(node, destructuringAndImportCallVisitor, context)); + hoistedStatements = append(hoistedStatements, node); } if (hasAssociatedEndOfDeclarationMarker(node)) { @@ -716,8 +716,8 @@ namespace ts { /*modifiers*/ undefined, node.name, /*typeParameters*/ undefined, - visitNodes(node.heritageClauses, destructuringAndImportCallVisitor, isHeritageClause), - visitNodes(node.members, destructuringAndImportCallVisitor, isClassElement) + visitNodes(node.heritageClauses, destructuringVisitor, isHeritageClause), + visitNodes(node.members, destructuringVisitor, isClassElement) ), node ) @@ -747,7 +747,7 @@ namespace ts { */ function visitVariableStatement(node: VariableStatement): VisitResult { if (!shouldHoistVariableDeclarationList(node.declarationList)) { - return visitNode(node, destructuringAndImportCallVisitor, isStatement); + return visitNode(node, destructuringVisitor, isStatement); } let expressions: Expression[]; @@ -820,13 +820,13 @@ namespace ts { return isBindingPattern(node.name) ? flattenDestructuringAssignment( node, - destructuringAndImportCallVisitor, + destructuringVisitor, context, FlattenLevel.All, /*needsValue*/ false, createAssignment ) - : createAssignment(node.name, visitNode(node.initializer, destructuringAndImportCallVisitor, isExpression)); + : createAssignment(node.name, visitNode(node.initializer, destructuringVisitor, isExpression)); } /** @@ -1204,7 +1204,7 @@ namespace ts { return visitEndOfDeclarationMarker(node); default: - return destructuringAndImportCallVisitor(node); + return destructuringVisitor(node); } } @@ -1220,8 +1220,8 @@ namespace ts { node = updateFor( node, visitForInitializer(node.initializer), - visitNode(node.condition, destructuringAndImportCallVisitor, isExpression), - visitNode(node.incrementor, destructuringAndImportCallVisitor, isExpression), + visitNode(node.condition, destructuringVisitor, isExpression), + visitNode(node.incrementor, destructuringVisitor, isExpression), visitNode(node.statement, nestedElementVisitor, isStatement) ); @@ -1241,7 +1241,7 @@ namespace ts { node = updateForIn( node, visitForInitializer(node.initializer), - visitNode(node.expression, destructuringAndImportCallVisitor, isExpression), + visitNode(node.expression, destructuringVisitor, isExpression), visitNode(node.statement, nestedElementVisitor, isStatement, liftToBlock) ); @@ -1262,7 +1262,7 @@ namespace ts { node, node.awaitModifier, visitForInitializer(node.initializer), - visitNode(node.expression, destructuringAndImportCallVisitor, isExpression), + visitNode(node.expression, destructuringVisitor, isExpression), visitNode(node.statement, nestedElementVisitor, isStatement, liftToBlock) ); @@ -1313,7 +1313,7 @@ namespace ts { return updateDo( node, visitNode(node.statement, nestedElementVisitor, isStatement, liftToBlock), - visitNode(node.expression, destructuringAndImportCallVisitor, isExpression) + visitNode(node.expression, destructuringVisitor, isExpression) ); } @@ -1325,7 +1325,7 @@ namespace ts { function visitWhileStatement(node: WhileStatement): VisitResult { return updateWhile( node, - visitNode(node.expression, destructuringAndImportCallVisitor, isExpression), + visitNode(node.expression, destructuringVisitor, isExpression), visitNode(node.statement, nestedElementVisitor, isStatement, liftToBlock) ); } @@ -1351,7 +1351,7 @@ namespace ts { function visitWithStatement(node: WithStatement): VisitResult { return updateWith( node, - visitNode(node.expression, destructuringAndImportCallVisitor, isExpression), + visitNode(node.expression, destructuringVisitor, isExpression), visitNode(node.statement, nestedElementVisitor, isStatement, liftToBlock) ); } @@ -1364,7 +1364,7 @@ namespace ts { function visitSwitchStatement(node: SwitchStatement): VisitResult { return updateSwitch( node, - visitNode(node.expression, destructuringAndImportCallVisitor, isExpression), + visitNode(node.expression, destructuringVisitor, isExpression), visitNode(node.caseBlock, nestedElementVisitor, isCaseBlock) ); } @@ -1395,7 +1395,7 @@ namespace ts { function visitCaseClause(node: CaseClause): VisitResult { return updateCaseClause( node, - visitNode(node.expression, destructuringAndImportCallVisitor, isExpression), + visitNode(node.expression, destructuringVisitor, isExpression), visitNodes(node.statements, nestedElementVisitor, isStatement) ); } @@ -1461,43 +1461,19 @@ namespace ts { * * @param node The node to visit. */ - function destructuringAndImportCallVisitor(node: Node): VisitResult { + function destructuringVisitor(node: Node): VisitResult { if (node.transformFlags & TransformFlags.DestructuringAssignment && node.kind === SyntaxKind.BinaryExpression) { return visitDestructuringAssignment(node); } - else if (isImportCall(node)) { - return visitImportCallExpression(node); - } - else if ((node.transformFlags & TransformFlags.ContainsDestructuringAssignment) || (node.transformFlags & TransformFlags.ContainsDynamicImport)) { - return visitEachChild(node, destructuringAndImportCallVisitor, context); + else if (node.transformFlags & TransformFlags.ContainsDestructuringAssignment) { + return visitEachChild(node, destructuringVisitor, context); } else { return node; } } - function visitImportCallExpression(node: ImportCall): Expression { - // import("./blah") - // emit as - // System.register([], function (_export, _context) { - // return { - // setters: [], - // execute: () => { - // _context.import('./blah'); - // } - // }; - // }); - return createCall( - createPropertyAccess( - contextObject, - createIdentifier("import") - ), - /*typeArguments*/ undefined, - node.arguments - ); - } - /** * Visits a DestructuringAssignment to flatten destructuring to exported symbols. * @@ -1507,14 +1483,14 @@ namespace ts { if (hasExportedReferenceInDestructuringTarget(node.left)) { return flattenDestructuringAssignment( node, - destructuringAndImportCallVisitor, + destructuringVisitor, context, FlattenLevel.All, /*needsValue*/ true ); } - return visitEachChild(node, destructuringAndImportCallVisitor, context); + return visitEachChild(node, destructuringVisitor, context); } /** diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 8fb3d98fca8..ed1d5dcbe23 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -395,7 +395,6 @@ namespace ts { // Enum value count Count, - // Markers FirstAssignment = EqualsToken, LastAssignment = CaretEqualsToken, @@ -450,14 +449,6 @@ namespace ts { ThisNodeOrAnySubNodesHasError = 1 << 17, // If this node or any of its children had an error HasAggregatedChildData = 1 << 18, // If we've computed data from children and cached it in this node - // This flag will be set to true when the parse encounter dynamic import so that post-parsing process of module resolution - // will not walk the tree if the flag is not set. However, this flag is just a approximation because once it is set, the flag never get reset. - // (hence it is named "possiblyContainDynamicImport"). - // During editing, if dynamic import is remove, incremental parsing will *NOT* update this flag. This will then causes walking of the tree during module resolution. - // However, the removal operation should not occur often and in the case of the removal, it is likely that users will add back the import anyway. - // The advantage of this approach is its simplicity. For the case of batch compilation, we garuntee that users won't have to pay the price of walking the tree if dynamic import isn't used. - PossiblyContainDynamicImport = 1 << 19, - BlockScoped = Let | Const, ReachabilityCheckFlags = HasImplicitReturn | HasExplicitReturn, @@ -1010,10 +1001,8 @@ namespace ts { _unaryExpressionBrand: any; } - /** Deprecated, please use UpdateExpression */ - export type IncrementExpression = UpdateExpression; - export interface UpdateExpression extends UnaryExpression { - _updateExpressionBrand: any; + export interface IncrementExpression extends UnaryExpression { + _incrementExpressionBrand: any; } // see: https://tc39.github.io/ecma262/#prod-UpdateExpression @@ -1024,9 +1013,10 @@ namespace ts { | SyntaxKind.PlusToken | SyntaxKind.MinusToken | SyntaxKind.TildeToken - | SyntaxKind.ExclamationToken; + | SyntaxKind.ExclamationToken + ; - export interface PrefixUnaryExpression extends UpdateExpression { + export interface PrefixUnaryExpression extends IncrementExpression { kind: SyntaxKind.PrefixUnaryExpression; operator: PrefixUnaryOperator; operand: UnaryExpression; @@ -1038,13 +1028,13 @@ namespace ts { | SyntaxKind.MinusMinusToken ; - export interface PostfixUnaryExpression extends UpdateExpression { + export interface PostfixUnaryExpression extends IncrementExpression { kind: SyntaxKind.PostfixUnaryExpression; operand: LeftHandSideExpression; operator: PostfixUnaryOperator; } - export interface LeftHandSideExpression extends UpdateExpression { + export interface LeftHandSideExpression extends IncrementExpression { _leftHandSideExpressionBrand: any; } @@ -1072,10 +1062,6 @@ namespace ts { kind: SyntaxKind.SuperKeyword; } - export interface ImportExpression extends PrimaryExpression { - kind: SyntaxKind.ImportKeyword; - } - export interface DeleteExpression extends UnaryExpression { kind: SyntaxKind.DeleteExpression; expression: UnaryExpression; @@ -1468,7 +1454,10 @@ namespace ts { } // see: https://tc39.github.io/ecma262/#prod-SuperProperty - export type SuperProperty = SuperPropertyAccessExpression | SuperElementAccessExpression; + export type SuperProperty + = SuperPropertyAccessExpression + | SuperElementAccessExpression + ; export interface CallExpression extends LeftHandSideExpression, Declaration { kind: SyntaxKind.CallExpression; @@ -1482,10 +1471,6 @@ namespace ts { expression: SuperExpression; } - export interface ImportCall extends CallExpression { - expression: ImportExpression; - } - export interface ExpressionWithTypeArguments extends TypeNode { kind: SyntaxKind.ExpressionWithTypeArguments; parent?: HeritageClause; @@ -3579,7 +3564,6 @@ namespace ts { UMD = 3, System = 4, ES2015 = 5, - ESNext = 6 } export const enum JsxEmit { @@ -3964,11 +3948,6 @@ namespace ts { ContainsYield = 1 << 24, ContainsHoistedDeclarationOrCompletion = 1 << 25, - ContainsDynamicImport = 1 << 26, - - // Please leave this as 1 << 29. - // It is the maximum bit we can set before we outgrow the size of a v8 small integer (SMI) on an x86 system. - // It is a good reminder of how much room we have left HasComputedFlags = 1 << 29, // Transform flags have been computed. // Assertions diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 96aae0e3888..b52ace78615 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -596,10 +596,6 @@ namespace ts { return n.kind === SyntaxKind.CallExpression && (n).expression.kind === SyntaxKind.SuperKeyword; } - export function isImportCall(n: Node): n is ImportCall { - return n.kind === SyntaxKind.CallExpression && (n).expression.kind === SyntaxKind.ImportKeyword; - } - export function isPrologueDirective(node: Node): node is PrologueDirective { return node.kind === SyntaxKind.ExpressionStatement && (node).expression.kind === SyntaxKind.StringLiteral; diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 9bf4591112d..49dbdbf2102 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -857,7 +857,6 @@ namespace Harness { export function getDefaultLibFileName(options: ts.CompilerOptions): string { switch (options.target) { - case ts.ScriptTarget.ESNext: case ts.ScriptTarget.ES2017: return "lib.es2017.d.ts"; case ts.ScriptTarget.ES2016: diff --git a/src/harness/unittests/commandLineParsing.ts b/src/harness/unittests/commandLineParsing.ts index 01a208aa330..19ccc919d4c 100644 --- a/src/harness/unittests/commandLineParsing.ts +++ b/src/harness/unittests/commandLineParsing.ts @@ -113,7 +113,7 @@ namespace ts { start: undefined, length: undefined, }, { - messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'esnext'.", + messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015'.", category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category, code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code, diff --git a/src/harness/unittests/convertCompilerOptionsFromJson.ts b/src/harness/unittests/convertCompilerOptionsFromJson.ts index 798f8c6a76b..3aa1a4c9b8e 100644 --- a/src/harness/unittests/convertCompilerOptionsFromJson.ts +++ b/src/harness/unittests/convertCompilerOptionsFromJson.ts @@ -122,7 +122,7 @@ namespace ts { file: undefined, start: 0, length: 0, - messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'esnext'.", + messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015'.", code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category }] diff --git a/src/services/services.ts b/src/services/services.ts index 21c756a9acc..05fe59084b4 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -368,7 +368,7 @@ namespace ts { _primaryExpressionBrand: any; _memberExpressionBrand: any; _leftHandSideExpressionBrand: any; - _updateExpressionBrand: any; + _incrementExpressionBrand: any; _unaryExpressionBrand: any; _expressionBrand: any; /*@internal*/typeArguments: NodeArray; @@ -521,7 +521,6 @@ namespace ts { private namedDeclarations: Map; public ambientModuleNames: string[]; public checkJsDirective: CheckJsDirective | undefined; - public possiblyContainDynamicImport: boolean; constructor(kind: SyntaxKind, pos: number, end: number) { super(kind, pos, end); diff --git a/tests/baselines/reference/importCallExpression1ESNext.js b/tests/baselines/reference/importCallExpression1ESNext.js deleted file mode 100644 index 39b779c921f..00000000000 --- a/tests/baselines/reference/importCallExpression1ESNext.js +++ /dev/null @@ -1,27 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpression1ESNext.ts] //// - -//// [0.ts] -export function foo() { return "foo"; } - -//// [1.ts] -import("./0"); -var p1 = import("./0"); -p1.then(zero => { - return zero.foo(); -}) - -function foo() { - const p2 = import("./0"); -} - -//// [0.js] -export function foo() { return "foo"; } -//// [1.js] -import("./0"); -var p1 = import("./0"); -p1.then(zero => { - return zero.foo(); -}); -function foo() { - const p2 = import("./0"); -} diff --git a/tests/baselines/reference/importCallExpression1ESNext.symbols b/tests/baselines/reference/importCallExpression1ESNext.symbols deleted file mode 100644 index 28b5ba13e99..00000000000 --- a/tests/baselines/reference/importCallExpression1ESNext.symbols +++ /dev/null @@ -1,28 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export function foo() { return "foo"; } ->foo : Symbol(foo, Decl(0.ts, 0, 0)) - -=== tests/cases/conformance/dynamicImport/1.ts === -import("./0"); -var p1 = import("./0"); ->p1 : Symbol(p1, Decl(1.ts, 1, 3)) - -p1.then(zero => { ->p1.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->p1 : Symbol(p1, Decl(1.ts, 1, 3)) ->then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->zero : Symbol(zero, Decl(1.ts, 2, 8)) - - return zero.foo(); ->zero.foo : Symbol(foo, Decl(0.ts, 0, 0)) ->zero : Symbol(zero, Decl(1.ts, 2, 8)) ->foo : Symbol(foo, Decl(0.ts, 0, 0)) - -}) - -function foo() { ->foo : Symbol(foo, Decl(1.ts, 4, 2)) - - const p2 = import("./0"); ->p2 : Symbol(p2, Decl(1.ts, 7, 9)) -} diff --git a/tests/baselines/reference/importCallExpression1ESNext.types b/tests/baselines/reference/importCallExpression1ESNext.types deleted file mode 100644 index 53a1b3d08fa..00000000000 --- a/tests/baselines/reference/importCallExpression1ESNext.types +++ /dev/null @@ -1,39 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export function foo() { return "foo"; } ->foo : () => string ->"foo" : "foo" - -=== tests/cases/conformance/dynamicImport/1.ts === -import("./0"); ->import("./0") : Promise ->"./0" : "./0" - -var p1 = import("./0"); ->p1 : Promise ->import("./0") : Promise ->"./0" : "./0" - -p1.then(zero => { ->p1.then(zero => { return zero.foo();}) : Promise ->p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->p1 : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/dynamicImport/0") => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" - - return zero.foo(); ->zero.foo() : string ->zero.foo : () => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" ->foo : () => string - -}) - -function foo() { ->foo : () => void - - const p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise ->"./0" : "./0" -} diff --git a/tests/baselines/reference/importCallExpression2ESNext.js b/tests/baselines/reference/importCallExpression2ESNext.js deleted file mode 100644 index 662f57f07ff..00000000000 --- a/tests/baselines/reference/importCallExpression2ESNext.js +++ /dev/null @@ -1,29 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpression2ESNext.ts] //// - -//// [0.ts] -export class B { - print() { return "I am B"} -} - -//// [2.ts] -function foo(x: Promise) { - x.then(value => { - let b = new value.B(); - b.print(); - }) -} - -foo(import("./0")); - -//// [0.js] -export class B { - print() { return "I am B"; } -} -//// [2.js] -function foo(x) { - x.then(value => { - let b = new value.B(); - b.print(); - }); -} -foo(import("./0")); diff --git a/tests/baselines/reference/importCallExpression2ESNext.symbols b/tests/baselines/reference/importCallExpression2ESNext.symbols deleted file mode 100644 index 2002398aeb9..00000000000 --- a/tests/baselines/reference/importCallExpression2ESNext.symbols +++ /dev/null @@ -1,33 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : Symbol(B, Decl(0.ts, 0, 0)) - - print() { return "I am B"} ->print : Symbol(B.print, Decl(0.ts, 0, 16)) -} - -=== tests/cases/conformance/dynamicImport/2.ts === -function foo(x: Promise) { ->foo : Symbol(foo, Decl(2.ts, 0, 0)) ->x : Symbol(x, Decl(2.ts, 0, 13)) ->Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) - - x.then(value => { ->x.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->x : Symbol(x, Decl(2.ts, 0, 13)) ->then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->value : Symbol(value, Decl(2.ts, 1, 11)) - - let b = new value.B(); ->b : Symbol(b, Decl(2.ts, 2, 11)) ->value : Symbol(value, Decl(2.ts, 1, 11)) - - b.print(); ->b : Symbol(b, Decl(2.ts, 2, 11)) - - }) -} - -foo(import("./0")); ->foo : Symbol(foo, Decl(2.ts, 0, 0)) - diff --git a/tests/baselines/reference/importCallExpression2ESNext.types b/tests/baselines/reference/importCallExpression2ESNext.types deleted file mode 100644 index 084eb33dde9..00000000000 --- a/tests/baselines/reference/importCallExpression2ESNext.types +++ /dev/null @@ -1,45 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : B - - print() { return "I am B"} ->print : () => string ->"I am B" : "I am B" -} - -=== tests/cases/conformance/dynamicImport/2.ts === -function foo(x: Promise) { ->foo : (x: Promise) => void ->x : Promise ->Promise : Promise - - x.then(value => { ->x.then(value => { let b = new value.B(); b.print(); }) : Promise ->x.then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->x : Promise ->then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->value => { let b = new value.B(); b.print(); } : (value: any) => void ->value : any - - let b = new value.B(); ->b : any ->new value.B() : any ->value.B : any ->value : any ->B : any - - b.print(); ->b.print() : any ->b.print : any ->b : any ->print : any - - }) -} - -foo(import("./0")); ->foo(import("./0")) : void ->foo : (x: Promise) => void ->import("./0") : Promise ->"./0" : "./0" - diff --git a/tests/baselines/reference/importCallExpression3ESNext.js b/tests/baselines/reference/importCallExpression3ESNext.js deleted file mode 100644 index 0cd41388616..00000000000 --- a/tests/baselines/reference/importCallExpression3ESNext.js +++ /dev/null @@ -1,27 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpression3ESNext.ts] //// - -//// [0.ts] -export class B { - print() { return "I am B"} -} - -//// [2.ts] -async function foo() { - class C extends (await import("./0")).B {} - var c = new C(); - c.print(); -} -foo(); - -//// [0.js] -export class B { - print() { return "I am B"; } -} -//// [2.js] -async function foo() { - class C extends (await import("./0")).B { - } - var c = new C(); - c.print(); -} -foo(); diff --git a/tests/baselines/reference/importCallExpression3ESNext.symbols b/tests/baselines/reference/importCallExpression3ESNext.symbols deleted file mode 100644 index 5ca85d6e693..00000000000 --- a/tests/baselines/reference/importCallExpression3ESNext.symbols +++ /dev/null @@ -1,29 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : Symbol(B, Decl(0.ts, 0, 0)) - - print() { return "I am B"} ->print : Symbol(B.print, Decl(0.ts, 0, 16)) -} - -=== tests/cases/conformance/dynamicImport/2.ts === -async function foo() { ->foo : Symbol(foo, Decl(2.ts, 0, 0)) - - class C extends (await import("./0")).B {} ->C : Symbol(C, Decl(2.ts, 0, 22)) ->(await import("./0")).B : Symbol(B, Decl(0.ts, 0, 0)) ->B : Symbol(B, Decl(0.ts, 0, 0)) - - var c = new C(); ->c : Symbol(c, Decl(2.ts, 2, 7)) ->C : Symbol(C, Decl(2.ts, 0, 22)) - - c.print(); ->c.print : Symbol(B.print, Decl(0.ts, 0, 16)) ->c : Symbol(c, Decl(2.ts, 2, 7)) ->print : Symbol(B.print, Decl(0.ts, 0, 16)) -} -foo(); ->foo : Symbol(foo, Decl(2.ts, 0, 0)) - diff --git a/tests/baselines/reference/importCallExpression3ESNext.types b/tests/baselines/reference/importCallExpression3ESNext.types deleted file mode 100644 index e517be6e722..00000000000 --- a/tests/baselines/reference/importCallExpression3ESNext.types +++ /dev/null @@ -1,37 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : B - - print() { return "I am B"} ->print : () => string ->"I am B" : "I am B" -} - -=== tests/cases/conformance/dynamicImport/2.ts === -async function foo() { ->foo : () => Promise - - class C extends (await import("./0")).B {} ->C : C ->(await import("./0")).B : B ->(await import("./0")) : typeof "tests/cases/conformance/dynamicImport/0" ->await import("./0") : typeof "tests/cases/conformance/dynamicImport/0" ->import("./0") : Promise ->"./0" : "./0" ->B : typeof B - - var c = new C(); ->c : C ->new C() : C ->C : typeof C - - c.print(); ->c.print() : string ->c.print : () => string ->c : C ->print : () => string -} -foo(); ->foo() : Promise ->foo : () => Promise - diff --git a/tests/baselines/reference/importCallExpression4ESNext.js b/tests/baselines/reference/importCallExpression4ESNext.js deleted file mode 100644 index e148d5c1e51..00000000000 --- a/tests/baselines/reference/importCallExpression4ESNext.js +++ /dev/null @@ -1,49 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpression4ESNext.ts] //// - -//// [0.ts] -export class B { - print() { return "I am B"} -} - -export function foo() { return "foo" } - -//// [1.ts] -export function backup() { return "backup"; } - -//// [2.ts] -declare var console: any; -class C { - private myModule = import("./0"); - method() { - this.myModule.then(Zero => { - console.log(Zero.foo()); - }, async err => { - console.log(err); - let one = await import("./1"); - console.log(one.backup()); - }); - } -} - -//// [0.js] -export class B { - print() { return "I am B"; } -} -export function foo() { return "foo"; } -//// [1.js] -export function backup() { return "backup"; } -//// [2.js] -class C { - constructor() { - this.myModule = import("./0"); - } - method() { - this.myModule.then(Zero => { - console.log(Zero.foo()); - }, async (err) => { - console.log(err); - let one = await import("./1"); - console.log(one.backup()); - }); - } -} diff --git a/tests/baselines/reference/importCallExpression4ESNext.symbols b/tests/baselines/reference/importCallExpression4ESNext.symbols deleted file mode 100644 index 34a1dcf4d7b..00000000000 --- a/tests/baselines/reference/importCallExpression4ESNext.symbols +++ /dev/null @@ -1,61 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : Symbol(B, Decl(0.ts, 0, 0)) - - print() { return "I am B"} ->print : Symbol(B.print, Decl(0.ts, 0, 16)) -} - -export function foo() { return "foo" } ->foo : Symbol(foo, Decl(0.ts, 2, 1)) - -=== tests/cases/conformance/dynamicImport/1.ts === -export function backup() { return "backup"; } ->backup : Symbol(backup, Decl(1.ts, 0, 0)) - -=== tests/cases/conformance/dynamicImport/2.ts === -declare var console: any; ->console : Symbol(console, Decl(2.ts, 0, 11)) - -class C { ->C : Symbol(C, Decl(2.ts, 0, 25)) - - private myModule = import("./0"); ->myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) - - method() { ->method : Symbol(C.method, Decl(2.ts, 2, 37)) - - this.myModule.then(Zero => { ->this.myModule.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->this.myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) ->this : Symbol(C, Decl(2.ts, 0, 25)) ->myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) ->then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->Zero : Symbol(Zero, Decl(2.ts, 4, 27)) - - console.log(Zero.foo()); ->console : Symbol(console, Decl(2.ts, 0, 11)) ->Zero.foo : Symbol(foo, Decl(0.ts, 2, 1)) ->Zero : Symbol(Zero, Decl(2.ts, 4, 27)) ->foo : Symbol(foo, Decl(0.ts, 2, 1)) - - }, async err => { ->err : Symbol(err, Decl(2.ts, 6, 16)) - - console.log(err); ->console : Symbol(console, Decl(2.ts, 0, 11)) ->err : Symbol(err, Decl(2.ts, 6, 16)) - - let one = await import("./1"); ->one : Symbol(one, Decl(2.ts, 8, 15)) - - console.log(one.backup()); ->console : Symbol(console, Decl(2.ts, 0, 11)) ->one.backup : Symbol(backup, Decl(1.ts, 0, 0)) ->one : Symbol(one, Decl(2.ts, 8, 15)) ->backup : Symbol(backup, Decl(1.ts, 0, 0)) - - }); - } -} diff --git a/tests/baselines/reference/importCallExpression4ESNext.types b/tests/baselines/reference/importCallExpression4ESNext.types deleted file mode 100644 index 2ea666ba672..00000000000 --- a/tests/baselines/reference/importCallExpression4ESNext.types +++ /dev/null @@ -1,83 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : B - - print() { return "I am B"} ->print : () => string ->"I am B" : "I am B" -} - -export function foo() { return "foo" } ->foo : () => string ->"foo" : "foo" - -=== tests/cases/conformance/dynamicImport/1.ts === -export function backup() { return "backup"; } ->backup : () => string ->"backup" : "backup" - -=== tests/cases/conformance/dynamicImport/2.ts === -declare var console: any; ->console : any - -class C { ->C : C - - private myModule = import("./0"); ->myModule : Promise ->import("./0") : Promise ->"./0" : "./0" - - method() { ->method : () => void - - this.myModule.then(Zero => { ->this.myModule.then(Zero => { console.log(Zero.foo()); }, async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); }) : Promise ->this.myModule.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->this.myModule : Promise ->this : this ->myModule : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/dynamicImport/0") => void ->Zero : typeof "tests/cases/conformance/dynamicImport/0" - - console.log(Zero.foo()); ->console.log(Zero.foo()) : any ->console.log : any ->console : any ->log : any ->Zero.foo() : string ->Zero.foo : () => string ->Zero : typeof "tests/cases/conformance/dynamicImport/0" ->foo : () => string - - }, async err => { ->async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); } : (err: any) => Promise ->err : any - - console.log(err); ->console.log(err) : any ->console.log : any ->console : any ->log : any ->err : any - - let one = await import("./1"); ->one : typeof "tests/cases/conformance/dynamicImport/1" ->await import("./1") : typeof "tests/cases/conformance/dynamicImport/1" ->import("./1") : Promise ->"./1" : "./1" - - console.log(one.backup()); ->console.log(one.backup()) : any ->console.log : any ->console : any ->log : any ->one.backup() : string ->one.backup : () => string ->one : typeof "tests/cases/conformance/dynamicImport/1" ->backup : () => string - - }); - } -} diff --git a/tests/baselines/reference/importCallExpression5ESNext.errors.txt b/tests/baselines/reference/importCallExpression5ESNext.errors.txt deleted file mode 100644 index ed5900c2a03..00000000000 --- a/tests/baselines/reference/importCallExpression5ESNext.errors.txt +++ /dev/null @@ -1,31 +0,0 @@ -tests/cases/conformance/dynamicImport/2.ts(3,23): error TS7036: Dynamic import's specifier must be of type 'string', but here has type '"./0" | undefined'. -tests/cases/conformance/dynamicImport/2.ts(4,24): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'undefined'. -tests/cases/conformance/dynamicImport/2.ts(5,24): error TS7036: Dynamic import's specifier must be of type 'string', but here has type '"./1" | null'. -tests/cases/conformance/dynamicImport/2.ts(6,24): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'null'. - - -==== tests/cases/conformance/dynamicImport/0.ts (0 errors) ==== - export class B { - print() { return "I am B"} - } - - export function foo() { return "foo" } - -==== tests/cases/conformance/dynamicImport/1.ts (0 errors) ==== - export function backup() { return "backup"; } - -==== tests/cases/conformance/dynamicImport/2.ts (4 errors) ==== - declare function bar(): boolean; - const specify = bar() ? "./0" : undefined; - let myModule = import(specify); - ~~~~~~~ -!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type '"./0" | undefined'. - let myModule1 = import(undefined); - ~~~~~~~~~ -!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'undefined'. - let myModule2 = import(bar() ? "./1" : null); - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type '"./1" | null'. - let myModule3 = import(null); - ~~~~ -!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'null'. \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpression5ESNext.js b/tests/baselines/reference/importCallExpression5ESNext.js deleted file mode 100644 index 1f4c789120b..00000000000 --- a/tests/baselines/reference/importCallExpression5ESNext.js +++ /dev/null @@ -1,33 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpression5ESNext.ts] //// - -//// [0.ts] -export class B { - print() { return "I am B"} -} - -export function foo() { return "foo" } - -//// [1.ts] -export function backup() { return "backup"; } - -//// [2.ts] -declare function bar(): boolean; -const specify = bar() ? "./0" : undefined; -let myModule = import(specify); -let myModule1 = import(undefined); -let myModule2 = import(bar() ? "./1" : null); -let myModule3 = import(null); - -//// [0.js] -export class B { - print() { return "I am B"; } -} -export function foo() { return "foo"; } -//// [1.js] -export function backup() { return "backup"; } -//// [2.js] -const specify = bar() ? "./0" : undefined; -let myModule = import(specify); -let myModule1 = import(undefined); -let myModule2 = import(bar() ? "./1" : null); -let myModule3 = import(null); diff --git a/tests/baselines/reference/importCallExpression6ESNext.errors.txt b/tests/baselines/reference/importCallExpression6ESNext.errors.txt deleted file mode 100644 index 1703e0913d1..00000000000 --- a/tests/baselines/reference/importCallExpression6ESNext.errors.txt +++ /dev/null @@ -1,25 +0,0 @@ -tests/cases/conformance/dynamicImport/2.ts(4,24): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'undefined'. -tests/cases/conformance/dynamicImport/2.ts(6,24): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'null'. - - -==== tests/cases/conformance/dynamicImport/0.ts (0 errors) ==== - export class B { - print() { return "I am B"} - } - - export function foo() { return "foo" } - -==== tests/cases/conformance/dynamicImport/1.ts (0 errors) ==== - export function backup() { return "backup"; } - -==== tests/cases/conformance/dynamicImport/2.ts (2 errors) ==== - declare function bar(): boolean; - const specify = bar() ? "./0" : undefined; - let myModule = import(specify); - let myModule1 = import(undefined); - ~~~~~~~~~ -!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'undefined'. - let myModule2 = import(bar() ? "./1" : null); - let myModule3 = import(null); - ~~~~ -!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'null'. \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpression6ESNext.js b/tests/baselines/reference/importCallExpression6ESNext.js deleted file mode 100644 index bdac7328f69..00000000000 --- a/tests/baselines/reference/importCallExpression6ESNext.js +++ /dev/null @@ -1,33 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpression6ESNext.ts] //// - -//// [0.ts] -export class B { - print() { return "I am B"} -} - -export function foo() { return "foo" } - -//// [1.ts] -export function backup() { return "backup"; } - -//// [2.ts] -declare function bar(): boolean; -const specify = bar() ? "./0" : undefined; -let myModule = import(specify); -let myModule1 = import(undefined); -let myModule2 = import(bar() ? "./1" : null); -let myModule3 = import(null); - -//// [0.js] -export class B { - print() { return "I am B"; } -} -export function foo() { return "foo"; } -//// [1.js] -export function backup() { return "backup"; } -//// [2.js] -const specify = bar() ? "./0" : undefined; -let myModule = import(specify); -let myModule1 = import(undefined); -let myModule2 = import(bar() ? "./1" : null); -let myModule3 = import(null); diff --git a/tests/baselines/reference/importCallExpressionCheckReturntype1.errors.txt b/tests/baselines/reference/importCallExpressionCheckReturntype1.errors.txt deleted file mode 100644 index 39622f39b3f..00000000000 --- a/tests/baselines/reference/importCallExpressionCheckReturntype1.errors.txt +++ /dev/null @@ -1,30 +0,0 @@ -tests/cases/conformance/dynamicImport/1.ts(4,5): error TS2322: Type 'Promise' is not assignable to type 'Promise'. - Type 'typeof "tests/cases/conformance/dynamicImport/defaultPath"' is not assignable to type 'typeof "tests/cases/conformance/dynamicImport/anotherModule"'. - Property 'D' is missing in type 'typeof "tests/cases/conformance/dynamicImport/defaultPath"'. -tests/cases/conformance/dynamicImport/1.ts(5,10): error TS2352: Type 'Promise' cannot be converted to type 'Promise'. - Type 'typeof "tests/cases/conformance/dynamicImport/defaultPath"' is not comparable to type 'typeof "tests/cases/conformance/dynamicImport/anotherModule"'. - Property 'D' is missing in type 'typeof "tests/cases/conformance/dynamicImport/defaultPath"'. - - -==== tests/cases/conformance/dynamicImport/anotherModule.ts (0 errors) ==== - export class D{} - -==== tests/cases/conformance/dynamicImport/defaultPath.ts (0 errors) ==== - export class C {} - -==== tests/cases/conformance/dynamicImport/1.ts (2 errors) ==== - import * as defaultModule from "./defaultPath"; - import * as anotherModule from "./anotherModule"; - - let p1: Promise = import("./defaultPath"); - ~~ -!!! error TS2322: Type 'Promise' is not assignable to type 'Promise'. -!!! error TS2322: Type 'typeof "tests/cases/conformance/dynamicImport/defaultPath"' is not assignable to type 'typeof "tests/cases/conformance/dynamicImport/anotherModule"'. -!!! error TS2322: Property 'D' is missing in type 'typeof "tests/cases/conformance/dynamicImport/defaultPath"'. - let p2 = import("./defaultPath") as Promise; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2352: Type 'Promise' cannot be converted to type 'Promise'. -!!! error TS2352: Type 'typeof "tests/cases/conformance/dynamicImport/defaultPath"' is not comparable to type 'typeof "tests/cases/conformance/dynamicImport/anotherModule"'. -!!! error TS2352: Property 'D' is missing in type 'typeof "tests/cases/conformance/dynamicImport/defaultPath"'. - let p3: Promise = import("./defaultPath"); - \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionCheckReturntype1.js b/tests/baselines/reference/importCallExpressionCheckReturntype1.js deleted file mode 100644 index facb6913388..00000000000 --- a/tests/baselines/reference/importCallExpressionCheckReturntype1.js +++ /dev/null @@ -1,35 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionCheckReturntype1.ts] //// - -//// [anotherModule.ts] -export class D{} - -//// [defaultPath.ts] -export class C {} - -//// [1.ts] -import * as defaultModule from "./defaultPath"; -import * as anotherModule from "./anotherModule"; - -let p1: Promise = import("./defaultPath"); -let p2 = import("./defaultPath") as Promise; -let p3: Promise = import("./defaultPath"); - - -//// [anotherModule.js] -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -class D { -} -exports.D = D; -//// [defaultPath.js] -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -class C { -} -exports.C = C; -//// [1.js] -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -let p1 = Promise.resolve().then(function () { return require("./defaultPath"); }); -let p2 = Promise.resolve().then(function () { return require("./defaultPath"); }); -let p3 = Promise.resolve().then(function () { return require("./defaultPath"); }); diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit1.js b/tests/baselines/reference/importCallExpressionDeclarationEmit1.js deleted file mode 100644 index 07f95d3b3b2..00000000000 --- a/tests/baselines/reference/importCallExpressionDeclarationEmit1.js +++ /dev/null @@ -1,35 +0,0 @@ -//// [importCallExpressionDeclarationEmit1.ts] -declare function getSpecifier(): string; -declare var whatToLoad: boolean; -declare const directory: string; -declare const moduleFile: number; - -import(getSpecifier()); - -var p0 = import(`${directory}\${moduleFile}`); -var p1 = import(getSpecifier()); -const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") - -function returnDynamicLoad(path: string) { - return import(path); -} - -//// [importCallExpressionDeclarationEmit1.js] -Promise.resolve().then(function () { return require(getSpecifier()); }); -var p0 = Promise.resolve().then(function () { return require(`${directory}\${moduleFile}`); }); -var p1 = Promise.resolve().then(function () { return require(getSpecifier()); }); -const p2 = Promise.resolve().then(function () { return require(whatToLoad ? getSpecifier() : "defaulPath"); }); -function returnDynamicLoad(path) { - return Promise.resolve().then(function () { return require(path); }); -} - - -//// [importCallExpressionDeclarationEmit1.d.ts] -declare function getSpecifier(): string; -declare var whatToLoad: boolean; -declare const directory: string; -declare const moduleFile: number; -declare var p0: Promise; -declare var p1: Promise; -declare const p2: Promise; -declare function returnDynamicLoad(path: string): Promise; diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit1.symbols b/tests/baselines/reference/importCallExpressionDeclarationEmit1.symbols deleted file mode 100644 index d2266cc768b..00000000000 --- a/tests/baselines/reference/importCallExpressionDeclarationEmit1.symbols +++ /dev/null @@ -1,36 +0,0 @@ -=== tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit1.ts === -declare function getSpecifier(): string; ->getSpecifier : Symbol(getSpecifier, Decl(importCallExpressionDeclarationEmit1.ts, 0, 0)) - -declare var whatToLoad: boolean; ->whatToLoad : Symbol(whatToLoad, Decl(importCallExpressionDeclarationEmit1.ts, 1, 11)) - -declare const directory: string; ->directory : Symbol(directory, Decl(importCallExpressionDeclarationEmit1.ts, 2, 13)) - -declare const moduleFile: number; ->moduleFile : Symbol(moduleFile, Decl(importCallExpressionDeclarationEmit1.ts, 3, 13)) - -import(getSpecifier()); ->getSpecifier : Symbol(getSpecifier, Decl(importCallExpressionDeclarationEmit1.ts, 0, 0)) - -var p0 = import(`${directory}\${moduleFile}`); ->p0 : Symbol(p0, Decl(importCallExpressionDeclarationEmit1.ts, 7, 3)) ->directory : Symbol(directory, Decl(importCallExpressionDeclarationEmit1.ts, 2, 13)) - -var p1 = import(getSpecifier()); ->p1 : Symbol(p1, Decl(importCallExpressionDeclarationEmit1.ts, 8, 3)) ->getSpecifier : Symbol(getSpecifier, Decl(importCallExpressionDeclarationEmit1.ts, 0, 0)) - -const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") ->p2 : Symbol(p2, Decl(importCallExpressionDeclarationEmit1.ts, 9, 5)) ->whatToLoad : Symbol(whatToLoad, Decl(importCallExpressionDeclarationEmit1.ts, 1, 11)) ->getSpecifier : Symbol(getSpecifier, Decl(importCallExpressionDeclarationEmit1.ts, 0, 0)) - -function returnDynamicLoad(path: string) { ->returnDynamicLoad : Symbol(returnDynamicLoad, Decl(importCallExpressionDeclarationEmit1.ts, 9, 61)) ->path : Symbol(path, Decl(importCallExpressionDeclarationEmit1.ts, 11, 27)) - - return import(path); ->path : Symbol(path, Decl(importCallExpressionDeclarationEmit1.ts, 11, 27)) -} diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit1.types b/tests/baselines/reference/importCallExpressionDeclarationEmit1.types deleted file mode 100644 index db5400818c8..00000000000 --- a/tests/baselines/reference/importCallExpressionDeclarationEmit1.types +++ /dev/null @@ -1,47 +0,0 @@ -=== tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit1.ts === -declare function getSpecifier(): string; ->getSpecifier : () => string - -declare var whatToLoad: boolean; ->whatToLoad : boolean - -declare const directory: string; ->directory : string - -declare const moduleFile: number; ->moduleFile : number - -import(getSpecifier()); ->import(getSpecifier()) : Promise ->getSpecifier() : string ->getSpecifier : () => string - -var p0 = import(`${directory}\${moduleFile}`); ->p0 : Promise ->import(`${directory}\${moduleFile}`) : Promise ->`${directory}\${moduleFile}` : string ->directory : string - -var p1 = import(getSpecifier()); ->p1 : Promise ->import(getSpecifier()) : Promise ->getSpecifier() : string ->getSpecifier : () => string - -const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") ->p2 : Promise ->import(whatToLoad ? getSpecifier() : "defaulPath") : Promise ->whatToLoad ? getSpecifier() : "defaulPath" : string ->whatToLoad : boolean ->getSpecifier() : string ->getSpecifier : () => string ->"defaulPath" : "defaulPath" - -function returnDynamicLoad(path: string) { ->returnDynamicLoad : (path: string) => Promise ->path : string - - return import(path); ->import(path) : Promise ->path : string -} diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit2.errors.txt b/tests/baselines/reference/importCallExpressionDeclarationEmit2.errors.txt deleted file mode 100644 index 6c394c98bdf..00000000000 --- a/tests/baselines/reference/importCallExpressionDeclarationEmit2.errors.txt +++ /dev/null @@ -1,10 +0,0 @@ -tests/cases/conformance/dynamicImport/1.ts(1,5): error TS4023: Exported variable 'p1' has or is using name '"tests/cases/conformance/dynamicImport/0"' from external module "tests/cases/conformance/dynamicImport/0" but cannot be named. - - -==== tests/cases/conformance/dynamicImport/0.ts (0 errors) ==== - export function foo() { return "foo"; } - -==== tests/cases/conformance/dynamicImport/1.ts (1 errors) ==== - var p1 = import("./0"); - ~~ -!!! error TS4023: Exported variable 'p1' has or is using name '"tests/cases/conformance/dynamicImport/0"' from external module "tests/cases/conformance/dynamicImport/0" but cannot be named. \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit2.js b/tests/baselines/reference/importCallExpressionDeclarationEmit2.js deleted file mode 100644 index 7659e94ee81..00000000000 --- a/tests/baselines/reference/importCallExpressionDeclarationEmit2.js +++ /dev/null @@ -1,16 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit2.ts] //// - -//// [0.ts] -export function foo() { return "foo"; } - -//// [1.ts] -var p1 = import("./0"); - -//// [0.js] -export function foo() { return "foo"; } -//// [1.js] -var p1 = import("./0"); - - -//// [0.d.ts] -export declare function foo(): string; diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit3.js b/tests/baselines/reference/importCallExpressionDeclarationEmit3.js deleted file mode 100644 index d38c2309a33..00000000000 --- a/tests/baselines/reference/importCallExpressionDeclarationEmit3.js +++ /dev/null @@ -1,31 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit3.ts] //// - -//// [0.ts] -export function foo() { return "foo"; } - -//// [1.ts] -declare function getPath(): string; -import * as Zero from "./0"; -import("./0"); - -export var p0: Promise = import(getPath()); -export var p1: Promise = import("./0"); -export var p2: Promise = import("./0"); - - -//// [0.js] -export function foo() { return "foo"; } -//// [1.js] -import("./0"); -export var p0 = import(getPath()); -export var p1 = import("./0"); -export var p2 = import("./0"); - - -//// [0.d.ts] -export declare function foo(): string; -//// [1.d.ts] -import * as Zero from "./0"; -export declare var p0: Promise; -export declare var p1: Promise; -export declare var p2: Promise; diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit3.symbols b/tests/baselines/reference/importCallExpressionDeclarationEmit3.symbols deleted file mode 100644 index 1491e05db55..00000000000 --- a/tests/baselines/reference/importCallExpressionDeclarationEmit3.symbols +++ /dev/null @@ -1,28 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export function foo() { return "foo"; } ->foo : Symbol(foo, Decl(0.ts, 0, 0)) - -=== tests/cases/conformance/dynamicImport/1.ts === -declare function getPath(): string; ->getPath : Symbol(getPath, Decl(1.ts, 0, 0)) - -import * as Zero from "./0"; ->Zero : Symbol(Zero, Decl(1.ts, 1, 6)) - -import("./0"); - -export var p0: Promise = import(getPath()); ->p0 : Symbol(p0, Decl(1.ts, 4, 10)) ->Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) ->Zero : Symbol(Zero, Decl(1.ts, 1, 6)) ->getPath : Symbol(getPath, Decl(1.ts, 0, 0)) - -export var p1: Promise = import("./0"); ->p1 : Symbol(p1, Decl(1.ts, 5, 10)) ->Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) ->Zero : Symbol(Zero, Decl(1.ts, 1, 6)) - -export var p2: Promise = import("./0"); ->p2 : Symbol(p2, Decl(1.ts, 6, 10)) ->Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) - diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit3.types b/tests/baselines/reference/importCallExpressionDeclarationEmit3.types deleted file mode 100644 index fe4552b708f..00000000000 --- a/tests/baselines/reference/importCallExpressionDeclarationEmit3.types +++ /dev/null @@ -1,37 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export function foo() { return "foo"; } ->foo : () => string ->"foo" : "foo" - -=== tests/cases/conformance/dynamicImport/1.ts === -declare function getPath(): string; ->getPath : () => string - -import * as Zero from "./0"; ->Zero : typeof Zero - -import("./0"); ->import("./0") : Promise ->"./0" : "./0" - -export var p0: Promise = import(getPath()); ->p0 : Promise ->Promise : Promise ->Zero : typeof Zero ->import(getPath()) : Promise ->getPath() : string ->getPath : () => string - -export var p1: Promise = import("./0"); ->p1 : Promise ->Promise : Promise ->Zero : typeof Zero ->import("./0") : Promise ->"./0" : "./0" - -export var p2: Promise = import("./0"); ->p2 : Promise ->Promise : Promise ->import("./0") : Promise ->"./0" : "./0" - diff --git a/tests/baselines/reference/importCallExpressionES5AMD.js b/tests/baselines/reference/importCallExpressionES5AMD.js deleted file mode 100644 index cce61a5a3f9..00000000000 --- a/tests/baselines/reference/importCallExpressionES5AMD.js +++ /dev/null @@ -1,35 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionES5AMD.ts] //// - -//// [0.ts] -export function foo() { return "foo"; } - -//// [1.ts] -import("./0"); -var p1 = import("./0"); -p1.then(zero => { - return zero.foo(); -}); - -function foo() { - const p2 = import("./0"); -} - -//// [0.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - Object.defineProperty(exports, "__esModule", { value: true }); - function foo() { return "foo"; } - exports.foo = foo; -}); -//// [1.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); }); - var p1 = new Promise(function (resolve_2, reject_2) { require(["./0"], resolve_2, reject_2); }); - p1.then(function (zero) { - return zero.foo(); - }); - function foo() { - var p2 = new Promise(function (resolve_3, reject_3) { require(["./0"], resolve_3, reject_3); }); - } -}); diff --git a/tests/baselines/reference/importCallExpressionES5AMD.symbols b/tests/baselines/reference/importCallExpressionES5AMD.symbols deleted file mode 100644 index 333251da662..00000000000 --- a/tests/baselines/reference/importCallExpressionES5AMD.symbols +++ /dev/null @@ -1,28 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export function foo() { return "foo"; } ->foo : Symbol(foo, Decl(0.ts, 0, 0)) - -=== tests/cases/conformance/dynamicImport/1.ts === -import("./0"); -var p1 = import("./0"); ->p1 : Symbol(p1, Decl(1.ts, 1, 3)) - -p1.then(zero => { ->p1.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->p1 : Symbol(p1, Decl(1.ts, 1, 3)) ->then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->zero : Symbol(zero, Decl(1.ts, 2, 8)) - - return zero.foo(); ->zero.foo : Symbol(foo, Decl(0.ts, 0, 0)) ->zero : Symbol(zero, Decl(1.ts, 2, 8)) ->foo : Symbol(foo, Decl(0.ts, 0, 0)) - -}); - -function foo() { ->foo : Symbol(foo, Decl(1.ts, 4, 3)) - - const p2 = import("./0"); ->p2 : Symbol(p2, Decl(1.ts, 7, 9)) -} diff --git a/tests/baselines/reference/importCallExpressionES5AMD.types b/tests/baselines/reference/importCallExpressionES5AMD.types deleted file mode 100644 index 59da055ee01..00000000000 --- a/tests/baselines/reference/importCallExpressionES5AMD.types +++ /dev/null @@ -1,39 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export function foo() { return "foo"; } ->foo : () => string ->"foo" : "foo" - -=== tests/cases/conformance/dynamicImport/1.ts === -import("./0"); ->import("./0") : Promise ->"./0" : "./0" - -var p1 = import("./0"); ->p1 : Promise ->import("./0") : Promise ->"./0" : "./0" - -p1.then(zero => { ->p1.then(zero => { return zero.foo();}) : Promise ->p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->p1 : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/dynamicImport/0") => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" - - return zero.foo(); ->zero.foo() : string ->zero.foo : () => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" ->foo : () => string - -}); - -function foo() { ->foo : () => void - - const p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise ->"./0" : "./0" -} diff --git a/tests/baselines/reference/importCallExpressionES5CJS.js b/tests/baselines/reference/importCallExpressionES5CJS.js deleted file mode 100644 index 11d1bf46319..00000000000 --- a/tests/baselines/reference/importCallExpressionES5CJS.js +++ /dev/null @@ -1,30 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionES5CJS.ts] //// - -//// [0.ts] -export function foo() { return "foo"; } - -//// [1.ts] -import("./0"); -var p1 = import("./0"); -p1.then(zero => { - return zero.foo(); -}); - -function foo() { - const p2 = import("./0"); -} - -//// [0.js] -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function foo() { return "foo"; } -exports.foo = foo; -//// [1.js] -Promise.resolve().then(function () { return require("./0"); }); -var p1 = Promise.resolve().then(function () { return require("./0"); }); -p1.then(function (zero) { - return zero.foo(); -}); -function foo() { - var p2 = Promise.resolve().then(function () { return require("./0"); }); -} diff --git a/tests/baselines/reference/importCallExpressionES5CJS.symbols b/tests/baselines/reference/importCallExpressionES5CJS.symbols deleted file mode 100644 index 333251da662..00000000000 --- a/tests/baselines/reference/importCallExpressionES5CJS.symbols +++ /dev/null @@ -1,28 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export function foo() { return "foo"; } ->foo : Symbol(foo, Decl(0.ts, 0, 0)) - -=== tests/cases/conformance/dynamicImport/1.ts === -import("./0"); -var p1 = import("./0"); ->p1 : Symbol(p1, Decl(1.ts, 1, 3)) - -p1.then(zero => { ->p1.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->p1 : Symbol(p1, Decl(1.ts, 1, 3)) ->then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->zero : Symbol(zero, Decl(1.ts, 2, 8)) - - return zero.foo(); ->zero.foo : Symbol(foo, Decl(0.ts, 0, 0)) ->zero : Symbol(zero, Decl(1.ts, 2, 8)) ->foo : Symbol(foo, Decl(0.ts, 0, 0)) - -}); - -function foo() { ->foo : Symbol(foo, Decl(1.ts, 4, 3)) - - const p2 = import("./0"); ->p2 : Symbol(p2, Decl(1.ts, 7, 9)) -} diff --git a/tests/baselines/reference/importCallExpressionES5CJS.types b/tests/baselines/reference/importCallExpressionES5CJS.types deleted file mode 100644 index 59da055ee01..00000000000 --- a/tests/baselines/reference/importCallExpressionES5CJS.types +++ /dev/null @@ -1,39 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export function foo() { return "foo"; } ->foo : () => string ->"foo" : "foo" - -=== tests/cases/conformance/dynamicImport/1.ts === -import("./0"); ->import("./0") : Promise ->"./0" : "./0" - -var p1 = import("./0"); ->p1 : Promise ->import("./0") : Promise ->"./0" : "./0" - -p1.then(zero => { ->p1.then(zero => { return zero.foo();}) : Promise ->p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->p1 : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/dynamicImport/0") => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" - - return zero.foo(); ->zero.foo() : string ->zero.foo : () => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" ->foo : () => string - -}); - -function foo() { ->foo : () => void - - const p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise ->"./0" : "./0" -} diff --git a/tests/baselines/reference/importCallExpressionES5System.js b/tests/baselines/reference/importCallExpressionES5System.js deleted file mode 100644 index 1842fc6e60a..00000000000 --- a/tests/baselines/reference/importCallExpressionES5System.js +++ /dev/null @@ -1,46 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionES5System.ts] //// - -//// [0.ts] -export function foo() { return "foo"; } - -//// [1.ts] -import("./0"); -var p1 = import("./0"); -p1.then(zero => { - return zero.foo(); -}); - -function foo() { - const p2 = import("./0"); -} - -//// [0.js] -System.register([], function (exports_1, context_1) { - "use strict"; - var __moduleName = context_1 && context_1.id; - function foo() { return "foo"; } - exports_1("foo", foo); - return { - setters: [], - execute: function () { - } - }; -}); -//// [1.js] -System.register([], function (exports_1, context_1) { - var __moduleName = context_1 && context_1.id; - function foo() { - var p2 = context_1.import("./0"); - } - var p1; - return { - setters: [], - execute: function () { - context_1.import("./0"); - p1 = context_1.import("./0"); - p1.then(function (zero) { - return zero.foo(); - }); - } - }; -}); diff --git a/tests/baselines/reference/importCallExpressionES5System.symbols b/tests/baselines/reference/importCallExpressionES5System.symbols deleted file mode 100644 index 333251da662..00000000000 --- a/tests/baselines/reference/importCallExpressionES5System.symbols +++ /dev/null @@ -1,28 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export function foo() { return "foo"; } ->foo : Symbol(foo, Decl(0.ts, 0, 0)) - -=== tests/cases/conformance/dynamicImport/1.ts === -import("./0"); -var p1 = import("./0"); ->p1 : Symbol(p1, Decl(1.ts, 1, 3)) - -p1.then(zero => { ->p1.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->p1 : Symbol(p1, Decl(1.ts, 1, 3)) ->then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->zero : Symbol(zero, Decl(1.ts, 2, 8)) - - return zero.foo(); ->zero.foo : Symbol(foo, Decl(0.ts, 0, 0)) ->zero : Symbol(zero, Decl(1.ts, 2, 8)) ->foo : Symbol(foo, Decl(0.ts, 0, 0)) - -}); - -function foo() { ->foo : Symbol(foo, Decl(1.ts, 4, 3)) - - const p2 = import("./0"); ->p2 : Symbol(p2, Decl(1.ts, 7, 9)) -} diff --git a/tests/baselines/reference/importCallExpressionES5System.types b/tests/baselines/reference/importCallExpressionES5System.types deleted file mode 100644 index 59da055ee01..00000000000 --- a/tests/baselines/reference/importCallExpressionES5System.types +++ /dev/null @@ -1,39 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export function foo() { return "foo"; } ->foo : () => string ->"foo" : "foo" - -=== tests/cases/conformance/dynamicImport/1.ts === -import("./0"); ->import("./0") : Promise ->"./0" : "./0" - -var p1 = import("./0"); ->p1 : Promise ->import("./0") : Promise ->"./0" : "./0" - -p1.then(zero => { ->p1.then(zero => { return zero.foo();}) : Promise ->p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->p1 : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/dynamicImport/0") => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" - - return zero.foo(); ->zero.foo() : string ->zero.foo : () => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" ->foo : () => string - -}); - -function foo() { ->foo : () => void - - const p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise ->"./0" : "./0" -} diff --git a/tests/baselines/reference/importCallExpressionES5UMD.js b/tests/baselines/reference/importCallExpressionES5UMD.js deleted file mode 100644 index dfe6813839c..00000000000 --- a/tests/baselines/reference/importCallExpressionES5UMD.js +++ /dev/null @@ -1,52 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionES5UMD.ts] //// - -//// [0.ts] -export function foo() { return "foo"; } - -//// [1.ts] -import("./0"); -var p1 = import("./0"); -p1.then(zero => { - return zero.foo(); -}); - -function foo() { - const p2 = import("./0"); -} - -//// [0.js] -(function (factory) { - if (typeof module === "object" && typeof module.exports === "object") { - var v = factory(require, exports); - if (v !== undefined) module.exports = v; - } - else if (typeof define === "function" && define.amd) { - define(["require", "exports"], factory); - } -})(function (require, exports) { - "use strict"; - Object.defineProperty(exports, "__esModule", { value: true }); - function foo() { return "foo"; } - exports.foo = foo; -}); -//// [1.js] -(function (factory) { - if (typeof module === "object" && typeof module.exports === "object") { - var v = factory(require, exports); - if (v !== undefined) module.exports = v; - } - else if (typeof define === "function" && define.amd) { - define(["require", "exports"], factory); - } -})(function (require, exports) { - "use strict"; - var __syncRequire = typeof module === "object" && typeof module.exports === "object"; - __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); }); - var p1 = __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_2, reject_2) { require(["./0"], resolve_2, reject_2); }); - p1.then(function (zero) { - return zero.foo(); - }); - function foo() { - var p2 = __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_3, reject_3) { require(["./0"], resolve_3, reject_3); }); - } -}); diff --git a/tests/baselines/reference/importCallExpressionES5UMD.symbols b/tests/baselines/reference/importCallExpressionES5UMD.symbols deleted file mode 100644 index 333251da662..00000000000 --- a/tests/baselines/reference/importCallExpressionES5UMD.symbols +++ /dev/null @@ -1,28 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export function foo() { return "foo"; } ->foo : Symbol(foo, Decl(0.ts, 0, 0)) - -=== tests/cases/conformance/dynamicImport/1.ts === -import("./0"); -var p1 = import("./0"); ->p1 : Symbol(p1, Decl(1.ts, 1, 3)) - -p1.then(zero => { ->p1.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->p1 : Symbol(p1, Decl(1.ts, 1, 3)) ->then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->zero : Symbol(zero, Decl(1.ts, 2, 8)) - - return zero.foo(); ->zero.foo : Symbol(foo, Decl(0.ts, 0, 0)) ->zero : Symbol(zero, Decl(1.ts, 2, 8)) ->foo : Symbol(foo, Decl(0.ts, 0, 0)) - -}); - -function foo() { ->foo : Symbol(foo, Decl(1.ts, 4, 3)) - - const p2 = import("./0"); ->p2 : Symbol(p2, Decl(1.ts, 7, 9)) -} diff --git a/tests/baselines/reference/importCallExpressionES5UMD.types b/tests/baselines/reference/importCallExpressionES5UMD.types deleted file mode 100644 index 59da055ee01..00000000000 --- a/tests/baselines/reference/importCallExpressionES5UMD.types +++ /dev/null @@ -1,39 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export function foo() { return "foo"; } ->foo : () => string ->"foo" : "foo" - -=== tests/cases/conformance/dynamicImport/1.ts === -import("./0"); ->import("./0") : Promise ->"./0" : "./0" - -var p1 = import("./0"); ->p1 : Promise ->import("./0") : Promise ->"./0" : "./0" - -p1.then(zero => { ->p1.then(zero => { return zero.foo();}) : Promise ->p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->p1 : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/dynamicImport/0") => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" - - return zero.foo(); ->zero.foo() : string ->zero.foo : () => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" ->foo : () => string - -}); - -function foo() { ->foo : () => void - - const p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise ->"./0" : "./0" -} diff --git a/tests/baselines/reference/importCallExpressionErrorInES2015.errors.txt b/tests/baselines/reference/importCallExpressionErrorInES2015.errors.txt deleted file mode 100644 index d47980d1312..00000000000 --- a/tests/baselines/reference/importCallExpressionErrorInES2015.errors.txt +++ /dev/null @@ -1,24 +0,0 @@ -tests/cases/conformance/dynamicImport/1.ts(1,1): error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules. -tests/cases/conformance/dynamicImport/1.ts(2,10): error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules. -tests/cases/conformance/dynamicImport/1.ts(8,16): error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules. - - -==== tests/cases/conformance/dynamicImport/0.ts (0 errors) ==== - export function foo() { return "foo"; } - -==== tests/cases/conformance/dynamicImport/1.ts (3 errors) ==== - import("./0"); - ~~~~~~~~~~~~~ -!!! error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules. - var p1 = import("./0"); - ~~~~~~~~~~~~~ -!!! error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules. - p1.then(zero => { - return zero.foo(); - }) - - function foo() { - const p2 = import("./0"); - ~~~~~~~~~~~~~ -!!! error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules. - } \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionErrorInES2015.js b/tests/baselines/reference/importCallExpressionErrorInES2015.js deleted file mode 100644 index f07486504ee..00000000000 --- a/tests/baselines/reference/importCallExpressionErrorInES2015.js +++ /dev/null @@ -1,27 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionErrorInES2015.ts] //// - -//// [0.ts] -export function foo() { return "foo"; } - -//// [1.ts] -import("./0"); -var p1 = import("./0"); -p1.then(zero => { - return zero.foo(); -}) - -function foo() { - const p2 = import("./0"); -} - -//// [0.js] -export function foo() { return "foo"; } -//// [1.js] -import("./0"); -var p1 = import("./0"); -p1.then(zero => { - return zero.foo(); -}); -function foo() { - const p2 = import("./0"); -} diff --git a/tests/baselines/reference/importCallExpressionGrammarError.errors.txt b/tests/baselines/reference/importCallExpressionGrammarError.errors.txt deleted file mode 100644 index 6d64808e111..00000000000 --- a/tests/baselines/reference/importCallExpressionGrammarError.errors.txt +++ /dev/null @@ -1,34 +0,0 @@ -tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(5,8): error TS1325: Specifier of dynamic import cannot be spread element. -tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(7,17): error TS1325: Specifier of dynamic import cannot be spread element. -tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(8,12): error TS1324: Dynamic import must have one specifier as an argument. -tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(9,19): error TS1135: Argument expression expected. -tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(9,19): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'undefined'. -tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(10,12): error TS1324: Dynamic import must have one specifier as an argument. -tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(10,19): error TS2307: Cannot find module 'pathToModule'. - - -==== tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts (7 errors) ==== - declare function getSpecifier(): string; - declare var whatToLoad: boolean; - - var a = ["./0"]; - import(...["PathModule"]); - ~~~~~~~~~~~~~~~~~ -!!! error TS1325: Specifier of dynamic import cannot be spread element. - - var p1 = import(...a); - ~~~~ -!!! error TS1325: Specifier of dynamic import cannot be spread element. - const p2 = import(); - ~~~~~~~~ -!!! error TS1324: Dynamic import must have one specifier as an argument. - const p3 = import(,); - -!!! error TS1135: Argument expression expected. - -!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'undefined'. - const p4 = import("pathToModule", "secondModule"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1324: Dynamic import must have one specifier as an argument. - ~~~~~~~~~~~~~~ -!!! error TS2307: Cannot find module 'pathToModule'. \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionGrammarError.js b/tests/baselines/reference/importCallExpressionGrammarError.js deleted file mode 100644 index b30b0c9ddd5..00000000000 --- a/tests/baselines/reference/importCallExpressionGrammarError.js +++ /dev/null @@ -1,19 +0,0 @@ -//// [importCallExpressionGrammarError.ts] -declare function getSpecifier(): string; -declare var whatToLoad: boolean; - -var a = ["./0"]; -import(...["PathModule"]); - -var p1 = import(...a); -const p2 = import(); -const p3 = import(,); -const p4 = import("pathToModule", "secondModule"); - -//// [importCallExpressionGrammarError.js] -var a = ["./0"]; -Promise.resolve().then(function () { return require(...["PathModule"]); }); -var p1 = Promise.resolve().then(function () { return require(...a); }); -const p2 = Promise.resolve().then(function () { return require(); }); -const p3 = Promise.resolve().then(function () { return require(); }); -const p4 = Promise.resolve().then(function () { return require("pathToModule", "secondModule"); }); diff --git a/tests/baselines/reference/importCallExpressionInAMD1.js b/tests/baselines/reference/importCallExpressionInAMD1.js deleted file mode 100644 index e1758173646..00000000000 --- a/tests/baselines/reference/importCallExpressionInAMD1.js +++ /dev/null @@ -1,35 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionInAMD1.ts] //// - -//// [0.ts] -export function foo() { return "foo"; } - -//// [1.ts] -import("./0"); -var p1 = import("./0"); -p1.then(zero => { - return zero.foo(); -}); - -function foo() { - const p2 = import("./0"); -} - -//// [0.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - Object.defineProperty(exports, "__esModule", { value: true }); - function foo() { return "foo"; } - exports.foo = foo; -}); -//// [1.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); }); - var p1 = new Promise(function (resolve_2, reject_2) { require(["./0"], resolve_2, reject_2); }); - p1.then(zero => { - return zero.foo(); - }); - function foo() { - const p2 = new Promise(function (resolve_3, reject_3) { require(["./0"], resolve_3, reject_3); }); - } -}); diff --git a/tests/baselines/reference/importCallExpressionInAMD1.symbols b/tests/baselines/reference/importCallExpressionInAMD1.symbols deleted file mode 100644 index 333251da662..00000000000 --- a/tests/baselines/reference/importCallExpressionInAMD1.symbols +++ /dev/null @@ -1,28 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export function foo() { return "foo"; } ->foo : Symbol(foo, Decl(0.ts, 0, 0)) - -=== tests/cases/conformance/dynamicImport/1.ts === -import("./0"); -var p1 = import("./0"); ->p1 : Symbol(p1, Decl(1.ts, 1, 3)) - -p1.then(zero => { ->p1.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->p1 : Symbol(p1, Decl(1.ts, 1, 3)) ->then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->zero : Symbol(zero, Decl(1.ts, 2, 8)) - - return zero.foo(); ->zero.foo : Symbol(foo, Decl(0.ts, 0, 0)) ->zero : Symbol(zero, Decl(1.ts, 2, 8)) ->foo : Symbol(foo, Decl(0.ts, 0, 0)) - -}); - -function foo() { ->foo : Symbol(foo, Decl(1.ts, 4, 3)) - - const p2 = import("./0"); ->p2 : Symbol(p2, Decl(1.ts, 7, 9)) -} diff --git a/tests/baselines/reference/importCallExpressionInAMD1.types b/tests/baselines/reference/importCallExpressionInAMD1.types deleted file mode 100644 index 59da055ee01..00000000000 --- a/tests/baselines/reference/importCallExpressionInAMD1.types +++ /dev/null @@ -1,39 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export function foo() { return "foo"; } ->foo : () => string ->"foo" : "foo" - -=== tests/cases/conformance/dynamicImport/1.ts === -import("./0"); ->import("./0") : Promise ->"./0" : "./0" - -var p1 = import("./0"); ->p1 : Promise ->import("./0") : Promise ->"./0" : "./0" - -p1.then(zero => { ->p1.then(zero => { return zero.foo();}) : Promise ->p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->p1 : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/dynamicImport/0") => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" - - return zero.foo(); ->zero.foo() : string ->zero.foo : () => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" ->foo : () => string - -}); - -function foo() { ->foo : () => void - - const p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise ->"./0" : "./0" -} diff --git a/tests/baselines/reference/importCallExpressionInAMD2.js b/tests/baselines/reference/importCallExpressionInAMD2.js deleted file mode 100644 index 7347e2f8105..00000000000 --- a/tests/baselines/reference/importCallExpressionInAMD2.js +++ /dev/null @@ -1,39 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionInAMD2.ts] //// - -//// [0.ts] -export class B { - print() { return "I am B"} -} - -//// [2.ts] -// We use Promise for now as there is no way to specify shape of module object -function foo(x: Promise) { - x.then(value => { - let b = new value.B(); - b.print(); - }) -} - -foo(import("./0")); - -//// [0.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - Object.defineProperty(exports, "__esModule", { value: true }); - class B { - print() { return "I am B"; } - } - exports.B = B; -}); -//// [2.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - // We use Promise for now as there is no way to specify shape of module object - function foo(x) { - x.then(value => { - let b = new value.B(); - b.print(); - }); - } - foo(new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); })); -}); diff --git a/tests/baselines/reference/importCallExpressionInAMD2.symbols b/tests/baselines/reference/importCallExpressionInAMD2.symbols deleted file mode 100644 index 16fc79c774f..00000000000 --- a/tests/baselines/reference/importCallExpressionInAMD2.symbols +++ /dev/null @@ -1,34 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : Symbol(B, Decl(0.ts, 0, 0)) - - print() { return "I am B"} ->print : Symbol(B.print, Decl(0.ts, 0, 16)) -} - -=== tests/cases/conformance/dynamicImport/2.ts === -// We use Promise for now as there is no way to specify shape of module object -function foo(x: Promise) { ->foo : Symbol(foo, Decl(2.ts, 0, 0)) ->x : Symbol(x, Decl(2.ts, 1, 13)) ->Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) - - x.then(value => { ->x.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->x : Symbol(x, Decl(2.ts, 1, 13)) ->then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->value : Symbol(value, Decl(2.ts, 2, 11)) - - let b = new value.B(); ->b : Symbol(b, Decl(2.ts, 3, 11)) ->value : Symbol(value, Decl(2.ts, 2, 11)) - - b.print(); ->b : Symbol(b, Decl(2.ts, 3, 11)) - - }) -} - -foo(import("./0")); ->foo : Symbol(foo, Decl(2.ts, 0, 0)) - diff --git a/tests/baselines/reference/importCallExpressionInAMD2.types b/tests/baselines/reference/importCallExpressionInAMD2.types deleted file mode 100644 index 44b17eb51fd..00000000000 --- a/tests/baselines/reference/importCallExpressionInAMD2.types +++ /dev/null @@ -1,46 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : B - - print() { return "I am B"} ->print : () => string ->"I am B" : "I am B" -} - -=== tests/cases/conformance/dynamicImport/2.ts === -// We use Promise for now as there is no way to specify shape of module object -function foo(x: Promise) { ->foo : (x: Promise) => void ->x : Promise ->Promise : Promise - - x.then(value => { ->x.then(value => { let b = new value.B(); b.print(); }) : Promise ->x.then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->x : Promise ->then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->value => { let b = new value.B(); b.print(); } : (value: any) => void ->value : any - - let b = new value.B(); ->b : any ->new value.B() : any ->value.B : any ->value : any ->B : any - - b.print(); ->b.print() : any ->b.print : any ->b : any ->print : any - - }) -} - -foo(import("./0")); ->foo(import("./0")) : void ->foo : (x: Promise) => void ->import("./0") : Promise ->"./0" : "./0" - diff --git a/tests/baselines/reference/importCallExpressionInAMD3.js b/tests/baselines/reference/importCallExpressionInAMD3.js deleted file mode 100644 index 471f35a6415..00000000000 --- a/tests/baselines/reference/importCallExpressionInAMD3.js +++ /dev/null @@ -1,35 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionInAMD3.ts] //// - -//// [0.ts] -export class B { - print() { return "I am B"} -} - -//// [2.ts] -async function foo() { - class C extends (await import("./0")).B {} - var c = new C(); - c.print(); -} -foo(); - -//// [0.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - Object.defineProperty(exports, "__esModule", { value: true }); - class B { - print() { return "I am B"; } - } - exports.B = B; -}); -//// [2.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - async function foo() { - class C extends (await new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); })).B { - } - var c = new C(); - c.print(); - } - foo(); -}); diff --git a/tests/baselines/reference/importCallExpressionInAMD3.symbols b/tests/baselines/reference/importCallExpressionInAMD3.symbols deleted file mode 100644 index 5ca85d6e693..00000000000 --- a/tests/baselines/reference/importCallExpressionInAMD3.symbols +++ /dev/null @@ -1,29 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : Symbol(B, Decl(0.ts, 0, 0)) - - print() { return "I am B"} ->print : Symbol(B.print, Decl(0.ts, 0, 16)) -} - -=== tests/cases/conformance/dynamicImport/2.ts === -async function foo() { ->foo : Symbol(foo, Decl(2.ts, 0, 0)) - - class C extends (await import("./0")).B {} ->C : Symbol(C, Decl(2.ts, 0, 22)) ->(await import("./0")).B : Symbol(B, Decl(0.ts, 0, 0)) ->B : Symbol(B, Decl(0.ts, 0, 0)) - - var c = new C(); ->c : Symbol(c, Decl(2.ts, 2, 7)) ->C : Symbol(C, Decl(2.ts, 0, 22)) - - c.print(); ->c.print : Symbol(B.print, Decl(0.ts, 0, 16)) ->c : Symbol(c, Decl(2.ts, 2, 7)) ->print : Symbol(B.print, Decl(0.ts, 0, 16)) -} -foo(); ->foo : Symbol(foo, Decl(2.ts, 0, 0)) - diff --git a/tests/baselines/reference/importCallExpressionInAMD3.types b/tests/baselines/reference/importCallExpressionInAMD3.types deleted file mode 100644 index e517be6e722..00000000000 --- a/tests/baselines/reference/importCallExpressionInAMD3.types +++ /dev/null @@ -1,37 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : B - - print() { return "I am B"} ->print : () => string ->"I am B" : "I am B" -} - -=== tests/cases/conformance/dynamicImport/2.ts === -async function foo() { ->foo : () => Promise - - class C extends (await import("./0")).B {} ->C : C ->(await import("./0")).B : B ->(await import("./0")) : typeof "tests/cases/conformance/dynamicImport/0" ->await import("./0") : typeof "tests/cases/conformance/dynamicImport/0" ->import("./0") : Promise ->"./0" : "./0" ->B : typeof B - - var c = new C(); ->c : C ->new C() : C ->C : typeof C - - c.print(); ->c.print() : string ->c.print : () => string ->c : C ->print : () => string -} -foo(); ->foo() : Promise ->foo : () => Promise - diff --git a/tests/baselines/reference/importCallExpressionInAMD4.js b/tests/baselines/reference/importCallExpressionInAMD4.js deleted file mode 100644 index 6e50e139116..00000000000 --- a/tests/baselines/reference/importCallExpressionInAMD4.js +++ /dev/null @@ -1,63 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionInAMD4.ts] //// - -//// [0.ts] -export class B { - print() { return "I am B"} -} - -export function foo() { return "foo" } - -//// [1.ts] -export function backup() { return "backup"; } - -//// [2.ts] -declare var console: any; -class C { - private myModule = import("./0"); - method() { - this.myModule.then(Zero => { - console.log(Zero.foo()); - }, async err => { - console.log(err); - let one = await import("./1"); - console.log(one.backup()); - }); - } -} - -//// [0.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - Object.defineProperty(exports, "__esModule", { value: true }); - class B { - print() { return "I am B"; } - } - exports.B = B; - function foo() { return "foo"; } - exports.foo = foo; -}); -//// [1.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - Object.defineProperty(exports, "__esModule", { value: true }); - function backup() { return "backup"; } - exports.backup = backup; -}); -//// [2.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - class C { - constructor() { - this.myModule = new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); }); - } - method() { - this.myModule.then(Zero => { - console.log(Zero.foo()); - }, async (err) => { - console.log(err); - let one = await new Promise(function (resolve_2, reject_2) { require(["./1"], resolve_2, reject_2); }); - console.log(one.backup()); - }); - } - } -}); diff --git a/tests/baselines/reference/importCallExpressionInAMD4.symbols b/tests/baselines/reference/importCallExpressionInAMD4.symbols deleted file mode 100644 index 34a1dcf4d7b..00000000000 --- a/tests/baselines/reference/importCallExpressionInAMD4.symbols +++ /dev/null @@ -1,61 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : Symbol(B, Decl(0.ts, 0, 0)) - - print() { return "I am B"} ->print : Symbol(B.print, Decl(0.ts, 0, 16)) -} - -export function foo() { return "foo" } ->foo : Symbol(foo, Decl(0.ts, 2, 1)) - -=== tests/cases/conformance/dynamicImport/1.ts === -export function backup() { return "backup"; } ->backup : Symbol(backup, Decl(1.ts, 0, 0)) - -=== tests/cases/conformance/dynamicImport/2.ts === -declare var console: any; ->console : Symbol(console, Decl(2.ts, 0, 11)) - -class C { ->C : Symbol(C, Decl(2.ts, 0, 25)) - - private myModule = import("./0"); ->myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) - - method() { ->method : Symbol(C.method, Decl(2.ts, 2, 37)) - - this.myModule.then(Zero => { ->this.myModule.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->this.myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) ->this : Symbol(C, Decl(2.ts, 0, 25)) ->myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) ->then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->Zero : Symbol(Zero, Decl(2.ts, 4, 27)) - - console.log(Zero.foo()); ->console : Symbol(console, Decl(2.ts, 0, 11)) ->Zero.foo : Symbol(foo, Decl(0.ts, 2, 1)) ->Zero : Symbol(Zero, Decl(2.ts, 4, 27)) ->foo : Symbol(foo, Decl(0.ts, 2, 1)) - - }, async err => { ->err : Symbol(err, Decl(2.ts, 6, 16)) - - console.log(err); ->console : Symbol(console, Decl(2.ts, 0, 11)) ->err : Symbol(err, Decl(2.ts, 6, 16)) - - let one = await import("./1"); ->one : Symbol(one, Decl(2.ts, 8, 15)) - - console.log(one.backup()); ->console : Symbol(console, Decl(2.ts, 0, 11)) ->one.backup : Symbol(backup, Decl(1.ts, 0, 0)) ->one : Symbol(one, Decl(2.ts, 8, 15)) ->backup : Symbol(backup, Decl(1.ts, 0, 0)) - - }); - } -} diff --git a/tests/baselines/reference/importCallExpressionInAMD4.types b/tests/baselines/reference/importCallExpressionInAMD4.types deleted file mode 100644 index 2ea666ba672..00000000000 --- a/tests/baselines/reference/importCallExpressionInAMD4.types +++ /dev/null @@ -1,83 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : B - - print() { return "I am B"} ->print : () => string ->"I am B" : "I am B" -} - -export function foo() { return "foo" } ->foo : () => string ->"foo" : "foo" - -=== tests/cases/conformance/dynamicImport/1.ts === -export function backup() { return "backup"; } ->backup : () => string ->"backup" : "backup" - -=== tests/cases/conformance/dynamicImport/2.ts === -declare var console: any; ->console : any - -class C { ->C : C - - private myModule = import("./0"); ->myModule : Promise ->import("./0") : Promise ->"./0" : "./0" - - method() { ->method : () => void - - this.myModule.then(Zero => { ->this.myModule.then(Zero => { console.log(Zero.foo()); }, async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); }) : Promise ->this.myModule.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->this.myModule : Promise ->this : this ->myModule : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/dynamicImport/0") => void ->Zero : typeof "tests/cases/conformance/dynamicImport/0" - - console.log(Zero.foo()); ->console.log(Zero.foo()) : any ->console.log : any ->console : any ->log : any ->Zero.foo() : string ->Zero.foo : () => string ->Zero : typeof "tests/cases/conformance/dynamicImport/0" ->foo : () => string - - }, async err => { ->async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); } : (err: any) => Promise ->err : any - - console.log(err); ->console.log(err) : any ->console.log : any ->console : any ->log : any ->err : any - - let one = await import("./1"); ->one : typeof "tests/cases/conformance/dynamicImport/1" ->await import("./1") : typeof "tests/cases/conformance/dynamicImport/1" ->import("./1") : Promise ->"./1" : "./1" - - console.log(one.backup()); ->console.log(one.backup()) : any ->console.log : any ->console : any ->log : any ->one.backup() : string ->one.backup : () => string ->one : typeof "tests/cases/conformance/dynamicImport/1" ->backup : () => string - - }); - } -} diff --git a/tests/baselines/reference/importCallExpressionInCJS1.js b/tests/baselines/reference/importCallExpressionInCJS1.js deleted file mode 100644 index 3fb298b5bde..00000000000 --- a/tests/baselines/reference/importCallExpressionInCJS1.js +++ /dev/null @@ -1,30 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionInCJS1.ts] //// - -//// [0.ts] -export function foo() { return "foo"; } - -//// [1.ts] -import("./0"); -var p1 = import("./0"); -p1.then(zero => { - return zero.foo(); -}); - -function foo() { - const p2 = import("./0"); -} - -//// [0.js] -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function foo() { return "foo"; } -exports.foo = foo; -//// [1.js] -Promise.resolve().then(function () { return require("./0"); }); -var p1 = Promise.resolve().then(function () { return require("./0"); }); -p1.then(zero => { - return zero.foo(); -}); -function foo() { - const p2 = Promise.resolve().then(function () { return require("./0"); }); -} diff --git a/tests/baselines/reference/importCallExpressionInCJS1.symbols b/tests/baselines/reference/importCallExpressionInCJS1.symbols deleted file mode 100644 index 333251da662..00000000000 --- a/tests/baselines/reference/importCallExpressionInCJS1.symbols +++ /dev/null @@ -1,28 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export function foo() { return "foo"; } ->foo : Symbol(foo, Decl(0.ts, 0, 0)) - -=== tests/cases/conformance/dynamicImport/1.ts === -import("./0"); -var p1 = import("./0"); ->p1 : Symbol(p1, Decl(1.ts, 1, 3)) - -p1.then(zero => { ->p1.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->p1 : Symbol(p1, Decl(1.ts, 1, 3)) ->then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->zero : Symbol(zero, Decl(1.ts, 2, 8)) - - return zero.foo(); ->zero.foo : Symbol(foo, Decl(0.ts, 0, 0)) ->zero : Symbol(zero, Decl(1.ts, 2, 8)) ->foo : Symbol(foo, Decl(0.ts, 0, 0)) - -}); - -function foo() { ->foo : Symbol(foo, Decl(1.ts, 4, 3)) - - const p2 = import("./0"); ->p2 : Symbol(p2, Decl(1.ts, 7, 9)) -} diff --git a/tests/baselines/reference/importCallExpressionInCJS1.types b/tests/baselines/reference/importCallExpressionInCJS1.types deleted file mode 100644 index 59da055ee01..00000000000 --- a/tests/baselines/reference/importCallExpressionInCJS1.types +++ /dev/null @@ -1,39 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export function foo() { return "foo"; } ->foo : () => string ->"foo" : "foo" - -=== tests/cases/conformance/dynamicImport/1.ts === -import("./0"); ->import("./0") : Promise ->"./0" : "./0" - -var p1 = import("./0"); ->p1 : Promise ->import("./0") : Promise ->"./0" : "./0" - -p1.then(zero => { ->p1.then(zero => { return zero.foo();}) : Promise ->p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->p1 : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/dynamicImport/0") => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" - - return zero.foo(); ->zero.foo() : string ->zero.foo : () => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" ->foo : () => string - -}); - -function foo() { ->foo : () => void - - const p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise ->"./0" : "./0" -} diff --git a/tests/baselines/reference/importCallExpressionInCJS2.js b/tests/baselines/reference/importCallExpressionInCJS2.js deleted file mode 100644 index aa983a7a2fe..00000000000 --- a/tests/baselines/reference/importCallExpressionInCJS2.js +++ /dev/null @@ -1,40 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionInCJS2.ts] //// - -//// [0.ts] -export function foo() { return "foo"; } - -//// [1.ts] -export function backup() { return "backup"; } - -//// [2.ts] -async function compute(promise: Promise) { - let j = await promise; - if (!j) { - j = await import("./1"); - return j.backup(); - } - return j.foo(); -} - -compute(import("./0")); - -//// [0.js] -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function foo() { return "foo"; } -exports.foo = foo; -//// [1.js] -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function backup() { return "backup"; } -exports.backup = backup; -//// [2.js] -async function compute(promise) { - let j = await promise; - if (!j) { - j = await Promise.resolve().then(function () { return require("./1"); }); - return j.backup(); - } - return j.foo(); -} -compute(Promise.resolve().then(function () { return require("./0"); })); diff --git a/tests/baselines/reference/importCallExpressionInCJS2.symbols b/tests/baselines/reference/importCallExpressionInCJS2.symbols deleted file mode 100644 index 24f7a5cdb48..00000000000 --- a/tests/baselines/reference/importCallExpressionInCJS2.symbols +++ /dev/null @@ -1,34 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export function foo() { return "foo"; } ->foo : Symbol(foo, Decl(0.ts, 0, 0)) - -=== tests/cases/conformance/dynamicImport/1.ts === -export function backup() { return "backup"; } ->backup : Symbol(backup, Decl(1.ts, 0, 0)) - -=== tests/cases/conformance/dynamicImport/2.ts === -async function compute(promise: Promise) { ->compute : Symbol(compute, Decl(2.ts, 0, 0)) ->promise : Symbol(promise, Decl(2.ts, 0, 23)) ->Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) - - let j = await promise; ->j : Symbol(j, Decl(2.ts, 1, 7)) ->promise : Symbol(promise, Decl(2.ts, 0, 23)) - - if (!j) { ->j : Symbol(j, Decl(2.ts, 1, 7)) - - j = await import("./1"); ->j : Symbol(j, Decl(2.ts, 1, 7)) - - return j.backup(); ->j : Symbol(j, Decl(2.ts, 1, 7)) - } - return j.foo(); ->j : Symbol(j, Decl(2.ts, 1, 7)) -} - -compute(import("./0")); ->compute : Symbol(compute, Decl(2.ts, 0, 0)) - diff --git a/tests/baselines/reference/importCallExpressionInCJS2.types b/tests/baselines/reference/importCallExpressionInCJS2.types deleted file mode 100644 index 063a5224539..00000000000 --- a/tests/baselines/reference/importCallExpressionInCJS2.types +++ /dev/null @@ -1,51 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export function foo() { return "foo"; } ->foo : () => string ->"foo" : "foo" - -=== tests/cases/conformance/dynamicImport/1.ts === -export function backup() { return "backup"; } ->backup : () => string ->"backup" : "backup" - -=== tests/cases/conformance/dynamicImport/2.ts === -async function compute(promise: Promise) { ->compute : (promise: Promise) => Promise ->promise : Promise ->Promise : Promise - - let j = await promise; ->j : any ->await promise : any ->promise : Promise - - if (!j) { ->!j : boolean ->j : any - - j = await import("./1"); ->j = await import("./1") : typeof "tests/cases/conformance/dynamicImport/1" ->j : any ->await import("./1") : typeof "tests/cases/conformance/dynamicImport/1" ->import("./1") : Promise ->"./1" : "./1" - - return j.backup(); ->j.backup() : any ->j.backup : any ->j : any ->backup : any - } - return j.foo(); ->j.foo() : any ->j.foo : any ->j : any ->foo : any -} - -compute(import("./0")); ->compute(import("./0")) : Promise ->compute : (promise: Promise) => Promise ->import("./0") : Promise ->"./0" : "./0" - diff --git a/tests/baselines/reference/importCallExpressionInCJS3.js b/tests/baselines/reference/importCallExpressionInCJS3.js deleted file mode 100644 index 2f956d9ac3a..00000000000 --- a/tests/baselines/reference/importCallExpressionInCJS3.js +++ /dev/null @@ -1,34 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionInCJS3.ts] //// - -//// [0.ts] -export class B { - print() { return "I am B"} -} - -//// [2.ts] -// We use Promise for now as there is no way to specify shape of module object -function foo(x: Promise) { - x.then(value => { - let b = new value.B(); - b.print(); - }) -} - -foo(import("./0")); - -//// [0.js] -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -class B { - print() { return "I am B"; } -} -exports.B = B; -//// [2.js] -// We use Promise for now as there is no way to specify shape of module object -function foo(x) { - x.then(value => { - let b = new value.B(); - b.print(); - }); -} -foo(Promise.resolve().then(function () { return require("./0"); })); diff --git a/tests/baselines/reference/importCallExpressionInCJS3.symbols b/tests/baselines/reference/importCallExpressionInCJS3.symbols deleted file mode 100644 index 16fc79c774f..00000000000 --- a/tests/baselines/reference/importCallExpressionInCJS3.symbols +++ /dev/null @@ -1,34 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : Symbol(B, Decl(0.ts, 0, 0)) - - print() { return "I am B"} ->print : Symbol(B.print, Decl(0.ts, 0, 16)) -} - -=== tests/cases/conformance/dynamicImport/2.ts === -// We use Promise for now as there is no way to specify shape of module object -function foo(x: Promise) { ->foo : Symbol(foo, Decl(2.ts, 0, 0)) ->x : Symbol(x, Decl(2.ts, 1, 13)) ->Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) - - x.then(value => { ->x.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->x : Symbol(x, Decl(2.ts, 1, 13)) ->then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->value : Symbol(value, Decl(2.ts, 2, 11)) - - let b = new value.B(); ->b : Symbol(b, Decl(2.ts, 3, 11)) ->value : Symbol(value, Decl(2.ts, 2, 11)) - - b.print(); ->b : Symbol(b, Decl(2.ts, 3, 11)) - - }) -} - -foo(import("./0")); ->foo : Symbol(foo, Decl(2.ts, 0, 0)) - diff --git a/tests/baselines/reference/importCallExpressionInCJS3.types b/tests/baselines/reference/importCallExpressionInCJS3.types deleted file mode 100644 index 44b17eb51fd..00000000000 --- a/tests/baselines/reference/importCallExpressionInCJS3.types +++ /dev/null @@ -1,46 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : B - - print() { return "I am B"} ->print : () => string ->"I am B" : "I am B" -} - -=== tests/cases/conformance/dynamicImport/2.ts === -// We use Promise for now as there is no way to specify shape of module object -function foo(x: Promise) { ->foo : (x: Promise) => void ->x : Promise ->Promise : Promise - - x.then(value => { ->x.then(value => { let b = new value.B(); b.print(); }) : Promise ->x.then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->x : Promise ->then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->value => { let b = new value.B(); b.print(); } : (value: any) => void ->value : any - - let b = new value.B(); ->b : any ->new value.B() : any ->value.B : any ->value : any ->B : any - - b.print(); ->b.print() : any ->b.print : any ->b : any ->print : any - - }) -} - -foo(import("./0")); ->foo(import("./0")) : void ->foo : (x: Promise) => void ->import("./0") : Promise ->"./0" : "./0" - diff --git a/tests/baselines/reference/importCallExpressionInCJS4.js b/tests/baselines/reference/importCallExpressionInCJS4.js deleted file mode 100644 index 554a0b222ab..00000000000 --- a/tests/baselines/reference/importCallExpressionInCJS4.js +++ /dev/null @@ -1,30 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionInCJS4.ts] //// - -//// [0.ts] -export class B { - print() { return "I am B"} -} - -//// [2.ts] -async function foo() { - class C extends (await import("./0")).B {} - var c = new C(); - c.print(); -} -foo(); - -//// [0.js] -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -class B { - print() { return "I am B"; } -} -exports.B = B; -//// [2.js] -async function foo() { - class C extends (await Promise.resolve().then(function () { return require("./0"); })).B { - } - var c = new C(); - c.print(); -} -foo(); diff --git a/tests/baselines/reference/importCallExpressionInCJS4.symbols b/tests/baselines/reference/importCallExpressionInCJS4.symbols deleted file mode 100644 index 5ca85d6e693..00000000000 --- a/tests/baselines/reference/importCallExpressionInCJS4.symbols +++ /dev/null @@ -1,29 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : Symbol(B, Decl(0.ts, 0, 0)) - - print() { return "I am B"} ->print : Symbol(B.print, Decl(0.ts, 0, 16)) -} - -=== tests/cases/conformance/dynamicImport/2.ts === -async function foo() { ->foo : Symbol(foo, Decl(2.ts, 0, 0)) - - class C extends (await import("./0")).B {} ->C : Symbol(C, Decl(2.ts, 0, 22)) ->(await import("./0")).B : Symbol(B, Decl(0.ts, 0, 0)) ->B : Symbol(B, Decl(0.ts, 0, 0)) - - var c = new C(); ->c : Symbol(c, Decl(2.ts, 2, 7)) ->C : Symbol(C, Decl(2.ts, 0, 22)) - - c.print(); ->c.print : Symbol(B.print, Decl(0.ts, 0, 16)) ->c : Symbol(c, Decl(2.ts, 2, 7)) ->print : Symbol(B.print, Decl(0.ts, 0, 16)) -} -foo(); ->foo : Symbol(foo, Decl(2.ts, 0, 0)) - diff --git a/tests/baselines/reference/importCallExpressionInCJS4.types b/tests/baselines/reference/importCallExpressionInCJS4.types deleted file mode 100644 index e517be6e722..00000000000 --- a/tests/baselines/reference/importCallExpressionInCJS4.types +++ /dev/null @@ -1,37 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : B - - print() { return "I am B"} ->print : () => string ->"I am B" : "I am B" -} - -=== tests/cases/conformance/dynamicImport/2.ts === -async function foo() { ->foo : () => Promise - - class C extends (await import("./0")).B {} ->C : C ->(await import("./0")).B : B ->(await import("./0")) : typeof "tests/cases/conformance/dynamicImport/0" ->await import("./0") : typeof "tests/cases/conformance/dynamicImport/0" ->import("./0") : Promise ->"./0" : "./0" ->B : typeof B - - var c = new C(); ->c : C ->new C() : C ->C : typeof C - - c.print(); ->c.print() : string ->c.print : () => string ->c : C ->print : () => string -} -foo(); ->foo() : Promise ->foo : () => Promise - diff --git a/tests/baselines/reference/importCallExpressionInCJS5.js b/tests/baselines/reference/importCallExpressionInCJS5.js deleted file mode 100644 index 762da592827..00000000000 --- a/tests/baselines/reference/importCallExpressionInCJS5.js +++ /dev/null @@ -1,56 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionInCJS5.ts] //// - -//// [0.ts] -export class B { - print() { return "I am B"} -} - -export function foo() { return "foo" } - -//// [1.ts] -export function backup() { return "backup"; } - -//// [2.ts] -declare var console: any; -class C { - private myModule = import("./0"); - method() { - this.myModule.then(Zero => { - console.log(Zero.foo()); - }, async err => { - console.log(err); - let one = await import("./1"); - console.log(one.backup()); - }); - } -} - -//// [0.js] -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -class B { - print() { return "I am B"; } -} -exports.B = B; -function foo() { return "foo"; } -exports.foo = foo; -//// [1.js] -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function backup() { return "backup"; } -exports.backup = backup; -//// [2.js] -class C { - constructor() { - this.myModule = Promise.resolve().then(function () { return require("./0"); }); - } - method() { - this.myModule.then(Zero => { - console.log(Zero.foo()); - }, async (err) => { - console.log(err); - let one = await Promise.resolve().then(function () { return require("./1"); }); - console.log(one.backup()); - }); - } -} diff --git a/tests/baselines/reference/importCallExpressionInCJS5.symbols b/tests/baselines/reference/importCallExpressionInCJS5.symbols deleted file mode 100644 index 34a1dcf4d7b..00000000000 --- a/tests/baselines/reference/importCallExpressionInCJS5.symbols +++ /dev/null @@ -1,61 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : Symbol(B, Decl(0.ts, 0, 0)) - - print() { return "I am B"} ->print : Symbol(B.print, Decl(0.ts, 0, 16)) -} - -export function foo() { return "foo" } ->foo : Symbol(foo, Decl(0.ts, 2, 1)) - -=== tests/cases/conformance/dynamicImport/1.ts === -export function backup() { return "backup"; } ->backup : Symbol(backup, Decl(1.ts, 0, 0)) - -=== tests/cases/conformance/dynamicImport/2.ts === -declare var console: any; ->console : Symbol(console, Decl(2.ts, 0, 11)) - -class C { ->C : Symbol(C, Decl(2.ts, 0, 25)) - - private myModule = import("./0"); ->myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) - - method() { ->method : Symbol(C.method, Decl(2.ts, 2, 37)) - - this.myModule.then(Zero => { ->this.myModule.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->this.myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) ->this : Symbol(C, Decl(2.ts, 0, 25)) ->myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) ->then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->Zero : Symbol(Zero, Decl(2.ts, 4, 27)) - - console.log(Zero.foo()); ->console : Symbol(console, Decl(2.ts, 0, 11)) ->Zero.foo : Symbol(foo, Decl(0.ts, 2, 1)) ->Zero : Symbol(Zero, Decl(2.ts, 4, 27)) ->foo : Symbol(foo, Decl(0.ts, 2, 1)) - - }, async err => { ->err : Symbol(err, Decl(2.ts, 6, 16)) - - console.log(err); ->console : Symbol(console, Decl(2.ts, 0, 11)) ->err : Symbol(err, Decl(2.ts, 6, 16)) - - let one = await import("./1"); ->one : Symbol(one, Decl(2.ts, 8, 15)) - - console.log(one.backup()); ->console : Symbol(console, Decl(2.ts, 0, 11)) ->one.backup : Symbol(backup, Decl(1.ts, 0, 0)) ->one : Symbol(one, Decl(2.ts, 8, 15)) ->backup : Symbol(backup, Decl(1.ts, 0, 0)) - - }); - } -} diff --git a/tests/baselines/reference/importCallExpressionInCJS5.types b/tests/baselines/reference/importCallExpressionInCJS5.types deleted file mode 100644 index 2ea666ba672..00000000000 --- a/tests/baselines/reference/importCallExpressionInCJS5.types +++ /dev/null @@ -1,83 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : B - - print() { return "I am B"} ->print : () => string ->"I am B" : "I am B" -} - -export function foo() { return "foo" } ->foo : () => string ->"foo" : "foo" - -=== tests/cases/conformance/dynamicImport/1.ts === -export function backup() { return "backup"; } ->backup : () => string ->"backup" : "backup" - -=== tests/cases/conformance/dynamicImport/2.ts === -declare var console: any; ->console : any - -class C { ->C : C - - private myModule = import("./0"); ->myModule : Promise ->import("./0") : Promise ->"./0" : "./0" - - method() { ->method : () => void - - this.myModule.then(Zero => { ->this.myModule.then(Zero => { console.log(Zero.foo()); }, async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); }) : Promise ->this.myModule.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->this.myModule : Promise ->this : this ->myModule : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/dynamicImport/0") => void ->Zero : typeof "tests/cases/conformance/dynamicImport/0" - - console.log(Zero.foo()); ->console.log(Zero.foo()) : any ->console.log : any ->console : any ->log : any ->Zero.foo() : string ->Zero.foo : () => string ->Zero : typeof "tests/cases/conformance/dynamicImport/0" ->foo : () => string - - }, async err => { ->async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); } : (err: any) => Promise ->err : any - - console.log(err); ->console.log(err) : any ->console.log : any ->console : any ->log : any ->err : any - - let one = await import("./1"); ->one : typeof "tests/cases/conformance/dynamicImport/1" ->await import("./1") : typeof "tests/cases/conformance/dynamicImport/1" ->import("./1") : Promise ->"./1" : "./1" - - console.log(one.backup()); ->console.log(one.backup()) : any ->console.log : any ->console : any ->log : any ->one.backup() : string ->one.backup : () => string ->one : typeof "tests/cases/conformance/dynamicImport/1" ->backup : () => string - - }); - } -} diff --git a/tests/baselines/reference/importCallExpressionInScriptContext1.js b/tests/baselines/reference/importCallExpressionInScriptContext1.js deleted file mode 100644 index 2c2d2f904d5..00000000000 --- a/tests/baselines/reference/importCallExpressionInScriptContext1.js +++ /dev/null @@ -1,17 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionInScriptContext1.ts] //// - -//// [0.ts] -export function foo() { return "foo"; } - -//// [1.ts] -var p1 = import("./0"); -function arguments() { } // this is allow as the file doesn't have implicit "use strict" - -//// [0.js] -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function foo() { return "foo"; } -exports.foo = foo; -//// [1.js] -var p1 = Promise.resolve().then(function () { return require("./0"); }); -function arguments() { } // this is allow as the file doesn't have implicit "use strict" diff --git a/tests/baselines/reference/importCallExpressionInScriptContext1.symbols b/tests/baselines/reference/importCallExpressionInScriptContext1.symbols deleted file mode 100644 index 513612056a8..00000000000 --- a/tests/baselines/reference/importCallExpressionInScriptContext1.symbols +++ /dev/null @@ -1,11 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export function foo() { return "foo"; } ->foo : Symbol(foo, Decl(0.ts, 0, 0)) - -=== tests/cases/conformance/dynamicImport/1.ts === -var p1 = import("./0"); ->p1 : Symbol(p1, Decl(1.ts, 0, 3)) - -function arguments() { } // this is allow as the file doesn't have implicit "use strict" ->arguments : Symbol(arguments, Decl(1.ts, 0, 23)) - diff --git a/tests/baselines/reference/importCallExpressionInScriptContext1.types b/tests/baselines/reference/importCallExpressionInScriptContext1.types deleted file mode 100644 index c318667c7d8..00000000000 --- a/tests/baselines/reference/importCallExpressionInScriptContext1.types +++ /dev/null @@ -1,14 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export function foo() { return "foo"; } ->foo : () => string ->"foo" : "foo" - -=== tests/cases/conformance/dynamicImport/1.ts === -var p1 = import("./0"); ->p1 : Promise ->import("./0") : Promise ->"./0" : "./0" - -function arguments() { } // this is allow as the file doesn't have implicit "use strict" ->arguments : () => void - diff --git a/tests/baselines/reference/importCallExpressionInScriptContext2.errors.txt b/tests/baselines/reference/importCallExpressionInScriptContext2.errors.txt deleted file mode 100644 index 9020963f68f..00000000000 --- a/tests/baselines/reference/importCallExpressionInScriptContext2.errors.txt +++ /dev/null @@ -1,12 +0,0 @@ -tests/cases/conformance/dynamicImport/1.ts(3,10): error TS1100: Invalid use of 'arguments' in strict mode. - - -==== tests/cases/conformance/dynamicImport/0.ts (0 errors) ==== - export function foo() { return "foo"; } - -==== tests/cases/conformance/dynamicImport/1.ts (1 errors) ==== - "use strict" - var p1 = import("./0"); - function arguments() { } - ~~~~~~~~~ -!!! error TS1100: Invalid use of 'arguments' in strict mode. \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionInScriptContext2.js b/tests/baselines/reference/importCallExpressionInScriptContext2.js deleted file mode 100644 index 6b6e0109fda..00000000000 --- a/tests/baselines/reference/importCallExpressionInScriptContext2.js +++ /dev/null @@ -1,19 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionInScriptContext2.ts] //// - -//// [0.ts] -export function foo() { return "foo"; } - -//// [1.ts] -"use strict" -var p1 = import("./0"); -function arguments() { } - -//// [0.js] -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function foo() { return "foo"; } -exports.foo = foo; -//// [1.js] -"use strict"; -var p1 = Promise.resolve().then(function () { return require("./0"); }); -function arguments() { } diff --git a/tests/baselines/reference/importCallExpressionInSystem1.js b/tests/baselines/reference/importCallExpressionInSystem1.js deleted file mode 100644 index d74eb6ffc76..00000000000 --- a/tests/baselines/reference/importCallExpressionInSystem1.js +++ /dev/null @@ -1,46 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionInSystem1.ts] //// - -//// [0.ts] -export function foo() { return "foo"; } - -//// [1.ts] -import("./0"); -var p1 = import("./0"); -p1.then(zero => { - return zero.foo(); -}); - -function foo() { - const p2 = import("./0"); -} - -//// [0.js] -System.register([], function (exports_1, context_1) { - "use strict"; - var __moduleName = context_1 && context_1.id; - function foo() { return "foo"; } - exports_1("foo", foo); - return { - setters: [], - execute: function () { - } - }; -}); -//// [1.js] -System.register([], function (exports_1, context_1) { - var __moduleName = context_1 && context_1.id; - function foo() { - const p2 = context_1.import("./0"); - } - var p1; - return { - setters: [], - execute: function () { - context_1.import("./0"); - p1 = context_1.import("./0"); - p1.then(zero => { - return zero.foo(); - }); - } - }; -}); diff --git a/tests/baselines/reference/importCallExpressionInSystem1.symbols b/tests/baselines/reference/importCallExpressionInSystem1.symbols deleted file mode 100644 index 333251da662..00000000000 --- a/tests/baselines/reference/importCallExpressionInSystem1.symbols +++ /dev/null @@ -1,28 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export function foo() { return "foo"; } ->foo : Symbol(foo, Decl(0.ts, 0, 0)) - -=== tests/cases/conformance/dynamicImport/1.ts === -import("./0"); -var p1 = import("./0"); ->p1 : Symbol(p1, Decl(1.ts, 1, 3)) - -p1.then(zero => { ->p1.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->p1 : Symbol(p1, Decl(1.ts, 1, 3)) ->then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->zero : Symbol(zero, Decl(1.ts, 2, 8)) - - return zero.foo(); ->zero.foo : Symbol(foo, Decl(0.ts, 0, 0)) ->zero : Symbol(zero, Decl(1.ts, 2, 8)) ->foo : Symbol(foo, Decl(0.ts, 0, 0)) - -}); - -function foo() { ->foo : Symbol(foo, Decl(1.ts, 4, 3)) - - const p2 = import("./0"); ->p2 : Symbol(p2, Decl(1.ts, 7, 9)) -} diff --git a/tests/baselines/reference/importCallExpressionInSystem1.types b/tests/baselines/reference/importCallExpressionInSystem1.types deleted file mode 100644 index 59da055ee01..00000000000 --- a/tests/baselines/reference/importCallExpressionInSystem1.types +++ /dev/null @@ -1,39 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export function foo() { return "foo"; } ->foo : () => string ->"foo" : "foo" - -=== tests/cases/conformance/dynamicImport/1.ts === -import("./0"); ->import("./0") : Promise ->"./0" : "./0" - -var p1 = import("./0"); ->p1 : Promise ->import("./0") : Promise ->"./0" : "./0" - -p1.then(zero => { ->p1.then(zero => { return zero.foo();}) : Promise ->p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->p1 : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/dynamicImport/0") => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" - - return zero.foo(); ->zero.foo() : string ->zero.foo : () => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" ->foo : () => string - -}); - -function foo() { ->foo : () => void - - const p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise ->"./0" : "./0" -} diff --git a/tests/baselines/reference/importCallExpressionInSystem2.js b/tests/baselines/reference/importCallExpressionInSystem2.js deleted file mode 100644 index ea84e47e63c..00000000000 --- a/tests/baselines/reference/importCallExpressionInSystem2.js +++ /dev/null @@ -1,50 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionInSystem2.ts] //// - -//// [0.ts] -export class B { - print() { return "I am B"} -} - -//// [2.ts] -// We use Promise for now as there is no way to specify shape of module object -function foo(x: Promise) { - x.then(value => { - let b = new value.B(); - b.print(); - }) -} - -foo(import("./0")); - -//// [0.js] -System.register([], function (exports_1, context_1) { - "use strict"; - var __moduleName = context_1 && context_1.id; - var B; - return { - setters: [], - execute: function () { - B = class B { - print() { return "I am B"; } - }; - exports_1("B", B); - } - }; -}); -//// [2.js] -System.register([], function (exports_1, context_1) { - var __moduleName = context_1 && context_1.id; - // We use Promise for now as there is no way to specify shape of module object - function foo(x) { - x.then(value => { - let b = new value.B(); - b.print(); - }); - } - return { - setters: [], - execute: function () { - foo(context_1.import("./0")); - } - }; -}); diff --git a/tests/baselines/reference/importCallExpressionInSystem2.symbols b/tests/baselines/reference/importCallExpressionInSystem2.symbols deleted file mode 100644 index 16fc79c774f..00000000000 --- a/tests/baselines/reference/importCallExpressionInSystem2.symbols +++ /dev/null @@ -1,34 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : Symbol(B, Decl(0.ts, 0, 0)) - - print() { return "I am B"} ->print : Symbol(B.print, Decl(0.ts, 0, 16)) -} - -=== tests/cases/conformance/dynamicImport/2.ts === -// We use Promise for now as there is no way to specify shape of module object -function foo(x: Promise) { ->foo : Symbol(foo, Decl(2.ts, 0, 0)) ->x : Symbol(x, Decl(2.ts, 1, 13)) ->Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) - - x.then(value => { ->x.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->x : Symbol(x, Decl(2.ts, 1, 13)) ->then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->value : Symbol(value, Decl(2.ts, 2, 11)) - - let b = new value.B(); ->b : Symbol(b, Decl(2.ts, 3, 11)) ->value : Symbol(value, Decl(2.ts, 2, 11)) - - b.print(); ->b : Symbol(b, Decl(2.ts, 3, 11)) - - }) -} - -foo(import("./0")); ->foo : Symbol(foo, Decl(2.ts, 0, 0)) - diff --git a/tests/baselines/reference/importCallExpressionInSystem2.types b/tests/baselines/reference/importCallExpressionInSystem2.types deleted file mode 100644 index 44b17eb51fd..00000000000 --- a/tests/baselines/reference/importCallExpressionInSystem2.types +++ /dev/null @@ -1,46 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : B - - print() { return "I am B"} ->print : () => string ->"I am B" : "I am B" -} - -=== tests/cases/conformance/dynamicImport/2.ts === -// We use Promise for now as there is no way to specify shape of module object -function foo(x: Promise) { ->foo : (x: Promise) => void ->x : Promise ->Promise : Promise - - x.then(value => { ->x.then(value => { let b = new value.B(); b.print(); }) : Promise ->x.then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->x : Promise ->then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->value => { let b = new value.B(); b.print(); } : (value: any) => void ->value : any - - let b = new value.B(); ->b : any ->new value.B() : any ->value.B : any ->value : any ->B : any - - b.print(); ->b.print() : any ->b.print : any ->b : any ->print : any - - }) -} - -foo(import("./0")); ->foo(import("./0")) : void ->foo : (x: Promise) => void ->import("./0") : Promise ->"./0" : "./0" - diff --git a/tests/baselines/reference/importCallExpressionInSystem3.js b/tests/baselines/reference/importCallExpressionInSystem3.js deleted file mode 100644 index 309be9114fe..00000000000 --- a/tests/baselines/reference/importCallExpressionInSystem3.js +++ /dev/null @@ -1,46 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionInSystem3.ts] //// - -//// [0.ts] -export class B { - print() { return "I am B"} -} - -//// [2.ts] -async function foo() { - class C extends (await import("./0")).B {} - var c = new C(); - c.print(); -} -foo(); - -//// [0.js] -System.register([], function (exports_1, context_1) { - "use strict"; - var __moduleName = context_1 && context_1.id; - var B; - return { - setters: [], - execute: function () { - B = class B { - print() { return "I am B"; } - }; - exports_1("B", B); - } - }; -}); -//// [2.js] -System.register([], function (exports_1, context_1) { - var __moduleName = context_1 && context_1.id; - async function foo() { - class C extends (await context_1.import("./0")).B { - } - var c = new C(); - c.print(); - } - return { - setters: [], - execute: function () { - foo(); - } - }; -}); diff --git a/tests/baselines/reference/importCallExpressionInSystem3.symbols b/tests/baselines/reference/importCallExpressionInSystem3.symbols deleted file mode 100644 index 5ca85d6e693..00000000000 --- a/tests/baselines/reference/importCallExpressionInSystem3.symbols +++ /dev/null @@ -1,29 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : Symbol(B, Decl(0.ts, 0, 0)) - - print() { return "I am B"} ->print : Symbol(B.print, Decl(0.ts, 0, 16)) -} - -=== tests/cases/conformance/dynamicImport/2.ts === -async function foo() { ->foo : Symbol(foo, Decl(2.ts, 0, 0)) - - class C extends (await import("./0")).B {} ->C : Symbol(C, Decl(2.ts, 0, 22)) ->(await import("./0")).B : Symbol(B, Decl(0.ts, 0, 0)) ->B : Symbol(B, Decl(0.ts, 0, 0)) - - var c = new C(); ->c : Symbol(c, Decl(2.ts, 2, 7)) ->C : Symbol(C, Decl(2.ts, 0, 22)) - - c.print(); ->c.print : Symbol(B.print, Decl(0.ts, 0, 16)) ->c : Symbol(c, Decl(2.ts, 2, 7)) ->print : Symbol(B.print, Decl(0.ts, 0, 16)) -} -foo(); ->foo : Symbol(foo, Decl(2.ts, 0, 0)) - diff --git a/tests/baselines/reference/importCallExpressionInSystem3.types b/tests/baselines/reference/importCallExpressionInSystem3.types deleted file mode 100644 index e517be6e722..00000000000 --- a/tests/baselines/reference/importCallExpressionInSystem3.types +++ /dev/null @@ -1,37 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : B - - print() { return "I am B"} ->print : () => string ->"I am B" : "I am B" -} - -=== tests/cases/conformance/dynamicImport/2.ts === -async function foo() { ->foo : () => Promise - - class C extends (await import("./0")).B {} ->C : C ->(await import("./0")).B : B ->(await import("./0")) : typeof "tests/cases/conformance/dynamicImport/0" ->await import("./0") : typeof "tests/cases/conformance/dynamicImport/0" ->import("./0") : Promise ->"./0" : "./0" ->B : typeof B - - var c = new C(); ->c : C ->new C() : C ->C : typeof C - - c.print(); ->c.print() : string ->c.print : () => string ->c : C ->print : () => string -} -foo(); ->foo() : Promise ->foo : () => Promise - diff --git a/tests/baselines/reference/importCallExpressionInSystem4.js b/tests/baselines/reference/importCallExpressionInSystem4.js deleted file mode 100644 index ac01a0439e8..00000000000 --- a/tests/baselines/reference/importCallExpressionInSystem4.js +++ /dev/null @@ -1,80 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionInSystem4.ts] //// - -//// [0.ts] -export class B { - print() { return "I am B"} -} - -export function foo() { return "foo" } - -//// [1.ts] -export function backup() { return "backup"; } - -//// [2.ts] -declare var console: any; -class C { - private myModule = import("./0"); - method() { - this.myModule.then(Zero => { - console.log(Zero.foo()); - }, async err => { - console.log(err); - let one = await import("./1"); - console.log(one.backup()); - }); - } -} - -//// [0.js] -System.register([], function (exports_1, context_1) { - "use strict"; - var __moduleName = context_1 && context_1.id; - function foo() { return "foo"; } - exports_1("foo", foo); - var B; - return { - setters: [], - execute: function () { - B = class B { - print() { return "I am B"; } - }; - exports_1("B", B); - } - }; -}); -//// [1.js] -System.register([], function (exports_1, context_1) { - "use strict"; - var __moduleName = context_1 && context_1.id; - function backup() { return "backup"; } - exports_1("backup", backup); - return { - setters: [], - execute: function () { - } - }; -}); -//// [2.js] -System.register([], function (exports_1, context_1) { - var __moduleName = context_1 && context_1.id; - var C; - return { - setters: [], - execute: function () { - C = class C { - constructor() { - this.myModule = context_1.import("./0"); - } - method() { - this.myModule.then(Zero => { - console.log(Zero.foo()); - }, async (err) => { - console.log(err); - let one = await context_1.import("./1"); - console.log(one.backup()); - }); - } - }; - } - }; -}); diff --git a/tests/baselines/reference/importCallExpressionInSystem4.symbols b/tests/baselines/reference/importCallExpressionInSystem4.symbols deleted file mode 100644 index 34a1dcf4d7b..00000000000 --- a/tests/baselines/reference/importCallExpressionInSystem4.symbols +++ /dev/null @@ -1,61 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : Symbol(B, Decl(0.ts, 0, 0)) - - print() { return "I am B"} ->print : Symbol(B.print, Decl(0.ts, 0, 16)) -} - -export function foo() { return "foo" } ->foo : Symbol(foo, Decl(0.ts, 2, 1)) - -=== tests/cases/conformance/dynamicImport/1.ts === -export function backup() { return "backup"; } ->backup : Symbol(backup, Decl(1.ts, 0, 0)) - -=== tests/cases/conformance/dynamicImport/2.ts === -declare var console: any; ->console : Symbol(console, Decl(2.ts, 0, 11)) - -class C { ->C : Symbol(C, Decl(2.ts, 0, 25)) - - private myModule = import("./0"); ->myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) - - method() { ->method : Symbol(C.method, Decl(2.ts, 2, 37)) - - this.myModule.then(Zero => { ->this.myModule.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->this.myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) ->this : Symbol(C, Decl(2.ts, 0, 25)) ->myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) ->then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->Zero : Symbol(Zero, Decl(2.ts, 4, 27)) - - console.log(Zero.foo()); ->console : Symbol(console, Decl(2.ts, 0, 11)) ->Zero.foo : Symbol(foo, Decl(0.ts, 2, 1)) ->Zero : Symbol(Zero, Decl(2.ts, 4, 27)) ->foo : Symbol(foo, Decl(0.ts, 2, 1)) - - }, async err => { ->err : Symbol(err, Decl(2.ts, 6, 16)) - - console.log(err); ->console : Symbol(console, Decl(2.ts, 0, 11)) ->err : Symbol(err, Decl(2.ts, 6, 16)) - - let one = await import("./1"); ->one : Symbol(one, Decl(2.ts, 8, 15)) - - console.log(one.backup()); ->console : Symbol(console, Decl(2.ts, 0, 11)) ->one.backup : Symbol(backup, Decl(1.ts, 0, 0)) ->one : Symbol(one, Decl(2.ts, 8, 15)) ->backup : Symbol(backup, Decl(1.ts, 0, 0)) - - }); - } -} diff --git a/tests/baselines/reference/importCallExpressionInSystem4.types b/tests/baselines/reference/importCallExpressionInSystem4.types deleted file mode 100644 index 2ea666ba672..00000000000 --- a/tests/baselines/reference/importCallExpressionInSystem4.types +++ /dev/null @@ -1,83 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : B - - print() { return "I am B"} ->print : () => string ->"I am B" : "I am B" -} - -export function foo() { return "foo" } ->foo : () => string ->"foo" : "foo" - -=== tests/cases/conformance/dynamicImport/1.ts === -export function backup() { return "backup"; } ->backup : () => string ->"backup" : "backup" - -=== tests/cases/conformance/dynamicImport/2.ts === -declare var console: any; ->console : any - -class C { ->C : C - - private myModule = import("./0"); ->myModule : Promise ->import("./0") : Promise ->"./0" : "./0" - - method() { ->method : () => void - - this.myModule.then(Zero => { ->this.myModule.then(Zero => { console.log(Zero.foo()); }, async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); }) : Promise ->this.myModule.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->this.myModule : Promise ->this : this ->myModule : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/dynamicImport/0") => void ->Zero : typeof "tests/cases/conformance/dynamicImport/0" - - console.log(Zero.foo()); ->console.log(Zero.foo()) : any ->console.log : any ->console : any ->log : any ->Zero.foo() : string ->Zero.foo : () => string ->Zero : typeof "tests/cases/conformance/dynamicImport/0" ->foo : () => string - - }, async err => { ->async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); } : (err: any) => Promise ->err : any - - console.log(err); ->console.log(err) : any ->console.log : any ->console : any ->log : any ->err : any - - let one = await import("./1"); ->one : typeof "tests/cases/conformance/dynamicImport/1" ->await import("./1") : typeof "tests/cases/conformance/dynamicImport/1" ->import("./1") : Promise ->"./1" : "./1" - - console.log(one.backup()); ->console.log(one.backup()) : any ->console.log : any ->console : any ->log : any ->one.backup() : string ->one.backup : () => string ->one : typeof "tests/cases/conformance/dynamicImport/1" ->backup : () => string - - }); - } -} diff --git a/tests/baselines/reference/importCallExpressionInUMD1.js b/tests/baselines/reference/importCallExpressionInUMD1.js deleted file mode 100644 index f1bfcd3cc71..00000000000 --- a/tests/baselines/reference/importCallExpressionInUMD1.js +++ /dev/null @@ -1,52 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionInUMD1.ts] //// - -//// [0.ts] -export function foo() { return "foo"; } - -//// [1.ts] -import("./0"); -var p1 = import("./0"); -p1.then(zero => { - return zero.foo(); -}); - -function foo() { - const p2 = import("./0"); -} - -//// [0.js] -(function (factory) { - if (typeof module === "object" && typeof module.exports === "object") { - var v = factory(require, exports); - if (v !== undefined) module.exports = v; - } - else if (typeof define === "function" && define.amd) { - define(["require", "exports"], factory); - } -})(function (require, exports) { - "use strict"; - Object.defineProperty(exports, "__esModule", { value: true }); - function foo() { return "foo"; } - exports.foo = foo; -}); -//// [1.js] -(function (factory) { - if (typeof module === "object" && typeof module.exports === "object") { - var v = factory(require, exports); - if (v !== undefined) module.exports = v; - } - else if (typeof define === "function" && define.amd) { - define(["require", "exports"], factory); - } -})(function (require, exports) { - "use strict"; - var __syncRequire = typeof module === "object" && typeof module.exports === "object"; - __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); }); - var p1 = __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_2, reject_2) { require(["./0"], resolve_2, reject_2); }); - p1.then(zero => { - return zero.foo(); - }); - function foo() { - const p2 = __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_3, reject_3) { require(["./0"], resolve_3, reject_3); }); - } -}); diff --git a/tests/baselines/reference/importCallExpressionInUMD1.symbols b/tests/baselines/reference/importCallExpressionInUMD1.symbols deleted file mode 100644 index 333251da662..00000000000 --- a/tests/baselines/reference/importCallExpressionInUMD1.symbols +++ /dev/null @@ -1,28 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export function foo() { return "foo"; } ->foo : Symbol(foo, Decl(0.ts, 0, 0)) - -=== tests/cases/conformance/dynamicImport/1.ts === -import("./0"); -var p1 = import("./0"); ->p1 : Symbol(p1, Decl(1.ts, 1, 3)) - -p1.then(zero => { ->p1.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->p1 : Symbol(p1, Decl(1.ts, 1, 3)) ->then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->zero : Symbol(zero, Decl(1.ts, 2, 8)) - - return zero.foo(); ->zero.foo : Symbol(foo, Decl(0.ts, 0, 0)) ->zero : Symbol(zero, Decl(1.ts, 2, 8)) ->foo : Symbol(foo, Decl(0.ts, 0, 0)) - -}); - -function foo() { ->foo : Symbol(foo, Decl(1.ts, 4, 3)) - - const p2 = import("./0"); ->p2 : Symbol(p2, Decl(1.ts, 7, 9)) -} diff --git a/tests/baselines/reference/importCallExpressionInUMD1.types b/tests/baselines/reference/importCallExpressionInUMD1.types deleted file mode 100644 index 59da055ee01..00000000000 --- a/tests/baselines/reference/importCallExpressionInUMD1.types +++ /dev/null @@ -1,39 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export function foo() { return "foo"; } ->foo : () => string ->"foo" : "foo" - -=== tests/cases/conformance/dynamicImport/1.ts === -import("./0"); ->import("./0") : Promise ->"./0" : "./0" - -var p1 = import("./0"); ->p1 : Promise ->import("./0") : Promise ->"./0" : "./0" - -p1.then(zero => { ->p1.then(zero => { return zero.foo();}) : Promise ->p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->p1 : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/dynamicImport/0") => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" - - return zero.foo(); ->zero.foo() : string ->zero.foo : () => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" ->foo : () => string - -}); - -function foo() { ->foo : () => void - - const p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise ->"./0" : "./0" -} diff --git a/tests/baselines/reference/importCallExpressionInUMD2.js b/tests/baselines/reference/importCallExpressionInUMD2.js deleted file mode 100644 index db8b87a2f79..00000000000 --- a/tests/baselines/reference/importCallExpressionInUMD2.js +++ /dev/null @@ -1,56 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionInUMD2.ts] //// - -//// [0.ts] -export class B { - print() { return "I am B"} -} - -//// [2.ts] -// We use Promise for now as there is no way to specify shape of module object -function foo(x: Promise) { - x.then(value => { - let b = new value.B(); - b.print(); - }) -} - -foo(import("./0")); - -//// [0.js] -(function (factory) { - if (typeof module === "object" && typeof module.exports === "object") { - var v = factory(require, exports); - if (v !== undefined) module.exports = v; - } - else if (typeof define === "function" && define.amd) { - define(["require", "exports"], factory); - } -})(function (require, exports) { - "use strict"; - Object.defineProperty(exports, "__esModule", { value: true }); - class B { - print() { return "I am B"; } - } - exports.B = B; -}); -//// [2.js] -(function (factory) { - if (typeof module === "object" && typeof module.exports === "object") { - var v = factory(require, exports); - if (v !== undefined) module.exports = v; - } - else if (typeof define === "function" && define.amd) { - define(["require", "exports"], factory); - } -})(function (require, exports) { - "use strict"; - var __syncRequire = typeof module === "object" && typeof module.exports === "object"; - // We use Promise for now as there is no way to specify shape of module object - function foo(x) { - x.then(value => { - let b = new value.B(); - b.print(); - }); - } - foo(__syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); })); -}); diff --git a/tests/baselines/reference/importCallExpressionInUMD2.symbols b/tests/baselines/reference/importCallExpressionInUMD2.symbols deleted file mode 100644 index 16fc79c774f..00000000000 --- a/tests/baselines/reference/importCallExpressionInUMD2.symbols +++ /dev/null @@ -1,34 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : Symbol(B, Decl(0.ts, 0, 0)) - - print() { return "I am B"} ->print : Symbol(B.print, Decl(0.ts, 0, 16)) -} - -=== tests/cases/conformance/dynamicImport/2.ts === -// We use Promise for now as there is no way to specify shape of module object -function foo(x: Promise) { ->foo : Symbol(foo, Decl(2.ts, 0, 0)) ->x : Symbol(x, Decl(2.ts, 1, 13)) ->Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) - - x.then(value => { ->x.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->x : Symbol(x, Decl(2.ts, 1, 13)) ->then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->value : Symbol(value, Decl(2.ts, 2, 11)) - - let b = new value.B(); ->b : Symbol(b, Decl(2.ts, 3, 11)) ->value : Symbol(value, Decl(2.ts, 2, 11)) - - b.print(); ->b : Symbol(b, Decl(2.ts, 3, 11)) - - }) -} - -foo(import("./0")); ->foo : Symbol(foo, Decl(2.ts, 0, 0)) - diff --git a/tests/baselines/reference/importCallExpressionInUMD2.types b/tests/baselines/reference/importCallExpressionInUMD2.types deleted file mode 100644 index 44b17eb51fd..00000000000 --- a/tests/baselines/reference/importCallExpressionInUMD2.types +++ /dev/null @@ -1,46 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : B - - print() { return "I am B"} ->print : () => string ->"I am B" : "I am B" -} - -=== tests/cases/conformance/dynamicImport/2.ts === -// We use Promise for now as there is no way to specify shape of module object -function foo(x: Promise) { ->foo : (x: Promise) => void ->x : Promise ->Promise : Promise - - x.then(value => { ->x.then(value => { let b = new value.B(); b.print(); }) : Promise ->x.then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->x : Promise ->then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->value => { let b = new value.B(); b.print(); } : (value: any) => void ->value : any - - let b = new value.B(); ->b : any ->new value.B() : any ->value.B : any ->value : any ->B : any - - b.print(); ->b.print() : any ->b.print : any ->b : any ->print : any - - }) -} - -foo(import("./0")); ->foo(import("./0")) : void ->foo : (x: Promise) => void ->import("./0") : Promise ->"./0" : "./0" - diff --git a/tests/baselines/reference/importCallExpressionInUMD3.js b/tests/baselines/reference/importCallExpressionInUMD3.js deleted file mode 100644 index 41106e3ab78..00000000000 --- a/tests/baselines/reference/importCallExpressionInUMD3.js +++ /dev/null @@ -1,52 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionInUMD3.ts] //// - -//// [0.ts] -export class B { - print() { return "I am B"} -} - -//// [2.ts] -async function foo() { - class C extends (await import("./0")).B {} - var c = new C(); - c.print(); -} -foo(); - -//// [0.js] -(function (factory) { - if (typeof module === "object" && typeof module.exports === "object") { - var v = factory(require, exports); - if (v !== undefined) module.exports = v; - } - else if (typeof define === "function" && define.amd) { - define(["require", "exports"], factory); - } -})(function (require, exports) { - "use strict"; - Object.defineProperty(exports, "__esModule", { value: true }); - class B { - print() { return "I am B"; } - } - exports.B = B; -}); -//// [2.js] -(function (factory) { - if (typeof module === "object" && typeof module.exports === "object") { - var v = factory(require, exports); - if (v !== undefined) module.exports = v; - } - else if (typeof define === "function" && define.amd) { - define(["require", "exports"], factory); - } -})(function (require, exports) { - "use strict"; - var __syncRequire = typeof module === "object" && typeof module.exports === "object"; - async function foo() { - class C extends (await (__syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); }))).B { - } - var c = new C(); - c.print(); - } - foo(); -}); diff --git a/tests/baselines/reference/importCallExpressionInUMD3.symbols b/tests/baselines/reference/importCallExpressionInUMD3.symbols deleted file mode 100644 index 5ca85d6e693..00000000000 --- a/tests/baselines/reference/importCallExpressionInUMD3.symbols +++ /dev/null @@ -1,29 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : Symbol(B, Decl(0.ts, 0, 0)) - - print() { return "I am B"} ->print : Symbol(B.print, Decl(0.ts, 0, 16)) -} - -=== tests/cases/conformance/dynamicImport/2.ts === -async function foo() { ->foo : Symbol(foo, Decl(2.ts, 0, 0)) - - class C extends (await import("./0")).B {} ->C : Symbol(C, Decl(2.ts, 0, 22)) ->(await import("./0")).B : Symbol(B, Decl(0.ts, 0, 0)) ->B : Symbol(B, Decl(0.ts, 0, 0)) - - var c = new C(); ->c : Symbol(c, Decl(2.ts, 2, 7)) ->C : Symbol(C, Decl(2.ts, 0, 22)) - - c.print(); ->c.print : Symbol(B.print, Decl(0.ts, 0, 16)) ->c : Symbol(c, Decl(2.ts, 2, 7)) ->print : Symbol(B.print, Decl(0.ts, 0, 16)) -} -foo(); ->foo : Symbol(foo, Decl(2.ts, 0, 0)) - diff --git a/tests/baselines/reference/importCallExpressionInUMD3.types b/tests/baselines/reference/importCallExpressionInUMD3.types deleted file mode 100644 index e517be6e722..00000000000 --- a/tests/baselines/reference/importCallExpressionInUMD3.types +++ /dev/null @@ -1,37 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : B - - print() { return "I am B"} ->print : () => string ->"I am B" : "I am B" -} - -=== tests/cases/conformance/dynamicImport/2.ts === -async function foo() { ->foo : () => Promise - - class C extends (await import("./0")).B {} ->C : C ->(await import("./0")).B : B ->(await import("./0")) : typeof "tests/cases/conformance/dynamicImport/0" ->await import("./0") : typeof "tests/cases/conformance/dynamicImport/0" ->import("./0") : Promise ->"./0" : "./0" ->B : typeof B - - var c = new C(); ->c : C ->new C() : C ->C : typeof C - - c.print(); ->c.print() : string ->c.print : () => string ->c : C ->print : () => string -} -foo(); ->foo() : Promise ->foo : () => Promise - diff --git a/tests/baselines/reference/importCallExpressionInUMD4.js b/tests/baselines/reference/importCallExpressionInUMD4.js deleted file mode 100644 index 47ba83b1718..00000000000 --- a/tests/baselines/reference/importCallExpressionInUMD4.js +++ /dev/null @@ -1,88 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionInUMD4.ts] //// - -//// [0.ts] -export class B { - print() { return "I am B"} -} - -export function foo() { return "foo" } - -//// [1.ts] -export function backup() { return "backup"; } - -//// [2.ts] -declare var console: any; -class C { - private myModule = import("./0"); - method() { - this.myModule.then(Zero => { - console.log(Zero.foo()); - }, async err => { - console.log(err); - let one = await import("./1"); - console.log(one.backup()); - }); - } -} - -//// [0.js] -(function (factory) { - if (typeof module === "object" && typeof module.exports === "object") { - var v = factory(require, exports); - if (v !== undefined) module.exports = v; - } - else if (typeof define === "function" && define.amd) { - define(["require", "exports"], factory); - } -})(function (require, exports) { - "use strict"; - Object.defineProperty(exports, "__esModule", { value: true }); - class B { - print() { return "I am B"; } - } - exports.B = B; - function foo() { return "foo"; } - exports.foo = foo; -}); -//// [1.js] -(function (factory) { - if (typeof module === "object" && typeof module.exports === "object") { - var v = factory(require, exports); - if (v !== undefined) module.exports = v; - } - else if (typeof define === "function" && define.amd) { - define(["require", "exports"], factory); - } -})(function (require, exports) { - "use strict"; - Object.defineProperty(exports, "__esModule", { value: true }); - function backup() { return "backup"; } - exports.backup = backup; -}); -//// [2.js] -(function (factory) { - if (typeof module === "object" && typeof module.exports === "object") { - var v = factory(require, exports); - if (v !== undefined) module.exports = v; - } - else if (typeof define === "function" && define.amd) { - define(["require", "exports"], factory); - } -})(function (require, exports) { - "use strict"; - var __syncRequire = typeof module === "object" && typeof module.exports === "object"; - class C { - constructor() { - this.myModule = __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); }); - } - method() { - this.myModule.then(Zero => { - console.log(Zero.foo()); - }, async (err) => { - console.log(err); - let one = await (__syncRequire ? Promise.resolve().then(function () { return require("./1"); }) : new Promise(function (resolve_2, reject_2) { require(["./1"], resolve_2, reject_2); })); - console.log(one.backup()); - }); - } - } -}); diff --git a/tests/baselines/reference/importCallExpressionInUMD4.symbols b/tests/baselines/reference/importCallExpressionInUMD4.symbols deleted file mode 100644 index 34a1dcf4d7b..00000000000 --- a/tests/baselines/reference/importCallExpressionInUMD4.symbols +++ /dev/null @@ -1,61 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : Symbol(B, Decl(0.ts, 0, 0)) - - print() { return "I am B"} ->print : Symbol(B.print, Decl(0.ts, 0, 16)) -} - -export function foo() { return "foo" } ->foo : Symbol(foo, Decl(0.ts, 2, 1)) - -=== tests/cases/conformance/dynamicImport/1.ts === -export function backup() { return "backup"; } ->backup : Symbol(backup, Decl(1.ts, 0, 0)) - -=== tests/cases/conformance/dynamicImport/2.ts === -declare var console: any; ->console : Symbol(console, Decl(2.ts, 0, 11)) - -class C { ->C : Symbol(C, Decl(2.ts, 0, 25)) - - private myModule = import("./0"); ->myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) - - method() { ->method : Symbol(C.method, Decl(2.ts, 2, 37)) - - this.myModule.then(Zero => { ->this.myModule.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->this.myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) ->this : Symbol(C, Decl(2.ts, 0, 25)) ->myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) ->then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->Zero : Symbol(Zero, Decl(2.ts, 4, 27)) - - console.log(Zero.foo()); ->console : Symbol(console, Decl(2.ts, 0, 11)) ->Zero.foo : Symbol(foo, Decl(0.ts, 2, 1)) ->Zero : Symbol(Zero, Decl(2.ts, 4, 27)) ->foo : Symbol(foo, Decl(0.ts, 2, 1)) - - }, async err => { ->err : Symbol(err, Decl(2.ts, 6, 16)) - - console.log(err); ->console : Symbol(console, Decl(2.ts, 0, 11)) ->err : Symbol(err, Decl(2.ts, 6, 16)) - - let one = await import("./1"); ->one : Symbol(one, Decl(2.ts, 8, 15)) - - console.log(one.backup()); ->console : Symbol(console, Decl(2.ts, 0, 11)) ->one.backup : Symbol(backup, Decl(1.ts, 0, 0)) ->one : Symbol(one, Decl(2.ts, 8, 15)) ->backup : Symbol(backup, Decl(1.ts, 0, 0)) - - }); - } -} diff --git a/tests/baselines/reference/importCallExpressionInUMD4.types b/tests/baselines/reference/importCallExpressionInUMD4.types deleted file mode 100644 index 2ea666ba672..00000000000 --- a/tests/baselines/reference/importCallExpressionInUMD4.types +++ /dev/null @@ -1,83 +0,0 @@ -=== tests/cases/conformance/dynamicImport/0.ts === -export class B { ->B : B - - print() { return "I am B"} ->print : () => string ->"I am B" : "I am B" -} - -export function foo() { return "foo" } ->foo : () => string ->"foo" : "foo" - -=== tests/cases/conformance/dynamicImport/1.ts === -export function backup() { return "backup"; } ->backup : () => string ->"backup" : "backup" - -=== tests/cases/conformance/dynamicImport/2.ts === -declare var console: any; ->console : any - -class C { ->C : C - - private myModule = import("./0"); ->myModule : Promise ->import("./0") : Promise ->"./0" : "./0" - - method() { ->method : () => void - - this.myModule.then(Zero => { ->this.myModule.then(Zero => { console.log(Zero.foo()); }, async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); }) : Promise ->this.myModule.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->this.myModule : Promise ->this : this ->myModule : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/dynamicImport/0") => void ->Zero : typeof "tests/cases/conformance/dynamicImport/0" - - console.log(Zero.foo()); ->console.log(Zero.foo()) : any ->console.log : any ->console : any ->log : any ->Zero.foo() : string ->Zero.foo : () => string ->Zero : typeof "tests/cases/conformance/dynamicImport/0" ->foo : () => string - - }, async err => { ->async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); } : (err: any) => Promise ->err : any - - console.log(err); ->console.log(err) : any ->console.log : any ->console : any ->log : any ->err : any - - let one = await import("./1"); ->one : typeof "tests/cases/conformance/dynamicImport/1" ->await import("./1") : typeof "tests/cases/conformance/dynamicImport/1" ->import("./1") : Promise ->"./1" : "./1" - - console.log(one.backup()); ->console.log(one.backup()) : any ->console.log : any ->console : any ->log : any ->one.backup() : string ->one.backup : () => string ->one : typeof "tests/cases/conformance/dynamicImport/1" ->backup : () => string - - }); - } -} diff --git a/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js deleted file mode 100644 index 728d6636953..00000000000 --- a/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js +++ /dev/null @@ -1,61 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionReturnPromiseOfAny.ts] //// - -//// [defaultPath.ts] -export class C {} - -//// [1.ts] -import * as defaultModule from "./defaultPath"; -declare function getSpecifier(): string; -declare function ValidSomeCondition(): boolean; -declare var whatToLoad: boolean; -declare const directory: string; -declare const moduleFile: number; - -import(`${directory}\${moduleFile}`); -import(getSpecifier()); - -var p1 = import(ValidSomeCondition() ? "./0" : "externalModule"); -var p1: Promise = import(getSpecifier()); -var p11: Promise = import(getSpecifier()); -const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") as Promise; -p1.then(zero => { - return zero.foo(); // ok, zero is any -}); - -let j: string; -var p3: Promise = import(j=getSpecifier()); - -function * loadModule(directories: string[]) { - for (const directory of directories) { - const path = `${directory}\moduleFile`; - import(yield path); - } -} - - -//// [defaultPath.js] -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -class C { -} -exports.C = C; -//// [1.js] -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -Promise.resolve().then(function () { return require(`${directory}\${moduleFile}`); }); -Promise.resolve().then(function () { return require(getSpecifier()); }); -var p1 = Promise.resolve().then(function () { return require(ValidSomeCondition() ? "./0" : "externalModule"); }); -var p1 = Promise.resolve().then(function () { return require(getSpecifier()); }); -var p11 = Promise.resolve().then(function () { return require(getSpecifier()); }); -const p2 = Promise.resolve().then(function () { return require(whatToLoad ? getSpecifier() : "defaulPath"); }); -p1.then(zero => { - return zero.foo(); // ok, zero is any -}); -let j; -var p3 = Promise.resolve().then(function () { return require(j = getSpecifier()); }); -function* loadModule(directories) { - for (const directory of directories) { - const path = `${directory}\moduleFile`; - Promise.resolve().then(function () { return require(yield path); }); - } -} diff --git a/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.symbols b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.symbols deleted file mode 100644 index 0d46961475f..00000000000 --- a/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.symbols +++ /dev/null @@ -1,89 +0,0 @@ -=== tests/cases/conformance/dynamicImport/defaultPath.ts === -export class C {} ->C : Symbol(C, Decl(defaultPath.ts, 0, 0)) - -=== tests/cases/conformance/dynamicImport/1.ts === -import * as defaultModule from "./defaultPath"; ->defaultModule : Symbol(defaultModule, Decl(1.ts, 0, 6)) - -declare function getSpecifier(): string; ->getSpecifier : Symbol(getSpecifier, Decl(1.ts, 0, 47)) - -declare function ValidSomeCondition(): boolean; ->ValidSomeCondition : Symbol(ValidSomeCondition, Decl(1.ts, 1, 40)) - -declare var whatToLoad: boolean; ->whatToLoad : Symbol(whatToLoad, Decl(1.ts, 3, 11)) - -declare const directory: string; ->directory : Symbol(directory, Decl(1.ts, 4, 13)) - -declare const moduleFile: number; ->moduleFile : Symbol(moduleFile, Decl(1.ts, 5, 13)) - -import(`${directory}\${moduleFile}`); ->directory : Symbol(directory, Decl(1.ts, 4, 13)) - -import(getSpecifier()); ->getSpecifier : Symbol(getSpecifier, Decl(1.ts, 0, 47)) - -var p1 = import(ValidSomeCondition() ? "./0" : "externalModule"); ->p1 : Symbol(p1, Decl(1.ts, 10, 3), Decl(1.ts, 11, 3)) ->ValidSomeCondition : Symbol(ValidSomeCondition, Decl(1.ts, 1, 40)) - -var p1: Promise = import(getSpecifier()); ->p1 : Symbol(p1, Decl(1.ts, 10, 3), Decl(1.ts, 11, 3)) ->Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) ->getSpecifier : Symbol(getSpecifier, Decl(1.ts, 0, 47)) - -var p11: Promise = import(getSpecifier()); ->p11 : Symbol(p11, Decl(1.ts, 12, 3)) ->Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) ->defaultModule : Symbol(defaultModule, Decl(1.ts, 0, 6)) ->getSpecifier : Symbol(getSpecifier, Decl(1.ts, 0, 47)) - -const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") as Promise; ->p2 : Symbol(p2, Decl(1.ts, 13, 5)) ->whatToLoad : Symbol(whatToLoad, Decl(1.ts, 3, 11)) ->getSpecifier : Symbol(getSpecifier, Decl(1.ts, 0, 47)) ->Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) ->defaultModule : Symbol(defaultModule, Decl(1.ts, 0, 6)) - -p1.then(zero => { ->p1.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->p1 : Symbol(p1, Decl(1.ts, 10, 3), Decl(1.ts, 11, 3)) ->then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->zero : Symbol(zero, Decl(1.ts, 14, 8)) - - return zero.foo(); // ok, zero is any ->zero : Symbol(zero, Decl(1.ts, 14, 8)) - -}); - -let j: string; ->j : Symbol(j, Decl(1.ts, 18, 3)) - -var p3: Promise = import(j=getSpecifier()); ->p3 : Symbol(p3, Decl(1.ts, 19, 3)) ->Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) ->defaultModule : Symbol(defaultModule, Decl(1.ts, 0, 6)) ->j : Symbol(j, Decl(1.ts, 18, 3)) ->getSpecifier : Symbol(getSpecifier, Decl(1.ts, 0, 47)) - -function * loadModule(directories: string[]) { ->loadModule : Symbol(loadModule, Decl(1.ts, 19, 65)) ->directories : Symbol(directories, Decl(1.ts, 21, 22)) - - for (const directory of directories) { ->directory : Symbol(directory, Decl(1.ts, 22, 14)) ->directories : Symbol(directories, Decl(1.ts, 21, 22)) - - const path = `${directory}\moduleFile`; ->path : Symbol(path, Decl(1.ts, 23, 13)) ->directory : Symbol(directory, Decl(1.ts, 22, 14)) - - import(yield path); ->path : Symbol(path, Decl(1.ts, 23, 13)) - } -} - diff --git a/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.types b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.types deleted file mode 100644 index fc52b38c1fb..00000000000 --- a/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.types +++ /dev/null @@ -1,118 +0,0 @@ -=== tests/cases/conformance/dynamicImport/defaultPath.ts === -export class C {} ->C : C - -=== tests/cases/conformance/dynamicImport/1.ts === -import * as defaultModule from "./defaultPath"; ->defaultModule : typeof defaultModule - -declare function getSpecifier(): string; ->getSpecifier : () => string - -declare function ValidSomeCondition(): boolean; ->ValidSomeCondition : () => boolean - -declare var whatToLoad: boolean; ->whatToLoad : boolean - -declare const directory: string; ->directory : string - -declare const moduleFile: number; ->moduleFile : number - -import(`${directory}\${moduleFile}`); ->import(`${directory}\${moduleFile}`) : Promise ->`${directory}\${moduleFile}` : string ->directory : string - -import(getSpecifier()); ->import(getSpecifier()) : Promise ->getSpecifier() : string ->getSpecifier : () => string - -var p1 = import(ValidSomeCondition() ? "./0" : "externalModule"); ->p1 : Promise ->import(ValidSomeCondition() ? "./0" : "externalModule") : Promise ->ValidSomeCondition() ? "./0" : "externalModule" : "./0" | "externalModule" ->ValidSomeCondition() : boolean ->ValidSomeCondition : () => boolean ->"./0" : "./0" ->"externalModule" : "externalModule" - -var p1: Promise = import(getSpecifier()); ->p1 : Promise ->Promise : Promise ->import(getSpecifier()) : Promise ->getSpecifier() : string ->getSpecifier : () => string - -var p11: Promise = import(getSpecifier()); ->p11 : Promise ->Promise : Promise ->defaultModule : typeof defaultModule ->import(getSpecifier()) : Promise ->getSpecifier() : string ->getSpecifier : () => string - -const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") as Promise; ->p2 : Promise ->import(whatToLoad ? getSpecifier() : "defaulPath") as Promise : Promise ->import(whatToLoad ? getSpecifier() : "defaulPath") : Promise ->whatToLoad ? getSpecifier() : "defaulPath" : string ->whatToLoad : boolean ->getSpecifier() : string ->getSpecifier : () => string ->"defaulPath" : "defaulPath" ->Promise : Promise ->defaultModule : typeof defaultModule - -p1.then(zero => { ->p1.then(zero => { return zero.foo(); // ok, zero is any}) : Promise ->p1.then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->p1 : Promise ->then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->zero => { return zero.foo(); // ok, zero is any} : (zero: any) => any ->zero : any - - return zero.foo(); // ok, zero is any ->zero.foo() : any ->zero.foo : any ->zero : any ->foo : any - -}); - -let j: string; ->j : string - -var p3: Promise = import(j=getSpecifier()); ->p3 : Promise ->Promise : Promise ->defaultModule : typeof defaultModule ->import(j=getSpecifier()) : Promise ->j=getSpecifier() : string ->j : string ->getSpecifier() : string ->getSpecifier : () => string - -function * loadModule(directories: string[]) { ->loadModule : (directories: string[]) => IterableIterator ->directories : string[] - - for (const directory of directories) { ->directory : string ->directories : string[] - - const path = `${directory}\moduleFile`; ->path : string ->`${directory}\moduleFile` : string ->directory : string - - import(yield path); ->import(yield path) : Promise ->yield path : any ->path : string - } -} - diff --git a/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.errors.txt b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.errors.txt deleted file mode 100644 index a1159a31ebd..00000000000 --- a/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.errors.txt +++ /dev/null @@ -1,31 +0,0 @@ -tests/cases/conformance/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(5,8): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. -tests/cases/conformance/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(6,17): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. -tests/cases/conformance/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(7,19): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'boolean | "defaulPath"'. -tests/cases/conformance/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(12,17): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'string[]'. -tests/cases/conformance/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(13,17): error TS7036: Dynamic import's specifier must be of type 'string', but here has type '() => string'. - - -==== tests/cases/conformance/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts (5 errors) ==== - declare function getSpecifier(): boolean; - declare var whatToLoad: boolean; - - // Error specifier is not assignable to string - import(getSpecifier()); - ~~~~~~~~~~~~~~ -!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. - var p1 = import(getSpecifier()); - ~~~~~~~~~~~~~~ -!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. - const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'boolean | "defaulPath"'. - p1.then(zero => { - return zero.foo(); // ok, zero is any - }); - - var p3 = import(["path1", "path2"]); - ~~~~~~~~~~~~~~~~~~ -!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'string[]'. - var p4 = import(()=>"PathToModule"); - ~~~~~~~~~~~~~~~~~~ -!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type '() => string'. \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js deleted file mode 100644 index dde35d8048b..00000000000 --- a/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js +++ /dev/null @@ -1,25 +0,0 @@ -//// [importCallExpressionSpecifierNotStringTypeError.ts] -declare function getSpecifier(): boolean; -declare var whatToLoad: boolean; - -// Error specifier is not assignable to string -import(getSpecifier()); -var p1 = import(getSpecifier()); -const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") -p1.then(zero => { - return zero.foo(); // ok, zero is any -}); - -var p3 = import(["path1", "path2"]); -var p4 = import(()=>"PathToModule"); - -//// [importCallExpressionSpecifierNotStringTypeError.js] -// Error specifier is not assignable to string -Promise.resolve().then(function () { return require(getSpecifier()); }); -var p1 = Promise.resolve().then(function () { return require(getSpecifier()); }); -const p2 = Promise.resolve().then(function () { return require(whatToLoad ? getSpecifier() : "defaulPath"); }); -p1.then(zero => { - return zero.foo(); // ok, zero is any -}); -var p3 = Promise.resolve().then(function () { return require(["path1", "path2"]); }); -var p4 = Promise.resolve().then(function () { return require(() => "PathToModule"); }); diff --git a/tests/baselines/reference/importCallExpressionWithTypeArgument.errors.txt b/tests/baselines/reference/importCallExpressionWithTypeArgument.errors.txt deleted file mode 100644 index 8adf2789585..00000000000 --- a/tests/baselines/reference/importCallExpressionWithTypeArgument.errors.txt +++ /dev/null @@ -1,18 +0,0 @@ -tests/cases/conformance/dynamicImport/1.ts(2,10): error TS1326: Dynamic import cannot have type arguments -tests/cases/conformance/dynamicImport/1.ts(3,10): error TS1326: Dynamic import cannot have type arguments - - -==== tests/cases/conformance/dynamicImport/0.ts (0 errors) ==== - export function foo() { return "foo"; } - -==== tests/cases/conformance/dynamicImport/1.ts (2 errors) ==== - "use strict" - var p1 = import>("./0"); // error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1326: Dynamic import cannot have type arguments - var p2 = import<>("./0"); // error - ~~~~~~~~~~~~~~~ -!!! error TS1326: Dynamic import cannot have type arguments - // p1.then(value => { - // value.anyFunction(); - // }) \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionWithTypeArgument.js b/tests/baselines/reference/importCallExpressionWithTypeArgument.js deleted file mode 100644 index d8690cf5d75..00000000000 --- a/tests/baselines/reference/importCallExpressionWithTypeArgument.js +++ /dev/null @@ -1,22 +0,0 @@ -//// [tests/cases/conformance/dynamicImport/importCallExpressionWithTypeArgument.ts] //// - -//// [0.ts] -export function foo() { return "foo"; } - -//// [1.ts] -"use strict" -var p1 = import>("./0"); // error -var p2 = import<>("./0"); // error -// p1.then(value => { -// value.anyFunction(); -// }) - -//// [0.js] -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function foo() { return "foo"; } -exports.foo = foo; -//// [1.js] -"use strict"; -var p1 = (import)("./0"); // error -var p2 = (import)("./0"); // error diff --git a/tests/baselines/reference/transpile/Report an error when compiler-options module-kind is out-of-range.errors.txt b/tests/baselines/reference/transpile/Report an error when compiler-options module-kind is out-of-range.errors.txt index f746915da7d..d746f35cbe7 100644 --- a/tests/baselines/reference/transpile/Report an error when compiler-options module-kind is out-of-range.errors.txt +++ b/tests/baselines/reference/transpile/Report an error when compiler-options module-kind is out-of-range.errors.txt @@ -1,6 +1,6 @@ -error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'esnext'. +error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015'. -!!! error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'esnext'. +!!! error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015'. ==== file.ts (0 errors) ==== \ No newline at end of file diff --git a/tests/baselines/reference/transpile/Report an error when compiler-options target-script is out-of-range.errors.txt b/tests/baselines/reference/transpile/Report an error when compiler-options target-script is out-of-range.errors.txt index f746915da7d..d746f35cbe7 100644 --- a/tests/baselines/reference/transpile/Report an error when compiler-options target-script is out-of-range.errors.txt +++ b/tests/baselines/reference/transpile/Report an error when compiler-options target-script is out-of-range.errors.txt @@ -1,6 +1,6 @@ -error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'esnext'. +error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015'. -!!! error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'esnext'. +!!! error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015'. ==== file.ts (0 errors) ==== \ No newline at end of file diff --git a/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json b/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json index 772c218eb4e..04599005244 100644 --- a/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */ // "lib": [], /* Specify library files to be included in the compilation: */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json index 7a9b895636c..2a41e2c4df0 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */ // "lib": [], /* Specify library files to be included in the compilation: */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json index 70d5ed9d738..e29a2813282 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */ // "lib": [], /* Specify library files to be included in the compilation: */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json index 914b9d99d1b..69831916904 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */ // "lib": [], /* Specify library files to be included in the compilation: */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json index 50bd28442bb..407df036f89 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */ "lib": ["es5","es2015.promise"], /* Specify library files to be included in the compilation: */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json index 772c218eb4e..04599005244 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */ // "lib": [], /* Specify library files to be included in the compilation: */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json index afae7193d58..e4d0b37ae51 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */ "lib": ["es5","es2015.core"], /* Specify library files to be included in the compilation: */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json index a87fe9c5206..3e3f7a85b34 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */ // "lib": [], /* Specify library files to be included in the compilation: */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ diff --git a/tests/cases/conformance/dynamicImport/importCallExpression1ESNext.ts b/tests/cases/conformance/dynamicImport/importCallExpression1ESNext.ts deleted file mode 100644 index 295b6470301..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpression1ESNext.ts +++ /dev/null @@ -1,15 +0,0 @@ -// @module: esnext -// @target: esnext -// @filename: 0.ts -export function foo() { return "foo"; } - -// @filename: 1.ts -import("./0"); -var p1 = import("./0"); -p1.then(zero => { - return zero.foo(); -}) - -function foo() { - const p2 = import("./0"); -} \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpression2ESNext.ts b/tests/cases/conformance/dynamicImport/importCallExpression2ESNext.ts deleted file mode 100644 index f0e9b358854..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpression2ESNext.ts +++ /dev/null @@ -1,16 +0,0 @@ -// @module: esnext -// @target: esnext -// @filename: 0.ts -export class B { - print() { return "I am B"} -} - -// @filename: 2.ts -function foo(x: Promise) { - x.then(value => { - let b = new value.B(); - b.print(); - }) -} - -foo(import("./0")); \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpression3ESNext.ts b/tests/cases/conformance/dynamicImport/importCallExpression3ESNext.ts deleted file mode 100644 index ee7264b8c7e..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpression3ESNext.ts +++ /dev/null @@ -1,14 +0,0 @@ -// @module: esnext -// @target: esnext -// @filename: 0.ts -export class B { - print() { return "I am B"} -} - -// @filename: 2.ts -async function foo() { - class C extends (await import("./0")).B {} - var c = new C(); - c.print(); -} -foo(); \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpression4ESNext.ts b/tests/cases/conformance/dynamicImport/importCallExpression4ESNext.ts deleted file mode 100644 index 91342770d7d..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpression4ESNext.ts +++ /dev/null @@ -1,26 +0,0 @@ -// @module: esnext -// @target: esnext -// @filename: 0.ts -export class B { - print() { return "I am B"} -} - -export function foo() { return "foo" } - -// @filename: 1.ts -export function backup() { return "backup"; } - -// @filename: 2.ts -declare var console: any; -class C { - private myModule = import("./0"); - method() { - this.myModule.then(Zero => { - console.log(Zero.foo()); - }, async err => { - console.log(err); - let one = await import("./1"); - console.log(one.backup()); - }); - } -} \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpression5ESNext.ts b/tests/cases/conformance/dynamicImport/importCallExpression5ESNext.ts deleted file mode 100644 index 173b606a50c..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpression5ESNext.ts +++ /dev/null @@ -1,20 +0,0 @@ -// @module: esnext -// @target: esnext -// @strictNullChecks: true -// @filename: 0.ts -export class B { - print() { return "I am B"} -} - -export function foo() { return "foo" } - -// @filename: 1.ts -export function backup() { return "backup"; } - -// @filename: 2.ts -declare function bar(): boolean; -const specify = bar() ? "./0" : undefined; -let myModule = import(specify); -let myModule1 = import(undefined); -let myModule2 = import(bar() ? "./1" : null); -let myModule3 = import(null); \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpression6ESNext.ts b/tests/cases/conformance/dynamicImport/importCallExpression6ESNext.ts deleted file mode 100644 index f09521186e8..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpression6ESNext.ts +++ /dev/null @@ -1,19 +0,0 @@ -// @module: esnext -// @target: esnext -// @filename: 0.ts -export class B { - print() { return "I am B"} -} - -export function foo() { return "foo" } - -// @filename: 1.ts -export function backup() { return "backup"; } - -// @filename: 2.ts -declare function bar(): boolean; -const specify = bar() ? "./0" : undefined; -let myModule = import(specify); -let myModule1 = import(undefined); -let myModule2 = import(bar() ? "./1" : null); -let myModule3 = import(null); \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionCheckReturntype1.ts b/tests/cases/conformance/dynamicImport/importCallExpressionCheckReturntype1.ts deleted file mode 100644 index 1218565fa54..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionCheckReturntype1.ts +++ /dev/null @@ -1,17 +0,0 @@ -// @module: commonjs -// @target: es6 -// @noImplicitAny: true - -// @filename: anotherModule.ts -export class D{} - -// @filename: defaultPath.ts -export class C {} - -// @filename: 1.ts -import * as defaultModule from "./defaultPath"; -import * as anotherModule from "./anotherModule"; - -let p1: Promise = import("./defaultPath"); -let p2 = import("./defaultPath") as Promise; -let p3: Promise = import("./defaultPath"); diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit1.ts b/tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit1.ts deleted file mode 100644 index fb299951148..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit1.ts +++ /dev/null @@ -1,19 +0,0 @@ -// @module: commonjs -// @target: es6 -// @noImplicitAny: false -// @declaration: true - -declare function getSpecifier(): string; -declare var whatToLoad: boolean; -declare const directory: string; -declare const moduleFile: number; - -import(getSpecifier()); - -var p0 = import(`${directory}\${moduleFile}`); -var p1 = import(getSpecifier()); -const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") - -function returnDynamicLoad(path: string) { - return import(path); -} \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit2.ts b/tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit2.ts deleted file mode 100644 index 4b9196dea20..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit2.ts +++ /dev/null @@ -1,9 +0,0 @@ -// @module: esnext -// @target: esnext -// @declaration: true - -// @filename: 0.ts -export function foo() { return "foo"; } - -// @filename: 1.ts -var p1 = import("./0"); \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit3.ts b/tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit3.ts deleted file mode 100644 index 6d17d624190..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit3.ts +++ /dev/null @@ -1,15 +0,0 @@ -// @module: esnext -// @target: esnext -// @declaration: true - -// @filename: 0.ts -export function foo() { return "foo"; } - -// @filename: 1.ts -declare function getPath(): string; -import * as Zero from "./0"; -import("./0"); - -export var p0: Promise = import(getPath()); -export var p1: Promise = import("./0"); -export var p2: Promise = import("./0"); diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionES5AMD.ts b/tests/cases/conformance/dynamicImport/importCallExpressionES5AMD.ts deleted file mode 100644 index 33c31283ea0..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionES5AMD.ts +++ /dev/null @@ -1,16 +0,0 @@ -// @module: amd -// @target: es5 -// @lib: es6 -// @filename: 0.ts -export function foo() { return "foo"; } - -// @filename: 1.ts -import("./0"); -var p1 = import("./0"); -p1.then(zero => { - return zero.foo(); -}); - -function foo() { - const p2 = import("./0"); -} \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionES5CJS.ts b/tests/cases/conformance/dynamicImport/importCallExpressionES5CJS.ts deleted file mode 100644 index 900ddbdba0c..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionES5CJS.ts +++ /dev/null @@ -1,16 +0,0 @@ -// @module: commonjs -// @target: es5 -// @lib: es6 -// @filename: 0.ts -export function foo() { return "foo"; } - -// @filename: 1.ts -import("./0"); -var p1 = import("./0"); -p1.then(zero => { - return zero.foo(); -}); - -function foo() { - const p2 = import("./0"); -} \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionES5System.ts b/tests/cases/conformance/dynamicImport/importCallExpressionES5System.ts deleted file mode 100644 index c00ab6899c6..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionES5System.ts +++ /dev/null @@ -1,16 +0,0 @@ -// @module: system -// @target: es5 -// @lib: es6 -// @filename: 0.ts -export function foo() { return "foo"; } - -// @filename: 1.ts -import("./0"); -var p1 = import("./0"); -p1.then(zero => { - return zero.foo(); -}); - -function foo() { - const p2 = import("./0"); -} \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionES5UMD.ts b/tests/cases/conformance/dynamicImport/importCallExpressionES5UMD.ts deleted file mode 100644 index 699b0ffc342..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionES5UMD.ts +++ /dev/null @@ -1,16 +0,0 @@ -// @module: umd -// @target: es5 -// @lib: es6 -// @filename: 0.ts -export function foo() { return "foo"; } - -// @filename: 1.ts -import("./0"); -var p1 = import("./0"); -p1.then(zero => { - return zero.foo(); -}); - -function foo() { - const p2 = import("./0"); -} \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionErrorInES2015.ts b/tests/cases/conformance/dynamicImport/importCallExpressionErrorInES2015.ts deleted file mode 100644 index a7fcd8533a3..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionErrorInES2015.ts +++ /dev/null @@ -1,15 +0,0 @@ -// @module: es2015 -// @target: esnext -// @filename: 0.ts -export function foo() { return "foo"; } - -// @filename: 1.ts -import("./0"); -var p1 = import("./0"); -p1.then(zero => { - return zero.foo(); -}) - -function foo() { - const p2 = import("./0"); -} \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts b/tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts deleted file mode 100644 index 38dc47f3207..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts +++ /dev/null @@ -1,14 +0,0 @@ -// @module: commonjs -// @target: es6 -// @noImplicitAny: false - -declare function getSpecifier(): string; -declare var whatToLoad: boolean; - -var a = ["./0"]; -import(...["PathModule"]); - -var p1 = import(...a); -const p2 = import(); -const p3 = import(,); -const p4 = import("pathToModule", "secondModule"); \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionInAMD1.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInAMD1.ts deleted file mode 100644 index 63cfc54c732..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionInAMD1.ts +++ /dev/null @@ -1,15 +0,0 @@ -// @module: amd -// @target: esnext -// @filename: 0.ts -export function foo() { return "foo"; } - -// @filename: 1.ts -import("./0"); -var p1 = import("./0"); -p1.then(zero => { - return zero.foo(); -}); - -function foo() { - const p2 = import("./0"); -} \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionInAMD2.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInAMD2.ts deleted file mode 100644 index 96b2fd4ceff..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionInAMD2.ts +++ /dev/null @@ -1,17 +0,0 @@ -// @module: amd -// @target: esnext -// @filename: 0.ts -export class B { - print() { return "I am B"} -} - -// @filename: 2.ts -// We use Promise for now as there is no way to specify shape of module object -function foo(x: Promise) { - x.then(value => { - let b = new value.B(); - b.print(); - }) -} - -foo(import("./0")); \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionInAMD3.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInAMD3.ts deleted file mode 100644 index a2b287b4d95..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionInAMD3.ts +++ /dev/null @@ -1,14 +0,0 @@ -// @module: amd -// @target: esnext -// @filename: 0.ts -export class B { - print() { return "I am B"} -} - -// @filename: 2.ts -async function foo() { - class C extends (await import("./0")).B {} - var c = new C(); - c.print(); -} -foo(); \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionInAMD4.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInAMD4.ts deleted file mode 100644 index 10044ab674c..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionInAMD4.ts +++ /dev/null @@ -1,26 +0,0 @@ -// @module: amd -// @target: esnext -// @filename: 0.ts -export class B { - print() { return "I am B"} -} - -export function foo() { return "foo" } - -// @filename: 1.ts -export function backup() { return "backup"; } - -// @filename: 2.ts -declare var console: any; -class C { - private myModule = import("./0"); - method() { - this.myModule.then(Zero => { - console.log(Zero.foo()); - }, async err => { - console.log(err); - let one = await import("./1"); - console.log(one.backup()); - }); - } -} \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionInCJS1.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInCJS1.ts deleted file mode 100644 index e1457017552..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionInCJS1.ts +++ /dev/null @@ -1,15 +0,0 @@ -// @module: commonjs -// @target: esnext -// @filename: 0.ts -export function foo() { return "foo"; } - -// @filename: 1.ts -import("./0"); -var p1 = import("./0"); -p1.then(zero => { - return zero.foo(); -}); - -function foo() { - const p2 = import("./0"); -} \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionInCJS2.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInCJS2.ts deleted file mode 100644 index e42a58a290c..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionInCJS2.ts +++ /dev/null @@ -1,19 +0,0 @@ -// @module: commonjs -// @target: esnext -// @filename: 0.ts -export function foo() { return "foo"; } - -// @filename: 1.ts -export function backup() { return "backup"; } - -// @filename: 2.ts -async function compute(promise: Promise) { - let j = await promise; - if (!j) { - j = await import("./1"); - return j.backup(); - } - return j.foo(); -} - -compute(import("./0")); \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionInCJS3.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInCJS3.ts deleted file mode 100644 index 5990eb3a5a2..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionInCJS3.ts +++ /dev/null @@ -1,17 +0,0 @@ -// @module: commonjs -// @target: esnext -// @filename: 0.ts -export class B { - print() { return "I am B"} -} - -// @filename: 2.ts -// We use Promise for now as there is no way to specify shape of module object -function foo(x: Promise) { - x.then(value => { - let b = new value.B(); - b.print(); - }) -} - -foo(import("./0")); \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionInCJS4.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInCJS4.ts deleted file mode 100644 index fba246c0b8b..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionInCJS4.ts +++ /dev/null @@ -1,14 +0,0 @@ -// @module: commonjs -// @target: esnext -// @filename: 0.ts -export class B { - print() { return "I am B"} -} - -// @filename: 2.ts -async function foo() { - class C extends (await import("./0")).B {} - var c = new C(); - c.print(); -} -foo(); \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionInCJS5.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInCJS5.ts deleted file mode 100644 index db86764802b..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionInCJS5.ts +++ /dev/null @@ -1,26 +0,0 @@ -// @module: commonjs -// @target: esnext -// @filename: 0.ts -export class B { - print() { return "I am B"} -} - -export function foo() { return "foo" } - -// @filename: 1.ts -export function backup() { return "backup"; } - -// @filename: 2.ts -declare var console: any; -class C { - private myModule = import("./0"); - method() { - this.myModule.then(Zero => { - console.log(Zero.foo()); - }, async err => { - console.log(err); - let one = await import("./1"); - console.log(one.backup()); - }); - } -} \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionInScriptContext1.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInScriptContext1.ts deleted file mode 100644 index 166513321a3..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionInScriptContext1.ts +++ /dev/null @@ -1,10 +0,0 @@ -// @module: commonjs -// @target: es6 -// @noImplicitAny: false - -// @filename: 0.ts -export function foo() { return "foo"; } - -// @filename: 1.ts -var p1 = import("./0"); -function arguments() { } // this is allow as the file doesn't have implicit "use strict" \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionInScriptContext2.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInScriptContext2.ts deleted file mode 100644 index 754f7e865bb..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionInScriptContext2.ts +++ /dev/null @@ -1,11 +0,0 @@ -// @module: commonjs -// @target: es6 -// @noImplicitAny: false - -// @filename: 0.ts -export function foo() { return "foo"; } - -// @filename: 1.ts -"use strict" -var p1 = import("./0"); -function arguments() { } \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionInSystem1.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInSystem1.ts deleted file mode 100644 index a69e844c7a7..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionInSystem1.ts +++ /dev/null @@ -1,15 +0,0 @@ -// @module: system -// @target: esnext -// @filename: 0.ts -export function foo() { return "foo"; } - -// @filename: 1.ts -import("./0"); -var p1 = import("./0"); -p1.then(zero => { - return zero.foo(); -}); - -function foo() { - const p2 = import("./0"); -} \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionInSystem2.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInSystem2.ts deleted file mode 100644 index c6fac3683ee..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionInSystem2.ts +++ /dev/null @@ -1,17 +0,0 @@ -// @module: system -// @target: esnext -// @filename: 0.ts -export class B { - print() { return "I am B"} -} - -// @filename: 2.ts -// We use Promise for now as there is no way to specify shape of module object -function foo(x: Promise) { - x.then(value => { - let b = new value.B(); - b.print(); - }) -} - -foo(import("./0")); \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionInSystem3.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInSystem3.ts deleted file mode 100644 index 7f4485d8962..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionInSystem3.ts +++ /dev/null @@ -1,14 +0,0 @@ -// @module: system -// @target: esnext -// @filename: 0.ts -export class B { - print() { return "I am B"} -} - -// @filename: 2.ts -async function foo() { - class C extends (await import("./0")).B {} - var c = new C(); - c.print(); -} -foo(); \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionInSystem4.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInSystem4.ts deleted file mode 100644 index 1ab3040862c..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionInSystem4.ts +++ /dev/null @@ -1,26 +0,0 @@ -// @module: system -// @target: esnext -// @filename: 0.ts -export class B { - print() { return "I am B"} -} - -export function foo() { return "foo" } - -// @filename: 1.ts -export function backup() { return "backup"; } - -// @filename: 2.ts -declare var console: any; -class C { - private myModule = import("./0"); - method() { - this.myModule.then(Zero => { - console.log(Zero.foo()); - }, async err => { - console.log(err); - let one = await import("./1"); - console.log(one.backup()); - }); - } -} \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionInUMD1.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInUMD1.ts deleted file mode 100644 index 05c4d699104..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionInUMD1.ts +++ /dev/null @@ -1,15 +0,0 @@ -// @module: umd -// @target: esnext -// @filename: 0.ts -export function foo() { return "foo"; } - -// @filename: 1.ts -import("./0"); -var p1 = import("./0"); -p1.then(zero => { - return zero.foo(); -}); - -function foo() { - const p2 = import("./0"); -} \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionInUMD2.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInUMD2.ts deleted file mode 100644 index 2f76d0aa267..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionInUMD2.ts +++ /dev/null @@ -1,17 +0,0 @@ -// @module: umd -// @target: esnext -// @filename: 0.ts -export class B { - print() { return "I am B"} -} - -// @filename: 2.ts -// We use Promise for now as there is no way to specify shape of module object -function foo(x: Promise) { - x.then(value => { - let b = new value.B(); - b.print(); - }) -} - -foo(import("./0")); \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionInUMD3.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInUMD3.ts deleted file mode 100644 index 58d21ee52d0..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionInUMD3.ts +++ /dev/null @@ -1,14 +0,0 @@ -// @module: umd -// @target: esnext -// @filename: 0.ts -export class B { - print() { return "I am B"} -} - -// @filename: 2.ts -async function foo() { - class C extends (await import("./0")).B {} - var c = new C(); - c.print(); -} -foo(); \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionInUMD4.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInUMD4.ts deleted file mode 100644 index ef0f0999407..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionInUMD4.ts +++ /dev/null @@ -1,26 +0,0 @@ -// @module: umd -// @target: esnext -// @filename: 0.ts -export class B { - print() { return "I am B"} -} - -export function foo() { return "foo" } - -// @filename: 1.ts -export function backup() { return "backup"; } - -// @filename: 2.ts -declare var console: any; -class C { - private myModule = import("./0"); - method() { - this.myModule.then(Zero => { - console.log(Zero.foo()); - }, async err => { - console.log(err); - let one = await import("./1"); - console.log(one.backup()); - }); - } -} \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionReturnPromiseOfAny.ts b/tests/cases/conformance/dynamicImport/importCallExpressionReturnPromiseOfAny.ts deleted file mode 100644 index 34f0b63be6f..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionReturnPromiseOfAny.ts +++ /dev/null @@ -1,34 +0,0 @@ -// @module: commonjs -// @target: es6 -// @noImplicitAny: true -// @filename: defaultPath.ts -export class C {} - -// @filename: 1.ts -import * as defaultModule from "./defaultPath"; -declare function getSpecifier(): string; -declare function ValidSomeCondition(): boolean; -declare var whatToLoad: boolean; -declare const directory: string; -declare const moduleFile: number; - -import(`${directory}\${moduleFile}`); -import(getSpecifier()); - -var p1 = import(ValidSomeCondition() ? "./0" : "externalModule"); -var p1: Promise = import(getSpecifier()); -var p11: Promise = import(getSpecifier()); -const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") as Promise; -p1.then(zero => { - return zero.foo(); // ok, zero is any -}); - -let j: string; -var p3: Promise = import(j=getSpecifier()); - -function * loadModule(directories: string[]) { - for (const directory of directories) { - const path = `${directory}\moduleFile`; - import(yield path); - } -} diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts b/tests/cases/conformance/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts deleted file mode 100644 index 3af0ec89ac2..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts +++ /dev/null @@ -1,17 +0,0 @@ -// @module: commonjs -// @target: es6 -// @noImplicitAny: false - -declare function getSpecifier(): boolean; -declare var whatToLoad: boolean; - -// Error specifier is not assignable to string -import(getSpecifier()); -var p1 = import(getSpecifier()); -const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") -p1.then(zero => { - return zero.foo(); // ok, zero is any -}); - -var p3 = import(["path1", "path2"]); -var p4 = import(()=>"PathToModule"); \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionWithTypeArgument.ts b/tests/cases/conformance/dynamicImport/importCallExpressionWithTypeArgument.ts deleted file mode 100644 index 895b61af6ff..00000000000 --- a/tests/cases/conformance/dynamicImport/importCallExpressionWithTypeArgument.ts +++ /dev/null @@ -1,14 +0,0 @@ -// @module: commonjs -// @target: es6 -// @noImplicitAny: false - -// @filename: 0.ts -export function foo() { return "foo"; } - -// @filename: 1.ts -"use strict" -var p1 = import>("./0"); // error -var p2 = import<>("./0"); // error -// p1.then(value => { -// value.anyFunction(); -// }) \ No newline at end of file From 1d8f57e7b3206ea64cf5df7ce3bf8fcae2a5f9be Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Mon, 5 Jun 2017 11:17:44 -0700 Subject: [PATCH 19/23] Favour exact-match spelling suggestions Previously, the first match that was close enough was returned as the spelling suggestion. Now, if there is a candidate that differs only by case, it will always be the suggestion. --- src/compiler/checker.ts | 7 +++++- .../exactSpellingSuggestion.errors.txt | 16 ++++++++++++++ .../reference/exactSpellingSuggestion.js | 22 +++++++++++++++++++ .../cases/compiler/exactSpellingSuggestion.ts | 9 ++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/exactSpellingSuggestion.errors.txt create mode 100644 tests/baselines/reference/exactSpellingSuggestion.js create mode 100644 tests/cases/compiler/exactSpellingSuggestion.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1b3084f9cbd..1cc91550dc0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14522,6 +14522,7 @@ namespace ts { const maximumLengthDifference = Math.min(3, name.length * 0.34); let bestDistance = Number.MAX_VALUE; let bestCandidate = undefined; + let justCheckExactMatches = false; if (name.length > 30) { return undefined; } @@ -14534,6 +14535,9 @@ namespace ts { if (candidateName === name) { return candidate; } + if (justCheckExactMatches) { + continue; + } if (candidateName.length < 3 || name.length < 3 || candidateName === "eval" || @@ -14549,7 +14553,8 @@ namespace ts { continue; } if (distance < 3) { - return candidate; + justCheckExactMatches = true; + bestCandidate = candidate; } else if (distance < bestDistance) { bestDistance = distance; diff --git a/tests/baselines/reference/exactSpellingSuggestion.errors.txt b/tests/baselines/reference/exactSpellingSuggestion.errors.txt new file mode 100644 index 00000000000..dbe611590d4 --- /dev/null +++ b/tests/baselines/reference/exactSpellingSuggestion.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/exactSpellingSuggestion.ts(9,4): error TS2551: Property 'bit_2' does not exist on type 'typeof U8'. Did you mean 'BIT_2'? + + +==== tests/cases/compiler/exactSpellingSuggestion.ts (1 errors) ==== + // Fixes #16245 -- always suggest the exact match, even when + // other options are very close + enum U8 { + BIT_0 = 1 << 0, + BIT_1 = 1 << 1, + BIT_2 = 1 << 2 + } + + U8.bit_2 + ~~~~~ +!!! error TS2551: Property 'bit_2' does not exist on type 'typeof U8'. Did you mean 'BIT_2'? + \ No newline at end of file diff --git a/tests/baselines/reference/exactSpellingSuggestion.js b/tests/baselines/reference/exactSpellingSuggestion.js new file mode 100644 index 00000000000..7b71065061d --- /dev/null +++ b/tests/baselines/reference/exactSpellingSuggestion.js @@ -0,0 +1,22 @@ +//// [exactSpellingSuggestion.ts] +// Fixes #16245 -- always suggest the exact match, even when +// other options are very close +enum U8 { + BIT_0 = 1 << 0, + BIT_1 = 1 << 1, + BIT_2 = 1 << 2 +} + +U8.bit_2 + + +//// [exactSpellingSuggestion.js] +// Fixes #16245 -- always suggest the exact match, even when +// other options are very close +var U8; +(function (U8) { + U8[U8["BIT_0"] = 1] = "BIT_0"; + U8[U8["BIT_1"] = 2] = "BIT_1"; + U8[U8["BIT_2"] = 4] = "BIT_2"; +})(U8 || (U8 = {})); +U8.bit_2; diff --git a/tests/cases/compiler/exactSpellingSuggestion.ts b/tests/cases/compiler/exactSpellingSuggestion.ts new file mode 100644 index 00000000000..99aec9a0199 --- /dev/null +++ b/tests/cases/compiler/exactSpellingSuggestion.ts @@ -0,0 +1,9 @@ +// Fixes #16245 -- always suggest the exact match, even when +// other options are very close +enum U8 { + BIT_0 = 1 << 0, + BIT_1 = 1 << 1, + BIT_2 = 1 << 2 +} + +U8.bit_2 From 70564110c0fbca504518bde9a32863c56bf0a187 Mon Sep 17 00:00:00 2001 From: Andy Date: Mon, 5 Jun 2017 14:11:43 -0700 Subject: [PATCH 20/23] Make use of array helper functions (#16226) * Make use of array helper functions * Remove unnecessary 'ts.' --- src/compiler/core.ts | 2 +- src/compiler/factory.ts | 4 ++-- src/compiler/program.ts | 21 +++++++-------------- src/compiler/transformers/es2015.ts | 4 ++-- src/compiler/utilities.ts | 22 ++++------------------ src/harness/fourslash.ts | 17 ++--------------- src/harness/loggedIO.ts | 9 +++------ src/server/project.ts | 19 ++++++++----------- src/services/refactorProvider.ts | 12 +----------- 9 files changed, 30 insertions(+), 80 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 5819e634ff4..1792a393234 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -473,7 +473,7 @@ namespace ts { * @param array The array to map. * @param mapfn The callback used to map the result into one or more values. */ - export function flatMap(array: T[], mapfn: (x: T, i: number) => U | U[]): U[] { + export function flatMap(array: T[] | undefined, mapfn: (x: T, i: number) => U | U[] | undefined): U[] | undefined { let result: U[]; if (array) { result = []; diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 26c40b05239..a83f00ce86e 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -2503,8 +2503,8 @@ namespace ts { helpers } = sourceEmitNode; if (!destEmitNode) destEmitNode = {}; - if (leadingComments) destEmitNode.leadingComments = addRange(leadingComments.slice(), destEmitNode.leadingComments); - if (trailingComments) destEmitNode.trailingComments = addRange(trailingComments.slice(), destEmitNode.trailingComments); + if (leadingComments) destEmitNode.leadingComments = concatenate(leadingComments, destEmitNode.leadingComments); + if (trailingComments) destEmitNode.trailingComments = concatenate(trailingComments, destEmitNode.trailingComments); if (flags) destEmitNode.flags = flags; if (commentRange) destEmitNode.commentRange = commentRange; if (sourceMapRange) destEmitNode.sourceMapRange = sourceMapRange; diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 834122b3584..00df31ed5ab 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -984,16 +984,12 @@ namespace ts { if (sourceFile) { return getDiagnostics(sourceFile, cancellationToken); } - - const allDiagnostics: Diagnostic[] = []; - forEach(program.getSourceFiles(), sourceFile => { + return sortAndDeduplicateDiagnostics(flatMap(program.getSourceFiles(), sourceFile => { if (cancellationToken) { cancellationToken.throwIfCancellationRequested(); } - addRange(allDiagnostics, getDiagnostics(sourceFile, cancellationToken)); - }); - - return sortAndDeduplicateDiagnostics(allDiagnostics); + return getDiagnostics(sourceFile, cancellationToken); + })); } function getSyntacticDiagnostics(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] { @@ -1330,16 +1326,13 @@ namespace ts { } function getOptionsDiagnostics(): Diagnostic[] { - const allDiagnostics: Diagnostic[] = []; - addRange(allDiagnostics, fileProcessingDiagnostics.getGlobalDiagnostics()); - addRange(allDiagnostics, programDiagnostics.getGlobalDiagnostics()); - return sortAndDeduplicateDiagnostics(allDiagnostics); + return sortAndDeduplicateDiagnostics(concatenate( + fileProcessingDiagnostics.getGlobalDiagnostics(), + programDiagnostics.getGlobalDiagnostics())); } function getGlobalDiagnostics(): Diagnostic[] { - const allDiagnostics: Diagnostic[] = []; - addRange(allDiagnostics, getDiagnosticsProducingTypeChecker().getGlobalDiagnostics()); - return sortAndDeduplicateDiagnostics(allDiagnostics); + return sortAndDeduplicateDiagnostics(getDiagnosticsProducingTypeChecker().getGlobalDiagnostics().slice()); } function processRootFile(fileName: string, isDefaultLib: boolean) { diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index a0656476421..7acbd3126b4 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -2095,9 +2095,9 @@ namespace ts { enableSubstitutionsForBlockScopedBindings(); } - const declarations = flatten(map(node.declarations, node.flags & NodeFlags.Let + const declarations = flatMap(node.declarations, node.flags & NodeFlags.Let ? visitVariableDeclarationInLetDeclarationList - : visitVariableDeclaration)); + : visitVariableDeclaration); const declarationList = createVariableDeclarationList(declarations); setOriginalNode(declarationList, node); diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index b52ace78615..faec63d5a28 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1434,24 +1434,10 @@ namespace ts { } function getJSDocTags(node: Node, kind: SyntaxKind): JSDocTag[] { - const docs = getJSDocs(node); - if (docs) { - const result: JSDocTag[] = []; - for (const doc of docs) { - if (doc.kind === SyntaxKind.JSDocParameterTag) { - if (doc.kind === kind) { - result.push(doc as JSDocTag); - } - } - else { - const tags = (doc as JSDoc).tags; - if (tags) { - result.push(...filter(tags, tag => tag.kind === kind)); - } - } - } - return result; - } + return flatMap(getJSDocs(node), doc => + doc.kind === SyntaxKind.JSDocComment + ? filter((doc as JSDoc).tags, tag => tag.kind === kind) + : doc.kind === kind && doc); } function getFirstJSDocTag(node: Node, kind: SyntaxKind): JSDocTag { diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 8f19b83c7ad..4045c738aa0 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -479,24 +479,11 @@ namespace FourSlash { } private getDiagnostics(fileName: string): ts.Diagnostic[] { - const syntacticErrors = this.languageService.getSyntacticDiagnostics(fileName); - const semanticErrors = this.languageService.getSemanticDiagnostics(fileName); - - const diagnostics: ts.Diagnostic[] = []; - diagnostics.push.apply(diagnostics, syntacticErrors); - diagnostics.push.apply(diagnostics, semanticErrors); - - return diagnostics; + return this.languageService.getSyntacticDiagnostics(fileName).concat(this.languageService.getSemanticDiagnostics(fileName)); } private getAllDiagnostics(): ts.Diagnostic[] { - const diagnostics: ts.Diagnostic[] = []; - - for (const fileName of this.languageServiceAdapterHost.getFilenames()) { - diagnostics.push.apply(this.getDiagnostics(fileName)); - } - - return diagnostics; + return ts.flatMap(this.languageServiceAdapterHost.getFilenames(), fileName => this.getDiagnostics(fileName)); } public verifyErrorExistsAfterMarker(markerName: string, negative: boolean, after: boolean) { diff --git a/src/harness/loggedIO.ts b/src/harness/loggedIO.ts index eeb47f0cfa0..76f585b623a 100644 --- a/src/harness/loggedIO.ts +++ b/src/harness/loggedIO.ts @@ -232,14 +232,11 @@ namespace Playback { // different entry). // TODO (yuisu): We can certainly remove these once we recapture the RWC using new API const normalizedPath = ts.normalizePath(path).toLowerCase(); - const result: string[] = []; - for (const directory of replayLog.directoriesRead) { + return ts.flatMap(replayLog.directoriesRead, directory => { if (ts.normalizeSlashes(directory.path).toLowerCase() === normalizedPath) { - result.push(...directory.result); + return directory.result; } - } - - return result; + }); }); wrapper.writeFile = recordReplay(wrapper.writeFile, underlying)( diff --git a/src/server/project.ts b/src/server/project.ts index c76e5296678..be854f948ea 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -976,18 +976,15 @@ namespace ts.server { } getExternalFiles(): SortedReadonlyArray { - const items: string[] = []; - for (const plugin of this.plugins) { - if (typeof plugin.getExternalFiles === "function") { - try { - items.push(...plugin.getExternalFiles(this)); - } - catch (e) { - this.projectService.logger.info(`A plugin threw an exception in getExternalFiles: ${e}`); - } + return toSortedReadonlyArray(flatMap(this.plugins, plugin => { + if (typeof plugin.getExternalFiles !== "function") return; + try { + return plugin.getExternalFiles(this); } - } - return toSortedReadonlyArray(items); + catch (e) { + this.projectService.logger.info(`A plugin threw an exception in getExternalFiles: ${e}`); + } + })); } watchConfigFile(callback: (project: ConfiguredProject) => void) { diff --git a/src/services/refactorProvider.ts b/src/services/refactorProvider.ts index 0b6ea3487ec..1058f9c2ca6 100644 --- a/src/services/refactorProvider.ts +++ b/src/services/refactorProvider.ts @@ -52,18 +52,8 @@ namespace ts { } export function getRefactorCodeActions(context: RefactorContext, refactorName: string): CodeAction[] | undefined { - - let result: CodeAction[]; const refactor = refactors.get(refactorName); - if (!refactor) { - return undefined; - } - - const codeActions = refactor.getCodeActions(context); - if (codeActions) { - addRange((result || (result = [])), codeActions); - } - return result; + return refactor && refactor.getCodeActions(context); } } } From 8ace7b826f3bf53b503d5cb870befc1a4deca69b Mon Sep 17 00:00:00 2001 From: Andy Date: Mon, 5 Jun 2017 14:23:39 -0700 Subject: [PATCH 21/23] importFixes: Support missing "React" at a JSXOpeningElement (#16066) * importFixes: Support missing "React" at a JSXOpeningElement * Fix nextLineRule linting * Rename to resolveJsxNamespaceAtLocation * Expose getJsxNamespace and resolveNameAtLocation separately --- scripts/tslint/nextLineRule.ts | 4 +- src/compiler/checker.ts | 12 ++++-- src/compiler/program.ts | 3 +- src/compiler/types.ts | 3 ++ src/harness/fourslash.ts | 5 ++- src/harness/unittests/telemetry.ts | 3 +- src/services/codefixes/importFixes.ts | 38 +++++++++++++------ src/services/findAllReferences.ts | 3 +- src/services/importTracker.ts | 3 +- .../importNameCodeFixUMDGlobalReact0.ts | 28 ++++++++++++++ .../importNameCodeFixUMDGlobalReact1.ts | 28 ++++++++++++++ .../importNameCodeFixUMDGlobalReact2.ts | 21 ++++++++++ 12 files changed, 130 insertions(+), 21 deletions(-) create mode 100644 tests/cases/fourslash/importNameCodeFixUMDGlobalReact0.ts create mode 100644 tests/cases/fourslash/importNameCodeFixUMDGlobalReact1.ts create mode 100644 tests/cases/fourslash/importNameCodeFixUMDGlobalReact2.ts diff --git a/scripts/tslint/nextLineRule.ts b/scripts/tslint/nextLineRule.ts index b149d09eb38..fa03746afc6 100644 --- a/scripts/tslint/nextLineRule.ts +++ b/scripts/tslint/nextLineRule.ts @@ -18,7 +18,7 @@ export class Rule extends Lint.Rules.AbstractRule { function walk(ctx: Lint.WalkContext, checkCatch: boolean, checkElse: boolean): void { const { sourceFile } = ctx; - function recur(node: ts.Node): void { + ts.forEachChild(sourceFile, function recur(node) { switch (node.kind) { case ts.SyntaxKind.IfStatement: checkIf(node as ts.IfStatement); @@ -28,7 +28,7 @@ function walk(ctx: Lint.WalkContext, checkCatch: boolean, checkElse: boole break; } ts.forEachChild(node, recur); - } + }); function checkIf(node: ts.IfStatement): void { const { thenStatement, elseStatement } = node; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1cc91550dc0..af876e32468 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -210,6 +210,11 @@ namespace ts { getSuggestionForNonexistentProperty, getSuggestionForNonexistentSymbol, getBaseConstraintOfType, + getJsxNamespace, + resolveNameAtLocation(location: Node, name: string, meaning: SymbolFlags): Symbol | undefined { + location = getParseTreeNode(location); + return resolveName(location, name, meaning, /*nameNotFoundMessage*/ undefined, name); + }, }; const tupleTypes: GenericType[] = []; @@ -847,7 +852,7 @@ namespace ts { location: Node | undefined, name: string, meaning: SymbolFlags, - nameNotFoundMessage: DiagnosticMessage, + nameNotFoundMessage: DiagnosticMessage | undefined, nameArg: string | Identifier, suggestedNameNotFoundMessage?: DiagnosticMessage): Symbol { return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, getSymbol, suggestedNameNotFoundMessage); @@ -5841,7 +5846,8 @@ namespace ts { } } return arrayFrom(props.values()); - } else { + } + else { return getPropertiesOfType(type); } } @@ -14151,7 +14157,7 @@ namespace ts { checkJsxPreconditions(node); // The reactNamespace/jsxFactory's root symbol should be marked as 'used' so we don't incorrectly elide its import. // And if there is no reactNamespace/jsxFactory's symbol in scope when targeting React emit, we should issue an error. - const reactRefErr = compilerOptions.jsx === JsxEmit.React ? Diagnostics.Cannot_find_name_0 : undefined; + const reactRefErr = diagnostics && compilerOptions.jsx === JsxEmit.React ? Diagnostics.Cannot_find_name_0 : undefined; const reactNamespace = getJsxNamespace(); const reactSym = resolveName(node.tagName, reactNamespace, SymbolFlags.Value, reactRefErr, reactNamespace); if (reactSym) { diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 00df31ed5ab..39d82b8606d 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1479,7 +1479,8 @@ namespace ts { } } return sourceFile; - } else { + } + else { const sourceFileNoExtension = options.allowNonTsExtensions && getSourceFile(fileName); if (sourceFileNoExtension) return sourceFileNoExtension; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index ed1d5dcbe23..83aa50fb803 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2605,6 +2605,9 @@ namespace ts { * Does not include properties of primitive types. */ /* @internal */ getAllPossiblePropertiesOfType(type: Type): Symbol[]; + + /* @internal */ getJsxNamespace(): string; + /* @internal */ resolveNameAtLocation(location: Node, name: string, meaning: SymbolFlags): Symbol | undefined; } export enum NodeBuilderFlags { diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 4045c738aa0..4b5af197a36 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2372,7 +2372,10 @@ namespace FourSlash { const codeFixes = this.getCodeFixActions(this.activeFile.fileName, errorCode); if (!codeFixes || codeFixes.length === 0) { - this.raiseError("No codefixes returned."); + if (expectedTextArray.length !== 0) { + this.raiseError("No codefixes returned."); + } + return; } const actualTextArray: string[] = []; diff --git a/src/harness/unittests/telemetry.ts b/src/harness/unittests/telemetry.ts index d3811edf251..f250c732c0b 100644 --- a/src/harness/unittests/telemetry.ts +++ b/src/harness/unittests/telemetry.ts @@ -252,7 +252,8 @@ namespace ts.projectSystem { } getEvent(eventName: T["eventName"], mayBeMore = false): T["data"] { - if (mayBeMore) assert(this.events.length !== 0); else assert.equal(this.events.length, 1); + if (mayBeMore) { assert(this.events.length !== 0); } + else { assert.equal(this.events.length, 1); } const event = this.events.shift(); assert.equal(event.eventName, eventName); return event.data; diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index 53ec99fac81..c2d26da4392 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -138,8 +138,23 @@ namespace ts.codefix { const currentTokenMeaning = getMeaningFromLocation(token); if (context.errorCode === Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead.code) { - const symbol = checker.getAliasedSymbol(checker.getSymbolAtLocation(token)); - return getCodeActionForImport(symbol, /*isDefault*/ false, /*isNamespaceImport*/ true); + const umdSymbol = checker.getSymbolAtLocation(token); + let symbol: ts.Symbol; + let symbolName: string; + if (umdSymbol.flags & ts.SymbolFlags.Alias) { + symbol = checker.getAliasedSymbol(umdSymbol); + symbolName = name; + } + else if (isJsxOpeningLikeElement(token.parent) && token.parent.tagName === token) { + // The error wasn't for the symbolAtLocation, it was for the JSX tag itself, which needs access to e.g. `React`. + symbol = checker.getAliasedSymbol(checker.resolveNameAtLocation(token, checker.getJsxNamespace(), SymbolFlags.Value)); + symbolName = symbol.name; + } + else { + Debug.fail("Either the symbol or the JSX namespace should be a UMD global if we got here"); + } + + return getCodeActionForImport(symbol, symbolName, /*isDefault*/ false, /*isNamespaceImport*/ true); } const candidateModules = checker.getAmbientModules(); @@ -159,7 +174,7 @@ namespace ts.codefix { if (localSymbol && localSymbol.name === name && checkSymbolHasMeaning(localSymbol, currentTokenMeaning)) { // check if this symbol is already used const symbolId = getUniqueSymbolId(localSymbol); - symbolIdActionMap.addActions(symbolId, getCodeActionForImport(moduleSymbol, /*isDefault*/ true)); + symbolIdActionMap.addActions(symbolId, getCodeActionForImport(moduleSymbol, name, /*isDefault*/ true)); } } @@ -167,7 +182,7 @@ namespace ts.codefix { const exportSymbolWithIdenticalName = checker.tryGetMemberInModuleExports(name, moduleSymbol); if (exportSymbolWithIdenticalName && checkSymbolHasMeaning(exportSymbolWithIdenticalName, currentTokenMeaning)) { const symbolId = getUniqueSymbolId(exportSymbolWithIdenticalName); - symbolIdActionMap.addActions(symbolId, getCodeActionForImport(moduleSymbol)); + symbolIdActionMap.addActions(symbolId, getCodeActionForImport(moduleSymbol, name)); } } @@ -218,7 +233,7 @@ namespace ts.codefix { return declarations ? some(symbol.declarations, decl => !!(getMeaningFromDeclaration(decl) & meaning)) : false; } - function getCodeActionForImport(moduleSymbol: Symbol, isDefault?: boolean, isNamespaceImport?: boolean): ImportCodeAction[] { + function getCodeActionForImport(moduleSymbol: Symbol, symbolName: string, isDefault?: boolean, isNamespaceImport?: boolean): ImportCodeAction[] { const existingDeclarations = getImportDeclarations(moduleSymbol); if (existingDeclarations.length > 0) { // With an existing import statement, there are more than one actions the user can do. @@ -375,10 +390,10 @@ namespace ts.codefix { const moduleSpecifierWithoutQuotes = stripQuotes(moduleSpecifier || getModuleSpecifierForNewImport()); const changeTracker = createChangeTracker(); const importClause = isDefault - ? createImportClause(createIdentifier(name), /*namedBindings*/ undefined) + ? createImportClause(createIdentifier(symbolName), /*namedBindings*/ undefined) : isNamespaceImport - ? createImportClause(/*name*/ undefined, createNamespaceImport(createIdentifier(name))) - : createImportClause(/*name*/ undefined, createNamedImports([createImportSpecifier(/*propertyName*/ undefined, createIdentifier(name))])); + ? createImportClause(/*name*/ undefined, createNamespaceImport(createIdentifier(symbolName))) + : createImportClause(/*name*/ undefined, createNamedImports([createImportSpecifier(/*propertyName*/ undefined, createIdentifier(symbolName))])); const importDecl = createImportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, importClause, createLiteral(moduleSpecifierWithoutQuotes)); if (!lastImportDeclaration) { changeTracker.insertNodeAt(sourceFile, sourceFile.getStart(), importDecl, { suffix: `${context.newLineCharacter}${context.newLineCharacter}` }); @@ -392,7 +407,7 @@ namespace ts.codefix { // are there are already a new line seperating code and import statements. return createCodeAction( Diagnostics.Import_0_from_1, - [name, `"${moduleSpecifierWithoutQuotes}"`], + [symbolName, `"${moduleSpecifierWithoutQuotes}"`], changeTracker.getChanges(), "NewImport", moduleSpecifierWithoutQuotes @@ -412,8 +427,9 @@ namespace ts.codefix { removeFileExtension(getRelativePath(moduleFileName, sourceDirectory)); function tryGetModuleNameFromAmbientModule(): string { - if (moduleSymbol.valueDeclaration.kind !== SyntaxKind.SourceFile) { - return moduleSymbol.name; + const decl = moduleSymbol.valueDeclaration; + if (isModuleDeclaration(decl) && isStringLiteral(decl.name)) { + return decl.name.text; } } diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index df499cbd38a..c1a7408fae7 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -185,7 +185,8 @@ namespace ts.FindAllReferences { if (entry.type === "node") { const { node } = entry; return { textSpan: getTextSpan(node), fileName: node.getSourceFile().fileName, ...implementationKindDisplayParts(node, checker) }; - } else { + } + else { const { textSpan, fileName } = entry; return { textSpan, fileName, kind: ScriptElementKind.unknown, displayParts: [] }; } diff --git a/src/services/importTracker.ts b/src/services/importTracker.ts index f20c80c14ef..585af7ebd31 100644 --- a/src/services/importTracker.ts +++ b/src/services/importTracker.ts @@ -530,7 +530,8 @@ namespace ts.FindAllReferences { if (parent.kind === SyntaxKind.VariableDeclaration) { const p = parent as ts.VariableDeclaration; return p.parent.kind === ts.SyntaxKind.CatchClause ? undefined : p.parent.parent.kind === SyntaxKind.VariableStatement ? p.parent.parent : undefined; - } else { + } + else { return parent; } } diff --git a/tests/cases/fourslash/importNameCodeFixUMDGlobalReact0.ts b/tests/cases/fourslash/importNameCodeFixUMDGlobalReact0.ts new file mode 100644 index 00000000000..260c34d10a6 --- /dev/null +++ b/tests/cases/fourslash/importNameCodeFixUMDGlobalReact0.ts @@ -0,0 +1,28 @@ +/// + +// @jsx: react + +// @Filename: /node_modules/@types/react/index.d.ts +////export = React; +////export as namespace React; +////declare namespace React { +//// export class Component { render(): JSX.Element | null; } +////} +////declare global { +//// namespace JSX { +//// interface Element {} +//// } +////} + +// @Filename: /a.tsx +////[|import { Component } from "react"; +////export class MyMap extends Component { } +////;|] + +goTo.file("/a.tsx"); + +verify.importFixAtPosition([ +`import { Component } from "react"; +import * as React from "react"; +export class MyMap extends Component { } +;`]); diff --git a/tests/cases/fourslash/importNameCodeFixUMDGlobalReact1.ts b/tests/cases/fourslash/importNameCodeFixUMDGlobalReact1.ts new file mode 100644 index 00000000000..ccd69c50199 --- /dev/null +++ b/tests/cases/fourslash/importNameCodeFixUMDGlobalReact1.ts @@ -0,0 +1,28 @@ +/// + +// @jsx: react + +// @Filename: /node_modules/@types/react/index.d.ts +////export = React; +////export as namespace React; +////declare namespace React { +//// export class Component { render(): JSX.Element | null; } +////} +////declare global { +//// namespace JSX { +//// interface Element {} +//// } +////} + +// @Filename: /a.tsx +////[|import { Component } from "react"; +////export class MyMap extends Component { } +////;|] + +goTo.file("/a.tsx"); + +verify.importFixAtPosition([ +`import { Component } from "react"; +import * as React from "react"; +export class MyMap extends Component { } +;`]); diff --git a/tests/cases/fourslash/importNameCodeFixUMDGlobalReact2.ts b/tests/cases/fourslash/importNameCodeFixUMDGlobalReact2.ts new file mode 100644 index 00000000000..a3c8253fbd1 --- /dev/null +++ b/tests/cases/fourslash/importNameCodeFixUMDGlobalReact2.ts @@ -0,0 +1,21 @@ +/// + +// https://github.com/Microsoft/TypeScript/issues/16065 + +// @jsx: react +// @jsxFactory: factory + +// @Filename: /factory.ts +////export function factory() { return {}; } +////declare global { +//// namespace JSX { +//// interface Element {} +//// } +////} + +// @Filename: /a.tsx +////[|
|] + +goTo.file("/a.tsx"); +verify.not +verify.importFixAtPosition([]); From bb54a6a53e0ace961270a5ff21afd9b914e1c6c1 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Mon, 5 Jun 2017 15:57:32 -0700 Subject: [PATCH 22/23] Typeof can refer to a class in a previous file with --out (#16269) * Typeof can refer block-scoped values in prev file `typeof C` can now refer to block-scoped values in a preceding file when used with --out or --outFile. Previously this was not allowed with --out or --outFile since they depend on file order for their emit. * Test `typeof C` reference across files with --out --- src/compiler/checker.ts | 1 + .../blockScopedClassDeclarationAcrossFiles.js | 15 +++++++++++++++ ...blockScopedClassDeclarationAcrossFiles.symbols | 9 +++++++++ .../blockScopedClassDeclarationAcrossFiles.types | 9 +++++++++ .../blockScopedClassDeclarationAcrossFiles.ts | 5 +++++ 5 files changed, 39 insertions(+) create mode 100644 tests/baselines/reference/blockScopedClassDeclarationAcrossFiles.js create mode 100644 tests/baselines/reference/blockScopedClassDeclarationAcrossFiles.symbols create mode 100644 tests/baselines/reference/blockScopedClassDeclarationAcrossFiles.types create mode 100644 tests/cases/compiler/blockScopedClassDeclarationAcrossFiles.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index af876e32468..cc4a0f4e34d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -740,6 +740,7 @@ namespace ts { if (declarationFile !== useFile) { if ((modulekind && (declarationFile.externalModuleIndicator || useFile.externalModuleIndicator)) || (!compilerOptions.outFile && !compilerOptions.out) || + isInTypeQuery(usage) || isInAmbientContext(declaration)) { // nodes are in different files and order cannot be determined return true; diff --git a/tests/baselines/reference/blockScopedClassDeclarationAcrossFiles.js b/tests/baselines/reference/blockScopedClassDeclarationAcrossFiles.js new file mode 100644 index 00000000000..b89943b24ff --- /dev/null +++ b/tests/baselines/reference/blockScopedClassDeclarationAcrossFiles.js @@ -0,0 +1,15 @@ +//// [tests/cases/compiler/blockScopedClassDeclarationAcrossFiles.ts] //// + +//// [c.ts] +let foo: typeof C; +//// [b.ts] +class C { } + + +//// [foo.js] +var foo; +var C = (function () { + function C() { + } + return C; +}()); diff --git a/tests/baselines/reference/blockScopedClassDeclarationAcrossFiles.symbols b/tests/baselines/reference/blockScopedClassDeclarationAcrossFiles.symbols new file mode 100644 index 00000000000..c5c6e40da20 --- /dev/null +++ b/tests/baselines/reference/blockScopedClassDeclarationAcrossFiles.symbols @@ -0,0 +1,9 @@ +=== tests/cases/compiler/c.ts === +let foo: typeof C; +>foo : Symbol(foo, Decl(c.ts, 0, 3)) +>C : Symbol(C, Decl(b.ts, 0, 0)) + +=== tests/cases/compiler/b.ts === +class C { } +>C : Symbol(C, Decl(b.ts, 0, 0)) + diff --git a/tests/baselines/reference/blockScopedClassDeclarationAcrossFiles.types b/tests/baselines/reference/blockScopedClassDeclarationAcrossFiles.types new file mode 100644 index 00000000000..5bc8862b2aa --- /dev/null +++ b/tests/baselines/reference/blockScopedClassDeclarationAcrossFiles.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/c.ts === +let foo: typeof C; +>foo : typeof C +>C : typeof C + +=== tests/cases/compiler/b.ts === +class C { } +>C : C + diff --git a/tests/cases/compiler/blockScopedClassDeclarationAcrossFiles.ts b/tests/cases/compiler/blockScopedClassDeclarationAcrossFiles.ts new file mode 100644 index 00000000000..16827602308 --- /dev/null +++ b/tests/cases/compiler/blockScopedClassDeclarationAcrossFiles.ts @@ -0,0 +1,5 @@ +// @outFile: foo.js +// @Filename: c.ts +let foo: typeof C; +// @Filename: b.ts +class C { } From 1f3c2b399828f8e08ce07d4fc29ab92982c561f3 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 5 Jun 2017 16:19:32 -0700 Subject: [PATCH 23/23] JSX Closing tags get priority over other completion types (#15922) Fixes #15897 --- src/services/completions.ts | 38 ++++++++++--------- .../fourslash/jsxQualifiedTagCompletion.ts | 15 ++++++++ 2 files changed, 35 insertions(+), 18 deletions(-) create mode 100644 tests/cases/fourslash/jsxQualifiedTagCompletion.ts diff --git a/src/services/completions.ts b/src/services/completions.ts index a895be8a7da..71fe4ce1c78 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -20,6 +20,22 @@ namespace ts.Completions { const { symbols, isGlobalCompletion, isMemberCompletion, isNewIdentifierLocation, location, requestJsDocTagName, requestJsDocTag, hasFilteredClassMemberKeywords } = completionData; + if (sourceFile.languageVariant === LanguageVariant.JSX && + location && location.parent && location.parent.kind === SyntaxKind.JsxClosingElement) { + // In the TypeScript JSX element, if such element is not defined. When users query for completion at closing tag, + // instead of simply giving unknown value, the completion will return the tag-name of an associated opening-element. + // For example: + // var x =
completion list at "1" will contain "div" with type any + const tagName = (location.parent.parent).openingElement.tagName; + return { isGlobalCompletion: false, isMemberCompletion: true, isNewIdentifierLocation: false, + entries: [{ + name: (tagName).getFullText(), + kind: ScriptElementKind.classElement, + kindModifiers: undefined, + sortText: "0", + }]}; + } + if (requestJsDocTagName) { // If the current position is a jsDoc tag name, only tag names should be provided for completion return { isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: false, entries: JsDoc.getJSDocTagNameCompletions() }; @@ -38,21 +54,7 @@ namespace ts.Completions { } else { if (!symbols || symbols.length === 0) { - if (sourceFile.languageVariant === LanguageVariant.JSX && - location.parent && location.parent.kind === SyntaxKind.JsxClosingElement) { - // In the TypeScript JSX element, if such element is not defined. When users query for completion at closing tag, - // instead of simply giving unknown value, the completion will return the tag-name of an associated opening-element. - // For example: - // var x =
completion list at "1" will contain "div" with type any - const tagName = (location.parent.parent).openingElement.tagName; - entries.push({ - name: (tagName).text, - kind: undefined, - kindModifiers: undefined, - sortText: "0", - }); - } - else if (!hasFilteredClassMemberKeywords) { + if (!hasFilteredClassMemberKeywords) { return undefined; } } @@ -495,7 +497,7 @@ namespace ts.Completions { // It has a left-hand side, so we're not in an opening JSX tag. break; } - // falls through + // falls through case SyntaxKind.JsxSelfClosingElement: case SyntaxKind.JsxElement: @@ -1050,7 +1052,7 @@ namespace ts.Completions { default: if (isFromClassElementDeclaration(contextToken) && (isClassMemberCompletionKeyword(contextToken.kind) || - isClassMemberCompletionKeywordText(contextToken.getText()))) { + isClassMemberCompletionKeywordText(contextToken.getText()))) { return contextToken.parent.parent as ClassLikeDeclaration; } } @@ -1213,7 +1215,7 @@ namespace ts.Completions { if (isFromClassElementDeclaration(contextToken)) { return false; } - // falls through + // falls through case SyntaxKind.ClassKeyword: case SyntaxKind.EnumKeyword: case SyntaxKind.InterfaceKeyword: diff --git a/tests/cases/fourslash/jsxQualifiedTagCompletion.ts b/tests/cases/fourslash/jsxQualifiedTagCompletion.ts new file mode 100644 index 00000000000..3d799324e7e --- /dev/null +++ b/tests/cases/fourslash/jsxQualifiedTagCompletion.ts @@ -0,0 +1,15 @@ +/// + +//@Filename: file.tsx +//// declare var React: any; +//// namespace NS { +//// export var Foo: any = null; +//// } +//// const j = Hello!/**/ +//// + +goTo.marker(); +edit.insert("