Merge pull request #2550 from Microsoft/separateCompilation

Relax import/export elision rules for separate compilation
This commit is contained in:
Vladimir Matveev 2015-03-31 14:51:39 -07:00
commit f239bbc3b1
55 changed files with 578 additions and 16 deletions

View File

@ -713,8 +713,14 @@ module ts {
function markExportAsReferenced(node: ImportEqualsDeclaration | ExportAssignment | ExportSpecifier) {
let symbol = getSymbolOfNode(node);
let target = resolveAlias(symbol);
if (target && target !== unknownSymbol && target.flags & SymbolFlags.Value && !isConstEnumOrConstEnumOnlyModule(target)) {
markAliasSymbolAsReferenced(symbol);
if (target) {
let markAlias =
(target === unknownSymbol && compilerOptions.separateCompilation) ||
(target !== unknownSymbol && (target.flags & SymbolFlags.Value) && !isConstEnumOrConstEnumOnlyModule(target));
if (markAlias) {
markAliasSymbolAsReferenced(symbol);
}
}
}
@ -9747,7 +9753,9 @@ module ts {
checkKindsOfPropertyMemberOverrides(type, baseType);
}
}
if (type.baseTypes.length || (baseTypeNode && compilerOptions.separateCompilation)) {
// Check that base type can be evaluated as expression
checkExpressionOrQualifiedName(baseTypeNode.typeName);
}
@ -10151,6 +10159,11 @@ module ts {
computeEnumMemberValues(node);
let enumIsConst = isConst(node);
if (compilerOptions.separateCompilation && enumIsConst && isInAmbientContext(node)) {
error(node.name, Diagnostics.Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided);
}
// Spec 2014 - Section 9.3:
// It isn't possible for one enum declaration to continue the automatic numbering sequence of another,
// and when an enum type has multiple declarations, only one declaration is permitted to omit a value
@ -10161,7 +10174,6 @@ module ts {
let firstDeclaration = getDeclarationOfKind(enumSymbol, node.kind);
if (node === firstDeclaration) {
if (enumSymbol.declarations.length > 1) {
let enumIsConst = isConst(node);
// check that const is placed\omitted on all enum declarations
forEach(enumSymbol.declarations, decl => {
if (isConstEnumDeclaration(decl) !== enumIsConst) {
@ -10223,7 +10235,7 @@ module ts {
if (symbol.flags & SymbolFlags.ValueModule
&& symbol.declarations.length > 1
&& !isInAmbientContext(node)
&& isInstantiatedModule(node, compilerOptions.preserveConstEnums)) {
&& isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.separateCompilation)) {
let classOrFunc = getFirstNonAmbientClassOrFunctionDeclaration(symbol);
if (classOrFunc) {
if (getSourceFileOfNode(node) !== getSourceFileOfNode(classOrFunc)) {
@ -11266,13 +11278,18 @@ module ts {
// parent is not source file or it is not reference to internal module
return false;
}
return isAliasResolvedToValue(getSymbolOfNode(node));
var isValue = isAliasResolvedToValue(getSymbolOfNode(node));
return isValue && node.moduleReference && !nodeIsMissing(node.moduleReference);
}
function isAliasResolvedToValue(symbol: Symbol): boolean {
let target = resolveAlias(symbol);
if (target === unknownSymbol && compilerOptions.separateCompilation) {
return true;
}
// const enums and modules that contain only const enums are not considered values from the emit perespective
return target !== unknownSymbol && target.flags & SymbolFlags.Value && !isConstEnumOrConstEnumOnlyModule(target);
return target !== unknownSymbol && target && target.flags & SymbolFlags.Value && !isConstEnumOrConstEnumOnlyModule(target);
}
function isConstEnumOrConstEnumOnlyModule(s: Symbol): boolean {

View File

@ -109,6 +109,10 @@ module ts {
type: "boolean",
description: Diagnostics.Do_not_emit_comments_to_output,
},
{
name: "separateCompilation",
type: "boolean",
},
{
name: "sourceMap",
type: "boolean",

View File

@ -165,6 +165,8 @@ module ts {
Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1205, category: DiagnosticCategory.Error, key: "Decorators are only available when targeting ECMAScript 5 and higher." },
Decorators_are_not_valid_here: { code: 1206, category: DiagnosticCategory.Error, key: "Decorators are not valid here." },
Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name: { code: 1207, category: DiagnosticCategory.Error, key: "Decorators cannot be applied to multiple get/set accessors of the same name." },
Cannot_compile_non_external_modules_when_the_separateCompilation_flag_is_provided: { code: 1208, category: DiagnosticCategory.Error, key: "Cannot compile non-external modules when the '--separateCompilation' flag is provided." },
Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided: { code: 1209, category: DiagnosticCategory.Error, key: "Ambient const enums are not allowed when the '--separateCompilation' flag is provided." },
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },
@ -434,6 +436,11 @@ module ts {
Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'out' or 'outDir'." },
Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'declaration'." },
Option_project_cannot_be_mixed_with_source_files_on_a_command_line: { code: 5042, category: DiagnosticCategory.Error, key: "Option 'project' cannot be mixed with source files on a command line." },
Option_sourceMap_cannot_be_specified_with_option_separateCompilation: { code: 5043, category: DiagnosticCategory.Error, key: "Option 'sourceMap' cannot be specified with option 'separateCompilation'." },
Option_declaration_cannot_be_specified_with_option_separateCompilation: { code: 5044, category: DiagnosticCategory.Error, key: "Option 'declaration' cannot be specified with option 'separateCompilation'." },
Option_noEmitOnError_cannot_be_specified_with_option_separateCompilation: { code: 5045, category: DiagnosticCategory.Error, key: "Option 'noEmitOnError' cannot be specified with option 'separateCompilation'." },
Option_out_cannot_be_specified_with_option_separateCompilation: { code: 5046, category: DiagnosticCategory.Error, key: "Option 'out' cannot be specified with option 'separateCompilation'." },
Option_separateCompilation_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher: { code: 5047, category: DiagnosticCategory.Error, key: "Option 'separateCompilation' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher." },
Concatenate_and_emit_output_to_single_file: { code: 6001, category: DiagnosticCategory.Message, key: "Concatenate and emit output to single file." },
Generates_corresponding_d_ts_file: { code: 6002, category: DiagnosticCategory.Message, key: "Generates corresponding '.d.ts' file." },
Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: { code: 6003, category: DiagnosticCategory.Message, key: "Specifies the location where debugger should locate map files instead of generated locations." },

View File

@ -651,7 +651,14 @@
"category": "Error",
"code": 1207
},
"Cannot compile non-external modules when the '--separateCompilation' flag is provided.": {
"category": "Error",
"code": 1208
},
"Ambient const enums are not allowed when the '--separateCompilation' flag is provided.": {
"category": "Error",
"code": 1209
},
"Duplicate identifier '{0}'.": {
"category": "Error",
"code": 2300
@ -1729,6 +1736,26 @@
"category": "Error",
"code": 5042
},
"Option 'sourceMap' cannot be specified with option 'separateCompilation'.": {
"category": "Error",
"code": 5043
},
"Option 'declaration' cannot be specified with option 'separateCompilation'.": {
"category": "Error",
"code": 5044
},
"Option 'noEmitOnError' cannot be specified with option 'separateCompilation'.": {
"category": "Error",
"code": 5045
},
"Option 'out' cannot be specified with option 'separateCompilation'.": {
"category": "Error",
"code": 5046
},
"Option 'separateCompilation' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher.": {
"category": "Error",
"code": 5047
},
"Concatenate and emit output to single file.": {
"category": "Message",
"code": 6001

View File

@ -1641,6 +1641,11 @@ module ts {
}
function tryEmitConstantValue(node: PropertyAccessExpression | ElementAccessExpression): boolean {
if (compilerOptions.separateCompilation) {
// do not inline enum values in separate compilation mode
return false;
}
let constantValue = resolver.getConstantValue(node);
if (constantValue !== undefined) {
write(constantValue.toString());
@ -3872,7 +3877,7 @@ module ts {
function shouldEmitEnumDeclaration(node: EnumDeclaration) {
let isConstEnum = isConst(node);
return !isConstEnum || compilerOptions.preserveConstEnums;
return !isConstEnum || compilerOptions.preserveConstEnums || compilerOptions.separateCompilation;
}
function emitEnumDeclaration(node: EnumDeclaration) {
@ -3964,7 +3969,7 @@ module ts {
}
function shouldEmitModuleDeclaration(node: ModuleDeclaration) {
return isInstantiatedModule(node, compilerOptions.preserveConstEnums);
return isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.separateCompilation);
}
function emitModuleDeclaration(node: ModuleDeclaration) {

View File

@ -454,6 +454,24 @@ module ts {
}
function verifyCompilerOptions() {
if (options.separateCompilation) {
if (options.sourceMap) {
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_sourceMap_cannot_be_specified_with_option_separateCompilation));
}
if (options.declaration) {
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_declaration_cannot_be_specified_with_option_separateCompilation));
}
if (options.noEmitOnError) {
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_noEmitOnError_cannot_be_specified_with_option_separateCompilation));
}
if (options.out) {
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_out_cannot_be_specified_with_option_separateCompilation));
}
}
if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) {
// Error to specify --mapRoot or --sourceRoot without mapSourceFiles
if (options.mapRoot) {
@ -468,12 +486,21 @@ module ts {
let languageVersion = options.target || ScriptTarget.ES3;
let firstExternalModuleSourceFile = forEach(files, f => isExternalModule(f) ? f : undefined);
if (firstExternalModuleSourceFile && !options.module) {
if (options.separateCompilation) {
if (!options.module && languageVersion < ScriptTarget.ES6) {
// We cannot use createDiagnosticFromNode because nodes do not have parents yet
let span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator);
diagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided));
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_separateCompilation_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher));
}
let firstNonExternalModuleSourceFile = forEach(files, f => !isExternalModule(f) && !isDeclarationFile(f) ? f : undefined);
if (firstNonExternalModuleSourceFile) {
let span = getErrorSpanForNode(firstNonExternalModuleSourceFile, firstNonExternalModuleSourceFile);
diagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_non_external_modules_when_the_separateCompilation_flag_is_provided));
}
}
else if (firstExternalModuleSourceFile && languageVersion < ScriptTarget.ES6 && !options.module) {
// We cannot use createDiagnosticFromNode because nodes do not have parents yet
let span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator);
diagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided));
}
// Cannot specify module gen target when in es6 or above
@ -481,11 +508,11 @@ module ts {
diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_compile_external_modules_into_amd_or_commonjs_when_targeting_es6_or_higher));
}
// there has to be common source directory if user specified --outdir || --sourcRoot
// there has to be common source directory if user specified --outdir || --sourceRoot
// if user specified --mapRoot, there needs to be common source directory if there would be multiple files being emitted
if (options.outDir || // there is --outDir specified
options.sourceRoot || // there is --sourceRoot specified
(options.mapRoot && // there is --mapRoot Specified and there would be multiple js files generated
(options.mapRoot && // there is --mapRoot specified and there would be multiple js files generated
(!options.out || firstExternalModuleSourceFile !== undefined))) {
let commonPathComponents: string[];

View File

@ -1585,6 +1585,7 @@ module ts {
target?: ScriptTarget;
version?: boolean;
watch?: boolean;
separateCompilation?: boolean;
/* @internal */ stripInternal?: boolean;
[option: string]: string | number | boolean;
}

View File

@ -274,6 +274,13 @@ module ts {
export function getErrorSpanForNode(sourceFile: SourceFile, node: Node): TextSpan {
let errorNode = node;
switch (node.kind) {
case SyntaxKind.SourceFile:
let pos = skipTrivia(sourceFile.text, 0, /*stopAfterLineBreak*/ false);
if (pos === sourceFile.text.length) {
// file is empty - return span for the beginning of the file
return createTextSpan(0, 0);
}
return getSpanOfTokenAtPosition(sourceFile, pos);
// This list is a work in progress. Add missing node kinds to improve their error
// spans.
case SyntaxKind.VariableDeclaration:

View File

@ -1052,6 +1052,10 @@ module Harness {
options.preserveConstEnums = setting.value === 'true';
break;
case 'separatecompilation':
options.separateCompilation = setting.value === 'true';
break;
case 'suppressimplicitanyindexerrors':
options.suppressImplicitAnyIndexErrors = setting.value === 'true';
break;
@ -1451,7 +1455,12 @@ module Harness {
var optionRegex = /^[\/]{2}\s*@(\w+)\s*:\s*(\S*)/gm; // multiple matches on multiple lines
// List of allowed metadata names
var fileMetadataNames = ["filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outdir", "noemitonerror", "noimplicitany", "noresolve", "newline", "newlines", "emitbom", "errortruncation", "usecasesensitivefilenames", "preserveconstenums", "includebuiltfile", "suppressimplicitanyindexerrors", "stripinternal"];
var fileMetadataNames = ["filename", "comments", "declaration", "module",
"nolib", "sourcemap", "target", "out", "outdir", "noemitonerror",
"noimplicitany", "noresolve", "newline", "newlines", "emitbom",
"errortruncation", "usecasesensitivefilenames", "preserveconstenums",
"includebuiltfile", "suppressimplicitanyindexerrors", "stripinternal",
"separatecompilation"];
function extractCompilerSettings(content: string): CompilerSetting[] {

View File

@ -1635,6 +1635,61 @@ module ts {
sourceFile.scriptSnapshot = scriptSnapshot;
}
/*
* This function will compile source text from 'input' argument using specified compiler options.
* If not options are provided - it will use a set of default compiler options.
* Extra compiler options that will unconditionally be used bu this function are:
* - separateCompilation = true
* - allowNonTsExtensions = true
*/
export function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]): string {
let options = compilerOptions ? clone(compilerOptions) : getDefaultCompilerOptions();
options.separateCompilation = true;
// Filename can be non-ts file.
options.allowNonTsExtensions = true;
// Parse
var inputFileName = fileName || "module.ts";
var sourceFile = createSourceFile(inputFileName, input, options.target);
// Store syntactic diagnostics
if (diagnostics && sourceFile.parseDiagnostics) {
diagnostics.push(...sourceFile.parseDiagnostics);
}
// Output
let outputText: string;
// Create a compilerHost object to allow the compiler to read and write files
var compilerHost: CompilerHost = {
getSourceFile: (fileName, target) => fileName === inputFileName ? sourceFile : undefined,
writeFile: (name, text, writeByteOrderMark) => {
Debug.assert(outputText === undefined, "Unexpected multiple outputs for the file: " + name);
outputText = text;
},
getDefaultLibFileName: () => "lib.d.ts",
useCaseSensitiveFileNames: () => false,
getCanonicalFileName: fileName => fileName,
getCurrentDirectory: () => "",
getNewLine: () => "\r\n"
};
var program = createProgram([inputFileName], options, compilerHost);
if (diagnostics) {
diagnostics.push(...program.getGlobalDiagnostics());
}
// Emit
program.emit();
Debug.assert(outputText !== undefined, "Output generation failed");
return outputText;
}
export function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile {
let sourceFile = createSourceFile(fileName, scriptSnapshot.getText(0, scriptSnapshot.getLength()), scriptTarget, setNodeParents);
setSourceFileFields(sourceFile, scriptSnapshot, version);

View File

@ -1241,6 +1241,7 @@ declare module "typescript" {
target?: ScriptTarget;
version?: boolean;
watch?: boolean;
separateCompilation?: boolean;
[option: string]: string | number | boolean;
}
const enum ModuleKind {
@ -1982,6 +1983,7 @@ declare module "typescript" {
isCancellationRequested(): boolean;
throwIfCancellationRequested(): void;
}
function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]): string;
function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile;
let disableIncrementalParsing: boolean;
function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;

View File

@ -3978,6 +3978,9 @@ declare module "typescript" {
watch?: boolean;
>watch : boolean
separateCompilation?: boolean;
>separateCompilation : boolean
[option: string]: string | number | boolean;
>option : string
}
@ -6154,6 +6157,15 @@ declare module "typescript" {
throwIfCancellationRequested(): void;
>throwIfCancellationRequested : () => void
}
function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]): string;
>transpile : (input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]) => string
>input : string
>compilerOptions : CompilerOptions
>CompilerOptions : CompilerOptions
>fileName : string
>diagnostics : Diagnostic[]
>Diagnostic : Diagnostic
function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile;
>createLanguageServiceSourceFile : (fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean) => SourceFile
>fileName : string

View File

@ -1272,6 +1272,7 @@ declare module "typescript" {
target?: ScriptTarget;
version?: boolean;
watch?: boolean;
separateCompilation?: boolean;
[option: string]: string | number | boolean;
}
const enum ModuleKind {
@ -2013,6 +2014,7 @@ declare module "typescript" {
isCancellationRequested(): boolean;
throwIfCancellationRequested(): void;
}
function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]): string;
function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile;
let disableIncrementalParsing: boolean;
function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;

View File

@ -4124,6 +4124,9 @@ declare module "typescript" {
watch?: boolean;
>watch : boolean
separateCompilation?: boolean;
>separateCompilation : boolean
[option: string]: string | number | boolean;
>option : string
}
@ -6300,6 +6303,15 @@ declare module "typescript" {
throwIfCancellationRequested(): void;
>throwIfCancellationRequested : () => void
}
function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]): string;
>transpile : (input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]) => string
>input : string
>compilerOptions : CompilerOptions
>CompilerOptions : CompilerOptions
>fileName : string
>diagnostics : Diagnostic[]
>Diagnostic : Diagnostic
function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile;
>createLanguageServiceSourceFile : (fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean) => SourceFile
>fileName : string

View File

@ -1273,6 +1273,7 @@ declare module "typescript" {
target?: ScriptTarget;
version?: boolean;
watch?: boolean;
separateCompilation?: boolean;
[option: string]: string | number | boolean;
}
const enum ModuleKind {
@ -2014,6 +2015,7 @@ declare module "typescript" {
isCancellationRequested(): boolean;
throwIfCancellationRequested(): void;
}
function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]): string;
function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile;
let disableIncrementalParsing: boolean;
function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;

View File

@ -4074,6 +4074,9 @@ declare module "typescript" {
watch?: boolean;
>watch : boolean
separateCompilation?: boolean;
>separateCompilation : boolean
[option: string]: string | number | boolean;
>option : string
}
@ -6250,6 +6253,15 @@ declare module "typescript" {
throwIfCancellationRequested(): void;
>throwIfCancellationRequested : () => void
}
function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]): string;
>transpile : (input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]) => string
>input : string
>compilerOptions : CompilerOptions
>CompilerOptions : CompilerOptions
>fileName : string
>diagnostics : Diagnostic[]
>Diagnostic : Diagnostic
function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile;
>createLanguageServiceSourceFile : (fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean) => SourceFile
>fileName : string

View File

@ -1310,6 +1310,7 @@ declare module "typescript" {
target?: ScriptTarget;
version?: boolean;
watch?: boolean;
separateCompilation?: boolean;
[option: string]: string | number | boolean;
}
const enum ModuleKind {
@ -2051,6 +2052,7 @@ declare module "typescript" {
isCancellationRequested(): boolean;
throwIfCancellationRequested(): void;
}
function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]): string;
function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile;
let disableIncrementalParsing: boolean;
function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;

View File

@ -4247,6 +4247,9 @@ declare module "typescript" {
watch?: boolean;
>watch : boolean
separateCompilation?: boolean;
>separateCompilation : boolean
[option: string]: string | number | boolean;
>option : string
}
@ -6423,6 +6426,15 @@ declare module "typescript" {
throwIfCancellationRequested(): void;
>throwIfCancellationRequested : () => void
}
function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]): string;
>transpile : (input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]) => string
>input : string
>compilerOptions : CompilerOptions
>CompilerOptions : CompilerOptions
>fileName : string
>diagnostics : Diagnostic[]
>Diagnostic : Diagnostic
function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile;
>createLanguageServiceSourceFile : (fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean) => SourceFile
>fileName : string

View File

@ -0,0 +1,10 @@
tests/cases/compiler/separateCompilationAmbientConstEnum.ts(3,20): error TS1209: Ambient const enums are not allowed when the '--separateCompilation' flag is provided.
==== tests/cases/compiler/separateCompilationAmbientConstEnum.ts (1 errors) ====
declare const enum E { X = 1}
~
!!! error TS1209: Ambient const enums are not allowed when the '--separateCompilation' flag is provided.
export var y;

View File

@ -0,0 +1,8 @@
//// [separateCompilationAmbientConstEnum.ts]
declare const enum E { X = 1}
export var y;
//// [separateCompilationAmbientConstEnum.js]
export var y;

View File

@ -0,0 +1,7 @@
error TS5044: Option 'declaration' cannot be specified with option 'separateCompilation'.
!!! error TS5044: Option 'declaration' cannot be specified with option 'separateCompilation'.
==== tests/cases/compiler/separateCompilationDeclaration.ts (0 errors) ====
export var x;

View File

@ -0,0 +1,10 @@
//// [separateCompilationDeclaration.ts]
export var x;
//// [separateCompilationDeclaration.js]
export var x;
//// [separateCompilationDeclaration.d.ts]
export declare var x: any;

View File

@ -0,0 +1,5 @@
//// [separateCompilationES6.ts]
export var x;
//// [separateCompilationES6.js]
export var x;

View File

@ -0,0 +1,4 @@
=== tests/cases/compiler/separateCompilationES6.ts ===
export var x;
>x : any

View File

@ -0,0 +1,28 @@
tests/cases/compiler/separateCompilationImportExportElision.ts(2,17): error TS2307: Cannot find external module 'module'.
tests/cases/compiler/separateCompilationImportExportElision.ts(3,18): error TS2307: Cannot find external module 'module'.
tests/cases/compiler/separateCompilationImportExportElision.ts(4,21): error TS2307: Cannot find external module 'module'.
tests/cases/compiler/separateCompilationImportExportElision.ts(12,18): error TS2307: Cannot find external module 'module'.
==== tests/cases/compiler/separateCompilationImportExportElision.ts (4 errors) ====
import {c} from "module"
~~~~~~~~
!!! error TS2307: Cannot find external module 'module'.
import {c2} from "module"
~~~~~~~~
!!! error TS2307: Cannot find external module 'module'.
import * as ns from "module"
~~~~~~~~
!!! error TS2307: Cannot find external module 'module'.
class C extends c2.C {
}
let x = new c();
let y = ns.value;
export {c1} from "module";
~~~~~~~~
!!! error TS2307: Cannot find external module 'module'.
export var z = x;

View File

@ -0,0 +1,37 @@
//// [separateCompilationImportExportElision.ts]
import {c} from "module"
import {c2} from "module"
import * as ns from "module"
class C extends c2.C {
}
let x = new c();
let y = ns.value;
export {c1} from "module";
export var z = x;
//// [separateCompilationImportExportElision.js]
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var module_1 = require("module");
var module_2 = require("module");
var ns = require("module");
var C = (function (_super) {
__extends(C, _super);
function C() {
_super.apply(this, arguments);
}
return C;
})(module_2.c2.C);
var x = new module_1.c();
var y = ns.value;
var module_3 = require("module");
exports.c1 = module_3.c1;
exports.z = x;

View File

@ -0,0 +1,7 @@
error TS5045: Option 'noEmitOnError' cannot be specified with option 'separateCompilation'.
!!! error TS5045: Option 'noEmitOnError' cannot be specified with option 'separateCompilation'.
==== tests/cases/compiler/separateCompilationNoEmitOnError.ts (0 errors) ====
export var x;

View File

@ -0,0 +1,8 @@
tests/cases/compiler/separateCompilationNoExternalModule.ts(2,1): error TS1208: Cannot compile non-external modules when the '--separateCompilation' flag is provided.
==== tests/cases/compiler/separateCompilationNoExternalModule.ts (1 errors) ====
var x;
~~~
!!! error TS1208: Cannot compile non-external modules when the '--separateCompilation' flag is provided.

View File

@ -0,0 +1,6 @@
//// [separateCompilationNoExternalModule.ts]
var x;
//// [separateCompilationNoExternalModule.js]
var x;

View File

@ -0,0 +1,14 @@
//// [separateCompilationNonAmbientConstEnum.ts]
const enum E { X = 100 };
var e = E.X;
export var x;
//// [separateCompilationNonAmbientConstEnum.js]
var E;
(function (E) {
E[E["X"] = 100] = "X";
})(E || (E = {}));
;
var e = E.X;
export var x;

View File

@ -0,0 +1,15 @@
=== tests/cases/compiler/separateCompilationNonAmbientConstEnum.ts ===
const enum E { X = 100 };
>E : E
>X : E
var e = E.X;
>e : E
>E.X : E
>E : typeof E
>X : E
export var x;
>x : any

View File

@ -0,0 +1,12 @@
error TS5046: Option 'out' cannot be specified with option 'separateCompilation'.
tests/cases/compiler/file2.ts(1,1): error TS1208: Cannot compile non-external modules when the '--separateCompilation' flag is provided.
!!! error TS5046: Option 'out' cannot be specified with option 'separateCompilation'.
==== tests/cases/compiler/file1.ts (0 errors) ====
export var x;
==== tests/cases/compiler/file2.ts (1 errors) ====
var y;
~~~
!!! error TS1208: Cannot compile non-external modules when the '--separateCompilation' flag is provided.

View File

@ -0,0 +1,12 @@
//// [tests/cases/compiler/separateCompilationOut.ts] ////
//// [file1.ts]
export var x;
//// [file2.ts]
var y;
//// [file1.js]
export var x;
//// [all.js]
var y;

View File

@ -0,0 +1,7 @@
error TS5043: Option 'sourceMap' cannot be specified with option 'separateCompilation'.
!!! error TS5043: Option 'sourceMap' cannot be specified with option 'separateCompilation'.
==== tests/cases/compiler/separateCompilationSourceMap.ts (0 errors) ====
export var x;

View File

@ -0,0 +1,7 @@
//// [separateCompilationSourceMap.ts]
export var x;
//// [separateCompilationSourceMap.js]
export var x;
//# sourceMappingURL=separateCompilationSourceMap.js.map

View File

@ -0,0 +1,2 @@
//// [separateCompilationSourceMap.js.map]
{"version":3,"file":"separateCompilationSourceMap.js","sourceRoot":"","sources":["separateCompilationSourceMap.ts"],"names":[],"mappings":"AACA,WAAW,CAAC,CAAC"}

View File

@ -0,0 +1,27 @@
===================================================================
JsFile: separateCompilationSourceMap.js
mapUrl: separateCompilationSourceMap.js.map
sourceRoot:
sources: separateCompilationSourceMap.ts
===================================================================
-------------------------------------------------------------------
emittedFile:tests/cases/compiler/separateCompilationSourceMap.js
sourceFile:separateCompilationSourceMap.ts
-------------------------------------------------------------------
>>>export var x;
1 >
2 >^^^^^^^^^^^
3 > ^
4 > ^
5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
1 >
>
2 >export var
3 > x
4 > ;
1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0)
2 >Emitted(1, 12) Source(2, 12) + SourceIndex(0)
3 >Emitted(1, 13) Source(2, 13) + SourceIndex(0)
4 >Emitted(1, 14) Source(2, 14) + SourceIndex(0)
---
>>>//# sourceMappingURL=separateCompilationSourceMap.js.map

View File

@ -0,0 +1,5 @@
//// [separateCompilationSpecifiedModule.ts]
export var x;
//// [separateCompilationSpecifiedModule.js]
exports.x;

View File

@ -0,0 +1,4 @@
=== tests/cases/compiler/separateCompilationSpecifiedModule.ts ===
export var x;
>x : any

View File

@ -0,0 +1,6 @@
error TS5047: Option 'separateCompilation' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher.
!!! error TS5047: Option 'separateCompilation' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher.
==== tests/cases/compiler/separateCompilationUnspecifiedModule.ts (0 errors) ====
export var x;

View File

@ -0,0 +1,5 @@
//// [separateCompilationUnspecifiedModule.ts]
export var x;
//// [separateCompilationUnspecifiedModule.js]
exports.x;

View File

@ -0,0 +1,11 @@
//// [tests/cases/compiler/separateCompilationWithDeclarationFile.ts] ////
//// [file1.d.ts]
declare function foo(): void;
//// [file1.ts]
export var x;
//// [file1.js]
export var x;

View File

@ -0,0 +1,9 @@
=== tests/cases/compiler/file1.d.ts ===
declare function foo(): void;
>foo : () => void
=== tests/cases/compiler/file1.ts ===
export var x;
>x : any

View File

@ -0,0 +1,7 @@
// @separateCompilation: true
// @target: es6
// @filename: file1.ts
declare const enum E { X = 1}
export var y;

View File

@ -0,0 +1,6 @@
// @separateCompilation: true
// @declaration: true
// @target: es6
// @filename: file1.ts
export var x;

View File

@ -0,0 +1,4 @@
// @separateCompilation: true
// @target: es6
// @filename: file1.ts
export var x;

View File

@ -0,0 +1,17 @@
// @separateCompilation: true
// @target: es5
// @module: commonjs
// @filename: file1.ts
import {c} from "module"
import {c2} from "module"
import * as ns from "module"
class C extends c2.C {
}
let x = new c();
let y = ns.value;
export {c1} from "module";
export var z = x;

View File

@ -0,0 +1,6 @@
// @separateCompilation: true
// @noEmitOnError:true
// @target: es6
// @filename: file1.ts
export var x;

View File

@ -0,0 +1,5 @@
// @separateCompilation: true
// @target: es6
// @filename: file1.ts
var x;

View File

@ -0,0 +1,7 @@
// @separateCompilation: true
// @target: es6
// @filename: file1.ts
const enum E { X = 100 };
var e = E.X;
export var x;

View File

@ -0,0 +1,8 @@
// @separateCompilation: true
// @out:all.js
// @target: es6
// @filename: file1.ts
export var x;
// @filename: file2.ts
var y;

View File

@ -0,0 +1,6 @@
// @separateCompilation: true
// @sourceMap:sourcemap.map
// @target: es6
// @filename: file1.ts
export var x;

View File

@ -0,0 +1,4 @@
// @separateCompilation: true
// @module: commonjs
// @filename: file1.ts
export var x;

View File

@ -0,0 +1,3 @@
// @separateCompilation: true
// @filename: file1.ts
export var x;

View File

@ -0,0 +1,8 @@
// @separateCompilation: true
// @target: es6
// @filename: file1.d.ts
declare function foo(): void;
// @filename: file1.ts
export var x;