Merge pull request #9176 from Microsoft/Fix9173-2

Clear out unused compiler options when transpiling
This commit is contained in:
Mohamed Hegazy 2016-06-20 09:54:58 -07:00 committed by GitHub
commit 8b5616d297
50 changed files with 370 additions and 34 deletions

View file

@ -2002,9 +2002,17 @@ namespace ts {
// so pass --noLib to avoid reporting a file not found error.
options.noLib = true;
// Clear out the lib and types option as well
// Clear out other settings that would not be used in transpiling this module
options.lib = undefined;
options.types = undefined;
options.noEmit = undefined;
options.noEmitOnError = undefined;
options.paths = undefined;
options.rootDirs = undefined;
options.declaration = undefined;
options.declarationDir = undefined;
options.out = undefined;
options.outFile = undefined;
// We are not doing a full typecheck, we are not resolving the whole context,
// so pass --noResolve to avoid reporting missing file errors.

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,2 @@
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,2 @@
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -0,0 +1,3 @@
"use strict";
x;
//# sourceMappingURL=input.js.map

View file

@ -118,8 +118,8 @@ namespace ts {
transpilesCorrectly("Generates no diagnostics for missing file references", `/// <reference path="file2.ts" />
var x = 0;`, {
options: { compilerOptions: { module: ModuleKind.CommonJS } }
});
options: { compilerOptions: { module: ModuleKind.CommonJS } }
});
transpilesCorrectly("Generates no diagnostics for missing module imports", `import {a} from "module2";`, {
options: { compilerOptions: { module: ModuleKind.CommonJS } }
@ -153,22 +153,22 @@ var x = 0;`, {
`import {foo} from "SomeName";\n` +
`declare function use(a: any);\n` +
`use(foo);`, {
options: { compilerOptions: { module: ModuleKind.System, newLine: NewLineKind.LineFeed }, renamedDependencies: { "SomeName": "SomeOtherName" } }
});
options: { compilerOptions: { module: ModuleKind.System, newLine: NewLineKind.LineFeed }, renamedDependencies: { "SomeName": "SomeOtherName" } }
});
transpilesCorrectly("Rename dependencies - AMD",
`import {foo} from "SomeName";\n` +
`declare function use(a: any);\n` +
`use(foo);`, {
options: { compilerOptions: { module: ModuleKind.AMD, newLine: NewLineKind.LineFeed }, renamedDependencies: { "SomeName": "SomeOtherName" } }
});
options: { compilerOptions: { module: ModuleKind.AMD, newLine: NewLineKind.LineFeed }, renamedDependencies: { "SomeName": "SomeOtherName" } }
});
transpilesCorrectly("Rename dependencies - UMD",
`import {foo} from "SomeName";\n` +
`declare function use(a: any);\n` +
`use(foo);`, {
options: { compilerOptions: { module: ModuleKind.UMD, newLine: NewLineKind.LineFeed }, renamedDependencies: { "SomeName": "SomeOtherName" } }
});
options: { compilerOptions: { module: ModuleKind.UMD, newLine: NewLineKind.LineFeed }, renamedDependencies: { "SomeName": "SomeOtherName" } }
});
transpilesCorrectly("Transpile with emit decorators and emit metadata",
`import {db} from './db';\n` +
@ -184,17 +184,17 @@ var x = 0;`, {
` }\n` +
`}\n` +
`export {MyClass}; \n`, {
options: {
compilerOptions: {
module: ModuleKind.CommonJS,
newLine: NewLineKind.LineFeed,
noEmitHelpers: true,
emitDecoratorMetadata: true,
experimentalDecorators: true,
target: ScriptTarget.ES5,
options: {
compilerOptions: {
module: ModuleKind.CommonJS,
newLine: NewLineKind.LineFeed,
noEmitHelpers: true,
emitDecoratorMetadata: true,
experimentalDecorators: true,
target: ScriptTarget.ES5,
}
}
}
});
});
transpilesCorrectly("Supports backslashes in file name", "var x", {
options: { fileName: "a\\b.ts" }
@ -213,27 +213,21 @@ var x = 0;`, {
});
transpilesCorrectly("Accepts string as enum values for compile-options", "export const x = 0", {
options: { compilerOptions: {
module: <ModuleKind><any>"es6",
// Capitalization and spaces ignored
target: <ScriptTarget><any>" Es6 "
}}
options: {
compilerOptions: {
module: <ModuleKind><any>"es6",
// Capitalization and spaces ignored
target: <ScriptTarget><any>" Es6 "
}
}
});
transpilesCorrectly("Report an error when compiler-options module-kind is out-of-range", "", {
options: { compilerOptions: { module: <ModuleKind><any>123 }}
options: { compilerOptions: { module: <ModuleKind><any>123 } }
});
transpilesCorrectly("Report an error when compiler-options target-script is out-of-range", "", {
options: { compilerOptions: { module: <ModuleKind><any>123 }}
});
transpilesCorrectly("Report an error when compiler-options input is empty object", "", {
options: { compilerOptions: { module: <ModuleKind><any>{} }}
});
transpilesCorrectly("Report an error when compiler-options input is empty string", "", {
options: { compilerOptions: { module: <ModuleKind><any>"" }}
options: { compilerOptions: { module: <ModuleKind><any>123 } }
});
transpilesCorrectly("Support options with lib values", "const a = 10;", {
@ -243,5 +237,197 @@ var x = 0;`, {
transpilesCorrectly("Support options with types values", "const a = 10;", {
options: { compilerOptions: { types: ["jquery", "typescript"], module: ModuleKind.CommonJS }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'allowJs'", "x;", {
options: { compilerOptions: { allowJs: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'allowSyntheticDefaultImports'", "x;", {
options: { compilerOptions: { allowSyntheticDefaultImports: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'allowUnreachableCode'", "x;", {
options: { compilerOptions: { allowUnreachableCode: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'allowUnusedLabels'", "x;", {
options: { compilerOptions: { allowUnusedLabels: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'baseUrl'", "x;", {
options: { compilerOptions: { baseUrl: "./folder/baseUrl" }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'charset'", "x;", {
options: { compilerOptions: { charset: "en-us" }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'declaration'", "x;", {
options: { compilerOptions: { declaration: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'declarationDir'", "x;", {
options: { compilerOptions: { declarationDir: "out/declarations" }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'emitBOM'", "x;", {
options: { compilerOptions: { emitBOM: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'emitDecoratorMetadata'", "x;", {
options: { compilerOptions: { emitDecoratorMetadata: true, experimentalDecorators: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'experimentalDecorators'", "x;", {
options: { compilerOptions: { experimentalDecorators: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'forceConsistentCasingInFileNames'", "x;", {
options: { compilerOptions: { forceConsistentCasingInFileNames: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'isolatedModules'", "x;", {
options: { compilerOptions: { isolatedModules: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'jsx'", "x;", {
options: { compilerOptions: { jsx: 1 }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'lib'", "x;", {
options: { compilerOptions: { lib: ["es2015", "dom"] }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'locale'", "x;", {
options: { compilerOptions: { locale: "en-us" }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'module'", "x;", {
options: { compilerOptions: { module: ModuleKind.CommonJS }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'moduleResolution'", "x;", {
options: { compilerOptions: { moduleResolution: ModuleResolutionKind.NodeJs }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'newLine'", "x;", {
options: { compilerOptions: { newLine: NewLineKind.CarriageReturnLineFeed }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'noEmit'", "x;", {
options: { compilerOptions: { noEmit: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'noEmitHelpers'", "x;", {
options: { compilerOptions: { noEmitHelpers: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'noEmitOnError'", "x;", {
options: { compilerOptions: { noEmitOnError: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'noErrorTruncation'", "x;", {
options: { compilerOptions: { noErrorTruncation: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'noFallthroughCasesInSwitch'", "x;", {
options: { compilerOptions: { noFallthroughCasesInSwitch: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'noImplicitAny'", "x;", {
options: { compilerOptions: { noImplicitAny: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'noImplicitReturns'", "x;", {
options: { compilerOptions: { noImplicitReturns: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'noImplicitThis'", "x;", {
options: { compilerOptions: { noImplicitThis: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'noImplicitUseStrict'", "x;", {
options: { compilerOptions: { noImplicitUseStrict: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'noLib'", "x;", {
options: { compilerOptions: { noLib: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'noResolve'", "x;", {
options: { compilerOptions: { noResolve: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'out'", "x;", {
options: { compilerOptions: { out: "./out" }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'outDir'", "x;", {
options: { compilerOptions: { outDir: "./outDir" }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'outFile'", "x;", {
options: { compilerOptions: { outFile: "./outFile" }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'paths'", "x;", {
options: { compilerOptions: { paths: { "*": ["./generated*"] } }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'preserveConstEnums'", "x;", {
options: { compilerOptions: { preserveConstEnums: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'reactNamespace'", "x;", {
options: { compilerOptions: { reactNamespace: "react" }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'removeComments'", "x;", {
options: { compilerOptions: { removeComments: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'rootDir'", "x;", {
options: { compilerOptions: { rootDir: "./rootDir" }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'rootDirs'", "x;", {
options: { compilerOptions: { rootDirs: ["./a", "./b"] }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'skipLibCheck'", "x;", {
options: { compilerOptions: { skipLibCheck: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'skipDefaultLibCheck'", "x;", {
options: { compilerOptions: { skipDefaultLibCheck: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'strictNullChecks'", "x;", {
options: { compilerOptions: { strictNullChecks: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'stripInternal'", "x;", {
options: { compilerOptions: { stripInternal: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'suppressExcessPropertyErrors'", "x;", {
options: { compilerOptions: { suppressExcessPropertyErrors: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'suppressImplicitAnyIndexErrors'", "x;", {
options: { compilerOptions: { suppressImplicitAnyIndexErrors: true }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'target'", "x;", {
options: { compilerOptions: { target: 2 }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'types'", "x;", {
options: { compilerOptions: { types: ["jquery", "jasmine"] }, fileName: "input.js", reportDiagnostics: true }
});
transpilesCorrectly("Supports setting 'typeRoots'", "x;", {
options: { compilerOptions: { typeRoots: ["./folder"] }, fileName: "input.js", reportDiagnostics: true }
});
});
}