Merge pull request #2840 from Microsoft/systemModule
Added support for emitting System.register modules
This commit is contained in:
commit
824808c1d8
|
@ -10689,9 +10689,15 @@ module ts {
|
|||
}
|
||||
checkExternalModuleExports(container);
|
||||
|
||||
if (node.isExportEquals && languageVersion >= ScriptTarget.ES6) {
|
||||
// export assignment is deprecated in es6 or above
|
||||
grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead);
|
||||
if (node.isExportEquals) {
|
||||
if (languageVersion >= ScriptTarget.ES6) {
|
||||
// export assignment is deprecated in es6 or above
|
||||
grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead);
|
||||
}
|
||||
else if (compilerOptions.module === ModuleKind.System) {
|
||||
// system modules does not support export assignment
|
||||
grammarErrorOnNode(node, Diagnostics.Export_assignment_is_not_supported_when_module_flag_is_system);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11514,9 +11520,11 @@ module ts {
|
|||
|
||||
function getExportNameSubstitution(symbol: Symbol, location: Node, getGeneratedNameForNode: (Node: Node) => string): string {
|
||||
if (isExternalModuleSymbol(symbol.parent)) {
|
||||
// If this is es6 or higher, just use the name of the export
|
||||
// 1. If this is es6 or higher, just use the name of the export
|
||||
// no need to qualify it.
|
||||
if (languageVersion >= ScriptTarget.ES6) {
|
||||
// 2. export mechanism for System modules is different from CJS\AMD
|
||||
// and it does not need qualifications for exports
|
||||
if (languageVersion >= ScriptTarget.ES6 || compilerOptions.module === ModuleKind.System) {
|
||||
return undefined;
|
||||
}
|
||||
return "exports." + unescapeIdentifier(symbol.name);
|
||||
|
@ -11877,6 +11885,15 @@ module ts {
|
|||
return !!resolveName(location, name, SymbolFlags.Value, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined);
|
||||
}
|
||||
|
||||
function getReferencedValueDeclaration(reference: Identifier): Declaration {
|
||||
Debug.assert(!nodeIsSynthesized(reference));
|
||||
let symbol =
|
||||
getNodeLinks(reference).resolvedSymbol ||
|
||||
resolveName(reference, reference.text, SymbolFlags.Value | SymbolFlags.Alias, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined);
|
||||
|
||||
return symbol && getExportSymbolOfValueSymbolIfExported(symbol).valueDeclaration;
|
||||
}
|
||||
|
||||
function getBlockScopedVariableId(n: Identifier): number {
|
||||
Debug.assert(!nodeIsSynthesized(n));
|
||||
|
||||
|
@ -11935,6 +11952,7 @@ module ts {
|
|||
resolvesToSomeValue,
|
||||
collectLinkedAliases,
|
||||
getBlockScopedVariableId,
|
||||
getReferencedValueDeclaration,
|
||||
serializeTypeOfNode,
|
||||
serializeParameterTypesOfNode,
|
||||
serializeReturnTypeOfNode,
|
||||
|
|
|
@ -51,11 +51,12 @@ module ts {
|
|||
type: {
|
||||
"commonjs": ModuleKind.CommonJS,
|
||||
"amd": ModuleKind.AMD,
|
||||
"umd": ModuleKind.UMD
|
||||
"system": ModuleKind.System,
|
||||
"umd": ModuleKind.UMD,
|
||||
},
|
||||
description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_or_umd,
|
||||
description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_or_umd,
|
||||
paramType: Diagnostics.KIND,
|
||||
error: Diagnostics.Argument_for_module_option_must_be_commonjs_amd_or_umd
|
||||
error: Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_or_umd
|
||||
},
|
||||
{
|
||||
name: "noEmit",
|
||||
|
|
|
@ -161,7 +161,7 @@ module ts {
|
|||
Line_terminator_not_permitted_before_arrow: { code: 1200, category: DiagnosticCategory.Error, key: "Line terminator not permitted before arrow." },
|
||||
Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead: { code: 1202, category: DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead." },
|
||||
Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead: { code: 1203, category: DiagnosticCategory.Error, key: "Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead." },
|
||||
Cannot_compile_external_modules_into_amd_commonjs_or_umd_when_targeting_ES6_or_higher: { code: 1204, category: DiagnosticCategory.Error, key: "Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher." },
|
||||
Cannot_compile_external_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher: { code: 1204, category: DiagnosticCategory.Error, key: "Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher." },
|
||||
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." },
|
||||
|
@ -175,6 +175,7 @@ module ts {
|
|||
Type_expected_0_is_a_reserved_word_in_strict_mode: { code: 1215, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode" },
|
||||
Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1216, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." },
|
||||
Type_expected_0_is_a_reserved_word_in_strict_mode_Module_is_automatically_in_strict_mode: { code: 1217, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Module is automatically in strict mode." },
|
||||
Export_assignment_is_not_supported_when_module_flag_is_system: { code: 1218, category: DiagnosticCategory.Error, key: "Export assignment is not supported when '--module' flag is 'system'." },
|
||||
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." },
|
||||
|
@ -464,7 +465,7 @@ module ts {
|
|||
Do_not_emit_comments_to_output: { code: 6009, category: DiagnosticCategory.Message, key: "Do not emit comments to output." },
|
||||
Do_not_emit_outputs: { code: 6010, category: DiagnosticCategory.Message, key: "Do not emit outputs." },
|
||||
Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" },
|
||||
Specify_module_code_generation_Colon_commonjs_amd_or_umd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs', 'amd', or 'umd'." },
|
||||
Specify_module_code_generation_Colon_commonjs_amd_system_or_umd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs', 'amd', 'system' or 'umd'" },
|
||||
Print_this_message: { code: 6017, category: DiagnosticCategory.Message, key: "Print this message." },
|
||||
Print_the_compiler_s_version: { code: 6019, category: DiagnosticCategory.Message, key: "Print the compiler's version." },
|
||||
Compile_the_project_in_the_given_directory: { code: 6020, category: DiagnosticCategory.Message, key: "Compile the project in the given directory." },
|
||||
|
@ -485,7 +486,7 @@ module ts {
|
|||
Generates_corresponding_map_file: { code: 6043, category: DiagnosticCategory.Message, key: "Generates corresponding '.map' file." },
|
||||
Compiler_option_0_expects_an_argument: { code: 6044, category: DiagnosticCategory.Error, key: "Compiler option '{0}' expects an argument." },
|
||||
Unterminated_quoted_string_in_response_file_0: { code: 6045, category: DiagnosticCategory.Error, key: "Unterminated quoted string in response file '{0}'." },
|
||||
Argument_for_module_option_must_be_commonjs_amd_or_umd: { code: 6046, category: DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs', 'amd', or 'umd'." },
|
||||
Argument_for_module_option_must_be_commonjs_amd_system_or_umd: { code: 6046, category: DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs', 'amd', 'system' or 'umd'." },
|
||||
Argument_for_target_option_must_be_ES3_ES5_or_ES6: { code: 6047, category: DiagnosticCategory.Error, key: "Argument for '--target' option must be 'ES3', 'ES5', or 'ES6'." },
|
||||
Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1: { code: 6048, category: DiagnosticCategory.Error, key: "Locale must be of the form <language> or <language>-<territory>. For example '{0}' or '{1}'." },
|
||||
Unsupported_locale_0: { code: 6049, category: DiagnosticCategory.Error, key: "Unsupported locale '{0}'." },
|
||||
|
|
|
@ -631,7 +631,7 @@
|
|||
"category": "Error",
|
||||
"code": 1203
|
||||
},
|
||||
"Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.": {
|
||||
"Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.": {
|
||||
"category": "Error",
|
||||
"code": 1204
|
||||
},
|
||||
|
@ -687,6 +687,10 @@
|
|||
"category": "Error",
|
||||
"code": 1217
|
||||
},
|
||||
"Export assignment is not supported when '--module' flag is 'system'.": {
|
||||
"category": "Error",
|
||||
"code": 1218
|
||||
},
|
||||
"Duplicate identifier '{0}'.": {
|
||||
"category": "Error",
|
||||
"code": 2300
|
||||
|
@ -1844,7 +1848,7 @@
|
|||
"category": "Message",
|
||||
"code": 6015
|
||||
},
|
||||
"Specify module code generation: 'commonjs', 'amd', or 'umd'.": {
|
||||
"Specify module code generation: 'commonjs', 'amd', 'system' or 'umd'": {
|
||||
"category": "Message",
|
||||
"code": 6016
|
||||
},
|
||||
|
@ -1928,7 +1932,7 @@
|
|||
"category": "Error",
|
||||
"code": 6045
|
||||
},
|
||||
"Argument for '--module' option must be 'commonjs', 'amd', or 'umd'.": {
|
||||
"Argument for '--module' option must be 'commonjs', 'amd', 'system' or 'umd'.": {
|
||||
"category": "Error",
|
||||
"code": 6046
|
||||
},
|
||||
|
|
5229
src/compiler/emitter.js
Normal file
5229
src/compiler/emitter.js
Normal file
File diff suppressed because it is too large
Load diff
|
@ -122,6 +122,13 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
|
|||
let decreaseIndent = writer.decreaseIndent;
|
||||
|
||||
let currentSourceFile: SourceFile;
|
||||
// name of an exporter function if file is a System external module
|
||||
// System.register([...], function (<exporter>) {...})
|
||||
// exporting in System modules looks like:
|
||||
// export var x; ... x = 1
|
||||
// =>
|
||||
// var x;... exporter("x", x = 1)
|
||||
let exportFunctionForFile: string;
|
||||
|
||||
let generatedNameSet: Map<string> = {};
|
||||
let nodeToGeneratedName: string[] = [];
|
||||
|
@ -196,6 +203,7 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
|
|||
|
||||
function emitSourceFile(sourceFile: SourceFile): void {
|
||||
currentSourceFile = sourceFile;
|
||||
exportFunctionForFile = undefined;
|
||||
emit(sourceFile);
|
||||
}
|
||||
|
||||
|
@ -1142,7 +1150,7 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
|
|||
if (!computedPropertyNamesToGeneratedNames) {
|
||||
computedPropertyNamesToGeneratedNames = [];
|
||||
}
|
||||
|
||||
|
||||
let generatedName = computedPropertyNamesToGeneratedNames[getNodeId(node)];
|
||||
if (generatedName) {
|
||||
// we have already generated a variable for this node, write that value instead.
|
||||
|
@ -1929,7 +1937,35 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
|
|||
emit(node.expression);
|
||||
}
|
||||
|
||||
function isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node: Node): boolean {
|
||||
if (!isCurrentFileSystemExternalModule() || node.kind !== SyntaxKind.Identifier || nodeIsSynthesized(node)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const isVariableDeclarationOrBindingElement =
|
||||
node.parent && (node.parent.kind === SyntaxKind.VariableDeclaration || node.parent.kind === SyntaxKind.BindingElement);
|
||||
|
||||
const targetDeclaration =
|
||||
isVariableDeclarationOrBindingElement
|
||||
? <Declaration>node.parent
|
||||
: resolver.getReferencedValueDeclaration(<Identifier>node);
|
||||
|
||||
return isSourceFileLevelDeclarationInSystemJsModule(targetDeclaration, /*isExported*/ true);
|
||||
}
|
||||
|
||||
function emitPrefixUnaryExpression(node: PrefixUnaryExpression) {
|
||||
const exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand);
|
||||
|
||||
if (exportChanged) {
|
||||
// emit
|
||||
// ++x
|
||||
// as
|
||||
// exports('x', ++x)
|
||||
write(`${exportFunctionForFile}("`);
|
||||
emitNodeWithoutSourceMap(node.operand);
|
||||
write(`", `);
|
||||
}
|
||||
|
||||
write(tokenToString(node.operator));
|
||||
// In some cases, we need to emit a space between the operator and the operand. One obvious case
|
||||
// is when the operator is an identifier, like delete or typeof. We also need to do this for plus
|
||||
|
@ -1953,11 +1989,69 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
|
|||
}
|
||||
}
|
||||
emit(node.operand);
|
||||
|
||||
if (exportChanged) {
|
||||
write(")");
|
||||
}
|
||||
}
|
||||
|
||||
function emitPostfixUnaryExpression(node: PostfixUnaryExpression) {
|
||||
emit(node.operand);
|
||||
write(tokenToString(node.operator));
|
||||
const exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand);
|
||||
if (exportChanged) {
|
||||
// export function returns the value that was passes as the second argument
|
||||
// however for postfix unary expressions result value should be the value before modification.
|
||||
// emit 'x++' as '(export('x', ++x) - 1)' and 'x--' as '(export('x', --x) + 1)'
|
||||
write(`(${exportFunctionForFile}("`);
|
||||
emitNodeWithoutSourceMap(node.operand);
|
||||
write(`", `);
|
||||
|
||||
write(tokenToString(node.operator));
|
||||
emit(node.operand);
|
||||
|
||||
if (node.operator === SyntaxKind.PlusPlusToken) {
|
||||
write(") - 1)");
|
||||
}
|
||||
else {
|
||||
write(") + 1)");
|
||||
}
|
||||
}
|
||||
else {
|
||||
emit(node.operand);
|
||||
write(tokenToString(node.operator));
|
||||
}
|
||||
}
|
||||
|
||||
function shouldHoistDeclarationInSystemJsModule(node: Node): boolean {
|
||||
return isSourceFileLevelDeclarationInSystemJsModule(node, /*isExported*/ false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks if given node is a source file level declaration (not nested in module/function).
|
||||
* If 'isExported' is true - then declaration must also be exported.
|
||||
* This function is used in two cases:
|
||||
* - check if node is a exported source file level value to determine
|
||||
* if we should also export the value after its it changed
|
||||
* - check if node is a source level declaration to emit it differently,
|
||||
* i.e non-exported variable statement 'var x = 1' is hoisted so
|
||||
* we we emit variable statement 'var' should be dropped.
|
||||
*/
|
||||
function isSourceFileLevelDeclarationInSystemJsModule(node: Node, isExported: boolean): boolean {
|
||||
if (!node || languageVersion >= ScriptTarget.ES6 || !isCurrentFileSystemExternalModule()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let current: Node = node;
|
||||
while (current) {
|
||||
if (current.kind === SyntaxKind.SourceFile) {
|
||||
return !isExported || ((getCombinedNodeFlags(node) & NodeFlags.Export) !== 0)
|
||||
}
|
||||
else if (isFunctionLike(current) || current.kind === SyntaxKind.ModuleBlock) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
current = current.parent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function emitBinaryExpression(node: BinaryExpression) {
|
||||
|
@ -1966,12 +2060,26 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
|
|||
emitDestructuring(node, node.parent.kind === SyntaxKind.ExpressionStatement);
|
||||
}
|
||||
else {
|
||||
const exportChanged =
|
||||
node.operatorToken.kind >= SyntaxKind.FirstAssignment &&
|
||||
node.operatorToken.kind <= SyntaxKind.LastAssignment &&
|
||||
isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.left);
|
||||
|
||||
if (exportChanged) {
|
||||
// emit assignment 'x <op> y' as 'exports("x", x <op> y)'
|
||||
write(`${exportFunctionForFile}("`);
|
||||
emitNodeWithoutSourceMap(node.left);
|
||||
write(`", `);
|
||||
}
|
||||
emit(node.left);
|
||||
let indentedBeforeOperator = indentIfOnDifferentLines(node, node.left, node.operatorToken, node.operatorToken.kind !== SyntaxKind.CommaToken ? " " : undefined);
|
||||
write(tokenToString(node.operatorToken.kind));
|
||||
let indentedAfterOperator = indentIfOnDifferentLines(node, node.operatorToken, node.right, " ");
|
||||
emit(node.right);
|
||||
decreaseIndentIf(indentedBeforeOperator, indentedAfterOperator);
|
||||
if (exportChanged) {
|
||||
write(")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2097,7 +2205,16 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
|
|||
emitEmbeddedStatement(node.statement);
|
||||
}
|
||||
|
||||
function emitStartOfVariableDeclarationList(decl: Node, startPos?: number): void {
|
||||
/* Returns true if start of variable declaration list was emitted.
|
||||
* Return false if nothing was written - this can happen for source file level variable declarations
|
||||
* in system modules - such variable declarations are hoisted.
|
||||
*/
|
||||
function tryEmitStartOfVariableDeclarationList(decl: VariableDeclarationList, startPos?: number): boolean {
|
||||
if (shouldHoistVariable(decl, /*checkIfSourceFileLevelDecl*/ true)) {
|
||||
// variables in variable declaration list were already hoisted
|
||||
return false;
|
||||
}
|
||||
|
||||
let tokenKind = SyntaxKind.VarKeyword;
|
||||
if (decl && languageVersion >= ScriptTarget.ES6) {
|
||||
if (isLet(decl)) {
|
||||
|
@ -2110,17 +2227,43 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
|
|||
|
||||
if (startPos !== undefined) {
|
||||
emitToken(tokenKind, startPos);
|
||||
write(" ")
|
||||
}
|
||||
else {
|
||||
switch (tokenKind) {
|
||||
case SyntaxKind.VarKeyword:
|
||||
return write("var ");
|
||||
write("var ");
|
||||
break;
|
||||
case SyntaxKind.LetKeyword:
|
||||
return write("let ");
|
||||
write("let ");
|
||||
break;
|
||||
case SyntaxKind.ConstKeyword:
|
||||
return write("const ");
|
||||
write("const ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function emitVariableDeclarationListSkippingUninitializedEntries(list: VariableDeclarationList): boolean {
|
||||
let started = false;
|
||||
for (let decl of list.declarations) {
|
||||
if (!decl.initializer) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!started) {
|
||||
started = true;
|
||||
}
|
||||
else {
|
||||
write(", ");
|
||||
}
|
||||
|
||||
emit(decl);
|
||||
}
|
||||
|
||||
return started;
|
||||
}
|
||||
|
||||
function emitForStatement(node: ForStatement) {
|
||||
|
@ -2129,10 +2272,13 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
|
|||
endPos = emitToken(SyntaxKind.OpenParenToken, endPos);
|
||||
if (node.initializer && node.initializer.kind === SyntaxKind.VariableDeclarationList) {
|
||||
let variableDeclarationList = <VariableDeclarationList>node.initializer;
|
||||
let declarations = variableDeclarationList.declarations;
|
||||
emitStartOfVariableDeclarationList(declarations[0], endPos);
|
||||
write(" ");
|
||||
emitCommaList(declarations);
|
||||
let startIsEmitted = tryEmitStartOfVariableDeclarationList(variableDeclarationList, endPos);
|
||||
if (startIsEmitted) {
|
||||
emitCommaList(variableDeclarationList.declarations);
|
||||
}
|
||||
else {
|
||||
emitVariableDeclarationListSkippingUninitializedEntries(variableDeclarationList);
|
||||
}
|
||||
}
|
||||
else if (node.initializer) {
|
||||
emit(node.initializer);
|
||||
|
@ -2156,10 +2302,8 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
|
|||
if (node.initializer.kind === SyntaxKind.VariableDeclarationList) {
|
||||
let variableDeclarationList = <VariableDeclarationList>node.initializer;
|
||||
if (variableDeclarationList.declarations.length >= 1) {
|
||||
let decl = variableDeclarationList.declarations[0];
|
||||
emitStartOfVariableDeclarationList(decl, endPos);
|
||||
write(" ");
|
||||
emit(decl);
|
||||
tryEmitStartOfVariableDeclarationList(variableDeclarationList, endPos);
|
||||
emit(variableDeclarationList.declarations[0]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -2453,7 +2597,7 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
|
|||
write(getGeneratedNameForNode(container));
|
||||
write(".");
|
||||
}
|
||||
else if (languageVersion < ScriptTarget.ES6) {
|
||||
else if (languageVersion < ScriptTarget.ES6 && compilerOptions.module !== ModuleKind.System) {
|
||||
write("exports.");
|
||||
}
|
||||
}
|
||||
|
@ -2473,18 +2617,35 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
|
|||
if (node.flags & NodeFlags.Export) {
|
||||
writeLine();
|
||||
emitStart(node);
|
||||
if (node.flags & NodeFlags.Default) {
|
||||
if (languageVersion === ScriptTarget.ES3) {
|
||||
write("exports[\"default\"]");
|
||||
} else {
|
||||
write("exports.default");
|
||||
|
||||
if (compilerOptions.module === ModuleKind.System) {
|
||||
// emit export default <smth> as
|
||||
// export("default", <smth>)
|
||||
write(`${exportFunctionForFile}("`);
|
||||
if (node.flags & NodeFlags.Default) {
|
||||
write("default");
|
||||
}
|
||||
else {
|
||||
emitNodeWithoutSourceMap(node.name);
|
||||
}
|
||||
write(`", `);
|
||||
emitDeclarationName(node);
|
||||
write(")")
|
||||
}
|
||||
else {
|
||||
emitModuleMemberName(node);
|
||||
if (node.flags & NodeFlags.Default) {
|
||||
if (languageVersion === ScriptTarget.ES3) {
|
||||
write("exports[\"default\"]");
|
||||
} else {
|
||||
write("exports.default");
|
||||
}
|
||||
}
|
||||
else {
|
||||
emitModuleMemberName(node);
|
||||
}
|
||||
write(" = ");
|
||||
emitDeclarationName(node);
|
||||
}
|
||||
write(" = ");
|
||||
emitDeclarationName(node);
|
||||
emitEnd(node);
|
||||
write(";");
|
||||
}
|
||||
|
@ -2495,12 +2656,21 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
|
|||
for (let specifier of exportSpecifiers[name.text]) {
|
||||
writeLine();
|
||||
emitStart(specifier.name);
|
||||
emitContainingModuleName(specifier);
|
||||
write(".");
|
||||
emitNodeWithoutSourceMap(specifier.name);
|
||||
emitEnd(specifier.name);
|
||||
write(" = ");
|
||||
emitExpressionIdentifier(name);
|
||||
if (compilerOptions.module === ModuleKind.System) {
|
||||
write(`${exportFunctionForFile}("`);
|
||||
emitNodeWithoutSourceMap(specifier.name);
|
||||
write(`", `);
|
||||
emitExpressionIdentifier(name);
|
||||
write(")")
|
||||
}
|
||||
else {
|
||||
emitContainingModuleName(specifier);
|
||||
write(".");
|
||||
emitNodeWithoutSourceMap(specifier.name);
|
||||
emitEnd(specifier.name);
|
||||
write(" = ");
|
||||
emitExpressionIdentifier(name);
|
||||
}
|
||||
write(";");
|
||||
}
|
||||
}
|
||||
|
@ -2508,9 +2678,21 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
|
|||
|
||||
function emitDestructuring(root: BinaryExpression | VariableDeclaration | ParameterDeclaration, isAssignmentExpressionStatement: boolean, value?: Expression) {
|
||||
let emitCount = 0;
|
||||
|
||||
// An exported declaration is actually emitted as an assignment (to a property on the module object), so
|
||||
// temporary variables in an exported declaration need to have real declarations elsewhere
|
||||
let isDeclaration = (root.kind === SyntaxKind.VariableDeclaration && !(getCombinedNodeFlags(root) & NodeFlags.Export)) || root.kind === SyntaxKind.Parameter;
|
||||
// Also temporary variables should be explicitly allocated for source level declarations when module target is system
|
||||
// because actual variable declarations are hoisted
|
||||
let canDefineTempVariablesInPlace = false;
|
||||
if (root.kind === SyntaxKind.VariableDeclaration) {
|
||||
let isExported = getCombinedNodeFlags(root) & NodeFlags.Export;
|
||||
let isSourceLevelForSystemModuleKind = shouldHoistDeclarationInSystemJsModule(root);
|
||||
canDefineTempVariablesInPlace = !isExported && !isSourceLevelForSystemModuleKind;
|
||||
}
|
||||
else if (root.kind === SyntaxKind.Parameter) {
|
||||
canDefineTempVariablesInPlace = true;
|
||||
}
|
||||
|
||||
if (root.kind === SyntaxKind.BinaryExpression) {
|
||||
emitAssignmentExpression(<BinaryExpression>root);
|
||||
}
|
||||
|
@ -2525,20 +2707,37 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
|
|||
}
|
||||
|
||||
renameNonTopLevelLetAndConst(name);
|
||||
if (name.parent && (name.parent.kind === SyntaxKind.VariableDeclaration || name.parent.kind === SyntaxKind.BindingElement)) {
|
||||
|
||||
const isVariableDeclarationOrBindingElement =
|
||||
name.parent && (name.parent.kind === SyntaxKind.VariableDeclaration || name.parent.kind === SyntaxKind.BindingElement);
|
||||
|
||||
let exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(name);
|
||||
|
||||
if (exportChanged) {
|
||||
write(`${exportFunctionForFile}("`);
|
||||
emitNodeWithoutSourceMap(name);
|
||||
write(`", `);
|
||||
}
|
||||
|
||||
if (isVariableDeclarationOrBindingElement) {
|
||||
emitModuleMemberName(<Declaration>name.parent);
|
||||
}
|
||||
else {
|
||||
emit(name);
|
||||
}
|
||||
|
||||
write(" = ");
|
||||
emit(value);
|
||||
|
||||
if (exportChanged) {
|
||||
write(")");
|
||||
}
|
||||
}
|
||||
|
||||
function ensureIdentifier(expr: Expression): Expression {
|
||||
if (expr.kind !== SyntaxKind.Identifier) {
|
||||
let identifier = createTempVariable(TempFlags.Auto);
|
||||
if (!isDeclaration) {
|
||||
if (!canDefineTempVariablesInPlace) {
|
||||
recordTempDeclaration(identifier);
|
||||
}
|
||||
emitAssignment(identifier, expr);
|
||||
|
@ -2718,7 +2917,6 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
|
|||
}
|
||||
else {
|
||||
renameNonTopLevelLetAndConst(<Identifier>node.name);
|
||||
emitModuleMemberName(node);
|
||||
|
||||
let initializer = node.initializer;
|
||||
if (!initializer && languageVersion < ScriptTarget.ES6) {
|
||||
|
@ -2741,7 +2939,20 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
|
|||
}
|
||||
}
|
||||
|
||||
let exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.name);
|
||||
|
||||
if (exportChanged) {
|
||||
write(`${exportFunctionForFile}("`);
|
||||
emitNodeWithoutSourceMap(node.name);
|
||||
write(`", `);
|
||||
}
|
||||
|
||||
emitModuleMemberName(node);
|
||||
emitOptional(" = ", initializer);
|
||||
|
||||
if (exportChanged) {
|
||||
write(")")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2821,16 +3032,25 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
|
|||
}
|
||||
|
||||
function emitVariableStatement(node: VariableStatement) {
|
||||
let startIsEmitted = true;
|
||||
if (!(node.flags & NodeFlags.Export)) {
|
||||
emitStartOfVariableDeclarationList(node.declarationList);
|
||||
startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList);
|
||||
}
|
||||
else if (isES6ExportedDeclaration(node)) {
|
||||
// Exported ES6 module member
|
||||
write("export ");
|
||||
emitStartOfVariableDeclarationList(node.declarationList);
|
||||
startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList);
|
||||
}
|
||||
if (startIsEmitted) {
|
||||
emitCommaList(node.declarationList.declarations);
|
||||
write(";");
|
||||
}
|
||||
else {
|
||||
let atLeastOneItem = emitVariableDeclarationListSkippingUninitializedEntries(node.declarationList);
|
||||
if (atLeastOneItem) {
|
||||
write(";");
|
||||
}
|
||||
}
|
||||
emitCommaList(node.declarationList.declarations);
|
||||
write(";");
|
||||
if (languageVersion < ScriptTarget.ES6 && node.parent === currentSourceFile) {
|
||||
forEach(node.declarationList.declarations, emitExportVariableAssignments);
|
||||
}
|
||||
|
@ -3721,7 +3941,10 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
|
|||
|
||||
function emitClassLikeDeclarationBelowES6(node: ClassLikeDeclaration) {
|
||||
if (node.kind === SyntaxKind.ClassDeclaration) {
|
||||
write("var ");
|
||||
// source file level classes in system modules are hoisted so 'var's for them are already defined
|
||||
if (!shouldHoistDeclarationInSystemJsModule(node)) {
|
||||
write("var ");
|
||||
}
|
||||
emitDeclarationName(node);
|
||||
write(" = ");
|
||||
}
|
||||
|
@ -4231,13 +4454,14 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
|
|||
if (!shouldEmit) {
|
||||
return emitOnlyPinnedOrTripleSlashComments(node);
|
||||
}
|
||||
let hoistedInDeclarationScope = shouldHoistDeclarationInSystemJsModule(node);
|
||||
let emitVarForModule = !hoistedInDeclarationScope && !isModuleMergedWithES6Class(node);
|
||||
|
||||
if (!isModuleMergedWithES6Class(node)) {
|
||||
if (emitVarForModule) {
|
||||
emitStart(node);
|
||||
if (isES6ExportedDeclaration(node)) {
|
||||
write("export ");
|
||||
}
|
||||
|
||||
write("var ");
|
||||
emit(node.name);
|
||||
write(";");
|
||||
|
@ -4287,6 +4511,14 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
|
|||
write(" = {}));");
|
||||
emitEnd(node);
|
||||
if (!isES6ExportedDeclaration(node) && node.name.kind === SyntaxKind.Identifier && node.parent === currentSourceFile) {
|
||||
if (compilerOptions.module === ModuleKind.System && (node.flags & NodeFlags.Export)) {
|
||||
writeLine();
|
||||
write(`${exportFunctionForFile}("`);
|
||||
emitDeclarationName(node);
|
||||
write(`", `);
|
||||
emitDeclarationName(node);
|
||||
write(")");
|
||||
}
|
||||
emitExportMemberAssignments(<Identifier>node.name);
|
||||
}
|
||||
}
|
||||
|
@ -4463,6 +4695,8 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
|
|||
}
|
||||
|
||||
function emitExportDeclaration(node: ExportDeclaration) {
|
||||
Debug.assert(compilerOptions.module !== ModuleKind.System);
|
||||
|
||||
if (languageVersion < ScriptTarget.ES6) {
|
||||
if (node.moduleSpecifier && (!node.exportClause || resolver.isValueAliasDeclaration(node))) {
|
||||
emitStart(node);
|
||||
|
@ -4568,13 +4802,20 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
|
|||
else {
|
||||
writeLine();
|
||||
emitStart(node);
|
||||
emitContainingModuleName(node);
|
||||
if (languageVersion === ScriptTarget.ES3) {
|
||||
write("[\"default\"] = ");
|
||||
} else {
|
||||
write(".default = ");
|
||||
if (compilerOptions.module === ModuleKind.System) {
|
||||
write(`${exportFunctionForFile}("default",`);
|
||||
emit(node.expression);
|
||||
write(")");
|
||||
}
|
||||
else {
|
||||
emitContainingModuleName(node);
|
||||
if (languageVersion === ScriptTarget.ES3) {
|
||||
write("[\"default\"] = ");
|
||||
} else {
|
||||
write(".default = ");
|
||||
}
|
||||
emit(node.expression);
|
||||
}
|
||||
emit(node.expression);
|
||||
write(";");
|
||||
emitEnd(node);
|
||||
}
|
||||
|
@ -4647,6 +4888,388 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
|
|||
}
|
||||
}
|
||||
|
||||
function getLocalNameForExternalImport(importNode: ImportDeclaration | ExportDeclaration | ImportEqualsDeclaration): string {
|
||||
let namespaceDeclaration = getNamespaceDeclarationNode(importNode);
|
||||
if (namespaceDeclaration && !isDefaultImport(importNode)) {
|
||||
return getSourceTextOfNodeFromSourceFile(currentSourceFile, namespaceDeclaration.name);
|
||||
}
|
||||
else {
|
||||
return getGeneratedNameForNode(<ImportDeclaration | ExportDeclaration>importNode);
|
||||
}
|
||||
}
|
||||
|
||||
function getExternalModuleNameText(importNode: ImportDeclaration | ExportDeclaration | ImportEqualsDeclaration): string {
|
||||
let moduleName = getExternalModuleName(importNode);
|
||||
if (moduleName.kind === SyntaxKind.StringLiteral) {
|
||||
return getLiteralText(<LiteralExpression>moduleName);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function emitVariableDeclarationsForImports(): void {
|
||||
if (externalImports.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
writeLine();
|
||||
let started = false;
|
||||
for (let importNode of externalImports) {
|
||||
// do not create variable declaration for exports and imports that lack import clause
|
||||
let skipNode =
|
||||
importNode.kind === SyntaxKind.ExportDeclaration ||
|
||||
(importNode.kind === SyntaxKind.ImportDeclaration && !(<ImportDeclaration>importNode).importClause)
|
||||
|
||||
if (skipNode) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!started) {
|
||||
write("var ");
|
||||
started = true;
|
||||
}
|
||||
else {
|
||||
write(", ");
|
||||
}
|
||||
|
||||
write(getLocalNameForExternalImport(importNode));
|
||||
}
|
||||
|
||||
if (started) {
|
||||
write(";");
|
||||
}
|
||||
}
|
||||
|
||||
function hoistTopLevelVariableAndFunctionDeclarations(node: SourceFile): void {
|
||||
// per ES6 spec:
|
||||
// 15.2.1.16.4 ModuleDeclarationInstantiation() Concrete Method
|
||||
// - var declarations are initialized to undefined - 14.a.ii
|
||||
// - function/generator declarations are instantiated - 16.a.iv
|
||||
// this means that after module is instantiated but before its evaluation
|
||||
// exported functions are already accessible at import sites
|
||||
// in theory we should hoist only exported functions and its dependencies
|
||||
// in practice to simplify things we'll hoist all source level functions and variable declaration
|
||||
// including variables declarations for module and class declarations
|
||||
let hoistedVars: (Identifier | ClassDeclaration | ModuleDeclaration)[];
|
||||
let hoistedFunctionDeclarations: FunctionDeclaration[];
|
||||
|
||||
visit(node);
|
||||
|
||||
if (hoistedVars) {
|
||||
writeLine();
|
||||
write("var ");
|
||||
for (let i = 0; i < hoistedVars.length; ++i) {
|
||||
let local = hoistedVars[i];
|
||||
if (i !== 0) {
|
||||
write(", ");
|
||||
}
|
||||
if (local.kind === SyntaxKind.ClassDeclaration || local.kind === SyntaxKind.ModuleDeclaration) {
|
||||
emitDeclarationName(<ClassDeclaration | ModuleDeclaration>local);
|
||||
}
|
||||
else {
|
||||
emit(local);
|
||||
}
|
||||
}
|
||||
write(";")
|
||||
}
|
||||
|
||||
if (hoistedFunctionDeclarations) {
|
||||
for (let f of hoistedFunctionDeclarations) {
|
||||
writeLine();
|
||||
emit(f);
|
||||
}
|
||||
}
|
||||
|
||||
function visit(node: Node): void {
|
||||
if (node.kind === SyntaxKind.FunctionDeclaration) {
|
||||
if (!hoistedFunctionDeclarations) {
|
||||
hoistedFunctionDeclarations = [];
|
||||
}
|
||||
|
||||
hoistedFunctionDeclarations.push(<FunctionDeclaration>node);
|
||||
return;
|
||||
}
|
||||
|
||||
if (node.kind === SyntaxKind.ClassDeclaration) {
|
||||
// TODO: rename block scoped classes
|
||||
if (!hoistedVars) {
|
||||
hoistedVars = [];
|
||||
}
|
||||
|
||||
hoistedVars.push(<ClassDeclaration>node);
|
||||
return;
|
||||
}
|
||||
|
||||
if (node.kind === SyntaxKind.ModuleDeclaration && shouldEmitModuleDeclaration(<ModuleDeclaration>node)) {
|
||||
if (!hoistedVars) {
|
||||
hoistedVars = [];
|
||||
}
|
||||
|
||||
hoistedVars.push(<ModuleDeclaration>node);
|
||||
return;
|
||||
}
|
||||
|
||||
if (node.kind === SyntaxKind.VariableDeclaration || node.kind === SyntaxKind.BindingElement) {
|
||||
if (shouldHoistVariable(<VariableDeclaration | BindingElement>node, /*checkIfSourceFileLevelDecl*/ false)) {
|
||||
let name = (<VariableDeclaration | BindingElement>node).name;
|
||||
if (name.kind === SyntaxKind.Identifier) {
|
||||
if (!hoistedVars) {
|
||||
hoistedVars = [];
|
||||
}
|
||||
|
||||
hoistedVars.push(<Identifier>name);
|
||||
}
|
||||
else {
|
||||
forEachChild(name, visit);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (isBindingPattern(node)) {
|
||||
forEach((<BindingPattern>node).elements, visit);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isDeclaration(node)) {
|
||||
forEachChild(node, visit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function shouldHoistVariable(node: VariableDeclaration | VariableDeclarationList | BindingElement, checkIfSourceFileLevelDecl: boolean): boolean {
|
||||
if (checkIfSourceFileLevelDecl && !shouldHoistDeclarationInSystemJsModule(node)) {
|
||||
return false;
|
||||
}
|
||||
// hoist variable if
|
||||
// - it is not block scoped
|
||||
// - it is top level block scoped
|
||||
// if block scoped variables are nested in some another block then
|
||||
// no other functions can use them except ones that are defined at least in the same block
|
||||
return (getCombinedNodeFlags(node) & NodeFlags.BlockScoped) === 0 ||
|
||||
getEnclosingBlockScopeContainer(node).kind === SyntaxKind.SourceFile;
|
||||
}
|
||||
|
||||
function isCurrentFileSystemExternalModule() {
|
||||
return compilerOptions.module === ModuleKind.System && isExternalModule(currentSourceFile);
|
||||
}
|
||||
|
||||
function emitSystemModuleBody(node: SourceFile, startIndex: number): void {
|
||||
// shape of the body in system modules:
|
||||
// function (exports) {
|
||||
// <list of local aliases for imports>
|
||||
// <hoisted function declarations>
|
||||
// <hoisted variable declarations>
|
||||
// return {
|
||||
// setters: [
|
||||
// <list of setter function for imports>
|
||||
// ],
|
||||
// execute: function() {
|
||||
// <module statements>
|
||||
// }
|
||||
// }
|
||||
// <temp declarations>
|
||||
// }
|
||||
// I.e:
|
||||
// import {x} from 'file1'
|
||||
// var y = 1;
|
||||
// export function foo() { return y + x(); }
|
||||
// console.log(y);
|
||||
// will be transformed to
|
||||
// function(exports) {
|
||||
// var file1; // local alias
|
||||
// var y;
|
||||
// function foo() { return y + file1.x(); }
|
||||
// exports("foo", foo);
|
||||
// return {
|
||||
// setters: [
|
||||
// function(v) { file1 = v }
|
||||
// ],
|
||||
// execute(): function() {
|
||||
// y = 1;
|
||||
// console.log(y);
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
emitVariableDeclarationsForImports();
|
||||
writeLine();
|
||||
hoistTopLevelVariableAndFunctionDeclarations(node);
|
||||
writeLine();
|
||||
write("return {");
|
||||
increaseIndent();
|
||||
writeLine();
|
||||
emitSetters();
|
||||
writeLine();
|
||||
emitExecute(node, startIndex);
|
||||
emitTempDeclarations(/*newLine*/ true)
|
||||
decreaseIndent();
|
||||
writeLine();
|
||||
write("}"); // return
|
||||
}
|
||||
|
||||
function emitSetters() {
|
||||
write("setters:[");
|
||||
for (let i = 0; i < externalImports.length; ++i) {
|
||||
if (i !== 0) {
|
||||
write(",");
|
||||
}
|
||||
|
||||
writeLine();
|
||||
increaseIndent();
|
||||
let importNode = externalImports[i];
|
||||
let importVariableName = getLocalNameForExternalImport(importNode) || "";
|
||||
let parameterName = "_" + importVariableName;
|
||||
write(`function (${parameterName}) {`);
|
||||
|
||||
switch (importNode.kind) {
|
||||
case SyntaxKind.ImportDeclaration:
|
||||
if (!(<ImportDeclaration>importNode).importClause) {
|
||||
// 'import "..."' case
|
||||
// module is imported only for side-effects, setter body will be empty
|
||||
break;
|
||||
}
|
||||
// fall-through
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
Debug.assert(importVariableName !== "");
|
||||
|
||||
increaseIndent();
|
||||
writeLine();
|
||||
// save import into the local
|
||||
write(`${importVariableName} = ${parameterName}`);
|
||||
writeLine();
|
||||
|
||||
let defaultName =
|
||||
importNode.kind === SyntaxKind.ImportDeclaration
|
||||
? (<ImportDeclaration>importNode).importClause.name
|
||||
: (<ImportEqualsDeclaration>importNode).name;
|
||||
|
||||
if (defaultName) {
|
||||
// emit re-export for imported default name
|
||||
// import n1 from 'foo1'
|
||||
// import n2 = require('foo2')
|
||||
// export {n1}
|
||||
// export {n2}
|
||||
emitExportMemberAssignments(defaultName);
|
||||
writeLine();
|
||||
}
|
||||
|
||||
if (importNode.kind === SyntaxKind.ImportDeclaration &&
|
||||
(<ImportDeclaration>importNode).importClause.namedBindings) {
|
||||
|
||||
let namedBindings = (<ImportDeclaration>importNode).importClause.namedBindings;
|
||||
if (namedBindings.kind === SyntaxKind.NamespaceImport) {
|
||||
// emit re-export for namespace
|
||||
// import * as n from 'foo'
|
||||
// export {n}
|
||||
emitExportMemberAssignments((<NamespaceImport>namedBindings).name);
|
||||
writeLine();
|
||||
}
|
||||
else {
|
||||
// emit re-exports for named imports
|
||||
// import {a, b} from 'foo'
|
||||
// export {a, b as c}
|
||||
for (let element of (<NamedImports>namedBindings).elements) {
|
||||
emitExportMemberAssignments(element.name || element.propertyName);
|
||||
writeLine()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
decreaseIndent();
|
||||
break;
|
||||
case SyntaxKind.ExportDeclaration:
|
||||
Debug.assert(importVariableName !== "");
|
||||
|
||||
increaseIndent();
|
||||
|
||||
if ((<ExportDeclaration>importNode).exportClause) {
|
||||
// export {a, b as c} from 'foo'
|
||||
// emit as:
|
||||
// exports('a', _foo["a"])
|
||||
// exports('c', _foo["b"])
|
||||
for (let e of (<ExportDeclaration>importNode).exportClause.elements) {
|
||||
writeLine();
|
||||
write(`${exportFunctionForFile}("`);
|
||||
emitNodeWithoutSourceMap(e.name);
|
||||
write(`", ${parameterName}["`);
|
||||
emitNodeWithoutSourceMap(e.propertyName || e.name);
|
||||
write(`"]);`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
writeLine();
|
||||
// export * from 'foo'
|
||||
// emit as:
|
||||
// for (var n in _foo) exports(n, _foo[n]);
|
||||
// NOTE: it is safe to use name 'n' since parameter name always starts with '_'
|
||||
write(`for (var n in ${parameterName}) ${exportFunctionForFile}(n, ${parameterName}[n]);`);
|
||||
}
|
||||
|
||||
writeLine();
|
||||
decreaseIndent();
|
||||
break;
|
||||
}
|
||||
|
||||
write("}")
|
||||
decreaseIndent();
|
||||
}
|
||||
write("],");
|
||||
}
|
||||
|
||||
function emitExecute(node: SourceFile, startIndex: number) {
|
||||
write("execute: function() {");
|
||||
increaseIndent();
|
||||
writeLine();
|
||||
for (let i = startIndex; i < node.statements.length; ++i) {
|
||||
let statement = node.statements[i];
|
||||
// - imports/exports are not emitted for system modules
|
||||
// - function declarations are not emitted because they were already hoisted
|
||||
switch (statement.kind) {
|
||||
case SyntaxKind.ExportDeclaration:
|
||||
case SyntaxKind.ImportDeclaration:
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
continue;
|
||||
}
|
||||
writeLine();
|
||||
emit(statement);
|
||||
}
|
||||
decreaseIndent();
|
||||
writeLine();
|
||||
write("}") // execute
|
||||
}
|
||||
|
||||
function emitSystemModule(node: SourceFile, startIndex: number): void {
|
||||
collectExternalModuleInfo(node);
|
||||
// System modules has the following shape
|
||||
// System.register(['dep-1', ... 'dep-n'], function(exports) {/* module body function */})
|
||||
// 'exports' here is a function 'exports<T>(name: string, value: T): T' that is used to publish exported values.
|
||||
// 'exports' returns its 'value' argument so in most cases expressions
|
||||
// that mutate exported values can be rewritten as:
|
||||
// expr -> exports('name', expr).
|
||||
// The only exception in this rule is postfix unary operators,
|
||||
// see comment to 'emitPostfixUnaryExpression' for more details
|
||||
Debug.assert(!exportFunctionForFile);
|
||||
// make sure that name of 'exports' function does not conflict with existing identifiers
|
||||
exportFunctionForFile = makeUniqueName("exports");
|
||||
write("System.register([");
|
||||
for (let i = 0; i < externalImports.length; ++i) {
|
||||
let text = getExternalModuleNameText(externalImports[i]);
|
||||
if (i !== 0) {
|
||||
write(", ");
|
||||
}
|
||||
write(text);
|
||||
}
|
||||
write(`], function(${exportFunctionForFile}) {`);
|
||||
writeLine();
|
||||
increaseIndent();
|
||||
emitCaptureThisForNodeIfNecessary(node);
|
||||
emitSystemModuleBody(node, startIndex);
|
||||
decreaseIndent();
|
||||
writeLine();
|
||||
write("});");
|
||||
}
|
||||
|
||||
function emitAMDDependencies(node: SourceFile, includeNonAmdDependencies: boolean) {
|
||||
// An AMD define function has the following shape:
|
||||
// define(id?, dependencies?, factory);
|
||||
|
@ -4664,8 +5287,8 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
|
|||
// factory function.
|
||||
let unaliasedModuleNames: string[] = []; // names of modules with no corresponding parameters in
|
||||
// factory function.
|
||||
let importAliasNames: string[] = []; // names of the parameters in the factory function; these
|
||||
// parameters need to match the indexes of the corresponding
|
||||
let importAliasNames: string[] = []; // names of the parameters in the factory function; these
|
||||
// parameters need to match the indexes of the corresponding
|
||||
// module names in aliasedModuleNames.
|
||||
|
||||
// Fill in amd-dependency tags
|
||||
|
@ -4681,22 +5304,10 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
|
|||
|
||||
for (let importNode of externalImports) {
|
||||
// Find the name of the external module
|
||||
let externalModuleName = "";
|
||||
let moduleName = getExternalModuleName(importNode);
|
||||
if (moduleName.kind === SyntaxKind.StringLiteral) {
|
||||
externalModuleName = getLiteralText(<LiteralExpression>moduleName);
|
||||
}
|
||||
let externalModuleName = getExternalModuleNameText(importNode);
|
||||
|
||||
// Find the name of the module alias, if there is one
|
||||
let importAliasName: string;
|
||||
let namespaceDeclaration = getNamespaceDeclarationNode(importNode);
|
||||
if (namespaceDeclaration && !isDefaultImport(importNode)) {
|
||||
importAliasName = getSourceTextOfNodeFromSourceFile(currentSourceFile, namespaceDeclaration.name);
|
||||
}
|
||||
else {
|
||||
importAliasName = getGeneratedNameForNode(<ImportDeclaration | ExportDeclaration>importNode);
|
||||
}
|
||||
|
||||
let importAliasName = getLocalNameForExternalImport(importNode);
|
||||
if (includeNonAmdDependencies && importAliasName) {
|
||||
aliasedModuleNames.push(externalModuleName);
|
||||
importAliasNames.push(importAliasName);
|
||||
|
@ -4861,6 +5472,9 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
|
|||
else if (compilerOptions.module === ModuleKind.AMD) {
|
||||
emitAMDModule(node, startIndex);
|
||||
}
|
||||
else if (compilerOptions.module === ModuleKind.System) {
|
||||
emitSystemModule(node, startIndex);
|
||||
}
|
||||
else if (compilerOptions.module === ModuleKind.UMD) {
|
||||
emitUMDModule(node, startIndex);
|
||||
}
|
||||
|
|
|
@ -567,7 +567,7 @@ module ts {
|
|||
|
||||
// Cannot specify module gen target when in es6 or above
|
||||
if (options.module && languageVersion >= ScriptTarget.ES6) {
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_compile_external_modules_into_amd_commonjs_or_umd_when_targeting_ES6_or_higher));
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_compile_external_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher));
|
||||
}
|
||||
|
||||
// there has to be common source directory if user specified --outdir || --sourceRoot
|
||||
|
|
|
@ -1277,6 +1277,7 @@ module ts {
|
|||
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
|
||||
resolvesToSomeValue(location: Node, name: string): boolean;
|
||||
getBlockScopedVariableId(node: Identifier): number;
|
||||
getReferencedValueDeclaration(reference: Identifier): Declaration;
|
||||
serializeTypeOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): string | string[];
|
||||
serializeParameterTypesOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): (string | string[])[];
|
||||
serializeReturnTypeOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): string | string[];
|
||||
|
@ -1679,6 +1680,7 @@ module ts {
|
|||
CommonJS = 1,
|
||||
AMD = 2,
|
||||
UMD = 3,
|
||||
System = 4,
|
||||
}
|
||||
|
||||
export interface LineAndCharacter {
|
||||
|
|
|
@ -961,6 +961,8 @@ module Harness {
|
|||
options.module = ts.ModuleKind.UMD;
|
||||
} else if (setting.value.toLowerCase() === 'commonjs') {
|
||||
options.module = ts.ModuleKind.CommonJS;
|
||||
} else if (setting.value.toLowerCase() === 'system') {
|
||||
options.module = ts.ModuleKind.System;
|
||||
} else if (setting.value.toLowerCase() === 'unspecified') {
|
||||
options.module = ts.ModuleKind.None;
|
||||
} else {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.
|
||||
error TS1204: Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.
|
||||
tests/cases/compiler/constDeclarations_access_2.ts(2,1): error TS1202: Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead.
|
||||
tests/cases/compiler/constDeclarations_access_2.ts(4,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
|
||||
tests/cases/compiler/constDeclarations_access_2.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
|
||||
|
@ -20,7 +20,7 @@ tests/cases/compiler/constDeclarations_access_2.ts(22,3): error TS2449: The oper
|
|||
tests/cases/compiler/constDeclarations_access_2.ts(24,1): error TS2450: Left-hand side of assignment expression cannot be a constant.
|
||||
|
||||
|
||||
!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.
|
||||
!!! error TS1204: Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.
|
||||
==== tests/cases/compiler/constDeclarations_access_2.ts (19 errors) ====
|
||||
///<reference path='constDeclarations_access_1.ts'/>
|
||||
import m = require('constDeclarations_access_1');
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.
|
||||
error TS1204: Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.
|
||||
|
||||
|
||||
!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.
|
||||
!!! error TS1204: Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.
|
||||
==== tests/cases/compiler/es6-amd.ts (0 errors) ====
|
||||
|
||||
class A
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.
|
||||
error TS1204: Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.
|
||||
|
||||
|
||||
!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.
|
||||
!!! error TS1204: Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.
|
||||
==== tests/cases/compiler/es6-declaration-amd.ts (0 errors) ====
|
||||
|
||||
class A
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.
|
||||
error TS1204: Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.
|
||||
|
||||
|
||||
!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.
|
||||
!!! error TS1204: Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.
|
||||
==== tests/cases/compiler/es6-sourcemap-amd.ts (0 errors) ====
|
||||
|
||||
class A
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.
|
||||
error TS1204: Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.
|
||||
|
||||
|
||||
!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.
|
||||
!!! error TS1204: Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.
|
||||
==== tests/cases/compiler/es6-umd.ts (0 errors) ====
|
||||
|
||||
class A
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.
|
||||
error TS1204: Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.
|
||||
|
||||
|
||||
!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.
|
||||
!!! error TS1204: Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.
|
||||
==== tests/cases/compiler/es6-umd2.ts (0 errors) ====
|
||||
|
||||
export class A
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.
|
||||
error TS1204: Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.
|
||||
|
||||
|
||||
!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.
|
||||
!!! error TS1204: Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.
|
||||
==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0.ts (0 errors) ====
|
||||
|
||||
export var a = 10;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.
|
||||
error TS1204: Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.
|
||||
|
||||
|
||||
!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.
|
||||
!!! error TS1204: Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.
|
||||
==== tests/cases/compiler/es6ImportNameSpaceImport_0.ts (0 errors) ====
|
||||
|
||||
export var a = 10;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.
|
||||
error TS1204: Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.
|
||||
|
||||
|
||||
!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.
|
||||
!!! error TS1204: Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.
|
||||
==== tests/cases/compiler/es6ImportNamedImport_0.ts (0 errors) ====
|
||||
|
||||
export var a = 10;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.
|
||||
error TS1204: Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.
|
||||
tests/cases/compiler/es6ImportNamedImportInExportAssignment_1.ts(2,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead.
|
||||
|
||||
|
||||
!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.
|
||||
!!! error TS1204: Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.
|
||||
==== tests/cases/compiler/es6ImportNamedImportInExportAssignment_0.ts (0 errors) ====
|
||||
|
||||
export var a = 10;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.
|
||||
error TS1204: Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.
|
||||
|
||||
|
||||
!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.
|
||||
!!! error TS1204: Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.
|
||||
==== tests/cases/compiler/es6ModuleWithModuleGenTargetAmd.ts (0 errors) ====
|
||||
export class A
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.
|
||||
error TS1204: Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.
|
||||
|
||||
|
||||
!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.
|
||||
!!! error TS1204: Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.
|
||||
==== tests/cases/compiler/es6ModuleWithModuleGenTargetCommonjs.ts (0 errors) ====
|
||||
export class A
|
||||
{
|
||||
|
|
7
tests/baselines/reference/systemModule1.errors.txt
Normal file
7
tests/baselines/reference/systemModule1.errors.txt
Normal file
|
@ -0,0 +1,7 @@
|
|||
error TS1204: Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.
|
||||
|
||||
|
||||
!!! error TS1204: Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.
|
||||
==== tests/cases/compiler/systemModule1.ts (0 errors) ====
|
||||
|
||||
export var x = 1;
|
6
tests/baselines/reference/systemModule1.js
Normal file
6
tests/baselines/reference/systemModule1.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
//// [systemModule1.ts]
|
||||
|
||||
export var x = 1;
|
||||
|
||||
//// [systemModule1.js]
|
||||
export var x = 1;
|
18
tests/baselines/reference/systemModule10.errors.txt
Normal file
18
tests/baselines/reference/systemModule10.errors.txt
Normal file
|
@ -0,0 +1,18 @@
|
|||
tests/cases/compiler/systemModule10.ts(2,20): error TS2307: Cannot find external module 'file1'.
|
||||
tests/cases/compiler/systemModule10.ts(3,21): error TS2307: Cannot find external module 'file2'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/systemModule10.ts (2 errors) ====
|
||||
|
||||
import n, {x} from 'file1'
|
||||
~~~~~~~
|
||||
!!! error TS2307: Cannot find external module 'file1'.
|
||||
import n2 = require('file2');
|
||||
~~~~~~~
|
||||
!!! error TS2307: Cannot find external module 'file2'.
|
||||
export {x}
|
||||
export {x as y}
|
||||
export {n}
|
||||
export {n as n1}
|
||||
export {n2}
|
||||
export {n2 as n3}
|
32
tests/baselines/reference/systemModule10.js
Normal file
32
tests/baselines/reference/systemModule10.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
//// [systemModule10.ts]
|
||||
|
||||
import n, {x} from 'file1'
|
||||
import n2 = require('file2');
|
||||
export {x}
|
||||
export {x as y}
|
||||
export {n}
|
||||
export {n as n1}
|
||||
export {n2}
|
||||
export {n2 as n3}
|
||||
|
||||
//// [systemModule10.js]
|
||||
System.register(['file1', 'file2'], function(exports_1) {
|
||||
var file1_1, n2;
|
||||
return {
|
||||
setters:[
|
||||
function (_file1_1) {
|
||||
file1_1 = _file1_1
|
||||
exports_1("n", file1_1["default"]);
|
||||
exports_1("n1", file1_1["default"]);
|
||||
exports_1("x", file1_1.x);
|
||||
exports_1("y", file1_1.x);
|
||||
},
|
||||
function (_n2) {
|
||||
n2 = _n2
|
||||
exports_1("n2", n2);
|
||||
exports_1("n3", n2);
|
||||
}],
|
||||
execute: function() {
|
||||
}
|
||||
}
|
||||
});
|
18
tests/baselines/reference/systemModule10_ES5.errors.txt
Normal file
18
tests/baselines/reference/systemModule10_ES5.errors.txt
Normal file
|
@ -0,0 +1,18 @@
|
|||
tests/cases/compiler/systemModule10_ES5.ts(2,20): error TS2307: Cannot find external module 'file1'.
|
||||
tests/cases/compiler/systemModule10_ES5.ts(3,21): error TS2307: Cannot find external module 'file2'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/systemModule10_ES5.ts (2 errors) ====
|
||||
|
||||
import n, {x} from 'file1'
|
||||
~~~~~~~
|
||||
!!! error TS2307: Cannot find external module 'file1'.
|
||||
import n2 = require('file2');
|
||||
~~~~~~~
|
||||
!!! error TS2307: Cannot find external module 'file2'.
|
||||
export {x}
|
||||
export {x as y}
|
||||
export {n}
|
||||
export {n as n1}
|
||||
export {n2}
|
||||
export {n2 as n3}
|
32
tests/baselines/reference/systemModule10_ES5.js
Normal file
32
tests/baselines/reference/systemModule10_ES5.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
//// [systemModule10_ES5.ts]
|
||||
|
||||
import n, {x} from 'file1'
|
||||
import n2 = require('file2');
|
||||
export {x}
|
||||
export {x as y}
|
||||
export {n}
|
||||
export {n as n1}
|
||||
export {n2}
|
||||
export {n2 as n3}
|
||||
|
||||
//// [systemModule10_ES5.js]
|
||||
System.register(['file1', 'file2'], function(exports_1) {
|
||||
var file1_1, n2;
|
||||
return {
|
||||
setters:[
|
||||
function (_file1_1) {
|
||||
file1_1 = _file1_1
|
||||
exports_1("n", file1_1.default);
|
||||
exports_1("n1", file1_1.default);
|
||||
exports_1("x", file1_1.x);
|
||||
exports_1("y", file1_1.x);
|
||||
},
|
||||
function (_n2) {
|
||||
n2 = _n2
|
||||
exports_1("n2", n2);
|
||||
exports_1("n3", n2);
|
||||
}],
|
||||
execute: function() {
|
||||
}
|
||||
}
|
||||
});
|
11
tests/baselines/reference/systemModule11.errors.txt
Normal file
11
tests/baselines/reference/systemModule11.errors.txt
Normal file
|
@ -0,0 +1,11 @@
|
|||
tests/cases/compiler/systemModule11.ts(3,17): error TS2307: Cannot find external module 'bar'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/systemModule11.ts (1 errors) ====
|
||||
|
||||
import 'foo'
|
||||
import {f} from 'bar';
|
||||
~~~~~
|
||||
!!! error TS2307: Cannot find external module 'bar'.
|
||||
|
||||
f();
|
21
tests/baselines/reference/systemModule11.js
Normal file
21
tests/baselines/reference/systemModule11.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
//// [systemModule11.ts]
|
||||
|
||||
import 'foo'
|
||||
import {f} from 'bar';
|
||||
|
||||
f();
|
||||
|
||||
//// [systemModule11.js]
|
||||
System.register(['foo', 'bar'], function(exports_1) {
|
||||
var bar_1;
|
||||
return {
|
||||
setters:[
|
||||
function (_) {},
|
||||
function (_bar_1) {
|
||||
bar_1 = _bar_1
|
||||
}],
|
||||
execute: function() {
|
||||
bar_1.f();
|
||||
}
|
||||
}
|
||||
});
|
9
tests/baselines/reference/systemModule2.errors.txt
Normal file
9
tests/baselines/reference/systemModule2.errors.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
tests/cases/compiler/systemModule2.ts(3,1): error TS1218: Export assignment is not supported when '--module' flag is 'system'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/systemModule2.ts (1 errors) ====
|
||||
|
||||
var x = 1;
|
||||
export = x;
|
||||
~~~~~~~~~~~
|
||||
!!! error TS1218: Export assignment is not supported when '--module' flag is 'system'.
|
15
tests/baselines/reference/systemModule2.js
Normal file
15
tests/baselines/reference/systemModule2.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
//// [systemModule2.ts]
|
||||
|
||||
var x = 1;
|
||||
export = x;
|
||||
|
||||
//// [systemModule2.js]
|
||||
System.register([], function(exports_1) {
|
||||
var x;
|
||||
return {
|
||||
setters:[],
|
||||
execute: function() {
|
||||
x = 1;
|
||||
}
|
||||
}
|
||||
});
|
69
tests/baselines/reference/systemModule3.js
Normal file
69
tests/baselines/reference/systemModule3.js
Normal file
|
@ -0,0 +1,69 @@
|
|||
//// [tests/cases/compiler/systemModule3.ts] ////
|
||||
|
||||
//// [file1.ts]
|
||||
|
||||
|
||||
export default function() {}
|
||||
|
||||
//// [file2.ts]
|
||||
|
||||
export default function f() {}
|
||||
|
||||
//// [file3.ts]
|
||||
|
||||
export default class C {}
|
||||
|
||||
//// [file4.ts]
|
||||
|
||||
export default class {}
|
||||
|
||||
//// [file1.js]
|
||||
System.register([], function(exports_1) {
|
||||
function default_1() { }
|
||||
exports_1("default", default_1);
|
||||
return {
|
||||
setters:[],
|
||||
execute: function() {
|
||||
}
|
||||
}
|
||||
});
|
||||
//// [file2.js]
|
||||
System.register([], function(exports_1) {
|
||||
function f() { }
|
||||
exports_1("default", f);
|
||||
return {
|
||||
setters:[],
|
||||
execute: function() {
|
||||
}
|
||||
}
|
||||
});
|
||||
//// [file3.js]
|
||||
System.register([], function(exports_1) {
|
||||
var C;
|
||||
return {
|
||||
setters:[],
|
||||
execute: function() {
|
||||
C = (function () {
|
||||
function C() {
|
||||
}
|
||||
return C;
|
||||
})();
|
||||
exports_1("default", C);
|
||||
}
|
||||
}
|
||||
});
|
||||
//// [file4.js]
|
||||
System.register([], function(exports_1) {
|
||||
var default_1;
|
||||
return {
|
||||
setters:[],
|
||||
execute: function() {
|
||||
default_1 = (function () {
|
||||
function default_1() {
|
||||
}
|
||||
return default_1;
|
||||
})();
|
||||
exports_1("default", default_1);
|
||||
}
|
||||
}
|
||||
});
|
19
tests/baselines/reference/systemModule3.symbols
Normal file
19
tests/baselines/reference/systemModule3.symbols
Normal file
|
@ -0,0 +1,19 @@
|
|||
=== tests/cases/compiler/file1.ts ===
|
||||
|
||||
No type information for this code.
|
||||
No type information for this code.export default function() {}
|
||||
No type information for this code.
|
||||
No type information for this code.=== tests/cases/compiler/file2.ts ===
|
||||
|
||||
export default function f() {}
|
||||
>f : Symbol(f, Decl(file2.ts, 0, 0))
|
||||
|
||||
=== tests/cases/compiler/file3.ts ===
|
||||
|
||||
export default class C {}
|
||||
>C : Symbol(C, Decl(file3.ts, 0, 0))
|
||||
|
||||
=== tests/cases/compiler/file4.ts ===
|
||||
|
||||
No type information for this code.export default class {}
|
||||
No type information for this code.
|
19
tests/baselines/reference/systemModule3.types
Normal file
19
tests/baselines/reference/systemModule3.types
Normal file
|
@ -0,0 +1,19 @@
|
|||
=== tests/cases/compiler/file1.ts ===
|
||||
|
||||
No type information for this code.
|
||||
No type information for this code.export default function() {}
|
||||
No type information for this code.
|
||||
No type information for this code.=== tests/cases/compiler/file2.ts ===
|
||||
|
||||
export default function f() {}
|
||||
>f : () => void
|
||||
|
||||
=== tests/cases/compiler/file3.ts ===
|
||||
|
||||
export default class C {}
|
||||
>C : C
|
||||
|
||||
=== tests/cases/compiler/file4.ts ===
|
||||
|
||||
No type information for this code.export default class {}
|
||||
No type information for this code.
|
16
tests/baselines/reference/systemModule4.js
Normal file
16
tests/baselines/reference/systemModule4.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
//// [systemModule4.ts]
|
||||
|
||||
export var x = 1;
|
||||
export var y;
|
||||
|
||||
//// [systemModule4.js]
|
||||
System.register([], function(exports_1) {
|
||||
var x, y;
|
||||
return {
|
||||
setters:[],
|
||||
execute: function() {
|
||||
exports_1("x", x = 1);
|
||||
exports_1("y", y);
|
||||
}
|
||||
}
|
||||
});
|
8
tests/baselines/reference/systemModule4.symbols
Normal file
8
tests/baselines/reference/systemModule4.symbols
Normal file
|
@ -0,0 +1,8 @@
|
|||
=== tests/cases/compiler/systemModule4.ts ===
|
||||
|
||||
export var x = 1;
|
||||
>x : Symbol(x, Decl(systemModule4.ts, 1, 10))
|
||||
|
||||
export var y;
|
||||
>y : Symbol(y, Decl(systemModule4.ts, 2, 10))
|
||||
|
9
tests/baselines/reference/systemModule4.types
Normal file
9
tests/baselines/reference/systemModule4.types
Normal file
|
@ -0,0 +1,9 @@
|
|||
=== tests/cases/compiler/systemModule4.ts ===
|
||||
|
||||
export var x = 1;
|
||||
>x : number
|
||||
>1 : number
|
||||
|
||||
export var y;
|
||||
>y : any
|
||||
|
15
tests/baselines/reference/systemModule5.js
Normal file
15
tests/baselines/reference/systemModule5.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
//// [systemModule5.ts]
|
||||
|
||||
export function foo() {}
|
||||
|
||||
|
||||
//// [systemModule5.js]
|
||||
System.register([], function(exports_1) {
|
||||
function foo() { }
|
||||
exports_1("foo", foo);
|
||||
return {
|
||||
setters:[],
|
||||
execute: function() {
|
||||
}
|
||||
}
|
||||
});
|
5
tests/baselines/reference/systemModule5.symbols
Normal file
5
tests/baselines/reference/systemModule5.symbols
Normal file
|
@ -0,0 +1,5 @@
|
|||
=== tests/cases/compiler/systemModule5.ts ===
|
||||
|
||||
export function foo() {}
|
||||
>foo : Symbol(foo, Decl(systemModule5.ts, 0, 0))
|
||||
|
5
tests/baselines/reference/systemModule5.types
Normal file
5
tests/baselines/reference/systemModule5.types
Normal file
|
@ -0,0 +1,5 @@
|
|||
=== tests/cases/compiler/systemModule5.ts ===
|
||||
|
||||
export function foo() {}
|
||||
>foo : () => void
|
||||
|
26
tests/baselines/reference/systemModule6.js
Normal file
26
tests/baselines/reference/systemModule6.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
//// [systemModule6.ts]
|
||||
|
||||
export class C {}
|
||||
function foo() {
|
||||
new C();
|
||||
}
|
||||
|
||||
|
||||
//// [systemModule6.js]
|
||||
System.register([], function(exports_1) {
|
||||
var C;
|
||||
function foo() {
|
||||
new C();
|
||||
}
|
||||
return {
|
||||
setters:[],
|
||||
execute: function() {
|
||||
C = (function () {
|
||||
function C() {
|
||||
}
|
||||
return C;
|
||||
})();
|
||||
exports_1("C", C);
|
||||
}
|
||||
}
|
||||
});
|
12
tests/baselines/reference/systemModule6.symbols
Normal file
12
tests/baselines/reference/systemModule6.symbols
Normal file
|
@ -0,0 +1,12 @@
|
|||
=== tests/cases/compiler/systemModule6.ts ===
|
||||
|
||||
export class C {}
|
||||
>C : Symbol(C, Decl(systemModule6.ts, 0, 0))
|
||||
|
||||
function foo() {
|
||||
>foo : Symbol(foo, Decl(systemModule6.ts, 1, 17))
|
||||
|
||||
new C();
|
||||
>C : Symbol(C, Decl(systemModule6.ts, 0, 0))
|
||||
}
|
||||
|
13
tests/baselines/reference/systemModule6.types
Normal file
13
tests/baselines/reference/systemModule6.types
Normal file
|
@ -0,0 +1,13 @@
|
|||
=== tests/cases/compiler/systemModule6.ts ===
|
||||
|
||||
export class C {}
|
||||
>C : C
|
||||
|
||||
function foo() {
|
||||
>foo : () => void
|
||||
|
||||
new C();
|
||||
>new C() : C
|
||||
>C : typeof C
|
||||
}
|
||||
|
26
tests/baselines/reference/systemModule7.js
Normal file
26
tests/baselines/reference/systemModule7.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
//// [systemModule7.ts]
|
||||
|
||||
// filename: instantiatedModule.ts
|
||||
export module M {
|
||||
var x = 1;
|
||||
}
|
||||
|
||||
// filename: nonInstantiatedModule.ts
|
||||
export module M {
|
||||
interface I {}
|
||||
}
|
||||
|
||||
//// [systemModule7.js]
|
||||
System.register([], function(exports_1) {
|
||||
var M;
|
||||
return {
|
||||
setters:[],
|
||||
execute: function() {
|
||||
// filename: instantiatedModule.ts
|
||||
(function (M) {
|
||||
var x = 1;
|
||||
})(M = M || (M = {}));
|
||||
exports_1("M", M)
|
||||
}
|
||||
}
|
||||
});
|
17
tests/baselines/reference/systemModule7.symbols
Normal file
17
tests/baselines/reference/systemModule7.symbols
Normal file
|
@ -0,0 +1,17 @@
|
|||
=== tests/cases/compiler/systemModule7.ts ===
|
||||
|
||||
// filename: instantiatedModule.ts
|
||||
export module M {
|
||||
>M : Symbol(M, Decl(systemModule7.ts, 0, 0), Decl(systemModule7.ts, 4, 1))
|
||||
|
||||
var x = 1;
|
||||
>x : Symbol(x, Decl(systemModule7.ts, 3, 7))
|
||||
}
|
||||
|
||||
// filename: nonInstantiatedModule.ts
|
||||
export module M {
|
||||
>M : Symbol(M, Decl(systemModule7.ts, 0, 0), Decl(systemModule7.ts, 4, 1))
|
||||
|
||||
interface I {}
|
||||
>I : Symbol(I, Decl(systemModule7.ts, 7, 17))
|
||||
}
|
18
tests/baselines/reference/systemModule7.types
Normal file
18
tests/baselines/reference/systemModule7.types
Normal file
|
@ -0,0 +1,18 @@
|
|||
=== tests/cases/compiler/systemModule7.ts ===
|
||||
|
||||
// filename: instantiatedModule.ts
|
||||
export module M {
|
||||
>M : typeof M
|
||||
|
||||
var x = 1;
|
||||
>x : number
|
||||
>1 : number
|
||||
}
|
||||
|
||||
// filename: nonInstantiatedModule.ts
|
||||
export module M {
|
||||
>M : typeof M
|
||||
|
||||
interface I {}
|
||||
>I : I
|
||||
}
|
71
tests/baselines/reference/systemModule8.js
Normal file
71
tests/baselines/reference/systemModule8.js
Normal file
|
@ -0,0 +1,71 @@
|
|||
//// [systemModule8.ts]
|
||||
|
||||
export var x;
|
||||
x = 1;
|
||||
x++;
|
||||
x--;
|
||||
++x;
|
||||
--x;
|
||||
x += 1;
|
||||
x -= 1;
|
||||
x *= 1;
|
||||
x /= 1;
|
||||
x |= 1;
|
||||
x &= 1;
|
||||
x + 1;
|
||||
x - 1;
|
||||
x & 1;
|
||||
x | 1;
|
||||
for (x = 5;;x++) {}
|
||||
for (x = 8;;x--) {}
|
||||
for (x = 15;;++x) {}
|
||||
for (x = 18;;--x) {}
|
||||
|
||||
for (let x = 50;;) {}
|
||||
function foo() {
|
||||
x = 100;
|
||||
}
|
||||
|
||||
export let [y] = [1];
|
||||
export const {a: z0, b: {c: z1}} = {a: true, b: {c: "123"}};
|
||||
for ([x] of [[1]]) {}
|
||||
|
||||
//// [systemModule8.js]
|
||||
System.register([], function(exports_1) {
|
||||
var x, y, z0, z1;
|
||||
function foo() {
|
||||
exports_1("x", x = 100);
|
||||
}
|
||||
return {
|
||||
setters:[],
|
||||
execute: function() {
|
||||
exports_1("x", x);
|
||||
exports_1("x", x = 1);
|
||||
(exports_1("x", ++x) - 1);
|
||||
(exports_1("x", --x) + 1);
|
||||
exports_1("x", ++x);
|
||||
exports_1("x", --x);
|
||||
exports_1("x", x += 1);
|
||||
exports_1("x", x -= 1);
|
||||
exports_1("x", x *= 1);
|
||||
exports_1("x", x /= 1);
|
||||
exports_1("x", x |= 1);
|
||||
exports_1("x", x &= 1);
|
||||
x + 1;
|
||||
x - 1;
|
||||
x & 1;
|
||||
x | 1;
|
||||
for (exports_1("x", x = 5);; (exports_1("x", ++x) - 1)) { }
|
||||
for (exports_1("x", x = 8);; (exports_1("x", --x) + 1)) { }
|
||||
for (exports_1("x", x = 15);; exports_1("x", ++x)) { }
|
||||
for (exports_1("x", x = 18);; exports_1("x", --x)) { }
|
||||
for (var x_1 = 50;;) { }
|
||||
exports_1("y", y = [1][0]);
|
||||
_a = { a: true, b: { c: "123" } }, exports_1("z0", z0 = _a.a), exports_1("z1", z1 = _a.b.c);
|
||||
for (var _i = 0, _b = [[1]]; _i < _b.length; _i++) {
|
||||
exports_1("x", x = _b[_i][0]);
|
||||
}
|
||||
}
|
||||
var _a;
|
||||
}
|
||||
});
|
89
tests/baselines/reference/systemModule8.symbols
Normal file
89
tests/baselines/reference/systemModule8.symbols
Normal file
|
@ -0,0 +1,89 @@
|
|||
=== tests/cases/compiler/systemModule8.ts ===
|
||||
|
||||
export var x;
|
||||
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
|
||||
|
||||
x = 1;
|
||||
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
|
||||
|
||||
x++;
|
||||
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
|
||||
|
||||
x--;
|
||||
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
|
||||
|
||||
++x;
|
||||
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
|
||||
|
||||
--x;
|
||||
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
|
||||
|
||||
x += 1;
|
||||
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
|
||||
|
||||
x -= 1;
|
||||
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
|
||||
|
||||
x *= 1;
|
||||
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
|
||||
|
||||
x /= 1;
|
||||
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
|
||||
|
||||
x |= 1;
|
||||
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
|
||||
|
||||
x &= 1;
|
||||
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
|
||||
|
||||
x + 1;
|
||||
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
|
||||
|
||||
x - 1;
|
||||
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
|
||||
|
||||
x & 1;
|
||||
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
|
||||
|
||||
x | 1;
|
||||
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
|
||||
|
||||
for (x = 5;;x++) {}
|
||||
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
|
||||
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
|
||||
|
||||
for (x = 8;;x--) {}
|
||||
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
|
||||
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
|
||||
|
||||
for (x = 15;;++x) {}
|
||||
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
|
||||
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
|
||||
|
||||
for (x = 18;;--x) {}
|
||||
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
|
||||
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
|
||||
|
||||
for (let x = 50;;) {}
|
||||
>x : Symbol(x, Decl(systemModule8.ts, 22, 8))
|
||||
|
||||
function foo() {
|
||||
>foo : Symbol(foo, Decl(systemModule8.ts, 22, 21))
|
||||
|
||||
x = 100;
|
||||
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
|
||||
}
|
||||
|
||||
export let [y] = [1];
|
||||
>y : Symbol(y, Decl(systemModule8.ts, 27, 12))
|
||||
|
||||
export const {a: z0, b: {c: z1}} = {a: true, b: {c: "123"}};
|
||||
>z0 : Symbol(z0, Decl(systemModule8.ts, 28, 14))
|
||||
>z1 : Symbol(z1, Decl(systemModule8.ts, 28, 25))
|
||||
>a : Symbol(a, Decl(systemModule8.ts, 28, 36))
|
||||
>b : Symbol(b, Decl(systemModule8.ts, 28, 44))
|
||||
>c : Symbol(c, Decl(systemModule8.ts, 28, 49))
|
||||
|
||||
for ([x] of [[1]]) {}
|
||||
>x : Symbol(x, Decl(systemModule8.ts, 1, 10))
|
||||
|
143
tests/baselines/reference/systemModule8.types
Normal file
143
tests/baselines/reference/systemModule8.types
Normal file
|
@ -0,0 +1,143 @@
|
|||
=== tests/cases/compiler/systemModule8.ts ===
|
||||
|
||||
export var x;
|
||||
>x : any
|
||||
|
||||
x = 1;
|
||||
>x = 1 : number
|
||||
>x : any
|
||||
>1 : number
|
||||
|
||||
x++;
|
||||
>x++ : number
|
||||
>x : any
|
||||
|
||||
x--;
|
||||
>x-- : number
|
||||
>x : any
|
||||
|
||||
++x;
|
||||
>++x : number
|
||||
>x : any
|
||||
|
||||
--x;
|
||||
>--x : number
|
||||
>x : any
|
||||
|
||||
x += 1;
|
||||
>x += 1 : any
|
||||
>x : any
|
||||
>1 : number
|
||||
|
||||
x -= 1;
|
||||
>x -= 1 : number
|
||||
>x : any
|
||||
>1 : number
|
||||
|
||||
x *= 1;
|
||||
>x *= 1 : number
|
||||
>x : any
|
||||
>1 : number
|
||||
|
||||
x /= 1;
|
||||
>x /= 1 : number
|
||||
>x : any
|
||||
>1 : number
|
||||
|
||||
x |= 1;
|
||||
>x |= 1 : number
|
||||
>x : any
|
||||
>1 : number
|
||||
|
||||
x &= 1;
|
||||
>x &= 1 : number
|
||||
>x : any
|
||||
>1 : number
|
||||
|
||||
x + 1;
|
||||
>x + 1 : any
|
||||
>x : any
|
||||
>1 : number
|
||||
|
||||
x - 1;
|
||||
>x - 1 : number
|
||||
>x : any
|
||||
>1 : number
|
||||
|
||||
x & 1;
|
||||
>x & 1 : number
|
||||
>x : any
|
||||
>1 : number
|
||||
|
||||
x | 1;
|
||||
>x | 1 : number
|
||||
>x : any
|
||||
>1 : number
|
||||
|
||||
for (x = 5;;x++) {}
|
||||
>x = 5 : number
|
||||
>x : any
|
||||
>5 : number
|
||||
>x++ : number
|
||||
>x : any
|
||||
|
||||
for (x = 8;;x--) {}
|
||||
>x = 8 : number
|
||||
>x : any
|
||||
>8 : number
|
||||
>x-- : number
|
||||
>x : any
|
||||
|
||||
for (x = 15;;++x) {}
|
||||
>x = 15 : number
|
||||
>x : any
|
||||
>15 : number
|
||||
>++x : number
|
||||
>x : any
|
||||
|
||||
for (x = 18;;--x) {}
|
||||
>x = 18 : number
|
||||
>x : any
|
||||
>18 : number
|
||||
>--x : number
|
||||
>x : any
|
||||
|
||||
for (let x = 50;;) {}
|
||||
>x : number
|
||||
>50 : number
|
||||
|
||||
function foo() {
|
||||
>foo : () => void
|
||||
|
||||
x = 100;
|
||||
>x = 100 : number
|
||||
>x : any
|
||||
>100 : number
|
||||
}
|
||||
|
||||
export let [y] = [1];
|
||||
>y : number
|
||||
>[1] : [number]
|
||||
>1 : number
|
||||
|
||||
export const {a: z0, b: {c: z1}} = {a: true, b: {c: "123"}};
|
||||
>a : any
|
||||
>z0 : boolean
|
||||
>b : any
|
||||
>c : any
|
||||
>z1 : string
|
||||
>{a: true, b: {c: "123"}} : { a: boolean; b: { c: string; }; }
|
||||
>a : boolean
|
||||
>true : boolean
|
||||
>b : { c: string; }
|
||||
>{c: "123"} : { c: string; }
|
||||
>c : string
|
||||
>"123" : string
|
||||
|
||||
for ([x] of [[1]]) {}
|
||||
>[x] : any[]
|
||||
>x : any
|
||||
>[[1]] : number[][]
|
||||
>[1] : number[]
|
||||
>1 : number
|
||||
|
42
tests/baselines/reference/systemModule9.errors.txt
Normal file
42
tests/baselines/reference/systemModule9.errors.txt
Normal file
|
@ -0,0 +1,42 @@
|
|||
tests/cases/compiler/systemModule9.ts(2,21): error TS2307: Cannot find external module 'file1'.
|
||||
tests/cases/compiler/systemModule9.ts(3,25): error TS2307: Cannot find external module 'file2'.
|
||||
tests/cases/compiler/systemModule9.ts(4,15): error TS2307: Cannot find external module 'file3'.
|
||||
tests/cases/compiler/systemModule9.ts(6,25): error TS2307: Cannot find external module 'file5'.
|
||||
tests/cases/compiler/systemModule9.ts(7,22): error TS2307: Cannot find external module 'file6'.
|
||||
tests/cases/compiler/systemModule9.ts(17,15): error TS2307: Cannot find external module 'file7'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/systemModule9.ts (6 errors) ====
|
||||
|
||||
import * as ns from 'file1';
|
||||
~~~~~~~
|
||||
!!! error TS2307: Cannot find external module 'file1'.
|
||||
import {a, b as c} from 'file2';
|
||||
~~~~~~~
|
||||
!!! error TS2307: Cannot find external module 'file2'.
|
||||
import d from 'file3'
|
||||
~~~~~~~
|
||||
!!! error TS2307: Cannot find external module 'file3'.
|
||||
import 'file4'
|
||||
import e, * as ns2 from 'file5';
|
||||
~~~~~~~
|
||||
!!! error TS2307: Cannot find external module 'file5'.
|
||||
import ns3 = require('file6');
|
||||
~~~~~~~
|
||||
!!! error TS2307: Cannot find external module 'file6'.
|
||||
|
||||
ns.f();
|
||||
a();
|
||||
c();
|
||||
d();
|
||||
e();
|
||||
ns2.f();
|
||||
ns3.f();
|
||||
|
||||
export * from 'file7';
|
||||
~~~~~~~
|
||||
!!! error TS2307: Cannot find external module 'file7'.
|
||||
|
||||
var x, y = true;
|
||||
export {x};
|
||||
export {y as z};
|
62
tests/baselines/reference/systemModule9.js
Normal file
62
tests/baselines/reference/systemModule9.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
//// [systemModule9.ts]
|
||||
|
||||
import * as ns from 'file1';
|
||||
import {a, b as c} from 'file2';
|
||||
import d from 'file3'
|
||||
import 'file4'
|
||||
import e, * as ns2 from 'file5';
|
||||
import ns3 = require('file6');
|
||||
|
||||
ns.f();
|
||||
a();
|
||||
c();
|
||||
d();
|
||||
e();
|
||||
ns2.f();
|
||||
ns3.f();
|
||||
|
||||
export * from 'file7';
|
||||
|
||||
var x, y = true;
|
||||
export {x};
|
||||
export {y as z};
|
||||
|
||||
//// [systemModule9.js]
|
||||
System.register(['file1', 'file2', 'file3', 'file4', 'file5', 'file6', 'file7'], function(exports_1) {
|
||||
var ns, file2_1, file3_1, file5_1, ns3;
|
||||
var x, y;
|
||||
return {
|
||||
setters:[
|
||||
function (_ns) {
|
||||
ns = _ns
|
||||
},
|
||||
function (_file2_1) {
|
||||
file2_1 = _file2_1
|
||||
},
|
||||
function (_file3_1) {
|
||||
file3_1 = _file3_1
|
||||
},
|
||||
function (_) {},
|
||||
function (_file5_1) {
|
||||
file5_1 = _file5_1
|
||||
},
|
||||
function (_ns3) {
|
||||
ns3 = _ns3
|
||||
},
|
||||
function (_file7_1) {
|
||||
for (var n in _file7_1) exports_1(n, _file7_1[n]);
|
||||
}],
|
||||
execute: function() {
|
||||
ns.f();
|
||||
file2_1.a();
|
||||
file2_1.b();
|
||||
file3_1["default"]();
|
||||
file5_1["default"]();
|
||||
ns2.f();
|
||||
ns3.f();
|
||||
y = true;
|
||||
exports_1("x", x);
|
||||
exports_1("z", y);
|
||||
}
|
||||
}
|
||||
});
|
4
tests/cases/compiler/systemModule1.ts
Normal file
4
tests/cases/compiler/systemModule1.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
// @target: es6
|
||||
// @module: system
|
||||
|
||||
export var x = 1;
|
11
tests/cases/compiler/systemModule10.ts
Normal file
11
tests/cases/compiler/systemModule10.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
// @module: system
|
||||
// @separateCompilation: true
|
||||
|
||||
import n, {x} from 'file1'
|
||||
import n2 = require('file2');
|
||||
export {x}
|
||||
export {x as y}
|
||||
export {n}
|
||||
export {n as n1}
|
||||
export {n2}
|
||||
export {n2 as n3}
|
12
tests/cases/compiler/systemModule10_ES5.ts
Normal file
12
tests/cases/compiler/systemModule10_ES5.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
// @target: es5
|
||||
// @module: system
|
||||
// @separateCompilation: true
|
||||
|
||||
import n, {x} from 'file1'
|
||||
import n2 = require('file2');
|
||||
export {x}
|
||||
export {x as y}
|
||||
export {n}
|
||||
export {n as n1}
|
||||
export {n2}
|
||||
export {n2 as n3}
|
7
tests/cases/compiler/systemModule11.ts
Normal file
7
tests/cases/compiler/systemModule11.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
// @module: system
|
||||
// @separateCompilation: true
|
||||
|
||||
import 'foo'
|
||||
import {f} from 'bar';
|
||||
|
||||
f();
|
4
tests/cases/compiler/systemModule2.ts
Normal file
4
tests/cases/compiler/systemModule2.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
// @module: system
|
||||
|
||||
var x = 1;
|
||||
export = x;
|
17
tests/cases/compiler/systemModule3.ts
Normal file
17
tests/cases/compiler/systemModule3.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
// @module: system
|
||||
|
||||
// @filename: file1.ts
|
||||
|
||||
export default function() {}
|
||||
|
||||
// @filename: file2.ts
|
||||
|
||||
export default function f() {}
|
||||
|
||||
// @filename: file3.ts
|
||||
|
||||
export default class C {}
|
||||
|
||||
// @filename: file4.ts
|
||||
|
||||
export default class {}
|
4
tests/cases/compiler/systemModule4.ts
Normal file
4
tests/cases/compiler/systemModule4.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
// @module: system
|
||||
|
||||
export var x = 1;
|
||||
export var y;
|
3
tests/cases/compiler/systemModule5.ts
Normal file
3
tests/cases/compiler/systemModule5.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
// @module: system
|
||||
|
||||
export function foo() {}
|
6
tests/cases/compiler/systemModule6.ts
Normal file
6
tests/cases/compiler/systemModule6.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
// @module: system
|
||||
|
||||
export class C {}
|
||||
function foo() {
|
||||
new C();
|
||||
}
|
11
tests/cases/compiler/systemModule7.ts
Normal file
11
tests/cases/compiler/systemModule7.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
// @module: system
|
||||
|
||||
// filename: instantiatedModule.ts
|
||||
export module M {
|
||||
var x = 1;
|
||||
}
|
||||
|
||||
// filename: nonInstantiatedModule.ts
|
||||
export module M {
|
||||
interface I {}
|
||||
}
|
31
tests/cases/compiler/systemModule8.ts
Normal file
31
tests/cases/compiler/systemModule8.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
// @module: system
|
||||
|
||||
export var x;
|
||||
x = 1;
|
||||
x++;
|
||||
x--;
|
||||
++x;
|
||||
--x;
|
||||
x += 1;
|
||||
x -= 1;
|
||||
x *= 1;
|
||||
x /= 1;
|
||||
x |= 1;
|
||||
x &= 1;
|
||||
x + 1;
|
||||
x - 1;
|
||||
x & 1;
|
||||
x | 1;
|
||||
for (x = 5;;x++) {}
|
||||
for (x = 8;;x--) {}
|
||||
for (x = 15;;++x) {}
|
||||
for (x = 18;;--x) {}
|
||||
|
||||
for (let x = 50;;) {}
|
||||
function foo() {
|
||||
x = 100;
|
||||
}
|
||||
|
||||
export let [y] = [1];
|
||||
export const {a: z0, b: {c: z1}} = {a: true, b: {c: "123"}};
|
||||
for ([x] of [[1]]) {}
|
23
tests/cases/compiler/systemModule9.ts
Normal file
23
tests/cases/compiler/systemModule9.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
// @module: system
|
||||
// @separateCompilation: true
|
||||
|
||||
import * as ns from 'file1';
|
||||
import {a, b as c} from 'file2';
|
||||
import d from 'file3'
|
||||
import 'file4'
|
||||
import e, * as ns2 from 'file5';
|
||||
import ns3 = require('file6');
|
||||
|
||||
ns.f();
|
||||
a();
|
||||
c();
|
||||
d();
|
||||
e();
|
||||
ns2.f();
|
||||
ns3.f();
|
||||
|
||||
export * from 'file7';
|
||||
|
||||
var x, y = true;
|
||||
export {x};
|
||||
export {y as z};
|
Loading…
Reference in a new issue