From a51f0bf8bbca289f692e046cecd18670fd5cf6dd Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 25 Mar 2015 23:18:58 -0700 Subject: [PATCH 1/9] added relaxed emit rules for separate compilation --- src/compiler/checker.ts | 19 ++++++++-- src/compiler/types.ts | 1 + src/services/services.ts | 80 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6fdaac79cea00..9765ceee4a965 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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); + } } } @@ -9745,7 +9751,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); } @@ -11264,11 +11272,16 @@ 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); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index e5697f9f37239..9482339d09b5b 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1587,6 +1587,7 @@ module ts { target?: ScriptTarget; version?: boolean; watch?: boolean; + separateCompilation?: boolean; /* @internal */ stripInternal?: boolean; /* @internal */ preserveNewLines?: boolean; /* @internal */ cacheDownlevelForOfLength?: boolean; diff --git a/src/services/services.ts b/src/services/services.ts index 41ffc04e5aefd..5f8ab267e7d0b 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1635,6 +1635,86 @@ module ts { sourceFile.scriptSnapshot = scriptSnapshot; } + export function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, syntaxErrors?: Diagnostic[]): string { + let options = compilerOptions ? ts.clone(compilerOptions) : getDefaultCompilerOptions(); + + // Single file transformation is only guranteed to be correct if inside an external module. + // External modules have thier own scope and can not contribute to internal modules outside their + // scope. + if (options.target !== ScriptTarget.ES6 && (!options.module || options.module === ModuleKind.None)) { + // add errors + } + + // In sigle file transformation the compiler does not have access to declaration sites. + // Const enum property access will not be detected if they are not in the same file as the enum. + // thus they are goign to be emitted as normal propety access. To ensure correct behaviour at runtime, + // we need to generare the actual enum object so that the proprty accesses do not fail. + options.preserveConstEnums = true; + + // No reason to get declarations, we are only returning javascript + options.declaration = false; + + // Filename can be non-ts file. We are not locating any modules as well, so allow + // non-ts extensions + options.allowNonTsExtensions = true; + + // enable relaxed emit rules + options.separateCompilation = true; + + // We are not resolving references or modules, or even including the library. Disabling + // emit on error will block generating the output and has no meaningful use here. + options.noEmitOnError = false; + + // No resolution requests will be honered anyways. So do not do it + options.noResolve = true; + + // TODO (vladima): add inlineSourceMap once it is checked in + //if (options.sourceMap) { + // // We need to return a single string, so inline the sourceMap in the output + // options.inlineSourceMap = true;; + //} + + // Parse + var inputFileName = fileName || "module.ts"; + var sourceFile = ts.createSourceFile(inputFileName, input, options.target); + + // Store syntactic diagnostics + if (syntaxErrors && sourceFile.parseDiagnostics) { + syntaxErrors.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) => { + if (ts.fileExtensionIs(name, ".js")) { + 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" + }; + + // Note: The emitter needs a the checker to walk the file, so we will create a program for this + // though single file transformation does not really need this. First we need to drop the emitter + // dependcy on the checker and then implement a new resolver that does not do the full check. + var program = ts.createProgram([inputFileName], options, compilerHost); + + // 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); From 8f616ce65c5daa72565bdb60044671f1314f6606 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 30 Mar 2015 12:43:10 -0700 Subject: [PATCH 2/9] fix typos in comments --- src/services/services.ts | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 5f8ab267e7d0b..2d5ce2d5f25b7 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1638,41 +1638,37 @@ module ts { export function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, syntaxErrors?: Diagnostic[]): string { let options = compilerOptions ? ts.clone(compilerOptions) : getDefaultCompilerOptions(); - // Single file transformation is only guranteed to be correct if inside an external module. - // External modules have thier own scope and can not contribute to internal modules outside their + // Single file transformation is only guaranteed to be correct inside an external module. + // External modules have their own scope and cannot contribute to internal modules outside their // scope. if (options.target !== ScriptTarget.ES6 && (!options.module || options.module === ModuleKind.None)) { - // add errors + // TODO: add errors } - // In sigle file transformation the compiler does not have access to declaration sites. - // Const enum property access will not be detected if they are not in the same file as the enum. - // thus they are goign to be emitted as normal propety access. To ensure correct behaviour at runtime, - // we need to generare the actual enum object so that the proprty accesses do not fail. + // In single file transformation the compiler does not have access to declaration sites. + // Const enum property accesses will not be detected if they are not in the same file as the enum. + // thus they are going to be emitted as normal propety access. To ensure correct behaviour at runtime, + // we need to generate the actual enum object so that the property accesses do not fail. options.preserveConstEnums = true; // No reason to get declarations, we are only returning javascript options.declaration = false; - // Filename can be non-ts file. We are not locating any modules as well, so allow - // non-ts extensions + // Filename can be non-ts file. options.allowNonTsExtensions = true; // enable relaxed emit rules options.separateCompilation = true; - // We are not resolving references or modules, or even including the library. Disabling + // We are not resolving references or modules, or even including the default library. Disabling // emit on error will block generating the output and has no meaningful use here. options.noEmitOnError = false; - // No resolution requests will be honered anyways. So do not do it + // No resolution requests will be honored anyways. So do not do it options.noResolve = true; - // TODO (vladima): add inlineSourceMap once it is checked in - //if (options.sourceMap) { - // // We need to return a single string, so inline the sourceMap in the output - // options.inlineSourceMap = true;; - //} + // TODO (vladima): this should be enabled after adding support to inlinable source maps + options.sourceMap = false; // Parse var inputFileName = fileName || "module.ts"; @@ -1690,10 +1686,8 @@ module ts { var compilerHost: CompilerHost = { getSourceFile: (fileName, target) => fileName === inputFileName ? sourceFile : undefined, writeFile: (name, text, writeByteOrderMark) => { - if (ts.fileExtensionIs(name, ".js")) { - Debug.assert(outputText === undefined, "Unexpected multiple outputs for the file: " + name); - outputText = text; - } + Debug.assert(outputText === undefined, "Unexpected multiple outputs for the file: " + name); + outputText = text; }, getDefaultLibFileName: () => "lib.d.ts", useCaseSensitiveFileNames: () => false, @@ -1702,9 +1696,6 @@ module ts { getNewLine: () => "\r\n" }; - // Note: The emitter needs a the checker to walk the file, so we will create a program for this - // though single file transformation does not really need this. First we need to drop the emitter - // dependcy on the checker and then implement a new resolver that does not do the full check. var program = ts.createProgram([inputFileName], options, compilerHost); // Emit From 4b7e6cfc2e981fbd005812d0ce5a3c0167f689e4 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 30 Mar 2015 19:33:15 -0700 Subject: [PATCH 3/9] addressed CR feedback, accepted baselines --- src/compiler/checker.ts | 6 +-- src/compiler/commandLineParser.ts | 4 ++ .../diagnosticInformationMap.generated.ts | 6 +++ src/compiler/diagnosticMessages.json | 25 +++++++++- src/compiler/emitter.ts | 9 +++- src/compiler/program.ts | 39 +++++++++++++--- src/compiler/utilities.ts | 7 +++ src/services/services.ts | 46 ++++++------------- .../baselines/reference/APISample_compile.js | 2 + .../reference/APISample_compile.types | 12 +++++ tests/baselines/reference/APISample_linter.js | 2 + .../reference/APISample_linter.types | 12 +++++ .../reference/APISample_transform.js | 2 + .../reference/APISample_transform.types | 12 +++++ .../baselines/reference/APISample_watcher.js | 2 + .../reference/APISample_watcher.types | 12 +++++ 16 files changed, 155 insertions(+), 43 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 58383e2b6f1c1..a5c83f8d3faec 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -716,7 +716,7 @@ module ts { if (target) { let markAlias = (target === unknownSymbol && compilerOptions.separateCompilation) || - (target !== unknownSymbol && target.flags & SymbolFlags.Value && !isConstEnumOrConstEnumOnlyModule(target)); + (target !== unknownSymbol && (target.flags & SymbolFlags.Value) && !isConstEnumOrConstEnumOnlyModule(target)); if (markAlias) { markAliasSymbolAsReferenced(symbol); @@ -10231,7 +10231,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)) { @@ -11285,7 +11285,7 @@ module ts { 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 { diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 4ba2da757e5d8..c91fef403211d 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -117,6 +117,10 @@ module ts { type: "boolean", description: Diagnostics.Do_not_emit_comments_to_output, }, + { + name: "separateCompilation", + type: "boolean", + }, { name: "sourceMap", type: "boolean", diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 967afd171bac8..a7bbe3a3ba2f9 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -165,6 +165,7 @@ 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." }, 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 +435,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." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 6e24afad80c4a..d3643e6536efb 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -651,7 +651,10 @@ "category": "Error", "code": 1207 }, - + "Cannot compile non-external modules when the '--separateCompilation' flag is provided.": { + "category": "Error", + "code": 1208 + }, "Duplicate identifier '{0}'.": { "category": "Error", "code": 2300 @@ -1729,6 +1732,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 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 366bb1856ea39..bf58167bd8d7e 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -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()); @@ -3874,7 +3879,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) { @@ -3966,7 +3971,7 @@ module ts { } function shouldEmitModuleDeclaration(node: ModuleDeclaration) { - return isInstantiatedModule(node, compilerOptions.preserveConstEnums); + return isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.separateCompilation); } function emitModuleDeclaration(node: ModuleDeclaration) { diff --git a/src/compiler/program.ts b/src/compiler/program.ts index cb12e6da4d5db..1deb413231716 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -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) ? 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[]; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 9fa0674c25c07..936d40e18d320 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -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: diff --git a/src/services/services.ts b/src/services/services.ts index 2d5ce2d5f25b7..05e173e70bbeb 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1635,48 +1635,28 @@ module ts { sourceFile.scriptSnapshot = scriptSnapshot; } - export function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, syntaxErrors?: Diagnostic[]): string { + /* + * 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 ? ts.clone(compilerOptions) : getDefaultCompilerOptions(); - // Single file transformation is only guaranteed to be correct inside an external module. - // External modules have their own scope and cannot contribute to internal modules outside their - // scope. - if (options.target !== ScriptTarget.ES6 && (!options.module || options.module === ModuleKind.None)) { - // TODO: add errors - } - - // In single file transformation the compiler does not have access to declaration sites. - // Const enum property accesses will not be detected if they are not in the same file as the enum. - // thus they are going to be emitted as normal propety access. To ensure correct behaviour at runtime, - // we need to generate the actual enum object so that the property accesses do not fail. - options.preserveConstEnums = true; - - // No reason to get declarations, we are only returning javascript - options.declaration = false; + options.separateCompilation = true; // Filename can be non-ts file. options.allowNonTsExtensions = true; - // enable relaxed emit rules - options.separateCompilation = true; - - // We are not resolving references or modules, or even including the default library. Disabling - // emit on error will block generating the output and has no meaningful use here. - options.noEmitOnError = false; - - // No resolution requests will be honored anyways. So do not do it - options.noResolve = true; - - // TODO (vladima): this should be enabled after adding support to inlinable source maps - options.sourceMap = false; - // Parse var inputFileName = fileName || "module.ts"; var sourceFile = ts.createSourceFile(inputFileName, input, options.target); // Store syntactic diagnostics - if (syntaxErrors && sourceFile.parseDiagnostics) { - syntaxErrors.push(...sourceFile.parseDiagnostics); + if (diagnostics && sourceFile.parseDiagnostics) { + diagnostics.push(...sourceFile.parseDiagnostics); } // Output @@ -1698,6 +1678,10 @@ module ts { var program = ts.createProgram([inputFileName], options, compilerHost); + if (diagnostics) { + diagnostics.push(...program.getGlobalDiagnostics()); + } + // Emit program.emit(); diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 3f0ba5f18cd66..70e9f76115d88 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -1243,6 +1243,7 @@ declare module "typescript" { target?: ScriptTarget; version?: boolean; watch?: boolean; + separateCompilation?: boolean; [option: string]: string | number | boolean; } const enum ModuleKind { @@ -1984,6 +1985,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; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index eff47a4cb7bf1..f06e49fcba81a 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -3984,6 +3984,9 @@ declare module "typescript" { watch?: boolean; >watch : boolean + separateCompilation?: boolean; +>separateCompilation : boolean + [option: string]: string | number | boolean; >option : string } @@ -6160,6 +6163,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 diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index ab48f78affcb2..9387b52f4b95d 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -1274,6 +1274,7 @@ declare module "typescript" { target?: ScriptTarget; version?: boolean; watch?: boolean; + separateCompilation?: boolean; [option: string]: string | number | boolean; } const enum ModuleKind { @@ -2015,6 +2016,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; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 600bf5c6adc72..c92c66afd2fc4 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -4130,6 +4130,9 @@ declare module "typescript" { watch?: boolean; >watch : boolean + separateCompilation?: boolean; +>separateCompilation : boolean + [option: string]: string | number | boolean; >option : string } @@ -6306,6 +6309,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 diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index d40c078a1502a..fba3642d36993 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -1275,6 +1275,7 @@ declare module "typescript" { target?: ScriptTarget; version?: boolean; watch?: boolean; + separateCompilation?: boolean; [option: string]: string | number | boolean; } const enum ModuleKind { @@ -2016,6 +2017,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; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index 4ea9c49d7587d..a7a898e01be67 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -4080,6 +4080,9 @@ declare module "typescript" { watch?: boolean; >watch : boolean + separateCompilation?: boolean; +>separateCompilation : boolean + [option: string]: string | number | boolean; >option : string } @@ -6256,6 +6259,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 diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index c53034c11d796..1a203faea44cd 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -1312,6 +1312,7 @@ declare module "typescript" { target?: ScriptTarget; version?: boolean; watch?: boolean; + separateCompilation?: boolean; [option: string]: string | number | boolean; } const enum ModuleKind { @@ -2053,6 +2054,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; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 3903e169b4e3b..acbbfdb2eab85 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -4253,6 +4253,9 @@ declare module "typescript" { watch?: boolean; >watch : boolean + separateCompilation?: boolean; +>separateCompilation : boolean + [option: string]: string | number | boolean; >option : string } @@ -6429,6 +6432,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 From a6c88e290efb1f8f659f6bfe66833fda4345afc6 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 30 Mar 2015 21:35:27 -0700 Subject: [PATCH 4/9] addressed CR feedback --- src/services/services.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 05e173e70bbeb..296ff033ef2b9 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1643,7 +1643,7 @@ module ts { * - allowNonTsExtensions = true */ export function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]): string { - let options = compilerOptions ? ts.clone(compilerOptions) : getDefaultCompilerOptions(); + let options = compilerOptions ? clone(compilerOptions) : getDefaultCompilerOptions(); options.separateCompilation = true; @@ -1676,7 +1676,7 @@ module ts { getNewLine: () => "\r\n" }; - var program = ts.createProgram([inputFileName], options, compilerHost); + var program = createProgram([inputFileName], options, compilerHost); if (diagnostics) { diagnostics.push(...program.getGlobalDiagnostics()); From 955b4c05890bf2e10611ea954672415a55d343b7 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 30 Mar 2015 21:36:06 -0700 Subject: [PATCH 5/9] addressed CR feedback --- src/services/services.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/services.ts b/src/services/services.ts index 296ff033ef2b9..e481479150b73 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1652,7 +1652,7 @@ module ts { // Parse var inputFileName = fileName || "module.ts"; - var sourceFile = ts.createSourceFile(inputFileName, input, options.target); + var sourceFile = createSourceFile(inputFileName, input, options.target); // Store syntactic diagnostics if (diagnostics && sourceFile.parseDiagnostics) { From c885f59d1b4f176afb872c852649b585fed05900 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 30 Mar 2015 22:41:49 -0700 Subject: [PATCH 6/9] do not include declaration files in 'is external module' check --- src/compiler/program.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 1deb413231716..6a211d6213b65 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -491,7 +491,7 @@ module ts { 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) ? f : undefined); + 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)); From 49b3f85a179db0b020312214f681f670ccf7c0a4 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 30 Mar 2015 22:42:54 -0700 Subject: [PATCH 7/9] disallow ambient const enums in 'separate compilation' mode --- src/compiler/checker.ts | 6 +++++- src/compiler/diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a5c83f8d3faec..d303be36f74b1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10159,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 @@ -10169,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) { diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index a7bbe3a3ba2f9..32d36020d3d70 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -166,6 +166,7 @@ module ts { 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." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index d3643e6536efb..f593ac2ff70b3 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -655,6 +655,10 @@ "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 From 1803d730c2f737dda8ec765744745f8ffb4acf27 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 30 Mar 2015 23:17:45 -0700 Subject: [PATCH 8/9] added initial set of unit tests for separate compilation mode --- src/harness/harness.ts | 11 +++++++- ...rateCompilationAmbientConstEnum.errors.txt | 10 +++++++ .../separateCompilationAmbientConstEnum.js | 8 ++++++ .../separateCompilationDeclaration.errors.txt | 7 +++++ .../separateCompilationDeclaration.js | 10 +++++++ .../reference/separateCompilationES6.js | 5 ++++ .../reference/separateCompilationES6.types | 4 +++ ...eparateCompilationNoEmitOnError.errors.txt | 7 +++++ ...rateCompilationNoExternalModule.errors.txt | 8 ++++++ .../separateCompilationNoExternalModule.js | 6 +++++ .../separateCompilationNonAmbientConstEnum.js | 14 ++++++++++ ...parateCompilationNonAmbientConstEnum.types | 15 +++++++++++ .../separateCompilationOut.errors.txt | 12 +++++++++ .../reference/separateCompilationOut.js | 12 +++++++++ .../separateCompilationSourceMap.errors.txt | 7 +++++ .../reference/separateCompilationSourceMap.js | 7 +++++ .../separateCompilationSourceMap.js.map | 2 ++ ...separateCompilationSourceMap.sourcemap.txt | 27 +++++++++++++++++++ .../separateCompilationSpecifiedModule.js | 5 ++++ .../separateCompilationSpecifiedModule.types | 4 +++ ...ateCompilationUnspecifiedModule.errors.txt | 6 +++++ .../separateCompilationUnspecifiedModule.js | 5 ++++ .../separateCompilationWithDeclarationFile.js | 11 ++++++++ ...parateCompilationWithDeclarationFile.types | 9 +++++++ .../separateCompilationAmbientConstEnum.ts | 7 +++++ .../separateCompilationDeclaration.ts | 6 +++++ .../cases/compiler/separateCompilationES6.ts | 4 +++ .../separateCompilationNoEmitOnError.ts | 6 +++++ .../separateCompilationNoExternalModule.ts | 5 ++++ .../separateCompilationNonAmbientConstEnum.ts | 7 +++++ .../cases/compiler/separateCompilationOut.ts | 8 ++++++ .../compiler/separateCompilationSourceMap.ts | 6 +++++ .../separateCompilationSpecifiedModule.ts | 4 +++ .../separateCompilationUnspecifiedModule.ts | 3 +++ .../separateCompilationWithDeclarationFile.ts | 8 ++++++ 35 files changed, 275 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/separateCompilationAmbientConstEnum.errors.txt create mode 100644 tests/baselines/reference/separateCompilationAmbientConstEnum.js create mode 100644 tests/baselines/reference/separateCompilationDeclaration.errors.txt create mode 100644 tests/baselines/reference/separateCompilationDeclaration.js create mode 100644 tests/baselines/reference/separateCompilationES6.js create mode 100644 tests/baselines/reference/separateCompilationES6.types create mode 100644 tests/baselines/reference/separateCompilationNoEmitOnError.errors.txt create mode 100644 tests/baselines/reference/separateCompilationNoExternalModule.errors.txt create mode 100644 tests/baselines/reference/separateCompilationNoExternalModule.js create mode 100644 tests/baselines/reference/separateCompilationNonAmbientConstEnum.js create mode 100644 tests/baselines/reference/separateCompilationNonAmbientConstEnum.types create mode 100644 tests/baselines/reference/separateCompilationOut.errors.txt create mode 100644 tests/baselines/reference/separateCompilationOut.js create mode 100644 tests/baselines/reference/separateCompilationSourceMap.errors.txt create mode 100644 tests/baselines/reference/separateCompilationSourceMap.js create mode 100644 tests/baselines/reference/separateCompilationSourceMap.js.map create mode 100644 tests/baselines/reference/separateCompilationSourceMap.sourcemap.txt create mode 100644 tests/baselines/reference/separateCompilationSpecifiedModule.js create mode 100644 tests/baselines/reference/separateCompilationSpecifiedModule.types create mode 100644 tests/baselines/reference/separateCompilationUnspecifiedModule.errors.txt create mode 100644 tests/baselines/reference/separateCompilationUnspecifiedModule.js create mode 100644 tests/baselines/reference/separateCompilationWithDeclarationFile.js create mode 100644 tests/baselines/reference/separateCompilationWithDeclarationFile.types create mode 100644 tests/cases/compiler/separateCompilationAmbientConstEnum.ts create mode 100644 tests/cases/compiler/separateCompilationDeclaration.ts create mode 100644 tests/cases/compiler/separateCompilationES6.ts create mode 100644 tests/cases/compiler/separateCompilationNoEmitOnError.ts create mode 100644 tests/cases/compiler/separateCompilationNoExternalModule.ts create mode 100644 tests/cases/compiler/separateCompilationNonAmbientConstEnum.ts create mode 100644 tests/cases/compiler/separateCompilationOut.ts create mode 100644 tests/cases/compiler/separateCompilationSourceMap.ts create mode 100644 tests/cases/compiler/separateCompilationSpecifiedModule.ts create mode 100644 tests/cases/compiler/separateCompilationUnspecifiedModule.ts create mode 100644 tests/cases/compiler/separateCompilationWithDeclarationFile.ts diff --git a/src/harness/harness.ts b/src/harness/harness.ts index f401f19da211b..55f09105246a0 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1062,6 +1062,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; @@ -1461,7 +1465,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[] { diff --git a/tests/baselines/reference/separateCompilationAmbientConstEnum.errors.txt b/tests/baselines/reference/separateCompilationAmbientConstEnum.errors.txt new file mode 100644 index 0000000000000..6ea2e445e294a --- /dev/null +++ b/tests/baselines/reference/separateCompilationAmbientConstEnum.errors.txt @@ -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; \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationAmbientConstEnum.js b/tests/baselines/reference/separateCompilationAmbientConstEnum.js new file mode 100644 index 0000000000000..5b3af0957e74c --- /dev/null +++ b/tests/baselines/reference/separateCompilationAmbientConstEnum.js @@ -0,0 +1,8 @@ +//// [separateCompilationAmbientConstEnum.ts] + + +declare const enum E { X = 1} +export var y; + +//// [separateCompilationAmbientConstEnum.js] +export var y; diff --git a/tests/baselines/reference/separateCompilationDeclaration.errors.txt b/tests/baselines/reference/separateCompilationDeclaration.errors.txt new file mode 100644 index 0000000000000..8951184584c18 --- /dev/null +++ b/tests/baselines/reference/separateCompilationDeclaration.errors.txt @@ -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; \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationDeclaration.js b/tests/baselines/reference/separateCompilationDeclaration.js new file mode 100644 index 0000000000000..33d64b088de1e --- /dev/null +++ b/tests/baselines/reference/separateCompilationDeclaration.js @@ -0,0 +1,10 @@ +//// [separateCompilationDeclaration.ts] + +export var x; + +//// [separateCompilationDeclaration.js] +export var x; + + +//// [separateCompilationDeclaration.d.ts] +export declare var x: any; diff --git a/tests/baselines/reference/separateCompilationES6.js b/tests/baselines/reference/separateCompilationES6.js new file mode 100644 index 0000000000000..cf05e5590a8c8 --- /dev/null +++ b/tests/baselines/reference/separateCompilationES6.js @@ -0,0 +1,5 @@ +//// [separateCompilationES6.ts] +export var x; + +//// [separateCompilationES6.js] +export var x; diff --git a/tests/baselines/reference/separateCompilationES6.types b/tests/baselines/reference/separateCompilationES6.types new file mode 100644 index 0000000000000..70381906800f1 --- /dev/null +++ b/tests/baselines/reference/separateCompilationES6.types @@ -0,0 +1,4 @@ +=== tests/cases/compiler/separateCompilationES6.ts === +export var x; +>x : any + diff --git a/tests/baselines/reference/separateCompilationNoEmitOnError.errors.txt b/tests/baselines/reference/separateCompilationNoEmitOnError.errors.txt new file mode 100644 index 0000000000000..61d4f2d6d9ed8 --- /dev/null +++ b/tests/baselines/reference/separateCompilationNoEmitOnError.errors.txt @@ -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; \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationNoExternalModule.errors.txt b/tests/baselines/reference/separateCompilationNoExternalModule.errors.txt new file mode 100644 index 0000000000000..269727584d485 --- /dev/null +++ b/tests/baselines/reference/separateCompilationNoExternalModule.errors.txt @@ -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. \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationNoExternalModule.js b/tests/baselines/reference/separateCompilationNoExternalModule.js new file mode 100644 index 0000000000000..9ddc8bdef2cf8 --- /dev/null +++ b/tests/baselines/reference/separateCompilationNoExternalModule.js @@ -0,0 +1,6 @@ +//// [separateCompilationNoExternalModule.ts] + +var x; + +//// [separateCompilationNoExternalModule.js] +var x; diff --git a/tests/baselines/reference/separateCompilationNonAmbientConstEnum.js b/tests/baselines/reference/separateCompilationNonAmbientConstEnum.js new file mode 100644 index 0000000000000..74096adca1fde --- /dev/null +++ b/tests/baselines/reference/separateCompilationNonAmbientConstEnum.js @@ -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; diff --git a/tests/baselines/reference/separateCompilationNonAmbientConstEnum.types b/tests/baselines/reference/separateCompilationNonAmbientConstEnum.types new file mode 100644 index 0000000000000..d444cbd14933d --- /dev/null +++ b/tests/baselines/reference/separateCompilationNonAmbientConstEnum.types @@ -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 + diff --git a/tests/baselines/reference/separateCompilationOut.errors.txt b/tests/baselines/reference/separateCompilationOut.errors.txt new file mode 100644 index 0000000000000..7c2631a71822b --- /dev/null +++ b/tests/baselines/reference/separateCompilationOut.errors.txt @@ -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. \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationOut.js b/tests/baselines/reference/separateCompilationOut.js new file mode 100644 index 0000000000000..67dd2dcfbfabc --- /dev/null +++ b/tests/baselines/reference/separateCompilationOut.js @@ -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; diff --git a/tests/baselines/reference/separateCompilationSourceMap.errors.txt b/tests/baselines/reference/separateCompilationSourceMap.errors.txt new file mode 100644 index 0000000000000..5274ef3921eaa --- /dev/null +++ b/tests/baselines/reference/separateCompilationSourceMap.errors.txt @@ -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; \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationSourceMap.js b/tests/baselines/reference/separateCompilationSourceMap.js new file mode 100644 index 0000000000000..1e8f141eb47a0 --- /dev/null +++ b/tests/baselines/reference/separateCompilationSourceMap.js @@ -0,0 +1,7 @@ +//// [separateCompilationSourceMap.ts] + +export var x; + +//// [separateCompilationSourceMap.js] +export var x; +//# sourceMappingURL=separateCompilationSourceMap.js.map \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationSourceMap.js.map b/tests/baselines/reference/separateCompilationSourceMap.js.map new file mode 100644 index 0000000000000..68c4e2c78dbb8 --- /dev/null +++ b/tests/baselines/reference/separateCompilationSourceMap.js.map @@ -0,0 +1,2 @@ +//// [separateCompilationSourceMap.js.map] +{"version":3,"file":"separateCompilationSourceMap.js","sourceRoot":"","sources":["separateCompilationSourceMap.ts"],"names":[],"mappings":"AACA,WAAW,CAAC,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationSourceMap.sourcemap.txt b/tests/baselines/reference/separateCompilationSourceMap.sourcemap.txt new file mode 100644 index 0000000000000..74e0d73d7e03a --- /dev/null +++ b/tests/baselines/reference/separateCompilationSourceMap.sourcemap.txt @@ -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 \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationSpecifiedModule.js b/tests/baselines/reference/separateCompilationSpecifiedModule.js new file mode 100644 index 0000000000000..5f3c7ceb39cad --- /dev/null +++ b/tests/baselines/reference/separateCompilationSpecifiedModule.js @@ -0,0 +1,5 @@ +//// [separateCompilationSpecifiedModule.ts] +export var x; + +//// [separateCompilationSpecifiedModule.js] +exports.x; diff --git a/tests/baselines/reference/separateCompilationSpecifiedModule.types b/tests/baselines/reference/separateCompilationSpecifiedModule.types new file mode 100644 index 0000000000000..497f63faf62c6 --- /dev/null +++ b/tests/baselines/reference/separateCompilationSpecifiedModule.types @@ -0,0 +1,4 @@ +=== tests/cases/compiler/separateCompilationSpecifiedModule.ts === +export var x; +>x : any + diff --git a/tests/baselines/reference/separateCompilationUnspecifiedModule.errors.txt b/tests/baselines/reference/separateCompilationUnspecifiedModule.errors.txt new file mode 100644 index 0000000000000..ab0fd7ffe9d5d --- /dev/null +++ b/tests/baselines/reference/separateCompilationUnspecifiedModule.errors.txt @@ -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; \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationUnspecifiedModule.js b/tests/baselines/reference/separateCompilationUnspecifiedModule.js new file mode 100644 index 0000000000000..0f2e5c71a8782 --- /dev/null +++ b/tests/baselines/reference/separateCompilationUnspecifiedModule.js @@ -0,0 +1,5 @@ +//// [separateCompilationUnspecifiedModule.ts] +export var x; + +//// [separateCompilationUnspecifiedModule.js] +exports.x; diff --git a/tests/baselines/reference/separateCompilationWithDeclarationFile.js b/tests/baselines/reference/separateCompilationWithDeclarationFile.js new file mode 100644 index 0000000000000..71d7ef4192946 --- /dev/null +++ b/tests/baselines/reference/separateCompilationWithDeclarationFile.js @@ -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; diff --git a/tests/baselines/reference/separateCompilationWithDeclarationFile.types b/tests/baselines/reference/separateCompilationWithDeclarationFile.types new file mode 100644 index 0000000000000..94adc5fa27e09 --- /dev/null +++ b/tests/baselines/reference/separateCompilationWithDeclarationFile.types @@ -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 + diff --git a/tests/cases/compiler/separateCompilationAmbientConstEnum.ts b/tests/cases/compiler/separateCompilationAmbientConstEnum.ts new file mode 100644 index 0000000000000..aaccfaaf02c00 --- /dev/null +++ b/tests/cases/compiler/separateCompilationAmbientConstEnum.ts @@ -0,0 +1,7 @@ +// @separateCompilation: true +// @target: es6 + +// @filename: file1.ts + +declare const enum E { X = 1} +export var y; \ No newline at end of file diff --git a/tests/cases/compiler/separateCompilationDeclaration.ts b/tests/cases/compiler/separateCompilationDeclaration.ts new file mode 100644 index 0000000000000..11003a1919329 --- /dev/null +++ b/tests/cases/compiler/separateCompilationDeclaration.ts @@ -0,0 +1,6 @@ +// @separateCompilation: true +// @declaration: true +// @target: es6 + +// @filename: file1.ts +export var x; \ No newline at end of file diff --git a/tests/cases/compiler/separateCompilationES6.ts b/tests/cases/compiler/separateCompilationES6.ts new file mode 100644 index 0000000000000..a2ac8c8d94ee1 --- /dev/null +++ b/tests/cases/compiler/separateCompilationES6.ts @@ -0,0 +1,4 @@ +// @separateCompilation: true +// @target: es6 +// @filename: file1.ts +export var x; \ No newline at end of file diff --git a/tests/cases/compiler/separateCompilationNoEmitOnError.ts b/tests/cases/compiler/separateCompilationNoEmitOnError.ts new file mode 100644 index 0000000000000..fe0f59199f661 --- /dev/null +++ b/tests/cases/compiler/separateCompilationNoEmitOnError.ts @@ -0,0 +1,6 @@ +// @separateCompilation: true +// @noEmitOnError:true +// @target: es6 + +// @filename: file1.ts +export var x; \ No newline at end of file diff --git a/tests/cases/compiler/separateCompilationNoExternalModule.ts b/tests/cases/compiler/separateCompilationNoExternalModule.ts new file mode 100644 index 0000000000000..e66ef27c00523 --- /dev/null +++ b/tests/cases/compiler/separateCompilationNoExternalModule.ts @@ -0,0 +1,5 @@ +// @separateCompilation: true +// @target: es6 + +// @filename: file1.ts +var x; \ No newline at end of file diff --git a/tests/cases/compiler/separateCompilationNonAmbientConstEnum.ts b/tests/cases/compiler/separateCompilationNonAmbientConstEnum.ts new file mode 100644 index 0000000000000..5f3054238d932 --- /dev/null +++ b/tests/cases/compiler/separateCompilationNonAmbientConstEnum.ts @@ -0,0 +1,7 @@ +// @separateCompilation: true +// @target: es6 + +// @filename: file1.ts +const enum E { X = 100 }; +var e = E.X; +export var x; \ No newline at end of file diff --git a/tests/cases/compiler/separateCompilationOut.ts b/tests/cases/compiler/separateCompilationOut.ts new file mode 100644 index 0000000000000..6c0a95f8ae54c --- /dev/null +++ b/tests/cases/compiler/separateCompilationOut.ts @@ -0,0 +1,8 @@ +// @separateCompilation: true +// @out:all.js +// @target: es6 + +// @filename: file1.ts +export var x; +// @filename: file2.ts +var y; \ No newline at end of file diff --git a/tests/cases/compiler/separateCompilationSourceMap.ts b/tests/cases/compiler/separateCompilationSourceMap.ts new file mode 100644 index 0000000000000..7becf7cbdaf9f --- /dev/null +++ b/tests/cases/compiler/separateCompilationSourceMap.ts @@ -0,0 +1,6 @@ +// @separateCompilation: true +// @sourceMap:sourcemap.map +// @target: es6 + +// @filename: file1.ts +export var x; \ No newline at end of file diff --git a/tests/cases/compiler/separateCompilationSpecifiedModule.ts b/tests/cases/compiler/separateCompilationSpecifiedModule.ts new file mode 100644 index 0000000000000..6ba3a0d3bf423 --- /dev/null +++ b/tests/cases/compiler/separateCompilationSpecifiedModule.ts @@ -0,0 +1,4 @@ +// @separateCompilation: true +// @module: commonjs +// @filename: file1.ts +export var x; \ No newline at end of file diff --git a/tests/cases/compiler/separateCompilationUnspecifiedModule.ts b/tests/cases/compiler/separateCompilationUnspecifiedModule.ts new file mode 100644 index 0000000000000..38a3fd82868b1 --- /dev/null +++ b/tests/cases/compiler/separateCompilationUnspecifiedModule.ts @@ -0,0 +1,3 @@ +// @separateCompilation: true +// @filename: file1.ts +export var x; \ No newline at end of file diff --git a/tests/cases/compiler/separateCompilationWithDeclarationFile.ts b/tests/cases/compiler/separateCompilationWithDeclarationFile.ts new file mode 100644 index 0000000000000..121db1702a5ce --- /dev/null +++ b/tests/cases/compiler/separateCompilationWithDeclarationFile.ts @@ -0,0 +1,8 @@ +// @separateCompilation: true +// @target: es6 + +// @filename: file1.d.ts +declare function foo(): void; + +// @filename: file1.ts +export var x; \ No newline at end of file From 1bdcaa3d43db6a44bed574f93de3d422bb47bf04 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 31 Mar 2015 13:54:33 -0700 Subject: [PATCH 9/9] added tests for import\export elision --- ...eCompilationImportExportElision.errors.txt | 28 ++++++++++++++ .../separateCompilationImportExportElision.js | 37 +++++++++++++++++++ .../separateCompilationImportExportElision.ts | 17 +++++++++ 3 files changed, 82 insertions(+) create mode 100644 tests/baselines/reference/separateCompilationImportExportElision.errors.txt create mode 100644 tests/baselines/reference/separateCompilationImportExportElision.js create mode 100644 tests/cases/compiler/separateCompilationImportExportElision.ts diff --git a/tests/baselines/reference/separateCompilationImportExportElision.errors.txt b/tests/baselines/reference/separateCompilationImportExportElision.errors.txt new file mode 100644 index 0000000000000..db418681e8394 --- /dev/null +++ b/tests/baselines/reference/separateCompilationImportExportElision.errors.txt @@ -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; \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationImportExportElision.js b/tests/baselines/reference/separateCompilationImportExportElision.js new file mode 100644 index 0000000000000..2d255798c3f41 --- /dev/null +++ b/tests/baselines/reference/separateCompilationImportExportElision.js @@ -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; diff --git a/tests/cases/compiler/separateCompilationImportExportElision.ts b/tests/cases/compiler/separateCompilationImportExportElision.ts new file mode 100644 index 0000000000000..d7af74a1a691f --- /dev/null +++ b/tests/cases/compiler/separateCompilationImportExportElision.ts @@ -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; \ No newline at end of file