From d537b79c617ac28331f2a3574c97efb6578e784e Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 10 Nov 2016 14:28:34 -0800 Subject: [PATCH] Merge release-2.1 into master (#12157) * Update LKG * Update version * Update LKG * Skip overloads with too-short function parameters If the parameter of an overload is a function and the argument is also a function, skip the overload if the parameter has fewer arguments than the argument does. That overload cannot possibly apply, and should not participate in, for example, contextual typing. Example: ```ts interface I { (a: number): void; (b: string, c): void; } declare function f(i: I): void; f((x, y) => {}); ``` This code now skips the first overload instead of considering. This was a longstanding bug but was only uncovered now that more functions expressions are context sensitive. * Test skip overloads w/too-short function params 1. Update changed baseline. 2. Add a new test with baseline. * Minor style improvements * Ignore optionality when skipping overloads * Do not use contextual signatures with too few parameters * isAritySmaller runs later: getNonGenericSignature * rewrite void-returning statements in constructors that capture result of super call (#11868) * rewrite void-returning statements in constructors that capture result of super call * linter * Update LKG * Fix emit inferred type which is a generic type-alias both fully and partially fill type parameters * Add tests and baselines * Skip trying to use alias if there is target type * Update baselines * Add diagnostics to remind adding tsconfig file for certain external project (#11932) * Add diagnostics for certain external project * Show tsconfig suggestion * fix lint error * Address pr * fix comment * Update error message * Flag for not overwrite js files by default without generating errors (#11980) * WIP * Properly naming things * refactor * apply the option to all files and check out options * Fix typo * Update LKG * lockLinter * use local registry to check if typings package exist (#12014) (#12032) use local registry to check if typings package exist * Add test for https://github.com/Microsoft/TypeScript/pull/11980 (#12027) * add test for the fix for overwrite emitting error * cr feedback * enable sending telemetry events to tsserver client (#12034) (#12051) enable sending telemetry events * Update LKG * Reuse subtree transform flags for incrementally parsed nodes (#12088) * Update LKG * Update version * Update LKG * Do not emit "use strict" when targeting es6 or higher or module kind is es2015 and the file is external module * Add tests and baselines * [Release 2.1] fix11754 global augmentation (#12133) * Exclude global augmentation from module resolution logic * Address PR: check using string literal instead of NodeFlags.globalAugmentation * Remove comment --- src/compiler/checker.ts | 2 +- src/compiler/program.ts | 8 +++-- src/compiler/transformers/ts.ts | 6 +++- .../typingsInstaller/typingsInstaller.ts | 4 +-- .../reference/alwaysStrictModule3.js | 8 +++++ .../reference/alwaysStrictModule3.symbols | 6 ++++ .../reference/alwaysStrictModule3.types | 7 ++++ .../reference/alwaysStrictModule4.js | 9 +++++ .../reference/alwaysStrictModule4.symbols | 6 ++++ .../reference/alwaysStrictModule4.types | 7 ++++ .../reference/alwaysStrictModule5.js | 8 +++++ .../reference/alwaysStrictModule5.symbols | 6 ++++ .../reference/alwaysStrictModule5.types | 7 ++++ .../reference/alwaysStrictModule6.js | 9 +++++ .../reference/alwaysStrictModule6.symbols | 6 ++++ .../reference/alwaysStrictModule6.types | 7 ++++ ...arationEmitTypeAliasWithTypeParameters2.js | 17 ++++++++++ ...onEmitTypeAliasWithTypeParameters2.symbols | 30 +++++++++++++++++ ...tionEmitTypeAliasWithTypeParameters2.types | 32 ++++++++++++++++++ ...arationEmitTypeAliasWithTypeParameters3.js | 21 ++++++++++++ ...onEmitTypeAliasWithTypeParameters3.symbols | 20 +++++++++++ ...tionEmitTypeAliasWithTypeParameters3.types | 22 +++++++++++++ ...arationEmitTypeAliasWithTypeParameters4.js | 24 ++++++++++++++ ...onEmitTypeAliasWithTypeParameters4.symbols | 29 ++++++++++++++++ ...tionEmitTypeAliasWithTypeParameters4.types | 31 +++++++++++++++++ ...mitTypeAliasWithTypeParameters5.errors.txt | 16 +++++++++ ...arationEmitTypeAliasWithTypeParameters5.js | 17 ++++++++++ ...arationEmitTypeAliasWithTypeParameters6.js | 24 ++++++++++++++ ...onEmitTypeAliasWithTypeParameters6.symbols | 31 +++++++++++++++++ ...tionEmitTypeAliasWithTypeParameters6.types | 33 +++++++++++++++++++ .../globalAugmentationModuleResolution.js | 10 ++++++ ...globalAugmentationModuleResolution.symbols | 10 ++++++ ...balAugmentationModuleResolution.trace.json | 1 + .../globalAugmentationModuleResolution.types | 10 ++++++ tests/cases/compiler/alwaysStrictModule3.ts | 5 +++ tests/cases/compiler/alwaysStrictModule4.ts | 5 +++ tests/cases/compiler/alwaysStrictModule5.ts | 5 +++ tests/cases/compiler/alwaysStrictModule6.ts | 5 +++ ...arationEmitTypeAliasWithTypeParameters2.ts | 6 ++++ ...arationEmitTypeAliasWithTypeParameters3.ts | 8 +++++ ...arationEmitTypeAliasWithTypeParameters4.ts | 10 ++++++ ...arationEmitTypeAliasWithTypeParameters5.ts | 10 ++++++ ...arationEmitTypeAliasWithTypeParameters6.ts | 10 ++++++ .../globalAugmentationModuleResolution.ts | 8 +++++ 44 files changed, 549 insertions(+), 7 deletions(-) create mode 100644 tests/baselines/reference/alwaysStrictModule3.js create mode 100644 tests/baselines/reference/alwaysStrictModule3.symbols create mode 100644 tests/baselines/reference/alwaysStrictModule3.types create mode 100644 tests/baselines/reference/alwaysStrictModule4.js create mode 100644 tests/baselines/reference/alwaysStrictModule4.symbols create mode 100644 tests/baselines/reference/alwaysStrictModule4.types create mode 100644 tests/baselines/reference/alwaysStrictModule5.js create mode 100644 tests/baselines/reference/alwaysStrictModule5.symbols create mode 100644 tests/baselines/reference/alwaysStrictModule5.types create mode 100644 tests/baselines/reference/alwaysStrictModule6.js create mode 100644 tests/baselines/reference/alwaysStrictModule6.symbols create mode 100644 tests/baselines/reference/alwaysStrictModule6.types create mode 100644 tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters2.js create mode 100644 tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters2.symbols create mode 100644 tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters2.types create mode 100644 tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters3.js create mode 100644 tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters3.symbols create mode 100644 tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters3.types create mode 100644 tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters4.js create mode 100644 tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters4.symbols create mode 100644 tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters4.types create mode 100644 tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters5.errors.txt create mode 100644 tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters5.js create mode 100644 tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters6.js create mode 100644 tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters6.symbols create mode 100644 tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters6.types create mode 100644 tests/baselines/reference/globalAugmentationModuleResolution.js create mode 100644 tests/baselines/reference/globalAugmentationModuleResolution.symbols create mode 100644 tests/baselines/reference/globalAugmentationModuleResolution.trace.json create mode 100644 tests/baselines/reference/globalAugmentationModuleResolution.types create mode 100644 tests/cases/compiler/alwaysStrictModule3.ts create mode 100644 tests/cases/compiler/alwaysStrictModule4.ts create mode 100644 tests/cases/compiler/alwaysStrictModule5.ts create mode 100644 tests/cases/compiler/alwaysStrictModule6.ts create mode 100644 tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters2.ts create mode 100644 tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters3.ts create mode 100644 tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters4.ts create mode 100644 tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters5.ts create mode 100644 tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters6.ts create mode 100644 tests/cases/conformance/externalModules/globalAugmentationModuleResolution.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1510979305b..7bd8dfae88b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11493,7 +11493,7 @@ namespace ts { function checkJsxOpeningLikeElement(node: JsxOpeningLikeElement) { checkGrammarJsxElement(node); checkJsxPreconditions(node); - // The reactNamespace/jsxFactory's root symbol should be marked as 'used' so we don't incorrectly elide its import. + // 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 reactNamespace = getJsxNamespace(); diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 8b53f68bc6f..7225b311933 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -476,7 +476,7 @@ namespace ts { return resolveModuleNamesWorker(moduleNames, containingFile); } - // at this point we know that either + // at this point we know that either // - file has local declarations for ambient modules // OR // - old program state is available @@ -670,7 +670,7 @@ namespace ts { } const modifiedFilePaths = modifiedSourceFiles.map(f => f.newFile.path); - // try to verify results of module resolution + // try to verify results of module resolution for (const { oldFile: oldSourceFile, newFile: newSourceFile } of modifiedSourceFiles) { const newSourceFilePath = getNormalizedAbsolutePath(newSourceFile.fileName, currentDirectory); if (resolveModuleNamesWorker) { @@ -1447,7 +1447,9 @@ namespace ts { collectExternalModuleReferences(file); if (file.imports.length || file.moduleAugmentations.length) { file.resolvedModules = createMap(); - const moduleNames = map(concatenate(file.imports, file.moduleAugmentations), getTextOfLiteral); + // Because global augmentation doesn't have string literal name, we can check for global augmentation as such. + const nonGlobalAugmentation = filter(file.moduleAugmentations, (moduleAugmentation) => moduleAugmentation.kind === SyntaxKind.StringLiteral); + const moduleNames = map(concatenate(file.imports, nonGlobalAugmentation), getTextOfLiteral); const resolutions = resolveModuleNamesReusingOldState(moduleNames, getNormalizedAbsolutePath(file.fileName, currentDirectory), file); Debug.assert(resolutions.length === moduleNames.length); for (let i = 0; i < moduleNames.length; i++) { diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 1362746ba57..89fa039100a 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -471,7 +471,11 @@ namespace ts { currentSourceFile = node; // ensure "use strict" is emitted in all scenarios in alwaysStrict mode - if (compilerOptions.alwaysStrict) { + // There is no need to emit "use strict" in the following cases: + // 1. The file is an external module and target is es2015 or higher + // or 2. The file is an external module and module-kind is es6 or es2015 as such value is not allowed when targeting es5 or lower + if (compilerOptions.alwaysStrict && + !(isExternalModule(node) && (compilerOptions.target >= ScriptTarget.ES2015 || compilerOptions.module === ModuleKind.ES2015))) { node = ensureUseStrict(node); } diff --git a/src/server/typingsInstaller/typingsInstaller.ts b/src/server/typingsInstaller/typingsInstaller.ts index da97dbcd194..0873d5c328b 100644 --- a/src/server/typingsInstaller/typingsInstaller.ts +++ b/src/server/typingsInstaller/typingsInstaller.ts @@ -69,7 +69,7 @@ namespace ts.server.typingsInstaller { requestId: number; args: string[]; cwd: string; - onRequestCompleted: RequestCompletedAction + onRequestCompleted: RequestCompletedAction; }; export abstract class TypingsInstaller { @@ -380,7 +380,7 @@ namespace ts.server.typingsInstaller { compilerOptions: request.compilerOptions, typings, unresolvedImports: request.unresolvedImports, - kind: server.ActionSet + kind: ActionSet }; } diff --git a/tests/baselines/reference/alwaysStrictModule3.js b/tests/baselines/reference/alwaysStrictModule3.js new file mode 100644 index 00000000000..894bad25143 --- /dev/null +++ b/tests/baselines/reference/alwaysStrictModule3.js @@ -0,0 +1,8 @@ +//// [alwaysStrictModule3.ts] + +// module ES2015 +export const a = 1; + +//// [alwaysStrictModule3.js] +// module ES2015 +export var a = 1; diff --git a/tests/baselines/reference/alwaysStrictModule3.symbols b/tests/baselines/reference/alwaysStrictModule3.symbols new file mode 100644 index 00000000000..6f053673f0e --- /dev/null +++ b/tests/baselines/reference/alwaysStrictModule3.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/alwaysStrictModule3.ts === + +// module ES2015 +export const a = 1; +>a : Symbol(a, Decl(alwaysStrictModule3.ts, 2, 12)) + diff --git a/tests/baselines/reference/alwaysStrictModule3.types b/tests/baselines/reference/alwaysStrictModule3.types new file mode 100644 index 00000000000..75b11206a4f --- /dev/null +++ b/tests/baselines/reference/alwaysStrictModule3.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/alwaysStrictModule3.ts === + +// module ES2015 +export const a = 1; +>a : 1 +>1 : 1 + diff --git a/tests/baselines/reference/alwaysStrictModule4.js b/tests/baselines/reference/alwaysStrictModule4.js new file mode 100644 index 00000000000..1444f351bbd --- /dev/null +++ b/tests/baselines/reference/alwaysStrictModule4.js @@ -0,0 +1,9 @@ +//// [alwaysStrictModule4.ts] + +// Module commonjs +export const a = 1 + +//// [alwaysStrictModule4.js] +"use strict"; +// Module commonjs +exports.a = 1; diff --git a/tests/baselines/reference/alwaysStrictModule4.symbols b/tests/baselines/reference/alwaysStrictModule4.symbols new file mode 100644 index 00000000000..4b8a968ae16 --- /dev/null +++ b/tests/baselines/reference/alwaysStrictModule4.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/alwaysStrictModule4.ts === + +// Module commonjs +export const a = 1 +>a : Symbol(a, Decl(alwaysStrictModule4.ts, 2, 12)) + diff --git a/tests/baselines/reference/alwaysStrictModule4.types b/tests/baselines/reference/alwaysStrictModule4.types new file mode 100644 index 00000000000..fff87967605 --- /dev/null +++ b/tests/baselines/reference/alwaysStrictModule4.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/alwaysStrictModule4.ts === + +// Module commonjs +export const a = 1 +>a : 1 +>1 : 1 + diff --git a/tests/baselines/reference/alwaysStrictModule5.js b/tests/baselines/reference/alwaysStrictModule5.js new file mode 100644 index 00000000000..74b9d72263c --- /dev/null +++ b/tests/baselines/reference/alwaysStrictModule5.js @@ -0,0 +1,8 @@ +//// [alwaysStrictModule5.ts] + +// Targeting ES6 +export const a = 1; + +//// [alwaysStrictModule5.js] +// Targeting ES6 +export const a = 1; diff --git a/tests/baselines/reference/alwaysStrictModule5.symbols b/tests/baselines/reference/alwaysStrictModule5.symbols new file mode 100644 index 00000000000..903bf3c5c98 --- /dev/null +++ b/tests/baselines/reference/alwaysStrictModule5.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/alwaysStrictModule5.ts === + +// Targeting ES6 +export const a = 1; +>a : Symbol(a, Decl(alwaysStrictModule5.ts, 2, 12)) + diff --git a/tests/baselines/reference/alwaysStrictModule5.types b/tests/baselines/reference/alwaysStrictModule5.types new file mode 100644 index 00000000000..2bfa329ad7e --- /dev/null +++ b/tests/baselines/reference/alwaysStrictModule5.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/alwaysStrictModule5.ts === + +// Targeting ES6 +export const a = 1; +>a : 1 +>1 : 1 + diff --git a/tests/baselines/reference/alwaysStrictModule6.js b/tests/baselines/reference/alwaysStrictModule6.js new file mode 100644 index 00000000000..9a603926169 --- /dev/null +++ b/tests/baselines/reference/alwaysStrictModule6.js @@ -0,0 +1,9 @@ +//// [alwaysStrictModule6.ts] + +// Targeting ES5 +export const a = 1; + +//// [alwaysStrictModule6.js] +"use strict"; +// Targeting ES5 +exports.a = 1; diff --git a/tests/baselines/reference/alwaysStrictModule6.symbols b/tests/baselines/reference/alwaysStrictModule6.symbols new file mode 100644 index 00000000000..59a70f3e5b5 --- /dev/null +++ b/tests/baselines/reference/alwaysStrictModule6.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/alwaysStrictModule6.ts === + +// Targeting ES5 +export const a = 1; +>a : Symbol(a, Decl(alwaysStrictModule6.ts, 2, 12)) + diff --git a/tests/baselines/reference/alwaysStrictModule6.types b/tests/baselines/reference/alwaysStrictModule6.types new file mode 100644 index 00000000000..0970380911e --- /dev/null +++ b/tests/baselines/reference/alwaysStrictModule6.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/alwaysStrictModule6.ts === + +// Targeting ES5 +export const a = 1; +>a : 1 +>1 : 1 + diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters2.js b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters2.js new file mode 100644 index 00000000000..d5bf31bd755 --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters2.js @@ -0,0 +1,17 @@ +//// [declarationEmitTypeAliasWithTypeParameters2.ts] + +export type Bar = () => [X, Y, Z]; +export type Baz = Bar; +export type Baa = Baz; +export const y = (x: Baa) => 1 + +//// [declarationEmitTypeAliasWithTypeParameters2.js] +"use strict"; +exports.y = function (x) { return 1; }; + + +//// [declarationEmitTypeAliasWithTypeParameters2.d.ts] +export declare type Bar = () => [X, Y, Z]; +export declare type Baz = Bar; +export declare type Baa = Baz; +export declare const y: (x: Bar) => number; diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters2.symbols b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters2.symbols new file mode 100644 index 00000000000..cc13e9fd30b --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters2.symbols @@ -0,0 +1,30 @@ +=== tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters2.ts === + +export type Bar = () => [X, Y, Z]; +>Bar : Symbol(Bar, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 0, 0)) +>X : Symbol(X, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 1, 16)) +>Y : Symbol(Y, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 1, 18)) +>Z : Symbol(Z, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 1, 21)) +>X : Symbol(X, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 1, 16)) +>Y : Symbol(Y, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 1, 18)) +>Z : Symbol(Z, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 1, 21)) + +export type Baz = Bar; +>Baz : Symbol(Baz, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 1, 43)) +>M : Symbol(M, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 2, 16)) +>N : Symbol(N, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 2, 18)) +>Bar : Symbol(Bar, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 0, 0)) +>M : Symbol(M, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 2, 16)) +>N : Symbol(N, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 2, 18)) + +export type Baa = Baz; +>Baa : Symbol(Baa, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 2, 42)) +>Y : Symbol(Y, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 3, 16)) +>Baz : Symbol(Baz, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 1, 43)) +>Y : Symbol(Y, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 3, 16)) + +export const y = (x: Baa) => 1 +>y : Symbol(y, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 4, 12)) +>x : Symbol(x, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 4, 18)) +>Baa : Symbol(Baa, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 2, 42)) + diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters2.types b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters2.types new file mode 100644 index 00000000000..74becc49765 --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters2.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters2.ts === + +export type Bar = () => [X, Y, Z]; +>Bar : Bar +>X : X +>Y : Y +>Z : Z +>X : X +>Y : Y +>Z : Z + +export type Baz = Bar; +>Baz : Bar +>M : M +>N : N +>Bar : Bar +>M : M +>N : N + +export type Baa = Baz; +>Baa : Bar +>Y : Y +>Baz : Bar +>Y : Y + +export const y = (x: Baa) => 1 +>y : (x: Bar) => number +>(x: Baa) => 1 : (x: Bar) => number +>x : Bar +>Baa : Bar +>1 : 1 + diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters3.js b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters3.js new file mode 100644 index 00000000000..9e2a366a685 --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters3.js @@ -0,0 +1,21 @@ +//// [declarationEmitTypeAliasWithTypeParameters3.ts] + +type Foo = { + foo(): Foo +}; +function bar() { + return {} as Foo; +} + + +//// [declarationEmitTypeAliasWithTypeParameters3.js] +function bar() { + return {}; +} + + +//// [declarationEmitTypeAliasWithTypeParameters3.d.ts] +declare type Foo = { + foo(): Foo; +}; +declare function bar(): Foo; diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters3.symbols b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters3.symbols new file mode 100644 index 00000000000..a18b1372cf1 --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters3.symbols @@ -0,0 +1,20 @@ +=== tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters3.ts === + +type Foo = { +>Foo : Symbol(Foo, Decl(declarationEmitTypeAliasWithTypeParameters3.ts, 0, 0)) +>T : Symbol(T, Decl(declarationEmitTypeAliasWithTypeParameters3.ts, 1, 9)) + + foo(): Foo +>foo : Symbol(foo, Decl(declarationEmitTypeAliasWithTypeParameters3.ts, 1, 15)) +>U : Symbol(U, Decl(declarationEmitTypeAliasWithTypeParameters3.ts, 2, 8)) +>Foo : Symbol(Foo, Decl(declarationEmitTypeAliasWithTypeParameters3.ts, 0, 0)) +>U : Symbol(U, Decl(declarationEmitTypeAliasWithTypeParameters3.ts, 2, 8)) + +}; +function bar() { +>bar : Symbol(bar, Decl(declarationEmitTypeAliasWithTypeParameters3.ts, 3, 2)) + + return {} as Foo; +>Foo : Symbol(Foo, Decl(declarationEmitTypeAliasWithTypeParameters3.ts, 0, 0)) +} + diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters3.types b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters3.types new file mode 100644 index 00000000000..1b2ff140178 --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters3.types @@ -0,0 +1,22 @@ +=== tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters3.ts === + +type Foo = { +>Foo : Foo +>T : T + + foo(): Foo +>foo : () => Foo +>U : U +>Foo : Foo +>U : U + +}; +function bar() { +>bar : () => Foo + + return {} as Foo; +>{} as Foo : Foo +>{} : {} +>Foo : Foo +} + diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters4.js b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters4.js new file mode 100644 index 00000000000..26908d915e0 --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters4.js @@ -0,0 +1,24 @@ +//// [declarationEmitTypeAliasWithTypeParameters4.ts] + +type Foo = { + foo(): Foo +}; +type SubFoo = Foo; + +function foo() { + return {} as SubFoo; +} + + +//// [declarationEmitTypeAliasWithTypeParameters4.js] +function foo() { + return {}; +} + + +//// [declarationEmitTypeAliasWithTypeParameters4.d.ts] +declare type Foo = { + foo(): Foo; +}; +declare type SubFoo = Foo; +declare function foo(): Foo; diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters4.symbols b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters4.symbols new file mode 100644 index 00000000000..de73f544645 --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters4.symbols @@ -0,0 +1,29 @@ +=== tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters4.ts === + +type Foo = { +>Foo : Symbol(Foo, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 0, 0)) +>T : Symbol(T, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 1, 9)) +>Y : Symbol(Y, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 1, 11)) + + foo(): Foo +>foo : Symbol(foo, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 1, 18)) +>U : Symbol(U, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 2, 8)) +>J : Symbol(J, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 2, 10)) +>Foo : Symbol(Foo, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 0, 0)) +>U : Symbol(U, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 2, 8)) +>J : Symbol(J, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 2, 10)) + +}; +type SubFoo = Foo; +>SubFoo : Symbol(SubFoo, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 3, 2)) +>R : Symbol(R, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 4, 12)) +>Foo : Symbol(Foo, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 0, 0)) +>R : Symbol(R, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 4, 12)) + +function foo() { +>foo : Symbol(foo, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 4, 32)) + + return {} as SubFoo; +>SubFoo : Symbol(SubFoo, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 3, 2)) +} + diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters4.types b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters4.types new file mode 100644 index 00000000000..c545ac6bb05 --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters4.types @@ -0,0 +1,31 @@ +=== tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters4.ts === + +type Foo = { +>Foo : Foo +>T : T +>Y : Y + + foo(): Foo +>foo : () => Foo +>U : U +>J : J +>Foo : Foo +>U : U +>J : J + +}; +type SubFoo = Foo; +>SubFoo : Foo +>R : R +>Foo : Foo +>R : R + +function foo() { +>foo : () => Foo + + return {} as SubFoo; +>{} as SubFoo : Foo +>{} : {} +>SubFoo : Foo +} + diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters5.errors.txt b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters5.errors.txt new file mode 100644 index 00000000000..7f683dcc7b7 --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters5.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters5.ts(5,25): error TS4081: Exported type alias 'SubFoo' has or is using private name 'Foo'. + + +==== tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters5.ts (1 errors) ==== + + type Foo = { + foo(): Foo + }; + export type SubFoo = Foo; + ~~~ +!!! error TS4081: Exported type alias 'SubFoo' has or is using private name 'Foo'. + + function foo() { + return {} as SubFoo; + } + \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters5.js b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters5.js new file mode 100644 index 00000000000..2f4fff7d72c --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters5.js @@ -0,0 +1,17 @@ +//// [declarationEmitTypeAliasWithTypeParameters5.ts] + +type Foo = { + foo(): Foo +}; +export type SubFoo = Foo; + +function foo() { + return {} as SubFoo; +} + + +//// [declarationEmitTypeAliasWithTypeParameters5.js] +"use strict"; +function foo() { + return {}; +} diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters6.js b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters6.js new file mode 100644 index 00000000000..c8001446e3e --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters6.js @@ -0,0 +1,24 @@ +//// [declarationEmitTypeAliasWithTypeParameters6.ts] + +type Foo = { + foo(): Foo +}; +type SubFoo = Foo; + +function foo() { + return {} as SubFoo; +} + + +//// [declarationEmitTypeAliasWithTypeParameters6.js] +function foo() { + return {}; +} + + +//// [declarationEmitTypeAliasWithTypeParameters6.d.ts] +declare type Foo = { + foo(): Foo; +}; +declare type SubFoo = Foo; +declare function foo(): Foo; diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters6.symbols b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters6.symbols new file mode 100644 index 00000000000..ec29989f078 --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters6.symbols @@ -0,0 +1,31 @@ +=== tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters6.ts === + +type Foo = { +>Foo : Symbol(Foo, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 0, 0)) +>T : Symbol(T, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 1, 9)) +>Y : Symbol(Y, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 1, 11)) + + foo(): Foo +>foo : Symbol(foo, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 1, 18)) +>U : Symbol(U, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 2, 8)) +>J : Symbol(J, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 2, 10)) +>Foo : Symbol(Foo, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 0, 0)) +>U : Symbol(U, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 2, 8)) +>J : Symbol(J, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 2, 10)) + +}; +type SubFoo = Foo; +>SubFoo : Symbol(SubFoo, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 3, 2)) +>R : Symbol(R, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 4, 12)) +>S : Symbol(S, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 4, 14)) +>Foo : Symbol(Foo, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 0, 0)) +>S : Symbol(S, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 4, 14)) +>R : Symbol(R, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 4, 12)) + +function foo() { +>foo : Symbol(foo, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 4, 30)) + + return {} as SubFoo; +>SubFoo : Symbol(SubFoo, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 3, 2)) +} + diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters6.types b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters6.types new file mode 100644 index 00000000000..b02ccbc2be7 --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters6.types @@ -0,0 +1,33 @@ +=== tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters6.ts === + +type Foo = { +>Foo : Foo +>T : T +>Y : Y + + foo(): Foo +>foo : () => Foo +>U : U +>J : J +>Foo : Foo +>U : U +>J : J + +}; +type SubFoo = Foo; +>SubFoo : Foo +>R : R +>S : S +>Foo : Foo +>S : S +>R : R + +function foo() { +>foo : () => Foo + + return {} as SubFoo; +>{} as SubFoo : Foo +>{} : {} +>SubFoo : Foo +} + diff --git a/tests/baselines/reference/globalAugmentationModuleResolution.js b/tests/baselines/reference/globalAugmentationModuleResolution.js new file mode 100644 index 00000000000..e1a4ebce8c5 --- /dev/null +++ b/tests/baselines/reference/globalAugmentationModuleResolution.js @@ -0,0 +1,10 @@ +//// [a.ts] + +export { }; + +declare global { + var x: number; +} + +//// [a.js] +"use strict"; diff --git a/tests/baselines/reference/globalAugmentationModuleResolution.symbols b/tests/baselines/reference/globalAugmentationModuleResolution.symbols new file mode 100644 index 00000000000..614860d654e --- /dev/null +++ b/tests/baselines/reference/globalAugmentationModuleResolution.symbols @@ -0,0 +1,10 @@ +=== tests/cases/conformance/externalModules/a.ts === + +export { }; + +declare global { +>global : Symbol(global, Decl(a.ts, 1, 11)) + + var x: number; +>x : Symbol(x, Decl(a.ts, 4, 5)) +} diff --git a/tests/baselines/reference/globalAugmentationModuleResolution.trace.json b/tests/baselines/reference/globalAugmentationModuleResolution.trace.json new file mode 100644 index 00000000000..0637a088a01 --- /dev/null +++ b/tests/baselines/reference/globalAugmentationModuleResolution.trace.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/tests/baselines/reference/globalAugmentationModuleResolution.types b/tests/baselines/reference/globalAugmentationModuleResolution.types new file mode 100644 index 00000000000..c057ea2943d --- /dev/null +++ b/tests/baselines/reference/globalAugmentationModuleResolution.types @@ -0,0 +1,10 @@ +=== tests/cases/conformance/externalModules/a.ts === + +export { }; + +declare global { +>global : any + + var x: number; +>x : number +} diff --git a/tests/cases/compiler/alwaysStrictModule3.ts b/tests/cases/compiler/alwaysStrictModule3.ts new file mode 100644 index 00000000000..adb93cede36 --- /dev/null +++ b/tests/cases/compiler/alwaysStrictModule3.ts @@ -0,0 +1,5 @@ +// @alwaysStrict: true +// @module: es2015 + +// module ES2015 +export const a = 1; \ No newline at end of file diff --git a/tests/cases/compiler/alwaysStrictModule4.ts b/tests/cases/compiler/alwaysStrictModule4.ts new file mode 100644 index 00000000000..f731e6dd734 --- /dev/null +++ b/tests/cases/compiler/alwaysStrictModule4.ts @@ -0,0 +1,5 @@ +// @alwaysStrict: true +// @module: commonjs + +// Module commonjs +export const a = 1 \ No newline at end of file diff --git a/tests/cases/compiler/alwaysStrictModule5.ts b/tests/cases/compiler/alwaysStrictModule5.ts new file mode 100644 index 00000000000..d1ac5288370 --- /dev/null +++ b/tests/cases/compiler/alwaysStrictModule5.ts @@ -0,0 +1,5 @@ +// @alwaysStrict: true +// @target: es6 + +// Targeting ES6 +export const a = 1; \ No newline at end of file diff --git a/tests/cases/compiler/alwaysStrictModule6.ts b/tests/cases/compiler/alwaysStrictModule6.ts new file mode 100644 index 00000000000..064ece1a4e1 --- /dev/null +++ b/tests/cases/compiler/alwaysStrictModule6.ts @@ -0,0 +1,5 @@ +// @alwaysStrict: true +// @target: es5 + +// Targeting ES5 +export const a = 1; \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters2.ts b/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters2.ts new file mode 100644 index 00000000000..de94ad4998d --- /dev/null +++ b/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters2.ts @@ -0,0 +1,6 @@ +// @declaration: true + +export type Bar = () => [X, Y, Z]; +export type Baz = Bar; +export type Baa = Baz; +export const y = (x: Baa) => 1 \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters3.ts b/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters3.ts new file mode 100644 index 00000000000..6c7d4799abc --- /dev/null +++ b/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters3.ts @@ -0,0 +1,8 @@ +// @declaration: true + +type Foo = { + foo(): Foo +}; +function bar() { + return {} as Foo; +} diff --git a/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters4.ts b/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters4.ts new file mode 100644 index 00000000000..42bb8097997 --- /dev/null +++ b/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters4.ts @@ -0,0 +1,10 @@ +// @declaration: true + +type Foo = { + foo(): Foo +}; +type SubFoo = Foo; + +function foo() { + return {} as SubFoo; +} diff --git a/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters5.ts b/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters5.ts new file mode 100644 index 00000000000..b6334e76337 --- /dev/null +++ b/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters5.ts @@ -0,0 +1,10 @@ +// @declaration: true + +type Foo = { + foo(): Foo +}; +export type SubFoo = Foo; + +function foo() { + return {} as SubFoo; +} diff --git a/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters6.ts b/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters6.ts new file mode 100644 index 00000000000..9b313027021 --- /dev/null +++ b/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters6.ts @@ -0,0 +1,10 @@ +// @declaration: true + +type Foo = { + foo(): Foo +}; +type SubFoo = Foo; + +function foo() { + return {} as SubFoo; +} diff --git a/tests/cases/conformance/externalModules/globalAugmentationModuleResolution.ts b/tests/cases/conformance/externalModules/globalAugmentationModuleResolution.ts new file mode 100644 index 00000000000..4d87ffcab13 --- /dev/null +++ b/tests/cases/conformance/externalModules/globalAugmentationModuleResolution.ts @@ -0,0 +1,8 @@ +// @traceResolution: true + +// @fileName: a.ts +export { }; + +declare global { + var x: number; +} \ No newline at end of file