diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 0450ec25e77a0..d443c7c907a5a 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1765,7 +1765,7 @@ namespace ts { return bindPropertyOrMethodOrAccessor(node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes); case SyntaxKind.JsxSpreadAttribute: - emitFlags |= NodeFlags.HasJsxSpreadAttribute; + emitFlags |= NodeFlags.HasJsxSpreadAttributes; return; case SyntaxKind.CallSignature: diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2938aad7bdcf5..85d3cc67ef5f9 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1264,10 +1264,13 @@ namespace ts { } const moduleReferenceLiteral = moduleReferenceExpression; + return resolveExternalModule(location, moduleReferenceLiteral.text, moduleNotFoundError, moduleReferenceLiteral); + } + function resolveExternalModule(location: Node, moduleReference: string, moduleNotFoundError: DiagnosticMessage, errorNode: Node): Symbol { // Module names are escaped in our symbol table. However, string literal values aren't. // Escape the name in the "require(...)" clause to ensure we find the right symbol. - const moduleName = escapeIdentifier(moduleReferenceLiteral.text); + const moduleName = escapeIdentifier(moduleReference); if (moduleName === undefined) { return; @@ -1282,7 +1285,7 @@ namespace ts { } } - const resolvedModule = getResolvedModule(getSourceFileOfNode(location), moduleReferenceLiteral.text); + const resolvedModule = getResolvedModule(getSourceFileOfNode(location), moduleReference); const sourceFile = resolvedModule && host.getSourceFile(resolvedModule.resolvedFileName); if (sourceFile) { if (sourceFile.symbol) { @@ -1291,7 +1294,7 @@ namespace ts { } if (moduleNotFoundError) { // report errors only if it was requested - error(moduleReferenceLiteral, Diagnostics.File_0_is_not_a_module, sourceFile.fileName); + error(errorNode, Diagnostics.File_0_is_not_a_module, sourceFile.fileName); } return undefined; } @@ -1305,7 +1308,7 @@ namespace ts { if (moduleNotFoundError) { // report errors only if it was requested - error(moduleReferenceLiteral, moduleNotFoundError, moduleName); + error(errorNode, moduleNotFoundError, moduleName); } return undefined; } @@ -17445,6 +17448,11 @@ namespace ts { function isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean { node = getParseTreeNode(node); + // Purely synthesized nodes are always emitted. + if (node === undefined) { + return true; + } + if (isAliasSymbolDeclaration(node)) { const symbol = getSymbolOfNode(node); if (symbol && getSymbolLinks(symbol).referenced) { @@ -17759,27 +17767,37 @@ namespace ts { function initializeTypeChecker() { // Bind all source files and propagate errors - forEach(host.getSourceFiles(), file => { + for (const file of host.getSourceFiles()) { bindSourceFile(file, compilerOptions); - }); + } - let augmentations: LiteralExpression[][]; // Initialize global symbol table - forEach(host.getSourceFiles(), file => { + let augmentations: LiteralExpression[][]; + let requestedExternalEmitHelpers: NodeFlags = 0; + let firstFileRequestingExternalHelpers: SourceFile; + for (const file of host.getSourceFiles()) { if (!isExternalOrCommonJsModule(file)) { mergeSymbolTable(globals, file.locals); } if (file.patternAmbientModules && file.patternAmbientModules.length) { patternAmbientModules = concatenate(patternAmbientModules, file.patternAmbientModules); } - if (file.moduleAugmentations.length) { (augmentations || (augmentations = [])).push(file.moduleAugmentations); } if (file.symbol && file.symbol.globalExports) { mergeSymbolTable(globals, file.symbol.globalExports); } - }); + if ((compilerOptions.isolatedModules || isExternalModule(file)) && !file.isDeclarationFile) { + const fileRequestedExternalEmitHelpers = file.flags & NodeFlags.EmitHelperFlags; + if (fileRequestedExternalEmitHelpers) { + requestedExternalEmitHelpers |= fileRequestedExternalEmitHelpers; + if (firstFileRequestingExternalHelpers === undefined) { + firstFileRequestingExternalHelpers = file; + } + } + } + } if (augmentations) { // merge module augmentations. @@ -17842,6 +17860,48 @@ namespace ts { const symbol = getGlobalSymbol("ReadonlyArray", SymbolFlags.Type, /*diagnostic*/ undefined); globalReadonlyArrayType = symbol && getTypeOfGlobalSymbol(symbol, /*arity*/ 1); anyReadonlyArrayType = globalReadonlyArrayType ? createTypeFromGenericGlobalType(globalReadonlyArrayType, [anyType]) : anyArrayType; + + // If we have specified that we are importing helpers, we should report global + // errors if we cannot resolve the helpers external module, or if it does not have + // the necessary helpers exported. + if (compilerOptions.importHelpers && firstFileRequestingExternalHelpers) { + // Find the first reference to the helpers module. + const helpersModule = resolveExternalModule( + firstFileRequestingExternalHelpers, + externalHelpersModuleNameText, + Diagnostics.Cannot_find_module_0, + /*errorNode*/ undefined); + + // If we found the module, report errors if it does not have the necessary exports. + if (helpersModule) { + const exports = helpersModule.exports; + if (requestedExternalEmitHelpers & NodeFlags.HasClassExtends && languageVersion < ScriptTarget.ES6) { + verifyHelperSymbol(exports, "__extends", SymbolFlags.Value); + } + if (requestedExternalEmitHelpers & NodeFlags.HasJsxSpreadAttributes && compilerOptions.jsx !== JsxEmit.Preserve) { + verifyHelperSymbol(exports, "__assign", SymbolFlags.Value); + } + if (requestedExternalEmitHelpers & NodeFlags.HasDecorators) { + verifyHelperSymbol(exports, "__decorate", SymbolFlags.Value); + if (compilerOptions.emitDecoratorMetadata) { + verifyHelperSymbol(exports, "__metadata", SymbolFlags.Value); + } + } + if (requestedExternalEmitHelpers & NodeFlags.HasParamDecorators) { + verifyHelperSymbol(exports, "__param", SymbolFlags.Value); + } + if (requestedExternalEmitHelpers & NodeFlags.HasAsyncFunctions) { + verifyHelperSymbol(exports, "__awaiter", SymbolFlags.Value); + } + } + } + } + + function verifyHelperSymbol(symbols: SymbolTable, name: string, meaning: SymbolFlags) { + const symbol = getSymbol(symbols, escapeIdentifier(name), meaning); + if (!symbol) { + error(/*location*/ undefined, Diagnostics.Module_0_has_no_exported_member_1, externalHelpersModuleNameText, name); + } } function createInstantiatedPromiseLikeType(): ObjectType { diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index b0b11281420f8..ec1c89f327091 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -421,6 +421,11 @@ namespace ts { name: "strictNullChecks", type: "boolean", description: Diagnostics.Enable_strict_null_checks + }, + { + name: "importHelpers", + type: "boolean", + description: Diagnostics.Import_emit_helpers_from_tslib } ]; diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b78c342481f86..8b4d18dad57f6 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2776,6 +2776,10 @@ "category": "Message", "code": 6132 }, + "Import emit helpers from 'tslib'.": { + "category": "Message", + "code": 6133 + }, "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 868ede1b0a848..9f1f5b3cdbf4d 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2106,48 +2106,56 @@ const _super = (function (geti, seti) { } function emitEmitHelpers(node: SourceFile) { - let helpersEmitted = false; - // Only emit helpers if the user did not say otherwise. - if (!compilerOptions.noEmitHelpers) { - // Only Emit __extends function when target ES5. - // For target ES6 and above, we can emit classDeclaration as is. - if ((languageVersion < ScriptTarget.ES6) && (!extendsEmitted && node.flags & NodeFlags.HasClassExtends)) { - writeLines(extendsHelper); - extendsEmitted = true; - helpersEmitted = true; - } + if (compilerOptions.noEmitHelpers) { + return false; + } - if (compilerOptions.jsx !== JsxEmit.Preserve && !assignEmitted && (node.flags & NodeFlags.HasJsxSpreadAttribute)) { - writeLines(assignHelper); - assignEmitted = true; - } + // Don't emit helpers if we can import them. + if (compilerOptions.importHelpers + && (isExternalModule(node) || compilerOptions.isolatedModules)) { + return false; + } - if (!decorateEmitted && node.flags & NodeFlags.HasDecorators) { - writeLines(decorateHelper); - if (compilerOptions.emitDecoratorMetadata) { - writeLines(metadataHelper); - } + let helpersEmitted = false; - decorateEmitted = true; - helpersEmitted = true; - } + // Only Emit __extends function when target ES5. + // For target ES6 and above, we can emit classDeclaration as is. + if ((languageVersion < ScriptTarget.ES6) && (!extendsEmitted && node.flags & NodeFlags.HasClassExtends)) { + writeLines(extendsHelper); + extendsEmitted = true; + helpersEmitted = true; + } - if (!paramEmitted && node.flags & NodeFlags.HasParamDecorators) { - writeLines(paramHelper); - paramEmitted = true; - helpersEmitted = true; - } + if (compilerOptions.jsx !== JsxEmit.Preserve && !assignEmitted && (node.flags & NodeFlags.HasJsxSpreadAttributes)) { + writeLines(assignHelper); + assignEmitted = true; + } - if (!awaiterEmitted && node.flags & NodeFlags.HasAsyncFunctions) { - writeLines(awaiterHelper); - awaiterEmitted = true; - helpersEmitted = true; + if (!decorateEmitted && node.flags & NodeFlags.HasDecorators) { + writeLines(decorateHelper); + if (compilerOptions.emitDecoratorMetadata) { + writeLines(metadataHelper); } - if (helpersEmitted) { - writeLine(); - } + decorateEmitted = true; + helpersEmitted = true; + } + + if (!paramEmitted && node.flags & NodeFlags.HasParamDecorators) { + writeLines(paramHelper); + paramEmitted = true; + helpersEmitted = true; + } + + if (!awaiterEmitted && node.flags & NodeFlags.HasAsyncFunctions) { + writeLines(awaiterHelper); + awaiterEmitted = true; + helpersEmitted = true; + } + + if (helpersEmitted) { + writeLine(); } return helpersEmitted; diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 2ea5de249010f..f879f3660e405 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -800,30 +800,31 @@ namespace ts { updated.fileName = node.fileName; updated.path = node.path; updated.text = node.text; - updated.amdDependencies = node.amdDependencies; - updated.moduleName = node.moduleName; - updated.referencedFiles = node.referencedFiles; - updated.typeReferenceDirectives = node.typeReferenceDirectives; - updated.languageVariant = node.languageVariant; - updated.isDeclarationFile = node.isDeclarationFile; - updated.renamedDependencies = node.renamedDependencies; - updated.hasNoDefaultLib = node.hasNoDefaultLib; - updated.languageVersion = node.languageVersion; - updated.scriptKind = node.scriptKind; - updated.externalModuleIndicator = node.externalModuleIndicator; - updated.commonJsModuleIndicator = node.commonJsModuleIndicator; - updated.identifiers = node.identifiers; - updated.nodeCount = node.nodeCount; - updated.identifierCount = node.identifierCount; - updated.symbolCount = node.symbolCount; - updated.parseDiagnostics = node.parseDiagnostics; - updated.bindDiagnostics = node.bindDiagnostics; - updated.lineMap = node.lineMap; - updated.classifiableNames = node.classifiableNames; - updated.resolvedModules = node.resolvedModules; - updated.resolvedTypeReferenceDirectiveNames = node.resolvedTypeReferenceDirectiveNames; - updated.imports = node.imports; - updated.moduleAugmentations = node.moduleAugmentations; + if (node.amdDependencies !== undefined) updated.amdDependencies = node.amdDependencies; + if (node.moduleName !== undefined) updated.moduleName = node.moduleName; + if (node.referencedFiles !== undefined) updated.referencedFiles = node.referencedFiles; + if (node.typeReferenceDirectives !== undefined) updated.typeReferenceDirectives = node.typeReferenceDirectives; + if (node.languageVariant !== undefined) updated.languageVariant = node.languageVariant; + if (node.isDeclarationFile !== undefined) updated.isDeclarationFile = node.isDeclarationFile; + if (node.renamedDependencies !== undefined) updated.renamedDependencies = node.renamedDependencies; + if (node.hasNoDefaultLib !== undefined) updated.hasNoDefaultLib = node.hasNoDefaultLib; + if (node.languageVersion !== undefined) updated.languageVersion = node.languageVersion; + if (node.scriptKind !== undefined) updated.scriptKind = node.scriptKind; + if (node.externalModuleIndicator !== undefined) updated.externalModuleIndicator = node.externalModuleIndicator; + if (node.commonJsModuleIndicator !== undefined) updated.commonJsModuleIndicator = node.commonJsModuleIndicator; + if (node.identifiers !== undefined) updated.identifiers = node.identifiers; + if (node.nodeCount !== undefined) updated.nodeCount = node.nodeCount; + if (node.identifierCount !== undefined) updated.identifierCount = node.identifierCount; + if (node.symbolCount !== undefined) updated.symbolCount = node.symbolCount; + if (node.parseDiagnostics !== undefined) updated.parseDiagnostics = node.parseDiagnostics; + if (node.bindDiagnostics !== undefined) updated.bindDiagnostics = node.bindDiagnostics; + if (node.lineMap !== undefined) updated.lineMap = node.lineMap; + if (node.classifiableNames !== undefined) updated.classifiableNames = node.classifiableNames; + if (node.resolvedModules !== undefined) updated.resolvedModules = node.resolvedModules; + if (node.resolvedTypeReferenceDirectiveNames !== undefined) updated.resolvedTypeReferenceDirectiveNames = node.resolvedTypeReferenceDirectiveNames; + if (node.imports !== undefined) updated.imports = node.imports; + if (node.moduleAugmentations !== undefined) updated.moduleAugmentations = node.moduleAugmentations; + if (node.externalHelpersModuleName !== undefined) updated.externalHelpersModuleName = node.externalHelpersModuleName; return updateNode(updated, node); } @@ -923,6 +924,12 @@ namespace ts { return node; } + export function createNamespaceImport(name: Identifier): NamespaceImport { + const node = createNode(SyntaxKind.NamespaceImport); + node.name = name; + return node; + } + export function createNamedImports(elements: NodeArray, location?: TextRange): NamedImports { const node = createNode(SyntaxKind.NamedImports, location); node.elements = elements; @@ -1058,9 +1065,15 @@ namespace ts { // Helpers - export function createExtendsHelper(name: Identifier) { + export function createHelperName(externalHelpersModuleName: Identifier | undefined, name: string) { + return externalHelpersModuleName + ? createPropertyAccess(externalHelpersModuleName, name) + : createIdentifier(name); + } + + export function createExtendsHelper(externalHelpersModuleName: Identifier | undefined, name: Identifier) { return createCall( - createIdentifier("__extends"), + createHelperName(externalHelpersModuleName, "__extends"), /*typeArguments*/ undefined, [ name, @@ -1069,17 +1082,17 @@ namespace ts { ); } - export function createAssignHelper(attributesSegments: Expression[]) { + export function createAssignHelper(externalHelpersModuleName: Identifier | undefined, attributesSegments: Expression[]) { return createCall( - createIdentifier("__assign"), + createHelperName(externalHelpersModuleName, "__assign"), /*typeArguments*/ undefined, attributesSegments ); } - export function createParamHelper(expression: Expression, parameterOffset: number, location?: TextRange) { + export function createParamHelper(externalHelpersModuleName: Identifier | undefined, expression: Expression, parameterOffset: number, location?: TextRange) { return createCall( - createIdentifier("__param"), + createHelperName(externalHelpersModuleName, "__param"), /*typeArguments*/ undefined, [ createLiteral(parameterOffset), @@ -1089,9 +1102,9 @@ namespace ts { ); } - export function createMetadataHelper(metadataKey: string, metadataValue: Expression) { + export function createMetadataHelper(externalHelpersModuleName: Identifier | undefined, metadataKey: string, metadataValue: Expression) { return createCall( - createIdentifier("__metadata"), + createHelperName(externalHelpersModuleName, "__metadata"), /*typeArguments*/ undefined, [ createLiteral(metadataKey), @@ -1100,7 +1113,7 @@ namespace ts { ); } - export function createDecorateHelper(decoratorExpressions: Expression[], target: Expression, memberName?: Expression, descriptor?: Expression, location?: TextRange) { + export function createDecorateHelper(externalHelpersModuleName: Identifier | undefined, decoratorExpressions: Expression[], target: Expression, memberName?: Expression, descriptor?: Expression, location?: TextRange) { const argumentsArray: Expression[] = []; argumentsArray.push(createArrayLiteral(decoratorExpressions, /*location*/ undefined, /*multiLine*/ true)); argumentsArray.push(target); @@ -1111,12 +1124,12 @@ namespace ts { } } - return createCall(createIdentifier("__decorate"), /*typeArguments*/ undefined, argumentsArray, location); + return createCall(createHelperName(externalHelpersModuleName, "__decorate"), /*typeArguments*/ undefined, argumentsArray, location); } - export function createAwaiterHelper(hasLexicalArguments: boolean, promiseConstructor: EntityName | Expression, body: Block) { + export function createAwaiterHelper(externalHelpersModuleName: Identifier | undefined, hasLexicalArguments: boolean, promiseConstructor: EntityName | Expression, body: Block) { return createCall( - createIdentifier("__awaiter"), + createHelperName(externalHelpersModuleName, "__awaiter"), /*typeArguments*/ undefined, [ createThis(), @@ -1920,7 +1933,8 @@ namespace ts { export function getLocalNameForExternalImport(node: ImportDeclaration | ExportDeclaration | ImportEqualsDeclaration, sourceFile: SourceFile): Identifier { const namespaceDeclaration = getNamespaceDeclarationNode(node); if (namespaceDeclaration && !isDefaultImport(node)) { - return createIdentifier(getSourceTextOfNodeFromSourceFile(sourceFile, namespaceDeclaration.name)); + const name = namespaceDeclaration.name; + return isGeneratedIdentifier(name) ? name : createIdentifier(getSourceTextOfNodeFromSourceFile(sourceFile, namespaceDeclaration.name)); } if (node.kind === SyntaxKind.ImportDeclaration && (node).importClause) { return getGeneratedNameForNode(node); diff --git a/src/compiler/program.ts b/src/compiler/program.ts index faff7a58d2cc9..e7470d54a1611 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1719,6 +1719,17 @@ namespace ts { let imports: LiteralExpression[]; let moduleAugmentations: LiteralExpression[]; + // If we are importing helpers, we need to add a synthetic reference to resolve the + // helpers library. + if (options.importHelpers + && (options.isolatedModules || isExternalModuleFile) + && !file.isDeclarationFile) { + const externalHelpersModuleReference = createNode(SyntaxKind.StringLiteral); + externalHelpersModuleReference.text = externalHelpersModuleNameText; + externalHelpersModuleReference.parent = file; + imports = [externalHelpersModuleReference]; + } + for (const node of file.statements) { collectModuleReferences(node, /*inAmbientModule*/ false); if (isJavaScriptFile) { diff --git a/src/compiler/transformers/es6.ts b/src/compiler/transformers/es6.ts index 2f4f090a02e5e..060ad043e7828 100644 --- a/src/compiler/transformers/es6.ts +++ b/src/compiler/transformers/es6.ts @@ -702,7 +702,7 @@ namespace ts { if (extendsClauseElement) { statements.push( createStatement( - createExtendsHelper(getDeclarationName(node)), + createExtendsHelper(currentSourceFile.externalHelpersModuleName, getDeclarationName(node)), /*location*/ extendsClauseElement ) ); diff --git a/src/compiler/transformers/jsx.ts b/src/compiler/transformers/jsx.ts index 6a90fd0ecafe9..90503d5a5f689 100644 --- a/src/compiler/transformers/jsx.ts +++ b/src/compiler/transformers/jsx.ts @@ -7,6 +7,7 @@ namespace ts { export function transformJsx(context: TransformationContext) { const compilerOptions = context.getCompilerOptions(); + let currentSourceFile: SourceFile; return transformSourceFile; /** @@ -15,7 +16,10 @@ namespace ts { * @param node A SourceFile node. */ function transformSourceFile(node: SourceFile) { - return visitEachChild(node, visitor, context); + currentSourceFile = node; + node = visitEachChild(node, visitor, context); + currentSourceFile = undefined; + return node; } function visitor(node: Node): VisitResult { @@ -102,7 +106,7 @@ namespace ts { // Either emit one big object literal (no spread attribs), or // a call to the __assign helper. objectProperties = singleOrUndefined(segments) - || createAssignHelper(segments); + || createAssignHelper(currentSourceFile.externalHelpersModuleName, segments); } const element = createReactCreateElement( diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 07182b43b333b..2faf1fe141c57 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -51,6 +51,7 @@ namespace ts { let currentNamespace: ModuleDeclaration; let currentNamespaceContainerName: Identifier; let currentScope: SourceFile | Block | ModuleBlock | CaseBlock; + let currentSourceFileExternalHelpersModuleName: Identifier; /** * Keeps track of whether expression substitution has been enabled for specific edge cases. @@ -90,11 +91,7 @@ namespace ts { * @param node A SourceFile node. */ function transformSourceFile(node: SourceFile) { - currentSourceFile = node; - currentScope = node; - const visited = visitEachChild(node, visitor, context); - setNodeEmitFlags(visited, NodeEmitFlags.EmitEmitHelpers | getNodeEmitFlags(node)); - return visited; + return visitNode(node, visitor, isSourceFile); } /** @@ -132,7 +129,10 @@ namespace ts { * @param node The node to visit. */ function visitorWorker(node: Node): VisitResult { - if (node.transformFlags & TransformFlags.TypeScript) { + if (node.kind === SyntaxKind.SourceFile) { + return visitSourceFile(node); + } + else if (node.transformFlags & TransformFlags.TypeScript) { // This node is explicitly marked as TypeScript, so we should transform the node. return visitTypeScript(node); } @@ -420,6 +420,43 @@ namespace ts { } } + function visitSourceFile(node: SourceFile) { + currentSourceFile = node; + + // If the source file requires any helpers and is an external module, and + // the importHelpers compiler option is enabled, emit a synthesized import + // statement for the helpers library. + if (node.flags & NodeFlags.EmitHelperFlags + && compilerOptions.importHelpers + && (isExternalModule(node) || compilerOptions.isolatedModules)) { + startLexicalEnvironment(); + const statements: Statement[] = []; + const statementOffset = addPrologueDirectives(statements, node.statements); + const externalHelpersModuleName = createUniqueName(externalHelpersModuleNameText); + const externalHelpersModuleImport = createImportDeclaration( + createImportClause(/*name*/ undefined, createNamespaceImport(externalHelpersModuleName)), + createLiteral(externalHelpersModuleNameText) + ); + externalHelpersModuleImport.parent = node; + externalHelpersModuleImport.flags &= ~NodeFlags.Synthesized; + statements.push(externalHelpersModuleImport); + + currentSourceFileExternalHelpersModuleName = externalHelpersModuleName; + addRange(statements, visitNodes(node.statements, visitor, isStatement, statementOffset)); + addRange(statements, endLexicalEnvironment()); + currentSourceFileExternalHelpersModuleName = undefined; + + node = updateSourceFileNode(node, createNodeArray(statements, node.statements)); + node.externalHelpersModuleName = externalHelpersModuleName; + } + else { + node = visitEachChild(node, visitor, context); + } + + setNodeEmitFlags(node, NodeEmitFlags.EmitEmitHelpers | node.emitFlags); + return node; + } + /** * Tests whether we should emit a __decorate call for a class declaration. */ @@ -1345,6 +1382,7 @@ namespace ts { : undefined; const helper = createDecorateHelper( + currentSourceFileExternalHelpersModuleName, decoratorExpressions, prefix, memberName, @@ -1394,6 +1432,7 @@ namespace ts { const expression = createAssignment( decoratedClassAlias, createDecorateHelper( + currentSourceFileExternalHelpersModuleName, decoratorExpressions, getDeclarationName(node) ) @@ -1417,6 +1456,7 @@ namespace ts { const result = createAssignment( getDeclarationName(node), createDecorateHelper( + currentSourceFileExternalHelpersModuleName, decoratorExpressions, getDeclarationName(node) ), @@ -1448,7 +1488,11 @@ namespace ts { if (decorators) { expressions = []; for (const decorator of decorators) { - const helper = createParamHelper(transformDecorator(decorator), parameterOffset, /*location*/ decorator.expression); + const helper = createParamHelper( + currentSourceFileExternalHelpersModuleName, + transformDecorator(decorator), + parameterOffset, + /*location*/ decorator.expression); setNodeEmitFlags(helper, NodeEmitFlags.NoComments); expressions.push(helper); } @@ -1475,13 +1519,13 @@ namespace ts { function addOldTypeMetadata(node: Declaration, decoratorExpressions: Expression[]) { if (compilerOptions.emitDecoratorMetadata) { if (shouldAddTypeMetadata(node)) { - decoratorExpressions.push(createMetadataHelper("design:type", serializeTypeOfNode(node))); + decoratorExpressions.push(createMetadataHelper(currentSourceFileExternalHelpersModuleName, "design:type", serializeTypeOfNode(node))); } if (shouldAddParamTypesMetadata(node)) { - decoratorExpressions.push(createMetadataHelper("design:paramtypes", serializeParameterTypesOfNode(node))); + decoratorExpressions.push(createMetadataHelper(currentSourceFileExternalHelpersModuleName, "design:paramtypes", serializeParameterTypesOfNode(node))); } if (shouldAddReturnTypeMetadata(node)) { - decoratorExpressions.push(createMetadataHelper("design:returntype", serializeReturnTypeOfNode(node))); + decoratorExpressions.push(createMetadataHelper(currentSourceFileExternalHelpersModuleName, "design:returntype", serializeReturnTypeOfNode(node))); } } } @@ -1499,7 +1543,7 @@ namespace ts { (properties || (properties = [])).push(createPropertyAssignment("returnType", createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, [], /*type*/ undefined, /*equalsGreaterThanToken*/ undefined, serializeReturnTypeOfNode(node)))); } if (properties) { - decoratorExpressions.push(createMetadataHelper("design:typeinfo", createObjectLiteral(properties, /*location*/ undefined, /*multiLine*/ true))); + decoratorExpressions.push(createMetadataHelper(currentSourceFileExternalHelpersModuleName, "design:typeinfo", createObjectLiteral(properties, /*location*/ undefined, /*multiLine*/ true))); } } } @@ -2193,6 +2237,7 @@ namespace ts { statements.push( createReturn( createAwaiterHelper( + currentSourceFileExternalHelpersModuleName, hasLexicalArguments, promiseConstructor, transformFunctionBodyWorker(node.body) @@ -2219,6 +2264,7 @@ namespace ts { } else { return createAwaiterHelper( + currentSourceFileExternalHelpersModuleName, hasLexicalArguments, promiseConstructor, transformConciseBodyWorker(node.body, /*forceBlockFunctionBody*/ true) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 6c82fe07a4e9c..376a567017b30 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -388,34 +388,34 @@ namespace ts { export const enum NodeFlags { None = 0, - Let = 1 << 0, // Variable declaration - Const = 1 << 1, // Variable declaration - NestedNamespace = 1 << 2, // Namespace declaration - Synthesized = 1 << 3, // Node was synthesized during transformation - Namespace = 1 << 12, // Namespace declaration - ExportContext = 1 << 13, // Export context (initialized by binding) - ContainsThis = 1 << 14, // Interface contains references to "this" - HasImplicitReturn = 1 << 15, // If function implicitly returns on one of codepaths (initialized by binding) - HasExplicitReturn = 1 << 16, // If function has explicit reachable return on one of codepaths (initialized by binding) - GlobalAugmentation = 1 << 17, // Set if module declaration is an augmentation for the global scope - HasClassExtends = 1 << 18, // If the file has a non-ambient class with an extends clause in ES5 or lower (initialized by binding) - HasDecorators = 1 << 19, // If the file has decorators (initialized by binding) - HasParamDecorators = 1 << 20, // If the file has parameter decorators (initialized by binding) - HasAsyncFunctions = 1 << 21, // If the file has async functions (initialized by binding) - DisallowInContext = 1 << 22, // If node was parsed in a context where 'in-expressions' are not allowed - YieldContext = 1 << 23, // If node was parsed in the 'yield' context created when parsing a generator - DecoratorContext = 1 << 24, // If node was parsed as part of a decorator - AwaitContext = 1 << 25, // If node was parsed in the 'await' context created when parsing an async function - ThisNodeHasError = 1 << 26, // If the parser encountered an error when parsing the code that created this node - JavaScriptFile = 1 << 27, // If node was parsed in a JavaScript - ThisNodeOrAnySubNodesHasError = 1 << 28, // If this node or any of its children had an error - HasAggregatedChildData = 1 << 29, // If we've computed data from children and cached it in this node - HasJsxSpreadAttribute = 1 << 30, + Let = 1 << 0, // Variable declaration + Const = 1 << 1, // Variable declaration + NestedNamespace = 1 << 2, // Namespace declaration + Synthesized = 1 << 3, // Node was synthesized during transformation + Namespace = 1 << 4, // Namespace declaration + ExportContext = 1 << 5, // Export context (initialized by binding) + ContainsThis = 1 << 6, // Interface contains references to "this" + HasImplicitReturn = 1 << 7, // If function implicitly returns on one of codepaths (initialized by binding) + HasExplicitReturn = 1 << 8, // If function has explicit reachable return on one of codepaths (initialized by binding) + GlobalAugmentation = 1 << 9, // Set if module declaration is an augmentation for the global scope + HasClassExtends = 1 << 10, // If the file has a non-ambient class with an extends clause in ES5 or lower (initialized by binding) + HasDecorators = 1 << 11, // If the file has decorators (initialized by binding) + HasParamDecorators = 1 << 12, // If the file has parameter decorators (initialized by binding) + HasAsyncFunctions = 1 << 13, // If the file has async functions (initialized by binding) + HasJsxSpreadAttributes = 1 << 14, // If the file as JSX spread attributes (initialized by binding) + DisallowInContext = 1 << 15, // If node was parsed in a context where 'in-expressions' are not allowed + YieldContext = 1 << 16, // If node was parsed in the 'yield' context created when parsing a generator + DecoratorContext = 1 << 17, // If node was parsed as part of a decorator + AwaitContext = 1 << 18, // If node was parsed in the 'await' context created when parsing an async function + ThisNodeHasError = 1 << 19, // If the parser encountered an error when parsing the code that created this node + JavaScriptFile = 1 << 20, // If node was parsed in a JavaScript + ThisNodeOrAnySubNodesHasError = 1 << 21, // If this node or any of its children had an error + HasAggregatedChildData = 1 << 22, // If we've computed data from children and cached it in this node BlockScoped = Let | Const, ReachabilityCheckFlags = HasImplicitReturn | HasExplicitReturn, - EmitHelperFlags = HasClassExtends | HasDecorators | HasParamDecorators | HasAsyncFunctions, + EmitHelperFlags = HasClassExtends | HasDecorators | HasParamDecorators | HasAsyncFunctions | HasJsxSpreadAttributes, ReachabilityAndEmitFlags = ReachabilityCheckFlags | EmitHelperFlags, // Parsing context flags @@ -1726,6 +1726,8 @@ namespace ts { /* @internal */ imports: LiteralExpression[]; /* @internal */ moduleAugmentations: LiteralExpression[]; /* @internal */ patternAmbientModules?: PatternAmbientModule[]; + // The synthesized identifier for an imported external helpers module. + /* @internal */ externalHelpersModuleName?: Identifier; } export interface ScriptReferenceHost { @@ -2583,6 +2585,7 @@ namespace ts { experimentalDecorators?: boolean; forceConsistentCasingInFileNames?: boolean; /*@internal*/help?: boolean; + importHelpers?: boolean; /*@internal*/init?: boolean; inlineSourceMap?: boolean; inlineSources?: boolean; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index cd3655f325cc0..13d424ccc363d 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2,6 +2,8 @@ /* @internal */ namespace ts { + export const externalHelpersModuleNameText = "tslib"; + export interface ReferencePathMatchResult { fileReference?: FileReference; diagnosticMessage?: DiagnosticMessage; @@ -117,7 +119,7 @@ namespace ts { } export function hasResolvedModule(sourceFile: SourceFile, moduleNameText: string): boolean { - return sourceFile.resolvedModules && hasProperty(sourceFile.resolvedModules, moduleNameText); + return sourceFile && sourceFile.resolvedModules && hasProperty(sourceFile.resolvedModules, moduleNameText); } export function getResolvedModule(sourceFile: SourceFile, moduleNameText: string): ResolvedModule { diff --git a/tests/baselines/reference/importHelpers.js b/tests/baselines/reference/importHelpers.js new file mode 100644 index 0000000000000..f850b5cf17727 --- /dev/null +++ b/tests/baselines/reference/importHelpers.js @@ -0,0 +1,116 @@ +//// [tests/cases/compiler/importHelpers.ts] //// + +//// [external.ts] +export class A { } +export class B extends A { } + +declare var dec: any; + +@dec +class C { + method(@dec x: number) { + } +} + +//// [script.ts] +class A { } +class B extends A { } + +declare var dec: any; + +@dec +class C { + method(@dec x: number) { + } +} + +//// [tslib.d.ts] +export declare function __extends(d: Function, b: Function): void; +export declare function __assign(t: any, ...sources: any[]): any; +export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; +export declare function __param(paramIndex: number, decorator: Function): Function; +export declare function __metadata(metadataKey: any, metadataValue: any): Function; +export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; + + +//// [external.js] +"use strict"; +var tslib_1 = require("tslib"); +var A = (function () { + function A() { + } + return A; +}()); +exports.A = A; +var B = (function (_super) { + tslib_1.__extends(B, _super); + function B() { + _super.apply(this, arguments); + } + return B; +}(A)); +exports.B = B; +var C = (function () { + function C() { + } + C.prototype.method = function (x) { + }; + return C; +}()); +tslib_1.__decorate([ + tslib_1.__param(0, dec), + tslib_1.__metadata("design:type", Function), + tslib_1.__metadata("design:paramtypes", [Number]), + tslib_1.__metadata("design:returntype", void 0) +], C.prototype, "method", null); +C = tslib_1.__decorate([ + dec, + tslib_1.__metadata("design:paramtypes", []) +], C); +//// [script.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +var __param = (this && this.__param) || function (paramIndex, decorator) { + return function (target, key) { decorator(target, key, paramIndex); } +}; +var A = (function () { + function A() { + } + return A; +}()); +var B = (function (_super) { + __extends(B, _super); + function B() { + _super.apply(this, arguments); + } + return B; +}(A)); +var C = (function () { + function C() { + } + C.prototype.method = function (x) { + }; + return C; +}()); +__decorate([ + __param(0, dec), + __metadata("design:type", Function), + __metadata("design:paramtypes", [Number]), + __metadata("design:returntype", void 0) +], C.prototype, "method", null); +C = __decorate([ + dec, + __metadata("design:paramtypes", []) +], C); diff --git a/tests/baselines/reference/importHelpers.symbols b/tests/baselines/reference/importHelpers.symbols new file mode 100644 index 0000000000000..55ca5153e32cc --- /dev/null +++ b/tests/baselines/reference/importHelpers.symbols @@ -0,0 +1,91 @@ +=== tests/cases/compiler/external.ts === +export class A { } +>A : Symbol(A, Decl(external.ts, 0, 0)) + +export class B extends A { } +>B : Symbol(B, Decl(external.ts, 0, 18)) +>A : Symbol(A, Decl(external.ts, 0, 0)) + +declare var dec: any; +>dec : Symbol(dec, Decl(external.ts, 3, 11)) + +@dec +>dec : Symbol(dec, Decl(external.ts, 3, 11)) + +class C { +>C : Symbol(C, Decl(external.ts, 3, 21)) + + method(@dec x: number) { +>method : Symbol(C.method, Decl(external.ts, 6, 9)) +>dec : Symbol(dec, Decl(external.ts, 3, 11)) +>x : Symbol(x, Decl(external.ts, 7, 11)) + } +} + +=== tests/cases/compiler/script.ts === +class A { } +>A : Symbol(A, Decl(script.ts, 0, 0)) + +class B extends A { } +>B : Symbol(B, Decl(script.ts, 0, 11)) +>A : Symbol(A, Decl(script.ts, 0, 0)) + +declare var dec: any; +>dec : Symbol(dec, Decl(script.ts, 3, 11)) + +@dec +>dec : Symbol(dec, Decl(script.ts, 3, 11)) + +class C { +>C : Symbol(C, Decl(script.ts, 3, 21)) + + method(@dec x: number) { +>method : Symbol(C.method, Decl(script.ts, 6, 9)) +>dec : Symbol(dec, Decl(script.ts, 3, 11)) +>x : Symbol(x, Decl(script.ts, 7, 11)) + } +} + +=== tests/cases/compiler/tslib.d.ts === +export declare function __extends(d: Function, b: Function): void; +>__extends : Symbol(__extends, Decl(tslib.d.ts, --, --)) +>d : Symbol(d, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>b : Symbol(b, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +export declare function __assign(t: any, ...sources: any[]): any; +>__assign : Symbol(__assign, Decl(tslib.d.ts, --, --)) +>t : Symbol(t, Decl(tslib.d.ts, --, --)) +>sources : Symbol(sources, Decl(tslib.d.ts, --, --)) + +export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; +>__decorate : Symbol(__decorate, Decl(tslib.d.ts, --, --)) +>decorators : Symbol(decorators, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>target : Symbol(target, Decl(tslib.d.ts, --, --)) +>key : Symbol(key, Decl(tslib.d.ts, --, --)) +>desc : Symbol(desc, Decl(tslib.d.ts, --, --)) + +export declare function __param(paramIndex: number, decorator: Function): Function; +>__param : Symbol(__param, Decl(tslib.d.ts, --, --)) +>paramIndex : Symbol(paramIndex, Decl(tslib.d.ts, --, --)) +>decorator : Symbol(decorator, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +export declare function __metadata(metadataKey: any, metadataValue: any): Function; +>__metadata : Symbol(__metadata, Decl(tslib.d.ts, --, --)) +>metadataKey : Symbol(metadataKey, Decl(tslib.d.ts, --, --)) +>metadataValue : Symbol(metadataValue, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; +>__awaiter : Symbol(__awaiter, Decl(tslib.d.ts, --, --)) +>thisArg : Symbol(thisArg, Decl(tslib.d.ts, --, --)) +>_arguments : Symbol(_arguments, Decl(tslib.d.ts, --, --)) +>P : Symbol(P, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>generator : Symbol(generator, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + diff --git a/tests/baselines/reference/importHelpers.types b/tests/baselines/reference/importHelpers.types new file mode 100644 index 0000000000000..0ab8d40ee853f --- /dev/null +++ b/tests/baselines/reference/importHelpers.types @@ -0,0 +1,91 @@ +=== tests/cases/compiler/external.ts === +export class A { } +>A : A + +export class B extends A { } +>B : B +>A : A + +declare var dec: any; +>dec : any + +@dec +>dec : any + +class C { +>C : C + + method(@dec x: number) { +>method : (x: number) => void +>dec : any +>x : number + } +} + +=== tests/cases/compiler/script.ts === +class A { } +>A : A + +class B extends A { } +>B : B +>A : A + +declare var dec: any; +>dec : any + +@dec +>dec : any + +class C { +>C : C + + method(@dec x: number) { +>method : (x: number) => void +>dec : any +>x : number + } +} + +=== tests/cases/compiler/tslib.d.ts === +export declare function __extends(d: Function, b: Function): void; +>__extends : (d: Function, b: Function) => void +>d : Function +>Function : Function +>b : Function +>Function : Function + +export declare function __assign(t: any, ...sources: any[]): any; +>__assign : (t: any, ...sources: any[]) => any +>t : any +>sources : any[] + +export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; +>__decorate : (decorators: Function[], target: any, key?: string | symbol, desc?: any) => any +>decorators : Function[] +>Function : Function +>target : any +>key : string | symbol +>desc : any + +export declare function __param(paramIndex: number, decorator: Function): Function; +>__param : (paramIndex: number, decorator: Function) => Function +>paramIndex : number +>decorator : Function +>Function : Function +>Function : Function + +export declare function __metadata(metadataKey: any, metadataValue: any): Function; +>__metadata : (metadataKey: any, metadataValue: any) => Function +>metadataKey : any +>metadataValue : any +>Function : Function + +export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; +>__awaiter : (thisArg: any, _arguments: any, P: Function, generator: Function) => any +>thisArg : any +>_arguments : any +>P : Function +>Function : Function +>generator : Function +>Function : Function + diff --git a/tests/baselines/reference/importHelpersAmd.js b/tests/baselines/reference/importHelpersAmd.js new file mode 100644 index 0000000000000..bb02cbf04173a --- /dev/null +++ b/tests/baselines/reference/importHelpersAmd.js @@ -0,0 +1,40 @@ +//// [tests/cases/compiler/importHelpersAmd.ts] //// + +//// [a.ts] +export class A { } + +//// [b.ts] +import { A } from "./a"; +export class B extends A { } + +//// [tslib.d.ts] +export declare function __extends(d: Function, b: Function): void; +export declare function __assign(t: any, ...sources: any[]): any; +export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; +export declare function __param(paramIndex: number, decorator: Function): Function; +export declare function __metadata(metadataKey: any, metadataValue: any): Function; +export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; + + +//// [a.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + var A = (function () { + function A() { + } + return A; + }()); + exports.A = A; +}); +//// [b.js] +define(["require", "exports", "tslib", "./a"], function (require, exports, tslib_1, a_1) { + "use strict"; + var B = (function (_super) { + tslib_1.__extends(B, _super); + function B() { + _super.apply(this, arguments); + } + return B; + }(a_1.A)); + exports.B = B; +}); diff --git a/tests/baselines/reference/importHelpersAmd.symbols b/tests/baselines/reference/importHelpersAmd.symbols new file mode 100644 index 0000000000000..47528a8bba6b9 --- /dev/null +++ b/tests/baselines/reference/importHelpersAmd.symbols @@ -0,0 +1,55 @@ +=== tests/cases/compiler/a.ts === +export class A { } +>A : Symbol(A, Decl(a.ts, 0, 0)) + +=== tests/cases/compiler/b.ts === +import { A } from "./a"; +>A : Symbol(A, Decl(b.ts, 0, 8)) + +export class B extends A { } +>B : Symbol(B, Decl(b.ts, 0, 24)) +>A : Symbol(A, Decl(b.ts, 0, 8)) + +=== tests/cases/compiler/tslib.d.ts === +export declare function __extends(d: Function, b: Function): void; +>__extends : Symbol(__extends, Decl(tslib.d.ts, --, --)) +>d : Symbol(d, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>b : Symbol(b, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +export declare function __assign(t: any, ...sources: any[]): any; +>__assign : Symbol(__assign, Decl(tslib.d.ts, --, --)) +>t : Symbol(t, Decl(tslib.d.ts, --, --)) +>sources : Symbol(sources, Decl(tslib.d.ts, --, --)) + +export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; +>__decorate : Symbol(__decorate, Decl(tslib.d.ts, --, --)) +>decorators : Symbol(decorators, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>target : Symbol(target, Decl(tslib.d.ts, --, --)) +>key : Symbol(key, Decl(tslib.d.ts, --, --)) +>desc : Symbol(desc, Decl(tslib.d.ts, --, --)) + +export declare function __param(paramIndex: number, decorator: Function): Function; +>__param : Symbol(__param, Decl(tslib.d.ts, --, --)) +>paramIndex : Symbol(paramIndex, Decl(tslib.d.ts, --, --)) +>decorator : Symbol(decorator, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +export declare function __metadata(metadataKey: any, metadataValue: any): Function; +>__metadata : Symbol(__metadata, Decl(tslib.d.ts, --, --)) +>metadataKey : Symbol(metadataKey, Decl(tslib.d.ts, --, --)) +>metadataValue : Symbol(metadataValue, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; +>__awaiter : Symbol(__awaiter, Decl(tslib.d.ts, --, --)) +>thisArg : Symbol(thisArg, Decl(tslib.d.ts, --, --)) +>_arguments : Symbol(_arguments, Decl(tslib.d.ts, --, --)) +>P : Symbol(P, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>generator : Symbol(generator, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + diff --git a/tests/baselines/reference/importHelpersAmd.types b/tests/baselines/reference/importHelpersAmd.types new file mode 100644 index 0000000000000..9ff756ffaab94 --- /dev/null +++ b/tests/baselines/reference/importHelpersAmd.types @@ -0,0 +1,55 @@ +=== tests/cases/compiler/a.ts === +export class A { } +>A : A + +=== tests/cases/compiler/b.ts === +import { A } from "./a"; +>A : typeof A + +export class B extends A { } +>B : B +>A : A + +=== tests/cases/compiler/tslib.d.ts === +export declare function __extends(d: Function, b: Function): void; +>__extends : (d: Function, b: Function) => void +>d : Function +>Function : Function +>b : Function +>Function : Function + +export declare function __assign(t: any, ...sources: any[]): any; +>__assign : (t: any, ...sources: any[]) => any +>t : any +>sources : any[] + +export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; +>__decorate : (decorators: Function[], target: any, key?: string | symbol, desc?: any) => any +>decorators : Function[] +>Function : Function +>target : any +>key : string | symbol +>desc : any + +export declare function __param(paramIndex: number, decorator: Function): Function; +>__param : (paramIndex: number, decorator: Function) => Function +>paramIndex : number +>decorator : Function +>Function : Function +>Function : Function + +export declare function __metadata(metadataKey: any, metadataValue: any): Function; +>__metadata : (metadataKey: any, metadataValue: any) => Function +>metadataKey : any +>metadataValue : any +>Function : Function + +export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; +>__awaiter : (thisArg: any, _arguments: any, P: Function, generator: Function) => any +>thisArg : any +>_arguments : any +>P : Function +>Function : Function +>generator : Function +>Function : Function + diff --git a/tests/baselines/reference/importHelpersES6.js b/tests/baselines/reference/importHelpersES6.js new file mode 100644 index 0000000000000..209f3c34588e4 --- /dev/null +++ b/tests/baselines/reference/importHelpersES6.js @@ -0,0 +1,25 @@ +//// [tests/cases/compiler/importHelpersES6.ts] //// + +//// [a.ts] +declare var dec: any; +@dec export class A { + +} + +//// [tslib.d.ts] +export declare function __extends(d: Function, b: Function): void; +export declare function __assign(t: any, ...sources: any[]): any; +export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; +export declare function __param(paramIndex: number, decorator: Function): Function; +export declare function __metadata(metadataKey: any, metadataValue: any): Function; +export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; + + +//// [a.js] +import * as tslib_1 from "tslib"; +let A = class A { +}; +A = tslib_1.__decorate([ + dec +], A); +export { A }; diff --git a/tests/baselines/reference/importHelpersES6.symbols b/tests/baselines/reference/importHelpersES6.symbols new file mode 100644 index 0000000000000..284a2251a6bed --- /dev/null +++ b/tests/baselines/reference/importHelpersES6.symbols @@ -0,0 +1,53 @@ +=== tests/cases/compiler/a.ts === +declare var dec: any; +>dec : Symbol(dec, Decl(a.ts, 0, 11)) + +@dec export class A { +>dec : Symbol(dec, Decl(a.ts, 0, 11)) +>A : Symbol(A, Decl(a.ts, 0, 21)) + +} + +=== tests/cases/compiler/tslib.d.ts === +export declare function __extends(d: Function, b: Function): void; +>__extends : Symbol(__extends, Decl(tslib.d.ts, --, --)) +>d : Symbol(d, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>b : Symbol(b, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) + +export declare function __assign(t: any, ...sources: any[]): any; +>__assign : Symbol(__assign, Decl(tslib.d.ts, --, --)) +>t : Symbol(t, Decl(tslib.d.ts, --, --)) +>sources : Symbol(sources, Decl(tslib.d.ts, --, --)) + +export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; +>__decorate : Symbol(__decorate, Decl(tslib.d.ts, --, --)) +>decorators : Symbol(decorators, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>target : Symbol(target, Decl(tslib.d.ts, --, --)) +>key : Symbol(key, Decl(tslib.d.ts, --, --)) +>desc : Symbol(desc, Decl(tslib.d.ts, --, --)) + +export declare function __param(paramIndex: number, decorator: Function): Function; +>__param : Symbol(__param, Decl(tslib.d.ts, --, --)) +>paramIndex : Symbol(paramIndex, Decl(tslib.d.ts, --, --)) +>decorator : Symbol(decorator, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) + +export declare function __metadata(metadataKey: any, metadataValue: any): Function; +>__metadata : Symbol(__metadata, Decl(tslib.d.ts, --, --)) +>metadataKey : Symbol(metadataKey, Decl(tslib.d.ts, --, --)) +>metadataValue : Symbol(metadataValue, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) + +export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; +>__awaiter : Symbol(__awaiter, Decl(tslib.d.ts, --, --)) +>thisArg : Symbol(thisArg, Decl(tslib.d.ts, --, --)) +>_arguments : Symbol(_arguments, Decl(tslib.d.ts, --, --)) +>P : Symbol(P, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>generator : Symbol(generator, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) + diff --git a/tests/baselines/reference/importHelpersES6.types b/tests/baselines/reference/importHelpersES6.types new file mode 100644 index 0000000000000..ebfd5a5a2a51b --- /dev/null +++ b/tests/baselines/reference/importHelpersES6.types @@ -0,0 +1,53 @@ +=== tests/cases/compiler/a.ts === +declare var dec: any; +>dec : any + +@dec export class A { +>dec : any +>A : A + +} + +=== tests/cases/compiler/tslib.d.ts === +export declare function __extends(d: Function, b: Function): void; +>__extends : (d: Function, b: Function) => void +>d : Function +>Function : Function +>b : Function +>Function : Function + +export declare function __assign(t: any, ...sources: any[]): any; +>__assign : (t: any, ...sources: any[]) => any +>t : any +>sources : any[] + +export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; +>__decorate : (decorators: Function[], target: any, key?: string | symbol, desc?: any) => any +>decorators : Function[] +>Function : Function +>target : any +>key : string | symbol +>desc : any + +export declare function __param(paramIndex: number, decorator: Function): Function; +>__param : (paramIndex: number, decorator: Function) => Function +>paramIndex : number +>decorator : Function +>Function : Function +>Function : Function + +export declare function __metadata(metadataKey: any, metadataValue: any): Function; +>__metadata : (metadataKey: any, metadataValue: any) => Function +>metadataKey : any +>metadataValue : any +>Function : Function + +export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; +>__awaiter : (thisArg: any, _arguments: any, P: Function, generator: Function) => any +>thisArg : any +>_arguments : any +>P : Function +>Function : Function +>generator : Function +>Function : Function + diff --git a/tests/baselines/reference/importHelpersInIsolatedModules.errors.txt b/tests/baselines/reference/importHelpersInIsolatedModules.errors.txt new file mode 100644 index 0000000000000..7a53c1c8c9954 --- /dev/null +++ b/tests/baselines/reference/importHelpersInIsolatedModules.errors.txt @@ -0,0 +1,37 @@ +tests/cases/compiler/script.ts(1,1): error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. + + +==== tests/cases/compiler/external.ts (0 errors) ==== + export class A { } + export class B extends A { } + + declare var dec: any; + + @dec + class C { + method(@dec x: number) { + } + } + +==== tests/cases/compiler/script.ts (1 errors) ==== + class A { } + ~~~~~ +!!! error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. + class B extends A { } + + declare var dec: any; + + @dec + class C { + method(@dec x: number) { + } + } + +==== tests/cases/compiler/tslib.d.ts (0 errors) ==== + export declare function __extends(d: Function, b: Function): void; + export declare function __assign(t: any, ...sources: any[]): any; + export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; + export declare function __param(paramIndex: number, decorator: Function): Function; + export declare function __metadata(metadataKey: any, metadataValue: any): Function; + export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; + \ No newline at end of file diff --git a/tests/baselines/reference/importHelpersInIsolatedModules.js b/tests/baselines/reference/importHelpersInIsolatedModules.js new file mode 100644 index 0000000000000..a5929bc152cf2 --- /dev/null +++ b/tests/baselines/reference/importHelpersInIsolatedModules.js @@ -0,0 +1,101 @@ +//// [tests/cases/compiler/importHelpersInIsolatedModules.ts] //// + +//// [external.ts] +export class A { } +export class B extends A { } + +declare var dec: any; + +@dec +class C { + method(@dec x: number) { + } +} + +//// [script.ts] +class A { } +class B extends A { } + +declare var dec: any; + +@dec +class C { + method(@dec x: number) { + } +} + +//// [tslib.d.ts] +export declare function __extends(d: Function, b: Function): void; +export declare function __assign(t: any, ...sources: any[]): any; +export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; +export declare function __param(paramIndex: number, decorator: Function): Function; +export declare function __metadata(metadataKey: any, metadataValue: any): Function; +export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; + + +//// [external.js] +"use strict"; +var tslib_1 = require("tslib"); +var A = (function () { + function A() { + } + return A; +}()); +exports.A = A; +var B = (function (_super) { + tslib_1.__extends(B, _super); + function B() { + _super.apply(this, arguments); + } + return B; +}(A)); +exports.B = B; +var C = (function () { + function C() { + } + C.prototype.method = function (x) { + }; + return C; +}()); +tslib_1.__decorate([ + tslib_1.__param(0, dec), + tslib_1.__metadata("design:type", Function), + tslib_1.__metadata("design:paramtypes", [Number]), + tslib_1.__metadata("design:returntype", void 0) +], C.prototype, "method", null); +C = tslib_1.__decorate([ + dec, + tslib_1.__metadata("design:paramtypes", []) +], C); +//// [script.js] +"use strict"; +var tslib_1 = require("tslib"); +var A = (function () { + function A() { + } + return A; +}()); +var B = (function (_super) { + tslib_1.__extends(B, _super); + function B() { + _super.apply(this, arguments); + } + return B; +}(A)); +var C = (function () { + function C() { + } + C.prototype.method = function (x) { + }; + return C; +}()); +tslib_1.__decorate([ + tslib_1.__param(0, dec), + tslib_1.__metadata("design:type", Function), + tslib_1.__metadata("design:paramtypes", [Number]), + tslib_1.__metadata("design:returntype", void 0) +], C.prototype, "method", null); +C = tslib_1.__decorate([ + dec, + tslib_1.__metadata("design:paramtypes", []) +], C); diff --git a/tests/baselines/reference/importHelpersInTsx.js b/tests/baselines/reference/importHelpersInTsx.js new file mode 100644 index 0000000000000..29e43e191e8aa --- /dev/null +++ b/tests/baselines/reference/importHelpersInTsx.js @@ -0,0 +1,35 @@ +//// [tests/cases/compiler/importHelpersInTsx.tsx] //// + +//// [external.tsx] +declare var React: any; +declare var o: any; +export const x = + +//// [script.tsx] +declare var React: any; +declare var o: any; +const x = + +//// [tslib.d.ts] +export declare function __extends(d: Function, b: Function): void; +export declare function __assign(t: any, ...sources: any[]): any; +export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; +export declare function __param(paramIndex: number, decorator: Function): Function; +export declare function __metadata(metadataKey: any, metadataValue: any): Function; +export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; + + +//// [external.js] +"use strict"; +var tslib_1 = require("tslib"); +exports.x = React.createElement("span", tslib_1.__assign({}, o)); +//// [script.js] +var __assign = (this && this.__assign) || Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; +}; +var x = React.createElement("span", __assign({}, o)); diff --git a/tests/baselines/reference/importHelpersInTsx.symbols b/tests/baselines/reference/importHelpersInTsx.symbols new file mode 100644 index 0000000000000..465ce502385f1 --- /dev/null +++ b/tests/baselines/reference/importHelpersInTsx.symbols @@ -0,0 +1,67 @@ +=== tests/cases/compiler/external.tsx === +declare var React: any; +>React : Symbol(React, Decl(external.tsx, 0, 11)) + +declare var o: any; +>o : Symbol(o, Decl(external.tsx, 1, 11)) + +export const x = +>x : Symbol(x, Decl(external.tsx, 2, 12)) +>span : Symbol(unknown) +>o : Symbol(o, Decl(external.tsx, 1, 11)) + +=== tests/cases/compiler/script.tsx === +declare var React: any; +>React : Symbol(React, Decl(script.tsx, 0, 11)) + +declare var o: any; +>o : Symbol(o, Decl(script.tsx, 1, 11)) + +const x = +>x : Symbol(x, Decl(script.tsx, 2, 5)) +>span : Symbol(unknown) +>o : Symbol(o, Decl(script.tsx, 1, 11)) + +=== tests/cases/compiler/tslib.d.ts === +export declare function __extends(d: Function, b: Function): void; +>__extends : Symbol(__extends, Decl(tslib.d.ts, --, --)) +>d : Symbol(d, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>b : Symbol(b, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +export declare function __assign(t: any, ...sources: any[]): any; +>__assign : Symbol(__assign, Decl(tslib.d.ts, --, --)) +>t : Symbol(t, Decl(tslib.d.ts, --, --)) +>sources : Symbol(sources, Decl(tslib.d.ts, --, --)) + +export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; +>__decorate : Symbol(__decorate, Decl(tslib.d.ts, --, --)) +>decorators : Symbol(decorators, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>target : Symbol(target, Decl(tslib.d.ts, --, --)) +>key : Symbol(key, Decl(tslib.d.ts, --, --)) +>desc : Symbol(desc, Decl(tslib.d.ts, --, --)) + +export declare function __param(paramIndex: number, decorator: Function): Function; +>__param : Symbol(__param, Decl(tslib.d.ts, --, --)) +>paramIndex : Symbol(paramIndex, Decl(tslib.d.ts, --, --)) +>decorator : Symbol(decorator, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +export declare function __metadata(metadataKey: any, metadataValue: any): Function; +>__metadata : Symbol(__metadata, Decl(tslib.d.ts, --, --)) +>metadataKey : Symbol(metadataKey, Decl(tslib.d.ts, --, --)) +>metadataValue : Symbol(metadataValue, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; +>__awaiter : Symbol(__awaiter, Decl(tslib.d.ts, --, --)) +>thisArg : Symbol(thisArg, Decl(tslib.d.ts, --, --)) +>_arguments : Symbol(_arguments, Decl(tslib.d.ts, --, --)) +>P : Symbol(P, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>generator : Symbol(generator, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + diff --git a/tests/baselines/reference/importHelpersInTsx.types b/tests/baselines/reference/importHelpersInTsx.types new file mode 100644 index 0000000000000..a6ae6e95f866f --- /dev/null +++ b/tests/baselines/reference/importHelpersInTsx.types @@ -0,0 +1,69 @@ +=== tests/cases/compiler/external.tsx === +declare var React: any; +>React : any + +declare var o: any; +>o : any + +export const x = +>x : any +> : any +>span : any +>o : any + +=== tests/cases/compiler/script.tsx === +declare var React: any; +>React : any + +declare var o: any; +>o : any + +const x = +>x : any +> : any +>span : any +>o : any + +=== tests/cases/compiler/tslib.d.ts === +export declare function __extends(d: Function, b: Function): void; +>__extends : (d: Function, b: Function) => void +>d : Function +>Function : Function +>b : Function +>Function : Function + +export declare function __assign(t: any, ...sources: any[]): any; +>__assign : (t: any, ...sources: any[]) => any +>t : any +>sources : any[] + +export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; +>__decorate : (decorators: Function[], target: any, key?: string | symbol, desc?: any) => any +>decorators : Function[] +>Function : Function +>target : any +>key : string | symbol +>desc : any + +export declare function __param(paramIndex: number, decorator: Function): Function; +>__param : (paramIndex: number, decorator: Function) => Function +>paramIndex : number +>decorator : Function +>Function : Function +>Function : Function + +export declare function __metadata(metadataKey: any, metadataValue: any): Function; +>__metadata : (metadataKey: any, metadataValue: any) => Function +>metadataKey : any +>metadataValue : any +>Function : Function + +export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; +>__awaiter : (thisArg: any, _arguments: any, P: Function, generator: Function) => any +>thisArg : any +>_arguments : any +>P : Function +>Function : Function +>generator : Function +>Function : Function + diff --git a/tests/baselines/reference/importHelpersNoHelpers.errors.txt b/tests/baselines/reference/importHelpersNoHelpers.errors.txt new file mode 100644 index 0000000000000..ebb25dbd7c974 --- /dev/null +++ b/tests/baselines/reference/importHelpersNoHelpers.errors.txt @@ -0,0 +1,36 @@ +error TS2305: Module 'tslib' has no exported member '__decorate'. +error TS2305: Module 'tslib' has no exported member '__extends'. +error TS2305: Module 'tslib' has no exported member '__metadata'. +error TS2305: Module 'tslib' has no exported member '__param'. + + +!!! error TS2305: Module 'tslib' has no exported member '__decorate'. +!!! error TS2305: Module 'tslib' has no exported member '__extends'. +!!! error TS2305: Module 'tslib' has no exported member '__metadata'. +!!! error TS2305: Module 'tslib' has no exported member '__param'. +==== tests/cases/compiler/external.ts (0 errors) ==== + export class A { } + export class B extends A { } + + declare var dec: any; + + @dec + class C { + method(@dec x: number) { + } + } + +==== tests/cases/compiler/script.ts (0 errors) ==== + class A { } + class B extends A { } + + declare var dec: any; + + @dec + class C { + method(@dec x: number) { + } + } + +==== tests/cases/compiler/tslib.d.ts (0 errors) ==== + export {} \ No newline at end of file diff --git a/tests/baselines/reference/importHelpersNoHelpers.js b/tests/baselines/reference/importHelpersNoHelpers.js new file mode 100644 index 0000000000000..8c5afc99ece8b --- /dev/null +++ b/tests/baselines/reference/importHelpersNoHelpers.js @@ -0,0 +1,110 @@ +//// [tests/cases/compiler/importHelpersNoHelpers.ts] //// + +//// [external.ts] +export class A { } +export class B extends A { } + +declare var dec: any; + +@dec +class C { + method(@dec x: number) { + } +} + +//// [script.ts] +class A { } +class B extends A { } + +declare var dec: any; + +@dec +class C { + method(@dec x: number) { + } +} + +//// [tslib.d.ts] +export {} + +//// [external.js] +"use strict"; +var tslib_1 = require("tslib"); +var A = (function () { + function A() { + } + return A; +}()); +exports.A = A; +var B = (function (_super) { + tslib_1.__extends(B, _super); + function B() { + _super.apply(this, arguments); + } + return B; +}(A)); +exports.B = B; +var C = (function () { + function C() { + } + C.prototype.method = function (x) { + }; + return C; +}()); +tslib_1.__decorate([ + tslib_1.__param(0, dec), + tslib_1.__metadata("design:type", Function), + tslib_1.__metadata("design:paramtypes", [Number]), + tslib_1.__metadata("design:returntype", void 0) +], C.prototype, "method", null); +C = tslib_1.__decorate([ + dec, + tslib_1.__metadata("design:paramtypes", []) +], C); +//// [script.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +var __param = (this && this.__param) || function (paramIndex, decorator) { + return function (target, key) { decorator(target, key, paramIndex); } +}; +var A = (function () { + function A() { + } + return A; +}()); +var B = (function (_super) { + __extends(B, _super); + function B() { + _super.apply(this, arguments); + } + return B; +}(A)); +var C = (function () { + function C() { + } + C.prototype.method = function (x) { + }; + return C; +}()); +__decorate([ + __param(0, dec), + __metadata("design:type", Function), + __metadata("design:paramtypes", [Number]), + __metadata("design:returntype", void 0) +], C.prototype, "method", null); +C = __decorate([ + dec, + __metadata("design:paramtypes", []) +], C); diff --git a/tests/baselines/reference/importHelpersNoModule.errors.txt b/tests/baselines/reference/importHelpersNoModule.errors.txt new file mode 100644 index 0000000000000..d59fd0537ca5d --- /dev/null +++ b/tests/baselines/reference/importHelpersNoModule.errors.txt @@ -0,0 +1,28 @@ +error TS2307: Cannot find module 'tslib'. + + +!!! error TS2307: Cannot find module 'tslib'. +==== tests/cases/compiler/external.ts (0 errors) ==== + export class A { } + export class B extends A { } + + declare var dec: any; + + @dec + class C { + method(@dec x: number) { + } + } + +==== tests/cases/compiler/script.ts (0 errors) ==== + class A { } + class B extends A { } + + declare var dec: any; + + @dec + class C { + method(@dec x: number) { + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/importHelpersNoModule.js b/tests/baselines/reference/importHelpersNoModule.js new file mode 100644 index 0000000000000..36bc0c5f76bee --- /dev/null +++ b/tests/baselines/reference/importHelpersNoModule.js @@ -0,0 +1,108 @@ +//// [tests/cases/compiler/importHelpersNoModule.ts] //// + +//// [external.ts] +export class A { } +export class B extends A { } + +declare var dec: any; + +@dec +class C { + method(@dec x: number) { + } +} + +//// [script.ts] +class A { } +class B extends A { } + +declare var dec: any; + +@dec +class C { + method(@dec x: number) { + } +} + + +//// [external.js] +"use strict"; +var tslib_1 = require("tslib"); +var A = (function () { + function A() { + } + return A; +}()); +exports.A = A; +var B = (function (_super) { + tslib_1.__extends(B, _super); + function B() { + _super.apply(this, arguments); + } + return B; +}(A)); +exports.B = B; +var C = (function () { + function C() { + } + C.prototype.method = function (x) { + }; + return C; +}()); +tslib_1.__decorate([ + tslib_1.__param(0, dec), + tslib_1.__metadata("design:type", Function), + tslib_1.__metadata("design:paramtypes", [Number]), + tslib_1.__metadata("design:returntype", void 0) +], C.prototype, "method", null); +C = tslib_1.__decorate([ + dec, + tslib_1.__metadata("design:paramtypes", []) +], C); +//// [script.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +var __param = (this && this.__param) || function (paramIndex, decorator) { + return function (target, key) { decorator(target, key, paramIndex); } +}; +var A = (function () { + function A() { + } + return A; +}()); +var B = (function (_super) { + __extends(B, _super); + function B() { + _super.apply(this, arguments); + } + return B; +}(A)); +var C = (function () { + function C() { + } + C.prototype.method = function (x) { + }; + return C; +}()); +__decorate([ + __param(0, dec), + __metadata("design:type", Function), + __metadata("design:paramtypes", [Number]), + __metadata("design:returntype", void 0) +], C.prototype, "method", null); +C = __decorate([ + dec, + __metadata("design:paramtypes", []) +], C); diff --git a/tests/baselines/reference/importHelpersOutFile.js b/tests/baselines/reference/importHelpersOutFile.js new file mode 100644 index 0000000000000..cb50330c20c65 --- /dev/null +++ b/tests/baselines/reference/importHelpersOutFile.js @@ -0,0 +1,54 @@ +//// [tests/cases/compiler/importHelpersOutFile.ts] //// + +//// [a.ts] +export class A { } + +//// [b.ts] +import { A } from "./a"; +export class B extends A { } + +//// [c.ts] +import { A } from "./a"; +export class C extends A { } + +//// [tslib.d.ts] +export declare function __extends(d: Function, b: Function): void; +export declare function __assign(t: any, ...sources: any[]): any; +export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; +export declare function __param(paramIndex: number, decorator: Function): Function; +export declare function __metadata(metadataKey: any, metadataValue: any): Function; +export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; + + +//// [out.js] +define("a", ["require", "exports"], function (require, exports) { + "use strict"; + var A = (function () { + function A() { + } + return A; + }()); + exports.A = A; +}); +define("b", ["require", "exports", "tslib", "a"], function (require, exports, tslib_1, a_1) { + "use strict"; + var B = (function (_super) { + tslib_1.__extends(B, _super); + function B() { + _super.apply(this, arguments); + } + return B; + }(a_1.A)); + exports.B = B; +}); +define("c", ["require", "exports", "tslib", "a"], function (require, exports, tslib_2, a_2) { + "use strict"; + var C = (function (_super) { + tslib_2.__extends(C, _super); + function C() { + _super.apply(this, arguments); + } + return C; + }(a_2.A)); + exports.C = C; +}); diff --git a/tests/baselines/reference/importHelpersOutFile.symbols b/tests/baselines/reference/importHelpersOutFile.symbols new file mode 100644 index 0000000000000..086f3f9995e0a --- /dev/null +++ b/tests/baselines/reference/importHelpersOutFile.symbols @@ -0,0 +1,63 @@ +=== tests/cases/compiler/a.ts === +export class A { } +>A : Symbol(A, Decl(a.ts, 0, 0)) + +=== tests/cases/compiler/b.ts === +import { A } from "./a"; +>A : Symbol(A, Decl(b.ts, 0, 8)) + +export class B extends A { } +>B : Symbol(B, Decl(b.ts, 0, 24)) +>A : Symbol(A, Decl(b.ts, 0, 8)) + +=== tests/cases/compiler/c.ts === +import { A } from "./a"; +>A : Symbol(A, Decl(c.ts, 0, 8)) + +export class C extends A { } +>C : Symbol(C, Decl(c.ts, 0, 24)) +>A : Symbol(A, Decl(c.ts, 0, 8)) + +=== tests/cases/compiler/tslib.d.ts === +export declare function __extends(d: Function, b: Function): void; +>__extends : Symbol(__extends, Decl(tslib.d.ts, --, --)) +>d : Symbol(d, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>b : Symbol(b, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +export declare function __assign(t: any, ...sources: any[]): any; +>__assign : Symbol(__assign, Decl(tslib.d.ts, --, --)) +>t : Symbol(t, Decl(tslib.d.ts, --, --)) +>sources : Symbol(sources, Decl(tslib.d.ts, --, --)) + +export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; +>__decorate : Symbol(__decorate, Decl(tslib.d.ts, --, --)) +>decorators : Symbol(decorators, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>target : Symbol(target, Decl(tslib.d.ts, --, --)) +>key : Symbol(key, Decl(tslib.d.ts, --, --)) +>desc : Symbol(desc, Decl(tslib.d.ts, --, --)) + +export declare function __param(paramIndex: number, decorator: Function): Function; +>__param : Symbol(__param, Decl(tslib.d.ts, --, --)) +>paramIndex : Symbol(paramIndex, Decl(tslib.d.ts, --, --)) +>decorator : Symbol(decorator, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +export declare function __metadata(metadataKey: any, metadataValue: any): Function; +>__metadata : Symbol(__metadata, Decl(tslib.d.ts, --, --)) +>metadataKey : Symbol(metadataKey, Decl(tslib.d.ts, --, --)) +>metadataValue : Symbol(metadataValue, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; +>__awaiter : Symbol(__awaiter, Decl(tslib.d.ts, --, --)) +>thisArg : Symbol(thisArg, Decl(tslib.d.ts, --, --)) +>_arguments : Symbol(_arguments, Decl(tslib.d.ts, --, --)) +>P : Symbol(P, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>generator : Symbol(generator, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + diff --git a/tests/baselines/reference/importHelpersOutFile.types b/tests/baselines/reference/importHelpersOutFile.types new file mode 100644 index 0000000000000..96adc466d659d --- /dev/null +++ b/tests/baselines/reference/importHelpersOutFile.types @@ -0,0 +1,63 @@ +=== tests/cases/compiler/a.ts === +export class A { } +>A : A + +=== tests/cases/compiler/b.ts === +import { A } from "./a"; +>A : typeof A + +export class B extends A { } +>B : B +>A : A + +=== tests/cases/compiler/c.ts === +import { A } from "./a"; +>A : typeof A + +export class C extends A { } +>C : C +>A : A + +=== tests/cases/compiler/tslib.d.ts === +export declare function __extends(d: Function, b: Function): void; +>__extends : (d: Function, b: Function) => void +>d : Function +>Function : Function +>b : Function +>Function : Function + +export declare function __assign(t: any, ...sources: any[]): any; +>__assign : (t: any, ...sources: any[]) => any +>t : any +>sources : any[] + +export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; +>__decorate : (decorators: Function[], target: any, key?: string | symbol, desc?: any) => any +>decorators : Function[] +>Function : Function +>target : any +>key : string | symbol +>desc : any + +export declare function __param(paramIndex: number, decorator: Function): Function; +>__param : (paramIndex: number, decorator: Function) => Function +>paramIndex : number +>decorator : Function +>Function : Function +>Function : Function + +export declare function __metadata(metadataKey: any, metadataValue: any): Function; +>__metadata : (metadataKey: any, metadataValue: any) => Function +>metadataKey : any +>metadataValue : any +>Function : Function + +export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; +>__awaiter : (thisArg: any, _arguments: any, P: Function, generator: Function) => any +>thisArg : any +>_arguments : any +>P : Function +>Function : Function +>generator : Function +>Function : Function + diff --git a/tests/baselines/reference/importHelpersSystem.js b/tests/baselines/reference/importHelpersSystem.js new file mode 100644 index 0000000000000..3c1ee19ec48a9 --- /dev/null +++ b/tests/baselines/reference/importHelpersSystem.js @@ -0,0 +1,61 @@ +//// [tests/cases/compiler/importHelpersSystem.ts] //// + +//// [a.ts] +export class A { } + +//// [b.ts] +import { A } from "./a"; +export class B extends A { } + +//// [tslib.d.ts] +export declare function __extends(d: Function, b: Function): void; +export declare function __assign(t: any, ...sources: any[]): any; +export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; +export declare function __param(paramIndex: number, decorator: Function): Function; +export declare function __metadata(metadataKey: any, metadataValue: any): Function; +export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; + + +//// [a.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + var A; + return { + setters: [], + execute: function () { + A = (function () { + function A() { + } + return A; + }()); + exports_1("A", A); + } + }; +}); +//// [b.js] +System.register(["tslib", "./a"], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + var tslib_1, a_1, B; + return { + setters: [ + function (tslib_1_1) { + tslib_1 = tslib_1_1; + }, + function (a_1_1) { + a_1 = a_1_1; + } + ], + execute: function () { + B = (function (_super) { + tslib_1.__extends(B, _super); + function B() { + _super.apply(this, arguments); + } + return B; + }(a_1.A)); + exports_1("B", B); + } + }; +}); diff --git a/tests/baselines/reference/importHelpersSystem.symbols b/tests/baselines/reference/importHelpersSystem.symbols new file mode 100644 index 0000000000000..47528a8bba6b9 --- /dev/null +++ b/tests/baselines/reference/importHelpersSystem.symbols @@ -0,0 +1,55 @@ +=== tests/cases/compiler/a.ts === +export class A { } +>A : Symbol(A, Decl(a.ts, 0, 0)) + +=== tests/cases/compiler/b.ts === +import { A } from "./a"; +>A : Symbol(A, Decl(b.ts, 0, 8)) + +export class B extends A { } +>B : Symbol(B, Decl(b.ts, 0, 24)) +>A : Symbol(A, Decl(b.ts, 0, 8)) + +=== tests/cases/compiler/tslib.d.ts === +export declare function __extends(d: Function, b: Function): void; +>__extends : Symbol(__extends, Decl(tslib.d.ts, --, --)) +>d : Symbol(d, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>b : Symbol(b, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +export declare function __assign(t: any, ...sources: any[]): any; +>__assign : Symbol(__assign, Decl(tslib.d.ts, --, --)) +>t : Symbol(t, Decl(tslib.d.ts, --, --)) +>sources : Symbol(sources, Decl(tslib.d.ts, --, --)) + +export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; +>__decorate : Symbol(__decorate, Decl(tslib.d.ts, --, --)) +>decorators : Symbol(decorators, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>target : Symbol(target, Decl(tslib.d.ts, --, --)) +>key : Symbol(key, Decl(tslib.d.ts, --, --)) +>desc : Symbol(desc, Decl(tslib.d.ts, --, --)) + +export declare function __param(paramIndex: number, decorator: Function): Function; +>__param : Symbol(__param, Decl(tslib.d.ts, --, --)) +>paramIndex : Symbol(paramIndex, Decl(tslib.d.ts, --, --)) +>decorator : Symbol(decorator, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +export declare function __metadata(metadataKey: any, metadataValue: any): Function; +>__metadata : Symbol(__metadata, Decl(tslib.d.ts, --, --)) +>metadataKey : Symbol(metadataKey, Decl(tslib.d.ts, --, --)) +>metadataValue : Symbol(metadataValue, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; +>__awaiter : Symbol(__awaiter, Decl(tslib.d.ts, --, --)) +>thisArg : Symbol(thisArg, Decl(tslib.d.ts, --, --)) +>_arguments : Symbol(_arguments, Decl(tslib.d.ts, --, --)) +>P : Symbol(P, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>generator : Symbol(generator, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + diff --git a/tests/baselines/reference/importHelpersSystem.types b/tests/baselines/reference/importHelpersSystem.types new file mode 100644 index 0000000000000..9ff756ffaab94 --- /dev/null +++ b/tests/baselines/reference/importHelpersSystem.types @@ -0,0 +1,55 @@ +=== tests/cases/compiler/a.ts === +export class A { } +>A : A + +=== tests/cases/compiler/b.ts === +import { A } from "./a"; +>A : typeof A + +export class B extends A { } +>B : B +>A : A + +=== tests/cases/compiler/tslib.d.ts === +export declare function __extends(d: Function, b: Function): void; +>__extends : (d: Function, b: Function) => void +>d : Function +>Function : Function +>b : Function +>Function : Function + +export declare function __assign(t: any, ...sources: any[]): any; +>__assign : (t: any, ...sources: any[]) => any +>t : any +>sources : any[] + +export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; +>__decorate : (decorators: Function[], target: any, key?: string | symbol, desc?: any) => any +>decorators : Function[] +>Function : Function +>target : any +>key : string | symbol +>desc : any + +export declare function __param(paramIndex: number, decorator: Function): Function; +>__param : (paramIndex: number, decorator: Function) => Function +>paramIndex : number +>decorator : Function +>Function : Function +>Function : Function + +export declare function __metadata(metadataKey: any, metadataValue: any): Function; +>__metadata : (metadataKey: any, metadataValue: any) => Function +>metadataKey : any +>metadataValue : any +>Function : Function + +export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; +>__awaiter : (thisArg: any, _arguments: any, P: Function, generator: Function) => any +>thisArg : any +>_arguments : any +>P : Function +>Function : Function +>generator : Function +>Function : Function + diff --git a/tests/cases/compiler/importHelpers.ts b/tests/cases/compiler/importHelpers.ts new file mode 100644 index 0000000000000..2e15eb6352b88 --- /dev/null +++ b/tests/cases/compiler/importHelpers.ts @@ -0,0 +1,37 @@ +// @importHelpers: true +// @target: es5 +// @module: commonjs +// @moduleResolution: classic +// @experimentalDecorators: true +// @emitDecoratorMetadata: true +// @filename: external.ts +export class A { } +export class B extends A { } + +declare var dec: any; + +@dec +class C { + method(@dec x: number) { + } +} + +// @filename: script.ts +class A { } +class B extends A { } + +declare var dec: any; + +@dec +class C { + method(@dec x: number) { + } +} + +// @filename: tslib.d.ts +export declare function __extends(d: Function, b: Function): void; +export declare function __assign(t: any, ...sources: any[]): any; +export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; +export declare function __param(paramIndex: number, decorator: Function): Function; +export declare function __metadata(metadataKey: any, metadataValue: any): Function; +export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; diff --git a/tests/cases/compiler/importHelpersAmd.ts b/tests/cases/compiler/importHelpersAmd.ts new file mode 100644 index 0000000000000..bef63328d520e --- /dev/null +++ b/tests/cases/compiler/importHelpersAmd.ts @@ -0,0 +1,17 @@ +// @importHelpers: true +// @target: es5 +// @module: amd +// @filename: a.ts +export class A { } + +// @filename: b.ts +import { A } from "./a"; +export class B extends A { } + +// @filename: tslib.d.ts +export declare function __extends(d: Function, b: Function): void; +export declare function __assign(t: any, ...sources: any[]): any; +export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; +export declare function __param(paramIndex: number, decorator: Function): Function; +export declare function __metadata(metadataKey: any, metadataValue: any): Function; +export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; diff --git a/tests/cases/compiler/importHelpersES6.ts b/tests/cases/compiler/importHelpersES6.ts new file mode 100644 index 0000000000000..9be680a88d622 --- /dev/null +++ b/tests/cases/compiler/importHelpersES6.ts @@ -0,0 +1,16 @@ +// @importHelpers: true +// @target: es6 +// @experimentalDecorators: true +// @filename: a.ts +declare var dec: any; +@dec export class A { + +} + +// @filename: tslib.d.ts +export declare function __extends(d: Function, b: Function): void; +export declare function __assign(t: any, ...sources: any[]): any; +export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; +export declare function __param(paramIndex: number, decorator: Function): Function; +export declare function __metadata(metadataKey: any, metadataValue: any): Function; +export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; diff --git a/tests/cases/compiler/importHelpersInIsolatedModules.ts b/tests/cases/compiler/importHelpersInIsolatedModules.ts new file mode 100644 index 0000000000000..4c1dfd06ec082 --- /dev/null +++ b/tests/cases/compiler/importHelpersInIsolatedModules.ts @@ -0,0 +1,38 @@ +// @importHelpers: true +// @isolatedModules: true +// @target: es5 +// @module: commonjs +// @moduleResolution: classic +// @experimentalDecorators: true +// @emitDecoratorMetadata: true +// @filename: external.ts +export class A { } +export class B extends A { } + +declare var dec: any; + +@dec +class C { + method(@dec x: number) { + } +} + +// @filename: script.ts +class A { } +class B extends A { } + +declare var dec: any; + +@dec +class C { + method(@dec x: number) { + } +} + +// @filename: tslib.d.ts +export declare function __extends(d: Function, b: Function): void; +export declare function __assign(t: any, ...sources: any[]): any; +export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; +export declare function __param(paramIndex: number, decorator: Function): Function; +export declare function __metadata(metadataKey: any, metadataValue: any): Function; +export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; diff --git a/tests/cases/compiler/importHelpersInTsx.tsx b/tests/cases/compiler/importHelpersInTsx.tsx new file mode 100644 index 0000000000000..32e0e5bf3a0c0 --- /dev/null +++ b/tests/cases/compiler/importHelpersInTsx.tsx @@ -0,0 +1,24 @@ +// @importHelpers: true +// @target: es5 +// @module: commonjs +// @moduleResolution: classic +// @jsx: react +// @experimentalDecorators: true +// @emitDecoratorMetadata: true +// @filename: external.tsx +declare var React: any; +declare var o: any; +export const x = + +// @filename: script.tsx +declare var React: any; +declare var o: any; +const x = + +// @filename: tslib.d.ts +export declare function __extends(d: Function, b: Function): void; +export declare function __assign(t: any, ...sources: any[]): any; +export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; +export declare function __param(paramIndex: number, decorator: Function): Function; +export declare function __metadata(metadataKey: any, metadataValue: any): Function; +export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; diff --git a/tests/cases/compiler/importHelpersNoHelpers.ts b/tests/cases/compiler/importHelpersNoHelpers.ts new file mode 100644 index 0000000000000..8242855254806 --- /dev/null +++ b/tests/cases/compiler/importHelpersNoHelpers.ts @@ -0,0 +1,32 @@ +// @importHelpers: true +// @target: es5 +// @module: commonjs +// @moduleResolution: classic +// @experimentalDecorators: true +// @emitDecoratorMetadata: true +// @filename: external.ts +export class A { } +export class B extends A { } + +declare var dec: any; + +@dec +class C { + method(@dec x: number) { + } +} + +// @filename: script.ts +class A { } +class B extends A { } + +declare var dec: any; + +@dec +class C { + method(@dec x: number) { + } +} + +// @filename: tslib.d.ts +export {} \ No newline at end of file diff --git a/tests/cases/compiler/importHelpersNoModule.ts b/tests/cases/compiler/importHelpersNoModule.ts new file mode 100644 index 0000000000000..e824f2afb4854 --- /dev/null +++ b/tests/cases/compiler/importHelpersNoModule.ts @@ -0,0 +1,29 @@ +// @importHelpers: true +// @target: es5 +// @module: commonjs +// @moduleResolution: classic +// @experimentalDecorators: true +// @emitDecoratorMetadata: true +// @filename: external.ts +export class A { } +export class B extends A { } + +declare var dec: any; + +@dec +class C { + method(@dec x: number) { + } +} + +// @filename: script.ts +class A { } +class B extends A { } + +declare var dec: any; + +@dec +class C { + method(@dec x: number) { + } +} diff --git a/tests/cases/compiler/importHelpersOutFile.ts b/tests/cases/compiler/importHelpersOutFile.ts new file mode 100644 index 0000000000000..69e1e692617ad --- /dev/null +++ b/tests/cases/compiler/importHelpersOutFile.ts @@ -0,0 +1,22 @@ +// @importHelpers: true +// @target: es5 +// @module: amd +// @outfile: out.js +// @filename: a.ts +export class A { } + +// @filename: b.ts +import { A } from "./a"; +export class B extends A { } + +// @filename: c.ts +import { A } from "./a"; +export class C extends A { } + +// @filename: tslib.d.ts +export declare function __extends(d: Function, b: Function): void; +export declare function __assign(t: any, ...sources: any[]): any; +export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; +export declare function __param(paramIndex: number, decorator: Function): Function; +export declare function __metadata(metadataKey: any, metadataValue: any): Function; +export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; diff --git a/tests/cases/compiler/importHelpersSystem.ts b/tests/cases/compiler/importHelpersSystem.ts new file mode 100644 index 0000000000000..5b6081f17f3e9 --- /dev/null +++ b/tests/cases/compiler/importHelpersSystem.ts @@ -0,0 +1,17 @@ +// @importHelpers: true +// @target: es5 +// @module: system +// @filename: a.ts +export class A { } + +// @filename: b.ts +import { A } from "./a"; +export class B extends A { } + +// @filename: tslib.d.ts +export declare function __extends(d: Function, b: Function): void; +export declare function __assign(t: any, ...sources: any[]): any; +export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; +export declare function __param(paramIndex: number, decorator: Function): Function; +export declare function __metadata(metadataKey: any, metadataValue: any): Function; +export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any;