diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000000..74f5f4a640948 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.js linguist-language=TypeScript \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 305fad1e4a7e7..572ac835cd42f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,13 +3,4 @@ language: node_js node_js: - '0.10' -sudo: false - -before_script: npm install -g codeclimate-test-reporter - -after_script: - - cat coverage/lcov.info | codeclimate - -addons: - code_climate: - repo_token: 9852ac5362c8cc38c07ca5adc0f94c20c6c79bd78e17933dc284598a65338656 +sudo: false \ No newline at end of file diff --git a/Jakefile b/Jakefile index 3a19812b958a5..dd09085800cae 100644 --- a/Jakefile +++ b/Jakefile @@ -39,6 +39,7 @@ var compilerSources = [ "utilities.ts", "binder.ts", "checker.ts", + "declarationEmitter.ts", "emitter.ts", "program.ts", "commandLineParser.ts", @@ -57,6 +58,7 @@ var servicesSources = [ "utilities.ts", "binder.ts", "checker.ts", + "declarationEmitter.ts", "emitter.ts", "program.ts", "commandLineParser.ts", @@ -65,7 +67,7 @@ var servicesSources = [ return path.join(compilerDirectory, f); }).concat([ "breakpoints.ts", - "navigateTo.ts", + "navigateTo.ts", "navigationBar.ts", "outliningElementsCollector.ts", "patternMatcher.ts", @@ -539,7 +541,7 @@ function cleanTestDirs() { } jake.mkdirP(localRwcBaseline); - jake.mkdirP(localTest262Baseline); + jake.mkdirP(localTest262Baseline); jake.mkdirP(localBaseline); } @@ -718,7 +720,7 @@ file(loggedIOJsPath, [builtLocalDirectory, loggedIOpath], function() { var instrumenterPath = harnessDirectory + 'instrumenter.ts'; var instrumenterJsPath = builtLocalDirectory + 'instrumenter.js'; -compileFile(instrumenterJsPath, [instrumenterPath], [tscFile, instrumenterPath], [], /*useBuiltCompiler*/ true); +compileFile(instrumenterJsPath, [instrumenterPath], [tscFile, instrumenterPath].concat(libraryTargets), [], /*useBuiltCompiler*/ true); desc("Builds an instrumented tsc.js"); task('tsc-instrumented', [loggedIOJsPath, instrumenterJsPath, tscFile], function() { diff --git a/package.json b/package.json index 9261174b68f3b..c33f2a93ec18f 100644 --- a/package.json +++ b/package.json @@ -38,10 +38,9 @@ "mocha": "latest", "chai": "latest", "browserify": "latest", - "istanbul": "latest", - "codeclimate-test-reporter": "latest" + "istanbul": "latest" }, "scripts": { - "test": "jake generate-code-coverage" + "test": "jake runtests" } } diff --git a/scripts/processDiagnosticMessages.ts b/scripts/processDiagnosticMessages.ts index 0d32c605fdc08..b97e4a2ea5427 100644 --- a/scripts/processDiagnosticMessages.ts +++ b/scripts/processDiagnosticMessages.ts @@ -65,8 +65,7 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, nameMap: ' ' + convertPropertyName(nameMap[name]) + ': { code: ' + diagnosticDetails.code + ', category: DiagnosticCategory.' + diagnosticDetails.category + - ', key: "' + name.replace('"', '\\"') + '"' + - (diagnosticDetails.isEarly ? ', isEarly: true' : '') + + ', key: "' + name.replace(/[\"]/g, '\\"') + '"' + ' },\r\n'; } diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index ae0bb3a03022f..304777e040179 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -346,13 +346,14 @@ module ts { } else { bindDeclaration(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes, /*isBlockScopeContainer*/ true); - if (state === ModuleInstanceState.ConstEnumOnly) { - // mark value module as module that contains only enums - node.symbol.constEnumOnlyModule = true; + let currentModuleIsConstEnumOnly = state === ModuleInstanceState.ConstEnumOnly; + if (node.symbol.constEnumOnlyModule === undefined) { + // non-merged case - use the current state + node.symbol.constEnumOnlyModule = currentModuleIsConstEnumOnly; } - else if (node.symbol.constEnumOnlyModule) { - // const only value module was merged with instantiated module - reset flag - node.symbol.constEnumOnlyModule = false; + else { + // merged case: module is const enum only if all its pieces are non-instantiated or const enum + node.symbol.constEnumOnlyModule = node.symbol.constEnumOnlyModule && currentModuleIsConstEnumOnly; } } } @@ -529,7 +530,7 @@ module ts { bindChildren(node, 0, /*isBlockScopeContainer*/ false); break; case SyntaxKind.ExportAssignment: - if ((node).expression.kind === SyntaxKind.Identifier) { + if ((node).expression && (node).expression.kind === SyntaxKind.Identifier) { // An export default clause with an identifier exports all meanings of that identifier declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.Alias, SymbolFlags.PropertyExcludes | SymbolFlags.AliasExcludes); } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a84d0a6a8c959..6fdaac79cea00 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5,8 +5,23 @@ module ts { let nextNodeId = 1; let nextMergeId = 1; + // @internal + export function getNodeId(node: Node): number { + if (!node.id) node.id = nextNodeId++; + return node.id; + } + /* @internal */ export let checkTime = 0; + /* @internal */ + export function getSymbolId(symbol: Symbol): number { + if (!symbol.id) { + symbol.id = nextSymbolId++; + } + + return symbol.id; + } + export function createTypeChecker(host: TypeCheckerHost, produceDiagnostics: boolean): TypeChecker { let Symbol = objectAllocator.getSymbolConstructor(); let Type = objectAllocator.getTypeConstructor(); @@ -79,8 +94,7 @@ module ts { let emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); let anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); let noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); - let inferenceFailureType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); - + let anySignature = createSignature(undefined, undefined, emptyArray, anyType, 0, false, false); let unknownSignature = createSignature(undefined, undefined, emptyArray, unknownType, 0, false, false); @@ -101,11 +115,17 @@ module ts { let globalIterableType: ObjectType; let anyArrayType: Type; - + let globalTypedPropertyDescriptorType: ObjectType; + let globalClassDecoratorType: ObjectType; + let globalParameterDecoratorType: ObjectType; + let globalPropertyDecoratorType: ObjectType; + let globalMethodDecoratorType: ObjectType; + let tupleTypes: Map = {}; let unionTypes: Map = {}; let stringLiteralTypes: Map = {}; let emitExtends = false; + let emitDecorate = false; let mergedSymbols: Symbol[] = []; let symbolLinks: SymbolLinks[] = []; @@ -251,13 +271,13 @@ module ts { function getSymbolLinks(symbol: Symbol): SymbolLinks { if (symbol.flags & SymbolFlags.Transient) return symbol; - if (!symbol.id) symbol.id = nextSymbolId++; - return symbolLinks[symbol.id] || (symbolLinks[symbol.id] = {}); + var id = getSymbolId(symbol); + return symbolLinks[id] || (symbolLinks[id] = {}); } function getNodeLinks(node: Node): NodeLinks { - if (!node.id) node.id = nextNodeId++; - return nodeLinks[node.id] || (nodeLinks[node.id] = {}); + let nodeId = getNodeId(node); + return nodeLinks[nodeId] || (nodeLinks[nodeId] = {}); } function getSourceFile(node: Node): SourceFile { @@ -310,6 +330,7 @@ module ts { let lastLocation: Node; let propertyWithInvalidInitializer: Node; let errorLocation = location; + let grandparent: Node; loop: while (location) { // Locals of a source file are not in scope (because they get merged into the global symbol table) @@ -375,7 +396,7 @@ module ts { // } // case SyntaxKind.ComputedPropertyName: - let grandparent = location.parent.parent; + grandparent = location.parent.parent; if (grandparent.kind === SyntaxKind.ClassDeclaration || grandparent.kind === SyntaxKind.InterfaceDeclaration) { // A reference to this grandparent's type parameters would be an error if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & SymbolFlags.Type)) { @@ -407,6 +428,28 @@ module ts { break loop; } break; + case SyntaxKind.Decorator: + // Decorators are resolved at the class declaration. Resolving at the parameter + // or member would result in looking up locals in the method. + // + // function y() {} + // class C { + // method(@y x, y) {} // <-- decorator y should be resolved at the class declaration, not the parameter. + // } + // + if (location.parent && location.parent.kind === SyntaxKind.Parameter) { + location = location.parent; + } + // + // function y() {} + // class C { + // @y method(x, y) {} // <-- decorator y should be resolved at the class declaration, not the method. + // } + // + if (location.parent && isClassElement(location.parent)) { + location = location.parent; + } + break; } lastLocation = location; location = location.parent; @@ -446,7 +489,7 @@ module ts { let declaration = forEach(result.declarations, d => isBlockOrCatchScoped(d) ? d : undefined); Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined"); - + // first check if usage is lexically located after the declaration let isUsedBeforeDeclaration = !isDefinedBefore(declaration, errorLocation); if (!isUsedBeforeDeclaration) { @@ -463,7 +506,7 @@ module ts { if (variableDeclaration.parent.parent.kind === SyntaxKind.VariableStatement || variableDeclaration.parent.parent.kind === SyntaxKind.ForStatement) { - // variable statement/for statement case, + // variable statement/for statement case, // use site should not be inside variable declaration (initializer of declaration or binding element) isUsedBeforeDeclaration = isSameScopeDescendentOf(errorLocation, variableDeclaration, container); } @@ -495,6 +538,19 @@ module ts { return false; } + function getAnyImportSyntax(node: Node): AnyImportSyntax { + if (isAliasSymbolDeclaration(node)) { + if (node.kind === SyntaxKind.ImportEqualsDeclaration) { + return node; + } + + while (node && node.kind !== SyntaxKind.ImportDeclaration) { + node = node.parent; + } + return node; + } + } + function getDeclarationOfAliasSymbol(symbol: Symbol): Declaration { return forEach(symbol.declarations, d => isAliasSymbolDeclaration(d) ? d : undefined); } @@ -610,7 +666,7 @@ module ts { } function getTargetOfExportAssignment(node: ExportAssignment): Symbol { - return resolveEntityName(node.expression, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace); + return node.expression && resolveEntityName(node.expression, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace); } function getTargetOfAliasDeclaration(node: Declaration): Symbol { @@ -670,7 +726,7 @@ module ts { if (!links.referenced) { links.referenced = true; let node = getDeclarationOfAliasSymbol(symbol); - if (node.kind === SyntaxKind.ExportAssignment) { + if (node.kind === SyntaxKind.ExportAssignment && (node).expression) { // export default checkExpressionCached((node).expression); } @@ -1164,7 +1220,7 @@ module ts { } function hasVisibleDeclarations(symbol: Symbol): SymbolVisibilityResult { - let aliasesToMakeVisible: ImportEqualsDeclaration[]; + let aliasesToMakeVisible: AnyImportSyntax[]; if (forEach(symbol.declarations, declaration => !getIsDeclarationVisible(declaration))) { return undefined; } @@ -1174,17 +1230,19 @@ module ts { if (!isDeclarationVisible(declaration)) { // Mark the unexported alias as visible if its parent is visible // because these kind of aliases can be used to name types in declaration file - if (declaration.kind === SyntaxKind.ImportEqualsDeclaration && - !(declaration.flags & NodeFlags.Export) && - isDeclarationVisible(declaration.parent)) { + + var anyImportSyntax = getAnyImportSyntax(declaration); + if (anyImportSyntax && + !(anyImportSyntax.flags & NodeFlags.Export) && // import clause without export + isDeclarationVisible(anyImportSyntax.parent)) { getNodeLinks(declaration).isVisible = true; if (aliasesToMakeVisible) { - if (!contains(aliasesToMakeVisible, declaration)) { - aliasesToMakeVisible.push(declaration); + if (!contains(aliasesToMakeVisible, anyImportSyntax)) { + aliasesToMakeVisible.push(anyImportSyntax); } } else { - aliasesToMakeVisible = [declaration]; + aliasesToMakeVisible = [anyImportSyntax]; } return true; } @@ -1808,8 +1866,15 @@ module ts { function determineIfDeclarationIsVisible() { switch (node.kind) { - case SyntaxKind.VariableDeclaration: case SyntaxKind.BindingElement: + return isDeclarationVisible(node.parent.parent); + case SyntaxKind.VariableDeclaration: + if (isBindingPattern(node.name) && + !(node.name).elements.length) { + // If the binding pattern is empty, this variable declaration is not visible + return false; + } + // Otherwise fall through case SyntaxKind.ModuleDeclaration: case SyntaxKind.ClassDeclaration: case SyntaxKind.InterfaceDeclaration: @@ -1821,7 +1886,7 @@ module ts { // If the node is not exported or it is not ambient module element (except import declaration) if (!(getCombinedNodeFlags(node) & NodeFlags.Export) && !(node.kind !== SyntaxKind.ImportEqualsDeclaration && parent.kind !== SyntaxKind.SourceFile && isInAmbientContext(parent))) { - return isGlobalSourceFile(parent) || isUsedInExportAssignment(node); + return isGlobalSourceFile(parent); } // Exported members/ambient module elements (exception import declaration) are visible if parent is visible return isDeclarationVisible(parent); @@ -1854,6 +1919,13 @@ module ts { case SyntaxKind.ParenthesizedType: return isDeclarationVisible(node.parent); + // Default binding, import specifier and namespace import is visible + // only on demand so by default it is not visible + case SyntaxKind.ImportClause: + case SyntaxKind.NamespaceImport: + case SyntaxKind.ImportSpecifier: + return false; + // Type parameters are always visible case SyntaxKind.TypeParameter: // Source file is always visible @@ -1874,6 +1946,40 @@ module ts { } } + function collectLinkedAliases(node: Identifier): Node[]{ + var exportSymbol: Symbol; + if (node.parent && node.parent.kind === SyntaxKind.ExportAssignment) { + exportSymbol = resolveName(node.parent, node.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, Diagnostics.Cannot_find_name_0, node); + } + else if (node.parent.kind === SyntaxKind.ExportSpecifier) { + exportSymbol = getTargetOfExportSpecifier(node.parent); + } + var result: Node[] = []; + if (exportSymbol) { + buildVisibleNodeList(exportSymbol.declarations); + } + return result; + + function buildVisibleNodeList(declarations: Declaration[]) { + forEach(declarations, declaration => { + getNodeLinks(declaration).isVisible = true; + var resultNode = getAnyImportSyntax(declaration) || declaration; + if (!contains(result, resultNode)) { + result.push(resultNode); + } + + if (isInternalModuleImportEqualsDeclaration(declaration)) { + // Add the referenced top container visible + var internalModuleReference = (declaration).moduleReference; + var firstIdentifier = getFirstIdentifier(internalModuleReference); + var importSymbol = resolveName(declaration, firstIdentifier.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, + Diagnostics.Cannot_find_name_0, firstIdentifier); + buildVisibleNodeList(importSymbol.declarations); + } + }); + } + } + function getRootDeclaration(node: Node): Node { while (node.kind === SyntaxKind.BindingElement) { node = node.parent.parent; @@ -2114,7 +2220,16 @@ module ts { } // Handle export default expressions if (declaration.kind === SyntaxKind.ExportAssignment) { - return links.type = checkExpression((declaration).expression); + var exportAssignment = declaration; + if (exportAssignment.expression) { + return links.type = checkExpression(exportAssignment.expression); + } + else if (exportAssignment.type) { + return links.type = getTypeFromTypeNode(exportAssignment.type); + } + else { + return links.type = anyType; + } } // Handle variable, parameter or property links.type = resolvingType; @@ -3554,6 +3669,7 @@ module ts { return t => { for (let i = 0; i < context.typeParameters.length; i++) { if (t === context.typeParameters[i]) { + context.inferences[i].isFixed = true; return getInferredType(context, i); } } @@ -4412,8 +4528,11 @@ module ts { } function reportNoCommonSupertypeError(types: Type[], errorLocation: Node, errorMessageChainHead: DiagnosticMessageChain): void { + // The downfallType/bestSupertypeDownfallType is the first type that caused a particular candidate + // to not be the common supertype. So if it weren't for this one downfallType (and possibly others), + // the type in question could have been the common supertype. let bestSupertype: Type; - let bestSupertypeDownfallType: Type; // The type that caused bestSupertype not to be the common supertype + let bestSupertypeDownfallType: Type; let bestSupertypeScore = 0; for (let i = 0; i < types.length; i++) { @@ -4428,6 +4547,8 @@ module ts { } } + Debug.assert(!!downfallType, "If there is no common supertype, each type should have a downfallType"); + if (score > bestSupertypeScore) { bestSupertype = types[i]; bestSupertypeDownfallType = downfallType; @@ -4461,7 +4582,7 @@ module ts { } /** - * Check if a Type was written as a tuple type literal. + * Check if a Type was written as a tuple type literal. * Prefer using isTupleLikeType() unless the use of `elementTypes` is required. */ function isTupleType(type: Type): boolean { @@ -4610,13 +4731,12 @@ module ts { function createInferenceContext(typeParameters: TypeParameter[], inferUnionTypes: boolean): InferenceContext { let inferences: TypeInferences[] = []; for (let unused of typeParameters) { - inferences.push({ primary: undefined, secondary: undefined }); + inferences.push({ primary: undefined, secondary: undefined, isFixed: false }); } return { - typeParameters: typeParameters, - inferUnionTypes: inferUnionTypes, - inferenceCount: 0, - inferences: inferences, + typeParameters, + inferUnionTypes, + inferences, inferredTypes: new Array(typeParameters.length), }; } @@ -4662,11 +4782,21 @@ module ts { for (let i = 0; i < typeParameters.length; i++) { if (target === typeParameters[i]) { let inferences = context.inferences[i]; - let candidates = inferiority ? - inferences.secondary || (inferences.secondary = []) : - inferences.primary || (inferences.primary = []); - if (!contains(candidates, source)) candidates.push(source); - break; + if (!inferences.isFixed) { + // Any inferences that are made to a type parameter in a union type are inferior + // to inferences made to a flat (non-union) type. This is because if we infer to + // T | string[], we really don't know if we should be inferring to T or not (because + // the correct constituent on the target side could be string[]). Therefore, we put + // such inferior inferences into a secondary bucket, and only use them if the primary + // bucket is empty. + let candidates = inferiority ? + inferences.secondary || (inferences.secondary = []) : + inferences.primary || (inferences.primary = []); + if (!contains(candidates, source)) { + candidates.push(source); + } + } + return; } } } @@ -4772,21 +4902,35 @@ module ts { function getInferredType(context: InferenceContext, index: number): Type { let inferredType = context.inferredTypes[index]; + let inferenceSucceeded: boolean; if (!inferredType) { let inferences = getInferenceCandidates(context, index); if (inferences.length) { - // Infer widened union or supertype, or the undefined type for no common supertype + // Infer widened union or supertype, or the unknown type for no common supertype let unionOrSuperType = context.inferUnionTypes ? getUnionType(inferences) : getCommonSupertype(inferences); - inferredType = unionOrSuperType ? getWidenedType(unionOrSuperType) : inferenceFailureType; + inferredType = unionOrSuperType ? getWidenedType(unionOrSuperType) : unknownType; + inferenceSucceeded = !!unionOrSuperType; } else { - // Infer the empty object type when no inferences were made + // Infer the empty object type when no inferences were made. It is important to remember that + // in this case, inference still succeeds, meaning there is no error for not having inference + // candidates. An inference error only occurs when there are *conflicting* candidates, i.e. + // candidates with no common supertype. inferredType = emptyObjectType; + inferenceSucceeded = true; } - if (inferredType !== inferenceFailureType) { + + // Only do the constraint check if inference succeeded (to prevent cascading errors) + if (inferenceSucceeded) { let constraint = getConstraintOfTypeParameter(context.typeParameters[index]); inferredType = constraint && !isTypeAssignableTo(inferredType, constraint) ? constraint : inferredType; } + else if (context.failedTypeParameterIndex === undefined || context.failedTypeParameterIndex > index) { + // If inference failed, it is necessary to record the index of the failed type parameter (the one we are on). + // It might be that inference has already failed on a later type parameter on a previous call to inferTypeArguments. + // So if this failure is on preceding type parameter, this type parameter is the new failure index. + context.failedTypeParameterIndex = index; + } context.inferredTypes[index] = inferredType; } return inferredType; @@ -6383,11 +6527,32 @@ module ts { return getSignatureInstantiation(signature, getInferredTypes(context)); } - function inferTypeArguments(signature: Signature, args: Expression[], excludeArgument: boolean[]): InferenceContext { + function inferTypeArguments(signature: Signature, args: Expression[], excludeArgument: boolean[], context: InferenceContext): void { let typeParameters = signature.typeParameters; - let context = createInferenceContext(typeParameters, /*inferUnionTypes*/ false); let inferenceMapper = createInferenceMapper(context); + // Clear out all the inference results from the last time inferTypeArguments was called on this context + for (let i = 0; i < typeParameters.length; i++) { + // As an optimization, we don't have to clear (and later recompute) inferred types + // for type parameters that have already been fixed on the previous call to inferTypeArguments. + // It would be just as correct to reset all of them. But then we'd be repeating the same work + // for the type parameters that were fixed, namely the work done by getInferredType. + if (!context.inferences[i].isFixed) { + context.inferredTypes[i] = undefined; + } + } + + // On this call to inferTypeArguments, we may get more inferences for certain type parameters that were not + // fixed last time. This means that a type parameter that failed inference last time may succeed this time, + // or vice versa. Therefore, the failedTypeParameterIndex is useless if it points to an unfixed type parameter, + // because it may change. So here we reset it. However, getInferredType will not revisit any type parameters + // that were previously fixed. So if a fixed type parameter failed previously, it will fail again because + // it will contain the exact same set of inferences. So if we reset the index from a fixed type parameter, + // we will lose information that we won't recover this time around. + if (context.failedTypeParameterIndex !== undefined && !context.inferences[context.failedTypeParameterIndex].isFixed) { + context.failedTypeParameterIndex = undefined; + } + // We perform two passes over the arguments. In the first pass we infer from all arguments, but use // wildcards for all context sensitive function expressions. for (let i = 0; i < args.length; i++) { @@ -6422,18 +6587,7 @@ module ts { } } - let inferredTypes = getInferredTypes(context); - // Inference has failed if the inferenceFailureType type is in list of inferences - context.failedTypeParameterIndex = indexOf(inferredTypes, inferenceFailureType); - - // Wipe out the inferenceFailureType from the array so that error recovery can work properly - for (let i = 0; i < inferredTypes.length; i++) { - if (inferredTypes[i] === inferenceFailureType) { - inferredTypes[i] = unknownType; - } - } - - return context; + getInferredTypes(context); } function checkTypeArguments(signature: Signature, typeArguments: TypeNode[], typeArgumentResultTypes: Type[], reportErrors: boolean): boolean { @@ -6667,15 +6821,17 @@ module ts { return resolveErrorCall(node); function chooseOverload(candidates: Signature[], relation: Map) { - for (let current of candidates) { - if (!hasCorrectArity(node, args, current)) { + for (let originalCandidate of candidates) { + if (!hasCorrectArity(node, args, originalCandidate)) { continue; } - - let originalCandidate = current; - let inferenceResult: InferenceContext; + let candidate: Signature; let typeArgumentsAreValid: boolean; + let inferenceContext = originalCandidate.typeParameters + ? createInferenceContext(originalCandidate.typeParameters, /*inferUnionTypes*/ false) + : undefined; + while (true) { candidate = originalCandidate; if (candidate.typeParameters) { @@ -6685,9 +6841,9 @@ module ts { typeArgumentsAreValid = checkTypeArguments(candidate, typeArguments, typeArgumentTypes, /*reportErrors*/ false) } else { - inferenceResult = inferTypeArguments(candidate, args, excludeArgument); - typeArgumentsAreValid = inferenceResult.failedTypeParameterIndex < 0; - typeArgumentTypes = inferenceResult.inferredTypes; + inferTypeArguments(candidate, args, excludeArgument, inferenceContext); + typeArgumentsAreValid = inferenceContext.failedTypeParameterIndex === undefined; + typeArgumentTypes = inferenceContext.inferredTypes; } if (!typeArgumentsAreValid) { break; @@ -6717,7 +6873,7 @@ module ts { else { candidateForTypeArgumentError = originalCandidate; if (!typeArguments) { - resultOfFailedInference = inferenceResult; + resultOfFailedInference = inferenceContext; } } } @@ -7176,7 +7332,6 @@ module ts { case SyntaxKind.ElementAccessExpression: { let index = (n).argumentExpression; let symbol = findSymbol((n).expression); - if (symbol && index && index.kind === SyntaxKind.StringLiteral) { let name = (index).text; let prop = getPropertyOfType(getTypeOfSymbol(symbol), name); @@ -7191,14 +7346,37 @@ module ts { } } + function isImportedNameFromExternalModule(n: Node): boolean { + switch (n.kind) { + case SyntaxKind.ElementAccessExpression: + case SyntaxKind.PropertyAccessExpression: { + // all bindings for external module should be immutable + // so attempt to use a.b or a[b] as lhs will always fail + // no matter what b is + let symbol = findSymbol((n).expression); + return symbol && symbol.flags & SymbolFlags.Alias && isExternalModuleSymbol(resolveAlias(symbol)); + } + case SyntaxKind.ParenthesizedExpression: + return isImportedNameFromExternalModule((n).expression); + default: + return false; + } + } + if (!isReferenceOrErrorExpression(n)) { error(n, invalidReferenceMessage); return false; } + if (isConstVariableReference(n)) { error(n, constantVariableMessage); return false; } + + if (isImportedNameFromExternalModule(n)) { + error(n, invalidReferenceMessage); + } + return true; } @@ -7847,7 +8025,7 @@ module ts { // strict mode FunctionLikeDeclaration or FunctionExpression(13.1) // Grammar checking - checkGrammarModifiers(node) || checkGrammarEvalOrArgumentsInStrictMode(node, node.name); + checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEvalOrArgumentsInStrictMode(node, node.name); checkVariableLikeDeclaration(node); let func = getContainingFunction(node); @@ -7949,7 +8127,7 @@ module ts { function checkPropertyDeclaration(node: PropertyDeclaration) { // Grammar checking - checkGrammarModifiers(node) || checkGrammarProperty(node) || checkGrammarComputedPropertyName(node.name); + checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarProperty(node) || checkGrammarComputedPropertyName(node.name); checkVariableLikeDeclaration(node); } @@ -8088,6 +8266,10 @@ module ts { checkFunctionLikeDeclaration(node); } + function checkMissingDeclaration(node: Node) { + checkDecorators(node); + } + function checkTypeReference(node: TypeReferenceNode) { // Grammar checking checkGrammarTypeArguments(node, node.typeArguments); @@ -8479,6 +8661,60 @@ module ts { } } + /** Check a decorator */ + function checkDecorator(node: Decorator): void { + let expression: Expression = node.expression; + let exprType = checkExpression(expression); + + switch (node.parent.kind) { + case SyntaxKind.ClassDeclaration: + let classSymbol = getSymbolOfNode(node.parent); + let classConstructorType = getTypeOfSymbol(classSymbol); + let classDecoratorType = instantiateSingleCallFunctionType(globalClassDecoratorType, [classConstructorType]); + checkTypeAssignableTo(exprType, classDecoratorType, node); + break; + + case SyntaxKind.PropertyDeclaration: + checkTypeAssignableTo(exprType, globalPropertyDecoratorType, node); + break; + + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + let methodType = getTypeOfNode(node.parent); + let methodDecoratorType = instantiateSingleCallFunctionType(globalMethodDecoratorType, [methodType]); + checkTypeAssignableTo(exprType, methodDecoratorType, node); + break; + + case SyntaxKind.Parameter: + checkTypeAssignableTo(exprType, globalParameterDecoratorType, node); + break; + } + } + + /** Check the decorators of a node */ + function checkDecorators(node: Node): void { + if (!node.decorators) { + return; + } + + switch (node.kind) { + case SyntaxKind.ClassDeclaration: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.Parameter: + emitDecorate = true; + break; + + default: + return; + } + + forEach(node.decorators, checkDecorator); + } + function checkFunctionDeclaration(node: FunctionDeclaration): void { if (produceDiagnostics) { checkFunctionLikeDeclaration(node) || @@ -8493,6 +8729,7 @@ module ts { } function checkFunctionLikeDeclaration(node: FunctionLikeDeclaration): void { + checkDecorators(node); checkSignatureDeclaration(node); // Do not use hasDynamicName here, because that returns false for well known symbols. @@ -8683,36 +8920,48 @@ module ts { // const x = 0; // localDeclarationSymbol obtained after name resolution will correspond to this declaration // let x = 0; // symbol for this declaration will be 'symbol' // } - if (node.initializer && (getCombinedNodeFlags(node) & NodeFlags.BlockScoped) === 0) { - let symbol = getSymbolOfNode(node); - if (symbol.flags & SymbolFlags.FunctionScopedVariable) { - let localDeclarationSymbol = resolveName(node, (node.name).text, SymbolFlags.Variable, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined); - if (localDeclarationSymbol && - localDeclarationSymbol !== symbol && - localDeclarationSymbol.flags & SymbolFlags.BlockScopedVariable) { - if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & NodeFlags.BlockScoped) { - - let varDeclList = getAncestor(localDeclarationSymbol.valueDeclaration, SyntaxKind.VariableDeclarationList); - let container = - varDeclList.parent.kind === SyntaxKind.VariableStatement && - varDeclList.parent.parent; - - // names of block-scoped and function scoped variables can collide only - // if block scoped variable is defined in the function\module\source file scope (because of variable hoisting) - let namesShareScope = - container && - (container.kind === SyntaxKind.Block && isFunctionLike(container.parent) || - (container.kind === SyntaxKind.ModuleBlock && container.kind === SyntaxKind.ModuleDeclaration) || - container.kind === SyntaxKind.SourceFile); - - // here we know that function scoped variable is shadowed by block scoped one - // if they are defined in the same scope - binder has already reported redeclaration error - // otherwise if variable has an initializer - show error that initialization will fail - // since LHS will be block scoped name instead of function scoped - if (!namesShareScope) { - let name = symbolToString(localDeclarationSymbol); - error(node, Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name, name); - } + + // skip block-scoped variables and parameters + if ((getCombinedNodeFlags(node) & NodeFlags.BlockScoped) !== 0 || isParameterDeclaration(node)) { + return; + } + + // skip variable declarations that don't have initializers + // NOTE: in ES6 spec initializer is required in variable declarations where name is binding pattern + // so we'll always treat binding elements as initialized + if (node.kind === SyntaxKind.VariableDeclaration && !node.initializer) { + return; + } + + var symbol = getSymbolOfNode(node); + if (symbol.flags & SymbolFlags.FunctionScopedVariable) { + let localDeclarationSymbol = resolveName(node, (node.name).text, SymbolFlags.Variable, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined); + if (localDeclarationSymbol && + localDeclarationSymbol !== symbol && + localDeclarationSymbol.flags & SymbolFlags.BlockScopedVariable) { + if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & NodeFlags.BlockScoped) { + let varDeclList = getAncestor(localDeclarationSymbol.valueDeclaration, SyntaxKind.VariableDeclarationList); + let container = + varDeclList.parent.kind === SyntaxKind.VariableStatement && varDeclList.parent.parent + ? varDeclList.parent.parent + : undefined; + + // names of block-scoped and function scoped variables can collide only + // if block scoped variable is defined in the function\module\source file scope (because of variable hoisting) + let namesShareScope = + container && + (container.kind === SyntaxKind.Block && isFunctionLike(container.parent) || + container.kind === SyntaxKind.ModuleBlock || + container.kind === SyntaxKind.ModuleDeclaration || + container.kind === SyntaxKind.SourceFile); + + // here we know that function scoped variable is shadowed by block scoped one + // if they are defined in the same scope - binder has already reported redeclaration error + // otherwise if variable has an initializer - show error that initialization will fail + // since LHS will be block scoped name instead of function scoped + if (!namesShareScope) { + let name = symbolToString(localDeclarationSymbol); + error(node, Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name, name); } } } @@ -8763,6 +9012,7 @@ module ts { // Check variable, parameter, or property declaration function checkVariableLikeDeclaration(node: VariableLikeDeclaration) { + checkDecorators(node); checkSourceElement(node.type); // For a computed property, just check the initializer and exit // Do not use hasDynamicName here, because that returns false for well known symbols. @@ -8835,7 +9085,7 @@ module ts { function checkVariableStatement(node: VariableStatement) { // Grammar checking - checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarModifiers(node) || checkGrammarVariableDeclarationList(node.declarationList) || checkGrammarForDisallowedLetOrConstStatement(node); + checkGrammarDecorators(node) || checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarModifiers(node) || checkGrammarVariableDeclarationList(node.declarationList) || checkGrammarForDisallowedLetOrConstStatement(node); forEach(node.declarationList.declarations, checkSourceElement); } @@ -9129,7 +9379,7 @@ module ts { */ function checkElementTypeOfArrayOrString(arrayOrStringType: Type, expressionForError: Expression): Type { Debug.assert(languageVersion < ScriptTarget.ES6); - + // After we remove all types that are StringLike, we will know if there was a string constituent // based on whether the remaining type is the same as the initial type. let arrayType = removeTypesFromUnionType(arrayOrStringType, TypeFlags.StringLike, /*isTypeOfKind*/ true, /*allowEmptyUnionResult*/ true); @@ -9466,7 +9716,7 @@ module ts { function checkClassDeclaration(node: ClassDeclaration) { // Grammar checking checkGrammarClassDeclarationHeritageClauses(node); - + checkDecorators(node); if (node.name) { checkTypeNameIsReserved(node.name, Diagnostics.Class_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); @@ -9671,7 +9921,7 @@ module ts { function checkInterfaceDeclaration(node: InterfaceDeclaration) { // Grammar checking - checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node); + checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node); checkTypeParameters(node.typeParameters); if (produceDiagnostics) { @@ -9708,7 +9958,7 @@ module ts { function checkTypeAliasDeclaration(node: TypeAliasDeclaration) { // Grammar checking - checkGrammarModifiers(node); + checkGrammarDecorators(node) || checkGrammarModifiers(node); checkTypeNameIsReserved(node.name, Diagnostics.Type_alias_name_cannot_be_0); checkSourceElement(node.type); @@ -9730,7 +9980,7 @@ module ts { } let initializer = member.initializer; if (initializer) { - autoValue = getConstantValueForEnumMemberInitializer(initializer, enumIsConst); + autoValue = getConstantValueForEnumMemberInitializer(initializer); if (autoValue === undefined) { if (enumIsConst) { error(initializer, Diagnostics.In_const_enum_declarations_member_initializer_must_be_constant_expression); @@ -9765,7 +10015,7 @@ module ts { nodeLinks.flags |= NodeCheckFlags.EnumValuesComputed; } - function getConstantValueForEnumMemberInitializer(initializer: Expression, enumIsConst: boolean): number { + function getConstantValueForEnumMemberInitializer(initializer: Expression): number { return evalConstant(initializer); function evalConstant(e: Node): number { @@ -9778,14 +10028,10 @@ module ts { switch ((e).operator) { case SyntaxKind.PlusToken: return value; case SyntaxKind.MinusToken: return -value; - case SyntaxKind.TildeToken: return enumIsConst ? ~value : undefined; + case SyntaxKind.TildeToken: return ~value; } return undefined; case SyntaxKind.BinaryExpression: - if (!enumIsConst) { - return undefined; - } - let left = evalConstant((e).left); if (left === undefined) { return undefined; @@ -9811,14 +10057,10 @@ module ts { case SyntaxKind.NumericLiteral: return +(e).text; case SyntaxKind.ParenthesizedExpression: - return enumIsConst ? evalConstant((e).expression) : undefined; + return evalConstant((e).expression); case SyntaxKind.Identifier: case SyntaxKind.ElementAccessExpression: case SyntaxKind.PropertyAccessExpression: - if (!enumIsConst) { - return undefined; - } - let member = initializer.parent; let currentType = getTypeOfSymbol(getSymbolOfNode(member.parent)); let enumType: Type; @@ -9831,19 +10073,37 @@ module ts { propertyName = (e).text; } else { + let expression: Expression; if (e.kind === SyntaxKind.ElementAccessExpression) { if ((e).argumentExpression === undefined || (e).argumentExpression.kind !== SyntaxKind.StringLiteral) { return undefined; } - enumType = getTypeOfNode((e).expression); + expression = (e).expression; propertyName = ((e).argumentExpression).text; } else { - enumType = getTypeOfNode((e).expression); + expression = (e).expression; propertyName = (e).name.text; } - if (enumType !== currentType) { + + // expression part in ElementAccess\PropertyAccess should be either identifier or dottedName + var current = expression; + while (current) { + if (current.kind === SyntaxKind.Identifier) { + break; + } + else if (current.kind === SyntaxKind.PropertyAccessExpression) { + current = (current).expression; + } + else { + return undefined; + } + } + + enumType = checkExpression(expression); + // allow references to constant members of other enums + if (!(enumType.symbol && (enumType.symbol.flags & SymbolFlags.Enum))) { return undefined; } } @@ -9851,10 +10111,12 @@ module ts { if (propertyName === undefined) { return undefined; } + let property = getPropertyOfObjectType(enumType, propertyName); if (!property || !(property.flags & SymbolFlags.EnumMember)) { return undefined; } + let propertyDecl = property.valueDeclaration; // self references are illegal if (member === propertyDecl) { @@ -9865,6 +10127,7 @@ module ts { if (!isDefinedBefore(propertyDecl, member)) { return undefined; } + return getNodeLinks(propertyDecl).enumMemberValue; } } @@ -9877,7 +10140,7 @@ module ts { } // Grammar checking - checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); + checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); checkTypeNameIsReserved(node.name, Diagnostics.Enum_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); @@ -9943,7 +10206,7 @@ module ts { function checkModuleDeclaration(node: ModuleDeclaration) { if (produceDiagnostics) { // Grammar checking - if (!checkGrammarModifiers(node)) { + if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node)) { if (!isInAmbientContext(node) && node.name.kind === SyntaxKind.StringLiteral) { grammarErrorOnNode(node.name, Diagnostics.Only_ambient_modules_can_use_quoted_names); } @@ -10038,7 +10301,7 @@ module ts { } function checkImportDeclaration(node: ImportDeclaration) { - if (!checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { + if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { grammarErrorOnFirstToken(node, Diagnostics.An_import_declaration_cannot_have_modifiers); } if (checkExternalImportOrExportDeclaration(node)) { @@ -10060,7 +10323,7 @@ module ts { } function checkImportEqualsDeclaration(node: ImportEqualsDeclaration) { - checkGrammarModifiers(node); + checkGrammarDecorators(node) || checkGrammarModifiers(node); if (isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) { checkImportBinding(node); if (node.flags & NodeFlags.Export) { @@ -10081,11 +10344,17 @@ module ts { } } } + else { + if (languageVersion >= ScriptTarget.ES6) { + // Import equals declaration is deprecated in es6 or above + grammarErrorOnNode(node, Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead); + } + } } } function checkExportDeclaration(node: ExportDeclaration) { - if (!checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { + if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { grammarErrorOnFirstToken(node, Diagnostics.An_export_declaration_cannot_have_modifiers); } if (!node.moduleSpecifier || checkExternalImportOrExportDeclaration(node)) { @@ -10093,6 +10362,11 @@ module ts { // export { x, y } // export { x, y } from "foo" forEach(node.exportClause.elements, checkExportSpecifier); + + let inAmbientExternalModule = node.parent.kind === SyntaxKind.ModuleBlock && (node.parent.parent).name.kind === SyntaxKind.StringLiteral; + if (node.parent.kind !== SyntaxKind.SourceFile && !inAmbientExternalModule) { + error(node, Diagnostics.Export_declarations_are_not_permitted_in_an_internal_module); + } } else { // export * from "foo" @@ -10118,16 +10392,30 @@ module ts { return; } // Grammar checking - if (!checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { + if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { grammarErrorOnFirstToken(node, Diagnostics.An_export_assignment_cannot_have_modifiers); } - if (node.expression.kind === SyntaxKind.Identifier) { - markExportAsReferenced(node); + if (node.expression) { + if (node.expression.kind === SyntaxKind.Identifier) { + markExportAsReferenced(node); + } + else { + checkExpressionCached(node.expression); + } } - else { - checkExpressionCached(node.expression); + if (node.type) { + checkSourceElement(node.type); + if (!isInAmbientContext(node)) { + grammarErrorOnFirstToken(node.type, Diagnostics.A_type_annotation_on_an_export_statement_is_only_allowed_in_an_ambient_external_module_declaration); + } } + checkExternalModuleExports(container); + + if (node.isExportEquals && languageVersion >= ScriptTarget.ES6) { + // export assignment is deprecated in es6 or above + grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead); + } } function getModuleStatements(node: Declaration): ModuleElement[] { @@ -10265,6 +10553,8 @@ module ts { case SyntaxKind.DebuggerStatement: checkGrammarStatementInAmbientContext(node); return; + case SyntaxKind.MissingDeclaration: + return checkMissingDeclaration(node); } } @@ -10391,6 +10681,10 @@ module ts { links.flags |= NodeCheckFlags.EmitExtends; } + if (emitDecorate) { + links.flags |= NodeCheckFlags.EmitDecorate; + } + links.flags |= NodeCheckFlags.TypeChecked; } } @@ -10434,7 +10728,55 @@ module ts { function getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[] { let symbols: SymbolTable = {}; let memberFlags: NodeFlags = 0; - function copySymbol(symbol: Symbol, meaning: SymbolFlags) { + + if (isInsideWithStatementBody(location)) { + // We cannot answer semantic questions within a with block, do not proceed any further + return []; + } + + populateSymbols(); + + return symbolsToArray(symbols); + + function populateSymbols() { + while (location) { + if (location.locals && !isGlobalSourceFile(location)) { + copySymbols(location.locals, meaning); + } + + switch (location.kind) { + case SyntaxKind.SourceFile: + if (!isExternalModule(location)) { + break; + } + case SyntaxKind.ModuleDeclaration: + copySymbols(getSymbolOfNode(location).exports, meaning & SymbolFlags.ModuleMember); + break; + case SyntaxKind.EnumDeclaration: + copySymbols(getSymbolOfNode(location).exports, meaning & SymbolFlags.EnumMember); + break; + case SyntaxKind.ClassDeclaration: + case SyntaxKind.InterfaceDeclaration: + if (!(memberFlags & NodeFlags.Static)) { + copySymbols(getSymbolOfNode(location).members, meaning & SymbolFlags.Type); + } + break; + case SyntaxKind.FunctionExpression: + if ((location).name) { + copySymbol(location.symbol, meaning); + } + break; + } + + memberFlags = location.flags; + location = location.parent; + } + + copySymbols(globals, meaning); + } + + // Returns 'true' if we should stop processing symbols. + function copySymbol(symbol: Symbol, meaning: SymbolFlags): void { if (symbol.flags & meaning) { let id = symbol.name; if (!isReservedMemberName(id) && !hasProperty(symbols, id)) { @@ -10442,7 +10784,8 @@ module ts { } } } - function copySymbols(source: SymbolTable, meaning: SymbolFlags) { + + function copySymbols(source: SymbolTable, meaning: SymbolFlags): void { if (meaning) { for (let id in source) { if (hasProperty(source, id)) { @@ -10838,134 +11181,13 @@ module ts { return symbol.flags & SymbolFlags.ValueModule && symbol.declarations.length === 1 && symbol.declarations[0].kind === SyntaxKind.SourceFile; } - function isNodeDescendentOf(node: Node, ancestor: Node): boolean { - while (node) { - if (node === ancestor) return true; - node = node.parent; - } - return false; - } - - function isUniqueLocalName(name: string, container: Node): boolean { - for (let node = container; isNodeDescendentOf(node, container); node = node.nextContainer) { - if (node.locals && hasProperty(node.locals, name)) { - // We conservatively include alias symbols to cover cases where they're emitted as locals - if (node.locals[name].flags & (SymbolFlags.Value | SymbolFlags.ExportValue | SymbolFlags.Alias)) { - return false; - } - } - } - return true; - } - - function getGeneratedNamesForSourceFile(sourceFile: SourceFile): Map { - let links = getNodeLinks(sourceFile); - let generatedNames = links.generatedNames; - if (!generatedNames) { - generatedNames = links.generatedNames = {}; - generateNames(sourceFile); - } - return generatedNames; - - function generateNames(node: Node) { - switch (node.kind) { - case SyntaxKind.FunctionDeclaration: - case SyntaxKind.ClassDeclaration: - generateNameForFunctionOrClassDeclaration(node); - break; - case SyntaxKind.ModuleDeclaration: - generateNameForModuleOrEnum(node); - generateNames((node).body); - break; - case SyntaxKind.EnumDeclaration: - generateNameForModuleOrEnum(node); - break; - case SyntaxKind.ImportDeclaration: - generateNameForImportDeclaration(node); - break; - case SyntaxKind.ExportDeclaration: - generateNameForExportDeclaration(node); - break; - case SyntaxKind.ExportAssignment: - generateNameForExportAssignment(node); - break; - case SyntaxKind.SourceFile: - case SyntaxKind.ModuleBlock: - forEach((node).statements, generateNames); - break; - } - } - - function isExistingName(name: string) { - return hasProperty(globals, name) || hasProperty(sourceFile.identifiers, name) || hasProperty(generatedNames, name); - } - - function makeUniqueName(baseName: string): string { - let name = generateUniqueName(baseName, isExistingName); - return generatedNames[name] = name; - } - - function assignGeneratedName(node: Node, name: string) { - getNodeLinks(node).generatedName = unescapeIdentifier(name); - } - - function generateNameForFunctionOrClassDeclaration(node: Declaration) { - if (!node.name) { - assignGeneratedName(node, makeUniqueName("default")); - } - } - - function generateNameForModuleOrEnum(node: ModuleDeclaration | EnumDeclaration) { - if (node.name.kind === SyntaxKind.Identifier) { - let name = node.name.text; - // Use module/enum name itself if it is unique, otherwise make a unique variation - assignGeneratedName(node, isUniqueLocalName(name, node) ? name : makeUniqueName(name)); - } - } - - function generateNameForImportOrExportDeclaration(node: ImportDeclaration | ExportDeclaration) { - let expr = getExternalModuleName(node); - let baseName = expr.kind === SyntaxKind.StringLiteral ? - escapeIdentifier(makeIdentifierFromModuleName((expr).text)) : "module"; - assignGeneratedName(node, makeUniqueName(baseName)); - } - - function generateNameForImportDeclaration(node: ImportDeclaration) { - if (node.importClause) { - generateNameForImportOrExportDeclaration(node); - } - } - - function generateNameForExportDeclaration(node: ExportDeclaration) { - if (node.moduleSpecifier) { - generateNameForImportOrExportDeclaration(node); - } - } - - function generateNameForExportAssignment(node: ExportAssignment) { - if (node.expression.kind !== SyntaxKind.Identifier) { - assignGeneratedName(node, makeUniqueName("default")); - } - } - } - - function getGeneratedNameForNode(node: Node) { - let links = getNodeLinks(node); - if (!links.generatedName) { - getGeneratedNamesForSourceFile(getSourceFile(node)); + function getAliasNameSubstitution(symbol: Symbol, getGeneratedNameForNode: (node: Node) => string): string { + // If this is es6 or higher, just use the name of the export + // no need to qualify it. + if (languageVersion >= ScriptTarget.ES6) { + return undefined; } - return links.generatedName; - } - - function getLocalNameOfContainer(container: ModuleDeclaration | EnumDeclaration): string { - return getGeneratedNameForNode(container); - } - function getLocalNameForImportDeclaration(node: ImportDeclaration): string { - return getGeneratedNameForNode(node); - } - - function getAliasNameSubstitution(symbol: Symbol): string { let node = getDeclarationOfAliasSymbol(symbol); if (node) { if (node.kind === SyntaxKind.ImportClause) { @@ -10979,8 +11201,13 @@ module ts { } } - function getExportNameSubstitution(symbol: Symbol, location: Node): string { + function getExportNameSubstitution(symbol: Symbol, location: Node, getGeneratedNameForNode: (Node: Node) => string): string { if (isExternalModuleSymbol(symbol.parent)) { + // If this is es6 or higher, just use the name of the export + // no need to qualify it. + if (languageVersion >= ScriptTarget.ES6) { + return undefined; + } return "exports." + unescapeIdentifier(symbol.name); } let node = location; @@ -10993,24 +11220,24 @@ module ts { } } - function getExpressionNameSubstitution(node: Identifier): string { + function getExpressionNameSubstitution(node: Identifier, getGeneratedNameForNode: (Node: Node) => string): string { let symbol = getNodeLinks(node).resolvedSymbol || (isDeclarationName(node) ? getSymbolOfNode(node.parent) : undefined); if (symbol) { // Whan an identifier resolves to a parented symbol, it references an exported entity from // another declaration of the same internal module. if (symbol.parent) { - return getExportNameSubstitution(symbol, node.parent); + return getExportNameSubstitution(symbol, node.parent, getGeneratedNameForNode); } // If we reference an exported entity within the same module declaration, then whether // we prefix depends on the kind of entity. SymbolFlags.ExportHasLocal encompasses all the // kinds that we do NOT prefix. let exportSymbol = getExportSymbolOfValueSymbolIfExported(symbol); if (symbol !== exportSymbol && !(exportSymbol.flags & SymbolFlags.ExportHasLocal)) { - return getExportNameSubstitution(exportSymbol, node.parent); + return getExportNameSubstitution(exportSymbol, node.parent, getGeneratedNameForNode); } // Named imports from ES6 import declarations are rewritten if (symbol.flags & SymbolFlags.Alias) { - return getAliasNameSubstitution(symbol); + return getAliasNameSubstitution(symbol, getGeneratedNameForNode); } } } @@ -11027,7 +11254,7 @@ module ts { let exportClause = (node).exportClause; return exportClause && forEach(exportClause.elements, isValueAliasDeclaration); case SyntaxKind.ExportAssignment: - return (node).expression.kind === SyntaxKind.Identifier ? isAliasResolvedToValue(getSymbolOfNode(node)) : true; + return (node).expression && (node).expression.kind === SyntaxKind.Identifier ? isAliasResolvedToValue(getSymbolOfNode(node)) : true; } return false; } @@ -11050,14 +11277,18 @@ module ts { return isConstEnumSymbol(s) || s.constEnumOnlyModule; } - function isReferencedAliasDeclaration(node: Node): boolean { + function isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean { if (isAliasSymbolDeclaration(node)) { let symbol = getSymbolOfNode(node); if (getSymbolLinks(symbol).referenced) { return true; } } - return forEachChild(node, isReferencedAliasDeclaration); + + if (checkChildren) { + return forEachChild(node, node => isReferencedAliasDeclaration(node, checkChildren)); + } + return false; } function isImplementationOfOverload(node: FunctionLikeDeclaration) { @@ -11097,10 +11328,9 @@ module ts { let symbol = getNodeLinks(node).resolvedSymbol; if (symbol && (symbol.flags & SymbolFlags.EnumMember)) { - let declaration = symbol.valueDeclaration; - let constantValue: number; - if (declaration.kind === SyntaxKind.EnumMember) { - return getEnumMemberValue(declaration); + // inline property\index accesses only for const enums + if (isConstEnumDeclaration(symbol.valueDeclaration.parent)) { + return getEnumMemberValue(symbol.valueDeclaration); } } @@ -11122,35 +11352,28 @@ module ts { getSymbolDisplayBuilder().buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags); } - function isUnknownIdentifier(location: Node, name: string): boolean { - Debug.assert(!nodeIsSynthesized(location), "isUnknownIdentifier called with a synthesized location"); - return !resolveName(location, name, SymbolFlags.Value, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined) && - !hasProperty(getGeneratedNamesForSourceFile(getSourceFile(location)), name); + function writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) { + var type = getTypeOfExpression(expr); + getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); } - function getBlockScopedVariableId(n: Identifier): number { - Debug.assert(!nodeIsSynthesized(n)); + function hasGlobalName(name: string): boolean { + return hasProperty(globals, name); + } - // ignore name parts of property access expressions - if (n.parent.kind === SyntaxKind.PropertyAccessExpression && - (n.parent).name === n) { - return undefined; - } + function resolvesToSomeValue(location: Node, name: string): boolean { + Debug.assert(!nodeIsSynthesized(location), "resolvesToSomeValue called with a synthesized location"); + return !!resolveName(location, name, SymbolFlags.Value, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined); + } - // ignore property names in object binding patterns - if (n.parent.kind === SyntaxKind.BindingElement && - (n.parent).propertyName === n) { - return undefined; - } + function getBlockScopedVariableId(n: Identifier): number { + Debug.assert(!nodeIsSynthesized(n)); - // for names in variable declarations and binding elements try to short circuit and fetch symbol from the node - let declarationSymbol: Symbol = - (n.parent.kind === SyntaxKind.VariableDeclaration && (n.parent).name === n) || - n.parent.kind === SyntaxKind.BindingElement - ? getSymbolOfNode(n.parent) - : undefined; + let isVariableDeclarationOrBindingElement = + n.parent.kind === SyntaxKind.BindingElement || (n.parent.kind === SyntaxKind.VariableDeclaration && (n.parent).name === n); - let symbol = declarationSymbol || + let symbol = + (isVariableDeclarationOrBindingElement ? getSymbolOfNode(n.parent) : undefined) || getNodeLinks(n).resolvedSymbol || resolveName(n, n.text, SymbolFlags.Value | SymbolFlags.Alias, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined); @@ -11168,11 +11391,25 @@ module ts { return undefined; } + function instantiateSingleCallFunctionType(functionType: Type, typeArguments: Type[]): Type { + if (functionType === unknownType) { + return unknownType; + } + + let signature = getSingleCallSignature(functionType); + if (!signature) { + return unknownType; + } + + let instantiatedSignature = getSignatureInstantiation(signature, typeArguments); + return getOrCreateTypeFromSignature(instantiatedSignature); + } + function createResolver(): EmitResolver { return { - getGeneratedNameForNode, getExpressionNameSubstitution, isValueAliasDeclaration, + hasGlobalName, isReferencedAliasDeclaration, getNodeCheckFlags, isTopLevelValueImportEqualsWithEntityName, @@ -11180,10 +11417,12 @@ module ts { isImplementationOfOverload, writeTypeOfDeclaration, writeReturnTypeOfSignatureDeclaration, + writeTypeOfExpression, isSymbolAccessible, isEntityNameVisible, getConstantValue, - isUnknownIdentifier, + resolvesToSomeValue, + collectLinkedAliases, getBlockScopedVariableId, }; } @@ -11215,6 +11454,11 @@ module ts { globalNumberType = getGlobalType("Number"); globalBooleanType = getGlobalType("Boolean"); globalRegExpType = getGlobalType("RegExp"); + globalTypedPropertyDescriptorType = getTypeOfGlobalSymbol(getGlobalTypeSymbol("TypedPropertyDescriptor"), 1); + globalClassDecoratorType = getGlobalType("ClassDecorator"); + globalPropertyDecoratorType = getGlobalType("PropertyDecorator"); + globalMethodDecoratorType = getGlobalType("MethodDecorator"); + globalParameterDecoratorType = getGlobalType("ParameterDecorator"); // If we're in ES6 mode, load the TemplateStringsArray. // Otherwise, default to 'unknown' for the purposes of type checking in LS scenarios. @@ -11239,6 +11483,25 @@ module ts { // GRAMMAR CHECKING + function checkGrammarDecorators(node: Node): boolean { + if (!node.decorators) { + return false; + } + if (!nodeCanBeDecorated(node)) { + return grammarErrorOnNode(node, Diagnostics.Decorators_are_not_valid_here); + } + else if (languageVersion < ScriptTarget.ES5) { + return grammarErrorOnNode(node, Diagnostics.Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher); + } + else if (node.kind === SyntaxKind.GetAccessor || node.kind === SyntaxKind.SetAccessor) { + let accessors = getAllAccessorDeclarations((node.parent).members, node); + if (accessors.firstAccessor.decorators && node === accessors.secondAccessor) { + return grammarErrorOnNode(node, Diagnostics.Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name); + } + } + return false; + } + function checkGrammarModifiers(node: Node): boolean { switch (node.kind) { case SyntaxKind.GetAccessor: @@ -11382,16 +11645,15 @@ module ts { } } - function checkGrammarTypeParameterList(node: FunctionLikeDeclaration, typeParameters: NodeArray): boolean { + function checkGrammarTypeParameterList(node: FunctionLikeDeclaration, typeParameters: NodeArray, file: SourceFile): boolean { if (checkGrammarForDisallowedTrailingComma(typeParameters)) { return true; } if (typeParameters && typeParameters.length === 0) { let start = typeParameters.pos - "<".length; - let sourceFile = getSourceFileOfNode(node); - let end = skipTrivia(sourceFile.text, typeParameters.end) + ">".length; - return grammarErrorAtPos(sourceFile, start, end - start, Diagnostics.Type_parameter_list_cannot_be_empty); + let end = skipTrivia(file.text, typeParameters.end) + ">".length; + return grammarErrorAtPos(file, start, end - start, Diagnostics.Type_parameter_list_cannot_be_empty); } } @@ -11435,7 +11697,21 @@ module ts { function checkGrammarFunctionLikeDeclaration(node: FunctionLikeDeclaration): boolean { // Prevent cascading error by short-circuit - return checkGrammarModifiers(node) || checkGrammarTypeParameterList(node, node.typeParameters) || checkGrammarParameterList(node.parameters); + let file = getSourceFileOfNode(node); + return checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarTypeParameterList(node, node.typeParameters, file) || + checkGrammarParameterList(node.parameters) || checkGrammarArrowFunction(node, file); + } + + function checkGrammarArrowFunction(node: FunctionLikeDeclaration, file: SourceFile): boolean { + if (node.kind === SyntaxKind.ArrowFunction) { + let arrowFunction = node; + let startLine = getLineAndCharacterOfPosition(file, arrowFunction.equalsGreaterThanToken.pos).line; + let endLine = getLineAndCharacterOfPosition(file, arrowFunction.equalsGreaterThanToken.end).line; + if (startLine !== endLine) { + return grammarErrorOnNode(arrowFunction.equalsGreaterThanToken, Diagnostics.Line_terminator_not_permitted_before_arrow); + } + } + return false; } function checkGrammarIndexSignatureParameters(node: SignatureDeclaration): boolean { @@ -11479,7 +11755,7 @@ module ts { function checkGrammarIndexSignature(node: SignatureDeclaration) { // Prevent cascading error by short-circuit - checkGrammarModifiers(node) || checkGrammarIndexSignatureParameters(node) || checkGrammarForIndexSignatureModifier(node); + return checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarIndexSignatureParameters(node) || checkGrammarForIndexSignatureModifier(node); } function checkGrammarForAtLeastOneTypeArgument(node: Node, typeArguments: NodeArray): boolean { @@ -11528,7 +11804,7 @@ module ts { let seenExtendsClause = false; let seenImplementsClause = false; - if (!checkGrammarModifiers(node) && node.heritageClauses) { + if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && node.heritageClauses) { for (let heritageClause of node.heritageClauses) { if (heritageClause.token === SyntaxKind.ExtendsKeyword) { if (seenExtendsClause) { @@ -12108,8 +12384,8 @@ module ts { } function checkGrammarTopLevelElementForRequiredDeclareModifier(node: Node): boolean { - // A declare modifier is required for any top level .d.ts declaration except export=, interfaces and imports: - // categories: + // A declare modifier is required for any top level .d.ts declaration except export=, export default, + // interfaces and imports categories: // // DeclarationElement: // ExportAssignment @@ -12123,7 +12399,8 @@ module ts { node.kind === SyntaxKind.ImportEqualsDeclaration || node.kind === SyntaxKind.ExportDeclaration || node.kind === SyntaxKind.ExportAssignment || - (node.flags & NodeFlags.Ambient)) { + (node.flags & NodeFlags.Ambient) || + (node.flags & (NodeFlags.Export | NodeFlags.Default))) { return false; } diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 2362c96bbb7f3..4b93081dc3133 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -122,8 +122,10 @@ module ts { } export function addRange(to: T[], from: T[]): void { - for (let v of from) { - to.push(v); + if (to && from) { + for (let v of from) { + to.push(v); + } } } @@ -160,6 +162,39 @@ module ts { return ~low; } + export function reduceLeft(array: T[], f: (a: T, x: T) => T): T; + export function reduceLeft(array: T[], f: (a: U, x: T) => U, initial: U): U; + export function reduceLeft(array: T[], f: (a: U, x: T) => U, initial?: U): U { + if (array) { + var count = array.length; + if (count > 0) { + var pos = 0; + var result = arguments.length <= 2 ? array[pos++] : initial; + while (pos < count) { + result = f(result, array[pos++]); + } + return result; + } + } + return initial; + } + + export function reduceRight(array: T[], f: (a: T, x: T) => T): T; + export function reduceRight(array: T[], f: (a: U, x: T) => U, initial: U): U; + export function reduceRight(array: T[], f: (a: U, x: T) => U, initial?: U): U { + if (array) { + var pos = array.length - 1; + if (pos >= 0) { + var result = arguments.length <= 2 ? array[pos--] : initial; + while (pos >= 0) { + result = f(result, array[pos--]); + } + return result; + } + } + return initial; + } + let hasOwnProperty = Object.prototype.hasOwnProperty; export function hasProperty(map: Map, key: string): boolean { diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts new file mode 100644 index 0000000000000..cf75467e1c5b4 --- /dev/null +++ b/src/compiler/declarationEmitter.ts @@ -0,0 +1,1466 @@ +/// + +module ts { + + interface ModuleElementDeclarationEmitInfo { + node: Node; + outputPos: number; + indent: number; + asynchronousOutput?: string; // If the output for alias was written asynchronously, the corresponding output + subModuleElementDeclarationEmitInfo?: ModuleElementDeclarationEmitInfo[]; + isVisible?: boolean; + } + + interface DeclarationEmit { + reportedDeclarationError: boolean; + moduleElementDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[]; + synchronousDeclarationOutput: string; + referencePathsOutput: string; + } + + type GetSymbolAccessibilityDiagnostic = (symbolAccesibilityResult: SymbolAccessiblityResult) => SymbolAccessibilityDiagnostic; + + interface EmitTextWriterWithSymbolWriter extends EmitTextWriter, SymbolWriter { + getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic; + } + + interface SymbolAccessibilityDiagnostic { + errorNode: Node; + diagnosticMessage: DiagnosticMessage; + typeName?: DeclarationName; + } + + export function getDeclarationDiagnostics(host: EmitHost, resolver: EmitResolver, targetSourceFile: SourceFile): Diagnostic[] { + let diagnostics: Diagnostic[] = []; + let jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, ".js"); + emitDeclarations(host, resolver, diagnostics, jsFilePath, targetSourceFile); + return diagnostics; + } + + function emitDeclarations(host: EmitHost, resolver: EmitResolver, diagnostics: Diagnostic[], jsFilePath: string, root?: SourceFile): DeclarationEmit { + let newLine = host.getNewLine(); + let compilerOptions = host.getCompilerOptions(); + let languageVersion = compilerOptions.target || ScriptTarget.ES3; + + let write: (s: string) => void; + let writeLine: () => void; + let increaseIndent: () => void; + let decreaseIndent: () => void; + let writeTextOfNode: (sourceFile: SourceFile, node: Node) => void; + + let writer = createAndSetNewTextWriterWithSymbolWriter(); + + let enclosingDeclaration: Node; + let currentSourceFile: SourceFile; + let reportedDeclarationError = false; + let emitJsDocComments = compilerOptions.removeComments ? function (declaration: Node) { } : writeJsDocComments; + let emit = compilerOptions.stripInternal ? stripInternal : emitNode; + + let moduleElementDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[] = []; + let asynchronousSubModuleDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[]; + + // Contains the reference paths that needs to go in the declaration file. + // Collecting this separately because reference paths need to be first thing in the declaration file + // and we could be collecting these paths from multiple files into single one with --out option + let referencePathsOutput = ""; + + if (root) { + // Emitting just a single file, so emit references in this file only + if (!compilerOptions.noResolve) { + let addedGlobalFileReference = false; + forEach(root.referencedFiles, fileReference => { + let referencedFile = tryResolveScriptReference(host, root, fileReference); + + // All the references that are not going to be part of same file + if (referencedFile && ((referencedFile.flags & NodeFlags.DeclarationFile) || // This is a declare file reference + shouldEmitToOwnFile(referencedFile, compilerOptions) || // This is referenced file is emitting its own js file + !addedGlobalFileReference)) { // Or the global out file corresponding to this reference was not added + + writeReferencePath(referencedFile); + if (!isExternalModuleOrDeclarationFile(referencedFile)) { + addedGlobalFileReference = true; + } + } + }); + } + + emitSourceFile(root); + + // create asynchronous output for the importDeclarations + if (moduleElementDeclarationEmitInfo.length) { + let oldWriter = writer; + forEach(moduleElementDeclarationEmitInfo, aliasEmitInfo => { + if (aliasEmitInfo.isVisible) { + Debug.assert(aliasEmitInfo.node.kind === SyntaxKind.ImportDeclaration); + createAndSetNewTextWriterWithSymbolWriter(); + Debug.assert(aliasEmitInfo.indent === 0); + writeImportDeclaration(aliasEmitInfo.node); + aliasEmitInfo.asynchronousOutput = writer.getText(); + } + }); + setWriter(oldWriter); + } + } + else { + // Emit references corresponding to this file + let emittedReferencedFiles: SourceFile[] = []; + forEach(host.getSourceFiles(), sourceFile => { + if (!isExternalModuleOrDeclarationFile(sourceFile)) { + // Check what references need to be added + if (!compilerOptions.noResolve) { + forEach(sourceFile.referencedFiles, fileReference => { + let referencedFile = tryResolveScriptReference(host, sourceFile, fileReference); + + // If the reference file is a declaration file or an external module, emit that reference + if (referencedFile && (isExternalModuleOrDeclarationFile(referencedFile) && + !contains(emittedReferencedFiles, referencedFile))) { // If the file reference was not already emitted + + writeReferencePath(referencedFile); + emittedReferencedFiles.push(referencedFile); + } + }); + } + + emitSourceFile(sourceFile); + } + }); + } + + return { + reportedDeclarationError, + moduleElementDeclarationEmitInfo, + synchronousDeclarationOutput: writer.getText(), + referencePathsOutput, + } + + function hasInternalAnnotation(range: CommentRange) { + let text = currentSourceFile.text; + let comment = text.substring(range.pos, range.end); + return comment.indexOf("@internal") >= 0; + } + + function stripInternal(node: Node) { + if (node) { + let leadingCommentRanges = getLeadingCommentRanges(currentSourceFile.text, node.pos); + if (forEach(leadingCommentRanges, hasInternalAnnotation)) { + return; + } + + emitNode(node); + } + } + + function createAndSetNewTextWriterWithSymbolWriter(): EmitTextWriterWithSymbolWriter { + let writer = createTextWriter(newLine); + writer.trackSymbol = trackSymbol; + writer.writeKeyword = writer.write; + writer.writeOperator = writer.write; + writer.writePunctuation = writer.write; + writer.writeSpace = writer.write; + writer.writeStringLiteral = writer.writeLiteral; + writer.writeParameter = writer.write; + writer.writeSymbol = writer.write; + setWriter(writer); + return writer; + } + + function setWriter(newWriter: EmitTextWriterWithSymbolWriter) { + writer = newWriter; + write = newWriter.write; + writeTextOfNode = newWriter.writeTextOfNode; + writeLine = newWriter.writeLine; + increaseIndent = newWriter.increaseIndent; + decreaseIndent = newWriter.decreaseIndent; + } + + function writeAsynchronousModuleElements(nodes: Node[]) { + let oldWriter = writer; + forEach(nodes, declaration => { + let nodeToCheck: Node; + if (declaration.kind === SyntaxKind.VariableDeclaration) { + nodeToCheck = declaration.parent.parent; + } else if (declaration.kind === SyntaxKind.NamedImports || declaration.kind === SyntaxKind.ImportSpecifier || declaration.kind === SyntaxKind.ImportClause) { + Debug.fail("We should be getting ImportDeclaration instead to write"); + } else { + nodeToCheck = declaration; + } + + let moduleElementEmitInfo = forEach(moduleElementDeclarationEmitInfo, declEmitInfo => declEmitInfo.node === nodeToCheck ? declEmitInfo : undefined); + if (!moduleElementEmitInfo && asynchronousSubModuleDeclarationEmitInfo) { + moduleElementEmitInfo = forEach(asynchronousSubModuleDeclarationEmitInfo, declEmitInfo => declEmitInfo.node === nodeToCheck ? declEmitInfo : undefined); + } + + // If the alias was marked as not visible when we saw its declaration, we would have saved the aliasEmitInfo, but if we haven't yet visited the alias declaration + // then we don't need to write it at this point. We will write it when we actually see its declaration + // Eg. + // export function bar(a: foo.Foo) { } + // import foo = require("foo"); + // Writing of function bar would mark alias declaration foo as visible but we haven't yet visited that declaration so do nothing, + // we would write alias foo declaration when we visit it since it would now be marked as visible + if (moduleElementEmitInfo) { + if (moduleElementEmitInfo.node.kind === SyntaxKind.ImportDeclaration) { + // we have to create asynchronous output only after we have collected complete information + // because it is possible to enable multiple bindings as asynchronously visible + moduleElementEmitInfo.isVisible = true; + } + else { + createAndSetNewTextWriterWithSymbolWriter(); + for (let declarationIndent = moduleElementEmitInfo.indent; declarationIndent; declarationIndent--) { + increaseIndent(); + } + + if (nodeToCheck.kind === SyntaxKind.ModuleDeclaration) { + Debug.assert(asynchronousSubModuleDeclarationEmitInfo === undefined); + asynchronousSubModuleDeclarationEmitInfo = []; + } + writeModuleElement(nodeToCheck); + if (nodeToCheck.kind === SyntaxKind.ModuleDeclaration) { + moduleElementEmitInfo.subModuleElementDeclarationEmitInfo = asynchronousSubModuleDeclarationEmitInfo; + asynchronousSubModuleDeclarationEmitInfo = undefined; + } + moduleElementEmitInfo.asynchronousOutput = writer.getText(); + } + } + }); + setWriter(oldWriter); + } + + function handleSymbolAccessibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) { + if (symbolAccesibilityResult.accessibility === SymbolAccessibility.Accessible) { + // write the aliases + if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) { + writeAsynchronousModuleElements(symbolAccesibilityResult.aliasesToMakeVisible); + } + } + else { + // Report error + reportedDeclarationError = true; + let errorInfo = writer.getSymbolAccessibilityDiagnostic(symbolAccesibilityResult); + if (errorInfo) { + if (errorInfo.typeName) { + diagnostics.push(createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, + errorInfo.diagnosticMessage, + getSourceTextOfNodeFromSourceFile(currentSourceFile, errorInfo.typeName), + symbolAccesibilityResult.errorSymbolName, + symbolAccesibilityResult.errorModuleName)); + } + else { + diagnostics.push(createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, + errorInfo.diagnosticMessage, + symbolAccesibilityResult.errorSymbolName, + symbolAccesibilityResult.errorModuleName)); + } + } + } + } + + function trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) { + handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning)); + } + + function writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, type: TypeNode | StringLiteralExpression, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) { + writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; + write(": "); + if (type) { + // Write the type + emitType(type); + } + else { + resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer); + } + } + + function writeReturnTypeAtSignature(signature: SignatureDeclaration, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) { + writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; + write(": "); + if (signature.type) { + // Write the type + emitType(signature.type); + } + else { + resolver.writeReturnTypeOfSignatureDeclaration(signature, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer); + } + } + + function emitLines(nodes: Node[]) { + for (let node of nodes) { + emit(node); + } + } + + function emitSeparatedList(nodes: Node[], separator: string, eachNodeEmitFn: (node: Node) => void, canEmitFn?: (node: Node) => boolean) { + let currentWriterPos = writer.getTextPos(); + for (let node of nodes) { + if (!canEmitFn || canEmitFn(node)) { + if (currentWriterPos !== writer.getTextPos()) { + write(separator); + } + currentWriterPos = writer.getTextPos(); + eachNodeEmitFn(node); + } + } + } + + function emitCommaList(nodes: Node[], eachNodeEmitFn: (node: Node) => void, canEmitFn?: (node: Node) => boolean) { + emitSeparatedList(nodes, ", ", eachNodeEmitFn, canEmitFn); + } + + function writeJsDocComments(declaration: Node) { + if (declaration) { + let jsDocComments = getJsDocComments(declaration, currentSourceFile); + emitNewLineBeforeLeadingComments(currentSourceFile, writer, declaration, jsDocComments); + // jsDoc comments are emitted at /*leading comment1 */space/*leading comment*/space + emitComments(currentSourceFile, writer, jsDocComments, /*trailingSeparator*/ true, newLine, writeCommentRange); + } + } + + function emitTypeWithNewGetSymbolAccessibilityDiagnostic(type: TypeNode | EntityName, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) { + writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; + emitType(type); + } + + function emitType(type: TypeNode | StringLiteralExpression | Identifier | QualifiedName) { + switch (type.kind) { + case SyntaxKind.AnyKeyword: + case SyntaxKind.StringKeyword: + case SyntaxKind.NumberKeyword: + case SyntaxKind.BooleanKeyword: + case SyntaxKind.SymbolKeyword: + case SyntaxKind.VoidKeyword: + case SyntaxKind.StringLiteral: + return writeTextOfNode(currentSourceFile, type); + case SyntaxKind.TypeReference: + return emitTypeReference(type); + case SyntaxKind.TypeQuery: + return emitTypeQuery(type); + case SyntaxKind.ArrayType: + return emitArrayType(type); + case SyntaxKind.TupleType: + return emitTupleType(type); + case SyntaxKind.UnionType: + return emitUnionType(type); + case SyntaxKind.ParenthesizedType: + return emitParenType(type); + case SyntaxKind.FunctionType: + case SyntaxKind.ConstructorType: + return emitSignatureDeclarationWithJsDocComments(type); + case SyntaxKind.TypeLiteral: + return emitTypeLiteral(type); + case SyntaxKind.Identifier: + return emitEntityName(type); + case SyntaxKind.QualifiedName: + return emitEntityName(type); + default: + Debug.fail("Unknown type annotation: " + type.kind); + } + + function emitEntityName(entityName: EntityName) { + let visibilityResult = resolver.isEntityNameVisible(entityName, + // Aliases can be written asynchronously so use correct enclosing declaration + entityName.parent.kind === SyntaxKind.ImportEqualsDeclaration ? entityName.parent : enclosingDeclaration); + + handleSymbolAccessibilityError(visibilityResult); + writeEntityName(entityName); + + function writeEntityName(entityName: EntityName) { + if (entityName.kind === SyntaxKind.Identifier) { + writeTextOfNode(currentSourceFile, entityName); + } + else { + let qualifiedName = entityName; + writeEntityName(qualifiedName.left); + write("."); + writeTextOfNode(currentSourceFile, qualifiedName.right); + } + } + } + + function emitTypeReference(type: TypeReferenceNode) { + emitEntityName(type.typeName); + if (type.typeArguments) { + write("<"); + emitCommaList(type.typeArguments, emitType); + write(">"); + } + } + + function emitTypeQuery(type: TypeQueryNode) { + write("typeof "); + emitEntityName(type.exprName); + } + + function emitArrayType(type: ArrayTypeNode) { + emitType(type.elementType); + write("[]"); + } + + function emitTupleType(type: TupleTypeNode) { + write("["); + emitCommaList(type.elementTypes, emitType); + write("]"); + } + + function emitUnionType(type: UnionTypeNode) { + emitSeparatedList(type.types, " | ", emitType); + } + + function emitParenType(type: ParenthesizedTypeNode) { + write("("); + emitType(type.type); + write(")"); + } + + function emitTypeLiteral(type: TypeLiteralNode) { + write("{"); + if (type.members.length) { + writeLine(); + increaseIndent(); + // write members + emitLines(type.members); + decreaseIndent(); + } + write("}"); + } + } + + function emitSourceFile(node: SourceFile) { + currentSourceFile = node; + enclosingDeclaration = node; + emitLines(node.statements); + } + + function emitExportAssignment(node: ExportAssignment) { + write(node.isExportEquals ? "export = " : "export default "); + if (node.expression.kind === SyntaxKind.Identifier) { + writeTextOfNode(currentSourceFile, node.expression); + } + else { + write(": "); + if (node.type) { + emitType(node.type); + } + else { + writer.getSymbolAccessibilityDiagnostic = getDefaultExportAccessibilityDiagnostic; + resolver.writeTypeOfExpression(node.expression, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer); + } + } + write(";"); + writeLine(); + + // Make all the declarations visible for the export name + if (node.expression.kind === SyntaxKind.Identifier) { + let nodes = resolver.collectLinkedAliases(node.expression); + + // write each of these declarations asynchronously + writeAsynchronousModuleElements(nodes); + } + + function getDefaultExportAccessibilityDiagnostic(diagnostic: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + return { + diagnosticMessage: Diagnostics.Default_export_of_the_module_has_or_is_using_private_name_0, + errorNode: node + }; + } + } + + function isModuleElementVisible(node: Declaration) { + return resolver.isDeclarationVisible(node); + } + + function emitModuleElement(node: Node, isModuleElementVisible: boolean) { + if (isModuleElementVisible) { + writeModuleElement(node); + } + // Import equals declaration in internal module can become visible as part of any emit so lets make sure we add these irrespective + else if (node.kind === SyntaxKind.ImportEqualsDeclaration || + (node.parent.kind === SyntaxKind.SourceFile && isExternalModule(currentSourceFile))) { + let isVisible: boolean; + if (asynchronousSubModuleDeclarationEmitInfo && node.parent.kind !== SyntaxKind.SourceFile) { + // Import declaration of another module that is visited async so lets put it in right spot + asynchronousSubModuleDeclarationEmitInfo.push({ + node, + outputPos: writer.getTextPos(), + indent: writer.getIndent(), + isVisible + }); + } + else { + if (node.kind === SyntaxKind.ImportDeclaration) { + let importDeclaration = node; + if (importDeclaration.importClause) { + isVisible = (importDeclaration.importClause.name && resolver.isDeclarationVisible(importDeclaration.importClause)) || + isVisibleNamedBinding(importDeclaration.importClause.namedBindings); + } + } + moduleElementDeclarationEmitInfo.push({ + node, + outputPos: writer.getTextPos(), + indent: writer.getIndent(), + isVisible + }); + } + } + } + + function writeModuleElement(node: Node) { + switch (node.kind) { + case SyntaxKind.FunctionDeclaration: + return writeFunctionDeclaration(node); + case SyntaxKind.VariableStatement: + return writeVariableStatement(node); + case SyntaxKind.InterfaceDeclaration: + return writeInterfaceDeclaration(node); + case SyntaxKind.ClassDeclaration: + return writeClassDeclaration(node); + case SyntaxKind.TypeAliasDeclaration: + return writeTypeAliasDeclaration(node); + case SyntaxKind.EnumDeclaration: + return writeEnumDeclaration(node); + case SyntaxKind.ModuleDeclaration: + return writeModuleDeclaration(node); + case SyntaxKind.ImportEqualsDeclaration: + return writeImportEqualsDeclaration(node); + case SyntaxKind.ImportDeclaration: + return writeImportDeclaration(node); + default: + Debug.fail("Unknown symbol kind"); + } + } + + function emitModuleElementDeclarationFlags(node: Node) { + // If the node is parented in the current source file we need to emit export declare or just export + if (node.parent === currentSourceFile) { + // If the node is exported + if (node.flags & NodeFlags.Export) { + write("export "); + } + + if (node.flags & NodeFlags.Default) { + write("default "); + } + else if (node.kind !== SyntaxKind.InterfaceDeclaration) { + write("declare "); + } + } + } + + function emitClassMemberDeclarationFlags(node: Declaration) { + if (node.flags & NodeFlags.Private) { + write("private "); + } + else if (node.flags & NodeFlags.Protected) { + write("protected "); + } + + if (node.flags & NodeFlags.Static) { + write("static "); + } + } + + function writeImportEqualsDeclaration(node: ImportEqualsDeclaration) { + // note usage of writer. methods instead of aliases created, just to make sure we are using + // correct writer especially to handle asynchronous alias writing + emitJsDocComments(node); + if (node.flags & NodeFlags.Export) { + write("export "); + } + write("import "); + writeTextOfNode(currentSourceFile, node.name); + write(" = "); + if (isInternalModuleImportEqualsDeclaration(node)) { + emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.moduleReference, getImportEntityNameVisibilityError); + write(";"); + } + else { + write("require("); + writeTextOfNode(currentSourceFile, getExternalModuleImportEqualsDeclarationExpression(node)); + write(");"); + } + writer.writeLine(); + + function getImportEntityNameVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + return { + diagnosticMessage: Diagnostics.Import_declaration_0_is_using_private_name_1, + errorNode: node, + typeName: node.name + }; + } + } + + function isVisibleNamedBinding(namedBindings: NamespaceImport | NamedImports): boolean { + if (namedBindings) { + if (namedBindings.kind === SyntaxKind.NamespaceImport) { + return resolver.isDeclarationVisible(namedBindings); + } + else { + return forEach((namedBindings).elements, namedImport => resolver.isDeclarationVisible(namedImport)); + } + } + } + + function writeImportDeclaration(node: ImportDeclaration) { + if (!node.importClause && !(node.flags & NodeFlags.Export)) { + // do not write non-exported import declarations that don't have import clauses + return; + } + emitJsDocComments(node); + if (node.flags & NodeFlags.Export) { + write("export "); + } + write("import "); + if (node.importClause) { + let currentWriterPos = writer.getTextPos(); + if (node.importClause.name && resolver.isDeclarationVisible(node.importClause)) { + writeTextOfNode(currentSourceFile, node.importClause.name); + } + if (node.importClause.namedBindings && isVisibleNamedBinding(node.importClause.namedBindings)) { + if (currentWriterPos !== writer.getTextPos()) { + // If the default binding was emitted, write the separated + write(", "); + } + if (node.importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { + write("* as "); + writeTextOfNode(currentSourceFile, (node.importClause.namedBindings).name); + } + else { + write("{ "); + emitCommaList((node.importClause.namedBindings).elements, emitImportOrExportSpecifier, resolver.isDeclarationVisible); + write(" }"); + } + } + write(" from "); + } + writeTextOfNode(currentSourceFile, node.moduleSpecifier); + write(";"); + writer.writeLine(); + } + + function emitImportOrExportSpecifier(node: ImportOrExportSpecifier) { + if (node.propertyName) { + writeTextOfNode(currentSourceFile, node.propertyName); + write(" as "); + } + writeTextOfNode(currentSourceFile, node.name); + } + + function emitExportSpecifier(node: ExportSpecifier) { + emitImportOrExportSpecifier(node); + + // Make all the declarations visible for the export name + let nodes = resolver.collectLinkedAliases(node.propertyName || node.name); + + // write each of these declarations asynchronously + writeAsynchronousModuleElements(nodes); + } + + function emitExportDeclaration(node: ExportDeclaration) { + emitJsDocComments(node); + write("export "); + if (node.exportClause) { + write("{ "); + emitCommaList(node.exportClause.elements, emitExportSpecifier); + write(" }"); + } + else { + write("*"); + } + if (node.moduleSpecifier) { + write(" from "); + writeTextOfNode(currentSourceFile, node.moduleSpecifier); + } + write(";"); + writer.writeLine(); + } + + function writeModuleDeclaration(node: ModuleDeclaration) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + write("module "); + writeTextOfNode(currentSourceFile, node.name); + while (node.body.kind !== SyntaxKind.ModuleBlock) { + node = node.body; + write("."); + writeTextOfNode(currentSourceFile, node.name); + } + let prevEnclosingDeclaration = enclosingDeclaration; + enclosingDeclaration = node; + write(" {"); + writeLine(); + increaseIndent(); + emitLines((node.body).statements); + decreaseIndent(); + write("}"); + writeLine(); + enclosingDeclaration = prevEnclosingDeclaration; + } + + function writeTypeAliasDeclaration(node: TypeAliasDeclaration) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + write("type "); + writeTextOfNode(currentSourceFile, node.name); + write(" = "); + emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.type, getTypeAliasDeclarationVisibilityError); + write(";"); + writeLine(); + + function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + return { + diagnosticMessage: Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1, + errorNode: node.type, + typeName: node.name + }; + } + } + + function writeEnumDeclaration(node: EnumDeclaration) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + if (isConst(node)) { + write("const ") + } + write("enum "); + writeTextOfNode(currentSourceFile, node.name); + write(" {"); + writeLine(); + increaseIndent(); + emitLines(node.members); + decreaseIndent(); + write("}"); + writeLine(); + } + + function emitEnumMemberDeclaration(node: EnumMember) { + emitJsDocComments(node); + writeTextOfNode(currentSourceFile, node.name); + let enumMemberValue = resolver.getConstantValue(node); + if (enumMemberValue !== undefined) { + write(" = "); + write(enumMemberValue.toString()); + } + write(","); + writeLine(); + } + + function isPrivateMethodTypeParameter(node: TypeParameterDeclaration) { + return node.parent.kind === SyntaxKind.MethodDeclaration && (node.parent.flags & NodeFlags.Private); + } + + function emitTypeParameters(typeParameters: TypeParameterDeclaration[]) { + function emitTypeParameter(node: TypeParameterDeclaration) { + increaseIndent(); + emitJsDocComments(node); + decreaseIndent(); + writeTextOfNode(currentSourceFile, node.name); + // If there is constraint present and this is not a type parameter of the private method emit the constraint + if (node.constraint && !isPrivateMethodTypeParameter(node)) { + write(" extends "); + if (node.parent.kind === SyntaxKind.FunctionType || + node.parent.kind === SyntaxKind.ConstructorType || + (node.parent.parent && node.parent.parent.kind === SyntaxKind.TypeLiteral)) { + Debug.assert(node.parent.kind === SyntaxKind.MethodDeclaration || + node.parent.kind === SyntaxKind.MethodSignature || + node.parent.kind === SyntaxKind.FunctionType || + node.parent.kind === SyntaxKind.ConstructorType || + node.parent.kind === SyntaxKind.CallSignature || + node.parent.kind === SyntaxKind.ConstructSignature); + emitType(node.constraint); + } + else { + emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.constraint, getTypeParameterConstraintVisibilityError); + } + } + + function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + // Type parameter constraints are named by user so we should always be able to name it + let diagnosticMessage: DiagnosticMessage; + switch (node.parent.kind) { + case SyntaxKind.ClassDeclaration: + diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1; + break; + + case SyntaxKind.InterfaceDeclaration: + diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1; + break; + + case SyntaxKind.ConstructSignature: + diagnosticMessage = Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; + break; + + case SyntaxKind.CallSignature: + diagnosticMessage = Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; + break; + + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + if (node.parent.flags & NodeFlags.Static) { + diagnosticMessage = Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; + } + else if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) { + diagnosticMessage = Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; + } + else { + diagnosticMessage = Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; + } + break; + + case SyntaxKind.FunctionDeclaration: + diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1; + break; + + default: + Debug.fail("This is unknown parent for type parameter: " + node.parent.kind); + } + + return { + diagnosticMessage, + errorNode: node, + typeName: node.name + }; + } + } + + if (typeParameters) { + write("<"); + emitCommaList(typeParameters, emitTypeParameter); + write(">"); + } + } + + function emitHeritageClause(typeReferences: TypeReferenceNode[], isImplementsList: boolean) { + if (typeReferences) { + write(isImplementsList ? " implements " : " extends "); + emitCommaList(typeReferences, emitTypeOfTypeReference); + } + + function emitTypeOfTypeReference(node: TypeReferenceNode) { + emitTypeWithNewGetSymbolAccessibilityDiagnostic(node, getHeritageClauseVisibilityError); + + function getHeritageClauseVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + let diagnosticMessage: DiagnosticMessage; + // Heritage clause is written by user so it can always be named + if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) { + // Class or Interface implemented/extended is inaccessible + diagnosticMessage = isImplementsList ? + Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 : + Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1; + } + else { + // interface is inaccessible + diagnosticMessage = Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1; + } + + return { + diagnosticMessage, + errorNode: node, + typeName: (node.parent.parent).name + }; + } + } + } + + function writeClassDeclaration(node: ClassDeclaration) { + function emitParameterProperties(constructorDeclaration: ConstructorDeclaration) { + if (constructorDeclaration) { + forEach(constructorDeclaration.parameters, param => { + if (param.flags & NodeFlags.AccessibilityModifier) { + emitPropertyDeclaration(param); + } + }); + } + } + + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + write("class "); + writeTextOfNode(currentSourceFile, node.name); + let prevEnclosingDeclaration = enclosingDeclaration; + enclosingDeclaration = node; + emitTypeParameters(node.typeParameters); + let baseTypeNode = getClassBaseTypeNode(node); + if (baseTypeNode) { + emitHeritageClause([baseTypeNode], /*isImplementsList*/ false); + } + emitHeritageClause(getClassImplementedTypeNodes(node), /*isImplementsList*/ true); + write(" {"); + writeLine(); + increaseIndent(); + emitParameterProperties(getFirstConstructorWithBody(node)); + emitLines(node.members); + decreaseIndent(); + write("}"); + writeLine(); + enclosingDeclaration = prevEnclosingDeclaration; + } + + function writeInterfaceDeclaration(node: InterfaceDeclaration) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + write("interface "); + writeTextOfNode(currentSourceFile, node.name); + let prevEnclosingDeclaration = enclosingDeclaration; + enclosingDeclaration = node; + emitTypeParameters(node.typeParameters); + emitHeritageClause(getInterfaceBaseTypeNodes(node), /*isImplementsList*/ false); + write(" {"); + writeLine(); + increaseIndent(); + emitLines(node.members); + decreaseIndent(); + write("}"); + writeLine(); + enclosingDeclaration = prevEnclosingDeclaration; + } + + function emitPropertyDeclaration(node: Declaration) { + if (hasDynamicName(node)) { + return; + } + + emitJsDocComments(node); + emitClassMemberDeclarationFlags(node); + emitVariableDeclaration(node); + write(";"); + writeLine(); + } + + function emitVariableDeclaration(node: VariableDeclaration) { + // If we are emitting property it isn't moduleElement and hence we already know it needs to be emitted + // so there is no check needed to see if declaration is visible + if (node.kind !== SyntaxKind.VariableDeclaration || resolver.isDeclarationVisible(node)) { + if (isBindingPattern(node.name)) { + emitBindingPattern(node.name); + } + else { + // If this node is a computed name, it can only be a symbol, because we've already skipped + // it if it's not a well known symbol. In that case, the text of the name will be exactly + // what we want, namely the name expression enclosed in brackets. + writeTextOfNode(currentSourceFile, node.name); + // If optional property emit ? + if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && hasQuestionToken(node)) { + write("?"); + } + if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && node.parent.kind === SyntaxKind.TypeLiteral) { + emitTypeOfVariableDeclarationFromTypeLiteral(node); + } + else if (!(node.flags & NodeFlags.Private)) { + writeTypeOfDeclaration(node, node.type, getVariableDeclarationTypeVisibilityError); + } + } + } + + function getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult: SymbolAccessiblityResult) { + if (node.kind === SyntaxKind.VariableDeclaration) { + return symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Exported_variable_0_has_or_is_using_private_name_1; + } + // This check is to ensure we don't report error on constructor parameter property as that error would be reported during parameter emit + else if (node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) { + // TODO(jfreeman): Deal with computed properties in error reporting. + if (node.flags & NodeFlags.Static) { + return symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1; + } + else if (node.parent.kind === SyntaxKind.ClassDeclaration) { + return symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1; + } + else { + // Interfaces cannot have types that cannot be named + return symbolAccesibilityResult.errorModuleName ? + Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1; + } + } + } + + function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + let diagnosticMessage = getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult); + return diagnosticMessage !== undefined ? { + diagnosticMessage, + errorNode: node, + typeName: node.name + } : undefined; + } + + function emitBindingPattern(bindingPattern: BindingPattern) { + emitCommaList(bindingPattern.elements, emitBindingElement); + } + + function emitBindingElement(bindingElement: BindingElement) { + function getBindingElementTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + let diagnosticMessage = getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult); + return diagnosticMessage !== undefined ? { + diagnosticMessage, + errorNode: bindingElement, + typeName: bindingElement.name + } : undefined; + } + + if (bindingElement.name) { + if (isBindingPattern(bindingElement.name)) { + emitBindingPattern(bindingElement.name); + } + else { + writeTextOfNode(currentSourceFile, bindingElement.name); + writeTypeOfDeclaration(bindingElement, /*type*/ undefined, getBindingElementTypeVisibilityError); + } + } + } + } + + function emitTypeOfVariableDeclarationFromTypeLiteral(node: VariableLikeDeclaration) { + // if this is property of type literal, + // or is parameter of method/call/construct/index signature of type literal + // emit only if type is specified + if (node.type) { + write(": "); + emitType(node.type); + } + } + + function isVariableStatementVisible(node: VariableStatement) { + return forEach(node.declarationList.declarations, varDeclaration => resolver.isDeclarationVisible(varDeclaration)); + } + + function writeVariableStatement(node: VariableStatement) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + if (isLet(node.declarationList)) { + write("let "); + } + else if (isConst(node.declarationList)) { + write("const "); + } + else { + write("var "); + } + emitCommaList(node.declarationList.declarations, emitVariableDeclaration, resolver.isDeclarationVisible); + write(";"); + writeLine(); + } + + function emitAccessorDeclaration(node: AccessorDeclaration) { + if (hasDynamicName(node)) { + return; + } + + let accessors = getAllAccessorDeclarations((node.parent).members, node); + let accessorWithTypeAnnotation: AccessorDeclaration; + + if (node === accessors.firstAccessor) { + emitJsDocComments(accessors.getAccessor); + emitJsDocComments(accessors.setAccessor); + emitClassMemberDeclarationFlags(node); + writeTextOfNode(currentSourceFile, node.name); + if (!(node.flags & NodeFlags.Private)) { + accessorWithTypeAnnotation = node; + let type = getTypeAnnotationFromAccessor(node); + if (!type) { + // couldn't get type for the first accessor, try the another one + let anotherAccessor = node.kind === SyntaxKind.GetAccessor ? accessors.setAccessor : accessors.getAccessor; + type = getTypeAnnotationFromAccessor(anotherAccessor); + if (type) { + accessorWithTypeAnnotation = anotherAccessor; + } + } + writeTypeOfDeclaration(node, type, getAccessorDeclarationTypeVisibilityError); + } + write(";"); + writeLine(); + } + + function getTypeAnnotationFromAccessor(accessor: AccessorDeclaration): TypeNode | StringLiteralExpression { + if (accessor) { + return accessor.kind === SyntaxKind.GetAccessor + ? accessor.type // Getter - return type + : accessor.parameters.length > 0 + ? accessor.parameters[0].type // Setter parameter type + : undefined; + } + } + + function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + let diagnosticMessage: DiagnosticMessage; + if (accessorWithTypeAnnotation.kind === SyntaxKind.SetAccessor) { + // Setters have to have type named and cannot infer it so, the type should always be named + if (accessorWithTypeAnnotation.parent.flags & NodeFlags.Static) { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1; + } + else { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1; + } + return { + diagnosticMessage, + errorNode: accessorWithTypeAnnotation.parameters[0], + // TODO(jfreeman): Investigate why we are passing node.name instead of node.parameters[0].name + typeName: accessorWithTypeAnnotation.name + }; + } + else { + if (accessorWithTypeAnnotation.flags & NodeFlags.Static) { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : + Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0; + } + else { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : + Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0; + } + return { + diagnosticMessage, + errorNode: accessorWithTypeAnnotation.name, + typeName: undefined + }; + } + } + } + + function writeFunctionDeclaration(node: FunctionLikeDeclaration) { + if (hasDynamicName(node)) { + return; + } + + // If we are emitting Method/Constructor it isn't moduleElement and hence already determined to be emitting + // so no need to verify if the declaration is visible + if (!resolver.isImplementationOfOverload(node)) { + emitJsDocComments(node); + if (node.kind === SyntaxKind.FunctionDeclaration) { + emitModuleElementDeclarationFlags(node); + } + else if (node.kind === SyntaxKind.MethodDeclaration) { + emitClassMemberDeclarationFlags(node); + } + if (node.kind === SyntaxKind.FunctionDeclaration) { + write("function "); + writeTextOfNode(currentSourceFile, node.name); + } + else if (node.kind === SyntaxKind.Constructor) { + write("constructor"); + } + else { + writeTextOfNode(currentSourceFile, node.name); + if (hasQuestionToken(node)) { + write("?"); + } + } + emitSignatureDeclaration(node); + } + } + + function emitSignatureDeclarationWithJsDocComments(node: SignatureDeclaration) { + emitJsDocComments(node); + emitSignatureDeclaration(node); + } + + function emitSignatureDeclaration(node: SignatureDeclaration) { + // Construct signature or constructor type write new Signature + if (node.kind === SyntaxKind.ConstructSignature || node.kind === SyntaxKind.ConstructorType) { + write("new "); + } + emitTypeParameters(node.typeParameters); + if (node.kind === SyntaxKind.IndexSignature) { + write("["); + } + else { + write("("); + } + + let prevEnclosingDeclaration = enclosingDeclaration; + enclosingDeclaration = node; + + // Parameters + emitCommaList(node.parameters, emitParameterDeclaration); + + if (node.kind === SyntaxKind.IndexSignature) { + write("]"); + } + else { + write(")"); + } + + // If this is not a constructor and is not private, emit the return type + let isFunctionTypeOrConstructorType = node.kind === SyntaxKind.FunctionType || node.kind === SyntaxKind.ConstructorType; + if (isFunctionTypeOrConstructorType || node.parent.kind === SyntaxKind.TypeLiteral) { + // Emit type literal signature return type only if specified + if (node.type) { + write(isFunctionTypeOrConstructorType ? " => " : ": "); + emitType(node.type); + } + } + else if (node.kind !== SyntaxKind.Constructor && !(node.flags & NodeFlags.Private)) { + writeReturnTypeAtSignature(node, getReturnTypeVisibilityError); + } + + enclosingDeclaration = prevEnclosingDeclaration; + + if (!isFunctionTypeOrConstructorType) { + write(";"); + writeLine(); + } + + function getReturnTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + let diagnosticMessage: DiagnosticMessage; + switch (node.kind) { + case SyntaxKind.ConstructSignature: + // Interfaces cannot have return types that cannot be named + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0; + break; + + case SyntaxKind.CallSignature: + // Interfaces cannot have return types that cannot be named + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0; + break; + + case SyntaxKind.IndexSignature: + // Interfaces cannot have return types that cannot be named + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0; + break; + + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + if (node.flags & NodeFlags.Static) { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : + Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0; + } + else if (node.parent.kind === SyntaxKind.ClassDeclaration) { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : + Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0; + } + else { + // Interfaces cannot have return types that cannot be named + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0; + } + break; + + case SyntaxKind.FunctionDeclaration: + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : + Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_exported_function_has_or_is_using_private_name_0; + break; + + default: + Debug.fail("This is unknown kind for signature: " + node.kind); + } + + return { + diagnosticMessage, + errorNode: node.name || node, + }; + } + } + + function emitParameterDeclaration(node: ParameterDeclaration) { + increaseIndent(); + emitJsDocComments(node); + if (node.dotDotDotToken) { + write("..."); + } + if (isBindingPattern(node.name)) { + write("_" + indexOf((node.parent).parameters, node)); + } + else { + writeTextOfNode(currentSourceFile, node.name); + } + if (node.initializer || hasQuestionToken(node)) { + write("?"); + } + decreaseIndent(); + + if (node.parent.kind === SyntaxKind.FunctionType || + node.parent.kind === SyntaxKind.ConstructorType || + node.parent.parent.kind === SyntaxKind.TypeLiteral) { + emitTypeOfVariableDeclarationFromTypeLiteral(node); + } + else if (!(node.parent.flags & NodeFlags.Private)) { + writeTypeOfDeclaration(node, node.type, getParameterDeclarationTypeVisibilityError); + } + + function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + let diagnosticMessage: DiagnosticMessage; + switch (node.parent.kind) { + case SyntaxKind.Constructor: + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1; + break; + + case SyntaxKind.ConstructSignature: + // Interfaces cannot have parameter types that cannot be named + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; + break; + + case SyntaxKind.CallSignature: + // Interfaces cannot have parameter types that cannot be named + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; + break; + + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + if (node.parent.flags & NodeFlags.Static) { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; + } + else if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; + } + else { + // Interfaces cannot have parameter types that cannot be named + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; + } + break; + + case SyntaxKind.FunctionDeclaration: + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1; + break; + + default: + Debug.fail("This is unknown parent for parameter: " + node.parent.kind); + } + + return { + diagnosticMessage, + errorNode: node, + typeName: node.name + }; + } + } + + function emitNode(node: Node) { + switch (node.kind) { + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.ModuleDeclaration: + case SyntaxKind.ImportEqualsDeclaration: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.ClassDeclaration: + case SyntaxKind.TypeAliasDeclaration: + case SyntaxKind.EnumDeclaration: + return emitModuleElement(node, isModuleElementVisible(node)); + case SyntaxKind.VariableStatement: + return emitModuleElement(node, isVariableStatementVisible(node)); + case SyntaxKind.ImportDeclaration: + // Import declaration without import clause is visible, otherwise it is not visible + return emitModuleElement(node, /*isModuleElementVisible*/!(node).importClause); + case SyntaxKind.ExportDeclaration: + return emitExportDeclaration(node); + case SyntaxKind.Constructor: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + return writeFunctionDeclaration(node); + case SyntaxKind.ConstructSignature: + case SyntaxKind.CallSignature: + case SyntaxKind.IndexSignature: + return emitSignatureDeclarationWithJsDocComments(node); + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + return emitAccessorDeclaration(node); + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + return emitPropertyDeclaration(node); + case SyntaxKind.EnumMember: + return emitEnumMemberDeclaration(node); + case SyntaxKind.ExportAssignment: + return emitExportAssignment(node); + case SyntaxKind.SourceFile: + return emitSourceFile(node); + } + } + + function writeReferencePath(referencedFile: SourceFile) { + let declFileName = referencedFile.flags & NodeFlags.DeclarationFile + ? referencedFile.fileName // Declaration file, use declaration file name + : shouldEmitToOwnFile(referencedFile, compilerOptions) + ? getOwnEmitOutputFilePath(referencedFile, host, ".d.ts") // Own output file so get the .d.ts file + : removeFileExtension(compilerOptions.out) + ".d.ts";// Global out file + + declFileName = getRelativePathToDirectoryOrUrl( + getDirectoryPath(normalizeSlashes(jsFilePath)), + declFileName, + host.getCurrentDirectory(), + host.getCanonicalFileName, + /*isAbsolutePathAnUrl*/ false); + + referencePathsOutput += "/// " + newLine; + } + } + + // @internal + export function writeDeclarationFile(jsFilePath: string, sourceFile: SourceFile, host: EmitHost, resolver: EmitResolver, diagnostics: Diagnostic[]) { + let emitDeclarationResult = emitDeclarations(host, resolver, diagnostics, jsFilePath, sourceFile); + // TODO(shkamat): Should we not write any declaration file if any of them can produce error, + // or should we just not write this file like we are doing now + if (!emitDeclarationResult.reportedDeclarationError) { + let declarationOutput = emitDeclarationResult.referencePathsOutput + + getDeclarationOutput(emitDeclarationResult.synchronousDeclarationOutput, emitDeclarationResult.moduleElementDeclarationEmitInfo); + writeFile(host, diagnostics, removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, host.getCompilerOptions().emitBOM); + } + + function getDeclarationOutput(synchronousDeclarationOutput: string, moduleElementDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[]) { + let appliedSyncOutputPos = 0; + let declarationOutput = ""; + // apply asynchronous additions to the synchronous output + forEach(moduleElementDeclarationEmitInfo, aliasEmitInfo => { + if (aliasEmitInfo.asynchronousOutput) { + declarationOutput += synchronousDeclarationOutput.substring(appliedSyncOutputPos, aliasEmitInfo.outputPos); + declarationOutput += getDeclarationOutput(aliasEmitInfo.asynchronousOutput, aliasEmitInfo.subModuleElementDeclarationEmitInfo); + appliedSyncOutputPos = aliasEmitInfo.outputPos; + } + }); + declarationOutput += synchronousDeclarationOutput.substring(appliedSyncOutputPos); + return declarationOutput; + } + } +} \ No newline at end of file diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 361f656fc9168..967afd171bac8 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -157,6 +157,14 @@ module ts { Catch_clause_variable_cannot_have_an_initializer: { code: 1197, category: DiagnosticCategory.Error, key: "Catch clause variable cannot have an initializer." }, An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive: { code: 1198, category: DiagnosticCategory.Error, key: "An extended Unicode escape value must be between 0x0 and 0x10FFFF inclusive." }, Unterminated_Unicode_escape_sequence: { code: 1199, category: DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." }, + Line_terminator_not_permitted_before_arrow: { code: 1200, category: DiagnosticCategory.Error, key: "Line terminator not permitted before arrow." }, + A_type_annotation_on_an_export_statement_is_only_allowed_in_an_ambient_external_module_declaration: { code: 1201, category: DiagnosticCategory.Error, key: "A type annotation on an export statement is only allowed in an ambient external module declaration." }, + Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead: { code: 1202, category: DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead." }, + Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead: { code: 1203, category: DiagnosticCategory.Error, key: "Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead." }, + Cannot_compile_external_modules_into_amd_or_commonjs_when_targeting_es6_or_higher: { code: 1204, category: DiagnosticCategory.Error, key: "Cannot compile external modules into amd or commonjs when targeting es6 or higher." }, + Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1205, category: DiagnosticCategory.Error, key: "Decorators are only available when targeting ECMAScript 5 and higher." }, + Decorators_are_not_valid_here: { code: 1206, category: DiagnosticCategory.Error, key: "Decorators are not valid here." }, + Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name: { code: 1207, category: DiagnosticCategory.Error, key: "Decorators cannot be applied to multiple get/set accessors of the same name." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, @@ -339,9 +347,10 @@ module ts { Cannot_redeclare_identifier_0_in_catch_clause: { code: 2492, category: DiagnosticCategory.Error, key: "Cannot redeclare identifier '{0}' in catch clause" }, Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2: { code: 2493, category: DiagnosticCategory.Error, key: "Tuple type '{0}' with length '{1}' cannot be assigned to tuple with length '{2}'." }, Using_a_string_in_a_for_of_statement_is_only_supported_in_ECMAScript_5_and_higher: { code: 2494, category: DiagnosticCategory.Error, key: "Using a string in a 'for...of' statement is only supported in ECMAScript 5 and higher." }, - Type_0_is_not_an_array_type_or_a_string_type: { code: 2461, category: DiagnosticCategory.Error, key: "Type '{0}' is not an array type or a string type." }, - External_module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct: { code: 2496, category: DiagnosticCategory.Error, key: "External module '{0}' resolves to a non-module entity and cannot be imported using this construct." }, - External_module_0_uses_export_and_cannot_be_used_with_export_Asterisk: { code: 2497, category: DiagnosticCategory.Error, key: "External module '{0}' uses 'export =' and cannot be used with 'export *'." }, + Type_0_is_not_an_array_type_or_a_string_type: { code: 2495, category: DiagnosticCategory.Error, key: "Type '{0}' is not an array type or a string type." }, + The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression: { code: 2496, category: DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression." }, + External_module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct: { code: 2497, category: DiagnosticCategory.Error, key: "External module '{0}' resolves to a non-module entity and cannot be imported using this construct." }, + External_module_0_uses_export_and_cannot_be_used_with_export_Asterisk: { code: 2498, category: DiagnosticCategory.Error, key: "External module '{0}' uses 'export =' and cannot be used with 'export *'." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -411,6 +420,7 @@ module ts { Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 4077, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." }, Parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4078, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using private name '{1}'." }, Exported_type_alias_0_has_or_is_using_private_name_1: { code: 4081, category: DiagnosticCategory.Error, key: "Exported type alias '{0}' has or is using private name '{1}'." }, + Default_export_of_the_module_has_or_is_using_private_name_0: { code: 4082, category: DiagnosticCategory.Error, key: "Default export of the module has or is using private name '{0}'." }, Loop_contains_block_scoped_variable_0_referenced_by_a_function_in_the_loop_This_is_only_supported_in_ECMAScript_6_or_higher: { code: 4091, category: DiagnosticCategory.Error, key: "Loop contains block-scoped variable '{0}' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher." }, The_current_host_does_not_support_the_0_option: { code: 5001, category: DiagnosticCategory.Error, key: "The current host does not support the '{0}' option." }, Cannot_find_the_common_subdirectory_path_for_the_input_files: { code: 5009, category: DiagnosticCategory.Error, key: "Cannot find the common subdirectory path for the input files." }, @@ -488,6 +498,5 @@ module ts { You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library: { code: 8001, category: DiagnosticCategory.Error, key: "You cannot rename elements that are defined in the standard TypeScript library." }, yield_expressions_are_not_currently_supported: { code: 9000, category: DiagnosticCategory.Error, key: "'yield' expressions are not currently supported." }, Generators_are_not_currently_supported: { code: 9001, category: DiagnosticCategory.Error, key: "Generators are not currently supported." }, - The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression: { code: 9002, category: DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression." }, }; } \ No newline at end of file diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 6133642865a59..6e24afad80c4a 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -617,8 +617,41 @@ }, "Unterminated Unicode escape sequence.": { "category": "Error", - "code": 1199 + "code": 1199 }, + "Line terminator not permitted before arrow.": { + "category": "Error", + "code": 1200 + }, + "A type annotation on an export statement is only allowed in an ambient external module declaration.": { + "category": "Error", + "code": 1201 + }, + "Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead.": { + "category": "Error", + "code": 1202 + }, + "Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead.": { + "category": "Error", + "code": 1203 + }, + "Cannot compile external modules into amd or commonjs when targeting es6 or higher.": { + "category": "Error", + "code": 1204 + }, + "Decorators are only available when targeting ECMAScript 5 and higher.": { + "category": "Error", + "code": 1205 + }, + "Decorators are not valid here.": { + "category": "Error", + "code": 1206 + }, + "Decorators cannot be applied to multiple get/set accessors of the same name.": { + "category": "Error", + "code": 1207 + }, + "Duplicate identifier '{0}'.": { "category": "Error", "code": 2300 @@ -1349,16 +1382,20 @@ }, "Type '{0}' is not an array type or a string type.": { "category": "Error", - "code": 2461 + "code": 2495 }, - "External module '{0}' resolves to a non-module entity and cannot be imported using this construct.": { + "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.": { "category": "Error", "code": 2496 }, - "External module '{0}' uses 'export =' and cannot be used with 'export *'.": { + "External module '{0}' resolves to a non-module entity and cannot be imported using this construct.": { "category": "Error", "code": 2497 }, + "External module '{0}' uses 'export =' and cannot be used with 'export *'.": { + "category": "Error", + "code": 2498 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", @@ -1636,6 +1673,10 @@ "category": "Error", "code": 4081 }, + "Default export of the module has or is using private name '{0}'.": { + "category": "Error", + "code": 4082 + }, "Loop contains block-scoped variable '{0}' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher.": { "category": "Error", "code": 4091 @@ -1944,9 +1985,5 @@ "Generators are not currently supported.": { "category": "Error", "code": 9001 - }, - "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.": { - "category": "Error", - "code": 9002 } } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index d4271c2383023..02531593de6ff 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1,1523 +1,23 @@ /// +/// module ts { - interface EmitTextWriter { - write(s: string): void; - writeTextOfNode(sourceFile: SourceFile, node: Node): void; - writeLine(): void; - increaseIndent(): void; - decreaseIndent(): void; - getText(): string; - rawWrite(s: string): void; - writeLiteral(s: string): void; - getTextPos(): number; - getLine(): number; - getColumn(): number; - getIndent(): number; - } - - interface SymbolAccessibilityDiagnostic { - errorNode: Node; - diagnosticMessage: DiagnosticMessage; - typeName?: DeclarationName; - } - - // represents one LexicalEnvironment frame to store unique generated names - interface ScopeFrame { - names: Map; - previous: ScopeFrame; - } - - type GetSymbolAccessibilityDiagnostic = (symbolAccesibilityResult: SymbolAccessiblityResult) => SymbolAccessibilityDiagnostic; - - interface EmitTextWriterWithSymbolWriter extends EmitTextWriter, SymbolWriter { - getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic; - } - - interface AliasDeclarationEmitInfo { - declaration: ImportEqualsDeclaration; - outputPos: number; - indent: number; - asynchronousOutput?: string; // If the output for alias was written asynchronously, the corresponding output - } - - interface DeclarationEmit { - reportedDeclarationError: boolean; - aliasDeclarationEmitInfo: AliasDeclarationEmitInfo[]; - synchronousDeclarationOutput: string; - referencePathsOutput: string; - } - - let indentStrings: string[] = ["", " "]; - export function getIndentString(level: number) { - if (indentStrings[level] === undefined) { - indentStrings[level] = getIndentString(level - 1) + indentStrings[1]; - } - return indentStrings[level]; - } - - function getIndentSize() { - return indentStrings[1].length; - } - - export function shouldEmitToOwnFile(sourceFile: SourceFile, compilerOptions: CompilerOptions): boolean { - if (!isDeclarationFile(sourceFile)) { - if ((isExternalModule(sourceFile) || !compilerOptions.out) && !fileExtensionIs(sourceFile.fileName, ".js")) { - return true; - } - return false; - } - return false; - } - - export function isExternalModuleOrDeclarationFile(sourceFile: SourceFile) { - return isExternalModule(sourceFile) || isDeclarationFile(sourceFile); - } - - function createTextWriter(newLine: String): EmitTextWriter { - let output = ""; - let indent = 0; - let lineStart = true; - let lineCount = 0; - let linePos = 0; - - function write(s: string) { - if (s && s.length) { - if (lineStart) { - output += getIndentString(indent); - lineStart = false; - } - output += s; - } - } - - function rawWrite(s: string) { - if (s !== undefined) { - if (lineStart) { - lineStart = false; - } - output += s; - } - } - - function writeLiteral(s: string) { - if (s && s.length) { - write(s); - let lineStartsOfS = computeLineStarts(s); - if (lineStartsOfS.length > 1) { - lineCount = lineCount + lineStartsOfS.length - 1; - linePos = output.length - s.length + lineStartsOfS[lineStartsOfS.length - 1]; - } - } - } - - function writeLine() { - if (!lineStart) { - output += newLine; - lineCount++; - linePos = output.length; - lineStart = true; - } - } - - function writeTextOfNode(sourceFile: SourceFile, node: Node) { - write(getSourceTextOfNodeFromSourceFile(sourceFile, node)); - } - - return { - write, - rawWrite, - writeTextOfNode, - writeLiteral, - writeLine, - increaseIndent: () => indent++, - decreaseIndent: () => indent--, - getIndent: () => indent, - getTextPos: () => output.length, - getLine: () => lineCount + 1, - getColumn: () => lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1, - getText: () => output, - }; - } - - function getLineOfLocalPosition(currentSourceFile: SourceFile, pos: number) { - return getLineAndCharacterOfPosition(currentSourceFile, pos).line; - } - - function emitNewLineBeforeLeadingComments(currentSourceFile: SourceFile, writer: EmitTextWriter, node: TextRange, leadingComments: CommentRange[]) { - // If the leading comments start on different line than the start of node, write new line - if (leadingComments && leadingComments.length && node.pos !== leadingComments[0].pos && - getLineOfLocalPosition(currentSourceFile, node.pos) !== getLineOfLocalPosition(currentSourceFile, leadingComments[0].pos)) { - writer.writeLine(); - } - } - - function emitComments(currentSourceFile: SourceFile, writer: EmitTextWriter, comments: CommentRange[], trailingSeparator: boolean, newLine: string, - writeComment: (currentSourceFile: SourceFile, writer: EmitTextWriter, comment: CommentRange, newLine: string) => void) { - let emitLeadingSpace = !trailingSeparator; - forEach(comments, comment => { - if (emitLeadingSpace) { - writer.write(" "); - emitLeadingSpace = false; - } - writeComment(currentSourceFile, writer, comment, newLine); - if (comment.hasTrailingNewLine) { - writer.writeLine(); - } - else if (trailingSeparator) { - writer.write(" "); - } - else { - // Emit leading space to separate comment during next comment emit - emitLeadingSpace = true; - } - }); - } - - function writeCommentRange(currentSourceFile: SourceFile, writer: EmitTextWriter, comment: CommentRange, newLine: string){ - if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) { - let firstCommentLineAndCharacter = getLineAndCharacterOfPosition(currentSourceFile, comment.pos); - let lineCount = getLineStarts(currentSourceFile).length; - let firstCommentLineIndent: number; - for (let pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) { - let nextLineStart = (currentLine + 1) === lineCount - ? currentSourceFile.text.length + 1 - : getStartPositionOfLine(currentLine + 1, currentSourceFile); - - if (pos !== comment.pos) { - // If we are not emitting first line, we need to write the spaces to adjust the alignment - if (firstCommentLineIndent === undefined) { - firstCommentLineIndent = calculateIndent(getStartPositionOfLine(firstCommentLineAndCharacter.line, currentSourceFile), comment.pos); - } - - // These are number of spaces writer is going to write at current indent - let currentWriterIndentSpacing = writer.getIndent() * getIndentSize(); - - // Number of spaces we want to be writing - // eg: Assume writer indent - // module m { - // /* starts at character 9 this is line 1 - // * starts at character pos 4 line --1 = 8 - 8 + 3 - // More left indented comment */ --2 = 8 - 8 + 2 - // class c { } - // } - // module m { - // /* this is line 1 -- Assume current writer indent 8 - // * line --3 = 8 - 4 + 5 - // More right indented comment */ --4 = 8 - 4 + 11 - // class c { } - // } - let spacesToEmit = currentWriterIndentSpacing - firstCommentLineIndent + calculateIndent(pos, nextLineStart); - if (spacesToEmit > 0) { - let numberOfSingleSpacesToEmit = spacesToEmit % getIndentSize(); - let indentSizeSpaceString = getIndentString((spacesToEmit - numberOfSingleSpacesToEmit) / getIndentSize()); - - // Write indent size string ( in eg 1: = "", 2: "" , 3: string with 8 spaces 4: string with 12 spaces - writer.rawWrite(indentSizeSpaceString); - - // Emit the single spaces (in eg: 1: 3 spaces, 2: 2 spaces, 3: 1 space, 4: 3 spaces) - while (numberOfSingleSpacesToEmit) { - writer.rawWrite(" "); - numberOfSingleSpacesToEmit--; - } - } - else { - // No spaces to emit write empty string - writer.rawWrite(""); - } - } - - // Write the comment line text - writeTrimmedCurrentLine(pos, nextLineStart); - - pos = nextLineStart; - } - } - else { - // Single line comment of style //.... - writer.write(currentSourceFile.text.substring(comment.pos, comment.end)); - } - - function writeTrimmedCurrentLine(pos: number, nextLineStart: number) { - let end = Math.min(comment.end, nextLineStart - 1); - let currentLineText = currentSourceFile.text.substring(pos, end).replace(/^\s+|\s+$/g, ''); - if (currentLineText) { - // trimmed forward and ending spaces text - writer.write(currentLineText); - if (end !== comment.end) { - writer.writeLine(); - } - } - else { - // Empty string - make sure we write empty line - writer.writeLiteral(newLine); - } - } - - function calculateIndent(pos: number, end: number) { - let currentLineIndent = 0; - for (; pos < end && isWhiteSpace(currentSourceFile.text.charCodeAt(pos)); pos++) { - if (currentSourceFile.text.charCodeAt(pos) === CharacterCodes.tab) { - // Tabs = TabSize = indent size and go to next tabStop - currentLineIndent += getIndentSize() - (currentLineIndent % getIndentSize()); - } - else { - // Single space - currentLineIndent++; - } - } - - return currentLineIndent; - } - } - - function getFirstConstructorWithBody(node: ClassDeclaration): ConstructorDeclaration { - return forEach(node.members, member => { - if (member.kind === SyntaxKind.Constructor && nodeIsPresent((member).body)) { - return member; - } - }); - } - - function getAllAccessorDeclarations(declarations: NodeArray, accessor: AccessorDeclaration) { - let firstAccessor: AccessorDeclaration; - let getAccessor: AccessorDeclaration; - let setAccessor: AccessorDeclaration; - if (hasDynamicName(accessor)) { - firstAccessor = accessor; - if (accessor.kind === SyntaxKind.GetAccessor) { - getAccessor = accessor; - } - else if (accessor.kind === SyntaxKind.SetAccessor) { - setAccessor = accessor; - } - else { - Debug.fail("Accessor has wrong kind"); - } - } - else { - forEach(declarations, (member: Declaration) => { - if ((member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) - && (member.flags & NodeFlags.Static) === (accessor.flags & NodeFlags.Static)) { - let memberName = getPropertyNameForPropertyNameNode(member.name); - let accessorName = getPropertyNameForPropertyNameNode(accessor.name); - if (memberName === accessorName) { - if (!firstAccessor) { - firstAccessor = member; - } - - if (member.kind === SyntaxKind.GetAccessor && !getAccessor) { - getAccessor = member; - } - - if (member.kind === SyntaxKind.SetAccessor && !setAccessor) { - setAccessor = member; - } - } - } - }); - } - return { - firstAccessor, - getAccessor, - setAccessor - }; - } - - function getSourceFilePathInNewDir(sourceFile: SourceFile, host: EmitHost, newDirPath: string) { - let sourceFilePath = getNormalizedAbsolutePath(sourceFile.fileName, host.getCurrentDirectory()); - sourceFilePath = sourceFilePath.replace(host.getCommonSourceDirectory(), ""); - return combinePaths(newDirPath, sourceFilePath); - } - - function getOwnEmitOutputFilePath(sourceFile: SourceFile, host: EmitHost, extension: string){ - let compilerOptions = host.getCompilerOptions(); - let emitOutputFilePathWithoutExtension: string; - if (compilerOptions.outDir) { - emitOutputFilePathWithoutExtension = removeFileExtension(getSourceFilePathInNewDir(sourceFile, host, compilerOptions.outDir)); - } - else { - emitOutputFilePathWithoutExtension = removeFileExtension(sourceFile.fileName); - } - - return emitOutputFilePathWithoutExtension + extension; - } - - function writeFile(host: EmitHost, diagnostics: Diagnostic[], fileName: string, data: string, writeByteOrderMark: boolean) { - host.writeFile(fileName, data, writeByteOrderMark, hostErrorMessage => { - diagnostics.push(createCompilerDiagnostic(Diagnostics.Could_not_write_file_0_Colon_1, fileName, hostErrorMessage)); - }); - } - - function emitDeclarations(host: EmitHost, resolver: EmitResolver, diagnostics: Diagnostic[], jsFilePath: string, root?: SourceFile): DeclarationEmit { - let newLine = host.getNewLine(); - let compilerOptions = host.getCompilerOptions(); - let languageVersion = compilerOptions.target || ScriptTarget.ES3; - - let write: (s: string) => void; - let writeLine: () => void; - let increaseIndent: () => void; - let decreaseIndent: () => void; - let writeTextOfNode: (sourceFile: SourceFile, node: Node) => void; - - let writer = createAndSetNewTextWriterWithSymbolWriter(); - - let enclosingDeclaration: Node; - let currentSourceFile: SourceFile; - let reportedDeclarationError = false; - let emitJsDocComments = compilerOptions.removeComments ? function (declaration: Node) { } : writeJsDocComments; - let emit = compilerOptions.stripInternal ? stripInternal : emitNode; - - let aliasDeclarationEmitInfo: AliasDeclarationEmitInfo[] = []; - - // Contains the reference paths that needs to go in the declaration file. - // Collecting this separately because reference paths need to be first thing in the declaration file - // and we could be collecting these paths from multiple files into single one with --out option - let referencePathsOutput = ""; - - if (root) { - // Emitting just a single file, so emit references in this file only - if (!compilerOptions.noResolve) { - let addedGlobalFileReference = false; - forEach(root.referencedFiles, fileReference => { - let referencedFile = tryResolveScriptReference(host, root, fileReference); - - // All the references that are not going to be part of same file - if (referencedFile && ((referencedFile.flags & NodeFlags.DeclarationFile) || // This is a declare file reference - shouldEmitToOwnFile(referencedFile, compilerOptions) || // This is referenced file is emitting its own js file - !addedGlobalFileReference)) { // Or the global out file corresponding to this reference was not added - - writeReferencePath(referencedFile); - if (!isExternalModuleOrDeclarationFile(referencedFile)) { - addedGlobalFileReference = true; - } - } - }); - } - - emitSourceFile(root); - } - else { - // Emit references corresponding to this file - let emittedReferencedFiles: SourceFile[] = []; - forEach(host.getSourceFiles(), sourceFile => { - if (!isExternalModuleOrDeclarationFile(sourceFile)) { - // Check what references need to be added - if (!compilerOptions.noResolve) { - forEach(sourceFile.referencedFiles, fileReference => { - let referencedFile = tryResolveScriptReference(host, sourceFile, fileReference); - - // If the reference file is a declaration file or an external module, emit that reference - if (referencedFile && (isExternalModuleOrDeclarationFile(referencedFile) && - !contains(emittedReferencedFiles, referencedFile))) { // If the file reference was not already emitted - - writeReferencePath(referencedFile); - emittedReferencedFiles.push(referencedFile); - } - }); - } - - emitSourceFile(sourceFile); - } - }); - } - - return { - reportedDeclarationError, - aliasDeclarationEmitInfo, - synchronousDeclarationOutput: writer.getText(), - referencePathsOutput, - } - - function hasInternalAnnotation(range: CommentRange) { - let text = currentSourceFile.text; - let comment = text.substring(range.pos, range.end); - return comment.indexOf("@internal") >= 0; - } - - function stripInternal(node: Node) { - if (node) { - let leadingCommentRanges = getLeadingCommentRanges(currentSourceFile.text, node.pos); - if (forEach(leadingCommentRanges, hasInternalAnnotation)) { - return; - } - - emitNode(node); - } - } - - function createAndSetNewTextWriterWithSymbolWriter(): EmitTextWriterWithSymbolWriter { - let writer = createTextWriter(newLine); - writer.trackSymbol = trackSymbol; - writer.writeKeyword = writer.write; - writer.writeOperator = writer.write; - writer.writePunctuation = writer.write; - writer.writeSpace = writer.write; - writer.writeStringLiteral = writer.writeLiteral; - writer.writeParameter = writer.write; - writer.writeSymbol = writer.write; - setWriter(writer); - return writer; - } - - function setWriter(newWriter: EmitTextWriterWithSymbolWriter) { - writer = newWriter; - write = newWriter.write; - writeTextOfNode = newWriter.writeTextOfNode; - writeLine = newWriter.writeLine; - increaseIndent = newWriter.increaseIndent; - decreaseIndent = newWriter.decreaseIndent; - } - - function writeAsychronousImportEqualsDeclarations(importEqualsDeclarations: ImportEqualsDeclaration[]) { - let oldWriter = writer; - forEach(importEqualsDeclarations, aliasToWrite => { - let aliasEmitInfo = forEach(aliasDeclarationEmitInfo, declEmitInfo => declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined); - // If the alias was marked as not visible when we saw its declaration, we would have saved the aliasEmitInfo, but if we haven't yet visited the alias declaration - // then we don't need to write it at this point. We will write it when we actually see its declaration - // Eg. - // export function bar(a: foo.Foo) { } - // import foo = require("foo"); - // Writing of function bar would mark alias declaration foo as visible but we haven't yet visited that declaration so do nothing, - // we would write alias foo declaration when we visit it since it would now be marked as visible - if (aliasEmitInfo) { - createAndSetNewTextWriterWithSymbolWriter(); - for (let declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) { - increaseIndent(); - } - writeImportEqualsDeclaration(aliasToWrite); - aliasEmitInfo.asynchronousOutput = writer.getText(); - } - }); - setWriter(oldWriter); - } - - function handleSymbolAccessibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) { - if (symbolAccesibilityResult.accessibility === SymbolAccessibility.Accessible) { - // write the aliases - if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) { - writeAsychronousImportEqualsDeclarations(symbolAccesibilityResult.aliasesToMakeVisible); - } - } - else { - // Report error - reportedDeclarationError = true; - let errorInfo = writer.getSymbolAccessibilityDiagnostic(symbolAccesibilityResult); - if (errorInfo) { - if (errorInfo.typeName) { - diagnostics.push(createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, - errorInfo.diagnosticMessage, - getSourceTextOfNodeFromSourceFile(currentSourceFile, errorInfo.typeName), - symbolAccesibilityResult.errorSymbolName, - symbolAccesibilityResult.errorModuleName)); - } - else { - diagnostics.push(createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, - errorInfo.diagnosticMessage, - symbolAccesibilityResult.errorSymbolName, - symbolAccesibilityResult.errorModuleName)); - } - } - } - } - - function trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) { - handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning)); - } - - function writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, type: TypeNode | StringLiteralExpression, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) { - writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; - write(": "); - if (type) { - // Write the type - emitType(type); - } - else { - resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer); - } - } - - function writeReturnTypeAtSignature(signature: SignatureDeclaration, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) { - writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; - write(": "); - if (signature.type) { - // Write the type - emitType(signature.type); - } - else { - resolver.writeReturnTypeOfSignatureDeclaration(signature, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer); - } - } - - function emitLines(nodes: Node[]) { - for (let node of nodes) { - emit(node); - } - } - - function emitSeparatedList(nodes: Node[], separator: string, eachNodeEmitFn: (node: Node) => void) { - let currentWriterPos = writer.getTextPos(); - for (let node of nodes) { - if (currentWriterPos !== writer.getTextPos()) { - write(separator); - } - currentWriterPos = writer.getTextPos(); - eachNodeEmitFn(node); - } - } - - function emitCommaList(nodes: Node[], eachNodeEmitFn: (node: Node) => void) { - emitSeparatedList(nodes, ", ", eachNodeEmitFn); - } - - function writeJsDocComments(declaration: Node) { - if (declaration) { - let jsDocComments = getJsDocComments(declaration, currentSourceFile); - emitNewLineBeforeLeadingComments(currentSourceFile, writer, declaration, jsDocComments); - // jsDoc comments are emitted at /*leading comment1 */space/*leading comment*/space - emitComments(currentSourceFile, writer, jsDocComments, /*trailingSeparator*/ true, newLine, writeCommentRange); - } - } - - function emitTypeWithNewGetSymbolAccessibilityDiagnostic(type: TypeNode | EntityName, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) { - writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; - emitType(type); - } - - function emitType(type: TypeNode | StringLiteralExpression | Identifier | QualifiedName) { - switch (type.kind) { - case SyntaxKind.AnyKeyword: - case SyntaxKind.StringKeyword: - case SyntaxKind.NumberKeyword: - case SyntaxKind.BooleanKeyword: - case SyntaxKind.SymbolKeyword: - case SyntaxKind.VoidKeyword: - case SyntaxKind.StringLiteral: - return writeTextOfNode(currentSourceFile, type); - case SyntaxKind.TypeReference: - return emitTypeReference(type); - case SyntaxKind.TypeQuery: - return emitTypeQuery(type); - case SyntaxKind.ArrayType: - return emitArrayType(type); - case SyntaxKind.TupleType: - return emitTupleType(type); - case SyntaxKind.UnionType: - return emitUnionType(type); - case SyntaxKind.ParenthesizedType: - return emitParenType(type); - case SyntaxKind.FunctionType: - case SyntaxKind.ConstructorType: - return emitSignatureDeclarationWithJsDocComments(type); - case SyntaxKind.TypeLiteral: - return emitTypeLiteral(type); - case SyntaxKind.Identifier: - return emitEntityName(type); - case SyntaxKind.QualifiedName: - return emitEntityName(type); - default: - Debug.fail("Unknown type annotation: " + type.kind); - } - - function emitEntityName(entityName: EntityName) { - let visibilityResult = resolver.isEntityNameVisible(entityName, - // Aliases can be written asynchronously so use correct enclosing declaration - entityName.parent.kind === SyntaxKind.ImportEqualsDeclaration ? entityName.parent : enclosingDeclaration); - - handleSymbolAccessibilityError(visibilityResult); - writeEntityName(entityName); - - function writeEntityName(entityName: EntityName) { - if (entityName.kind === SyntaxKind.Identifier) { - writeTextOfNode(currentSourceFile, entityName); - } - else { - let qualifiedName = entityName; - writeEntityName(qualifiedName.left); - write("."); - writeTextOfNode(currentSourceFile, qualifiedName.right); - } - } - } - - function emitTypeReference(type: TypeReferenceNode) { - emitEntityName(type.typeName); - if (type.typeArguments) { - write("<"); - emitCommaList(type.typeArguments, emitType); - write(">"); - } - } - - function emitTypeQuery(type: TypeQueryNode) { - write("typeof "); - emitEntityName(type.exprName); - } - - function emitArrayType(type: ArrayTypeNode) { - emitType(type.elementType); - write("[]"); - } - - function emitTupleType(type: TupleTypeNode) { - write("["); - emitCommaList(type.elementTypes, emitType); - write("]"); - } - - function emitUnionType(type: UnionTypeNode) { - emitSeparatedList(type.types, " | ", emitType); - } - - function emitParenType(type: ParenthesizedTypeNode) { - write("("); - emitType(type.type); - write(")"); - } - - function emitTypeLiteral(type: TypeLiteralNode) { - write("{"); - if (type.members.length) { - writeLine(); - increaseIndent(); - // write members - emitLines(type.members); - decreaseIndent(); - } - write("}"); - } - } - - function emitSourceFile(node: SourceFile) { - currentSourceFile = node; - enclosingDeclaration = node; - emitLines(node.statements); - } - - function emitExportAssignment(node: ExportAssignment) { - write(node.isExportEquals ? "export = " : "export default "); - writeTextOfNode(currentSourceFile, node.expression); - write(";"); - writeLine(); - } - - function emitModuleElementDeclarationFlags(node: Node) { - // If the node is parented in the current source file we need to emit export declare or just export - if (node.parent === currentSourceFile) { - // If the node is exported - if (node.flags & NodeFlags.Export) { - write("export "); - } - - if (node.kind !== SyntaxKind.InterfaceDeclaration) { - write("declare "); - } - } - } - - function emitClassMemberDeclarationFlags(node: Declaration) { - if (node.flags & NodeFlags.Private) { - write("private "); - } - else if (node.flags & NodeFlags.Protected) { - write("protected "); - } - - if (node.flags & NodeFlags.Static) { - write("static "); - } - } - - function emitImportEqualsDeclaration(node: ImportEqualsDeclaration) { - let nodeEmitInfo = { - declaration: node, - outputPos: writer.getTextPos(), - indent: writer.getIndent(), - hasWritten: resolver.isDeclarationVisible(node) - }; - aliasDeclarationEmitInfo.push(nodeEmitInfo); - if (nodeEmitInfo.hasWritten) { - writeImportEqualsDeclaration(node); - } - } - - function writeImportEqualsDeclaration(node: ImportEqualsDeclaration) { - // note usage of writer. methods instead of aliases created, just to make sure we are using - // correct writer especially to handle asynchronous alias writing - emitJsDocComments(node); - if (node.flags & NodeFlags.Export) { - write("export "); - } - write("import "); - writeTextOfNode(currentSourceFile, node.name); - write(" = "); - if (isInternalModuleImportEqualsDeclaration(node)) { - emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.moduleReference, getImportEntityNameVisibilityError); - write(";"); - } - else { - write("require("); - writeTextOfNode(currentSourceFile, getExternalModuleImportEqualsDeclarationExpression(node)); - write(");"); - } - writer.writeLine(); - - function getImportEntityNameVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - return { - diagnosticMessage: Diagnostics.Import_declaration_0_is_using_private_name_1, - errorNode: node, - typeName: node.name - }; - } - } - - function emitModuleDeclaration(node: ModuleDeclaration) { - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - write("module "); - writeTextOfNode(currentSourceFile, node.name); - while (node.body.kind !== SyntaxKind.ModuleBlock) { - node = node.body; - write("."); - writeTextOfNode(currentSourceFile, node.name); - } - let prevEnclosingDeclaration = enclosingDeclaration; - enclosingDeclaration = node; - write(" {"); - writeLine(); - increaseIndent(); - emitLines((node.body).statements); - decreaseIndent(); - write("}"); - writeLine(); - enclosingDeclaration = prevEnclosingDeclaration; - } - } - - function emitTypeAliasDeclaration(node: TypeAliasDeclaration) { - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - write("type "); - writeTextOfNode(currentSourceFile, node.name); - write(" = "); - emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.type, getTypeAliasDeclarationVisibilityError); - write(";"); - writeLine(); - } - function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - return { - diagnosticMessage: Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1, - errorNode: node.type, - typeName: node.name - }; - } - } - - function emitEnumDeclaration(node: EnumDeclaration) { - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - if (isConst(node)) { - write("const ") - } - write("enum "); - writeTextOfNode(currentSourceFile, node.name); - write(" {"); - writeLine(); - increaseIndent(); - emitLines(node.members); - decreaseIndent(); - write("}"); - writeLine(); - } - } - - function emitEnumMemberDeclaration(node: EnumMember) { - emitJsDocComments(node); - writeTextOfNode(currentSourceFile, node.name); - let enumMemberValue = resolver.getConstantValue(node); - if (enumMemberValue !== undefined) { - write(" = "); - write(enumMemberValue.toString()); - } - write(","); - writeLine(); - } - - function isPrivateMethodTypeParameter(node: TypeParameterDeclaration) { - return node.parent.kind === SyntaxKind.MethodDeclaration && (node.parent.flags & NodeFlags.Private); - } - - function emitTypeParameters(typeParameters: TypeParameterDeclaration[]) { - function emitTypeParameter(node: TypeParameterDeclaration) { - increaseIndent(); - emitJsDocComments(node); - decreaseIndent(); - writeTextOfNode(currentSourceFile, node.name); - // If there is constraint present and this is not a type parameter of the private method emit the constraint - if (node.constraint && !isPrivateMethodTypeParameter(node)) { - write(" extends "); - if (node.parent.kind === SyntaxKind.FunctionType || - node.parent.kind === SyntaxKind.ConstructorType || - (node.parent.parent && node.parent.parent.kind === SyntaxKind.TypeLiteral)) { - Debug.assert(node.parent.kind === SyntaxKind.MethodDeclaration || - node.parent.kind === SyntaxKind.MethodSignature || - node.parent.kind === SyntaxKind.FunctionType || - node.parent.kind === SyntaxKind.ConstructorType || - node.parent.kind === SyntaxKind.CallSignature || - node.parent.kind === SyntaxKind.ConstructSignature); - emitType(node.constraint); - } - else { - emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.constraint, getTypeParameterConstraintVisibilityError); - } - } - - function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - // Type parameter constraints are named by user so we should always be able to name it - let diagnosticMessage: DiagnosticMessage; - switch (node.parent.kind) { - case SyntaxKind.ClassDeclaration: - diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1; - break; - - case SyntaxKind.InterfaceDeclaration: - diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1; - break; - - case SyntaxKind.ConstructSignature: - diagnosticMessage = Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; - break; - - case SyntaxKind.CallSignature: - diagnosticMessage = Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; - break; - - case SyntaxKind.MethodDeclaration: - case SyntaxKind.MethodSignature: - if (node.parent.flags & NodeFlags.Static) { - diagnosticMessage = Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; - } - else if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) { - diagnosticMessage = Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; - } - else { - diagnosticMessage = Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; - } - break; - - case SyntaxKind.FunctionDeclaration: - diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1; - break; - - default: - Debug.fail("This is unknown parent for type parameter: " + node.parent.kind); - } - - return { - diagnosticMessage, - errorNode: node, - typeName: node.name - }; - } - } - - if (typeParameters) { - write("<"); - emitCommaList(typeParameters, emitTypeParameter); - write(">"); - } - } - - function emitHeritageClause(typeReferences: TypeReferenceNode[], isImplementsList: boolean) { - if (typeReferences) { - write(isImplementsList ? " implements " : " extends "); - emitCommaList(typeReferences, emitTypeOfTypeReference); - } - - function emitTypeOfTypeReference(node: TypeReferenceNode) { - emitTypeWithNewGetSymbolAccessibilityDiagnostic(node, getHeritageClauseVisibilityError); - - function getHeritageClauseVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - let diagnosticMessage: DiagnosticMessage; - // Heritage clause is written by user so it can always be named - if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) { - // Class or Interface implemented/extended is inaccessible - diagnosticMessage = isImplementsList ? - Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 : - Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1; - } - else { - // interface is inaccessible - diagnosticMessage = Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1; - } - - return { - diagnosticMessage, - errorNode: node, - typeName: (node.parent.parent).name - }; - } - } - } - - function emitClassDeclaration(node: ClassDeclaration) { - function emitParameterProperties(constructorDeclaration: ConstructorDeclaration) { - if (constructorDeclaration) { - forEach(constructorDeclaration.parameters, param => { - if (param.flags & NodeFlags.AccessibilityModifier) { - emitPropertyDeclaration(param); - } - }); - } - } - - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - write("class "); - writeTextOfNode(currentSourceFile, node.name); - let prevEnclosingDeclaration = enclosingDeclaration; - enclosingDeclaration = node; - emitTypeParameters(node.typeParameters); - let baseTypeNode = getClassBaseTypeNode(node); - if (baseTypeNode) { - emitHeritageClause([baseTypeNode], /*isImplementsList*/ false); - } - emitHeritageClause(getClassImplementedTypeNodes(node), /*isImplementsList*/ true); - write(" {"); - writeLine(); - increaseIndent(); - emitParameterProperties(getFirstConstructorWithBody(node)); - emitLines(node.members); - decreaseIndent(); - write("}"); - writeLine(); - enclosingDeclaration = prevEnclosingDeclaration; - } - } - - function emitInterfaceDeclaration(node: InterfaceDeclaration) { - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - write("interface "); - writeTextOfNode(currentSourceFile, node.name); - let prevEnclosingDeclaration = enclosingDeclaration; - enclosingDeclaration = node; - emitTypeParameters(node.typeParameters); - emitHeritageClause(getInterfaceBaseTypeNodes(node), /*isImplementsList*/ false); - write(" {"); - writeLine(); - increaseIndent(); - emitLines(node.members); - decreaseIndent(); - write("}"); - writeLine(); - enclosingDeclaration = prevEnclosingDeclaration; - } - } - - function emitPropertyDeclaration(node: Declaration) { - if (hasDynamicName(node)) { - return; - } - - emitJsDocComments(node); - emitClassMemberDeclarationFlags(node); - emitVariableDeclaration(node); - write(";"); - writeLine(); - } - - function emitVariableDeclaration(node: VariableDeclaration) { - // If we are emitting property it isn't moduleElement and hence we already know it needs to be emitted - // so there is no check needed to see if declaration is visible - if (node.kind !== SyntaxKind.VariableDeclaration || resolver.isDeclarationVisible(node)) { - // If this node is a computed name, it can only be a symbol, because we've already skipped - // it if it's not a well known symbol. In that case, the text of the name will be exactly - // what we want, namely the name expression enclosed in brackets. - writeTextOfNode(currentSourceFile, node.name); - // If optional property emit ? - if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && hasQuestionToken(node)) { - write("?"); - } - if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && node.parent.kind === SyntaxKind.TypeLiteral) { - emitTypeOfVariableDeclarationFromTypeLiteral(node); - } - else if (!(node.flags & NodeFlags.Private)) { - writeTypeOfDeclaration(node, node.type, getVariableDeclarationTypeVisibilityError); - } - } - - function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - let diagnosticMessage: DiagnosticMessage; - if (node.kind === SyntaxKind.VariableDeclaration) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Exported_variable_0_has_or_is_using_private_name_1; - } - // This check is to ensure we don't report error on constructor parameter property as that error would be reported during parameter emit - else if (node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) { - // TODO(jfreeman): Deal with computed properties in error reporting. - if (node.flags & NodeFlags.Static) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1; - } - else if (node.parent.kind === SyntaxKind.ClassDeclaration) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1; - } - else { - // Interfaces cannot have types that cannot be named - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1; - } - } - - return diagnosticMessage !== undefined ? { - diagnosticMessage, - errorNode: node, - typeName: node.name - } : undefined; - } - } - - function emitTypeOfVariableDeclarationFromTypeLiteral(node: VariableLikeDeclaration) { - // if this is property of type literal, - // or is parameter of method/call/construct/index signature of type literal - // emit only if type is specified - if (node.type) { - write(": "); - emitType(node.type); - } - } - - function emitVariableStatement(node: VariableStatement) { - let hasDeclarationWithEmit = forEach(node.declarationList.declarations, varDeclaration => resolver.isDeclarationVisible(varDeclaration)); - if (hasDeclarationWithEmit) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - if (isLet(node.declarationList)) { - write("let "); - } - else if (isConst(node.declarationList)) { - write("const "); - } - else { - write("var "); - } - emitCommaList(node.declarationList.declarations, emitVariableDeclaration); - write(";"); - writeLine(); - } - } - - function emitAccessorDeclaration(node: AccessorDeclaration) { - if (hasDynamicName(node)) { - return; - } - - let accessors = getAllAccessorDeclarations((node.parent).members, node); - let accessorWithTypeAnnotation: AccessorDeclaration; - - if (node === accessors.firstAccessor) { - emitJsDocComments(accessors.getAccessor); - emitJsDocComments(accessors.setAccessor); - emitClassMemberDeclarationFlags(node); - writeTextOfNode(currentSourceFile, node.name); - if (!(node.flags & NodeFlags.Private)) { - accessorWithTypeAnnotation = node; - let type = getTypeAnnotationFromAccessor(node); - if (!type) { - // couldn't get type for the first accessor, try the another one - let anotherAccessor = node.kind === SyntaxKind.GetAccessor ? accessors.setAccessor : accessors.getAccessor; - type = getTypeAnnotationFromAccessor(anotherAccessor); - if (type) { - accessorWithTypeAnnotation = anotherAccessor; - } - } - writeTypeOfDeclaration(node, type, getAccessorDeclarationTypeVisibilityError); - } - write(";"); - writeLine(); - } - - function getTypeAnnotationFromAccessor(accessor: AccessorDeclaration): TypeNode | StringLiteralExpression { - if (accessor) { - return accessor.kind === SyntaxKind.GetAccessor - ? accessor.type // Getter - return type - : accessor.parameters.length > 0 - ? accessor.parameters[0].type // Setter parameter type - : undefined; - } - } - - function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - let diagnosticMessage: DiagnosticMessage; - if (accessorWithTypeAnnotation.kind === SyntaxKind.SetAccessor) { - // Setters have to have type named and cannot infer it so, the type should always be named - if (accessorWithTypeAnnotation.parent.flags & NodeFlags.Static) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1; - } - else { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1; - } - return { - diagnosticMessage, - errorNode: accessorWithTypeAnnotation.parameters[0], - // TODO(jfreeman): Investigate why we are passing node.name instead of node.parameters[0].name - typeName: accessorWithTypeAnnotation.name - }; - } - else { - if (accessorWithTypeAnnotation.flags & NodeFlags.Static) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : - Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0; - } - else { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : - Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0; - } - return { - diagnosticMessage, - errorNode: accessorWithTypeAnnotation.name, - typeName: undefined - }; - } - } - } - - function emitFunctionDeclaration(node: FunctionLikeDeclaration) { - if (hasDynamicName(node)) { - return; - } - - // If we are emitting Method/Constructor it isn't moduleElement and hence already determined to be emitting - // so no need to verify if the declaration is visible - if ((node.kind !== SyntaxKind.FunctionDeclaration || resolver.isDeclarationVisible(node)) && - !resolver.isImplementationOfOverload(node)) { - emitJsDocComments(node); - if (node.kind === SyntaxKind.FunctionDeclaration) { - emitModuleElementDeclarationFlags(node); - } - else if (node.kind === SyntaxKind.MethodDeclaration) { - emitClassMemberDeclarationFlags(node); - } - if (node.kind === SyntaxKind.FunctionDeclaration) { - write("function "); - writeTextOfNode(currentSourceFile, node.name); - } - else if (node.kind === SyntaxKind.Constructor) { - write("constructor"); - } - else { - writeTextOfNode(currentSourceFile, node.name); - if (hasQuestionToken(node)) { - write("?"); - } - } - emitSignatureDeclaration(node); - } - } - - function emitSignatureDeclarationWithJsDocComments(node: SignatureDeclaration) { - emitJsDocComments(node); - emitSignatureDeclaration(node); - } - - function emitSignatureDeclaration(node: SignatureDeclaration) { - // Construct signature or constructor type write new Signature - if (node.kind === SyntaxKind.ConstructSignature || node.kind === SyntaxKind.ConstructorType) { - write("new "); - } - emitTypeParameters(node.typeParameters); - if (node.kind === SyntaxKind.IndexSignature) { - write("["); - } - else { - write("("); - } - - let prevEnclosingDeclaration = enclosingDeclaration; - enclosingDeclaration = node; - - // Parameters - emitCommaList(node.parameters, emitParameterDeclaration); - - if (node.kind === SyntaxKind.IndexSignature) { - write("]"); - } - else { - write(")"); - } - - // If this is not a constructor and is not private, emit the return type - let isFunctionTypeOrConstructorType = node.kind === SyntaxKind.FunctionType || node.kind === SyntaxKind.ConstructorType; - if (isFunctionTypeOrConstructorType || node.parent.kind === SyntaxKind.TypeLiteral) { - // Emit type literal signature return type only if specified - if (node.type) { - write(isFunctionTypeOrConstructorType ? " => " : ": "); - emitType(node.type); - } - } - else if (node.kind !== SyntaxKind.Constructor && !(node.flags & NodeFlags.Private)) { - writeReturnTypeAtSignature(node, getReturnTypeVisibilityError); - } - - enclosingDeclaration = prevEnclosingDeclaration; - - if (!isFunctionTypeOrConstructorType) { - write(";"); - writeLine(); - } - - function getReturnTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - let diagnosticMessage: DiagnosticMessage; - switch (node.kind) { - case SyntaxKind.ConstructSignature: - // Interfaces cannot have return types that cannot be named - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0; - break; - - case SyntaxKind.CallSignature: - // Interfaces cannot have return types that cannot be named - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0; - break; - - case SyntaxKind.IndexSignature: - // Interfaces cannot have return types that cannot be named - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0; - break; - - case SyntaxKind.MethodDeclaration: - case SyntaxKind.MethodSignature: - if (node.flags & NodeFlags.Static) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : - Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0; - } - else if (node.parent.kind === SyntaxKind.ClassDeclaration) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : - Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0; - } - else { - // Interfaces cannot have return types that cannot be named - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0; - } - break; - - case SyntaxKind.FunctionDeclaration: - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : - Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_exported_function_has_or_is_using_private_name_0; - break; - - default: - Debug.fail("This is unknown kind for signature: " + node.kind); - } - - return { - diagnosticMessage, - errorNode: node.name || node, - }; - } - } - - function emitParameterDeclaration(node: ParameterDeclaration) { - increaseIndent(); - emitJsDocComments(node); - if (node.dotDotDotToken) { - write("..."); - } - if (isBindingPattern(node.name)) { - write("_" + indexOf((node.parent).parameters, node)); - } - else { - writeTextOfNode(currentSourceFile, node.name); - } - if (node.initializer || hasQuestionToken(node)) { - write("?"); - } - decreaseIndent(); - - if (node.parent.kind === SyntaxKind.FunctionType || - node.parent.kind === SyntaxKind.ConstructorType || - node.parent.parent.kind === SyntaxKind.TypeLiteral) { - emitTypeOfVariableDeclarationFromTypeLiteral(node); - } - else if (!(node.parent.flags & NodeFlags.Private)) { - writeTypeOfDeclaration(node, node.type, getParameterDeclarationTypeVisibilityError); - } - - function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - let diagnosticMessage: DiagnosticMessage; - switch (node.parent.kind) { - case SyntaxKind.Constructor: - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1; - break; - - case SyntaxKind.ConstructSignature: - // Interfaces cannot have parameter types that cannot be named - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; - break; - - case SyntaxKind.CallSignature: - // Interfaces cannot have parameter types that cannot be named - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; - break; - - case SyntaxKind.MethodDeclaration: - case SyntaxKind.MethodSignature: - if (node.parent.flags & NodeFlags.Static) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; - } - else if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; - } - else { - // Interfaces cannot have parameter types that cannot be named - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; - } - break; - - case SyntaxKind.FunctionDeclaration: - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1; - break; - - default: - Debug.fail("This is unknown parent for parameter: " + node.parent.kind); - } - - return { - diagnosticMessage, - errorNode: node, - typeName: node.name - }; - } - } - - function emitNode(node: Node) { - switch (node.kind) { - case SyntaxKind.Constructor: - case SyntaxKind.FunctionDeclaration: - case SyntaxKind.MethodDeclaration: - case SyntaxKind.MethodSignature: - return emitFunctionDeclaration(node); - case SyntaxKind.ConstructSignature: - case SyntaxKind.CallSignature: - case SyntaxKind.IndexSignature: - return emitSignatureDeclarationWithJsDocComments(node); - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - return emitAccessorDeclaration(node); - case SyntaxKind.VariableStatement: - return emitVariableStatement(node); - case SyntaxKind.PropertyDeclaration: - case SyntaxKind.PropertySignature: - return emitPropertyDeclaration(node); - case SyntaxKind.InterfaceDeclaration: - return emitInterfaceDeclaration(node); - case SyntaxKind.ClassDeclaration: - return emitClassDeclaration(node); - case SyntaxKind.TypeAliasDeclaration: - return emitTypeAliasDeclaration(node); - case SyntaxKind.EnumMember: - return emitEnumMemberDeclaration(node); - case SyntaxKind.EnumDeclaration: - return emitEnumDeclaration(node); - case SyntaxKind.ModuleDeclaration: - return emitModuleDeclaration(node); - case SyntaxKind.ImportEqualsDeclaration: - return emitImportEqualsDeclaration(node); - case SyntaxKind.ExportAssignment: - return emitExportAssignment(node); - case SyntaxKind.SourceFile: - return emitSourceFile(node); - } - } + // represents one LexicalEnvironment frame to store unique generated names + interface ScopeFrame { + names: Map; + previous: ScopeFrame; + } - function writeReferencePath(referencedFile: SourceFile) { - let declFileName = referencedFile.flags & NodeFlags.DeclarationFile - ? referencedFile.fileName // Declaration file, use declaration file name - : shouldEmitToOwnFile(referencedFile, compilerOptions) - ? getOwnEmitOutputFilePath(referencedFile, host, ".d.ts") // Own output file so get the .d.ts file - : removeFileExtension(compilerOptions.out) + ".d.ts";// Global out file - - declFileName = getRelativePathToDirectoryOrUrl( - getDirectoryPath(normalizeSlashes(jsFilePath)), - declFileName, - host.getCurrentDirectory(), - host.getCanonicalFileName, - /*isAbsolutePathAnUrl*/ false); - - referencePathsOutput += "/// " + newLine; - } + export function isExternalModuleOrDeclarationFile(sourceFile: SourceFile) { + return isExternalModule(sourceFile) || isDeclarationFile(sourceFile); } - export function getDeclarationDiagnostics(host: EmitHost, resolver: EmitResolver, targetSourceFile: SourceFile): Diagnostic[] { - let diagnostics: Diagnostic[] = []; - let jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, ".js"); - emitDeclarations(host, resolver, diagnostics, jsFilePath, targetSourceFile); - return diagnostics; + // flag enum used to request and track usages of few dedicated temp variables + // enum values are used to set/check bit values and thus should not have bit collisions. + const enum TempVariableKind { + auto = 0, + _i = 1, + _n = 2, } // @internal @@ -1561,6 +61,26 @@ module ts { sourceMaps: sourceMapDataList }; + function isNodeDescendentOf(node: Node, ancestor: Node): boolean { + while (node) { + if (node === ancestor) return true; + node = node.parent; + } + return false; + } + + function isUniqueLocalName(name: string, container: Node): boolean { + for (let node = container; isNodeDescendentOf(node, container); node = node.nextContainer) { + if (node.locals && hasProperty(node.locals, name)) { + // We conservatively include alias symbols to cover cases where they're emitted as locals + if (node.locals[name].flags & (SymbolFlags.Value | SymbolFlags.ExportValue | SymbolFlags.Alias)) { + return false; + } + } + } + return true; + } + function emitJavaScript(jsFilePath: string, root?: SourceFile) { let writer = createTextWriter(newLine); let write = writer.write; @@ -1572,16 +92,18 @@ module ts { let currentSourceFile: SourceFile; - let lastFrame: ScopeFrame; - let currentScopeNames: Map; - - let generatedBlockScopeNames: string[]; + let generatedNameSet: Map; + let nodeToGeneratedName: string[]; + let blockScopedVariableToGeneratedName: string[]; + let computedPropertyNamesToGeneratedNames: string[]; let extendsEmitted = false; + let decorateEmitted = false; let tempCount = 0; let tempVariables: Identifier[]; let tempParameters: Identifier[]; let externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[]; + let predefinedTempsInUse = TempVariableKind.auto; let exportSpecifiers: Map; let exportEquals: ExportAssignment; let hasExportStars: boolean; @@ -1589,25 +111,12 @@ module ts { /** write emitted output to disk*/ let writeEmittedFiles = writeJavaScriptFile; - /** Emit leading comments of the node */ - let emitLeadingComments = compilerOptions.removeComments ? (node: Node) => { } : emitLeadingDeclarationComments; - - /** Emit Trailing comments of the node */ - let emitTrailingComments = compilerOptions.removeComments ? (node: Node) => { } : emitTrailingDeclarationComments; - - let emitLeadingCommentsOfPosition = compilerOptions.removeComments ? (pos: number) => { } : emitLeadingCommentsOfLocalPosition; - let detachedCommentsInfo: { nodePos: number; detachedCommentEndPos: number }[]; - /** Emit detached comments of the node */ - let emitDetachedComments = compilerOptions.removeComments ? (node: TextRange) => { } : emitDetachedCommentsAtPosition; - let writeComment = writeCommentRange; /** Emit a node */ - let emitNodeWithoutSourceMap = compilerOptions.removeComments ? emitNodeWithoutSourceMapWithoutComments : emitNodeWithoutSourceMapWithComments; let emit = emitNodeWithoutSourceMap; - let emitWithoutComments = emitNodeWithoutSourceMapWithoutComments; /** Called just before starting emit of a node */ let emitStart = function (node: Node) { }; @@ -1659,81 +168,197 @@ module ts { emit(sourceFile); } - // enters the new lexical environment - // return value should be passed to matching call to exitNameScope. - function enterNameScope(): boolean { - let names = currentScopeNames; - currentScopeNames = undefined; - if (names) { - lastFrame = { names, previous: lastFrame }; - return true; + function generateNameForNode(node: Node) { + switch (node.kind) { + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.ClassDeclaration: + generateNameForFunctionOrClassDeclaration(node); + break; + case SyntaxKind.ModuleDeclaration: + generateNameForModuleOrEnum(node); + generateNameForNode((node).body); + break; + case SyntaxKind.EnumDeclaration: + generateNameForModuleOrEnum(node); + break; + case SyntaxKind.ImportDeclaration: + generateNameForImportDeclaration(node); + break; + case SyntaxKind.ExportDeclaration: + generateNameForExportDeclaration(node); + break; + case SyntaxKind.ExportAssignment: + generateNameForExportAssignment(node); + break; + case SyntaxKind.SourceFile: + case SyntaxKind.ModuleBlock: + forEach((node).statements, generateNameForNode); + break; } - return false; } - function exitNameScope(popFrame: boolean): void { - if (popFrame) { - currentScopeNames = lastFrame.names; - lastFrame = lastFrame.previous; + function isUniqueName(name: string): boolean { + return !resolver.hasGlobalName(name) && + !hasProperty(currentSourceFile.identifiers, name) && + (!generatedNameSet || !hasProperty(generatedNameSet, name)) + } + + // in cases like + // for (var x of []) { + // _i; + // } + // we should be able to detect if let _i was shadowed by some temp variable that was allocated in scope + function nameConflictsWithSomeTempVariable(name: string): boolean { + // temp variable names always start with '_' + if (name.length < 2 || name.charCodeAt(0) !== CharacterCodes._) { + return false; + } + + if (name === "_i") { + return !!(predefinedTempsInUse & TempVariableKind._i); + } + + if (name === "_n") { + return !!(predefinedTempsInUse & TempVariableKind._n); + } + + if (name.length === 2 && name.charCodeAt(1) >= CharacterCodes.a && name.charCodeAt(1) <= CharacterCodes.z) { + // handles _a .. _z + let n = name.charCodeAt(1) - CharacterCodes.a; + return n < tempCount; } else { - currentScopeNames = undefined; + // handles _1, _2... + let n = +name.substring(1); + return !isNaN(n) && n >= 0 && n < (tempCount - 26); } } - function generateUniqueNameForLocation(location: Node, baseName: string): string { - let name: string - // first try to check if base name can be used as is - if (!isExistingName(location, baseName)) { - name = baseName; + // This function generates a name using the following pattern: + // _a .. _h, _j ... _z, _0, _1, ... + // It is guaranteed that generated name will not shadow any existing user-defined names, + // however it can hide another name generated by this function higher in the scope. + // NOTE: names generated by 'makeTempVariableName' and 'makeUniqueName' will never conflict. + // see comment for 'makeTempVariableName' for more information. + function makeTempVariableName(location: Node, tempVariableKind: TempVariableKind): string { + let tempName: string; + if (tempVariableKind !== TempVariableKind.auto && !(predefinedTempsInUse & tempVariableKind)) { + tempName = tempVariableKind === TempVariableKind._i ? "_i" : "_n"; + if (!resolver.resolvesToSomeValue(location, tempName)) { + predefinedTempsInUse |= tempVariableKind; + return tempName; + } } - else { - name = generateUniqueName(baseName, n => isExistingName(location, n)); + + do { + // Note: we avoid generating _i and _n as those are common names we want in other places. + var char = CharacterCodes.a + tempCount; + if (char !== CharacterCodes.i && char !== CharacterCodes.n) { + if (tempCount < 26) { + tempName = "_" + String.fromCharCode(char); + } + else { + tempName = "_" + (tempCount - 26); + } + } + + tempCount++; } - - return recordNameInCurrentScope(name); + while (resolver.resolvesToSomeValue(location, tempName)); + + return tempName; } - - function recordNameInCurrentScope(name: string): string { - if (!currentScopeNames) { - currentScopeNames = {}; + + // Generates a name that is unique within current file and does not collide with + // any names in global scope. + // NOTE: names generated by 'makeTempVariableName' and 'makeUniqueName' will never conflict + // because of the way how these names are generated + // - makeUniqueName builds a name by picking a base name (which should not be empty string) + // and appending suffix '_' + // - makeTempVariableName creates a name using the following pattern: + // _a .. _h, _j ... _z, _0, _1, ... + // This means that names from 'makeTempVariableName' will have only one underscore at the beginning + // and names from 'makeUniqieName' will have at least one underscore in the middle + // so they will never collide. + function makeUniqueName(baseName: string): string { + Debug.assert(!!baseName); + + // Find the first unique 'name_n', where n is a positive number + if (baseName.charCodeAt(baseName.length - 1) !== CharacterCodes._) { + baseName += "_"; + } + + let i = 1; + let generatedName: string; + while (true) { + generatedName = baseName + i; + if (isUniqueName(generatedName)) { + break; + } + i++; } - return currentScopeNames[name] = name; + if (!generatedNameSet) { + generatedNameSet = {}; + } + return generatedNameSet[generatedName] = generatedName; } - function isExistingName(location: Node, name: string) { - // check if resolver is aware of this name (if name was seen during the typecheck) - if (!resolver.isUnknownIdentifier(location, name)) { - return true; + function renameNode(node: Node, name: string): string { + var nodeId = getNodeId(node); + + if (!nodeToGeneratedName) { + nodeToGeneratedName = []; } - // check if name is present in generated names that were introduced by the emitter - if (currentScopeNames && hasProperty(currentScopeNames, name)) { - return true; + return nodeToGeneratedName[nodeId] = unescapeIdentifier(name); + } + + function generateNameForFunctionOrClassDeclaration(node: Declaration) { + if (!node.name) { + renameNode(node, makeUniqueName("default")); } + } - // check generated names in outer scopes - // let x; - // function foo() { - // let x; // 1 - // function bar() { - // { - // let x; // 2 - // } - // console.log(x); // 3 - // } - //} - // here both x(1) and x(2) should be renamed and their names should be different - // so x in (3) will refer to x(1) - let frame = lastFrame; - while (frame) { - if (hasProperty(frame.names, name)) { - return true; - } - frame = frame.previous; + function generateNameForModuleOrEnum(node: ModuleDeclaration | EnumDeclaration) { + if (node.name.kind === SyntaxKind.Identifier) { + let name = node.name.text; + // Use module/enum name itself if it is unique, otherwise make a unique variation + renameNode(node, isUniqueLocalName(name, node) ? name : makeUniqueName(name)); } - return false; + } + + function generateNameForImportOrExportDeclaration(node: ImportDeclaration | ExportDeclaration) { + let expr = getExternalModuleName(node); + let baseName = expr.kind === SyntaxKind.StringLiteral ? + escapeIdentifier(makeIdentifierFromModuleName((expr).text)) : "module"; + renameNode(node, makeUniqueName(baseName)); + } + + function generateNameForImportDeclaration(node: ImportDeclaration) { + if (node.importClause) { + generateNameForImportOrExportDeclaration(node); + } + } + + function generateNameForExportDeclaration(node: ExportDeclaration) { + if (node.moduleSpecifier) { + generateNameForImportOrExportDeclaration(node); + } + } + + function generateNameForExportAssignment(node: ExportAssignment) { + if (node.expression && node.expression.kind !== SyntaxKind.Identifier) { + renameNode(node, makeUniqueName("default")); + } + } + + function getGeneratedNameForNode(node: Node) { + let nodeId = getNodeId(node); + if (!nodeToGeneratedName || !nodeToGeneratedName[nodeId]) { + generateNameForNode(node); + } + return nodeToGeneratedName ? nodeToGeneratedName[nodeId] : undefined; } function initializeEmitterWithSourceMaps() { @@ -2069,34 +694,25 @@ module ts { sourceMapDir = getDirectoryPath(normalizePath(jsFilePath)); } - function emitNodeWithSourceMap(node: Node) { + function emitNodeWithSourceMap(node: Node, allowGeneratedIdentifiers?: boolean) { if (node) { if (nodeIsSynthesized(node)) { - return emitNodeWithoutSourceMap(node); + return emitNodeWithoutSourceMap(node, /*allowGeneratedIdentifiers*/ false); } if (node.kind != SyntaxKind.SourceFile) { recordEmitNodeStartSpan(node); - emitNodeWithoutSourceMap(node); + emitNodeWithoutSourceMap(node, allowGeneratedIdentifiers); recordEmitNodeEndSpan(node); } else { recordNewSourceFileStart(node); - emitNodeWithoutSourceMap(node); + emitNodeWithoutSourceMap(node, /*allowGeneratedIdentifiers*/ false); } } } - function emitNodeWithSourceMapWithoutComments(node: Node) { - if (node) { - recordEmitNodeStartSpan(node); - emitNodeWithoutSourceMapWithoutComments(node); - recordEmitNodeEndSpan(node); - } - } - writeEmittedFiles = writeJavaScriptAndSourceMapFile; emit = emitNodeWithSourceMap; - emitWithoutComments = emitNodeWithSourceMapWithoutComments; emitStart = recordEmitNodeStartSpan; emitEnd = recordEmitNodeEndSpan; emitToken = writeTextWithSpanRecord; @@ -2109,32 +725,10 @@ module ts { writeFile(host, diagnostics, jsFilePath, emitOutput, writeByteOrderMark); } - // Create a temporary variable with a unique unused name. The forLoopVariable parameter signals that the - // name should be one that is appropriate for a for loop variable. - function createTempVariable(location: Node, preferredName?: string): Identifier { - for (var name = preferredName; !name || isExistingName(location, name); tempCount++) { - // _a .. _h, _j ... _z, _0, _1, ... - - // Note: we avoid generating _i and _n as those are common names we want in other places. - var char = CharacterCodes.a + tempCount; - if (char === CharacterCodes.i || char === CharacterCodes.n) { - continue; - } - - if (tempCount < 26) { - name = "_" + String.fromCharCode(char); - } - else { - name = "_" + (tempCount - 26); - } - } - - // This is necessary so that a name generated via renameNonTopLevelLetAndConst will see the name - // we just generated. - recordNameInCurrentScope(name); - + // Create a temporary variable with a unique unused name. + function createTempVariable(location: Node, tempVariableKind = TempVariableKind.auto): Identifier { let result = createSynthesizedNode(SyntaxKind.Identifier); - result.text = name; + result.text = makeTempVariableName(location, tempVariableKind); return result; } @@ -2145,8 +739,8 @@ module ts { tempVariables.push(name); } - function createAndRecordTempVariable(location: Node, preferredName?: string): Identifier { - let temp = createTempVariable(location, preferredName); + function createAndRecordTempVariable(location: Node, tempVariableKind?: TempVariableKind): Identifier { + let temp = createTempVariable(location, tempVariableKind); recordTempDeclaration(temp); return temp; @@ -2294,13 +888,13 @@ module ts { return true; } } - + return false; } function emitLiteral(node: LiteralExpression) { let text = getLiteralText(node); - + if (compilerOptions.sourceMap && (node.kind === SyntaxKind.StringLiteral || isTemplateLiteralKind(node.kind))) { writer.writeLiteral(text); } @@ -2312,7 +906,7 @@ module ts { write(text); } } - + function getLiteralText(node: LiteralExpression) { // Any template literal or string literal with an extended escape // (e.g. "\u{0067}") will need to be downleveled as a escaped string literal. @@ -2342,14 +936,14 @@ module ts { case SyntaxKind.NumericLiteral: return node.text; } - + Debug.fail(`Literal kind '${node.kind}' not accounted for.`); } - + function getQuotedEscapedLiteralText(leftQuote: string, text: string, rightQuote: string) { return leftQuote + escapeNonAsciiCharacters(escapeString(text)) + rightQuote; } - + function emitDownlevelRawTemplateLiteral(node: LiteralExpression) { // Find original source text, since we need to emit the raw strings of the tagged template. // The raw strings contain the (escaped) strings of what the user wrote. @@ -2368,10 +962,10 @@ module ts { // and LineTerminatorSequences are normalized to for both TV and TRV. text = text.replace(/\r\n?/g, "\n"); text = escapeString(text); - + write('"' + text + '"'); } - + function emitDownlevelTaggedTemplateArray(node: TaggedTemplateExpression, literalEmitter: (literal: LiteralExpression) => void) { write("["); if (node.template.kind === SyntaxKind.NoSubstitutionTemplateLiteral) { @@ -2386,7 +980,7 @@ module ts { } write("]"); } - + function emitDownlevelTaggedTemplate(node: TaggedTemplateExpression) { let tempVariable = createAndRecordTempVariable(node); write("("); @@ -2394,12 +988,12 @@ module ts { write(" = "); emitDownlevelTaggedTemplateArray(node, emit); write(", "); - + emit(tempVariable); write(".raw = "); emitDownlevelTaggedTemplateArray(node, emitDownlevelRawTemplateLiteral); write(", "); - + emitParenthesizedIf(node.tag, needsParenthesisForPropertyAccessOrInvocation(node.tag)); write("("); emit(tempVariable); @@ -2560,6 +1154,38 @@ module ts { emitLiteral(node); } else if (node.kind === SyntaxKind.ComputedPropertyName) { + // if this is a decorated computed property, we will need to capture the result + // of the property expression so that we can apply decorators later. This is to ensure + // we don't introduce unintended side effects: + // + // class C { + // [_a = x]() { } + // } + // + // The emit for the decorated computed property decorator is: + // + // Object.defineProperty(C.prototype, _a, __decorate([dec], C.prototype, _a, Object.getOwnPropertyDescriptor(C.prototype, _a))); + // + if (nodeIsDecorated(node.parent)) { + if (!computedPropertyNamesToGeneratedNames) { + computedPropertyNamesToGeneratedNames = []; + } + + let generatedName = computedPropertyNamesToGeneratedNames[node.id]; + if (generatedName) { + // we have already generated a variable for this node, write that value instead. + write(generatedName); + return; + } + + let generatedVariable = createTempVariable(node); + generatedName = generatedVariable.text; + recordTempDeclaration(generatedVariable); + computedPropertyNamesToGeneratedNames[node.id] = generatedName; + write(generatedName); + write(" = "); + } + emit((node).expression); } else { @@ -2614,7 +1240,7 @@ module ts { } function emitExpressionIdentifier(node: Identifier) { - let substitution = resolver.getExpressionNameSubstitution(node); + let substitution = resolver.getExpressionNameSubstitution(node, getGeneratedNameForNode); if (substitution) { write(substitution); } @@ -2623,17 +1249,24 @@ module ts { } } - function getBlockScopedVariableId(node: Identifier): number { - // return undefined for synthesized nodes - return !nodeIsSynthesized(node) && resolver.getBlockScopedVariableId(node); + function getGeneratedNameForIdentifier(node: Identifier): string { + if (nodeIsSynthesized(node) || !blockScopedVariableToGeneratedName) { + return undefined; + } + + var variableId = resolver.getBlockScopedVariableId(node) + if (variableId === undefined) { + return undefined; + } + + return blockScopedVariableToGeneratedName[variableId]; } - function emitIdentifier(node: Identifier) { - let variableId = getBlockScopedVariableId(node); - if (variableId !== undefined && generatedBlockScopeNames) { - let text = generatedBlockScopeNames[variableId]; - if (text) { - write(text); + function emitIdentifier(node: Identifier, allowGeneratedIdentifiers: boolean) { + if (allowGeneratedIdentifiers) { + let generatedName = getGeneratedNameForIdentifier(node); + if (generatedName) { + write(generatedName); return; } } @@ -2658,15 +1291,17 @@ module ts { } function emitSuper(node: Node) { - let flags = resolver.getNodeCheckFlags(node); - if (flags & NodeCheckFlags.SuperInstance) { - write("_super.prototype"); - } - else if (flags & NodeCheckFlags.SuperStatic) { - write("_super"); + if (languageVersion >= ScriptTarget.ES6) { + write("super"); } else { - write("super"); + var flags = resolver.getNodeCheckFlags(node); + if (flags & NodeCheckFlags.SuperInstance) { + write("_super.prototype"); + } + else { + write("_super"); + } } } @@ -2686,7 +1321,7 @@ module ts { function emitBindingElement(node: BindingElement) { if (node.propertyName) { - emit(node.propertyName); + emit(node.propertyName, /*allowGeneratedIdentifiers*/ false); write(": "); } if (node.dotDotDotToken) { @@ -2777,7 +1412,7 @@ module ts { write("]"); } else { - emitListWithSpread(elements, /*multiLine*/ (node.flags & NodeFlags.MultiLine) !== 0, + emitListWithSpread(elements, /*multiLine*/(node.flags & NodeFlags.MultiLine) !== 0, /*trailingComma*/ elements.hasTrailingComma); } } @@ -2852,7 +1487,7 @@ module ts { // manage by just emitting strings (which is a lot more performant). //let prefix = createIdentifier(resolver.getExpressionNamePrefix((property).name)); //return createPropertyAccessExpression(prefix, (property).name); - return createIdentifier(resolver.getExpressionNameSubstitution((property).name)); + return createIdentifier(resolver.getExpressionNameSubstitution((property).name, getGeneratedNameForNode)); case SyntaxKind.MethodDeclaration: return createFunctionExpression((property).parameters, (property).body); @@ -2919,7 +1554,7 @@ module ts { return result; } - + function createExpressionStatement(expression: Expression): ExpressionStatement { let result = createSynthesizedNode(SyntaxKind.ExpressionStatement); result.expression = expression; @@ -2973,7 +1608,7 @@ module ts { return result; } - + function createIdentifier(name: string, startsOnNewLine?: boolean) { let result = createSynthesizedNode(SyntaxKind.Identifier, startsOnNewLine); result.text = name; @@ -3004,7 +1639,7 @@ module ts { break; } } - + let hasComputedProperty = numInitialNonComputedProperties !== properties.length; if (hasComputedProperty) { emitDownlevelObjectLiteralWithComputedProperties(node, numInitialNonComputedProperties); @@ -3025,12 +1660,12 @@ module ts { function emitComputedPropertyName(node: ComputedPropertyName) { write("["); - emit(node.expression); + emitExpressionForPropertyName(node); write("]"); } function emitMethod(node: MethodDeclaration) { - emit(node.name); + emit(node.name, /*allowGeneratedIdentifiers*/ false); if (languageVersion < ScriptTarget.ES6) { write(": function "); } @@ -3038,13 +1673,13 @@ module ts { } function emitPropertyAssignment(node: PropertyDeclaration) { - emit(node.name); + emit(node.name, /*allowGeneratedIdentifiers*/ false); write(": "); emit(node.initializer); } function emitShorthandPropertyAssignment(node: ShorthandPropertyAssignment) { - emit(node.name); + emit(node.name, /*allowGeneratedIdentifiers*/ false); // If short-hand property has a prefix, then regardless of the target version, we will emit it as normal property assignment. For example: // module m { // export let y; @@ -3053,7 +1688,20 @@ module ts { // export let obj = { y }; // } // The short-hand property in obj need to emit as such ... = { y : m.y } regardless of the TargetScript version - if (languageVersion < ScriptTarget.ES6 || resolver.getExpressionNameSubstitution(node.name)) { + if (languageVersion < ScriptTarget.ES6) { + // Emit identifier as an identifier + write(": "); + var generatedName = getGeneratedNameForIdentifier(node.name); + if (generatedName) { + write(generatedName); + } + else { + // Even though this is stored as identifier treat it as an expression + // Short-hand, { x }, is equivalent of normal form { x: x } + emitExpressionIdentifier(node.name); + } + } + else if (resolver.getExpressionNameSubstitution(node.name, getGeneratedNameForNode)) { // Emit identifier as an identifier write(": "); // Even though this is stored as identifier treat it as an expression @@ -3106,7 +1754,7 @@ module ts { let indentedBeforeDot = indentIfOnDifferentLines(node, node.expression, node.dotToken); write("."); let indentedAfterDot = indentIfOnDifferentLines(node, node.dotToken, node.name); - emit(node.name); + emit(node.name, /*allowGeneratedIdentifiers*/ false); decreaseIndentIf(indentedBeforeDot, indentedAfterDot); } @@ -3202,14 +1850,14 @@ module ts { } let superCall = false; if (node.expression.kind === SyntaxKind.SuperKeyword) { - write("_super"); + emitSuper(node.expression); superCall = true; } else { emit(node.expression); superCall = node.expression.kind === SyntaxKind.PropertyAccessExpression && (node.expression).expression.kind === SyntaxKind.SuperKeyword; } - if (superCall) { + if (superCall && languageVersion < ScriptTarget.ES6) { write(".call("); emitThis(node.expression); if (node.arguments.length) { @@ -3236,7 +1884,7 @@ module ts { } function emitTaggedTemplateExpression(node: TaggedTemplateExpression): void { - if (compilerOptions.target >= ScriptTarget.ES6) { + if (languageVersion >= ScriptTarget.ES6) { emit(node.tag); write(" "); emit(node.template); @@ -3522,7 +2170,7 @@ module ts { if (languageVersion < ScriptTarget.ES6 && node.kind === SyntaxKind.ForOfStatement) { return emitDownLevelForOfStatement(node); } - + let endPos = emitToken(SyntaxKind.ForKeyword, node.pos); write(" "); endPos = emitToken(SyntaxKind.OpenParenToken, endPos); @@ -3549,7 +2197,7 @@ module ts { emitToken(SyntaxKind.CloseParenToken, node.expression.end); emitEmbeddedStatement(node.statement); } - + function emitDownLevelForOfStatement(node: ForOfStatement) { // The following ES6 code: // @@ -3586,10 +2234,10 @@ module ts { // // we don't want to emit a temporary variable for the RHS, just use it directly. let rhsIsIdentifier = node.expression.kind === SyntaxKind.Identifier; - let counter = createTempVariable(node, /*preferredName*/ "_i"); + let counter = createTempVariable(node, TempVariableKind._i); let rhsReference = rhsIsIdentifier ? node.expression : createTempVariable(node); - var cachedLength = compilerOptions.cacheDownlevelForOfLength ? createTempVariable(node, /*preferredName:*/ "_n") : undefined; + var cachedLength = compilerOptions.cacheDownlevelForOfLength ? createTempVariable(node, TempVariableKind._n) : undefined; // This is the let keyword for the counter and rhsReference. The let keyword for // the LHS will be emitted inside the body. @@ -3600,7 +2248,7 @@ module ts { emitNodeWithoutSourceMap(counter); write(" = 0"); emitEnd(node.expression); - + if (!rhsIsIdentifier) { // , _a = expr write(", "); @@ -3694,7 +2342,7 @@ module ts { } emitEnd(node.initializer); write(";"); - + if (node.statement.kind === SyntaxKind.Block) { emitLines((node.statement).statements); } @@ -3702,7 +2350,7 @@ module ts { writeLine(); emit(node.statement); } - + writeLine(); decreaseIndent(); write("}"); @@ -3830,19 +2478,25 @@ module ts { function emitContainingModuleName(node: Node) { let container = getContainingModule(node); - write(container ? resolver.getGeneratedNameForNode(container) : "exports"); + write(container ? getGeneratedNameForNode(container) : "exports"); } function emitModuleMemberName(node: Declaration) { emitStart(node.name); if (getCombinedNodeFlags(node) & NodeFlags.Export) { - emitContainingModuleName(node); - write("."); + var container = getContainingModule(node); + if (container) { + write(getGeneratedNameForNode(container)); + write("."); + } + else if (languageVersion < ScriptTarget.ES6) { + write("exports."); + } } emitNodeWithoutSourceMap(node.name); emitEnd(node.name); } - + function createVoidZero(): Expression { let zero = createSynthesizedNode(SyntaxKind.NumericLiteral); zero.text = "0"; @@ -4030,7 +2684,7 @@ module ts { function emitDestructuringAssignment(target: Expression, value: Expression) { if (target.kind === SyntaxKind.BinaryExpression && (target).operatorToken.kind === SyntaxKind.EqualsToken) { - value = createDefaultValueCheck(value,(target).right); + value = createDefaultValueCheck(value, (target).right); target = (target).left; } if (target.kind === SyntaxKind.ObjectLiteralExpression) { @@ -4149,7 +2803,10 @@ module ts { } function emitExportVariableAssignments(node: VariableDeclaration | BindingElement) { - let name = (node).name; + if (node.kind === SyntaxKind.OmittedExpression) { + return; + } + let name = node.name; if (name.kind === SyntaxKind.Identifier) { emitExportMemberAssignments(name); } @@ -4157,7 +2814,7 @@ module ts { forEach((name).elements, emitExportVariableAssignments); } } - + function getCombinedFlagsForIdentifier(node: Identifier): NodeFlags { if (!node.parent || (node.parent.kind !== SyntaxKind.VariableDeclaration && node.parent.kind !== SyntaxKind.BindingElement)) { return 0; @@ -4188,9 +2845,14 @@ module ts { // here it is known that node is a block scoped variable let list = getAncestor(node, SyntaxKind.VariableDeclarationList); - if (list.parent.kind === SyntaxKind.VariableStatement && list.parent.parent.kind === SyntaxKind.SourceFile) { - // do not rename variables that are defined on source file level - return; + if (list.parent.kind === SyntaxKind.VariableStatement) { + let isSourceFileLevelBinding = list.parent.parent.kind === SyntaxKind.SourceFile; + let isModuleLevelBinding = list.parent.parent.kind === SyntaxKind.ModuleBlock; + let isFunctionLevelBinding = + list.parent.parent.kind === SyntaxKind.Block && isFunctionLike(list.parent.parent.parent); + if (isSourceFileLevelBinding || isModuleLevelBinding || isFunctionLevelBinding) { + return; + } } let blockScopeContainer = getEnclosingBlockScopeContainer(node); @@ -4198,18 +2860,36 @@ module ts { ? blockScopeContainer : blockScopeContainer.parent; - let generatedName = generateUniqueNameForLocation(parent, (node).text); - let variableId = resolver.getBlockScopedVariableId(node); - if (!generatedBlockScopeNames) { - generatedBlockScopeNames = []; + var hasConflictsInEnclosingScope = + resolver.resolvesToSomeValue(parent, (node).text) || + nameConflictsWithSomeTempVariable((node).text); + + if (hasConflictsInEnclosingScope) { + let variableId = resolver.getBlockScopedVariableId(node); + if (!blockScopedVariableToGeneratedName) { + blockScopedVariableToGeneratedName = []; + } + + let generatedName = makeUniqueName((node).text); + blockScopedVariableToGeneratedName[variableId] = generatedName; } - generatedBlockScopeNames[variableId] = generatedName; + } + + function isES6ExportedDeclaration(node: Node) { + return !!(node.flags & NodeFlags.Export) && + languageVersion >= ScriptTarget.ES6 && + node.parent.kind === SyntaxKind.SourceFile; } function emitVariableStatement(node: VariableStatement) { if (!(node.flags & NodeFlags.Export)) { emitStartOfVariableDeclarationList(node.declarationList); } + else if (isES6ExportedDeclaration(node)) { + // Exported ES6 module member + write("export "); + emitStartOfVariableDeclarationList(node.declarationList); + } emitCommaList(node.declarationList.declarations); write(";"); if (languageVersion < ScriptTarget.ES6 && node.parent === currentSourceFile) { @@ -4274,7 +2954,7 @@ module ts { if (languageVersion < ScriptTarget.ES6 && hasRestParameters(node)) { let restIndex = node.parameters.length - 1; let restParam = node.parameters[restIndex]; - let tempName = createTempVariable(node, /*preferredName:*/ "_i").text; + let tempName = createTempVariable(node, TempVariableKind._i).text; writeLine(); emitLeadingComments(restParam); emitStart(restParam); @@ -4311,7 +2991,7 @@ module ts { function emitAccessor(node: AccessorDeclaration) { write(node.kind === SyntaxKind.GetAccessor ? "get " : "set "); - emit(node.name); + emit(node.name, /*allowGeneratedIdentifiers*/ false); emitSignatureAndBody(node); } @@ -4324,13 +3004,26 @@ module ts { emitNodeWithoutSourceMap(node.name); } else { - write(resolver.getGeneratedNameForNode(node)); + write(getGeneratedNameForNode(node)); + } + } + + function shouldEmitFunctionName(node: Declaration): boolean { + // Emit a declaration name for the function iff: + // it is a function expression with a name provided + // it is a function declaration with a name provided + // it is a function declaration is not the default export, and is missing a name (emit a generated name for it) + if (node.kind === SyntaxKind.FunctionExpression) { + return !!node.name; + } + else if (node.kind === SyntaxKind.FunctionDeclaration) { + return !!node.name || (languageVersion >= ScriptTarget.ES6 && !(node.flags & NodeFlags.Default)); } } function emitFunctionDeclaration(node: FunctionLikeDeclaration) { if (nodeIsMissing(node.body)) { - return emitPinnedOrTripleSlashComments(node); + return emitOnlyPinnedOrTripleSlashComments(node); } if (node.kind !== SyntaxKind.MethodDeclaration && node.kind !== SyntaxKind.MethodSignature) { @@ -4341,12 +3034,19 @@ module ts { // For targeting below es6, emit functions-like declaration including arrow function using function keyword. // When targeting ES6, emit arrow function natively in ES6 by omitting function keyword and using fat arrow instead if (!shouldEmitAsArrowFunction(node)) { + if (isES6ExportedDeclaration(node)) { + write("export "); + if (node.flags & NodeFlags.Default) { + write("default "); + } + } write("function "); } - if (node.kind === SyntaxKind.FunctionDeclaration || (node.kind === SyntaxKind.FunctionExpression && node.name)) { + if (shouldEmitFunctionName(node)) { emitDeclarationName(node); } + emitSignatureAndBody(node); if (languageVersion < ScriptTarget.ES6 && node.kind === SyntaxKind.FunctionDeclaration && node.parent === currentSourceFile && node.name) { emitExportMemberAssignments((node).name); @@ -4390,11 +3090,12 @@ module ts { let saveTempCount = tempCount; let saveTempVariables = tempVariables; let saveTempParameters = tempParameters; + let savePredefinedTempsInUse = predefinedTempsInUse; + tempCount = 0; tempVariables = undefined; tempParameters = undefined; - - let popFrame = enterNameScope() + predefinedTempsInUse = TempVariableKind.auto; // When targeting ES6, emit arrow function natively in ES6 if (shouldEmitAsArrowFunction(node)) { @@ -4417,10 +3118,11 @@ module ts { emitExpressionFunctionBody(node, node.body); } - emitExportMemberAssignment(node); - - exitNameScope(popFrame); + if (!isES6ExportedDeclaration(node)) { + emitExportMemberAssignment(node); + } + predefinedTempsInUse = savePredefinedTempsInUse; tempCount = saveTempCount; tempVariables = saveTempVariables; tempParameters = saveTempParameters; @@ -4471,10 +3173,7 @@ module ts { write(" "); emitStart(body); write("return "); - - // Don't emit comments on this body. We'll have already taken care of it above - // when we called emitDetachedComments. - emitWithoutComments(body); + emit(body); emitEnd(body); write(";"); emitTempDeclarations(/*newLine*/ false); @@ -4485,10 +3184,7 @@ module ts { writeLine(); emitLeadingComments(node.body); write("return "); - - // Don't emit comments on this body. We'll have already taken care of it above - // when we called emitDetachedComments. - emitWithoutComments(node.body); + emit(body); write(";"); emitTrailingComments(node.body); @@ -4616,25 +3312,21 @@ module ts { }); } - function emitMemberFunctions(node: ClassDeclaration) { + function emitMemberFunctionsForES5AndLower(node: ClassDeclaration) { forEach(node.members, member => { if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) { if (!(member).body) { - return emitPinnedOrTripleSlashComments(member); + return emitOnlyPinnedOrTripleSlashComments(member); } writeLine(); emitLeadingComments(member); emitStart(member); emitStart((member).name); - emitDeclarationName(node); - if (!(member.flags & NodeFlags.Static)) { - write(".prototype"); - } + emitClassMemberPrefix(node, member); emitMemberAccessForPropertyName((member).name); emitEnd((member).name); write(" = "); - // TODO (drosen): Should we performing emitStart twice on emitStart(member)? emitStart(member); emitFunctionDeclaration(member); emitEnd(member); @@ -4649,12 +3341,8 @@ module ts { emitStart(member); write("Object.defineProperty("); emitStart((member).name); - emitDeclarationName(node); - if (!(member.flags & NodeFlags.Static)) { - write(".prototype"); - } + emitClassMemberPrefix(node, member); write(", "); - // TODO: Shouldn't emitStart on name occur *here*? emitExpressionForPropertyName((member).name); emitEnd((member).name); write(", {"); @@ -4694,7 +3382,311 @@ module ts { }); } + function emitMemberFunctionsForES6AndHigher(node: ClassDeclaration) { + for (let member of node.members) { + if ((member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) && !(member).body) { + emitOnlyPinnedOrTripleSlashComments(member); + } + else if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature || member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) { + writeLine(); + emitLeadingComments(member); + emitStart(member); + if (member.flags & NodeFlags.Static) { + write("static "); + } + + if (member.kind === SyntaxKind.GetAccessor) { + write("get "); + } + else if (member.kind === SyntaxKind.SetAccessor) { + write("set "); + } + emit((member).name); + emitSignatureAndBody(member); + emitEnd(member); + emitTrailingComments(member); + } + } + } + + function emitConstructor(node: ClassDeclaration, baseTypeNode: TypeReferenceNode) { + let saveTempCount = tempCount; + let saveTempVariables = tempVariables; + let saveTempParameters = tempParameters; + let savePredefinedTempsInUse = predefinedTempsInUse; + tempCount = 0; + tempVariables = undefined; + tempParameters = undefined; + predefinedTempsInUse = TempVariableKind.auto; + + // Check if we have property assignment inside class declaration. + // If there is property assignment, we need to emit constructor whether users define it or not + // If there is no property assignment, we can omit constructor if users do not define it + let hasInstancePropertyWithInitializer = false; + + // Emit the constructor overload pinned comments + forEach(node.members, member => { + if (member.kind === SyntaxKind.Constructor && !(member).body) { + emitOnlyPinnedOrTripleSlashComments(member); + } + // Check if there is any non-static property assignment + if (member.kind === SyntaxKind.PropertyDeclaration && (member).initializer && (member.flags & NodeFlags.Static) === 0) { + hasInstancePropertyWithInitializer = true; + } + }); + + let ctor = getFirstConstructorWithBody(node); + + // For target ES6 and above, if there is no user-defined constructor and there is no property assignment + // do not emit constructor in class declaration. + if (languageVersion >= ScriptTarget.ES6 && !ctor && !hasInstancePropertyWithInitializer) { + return; + } + + if (ctor) { + emitLeadingComments(ctor); + } + emitStart(ctor || node); + + if (languageVersion < ScriptTarget.ES6) { + write("function "); + emitDeclarationName(node); + emitSignatureParameters(ctor); + } + else { + write("constructor"); + if (ctor) { + emitSignatureParameters(ctor); + } + else { + // Based on EcmaScript6 section 14.5.14: Runtime Semantics: ClassDefinitionEvaluation. + // If constructor is empty, then, + // If ClassHeritageopt is present, then + // Let constructor be the result of parsing the String "constructor(... args){ super (...args);}" using the syntactic grammar with the goal symbol MethodDefinition. + // Else, + // Let constructor be the result of parsing the String "constructor( ){ }" using the syntactic grammar with the goal symbol MethodDefinition + if (baseTypeNode) { + write("(...args)"); + } + else { + write("()"); + } + } + } + + write(" {"); + scopeEmitStart(node, "constructor"); + increaseIndent(); + if (ctor) { + emitDetachedComments(ctor.body.statements); + } + emitCaptureThisForNodeIfNecessary(node); + if (ctor) { + emitDefaultValueAssignments(ctor); + emitRestParameter(ctor); + if (baseTypeNode) { + var superCall = findInitialSuperCall(ctor); + if (superCall) { + writeLine(); + emit(superCall); + } + } + emitParameterPropertyAssignments(ctor); + } + else { + if (baseTypeNode) { + writeLine(); + emitStart(baseTypeNode); + if (languageVersion < ScriptTarget.ES6) { + write("_super.apply(this, arguments);"); + } + else { + write("super(...args);"); + } + emitEnd(baseTypeNode); + } + } + emitMemberAssignments(node, /*staticFlag*/0); + if (ctor) { + var statements: Node[] = (ctor.body).statements; + if (superCall) { + statements = statements.slice(1); + } + emitLines(statements); + } + emitTempDeclarations(/*newLine*/ true); + writeLine(); + if (ctor) { + emitLeadingCommentsOfPosition((ctor.body).statements.end); + } + decreaseIndent(); + emitToken(SyntaxKind.CloseBraceToken, ctor ? (ctor.body).statements.end : node.members.end); + scopeEmitEnd(); + emitEnd(ctor || node); + if (ctor) { + emitTrailingComments(ctor); + } + + predefinedTempsInUse = savePredefinedTempsInUse; + tempCount = saveTempCount; + tempVariables = saveTempVariables; + tempParameters = saveTempParameters; + } + function emitClassDeclaration(node: ClassDeclaration) { + if (languageVersion < ScriptTarget.ES6) { + emitClassDeclarationBelowES6(node); + } + else { + emitClassDeclarationForES6AndHigher(node); + } + } + + function emitClassDeclarationForES6AndHigher(node: ClassDeclaration) { + let thisNodeIsDecorated = nodeIsDecorated(node); + if (thisNodeIsDecorated) { + // To preserve the correct runtime semantics when decorators are applied to the class, + // the emit needs to follow one of the following rules: + // + // * For a local class declaration: + // + // @dec class C { + // } + // + // The emit should be: + // + // let C = class { + // }; + // Object.defineProperty(C, "name", { value: "C", configurable: true }); + // C = __decorate([dec], C); + // + // * For an exported class declaration: + // + // @dec export class C { + // } + // + // The emit should be: + // + // export let C = class { + // }; + // Object.defineProperty(C, "name", { value: "C", configurable: true }); + // C = __decorate([dec], C); + // + // * For a default export of a class declaration with a name: + // + // @dec default export class C { + // } + // + // The emit should be: + // + // let C = class { + // } + // Object.defineProperty(C, "name", { value: "C", configurable: true }); + // C = __decorate([dec], C); + // export default C; + // + // * For a default export of a class declaration without a name: + // + // @dec default export class { + // } + // + // The emit should be: + // + // let _default = class { + // } + // _default = __decorate([dec], _default); + // export default _default; + // + if (isES6ExportedDeclaration(node) && !(node.flags & NodeFlags.Default)) { + write("export "); + } + + write("let "); + emitDeclarationName(node); + write(" = "); + } + else if (isES6ExportedDeclaration(node)) { + write("export "); + if (node.flags & NodeFlags.Default) { + write("default "); + } + } + + write("class"); + + // check if this is an "export default class" as it may not have a name. Do not emit the name if the class is decorated. + if ((node.name || !(node.flags & NodeFlags.Default)) && !thisNodeIsDecorated) { + write(" "); + emitDeclarationName(node); + } + + var baseTypeNode = getClassBaseTypeNode(node); + if (baseTypeNode) { + write(" extends "); + emit(baseTypeNode.typeName); + } + + write(" {"); + increaseIndent(); + scopeEmitStart(node); + writeLine(); + emitConstructor(node, baseTypeNode); + emitMemberFunctionsForES6AndHigher(node); + decreaseIndent(); + writeLine(); + emitToken(SyntaxKind.CloseBraceToken, node.members.end); + scopeEmitEnd(); + + // For a decorated class, we need to assign its name (if it has one). This is because we emit + // the class as a class expression to avoid the double-binding of the identifier: + // + // let C = class { + // } + // Object.defineProperty(C, "name", { value: "C", configurable: true }); + // + if (thisNodeIsDecorated) { + write(";"); + if (node.name) { + writeLine(); + write("Object.defineProperty("); + emitDeclarationName(node); + write(", \"name\", { value: \""); + emitDeclarationName(node); + write("\", configurable: true });"); + writeLine(); + } + } + + // Emit static property assignment. Because classDeclaration is lexically evaluated, + // it is safe to emit static property assignment after classDeclaration + // From ES6 specification: + // HasLexicalDeclaration (N) : Determines if the argument identifier has a binding in this environment record that was created using + // a lexical declaration such as a LexicalDeclaration or a ClassDeclaration. + writeLine(); + emitMemberAssignments(node, NodeFlags.Static); + emitDecoratorsOfClass(node); + + // If this is an exported class, but not on the top level (i.e. on an internal + // module), export it + if (!isES6ExportedDeclaration(node) && (node.flags & NodeFlags.Export)) { + writeLine(); + emitStart(node); + emitModuleMemberName(node); + write(" = "); + emitDeclarationName(node); + emitEnd(node); + write(";"); + } + else if (isES6ExportedDeclaration(node) && (node.flags & NodeFlags.Default) && thisNodeIsDecorated) { + // if this is a top level default export of decorated class, write the export after the declaration. + writeLine(); + write("export default "); + emitDeclarationName(node); + write(";"); + } + } + + function emitClassDeclarationBelowES6(node: ClassDeclaration) { write("var "); emitDeclarationName(node); write(" = (function ("); @@ -4703,6 +3695,14 @@ module ts { write("_super"); } write(") {"); + let saveTempCount = tempCount; + let saveTempVariables = tempVariables; + let saveTempParameters = tempParameters; + let saveComputedPropertyNamesToGeneratedNames = computedPropertyNamesToGeneratedNames; + tempCount = 0; + tempVariables = undefined; + tempParameters = undefined; + computedPropertyNamesToGeneratedNames = undefined; increaseIndent(); scopeEmitStart(node); if (baseTypeNode) { @@ -4714,113 +3714,262 @@ module ts { emitEnd(baseTypeNode); } writeLine(); - emitConstructorOfClass(); - emitMemberFunctions(node); + emitConstructor(node, baseTypeNode); + emitMemberFunctionsForES5AndLower(node); emitMemberAssignments(node, NodeFlags.Static); writeLine(); + emitDecoratorsOfClass(node); + writeLine(); emitToken(SyntaxKind.CloseBraceToken, node.members.end, () => { write("return "); emitDeclarationName(node); }); write(";"); + emitTempDeclarations(/*newLine*/ true); + tempCount = saveTempCount; + tempVariables = saveTempVariables; + tempParameters = saveTempParameters; + computedPropertyNamesToGeneratedNames = saveComputedPropertyNamesToGeneratedNames; decreaseIndent(); writeLine(); emitToken(SyntaxKind.CloseBraceToken, node.members.end); scopeEmitEnd(); emitStart(node); - write(")("); - if (baseTypeNode) { - emit(baseTypeNode.typeName); - } + write(")("); + if (baseTypeNode) { + emit(baseTypeNode.typeName); + } + write(");"); + emitEnd(node); + + emitExportMemberAssignment(node); + + if (languageVersion < ScriptTarget.ES6 && node.parent === currentSourceFile && node.name) { + emitExportMemberAssignments(node.name); + } + } + + function emitClassMemberPrefix(node: ClassDeclaration, member: Node) { + emitDeclarationName(node); + if (!(member.flags & NodeFlags.Static)) { + write(".prototype"); + } + } + + function emitDecoratorsOfClass(node: ClassDeclaration) { + if (languageVersion < ScriptTarget.ES5) { + return; + } + + emitDecoratorsOfMembers(node, /*staticFlag*/ 0); + emitDecoratorsOfMembers(node, NodeFlags.Static); + emitDecoratorsOfConstructor(node); + } + + function emitDecoratorsOfConstructor(node: ClassDeclaration) { + let constructor = getFirstConstructorWithBody(node); + if (constructor) { + emitDecoratorsOfParameters(node, constructor); + } + + if (!nodeIsDecorated(node)) { + return; + } + + // Emit the call to __decorate. Given the class: + // + // @dec + // class C { + // } + // + // The emit for the class is: + // + // C = __decorate([dec], C); + // + + writeLine(); + emitStart(node); + emitDeclarationName(node); + write(" = "); + emitDecorateStart(node.decorators); + emitDeclarationName(node); write(");"); emitEnd(node); - emitExportMemberAssignment(node); - if (languageVersion < ScriptTarget.ES6 && node.parent === currentSourceFile && node.name) { - emitExportMemberAssignments(node.name); - } + writeLine(); + } - function emitConstructorOfClass() { - let saveTempCount = tempCount; - let saveTempVariables = tempVariables; - let saveTempParameters = tempParameters; - tempCount = 0; - tempVariables = undefined; - tempParameters = undefined; + function emitDecoratorsOfMembers(node: ClassDeclaration, staticFlag: NodeFlags) { + forEach(node.members, member => { + if ((member.flags & NodeFlags.Static) !== staticFlag) { + return; + } - let popFrame = enterNameScope(); + let decorators: NodeArray; + switch (member.kind) { + case SyntaxKind.MethodDeclaration: + // emit decorators of the method's parameters + emitDecoratorsOfParameters(node, member); + decorators = member.decorators; + break; - // Emit the constructor overload pinned comments - forEach(node.members, member => { - if (member.kind === SyntaxKind.Constructor && !(member).body) { - emitPinnedOrTripleSlashComments(member); - } - }); + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + let accessors = getAllAccessorDeclarations(node.members, member); + if (member !== accessors.firstAccessor) { + // skip the second accessor as we processed it with the first. + return; + } - let ctor = getFirstConstructorWithBody(node); - if (ctor) { - emitLeadingComments(ctor); + if (accessors.setAccessor) { + // emit decorators of the set accessor parameter + emitDecoratorsOfParameters(node, accessors.setAccessor); + } + + // get the decorators from the first decorated accessor. + decorators = accessors.firstAccessor.decorators; + if (!decorators && accessors.secondAccessor) { + decorators = accessors.secondAccessor.decorators; + } + break; + + case SyntaxKind.PropertyDeclaration: + decorators = member.decorators; + break; + + default: + // Constructor cannot be decorated, and its parameters are handled in emitDecoratorsOfConstructor + // Other members (i.e. IndexSignature) cannot be decorated. + return; } - emitStart(ctor || node); - write("function "); - emitDeclarationName(node); - emitSignatureParameters(ctor); - write(" {"); - scopeEmitStart(node, "constructor"); - increaseIndent(); - if (ctor) { - emitDetachedComments((ctor.body).statements); + + if (!decorators) { + return; } - emitCaptureThisForNodeIfNecessary(node); - let superCall: ExpressionStatement; - if (ctor) { - emitDefaultValueAssignments(ctor); - emitRestParameter(ctor); - if (baseTypeNode) { - superCall = findInitialSuperCall(ctor); - if (superCall) { - writeLine(); - emit(superCall); - } - } - emitParameterPropertyAssignments(ctor); + + // Emit the call to __decorate. Given the following: + // + // class C { + // @dec method() {} + // @dec get accessor() {} + // @dec prop; + // } + // + // The emit for a method is: + // + // Object.defineProperty(C.prototype, "method", __decorate([dec], C.prototype, "method", Object.getOwnPropertyDescriptor(C.prototype, "method"))); + // + // The emit for an accessor is: + // + // Object.defineProperty(C.prototype, "accessor", __decorate([dec], C.prototype, "accessor", Object.getOwnPropertyDescriptor(C.prototype, "accessor"))); + // + // The emit for a property is: + // + // __decorate([dec], C.prototype, "prop"); + // + + writeLine(); + emitStart(member); + if (member.kind !== SyntaxKind.PropertyDeclaration) { + write("Object.defineProperty("); + emitStart(member.name); + emitClassMemberPrefix(node, member); + write(", "); + emitExpressionForPropertyName(member.name); + emitEnd(member.name); + write(", "); } - else { - if (baseTypeNode) { - writeLine(); - emitStart(baseTypeNode); - write("_super.apply(this, arguments);"); - emitEnd(baseTypeNode); - } + + emitDecorateStart(decorators); + emitStart(member.name); + emitClassMemberPrefix(node, member); + write(", "); + emitExpressionForPropertyName(member.name); + emitEnd(member.name); + + if (member.kind !== SyntaxKind.PropertyDeclaration) { + write(", Object.getOwnPropertyDescriptor("); + emitStart(member.name); + emitClassMemberPrefix(node, member); + write(", "); + emitExpressionForPropertyName(member.name); + emitEnd(member.name); + write("))"); } - emitMemberAssignments(node, /*nonstatic*/0); - if (ctor) { - let statements: Node[] = (ctor.body).statements; - if (superCall) statements = statements.slice(1); - emitLines(statements); + + write(");"); + emitEnd(member); + writeLine(); + }); + } + + function emitDecoratorsOfParameters(node: ClassDeclaration, member: FunctionLikeDeclaration) { + forEach(member.parameters, (parameter, parameterIndex) => { + if (!nodeIsDecorated(parameter)) { + return; } - emitTempDeclarations(/*newLine*/ true); + + // Emit the decorators for a parameter. Given the following: + // + // class C { + // constructor(@dec p) { } + // method(@dec p) { } + // set accessor(@dec value) { } + // } + // + // The emit for a constructor is: + // + // __decorate([dec], C, void 0, 0); + // + // The emit for a parameter is: + // + // __decorate([dec], C.prototype, "method", 0); + // + // The emit for an accessor is: + // + // __decorate([dec], C.prototype, "accessor", 0); + // + writeLine(); - if (ctor) { - emitLeadingCommentsOfPosition((ctor.body).statements.end); + emitStart(parameter); + emitDecorateStart(parameter.decorators); + emitStart(parameter.name); + + if (member.kind === SyntaxKind.Constructor) { + emitDeclarationName(node); + write(", void 0"); } - decreaseIndent(); - emitToken(SyntaxKind.CloseBraceToken, ctor ? (ctor.body).statements.end : node.members.end); - scopeEmitEnd(); - emitEnd(ctor || node); - if (ctor) { - emitTrailingComments(ctor); + else { + emitClassMemberPrefix(node, member); + write(", "); + emitExpressionForPropertyName(member.name); } - exitNameScope(popFrame); + write(", "); + write(String(parameterIndex)); + emitEnd(parameter.name); + write(");"); + emitEnd(parameter); + writeLine(); + }); + } - tempCount = saveTempCount; - tempVariables = saveTempVariables; - tempParameters = saveTempParameters; + function emitDecorateStart(decorators: Decorator[]): void { + write("__decorate(["); + let decoratorCount = decorators.length; + for (let i = 0; i < decoratorCount; i++) { + if (i > 0) { + write(", "); + } + let decorator = decorators[i]; + emitStart(decorator); + emit(decorator.expression); + emitEnd(decorator); } + write("], "); } function emitInterfaceDeclaration(node: InterfaceDeclaration) { - emitPinnedOrTripleSlashComments(node); + emitOnlyPinnedOrTripleSlashComments(node); } function shouldEmitEnumDeclaration(node: EnumDeclaration) { @@ -4834,8 +3983,11 @@ module ts { return; } - if (!(node.flags & NodeFlags.Export)) { + if (!(node.flags & NodeFlags.Export) || isES6ExportedDeclaration(node)) { emitStart(node); + if (isES6ExportedDeclaration(node)) { + write("export "); + } write("var "); emit(node.name); emitEnd(node); @@ -4845,7 +3997,7 @@ module ts { emitStart(node); write("(function ("); emitStart(node.name); - write(resolver.getGeneratedNameForNode(node)); + write(getGeneratedNameForNode(node)); emitEnd(node.name); write(") {"); increaseIndent(); @@ -4861,7 +4013,7 @@ module ts { emitModuleMemberName(node); write(" = {}));"); emitEnd(node); - if (node.flags & NodeFlags.Export) { + if (!isES6ExportedDeclaration(node) && node.flags & NodeFlags.Export) { writeLine(); emitStart(node); write("var "); @@ -4879,9 +4031,9 @@ module ts { function emitEnumMember(node: EnumMember) { let enumParent = node.parent; emitStart(node); - write(resolver.getGeneratedNameForNode(enumParent)); + write(getGeneratedNameForNode(enumParent)); write("["); - write(resolver.getGeneratedNameForNode(enumParent)); + write(getGeneratedNameForNode(enumParent)); write("["); emitExpressionForPropertyName(node.name); write("] = "); @@ -4893,15 +4045,12 @@ module ts { } function writeEnumMemberDeclarationValue(member: EnumMember) { - if (!member.initializer || isConst(member.parent)) { - let value = resolver.getConstantValue(member); - if (value !== undefined) { - write(value.toString()); - return; - } + let value = resolver.getConstantValue(member); + if (value !== undefined) { + write(value.toString()); + return; } - - if (member.initializer) { + else if (member.initializer) { emit(member.initializer); } else { @@ -4925,10 +4074,13 @@ module ts { let shouldEmit = shouldEmitModuleDeclaration(node); if (!shouldEmit) { - return emitPinnedOrTripleSlashComments(node); + return emitOnlyPinnedOrTripleSlashComments(node); } emitStart(node); + if (isES6ExportedDeclaration(node)) { + write("export "); + } write("var "); emit(node.name); write(";"); @@ -4937,19 +4089,20 @@ module ts { emitStart(node); write("(function ("); emitStart(node.name); - write(resolver.getGeneratedNameForNode(node)); + write(getGeneratedNameForNode(node)); emitEnd(node.name); write(") "); if (node.body.kind === SyntaxKind.ModuleBlock) { let saveTempCount = tempCount; let saveTempVariables = tempVariables; + let savePredefinedTempsInUse = predefinedTempsInUse; tempCount = 0; tempVariables = undefined; - let popFrame = enterNameScope(); + predefinedTempsInUse = TempVariableKind.auto; emit(node.body); - exitNameScope(popFrame); + predefinedTempsInUse = savePredefinedTempsInUse; tempCount = saveTempCount; tempVariables = saveTempVariables; } @@ -4967,7 +4120,8 @@ module ts { scopeEmitEnd(); } write(")("); - if (node.flags & NodeFlags.Export) { + // write moduleDecl = containingModule.m only if it is not exported es6 module member + if ((node.flags & NodeFlags.Export) && !isES6ExportedDeclaration(node)) { emit(node.name); write(" = "); } @@ -4976,7 +4130,7 @@ module ts { emitModuleMemberName(node); write(" = {}));"); emitEnd(node); - if (languageVersion < ScriptTarget.ES6 && node.name.kind === SyntaxKind.Identifier && node.parent === currentSourceFile) { + if (!isES6ExportedDeclaration(node) && node.name.kind === SyntaxKind.Identifier && node.parent === currentSourceFile) { emitExportMemberAssignments(node.name); } } @@ -5015,10 +4169,58 @@ module ts { forEachChild(node, emitExportImportAssignments); } - function emitImportDeclaration(node: ImportDeclaration | ImportEqualsDeclaration) { + function emitImportDeclaration(node: ImportDeclaration) { + if (languageVersion < ScriptTarget.ES6) { + return emitExternalImportDeclaration(node); + } + + // ES6 import + if (node.importClause) { + let shouldEmitDefaultBindings = resolver.isReferencedAliasDeclaration(node.importClause); + let shouldEmitNamedBindings = node.importClause.namedBindings && resolver.isReferencedAliasDeclaration(node.importClause.namedBindings, /* checkChildren */ true); + if (shouldEmitDefaultBindings || shouldEmitNamedBindings) { + write("import "); + emitStart(node.importClause); + if (shouldEmitDefaultBindings) { + emit(node.importClause.name); + if (shouldEmitNamedBindings) { + write(", "); + } + } + if (shouldEmitNamedBindings) { + emitLeadingComments(node.importClause.namedBindings); + emitStart(node.importClause.namedBindings); + if (node.importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { + write("* as "); + emit((node.importClause.namedBindings).name); + } + else { + write("{ "); + emitExportOrImportSpecifierList((node.importClause.namedBindings).elements, resolver.isReferencedAliasDeclaration); + write(" }"); + } + emitEnd(node.importClause.namedBindings); + emitTrailingComments(node.importClause.namedBindings); + } + + emitEnd(node.importClause); + write(" from "); + emit(node.moduleSpecifier); + write(";"); + } + } + else { + write("import "); + emit(node.moduleSpecifier); + write(";"); + } + } + + function emitExternalImportDeclaration(node: ImportDeclaration | ImportEqualsDeclaration) { if (contains(externalImports, node)) { let isExportedImport = node.kind === SyntaxKind.ImportEqualsDeclaration && (node.flags & NodeFlags.Export) !== 0; let namespaceDeclaration = getNamespaceDeclarationNode(node); + if (compilerOptions.module !== ModuleKind.AMD) { emitLeadingComments(node); emitStart(node); @@ -5038,7 +4240,7 @@ module ts { let isNakedImport = SyntaxKind.ImportDeclaration && !(node).importClause; if (!isNakedImport) { write("var "); - write(resolver.getGeneratedNameForNode(node)); + write(getGeneratedNameForNode(node)); write(" = "); } } @@ -5048,7 +4250,7 @@ module ts { write(", "); emitModuleMemberName(namespaceDeclaration); write(" = "); - write(resolver.getGeneratedNameForNode(node)); + write(getGeneratedNameForNode(node)); } write(";"); emitEnd(node); @@ -5067,7 +4269,7 @@ module ts { write("var "); emitModuleMemberName(namespaceDeclaration); write(" = "); - write(resolver.getGeneratedNameForNode(node)); + write(getGeneratedNameForNode(node)); write(";"); } emitExportImportAssignments(node); @@ -5077,7 +4279,7 @@ module ts { function emitImportEqualsDeclaration(node: ImportEqualsDeclaration) { if (isExternalModuleImportEqualsDeclaration(node)) { - emitImportDeclaration(node); + emitExternalImportDeclaration(node); return; } // preserve old compiler's behavior: emit 'var' for import declaration (even if we do not consider them referenced) when @@ -5087,7 +4289,13 @@ module ts { (!isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportEqualsWithEntityName(node))) { emitLeadingComments(node); emitStart(node); - if (!(node.flags & NodeFlags.Export)) write("var "); + if (isES6ExportedDeclaration(node)) { + write("export "); + write("var "); + } + else if (!(node.flags & NodeFlags.Export)) { + write("var "); + } emitModuleMemberName(node); write(" = "); emit(node.moduleReference); @@ -5099,59 +4307,117 @@ module ts { } function emitExportDeclaration(node: ExportDeclaration) { - if (node.moduleSpecifier && (!node.exportClause || resolver.isValueAliasDeclaration(node))) { - emitStart(node); - let generatedName = resolver.getGeneratedNameForNode(node); - if (node.exportClause) { - // export { x, y, ... } from "foo" - if (compilerOptions.module !== ModuleKind.AMD) { - write("var "); - write(generatedName); - write(" = "); - emitRequire(getExternalModuleName(node)); - write(";"); - } - for (let specifier of node.exportClause.elements) { - if (resolver.isValueAliasDeclaration(specifier)) { - writeLine(); - emitStart(specifier); - emitContainingModuleName(specifier); - write("."); - emitNodeWithoutSourceMap(specifier.name); - write(" = "); + if (languageVersion < ScriptTarget.ES6) { + if (node.moduleSpecifier && (!node.exportClause || resolver.isValueAliasDeclaration(node))) { + emitStart(node); + let generatedName = getGeneratedNameForNode(node); + if (node.exportClause) { + // export { x, y, ... } from "foo" + if (compilerOptions.module !== ModuleKind.AMD) { + write("var "); write(generatedName); - write("."); - emitNodeWithoutSourceMap(specifier.propertyName || specifier.name); + write(" = "); + emitRequire(getExternalModuleName(node)); write(";"); - emitEnd(specifier); } + for (let specifier of node.exportClause.elements) { + if (resolver.isValueAliasDeclaration(specifier)) { + writeLine(); + emitStart(specifier); + emitContainingModuleName(specifier); + write("."); + emitNodeWithoutSourceMap(specifier.name); + write(" = "); + write(generatedName); + write("."); + emitNodeWithoutSourceMap(specifier.propertyName || specifier.name); + write(";"); + emitEnd(specifier); + } + } + } + else { + // export * from "foo" + writeLine(); + write("__export("); + if (compilerOptions.module !== ModuleKind.AMD) { + emitRequire(getExternalModuleName(node)); + } + else { + write(generatedName); + } + write(");"); } + emitEnd(node); } - else { - // export * from "foo" - writeLine(); - write("__export("); - if (compilerOptions.module !== ModuleKind.AMD) { - emitRequire(getExternalModuleName(node)); + } + else { + if (!node.exportClause || resolver.isValueAliasDeclaration(node)) { + emitStart(node); + write("export "); + if (node.exportClause) { + // export { x, y, ... } + write("{ "); + emitExportOrImportSpecifierList(node.exportClause.elements, resolver.isValueAliasDeclaration); + write(" }"); } else { - write(generatedName); + write("*"); + } + if (node.moduleSpecifier) { + write(" from "); + emitNodeWithoutSourceMap(node.moduleSpecifier); } - write(");"); + write(";"); + emitEnd(node); + } + } + } + + function emitExportOrImportSpecifierList(specifiers: ImportOrExportSpecifier[], shouldEmit: (node: Node) => boolean) { + Debug.assert(languageVersion >= ScriptTarget.ES6); + + let needsComma = false; + for (let specifier of specifiers) { + if (shouldEmit(specifier)) { + if (needsComma) { + write(", "); + } + emitStart(specifier); + if (specifier.propertyName) { + emitNodeWithoutSourceMap(specifier.propertyName); + write(" as "); + } + emitNodeWithoutSourceMap(specifier.name); + emitEnd(specifier); + needsComma = true; } - emitEnd(node); } } function emitExportAssignment(node: ExportAssignment) { if (!node.isExportEquals && resolver.isValueAliasDeclaration(node)) { - writeLine(); - emitStart(node); - emitContainingModuleName(node); - write(".default = "); - emit(node.expression); - write(";"); - emitEnd(node); + if (languageVersion >= ScriptTarget.ES6) { + writeLine(); + emitStart(node); + write("export default "); + var expression = node.expression; + emit(expression); + if (expression.kind !== SyntaxKind.FunctionDeclaration && + expression.kind !== SyntaxKind.ClassDeclaration) { + write(";"); + } + emitEnd(node); + } + else { + writeLine(); + emitStart(node); + emitContainingModuleName(node); + write(".default = "); + emit(node.expression); + write(";"); + emitEnd(node); + } } } @@ -5163,7 +4429,8 @@ module ts { for (let node of sourceFile.statements) { switch (node.kind) { case SyntaxKind.ImportDeclaration: - if (!(node).importClause || resolver.isReferencedAliasDeclaration(node)) { + if (!(node).importClause || + resolver.isReferencedAliasDeclaration((node).importClause, /*checkChildren*/ true)) { // import "mod" // import x from "mod" where x is referenced // import * as x from "mod" where x is referenced @@ -5234,6 +4501,7 @@ module ts { } function emitAMDModule(node: SourceFile, startIndex: number) { + collectExternalModuleInfo(node); writeLine(); write("define("); sortAMDModules(node.amdDependencies); @@ -5264,7 +4532,7 @@ module ts { emit(namespaceDeclaration.name); } else { - write(resolver.getGeneratedNameForNode(importNode)); + write(getGeneratedNameForNode(importNode)); } } for (let amdDependency of node.amdDependencies) { @@ -5286,6 +4554,7 @@ module ts { } function emitCommonJSModule(node: SourceFile, startIndex: number) { + collectExternalModuleInfo(node); emitExportStarHelper(); emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); @@ -5293,6 +4562,18 @@ module ts { emitExportEquals(/*emitAsReturn*/ false); } + function emitES6Module(node: SourceFile, startIndex: number) { + externalImports = undefined; + exportSpecifiers = undefined; + exportEquals = undefined; + hasExportStars = false; + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(/*newLine*/ true); + // Emit exportDefault if it exists will happen as part + // or normal statement emit. + } + function emitExportEquals(emitAsReturn: boolean) { if (exportEquals && resolver.isValueAliasDeclaration(exportEquals)) { writeLine(); @@ -5320,14 +4601,27 @@ module ts { return statements.length; } + function writeHelper(text: string): void { + let lines = text.split(/\r\n|\r|\n/g); + for (let i = 0; i < lines.length; ++i) { + let line = lines[i]; + if (line.length) { + writeLine(); + write(line); + } + } + } + function emitSourceFileNode(node: SourceFile) { // Start new file on new line writeLine(); emitDetachedComments(node); // emit prologue directives prior to __extends - let startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false); - if (!extendsEmitted && resolver.getNodeCheckFlags(node) & NodeCheckFlags.EmitExtends) { + var startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false); + // Only Emit __extends function when target ES5. + // For target ES6 and above, we can emit classDeclaration as if. + if ((languageVersion < ScriptTarget.ES6) && (!extendsEmitted && resolver.getNodeCheckFlags(node) & NodeCheckFlags.EmitExtends)) { writeLine(); write("var __extends = this.__extends || function (d, b) {"); increaseIndent(); @@ -5344,9 +4638,28 @@ module ts { write("};"); extendsEmitted = true; } + if (!decorateEmitted && resolver.getNodeCheckFlags(node) & NodeCheckFlags.EmitDecorate) { + writeHelper(` +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +};`); + decorateEmitted = true; + } if (isExternalModule(node)) { - collectExternalModuleInfo(node); - if (compilerOptions.module === ModuleKind.AMD) { + if (languageVersion >= ScriptTarget.ES6) { + emitES6Module(node, startIndex); + } + else if (compilerOptions.module === ModuleKind.AMD) { emitAMDModule(node, startIndex); } else { @@ -5366,13 +4679,13 @@ module ts { emitLeadingComments(node.endOfFileToken); } - function emitNodeWithoutSourceMapWithComments(node: Node): void { + function emitNodeWithoutSourceMap(node: Node, allowGeneratedIdentifiers?: boolean): void { if (!node) { return; } if (node.flags & NodeFlags.Ambient) { - return emitPinnedOrTripleSlashComments(node); + return emitOnlyPinnedOrTripleSlashComments(node); } let emitComments = shouldEmitLeadingAndTrailingComments(node); @@ -5380,29 +4693,17 @@ module ts { emitLeadingComments(node); } - emitJavaScriptWorker(node); + emitJavaScriptWorker(node, allowGeneratedIdentifiers); if (emitComments) { emitTrailingComments(node); } } - function emitNodeWithoutSourceMapWithoutComments(node: Node): void { - if (!node) { - return; - } - - if (node.flags & NodeFlags.Ambient) { - return emitPinnedOrTripleSlashComments(node); - } - - emitJavaScriptWorker(node); - } - function shouldEmitLeadingAndTrailingComments(node: Node) { switch (node.kind) { // All of these entities are emitted in a specialized fashion. As such, we allow - // the specilized methods for each to handle the comments on the nodes. + // the specialized methods for each to handle the comments on the nodes. case SyntaxKind.InterfaceDeclaration: case SyntaxKind.FunctionDeclaration: case SyntaxKind.ImportDeclaration: @@ -5422,15 +4723,28 @@ module ts { return shouldEmitEnumDeclaration(node); } + // If this is the expression body of an arrow function that we're down-leveling, + // then we don't want to emit comments when we emit the body. It will have already + // been taken care of when we emitted the 'return' statement for the function + // expression body. + if (node.kind !== SyntaxKind.Block && + node.parent && + node.parent.kind === SyntaxKind.ArrowFunction && + (node.parent).body === node && + compilerOptions.target <= ScriptTarget.ES5) { + + return false; + } + // Emit comments for everything else. return true; } - function emitJavaScriptWorker(node: Node) { + function emitJavaScriptWorker(node: Node, allowGeneratedIdentifiers: boolean = true) { // Check if the node can be emitted regardless of the ScriptTarget switch (node.kind) { case SyntaxKind.Identifier: - return emitIdentifier(node); + return emitIdentifier(node, allowGeneratedIdentifiers); case SyntaxKind.Parameter: return emitParameter(node); case SyntaxKind.MethodDeclaration: @@ -5588,7 +4902,8 @@ module ts { function getLeadingCommentsWithoutDetachedComments() { // get the leading comments from detachedPos - let leadingComments = getLeadingCommentRanges(currentSourceFile.text, detachedCommentsInfo[detachedCommentsInfo.length - 1].detachedCommentEndPos); + let leadingComments = getLeadingCommentRanges(currentSourceFile.text, + detachedCommentsInfo[detachedCommentsInfo.length - 1].detachedCommentEndPos); if (detachedCommentsInfo.length - 1) { detachedCommentsInfo.pop(); } @@ -5599,43 +4914,72 @@ module ts { return leadingComments; } + function filterComments(ranges: CommentRange[], onlyPinnedOrTripleSlashComments: boolean): CommentRange[] { + // If we're removing comments, then we want to strip out all but the pinned or + // triple slash comments. + if (ranges && onlyPinnedOrTripleSlashComments) { + ranges = filter(ranges, isPinnedOrTripleSlashComment); + if (ranges.length === 0) { + return undefined; + } + } + + return ranges; + } + function getLeadingCommentsToEmit(node: Node) { // Emit the leading comments only if the parent's pos doesn't match because parent should take care of emitting these comments if (node.parent) { if (node.parent.kind === SyntaxKind.SourceFile || node.pos !== node.parent.pos) { - let leadingComments: CommentRange[]; if (hasDetachedComments(node.pos)) { // get comments without detached comments - leadingComments = getLeadingCommentsWithoutDetachedComments(); + return getLeadingCommentsWithoutDetachedComments(); } else { // get the leading comments from the node - leadingComments = getLeadingCommentRangesOfNode(node, currentSourceFile); + return getLeadingCommentRangesOfNode(node, currentSourceFile); } - return leadingComments; } } } - function emitLeadingDeclarationComments(node: Node) { - let leadingComments = getLeadingCommentsToEmit(node); + function getTrailingCommentsToEmit(node: Node) { + // Emit the trailing comments only if the parent's pos doesn't match because parent should take care of emitting these comments + if (node.parent) { + if (node.parent.kind === SyntaxKind.SourceFile || node.end !== node.parent.end) { + return getTrailingCommentRanges(currentSourceFile.text, node.end); + } + } + } + + function emitOnlyPinnedOrTripleSlashComments(node: Node) { + emitLeadingCommentsWorker(node, /*onlyPinnedOrTripleSlashComments:*/ true); + } + + function emitLeadingComments(node: Node) { + return emitLeadingCommentsWorker(node, /*onlyPinnedOrTripleSlashComments:*/ compilerOptions.removeComments); + } + + function emitLeadingCommentsWorker(node: Node, onlyPinnedOrTripleSlashComments: boolean) { + // If the caller only wants pinned or triple slash comments, then always filter + // down to that set. Otherwise, filter based on the current compiler options. + let leadingComments = filterComments(getLeadingCommentsToEmit(node), onlyPinnedOrTripleSlashComments); + emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); + // Leading comments are emitted at /*leading comment1 */space/*leading comment*/space emitComments(currentSourceFile, writer, leadingComments, /*trailingSeparator*/ true, newLine, writeComment); } - function emitTrailingDeclarationComments(node: Node) { + function emitTrailingComments(node: Node) { // Emit the trailing comments only if the parent's end doesn't match - if (node.parent) { - if (node.parent.kind === SyntaxKind.SourceFile || node.end !== node.parent.end) { - let trailingComments = getTrailingCommentRanges(currentSourceFile.text, node.end); - // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/ - emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ false, newLine, writeComment); - } - } + var trailingComments = filterComments(getTrailingCommentsToEmit(node), /*onlyPinnedOrTripleSlashComments:*/ compilerOptions.removeComments); + + // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/ + emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ false, newLine, writeComment); } - function emitLeadingCommentsOfLocalPosition(pos: number) { + function emitLeadingCommentsOfPosition(pos: number) { let leadingComments: CommentRange[]; if (hasDetachedComments(pos)) { // get comments without detached comments @@ -5645,12 +4989,15 @@ module ts { // get the leading comments from the node leadingComments = getLeadingCommentRanges(currentSourceFile.text, pos); } + + leadingComments = filterComments(leadingComments, compilerOptions.removeComments); emitNewLineBeforeLeadingComments(currentSourceFile, writer, { pos: pos, end: pos }, leadingComments); + // Leading comments are emitted at /*leading comment1 */space/*leading comment*/space emitComments(currentSourceFile, writer, leadingComments, /*trailingSeparator*/ true, newLine, writeComment); } - function emitDetachedCommentsAtPosition(node: TextRange) { + function emitDetachedComments(node: TextRange) { let leadingComments = getLeadingCommentRanges(currentSourceFile.text, node.pos); if (leadingComments) { let detachedComments: CommentRange[] = []; @@ -5695,47 +5042,18 @@ module ts { } } - /** Emits /// or pinned which is comment starting with /*! comments */ - function emitPinnedOrTripleSlashComments(node: Node) { - let pinnedComments = ts.filter(getLeadingCommentsToEmit(node), isPinnedOrTripleSlashComment); - - function isPinnedOrTripleSlashComment(comment: CommentRange) { - if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) { - return currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.exclamation; - } - // Verify this is /// comment, but do the regexp match only when we first can find /// in the comment text - // so that we don't end up computing comment string and doing match for all // comments - else if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.slash && - comment.pos + 2 < comment.end && - currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.slash && - currentSourceFile.text.substring(comment.pos, comment.end).match(fullTripleSlashReferencePathRegEx)) { - return true; - } + function isPinnedOrTripleSlashComment(comment: CommentRange) { + if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) { + return currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.exclamation; + } + // Verify this is /// comment, but do the regexp match only when we first can find /// in the comment text + // so that we don't end up computing comment string and doing match for all // comments + else if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.slash && + comment.pos + 2 < comment.end && + currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.slash && + currentSourceFile.text.substring(comment.pos, comment.end).match(fullTripleSlashReferencePathRegEx)) { + return true; } - - emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, pinnedComments); - // Leading comments are emitted at /*leading comment1 */space/*leading comment*/space - emitComments(currentSourceFile, writer, pinnedComments, /*trailingSeparator*/ true, newLine, writeComment); - } - } - - function writeDeclarationFile(jsFilePath: string, sourceFile: SourceFile) { - let emitDeclarationResult = emitDeclarations(host, resolver, diagnostics, jsFilePath, sourceFile); - // TODO(shkamat): Should we not write any declaration file if any of them can produce error, - // or should we just not write this file like we are doing now - if (!emitDeclarationResult.reportedDeclarationError) { - let declarationOutput = emitDeclarationResult.referencePathsOutput; - // apply additions - let appliedSyncOutputPos = 0; - forEach(emitDeclarationResult.aliasDeclarationEmitInfo, aliasEmitInfo => { - if (aliasEmitInfo.asynchronousOutput) { - declarationOutput += emitDeclarationResult.synchronousDeclarationOutput.substring(appliedSyncOutputPos, aliasEmitInfo.outputPos); - declarationOutput += aliasEmitInfo.asynchronousOutput; - appliedSyncOutputPos = aliasEmitInfo.outputPos; - } - }); - declarationOutput += emitDeclarationResult.synchronousDeclarationOutput.substring(appliedSyncOutputPos); - writeFile(host, diagnostics, removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, compilerOptions.emitBOM); } } @@ -5743,7 +5061,7 @@ module ts { emitJavaScript(jsFilePath, sourceFile); if (compilerOptions.declaration) { - writeDeclarationFile(jsFilePath, sourceFile); + writeDeclarationFile(jsFilePath, sourceFile, host, resolver, diagnostics); } } } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 0031c7ebd22aa..14311ccbc52bc 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -8,7 +8,7 @@ module ts { export function getNodeConstructor(kind: SyntaxKind): new () => Node { return nodeConstructors[kind] || (nodeConstructors[kind] = objectAllocator.getNodeConstructor(kind)); } - + export function createNode(kind: SyntaxKind): Node { return new (getNodeConstructor(kind))(); } @@ -64,7 +64,8 @@ module ts { case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.VariableDeclaration: case SyntaxKind.BindingElement: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).propertyName) || visitNode(cbNode, (node).dotDotDotToken) || visitNode(cbNode, (node).name) || @@ -76,7 +77,8 @@ module ts { case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: case SyntaxKind.IndexSignature: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNodes(cbNodes, (node).typeParameters) || visitNodes(cbNodes, (node).parameters) || visitNode(cbNode, (node).type); @@ -88,13 +90,15 @@ module ts { case SyntaxKind.FunctionExpression: case SyntaxKind.FunctionDeclaration: case SyntaxKind.ArrowFunction: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).asteriskToken) || visitNode(cbNode, (node).name) || visitNode(cbNode, (node).questionToken) || visitNodes(cbNodes, (node).typeParameters) || visitNodes(cbNodes, (node).parameters) || visitNode(cbNode, (node).type) || + visitNode(cbNode, (node).equalsGreaterThanToken) || visitNode(cbNode, (node).body); case SyntaxKind.TypeReference: return visitNode(cbNode, (node).typeName) || @@ -170,7 +174,8 @@ module ts { return visitNodes(cbNodes, (node).statements) || visitNode(cbNode, (node).endOfFileToken); case SyntaxKind.VariableStatement: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).declarationList); case SyntaxKind.VariableDeclarationList: return visitNodes(cbNodes, (node).declarations); @@ -229,39 +234,48 @@ module ts { case SyntaxKind.CatchClause: return visitNode(cbNode, (node).variableDeclaration) || visitNode(cbNode, (node).block); + case SyntaxKind.Decorator: + return visitNode(cbNode, (node).expression); case SyntaxKind.ClassDeclaration: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).name) || visitNodes(cbNodes, (node).typeParameters) || visitNodes(cbNodes, (node).heritageClauses) || visitNodes(cbNodes, (node).members); case SyntaxKind.InterfaceDeclaration: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).name) || visitNodes(cbNodes, (node).typeParameters) || visitNodes(cbNodes, (node).heritageClauses) || visitNodes(cbNodes, (node).members); case SyntaxKind.TypeAliasDeclaration: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).name) || visitNode(cbNode, (node).type); case SyntaxKind.EnumDeclaration: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).name) || visitNodes(cbNodes, (node).members); case SyntaxKind.EnumMember: return visitNode(cbNode, (node).name) || visitNode(cbNode, (node).initializer); case SyntaxKind.ModuleDeclaration: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).name) || visitNode(cbNode, (node).body); case SyntaxKind.ImportEqualsDeclaration: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).name) || visitNode(cbNode, (node).moduleReference); case SyntaxKind.ImportDeclaration: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).importClause) || visitNode(cbNode, (node).moduleSpecifier); case SyntaxKind.ImportClause: @@ -273,7 +287,8 @@ module ts { case SyntaxKind.NamedExports: return visitNodes(cbNodes, (node).elements); case SyntaxKind.ExportDeclaration: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).exportClause) || visitNode(cbNode, (node).moduleSpecifier); case SyntaxKind.ImportSpecifier: @@ -281,8 +296,10 @@ module ts { return visitNode(cbNode, (node).propertyName) || visitNode(cbNode, (node).name); case SyntaxKind.ExportAssignment: - return visitNodes(cbNodes, node.modifiers) || - visitNode(cbNode, (node).expression); + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || + visitNode(cbNode, (node).expression) || + visitNode(cbNode, (node).type); case SyntaxKind.TemplateExpression: return visitNode(cbNode, (node).head) || visitNodes(cbNodes, (node).templateSpans); case SyntaxKind.TemplateSpan: @@ -293,6 +310,8 @@ module ts { return visitNodes(cbNodes, (node).types); case SyntaxKind.ExternalModuleReference: return visitNode(cbNode, (node).expression); + case SyntaxKind.MissingDeclaration: + return visitNodes(cbNodes, node.decorators); } } @@ -369,7 +388,7 @@ module ts { function fixupParentReferences(sourceFile: SourceFile) { // normally parent references are set during binding. However, for clients that only need - // a syntax tree, and no semantic features, then the binding process is an unnecessary + // a syntax tree, and no semantic features, then the binding process is an unnecessary // overhead. This functions allows us to set all the parents, without all the expense of // binding. @@ -379,7 +398,7 @@ module ts { function visitNode(n: Node): void { // walk down setting parents that differ from the parent we think it should be. This - // allows us to quickly bail out of setting parents for subtrees during incremental + // allows us to quickly bail out of setting parents for subtrees during incremental // parsing if (n.parent !== parent) { n.parent = parent; @@ -417,7 +436,7 @@ module ts { var text = oldText.substring(node.pos, node.end); } - // Ditch any existing LS children we may have created. This way we can avoid + // Ditch any existing LS children we may have created. This way we can avoid // moving them forward. node._children = undefined; node.pos += delta; @@ -455,9 +474,9 @@ module ts { // We may need to update both the 'pos' and the 'end' of the element. - // If the 'pos' is before the start of the change, then we don't need to touch it. - // If it isn't, then the 'pos' must be inside the change. How we update it will - // depend if delta is positive or negative. If delta is positive then we have + // If the 'pos' is before the start of the change, then we don't need to touch it. + // If it isn't, then the 'pos' must be inside the change. How we update it will + // depend if delta is positive or negative. If delta is positive then we have // something like: // // -------------------AAA----------------- @@ -471,7 +490,7 @@ module ts { // -------------------XXXYYYYYYY----------------- // -------------------ZZZ----------------- // - // In this case, any element that started in the 'X' range will keep its position. + // In this case, any element that started in the 'X' range will keep its position. // However any element htat started after that will have their pos adjusted to be // at the end of the new range. i.e. any node that started in the 'Y' range will // be adjusted to have their start at the end of the 'Z' range. @@ -481,7 +500,7 @@ module ts { element.pos = Math.min(element.pos, changeRangeNewEnd); // If the 'end' is after the change range, then we always adjust it by the delta - // amount. However, if the end is in the change range, then how we adjust it + // amount. However, if the end is in the change range, then how we adjust it // will depend on if delta is positive or negative. If delta is positive then we // have something like: // @@ -496,7 +515,7 @@ module ts { // -------------------XXXYYYYYYY----------------- // -------------------ZZZ----------------- // - // In this case, any element that ended in the 'X' range will keep its position. + // In this case, any element that ended in the 'X' range will keep its position. // However any element htat ended after that will have their pos adjusted to be // at the end of the new range. i.e. any node that ended in the 'Y' range will // be adjusted to have their end at the end of the 'Z' range. @@ -505,7 +524,7 @@ module ts { element.end += delta; } else { - // Element ends in the change range. The element will keep its position if + // Element ends in the change range. The element will keep its position if // possible. Or Move backward to the new-end if it's in the 'Y' range. element.end = Math.min(element.end, changeRangeNewEnd); } @@ -544,7 +563,7 @@ module ts { function visitNode(child: IncrementalNode) { Debug.assert(child.pos <= child.end); if (child.pos > changeRangeOldEnd) { - // Node is entirely past the change range. We need to move both its pos and + // Node is entirely past the change range. We need to move both its pos and // end, forward or backward appropriately. moveElementEntirelyPastChangeRange(child, /*isArray:*/ false, delta, oldText, newText, aggressiveChecks); return; @@ -607,10 +626,10 @@ module ts { // If the text changes with an insertion of / just before the semicolon then we end up with: // void foo() { //; } // - // If we were to just use the changeRange a is, then we would not rescan the { token + // If we were to just use the changeRange a is, then we would not rescan the { token // (as it does not intersect the actual original change range). Because an edit may // change the token touching it, we actually need to look back *at least* one token so - // that the prior token sees that change. + // that the prior token sees that change. let maxLookahead = 1; let start = changeRange.span.start; @@ -676,7 +695,7 @@ module ts { return; } - // If the child intersects this position, then this node is currently the nearest + // If the child intersects this position, then this node is currently the nearest // node that starts before the position. if (child.pos <= position) { if (child.pos >= bestResult.pos) { @@ -687,7 +706,7 @@ module ts { // Now, the node may overlap the position, or it may end entirely before the // position. If it overlaps with the position, then either it, or one of its - // children must be the nearest node before the position. So we can just + // children must be the nearest node before the position. So we can just // recurse into this child to see if we can find something better. if (position < child.end) { // The nearest node is either this child, or one of the children inside @@ -703,15 +722,15 @@ module ts { Debug.assert(child.end <= position); // The child ends entirely before this position. Say you have the following // (where $ is the position) - // - // ? $ : <...> <...> // - // We would want to find the nearest preceding node in "complex expr 2". + // ? $ : <...> <...> + // + // We would want to find the nearest preceding node in "complex expr 2". // To support that, we keep track of this node, and once we're done searching // for a best node, we recurse down this node to see if we can find a good // result in it. // - // This approach allows us to quickly skip over nodes that are entirely + // This approach allows us to quickly skip over nodes that are entirely // before the position, while still allowing us to find any nodes in the // last one that might be what we want. lastNodeEntirelyBeforePosition = child; @@ -744,13 +763,13 @@ module ts { } } - // Produces a new SourceFile for the 'newText' provided. The 'textChangeRange' parameter + // Produces a new SourceFile for the 'newText' provided. The 'textChangeRange' parameter // indicates what changed between the 'text' that this SourceFile has and the 'newText'. - // The SourceFile will be created with the compiler attempting to reuse as many nodes from + // The SourceFile will be created with the compiler attempting to reuse as many nodes from // this file as possible. // // Note: this function mutates nodes from this SourceFile. That means any existing nodes - // from this SourceFile that are being held onto may change as a result (including + // from this SourceFile that are being held onto may change as a result (including // becoming detached from any SourceFile). It is recommended that this SourceFile not // be used once 'update' is called on it. export function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile { @@ -769,7 +788,7 @@ module ts { } // Make sure we're not trying to incrementally update a source file more than once. Once - // we do an update the original source file is considered unusbale from that point onwards. + // we do an update the original source file is considered unusbale from that point onwards. // // This is because we do incremental parsing in-place. i.e. we take nodes from the old // tree and give them new positions and parents. From that point on, trusting the old @@ -781,24 +800,24 @@ module ts { let oldText = sourceFile.text; let syntaxCursor = createSyntaxCursor(sourceFile); - // Make the actual change larger so that we know to reparse anything whose lookahead + // Make the actual change larger so that we know to reparse anything whose lookahead // might have intersected the change. let changeRange = extendToAffectedRange(sourceFile, textChangeRange); checkChangeRange(sourceFile, newText, changeRange, aggressiveChecks); - // Ensure that extending the affected range only moved the start of the change range + // Ensure that extending the affected range only moved the start of the change range // earlier in the file. Debug.assert(changeRange.span.start <= textChangeRange.span.start); Debug.assert(textSpanEnd(changeRange.span) === textSpanEnd(textChangeRange.span)); Debug.assert(textSpanEnd(textChangeRangeNewSpan(changeRange)) === textSpanEnd(textChangeRangeNewSpan(textChangeRange))); - // The is the amount the nodes after the edit range need to be adjusted. It can be + // The is the amount the nodes after the edit range need to be adjusted. It can be // positive (if the edit added characters), negative (if the edit deleted characters) // or zero (if this was a pure overwrite with nothing added/removed). let delta = textChangeRangeNewSpan(changeRange).length - changeRange.span.length; // If we added or removed characters during the edit, then we need to go and adjust all - // the nodes after the edit. Those nodes may move forward (if we inserted chars) or they + // the nodes after the edit. Those nodes may move forward (if we inserted chars) or they // may move backward (if we deleted chars). // // Doing this helps us out in two ways. First, it means that any nodes/tokens we want @@ -811,7 +830,7 @@ module ts { // // We will also adjust the positions of nodes that intersect the change range as well. // By doing this, we ensure that all the positions in the old tree are consistent, not - // just the positions of nodes entirely before/after the change range. By being + // just the positions of nodes entirely before/after the change range. By being // consistent, we can then easily map from positions to nodes in the old tree easily. // // Also, mark any syntax elements that intersect the changed span. We know, up front, @@ -822,14 +841,14 @@ module ts { // Now that we've set up our internal incremental state just proceed and parse the // source file in the normal fashion. When possible the parser will retrieve and // reuse nodes from the old tree. - // + // // Note: passing in 'true' for setNodeParents is very important. When incrementally // parsing, we will be reusing nodes from the old tree, and placing it into new - // parents. If we don't set the parents now, we'll end up with an observably - // inconsistent tree. Setting the parents on the new tree should be very fast. We + // parents. If we don't set the parents now, we'll end up with an observably + // inconsistent tree. Setting the parents on the new tree should be very fast. We // will immediately bail out of walking any subtrees when we can see that their parents // are already correct. - let result = parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, syntaxCursor, /* setParentNode */ true) + let result = parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, syntaxCursor, /* setParentNode */ true) return result; } @@ -885,13 +904,13 @@ module ts { return { currentNode(position: number) { - // Only compute the current node if the position is different than the last time - // we were asked. The parser commonly asks for the node at the same position + // Only compute the current node if the position is different than the last time + // we were asked. The parser commonly asks for the node at the same position // twice. Once to know if can read an appropriate list element at a certain point, // and then to actually read and consume the node. if (position !== lastQueriedPosition) { - // Much of the time the parser will need the very next node in the array that - // we just returned a node from.So just simply check for that case and move + // Much of the time the parser will need the very next node in the array that + // we just returned a node from.So just simply check for that case and move // forward in the array instead of searching for the node again. if (current && current.end === position && currentArrayIndex < (currentArray.length - 1)) { currentArrayIndex++; @@ -905,7 +924,7 @@ module ts { } } - // Cache this query so that we don't do any extra work if the parser calls back + // Cache this query so that we don't do any extra work if the parser calls back // into us. Note: this is very common as the parser will make pairs of calls like // 'isListElement -> parseListElement'. If we were unable to find a node when // called with 'isListElement', we don't want to redo the work when parseListElement @@ -917,7 +936,7 @@ module ts { return current; } }; - + // Finds the highest element in the tree we can find that starts at the provided position. // The element must be a direct child of some node list in the tree. This way after we // return it, we can easily return its next sibling in the list. @@ -960,7 +979,7 @@ module ts { } else { if (child.pos < position && position < child.end) { - // Position in somewhere within this child. Search in it and + // Position in somewhere within this child. Search in it and // stop searching in this array. forEachChild(child, visitNode, visitArray); return true; @@ -985,6 +1004,8 @@ module ts { } function parseSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, syntaxCursor: SyntaxCursor, setParentNodes = false): SourceFile { + const disallowInAndDecoratorContext = ParserContextFlags.DisallowIn | ParserContextFlags.Decorator; + let parsingContext: ParsingContext = 0; let identifiers: Map = {}; let identifierCount = 0; @@ -1007,10 +1028,10 @@ module ts { // Whether or not we are in strict parsing mode. All that changes in strict parsing mode is // that some tokens that would be considered identifiers may be considered keywords. // - // When adding more parser context flags, consider which is the more common case that the + // When adding more parser context flags, consider which is the more common case that the // flag will be in. This should be hte 'false' state for that flag. The reason for this is // that we don't store data in our nodes unless the value is in the *non-default* state. So, - // for example, more often than code 'allows-in' (or doesn't 'disallow-in'). We opt for + // for example, more often than code 'allows-in' (or doesn't 'disallow-in'). We opt for // 'disallow-in' set to 'false'. Otherwise, if we had 'allowsIn' set to 'true', then almost // all nodes would need extra state on them to store this info. // @@ -1030,20 +1051,20 @@ module ts { // EqualityExpression[?In, ?Yield] === RelationalExpression[?In, ?Yield] // EqualityExpression[?In, ?Yield] !== RelationalExpression[?In, ?Yield] // - // Where you have to be careful is then understanding what the points are in the grammar + // Where you have to be careful is then understanding what the points are in the grammar // where the values are *not* passed along. For example: // // SingleNameBinding[Yield,GeneratorParameter] // [+GeneratorParameter]BindingIdentifier[Yield] Initializer[In]opt // [~GeneratorParameter]BindingIdentifier[?Yield]Initializer[In, ?Yield]opt // - // Here this is saying that if the GeneratorParameter context flag is set, that we should + // Here this is saying that if the GeneratorParameter context flag is set, that we should // explicitly set the 'yield' context flag to false before calling into the BindingIdentifier // and we should explicitly unset the 'yield' context flag before calling into the Initializer. - // production. Conversely, if the GeneratorParameter context flag is not set, then we + // production. Conversely, if the GeneratorParameter context flag is not set, then we // should leave the 'yield' context flag alone. // - // Getting this all correct is tricky and requires careful reading of the grammar to + // Getting this all correct is tricky and requires careful reading of the grammar to // understand when these values should be changed versus when they should be inherited. // // Note: it should not be necessary to save/restore these flags during speculative/lookahead @@ -1051,7 +1072,7 @@ module ts { // descent parsing and unwinding. let contextFlags: ParserContextFlags = 0; - // Whether or not we've had a parse error since creating the last AST node. If we have + // Whether or not we've had a parse error since creating the last AST node. If we have // encountered an error, it will be stored on the next AST node we create. Parse errors // can be broken down into three categories: // @@ -1062,7 +1083,7 @@ module ts { // by the 'parseExpected' function. // // 3) A token was present that no parsing function was able to consume. This type of error - // only occurs in the 'abortParsingListOrMoveToNextToken' function when the parser + // only occurs in the 'abortParsingListOrMoveToNextToken' function when the parser // decides to skip the token. // // In all of these cases, we want to mark the next node as having had an error before it. @@ -1071,8 +1092,8 @@ module ts { // node. in that event we would then not produce the same errors as we did before, causing // significant confusion problems. // - // Note: it is necessary that this value be saved/restored during speculative/lookahead - // parsing. During lookahead parsing, we will often create a node. That node will have + // Note: it is necessary that this value be saved/restored during speculative/lookahead + // parsing. During lookahead parsing, we will often create a node. That node will have // this value attached, and then this value will be set back to 'false'. If we decide to // rewind, we must get back to the same value we had prior to the lookahead. // @@ -1128,6 +1149,23 @@ module ts { setContextFlag(val, ParserContextFlags.GeneratorParameter); } + function setDecoratorContext(val: boolean) { + setContextFlag(val, ParserContextFlags.Decorator); + } + + function doOutsideOfContext(flags: ParserContextFlags, func: () => T): T { + let currentContextFlags = contextFlags & flags; + if (currentContextFlags) { + setContextFlag(false, currentContextFlags); + let result = func(); + setContextFlag(true, currentContextFlags); + return result; + } + + // no need to do anything special as we are not in any of the requested contexts + return func(); + } + function allowInAnd(func: () => T): T { if (contextFlags & ParserContextFlags.DisallowIn) { setDisallowInContext(false); @@ -1135,7 +1173,7 @@ module ts { setDisallowInContext(true); return result; } - + // no need to do anything special if 'in' is already allowed. return func(); } @@ -1176,6 +1214,18 @@ module ts { return func(); } + function doInDecoratorContext(func: () => T): T { + if (contextFlags & ParserContextFlags.Decorator) { + // no need to do anything special if we're already in the [Decorator] context. + return func(); + } + + setDecoratorContext(true); + let result = func(); + setDecoratorContext(false); + return result; + } + function inYieldContext() { return (contextFlags & ParserContextFlags.Yield) !== 0; } @@ -1192,6 +1242,10 @@ module ts { return (contextFlags & ParserContextFlags.DisallowIn) !== 0; } + function inDecoratorContext() { + return (contextFlags & ParserContextFlags.Decorator) !== 0; + } + function parseErrorAtCurrentToken(message: DiagnosticMessage, arg0?: any): void { let start = scanner.getTokenPos(); let length = scanner.getTextPos() - start; @@ -1206,7 +1260,7 @@ module ts { sourceFile.parseDiagnostics.push(createFileDiagnostic(sourceFile, start, length, message, arg0)); } - // Mark that we've encountered an error. We'll set an appropriate bit on the next + // Mark that we've encountered an error. We'll set an appropriate bit on the next // node we finish so that it can't be reused incrementally. parseErrorBeforeNextFinishedNode = true; } @@ -1245,7 +1299,7 @@ module ts { } function speculationHelper(callback: () => T, isLookAhead: boolean): T { - // Keep track of the state we'll need to rollback to if lookahead fails (or if the + // Keep track of the state we'll need to rollback to if lookahead fails (or if the // caller asked us to always reset our state). let saveToken = token; let saveParseDiagnosticsLength = sourceFile.parseDiagnostics.length; @@ -1253,13 +1307,13 @@ module ts { // Note: it is not actually necessary to save/restore the context flags here. That's // because the saving/restorating of these flags happens naturally through the recursive - // descent nature of our parser. However, we still store this here just so we can + // descent nature of our parser. However, we still store this here just so we can // assert that that invariant holds. let saveContextFlags = contextFlags; // If we're only looking ahead, then tell the scanner to only lookahead as well. - // Otherwise, if we're actually speculatively parsing, then tell the scanner to do the - // same. + // Otherwise, if we're actually speculatively parsing, then tell the scanner to do the + // same. let result = isLookAhead ? scanner.lookAhead(callback) : scanner.tryScan(callback); @@ -1277,15 +1331,15 @@ module ts { return result; } - // Invokes the provided callback then unconditionally restores the parser to the state it + // Invokes the provided callback then unconditionally restores the parser to the state it // was in immediately prior to invoking the callback. The result of invoking the callback // is returned from this function. function lookAhead(callback: () => T): T { return speculationHelper(callback, /*isLookAhead:*/ true); } - + // Invokes the provided callback. If the callback returns something falsy, then it restores - // the parser to the state it was in immediately prior to invoking the callback. If the + // the parser to the state it was in immediately prior to invoking the callback. If the // callback returns something truthy, then the parser state is not rolled back. The result // of invoking the callback is returned from this function. function tryParse(callback: () => T): T { @@ -1296,8 +1350,8 @@ module ts { if (token === SyntaxKind.Identifier) { return true; } - - // If we have a 'yield' keyword, and we're in the [yield] context, then 'yield' is + + // If we have a 'yield' keyword, and we're in the [yield] context, then 'yield' is // considered a keyword and is not an identifier. if (token === SyntaxKind.YieldKeyword && inYieldContext()) { return false; @@ -1401,7 +1455,7 @@ module ts { return node; } - + function createMissingNode(kind: SyntaxKind, reportAtCurrentPosition: boolean, diagnosticMessage: DiagnosticMessage, arg0?: any): Node { if (reportAtCurrentPosition) { parseErrorAtPosition(scanner.getStartPos(), 0, diagnosticMessage, arg0); @@ -1464,7 +1518,7 @@ module ts { // LiteralPropertyName // [+GeneratorParameter] ComputedPropertyName // [~GeneratorParameter] ComputedPropertyName[?Yield] - // + // // ComputedPropertyName[Yield] : // [ AssignmentExpression[In, ?Yield] ] // @@ -1648,13 +1702,13 @@ module ts { } function isVariableDeclaratorListTerminator(): boolean { - // If we can consume a semicolon (either explicitly, or with ASI), then consider us done + // If we can consume a semicolon (either explicitly, or with ASI), then consider us done // with parsing the list of variable declarators. if (canParseSemicolon()) { return true; } - // in the case where we're parsing the variable declarator of a 'for-in' statement, we + // in the case where we're parsing the variable declarator of a 'for-in' statement, we // are done if we see an 'in' keyword in front of us. Same with for-of if (isInOrOfKeyword(token)) { return true; @@ -1730,7 +1784,7 @@ module ts { if (node) { return consumeNode(node); } - + return parseElement(); } @@ -1738,9 +1792,9 @@ module ts { // If there is an outstanding parse error that we've encountered, but not attached to // some node, then we cannot get a node from the old source tree. This is because we // want to mark the next node we encounter as being unusable. - // + // // Note: This may be too conservative. Perhaps we could reuse hte node and set the bit - // on it (or its leftmost child) as having the error. For now though, being conservative + // on it (or its leftmost child) as having the error. For now though, being conservative // is nice and likely won't ever affect perf. if (parseErrorBeforeNextFinishedNode) { return undefined; @@ -1763,18 +1817,18 @@ module ts { return undefined; } - // Can't reuse a node that contains a parse error. This is necessary so that we + // Can't reuse a node that contains a parse error. This is necessary so that we // produce the same set of errors again. if (containsParseError(node)) { return undefined; } - // We can only reuse a node if it was parsed under the same strict mode that we're + // We can only reuse a node if it was parsed under the same strict mode that we're // currently in. i.e. if we originally parsed a node in non-strict mode, but then // the user added 'using strict' at the top of the file, then we can't use that node // again as the presense of strict mode may cause us to parse the tokens in the file // differetly. - // + // // Note: we *can* reuse tokens when the strict mode changes. That's because tokens // are unaffected by strict mode. It's just the parser will decide what to do with it // differently depending on what mode it is in. @@ -1828,32 +1882,32 @@ module ts { case ParsingContext.Parameters: return isReusableParameter(node); - // Any other lists we do not care about reusing nodes in. But feel free to add if + // Any other lists we do not care about reusing nodes in. But feel free to add if // you can do so safely. Danger areas involve nodes that may involve speculative // parsing. If speculative parsing is involved with the node, then the range the // parser reached while looking ahead might be in the edited range (see the example // in canReuseVariableDeclaratorNode for a good case of this). case ParsingContext.HeritageClauses: - // This would probably be safe to reuse. There is no speculative parsing with + // This would probably be safe to reuse. There is no speculative parsing with // heritage clauses. case ParsingContext.TypeReferences: - // This would probably be safe to reuse. There is no speculative parsing with + // This would probably be safe to reuse. There is no speculative parsing with // type names in a heritage clause. There can be generic names in the type - // name list. But because it is a type context, we never use speculative + // name list. But because it is a type context, we never use speculative // parsing on the type argument list. case ParsingContext.TypeParameters: - // This would probably be safe to reuse. There is no speculative parsing with + // This would probably be safe to reuse. There is no speculative parsing with // type parameters. Note that that's because type *parameters* only occur in // unambiguous *type* contexts. While type *arguments* occur in very ambiguous // *expression* contexts. case ParsingContext.TupleElementTypes: - // This would probably be safe to reuse. There is no speculative parsing with + // This would probably be safe to reuse. There is no speculative parsing with // tuple types. - // Technically, type argument list types are probably safe to reuse. While + // Technically, type argument list types are probably safe to reuse. While // speculative parsing is involved with them (since type argument lists are only // produced from speculative parsing a < as a type argument list), we only have // the types because speculative parsing succeeded. Thus, the lookahead never @@ -1861,12 +1915,12 @@ module ts { case ParsingContext.TypeArguments: // Note: these are almost certainly not safe to ever reuse. Expressions commonly - // need a large amount of lookahead, and we should not reuse them as they may + // need a large amount of lookahead, and we should not reuse them as they may // have actually intersected the edit. case ParsingContext.ArgumentExpressions: // This is not safe to reuse for the same reason as the 'AssignmentExpression' - // cases. i.e. a property assignment may end with an expression, and thus might + // cases. i.e. a property assignment may end with an expression, and thus might // have lookahead far beyond it's old node. case ParsingContext.ObjectLiteralMembers: } @@ -1980,11 +2034,11 @@ module ts { // // let v = new List < A, B // - // This is actually legal code. It's a list of variable declarators "v = new List() - // + // // then we have a problem. "v = new ListcreateMissingNode(SyntaxKind.Identifier, /*reportAtCurrentToken:*/ true, Diagnostics.Identifier_expected); } @@ -2185,7 +2239,7 @@ module ts { if (scanner.hasExtendedUnicodeEscape()) { node.hasExtendedUnicodeEscape = true; } - + if (scanner.isUnterminated()) { node.isUnterminated = true; } @@ -2193,7 +2247,7 @@ module ts { let tokenPos = scanner.getTokenPos(); nextToken(); finishNode(node); - + // Octal literals are not allowed in strict mode or ES5 // Note that theoretically the following condition would hold true literals like 009, // which is not octal.But because of how the scanner separates the tokens, we would @@ -2232,7 +2286,7 @@ module ts { let node = createNode(SyntaxKind.TypeParameter); node.name = parseIdentifier(); if (parseOptional(SyntaxKind.ExtendsKeyword)) { - // It's not uncommon for people to write improper constraints to a generic. If the + // It's not uncommon for people to write improper constraints to a generic. If the // user writes a constraint that is an expression and not an actual type, then parse // it out as an expression (so we can recover well), but report that a type is needed // instead. @@ -2271,7 +2325,7 @@ module ts { } function isStartOfParameter(): boolean { - return token === SyntaxKind.DotDotDotToken || isIdentifierOrPattern() || isModifier(token); + return token === SyntaxKind.DotDotDotToken || isIdentifierOrPattern() || isModifier(token) || token === SyntaxKind.AtToken; } function setModifiers(node: Node, modifiers: ModifiersArray) { @@ -2283,6 +2337,7 @@ module ts { function parseParameter(): ParameterDeclaration { let node = createNode(SyntaxKind.Parameter); + node.decorators = parseDecorators(); setModifiers(node, parseModifiers()); node.dotDotDotToken = parseOptionalToken(SyntaxKind.DotDotDotToken); @@ -2294,7 +2349,7 @@ module ts { if (getFullWidth(node.name) === 0 && node.flags === 0 && isModifier(token)) { // in cases like - // 'use strict' + // 'use strict' // function foo(static) // isParameter('static') === true, because of isModifier('static') // however 'static' is not a legal identifier in a strict mode. @@ -2341,7 +2396,7 @@ module ts { } } - // Note: after careful analysis of the grammar, it does not appear to be possible to + // Note: after careful analysis of the grammar, it does not appear to be possible to // have 'Yield' And 'GeneratorParameter' not in sync. i.e. any production calling // this FormalParameters production either always sets both to true, or always sets // both to false. As such we only have a single parameter to represent both. @@ -2388,7 +2443,7 @@ module ts { } function parseTypeMemberSemicolon() { - // We allow type members to be separated by commas or (possibly ASI) semicolons. + // We allow type members to be separated by commas or (possibly ASI) semicolons. // First check if it was a comma. If so, we're done with the member. if (parseOptional(SyntaxKind.CommaToken)) { return; @@ -2471,9 +2526,9 @@ module ts { return token === SyntaxKind.ColonToken || token === SyntaxKind.CommaToken || token === SyntaxKind.CloseBracketToken; } - function parseIndexSignatureDeclaration(modifiers: ModifiersArray): IndexSignatureDeclaration { - let fullStart = modifiers ? modifiers.pos : scanner.getStartPos(); + function parseIndexSignatureDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): IndexSignatureDeclaration { let node = createNode(SyntaxKind.IndexSignature, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); node.parameters = parseBracketedList(ParsingContext.Parameters, parseParameter, SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken); node.type = parseTypeAnnotation(); @@ -2550,7 +2605,7 @@ module ts { case SyntaxKind.OpenBracketToken: // Indexer or computed property return isIndexSignature() - ? parseIndexSignatureDeclaration(/*modifiers:*/ undefined) + ? parseIndexSignatureDeclaration(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers:*/ undefined) : parsePropertyOrMethodSignature(); case SyntaxKind.NewKeyword: if (lookAhead(isStartOfConstructSignature)) { @@ -2561,9 +2616,9 @@ module ts { case SyntaxKind.NumericLiteral: return parsePropertyOrMethodSignature(); default: - // Index declaration as allowed as a type member. But as per the grammar, + // Index declaration as allowed as a type member. But as per the grammar, // they also allow modifiers. So we have to check for an index declaration - // that might be following modifiers. This ensures that things work properly + // that might be following modifiers. This ensures that things work properly // when incrementally parsing as the parser will produce the Index declaration // if it has the same text regardless of whether it is inside a class or an // object type. @@ -2581,9 +2636,11 @@ module ts { } function parseIndexSignatureWithModifiers() { + let fullStart = scanner.getStartPos(); + let decorators = parseDecorators(); let modifiers = parseModifiers(); return isIndexSignature() - ? parseIndexSignatureDeclaration(modifiers) + ? parseIndexSignatureDeclaration(fullStart, decorators, modifiers) : undefined; } @@ -2839,19 +2896,29 @@ module ts { function isStartOfExpressionStatement(): boolean { // As per the grammar, neither '{' nor 'function' can start an expression statement. - return token !== SyntaxKind.OpenBraceToken && token !== SyntaxKind.FunctionKeyword && isStartOfExpression(); + return token !== SyntaxKind.OpenBraceToken && token !== SyntaxKind.FunctionKeyword && token !== SyntaxKind.AtToken && isStartOfExpression(); } function parseExpression(): Expression { // Expression[in]: - // AssignmentExpression[in] + // AssignmentExpression[in] // Expression[in] , AssignmentExpression[in] + // clear the decorator context when parsing Expression, as it should be unambiguous when parsing a decorator + let saveDecoratorContext = inDecoratorContext(); + if (saveDecoratorContext) { + setDecoratorContext(false); + } + let expr = parseAssignmentExpressionOrHigher(); let operatorToken: Node; while ((operatorToken = parseOptionalToken(SyntaxKind.CommaToken))) { expr = makeBinaryExpression(expr, operatorToken, parseAssignmentExpressionOrHigher()); } + + if (saveDecoratorContext) { + setDecoratorContext(true); + } return expr; } @@ -2860,13 +2927,13 @@ module ts { // It's not uncommon during typing for the user to miss writing the '=' token. Check if // there is no newline after the last token and if we're on an expression. If so, parse // this as an equals-value clause with a missing equals. - // NOTE: There are two places where we allow equals-value clauses. The first is in a + // NOTE: There are two places where we allow equals-value clauses. The first is in a // variable declarator. The second is with a parameter. For variable declarators // it's more likely that a { would be a allowed (as an object literal). While this // is also allowed for parameters, the risk is that we consume the { as an object // literal when it really will be for the block following the parameter. if (scanner.hasPrecedingLineBreak() || (inParameter && token === SyntaxKind.OpenBraceToken) || !isStartOfExpression()) { - // preceding line break, open brace in a parameter (likely a function body) or current token is not an expression - + // preceding line break, open brace in a parameter (likely a function body) or current token is not an expression - // do not try to parse initializer return undefined; } @@ -2887,17 +2954,17 @@ module ts { // 4) ArrowFunctionExpression[?in,?yield] // 5) [+Yield] YieldExpression[?In] // - // Note: for ease of implementation we treat productions '2' and '3' as the same thing. + // Note: for ease of implementation we treat productions '2' and '3' as the same thing. // (i.e. they're both BinaryExpressions with an assignment operator in it). // First, do the simple check if we have a YieldExpression (production '5'). if (isYieldExpression()) { return parseYieldExpression(); - } + } // Then, check if we have an arrow function (production '4') that starts with a parenthesized // parameter list. If we do, we must *not* recurse for productions 1, 2 or 3. An ArrowFunction is - // not a LeftHandSideExpression, nor does it start a ConditionalExpression. So we are done + // not a LeftHandSideExpression, nor does it start a ConditionalExpression. So we are done // with AssignmentExpression if we see one. let arrowExpression = tryParseParenthesizedArrowFunctionExpression(); if (arrowExpression) { @@ -2908,9 +2975,9 @@ module ts { // start with a LogicalOrExpression, while the assignment productions can only start with // LeftHandSideExpressions. // - // So, first, we try to just parse out a BinaryExpression. If we get something that is a - // LeftHandSide or higher, then we can try to parse out the assignment expression part. - // Otherwise, we try to parse out the conditional expression bit. We want to allow any + // So, first, we try to just parse out a BinaryExpression. If we get something that is a + // LeftHandSide or higher, then we can try to parse out the assignment expression part. + // Otherwise, we try to parse out the conditional expression bit. We want to allow any // binary expression here, so we pass in the 'lowest' precedence here so that it matches // and consumes anything. let expr = parseBinaryExpressionOrHigher(/*precedence:*/ 0); @@ -2923,7 +2990,7 @@ module ts { } // Now see if we might be in cases '2' or '3'. - // If the expression was a LHS expression, and we have an assignment operator, then + // If the expression was a LHS expression, and we have an assignment operator, then // we're in '2' or '3'. Consume the assignment and return. // // Note: we call reScanGreaterToken so that we get an appropriately merged token @@ -2938,7 +3005,7 @@ module ts { function isYieldExpression(): boolean { if (token === SyntaxKind.YieldKeyword) { - // If we have a 'yield' keyword, and htis is a context where yield expressions are + // If we have a 'yield' keyword, and htis is a context where yield expressions are // allowed, then definitely parse out a yield expression. if (inYieldContext()) { return true; @@ -2953,12 +3020,12 @@ module ts { // We're in a context where 'yield expr' is not allowed. However, if we can // definitely tell that the user was trying to parse a 'yield expr' and not // just a normal expr that start with a 'yield' identifier, then parse out - // a 'yield expr'. We can then report an error later that they are only + // a 'yield expr'. We can then report an error later that they are only // allowed in generator expressions. - // + // // for example, if we see 'yield(foo)', then we'll have to treat that as an // invocation expression of something called 'yield'. However, if we have - // 'yield foo' then that is not legal as a normal expression, so we can + // 'yield foo' then that is not legal as a normal expression, so we can // definitely recognize this as a yield expression. // // for now we just check if the next token is an identifier. More heuristics @@ -2997,7 +3064,7 @@ module ts { return finishNode(node); } else { - // if the next token is not on the same line as yield. or we don't have an '*' or + // if the next token is not on the same line as yield. or we don't have an '*' or // the start of an expressin, then this is just a simple "yield" expression. return finishNode(node); } @@ -3006,7 +3073,7 @@ module ts { function parseSimpleArrowFunctionExpression(identifier: Identifier): Expression { Debug.assert(token === SyntaxKind.EqualsGreaterThanToken, "parseSimpleArrowFunctionExpression should only have been called if we had a =>"); - let node = createNode(SyntaxKind.ArrowFunction, identifier.pos); + let node = createNode(SyntaxKind.ArrowFunction, identifier.pos); let parameter = createNode(SyntaxKind.Parameter, identifier.pos); parameter.name = identifier; @@ -3016,7 +3083,7 @@ module ts { node.parameters.pos = parameter.pos; node.parameters.end = parameter.end; - parseExpected(SyntaxKind.EqualsGreaterThanToken); + node.equalsGreaterThanToken = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken, false, Diagnostics._0_expected, "=>"); node.body = parseArrowFunctionExpressionBody(); return finishNode(node); @@ -3043,15 +3110,13 @@ module ts { return undefined; } - // If we have an arrow, then try to parse the body. Even if not, try to parse if we + // If we have an arrow, then try to parse the body. Even if not, try to parse if we // have an opening brace, just in case we're in an error state. - if (parseExpected(SyntaxKind.EqualsGreaterThanToken) || token === SyntaxKind.OpenBraceToken) { - arrowFunction.body = parseArrowFunctionExpressionBody(); - } - else { - // If not, we're probably better off bailing out and returning a bogus function expression. - arrowFunction.body = parseIdentifier(); - } + var lastToken = token; + arrowFunction.equalsGreaterThanToken = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken, /*reportAtCurrentPosition:*/false, Diagnostics._0_expected, "=>"); + arrowFunction.body = (lastToken === SyntaxKind.EqualsGreaterThanToken || lastToken === SyntaxKind.OpenBraceToken) + ? parseArrowFunctionExpressionBody() + : parseIdentifier(); return finishNode(arrowFunction); } @@ -3135,18 +3200,18 @@ module ts { } } - function parsePossibleParenthesizedArrowFunctionExpressionHead() { + function parsePossibleParenthesizedArrowFunctionExpressionHead(): ArrowFunction { return parseParenthesizedArrowFunctionExpressionHead(/*allowAmbiguity:*/ false); } - function parseParenthesizedArrowFunctionExpressionHead(allowAmbiguity: boolean): FunctionExpression { - let node = createNode(SyntaxKind.ArrowFunction); + function parseParenthesizedArrowFunctionExpressionHead(allowAmbiguity: boolean): ArrowFunction { + let node = createNode(SyntaxKind.ArrowFunction); // Arrow functions are never generators. // // If we're speculatively parsing a signature for a parenthesized arrow function, then // we have to have a complete parameter list. Otherwise we might see something like // a => (b => c) - // And think that "(b =>" was actually a parenthesized arrow function with a missing + // And think that "(b =>" was actually a parenthesized arrow function with a missing // close paren. fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ false, /*requireCompleteParameterList:*/ !allowAmbiguity, node); @@ -3179,7 +3244,7 @@ module ts { if (isStartOfStatement(/*inErrorRecovery:*/ true) && !isStartOfExpressionStatement() && token !== SyntaxKind.FunctionKeyword) { // Check if we got a plain statement (i.e. no expression-statements, no functions expressions/declarations) // - // Here we try to recover from a potential error situation in the case where the + // Here we try to recover from a potential error situation in the case where the // user meant to supply a block. For example, if the user wrote: // // a => @@ -3204,12 +3269,12 @@ module ts { return leftOperand; } - // Note: we explicitly 'allowIn' in the whenTrue part of the condition expression, and - // we do not that for the 'whenFalse' part. + // Note: we explicitly 'allowIn' in the whenTrue part of the condition expression, and + // we do not that for the 'whenFalse' part. let node = createNode(SyntaxKind.ConditionalExpression, leftOperand.pos); node.condition = leftOperand; node.questionToken = questionToken; - node.whenTrue = allowInAnd(parseAssignmentExpressionOrHigher); + node.whenTrue = doOutsideOfContext(disallowInAndDecoratorContext, parseAssignmentExpressionOrHigher); node.colonToken = parseExpectedToken(SyntaxKind.ColonToken, /*reportAtCurrentPosition:*/ false, Diagnostics._0_expected, tokenToString(SyntaxKind.ColonToken)); node.whenFalse = parseAssignmentExpressionOrHigher(); @@ -3227,7 +3292,7 @@ module ts { function parseBinaryExpressionRest(precedence: number, leftOperand: Expression): Expression { while (true) { - // We either have a binary operator here, or we're finished. We call + // We either have a binary operator here, or we're finished. We call // reScanGreaterToken so that we merge token sequences like > and = into >= reScanGreaterToken(); @@ -3374,15 +3439,15 @@ module ts { function parseLeftHandSideExpressionOrHigher(): LeftHandSideExpression { // Original Ecma: - // LeftHandSideExpression: See 11.2 + // LeftHandSideExpression: See 11.2 // NewExpression - // CallExpression + // CallExpression // // Our simplification: // - // LeftHandSideExpression: See 11.2 - // MemberExpression - // CallExpression + // LeftHandSideExpression: See 11.2 + // MemberExpression + // CallExpression // // See comment in parseMemberExpressionOrHigher on how we replaced NewExpression with // MemberExpression to make our lives easier. @@ -3391,14 +3456,14 @@ module ts { // out into its own productions: // // CallExpression: - // MemberExpression Arguments + // MemberExpression Arguments // CallExpression Arguments // CallExpression[Expression] // CallExpression.IdentifierName // super ( ArgumentListopt ) // super.IdentifierName // - // Because of the recursion in these calls, we need to bottom out first. There are two + // Because of the recursion in these calls, we need to bottom out first. There are two // bottom out states we can run into. Either we see 'super' which must start either of // the last two CallExpression productions. Or we have a MemberExpression which either // completes the LeftHandSideExpression, or starts the beginning of the first four @@ -3407,7 +3472,7 @@ module ts { ? parseSuperExpression() : parseMemberExpressionOrHigher(); - // Now, we *may* be complete. However, we might have consumed the start of a + // Now, we *may* be complete. However, we might have consumed the start of a // CallExpression. As such, we need to consume the rest of it here to be complete. return parseCallExpressionRest(expression); } @@ -3417,39 +3482,39 @@ module ts { // place ObjectCreationExpression and FunctionExpression into PrimaryExpression. // like so: // - // PrimaryExpression : See 11.1 + // PrimaryExpression : See 11.1 // this // Identifier // Literal // ArrayLiteral // ObjectLiteral - // (Expression) + // (Expression) // FunctionExpression // new MemberExpression Arguments? // - // MemberExpression : See 11.2 - // PrimaryExpression + // MemberExpression : See 11.2 + // PrimaryExpression // MemberExpression[Expression] // MemberExpression.IdentifierName // - // CallExpression : See 11.2 - // MemberExpression + // CallExpression : See 11.2 + // MemberExpression // CallExpression Arguments // CallExpression[Expression] - // CallExpression.IdentifierName + // CallExpression.IdentifierName // // Technically this is ambiguous. i.e. CallExpression defines: // // CallExpression: // CallExpression Arguments - // + // // If you see: "new Foo()" // - // Then that could be treated as a single ObjectCreationExpression, or it could be + // Then that could be treated as a single ObjectCreationExpression, or it could be // treated as the invocation of "new Foo". We disambiguate that in code (to match // the original grammar) by making sure that if we see an ObjectCreationExpression // we always consume arguments if they are there. So we treat "new Foo()" as an - // object creation only, and not at all as an invocation) Another way to think + // object creation only, and not at all as an invocation) Another way to think // about this is that for every "new" that we see, we will consume an argument list if // it is there as part of the *associated* object creation node. Any additional // argument lists we see, will become invocation expressions. @@ -3500,7 +3565,8 @@ module ts { continue; } - if (parseOptional(SyntaxKind.OpenBracketToken)) { + // when in the [Decorator] context, we do not parse ElementAccess as it could be part of a ComputedPropertyName + if (!inDecoratorContext() && parseOptional(SyntaxKind.OpenBracketToken)) { let indexedAccess = createNode(SyntaxKind.ElementAccessExpression, expression.pos); indexedAccess.expression = expression; @@ -3536,10 +3602,9 @@ module ts { function parseCallExpressionRest(expression: LeftHandSideExpression): LeftHandSideExpression { while (true) { expression = parseMemberExpressionRest(expression); - if (token === SyntaxKind.LessThanToken) { // See if this is the start of a generic invocation. If so, consume it and - // keep checking for postfix expressions. Otherwise, it's just a '<' that's + // keep checking for postfix expressions. Otherwise, it's just a '<' that's // part of an arithmetic expression. Break out so we consume it higher in the // stack. let typeArguments = tryParse(parseTypeArgumentsInExpression); @@ -3593,8 +3658,8 @@ module ts { function canFollowTypeArgumentsInExpression(): boolean { switch (token) { - case SyntaxKind.OpenParenToken: // foo( - // this case are the only case where this token can legally follow a type argument + case SyntaxKind.OpenParenToken: // foo( + // this case are the only case where this token can legally follow a type argument // list. So we definitely want to treat this as a type arg list. case SyntaxKind.DotToken: // foo. @@ -3615,7 +3680,7 @@ module ts { case SyntaxKind.BarToken: // foo | case SyntaxKind.CloseBraceToken: // foo } case SyntaxKind.EndOfFileToken: // foo - // these cases can't legally follow a type arg list. However, they're not legal + // these cases can't legally follow a type arg list. However, they're not legal // expressions either. The user is probably in the middle of a generic type. So // treat it as such. return true; @@ -3683,7 +3748,7 @@ module ts { } function parseArgumentExpression(): Expression { - return allowInAnd(parseArgumentOrArrayLiteralElement); + return doOutsideOfContext(disallowInAndDecoratorContext, parseArgumentOrArrayLiteralElement); } function parseArrayLiteralExpression(): ArrayLiteralExpression { @@ -3695,12 +3760,12 @@ module ts { return finishNode(node); } - function tryParseAccessorDeclaration(fullStart: number, modifiers: ModifiersArray): AccessorDeclaration { + function tryParseAccessorDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): AccessorDeclaration { if (parseContextualModifier(SyntaxKind.GetKeyword)) { - return parseAccessorDeclaration(SyntaxKind.GetAccessor, fullStart, modifiers); + return parseAccessorDeclaration(SyntaxKind.GetAccessor, fullStart, decorators, modifiers); } else if (parseContextualModifier(SyntaxKind.SetKeyword)) { - return parseAccessorDeclaration(SyntaxKind.SetAccessor, fullStart, modifiers); + return parseAccessorDeclaration(SyntaxKind.SetAccessor, fullStart, decorators, modifiers); } return undefined; @@ -3708,9 +3773,10 @@ module ts { function parseObjectLiteralElement(): ObjectLiteralElement { let fullStart = scanner.getStartPos(); + let decorators = parseDecorators(); let modifiers = parseModifiers(); - let accessor = tryParseAccessorDeclaration(fullStart, modifiers); + let accessor = tryParseAccessorDeclaration(fullStart, decorators, modifiers); if (accessor) { return accessor; } @@ -3723,7 +3789,7 @@ module ts { // Disallowing of optional property assignments happens in the grammar checker. let questionToken = parseOptionalToken(SyntaxKind.QuestionToken); if (asteriskToken || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { - return parseMethodDeclaration(fullStart, modifiers, asteriskToken, propertyName, questionToken); + return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, propertyName, questionToken); } // Parse to check if it is short-hand property assignment or normal property assignment @@ -3760,12 +3826,19 @@ module ts { // function * BindingIdentifier[Yield]opt (FormalParameters[Yield, GeneratorParameter]) { GeneratorBody[Yield] } // FunctionExpression: // function BindingIdentifieropt(FormalParameters) { FunctionBody } + let saveDecoratorContext = inDecoratorContext(); + if (saveDecoratorContext) { + setDecoratorContext(false); + } let node = createNode(SyntaxKind.FunctionExpression); parseExpected(SyntaxKind.FunctionKeyword); node.asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); node.name = node.asteriskToken ? doInYieldContext(parseOptionalIdentifier) : parseOptionalIdentifier(); fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ !!node.asteriskToken, /*requireCompleteParameterList:*/ false, node); node.body = parseFunctionBlock(/*allowYield:*/ !!node.asteriskToken, /* ignoreMissingOpenBrace */ false); + if (saveDecoratorContext) { + setDecoratorContext(true); + } return finishNode(node); } @@ -3802,8 +3875,19 @@ module ts { let savedYieldContext = inYieldContext(); setYieldContext(allowYield); + // We may be in a [Decorator] context when parsing a function expression or + // arrow function. The body of the function is not in [Decorator] context. + let saveDecoratorContext = inDecoratorContext(); + if (saveDecoratorContext) { + setDecoratorContext(false); + } + let block = parseBlock(ignoreMissingOpenBrace, /*checkForStrictMode*/ true, diagnosticMessage); + if (saveDecoratorContext) { + setDecoratorContext(true); + } + setYieldContext(savedYieldContext); return block; @@ -3836,7 +3920,7 @@ module ts { parseExpected(SyntaxKind.CloseParenToken); // From: https://mail.mozilla.org/pipermail/es-discuss/2011-August/016188.html - // 157 min --- All allen at wirfs-brock.com CONF --- "do{;}while(false)false" prohibited in + // 157 min --- All allen at wirfs-brock.com CONF --- "do{;}while(false)false" prohibited in // spec but allowed in consensus reality. Approved -- this is the de-facto standard whereby // do;while(0)x will have a semicolon inserted before x. parseOptional(SyntaxKind.SemicolonToken); @@ -3974,9 +4058,9 @@ module ts { // ThrowStatement[Yield] : // throw [no LineTerminator here]Expression[In, ?Yield]; - // Because of automatic semicolon insertion, we need to report error if this + // Because of automatic semicolon insertion, we need to report error if this // throw could be terminated with a semicolon. Note: we can't call 'parseExpression' - // directly as that might consume an expression on the following line. + // directly as that might consume an expression on the following line. // We just return 'undefined' in that case. The actual error will be reported in the // grammar walker. let node = createNode(SyntaxKind.ThrowStatement); @@ -4046,12 +4130,12 @@ module ts { function isStartOfStatement(inErrorRecovery: boolean): boolean { // Functions and variable statements are allowed as a statement. But as per the grammar, - // they also allow modifiers. So we have to check for those statements that might be - // following modifiers.This ensures that things work properly when incrementally parsing - // as the parser will produce the same FunctionDeclaraiton or VariableStatement if it has + // they also allow modifiers. So we have to check for those statements that might be + // following modifiers.This ensures that things work properly when incrementally parsing + // as the parser will produce the same FunctionDeclaraiton or VariableStatement if it has // the same text regardless of whether it is inside a block or not. if (isModifier(token)) { - let result = lookAhead(parseVariableStatementOrFunctionDeclarationWithModifiers); + let result = lookAhead(parseVariableStatementOrFunctionDeclarationWithDecoratorsOrModifiers); if (result) { return true; } @@ -4134,10 +4218,10 @@ module ts { return parseBlock(/*ignoreMissingOpenBrace:*/ false, /*checkForStrictMode:*/ false); case SyntaxKind.VarKeyword: case SyntaxKind.ConstKeyword: - // const here should always be parsed as const declaration because of check in 'isStatement' - return parseVariableStatement(scanner.getStartPos(), /*modifiers:*/ undefined); + // const here should always be parsed as const declaration because of check in 'isStatement' + return parseVariableStatement(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers:*/ undefined); case SyntaxKind.FunctionKeyword: - return parseFunctionDeclaration(scanner.getStartPos(), /*modifiers:*/ undefined); + return parseFunctionDeclaration(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers:*/ undefined); case SyntaxKind.SemicolonToken: return parseEmptyStatement(); case SyntaxKind.IfKeyword: @@ -4170,18 +4254,20 @@ module ts { case SyntaxKind.LetKeyword: // If let follows identifier on the same line, it is declaration parse it as variable statement if (isLetDeclaration()) { - return parseVariableStatement(scanner.getStartPos(), /*modifiers:*/ undefined); + return parseVariableStatement(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers:*/ undefined); } // Else parse it like identifier - fall through default: - // Functions and variable statements are allowed as a statement. But as per - // the grammar, they also allow modifiers. So we have to check for those + // Functions and variable statements are allowed as a statement. But as per + // the grammar, they also allow modifiers. So we have to check for those // statements that might be following modifiers. This ensures that things // work properly when incrementally parsing as the parser will produce the // same FunctionDeclaraiton or VariableStatement if it has the same text // regardless of whether it is inside a block or not. - if (isModifier(token)) { - let result = tryParse(parseVariableStatementOrFunctionDeclarationWithModifiers); + // Even though variable statements and function declarations cannot have decorators, + // we parse them here to provide better error recovery. + if (isModifier(token) || token === SyntaxKind.AtToken) { + let result = tryParse(parseVariableStatementOrFunctionDeclarationWithDecoratorsOrModifiers); if (result) { return result; } @@ -4191,8 +4277,9 @@ module ts { } } - function parseVariableStatementOrFunctionDeclarationWithModifiers(): FunctionDeclaration | VariableStatement { + function parseVariableStatementOrFunctionDeclarationWithDecoratorsOrModifiers(): FunctionDeclaration | VariableStatement { let start = scanner.getStartPos(); + let decorators = parseDecorators(); let modifiers = parseModifiers(); switch (token) { case SyntaxKind.ConstKeyword: @@ -4200,18 +4287,18 @@ module ts { if (nextTokenIsEnum) { return undefined; } - return parseVariableStatement(start, modifiers); + return parseVariableStatement(start, decorators, modifiers); case SyntaxKind.LetKeyword: if (!isLetDeclaration()) { return undefined; } - return parseVariableStatement(start, modifiers); + return parseVariableStatement(start, decorators, modifiers); case SyntaxKind.VarKeyword: - return parseVariableStatement(start, modifiers); + return parseVariableStatement(start, decorators, modifiers); case SyntaxKind.FunctionKeyword: - return parseFunctionDeclaration(start, modifiers); + return parseFunctionDeclaration(start, decorators, modifiers); } return undefined; @@ -4336,21 +4423,23 @@ module ts { return finishNode(node); } - + function canFollowContextualOfKeyword(): boolean { return nextTokenIsIdentifier() && nextToken() === SyntaxKind.CloseParenToken; } - function parseVariableStatement(fullStart: number, modifiers: ModifiersArray): VariableStatement { + function parseVariableStatement(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): VariableStatement { let node = createNode(SyntaxKind.VariableStatement, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); node.declarationList = parseVariableDeclarationList(/*inForStatementInitializer:*/ false); parseSemicolon(); return finishNode(node); } - function parseFunctionDeclaration(fullStart: number, modifiers: ModifiersArray): FunctionDeclaration { + function parseFunctionDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): FunctionDeclaration { let node = createNode(SyntaxKind.FunctionDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.FunctionKeyword); node.asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); @@ -4360,8 +4449,9 @@ module ts { return finishNode(node); } - function parseConstructorDeclaration(pos: number, modifiers: ModifiersArray): ConstructorDeclaration { + function parseConstructorDeclaration(pos: number, decorators: NodeArray, modifiers: ModifiersArray): ConstructorDeclaration { let node = createNode(SyntaxKind.Constructor, pos); + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.ConstructorKeyword); fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ false, /*requireCompleteParameterList:*/ false, node); @@ -4369,8 +4459,9 @@ module ts { return finishNode(node); } - function parseMethodDeclaration(fullStart: number, modifiers: ModifiersArray, asteriskToken: Node, name: DeclarationName, questionToken: Node, diagnosticMessage?: DiagnosticMessage): MethodDeclaration { + function parseMethodDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray, asteriskToken: Node, name: DeclarationName, questionToken: Node, diagnosticMessage?: DiagnosticMessage): MethodDeclaration { let method = createNode(SyntaxKind.MethodDeclaration, fullStart); + method.decorators = decorators; setModifiers(method, modifiers); method.asteriskToken = asteriskToken; method.name = name; @@ -4380,25 +4471,30 @@ module ts { return finishNode(method); } - function parsePropertyOrMethodDeclaration(fullStart: number, modifiers: ModifiersArray): ClassElement { + function parsePropertyDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray, name: DeclarationName, questionToken: Node): ClassElement { + let property = createNode(SyntaxKind.PropertyDeclaration, fullStart); + property.decorators = decorators; + setModifiers(property, modifiers); + property.name = name; + property.questionToken = questionToken; + property.type = parseTypeAnnotation(); + property.initializer = allowInAnd(parseNonParameterInitializer); + parseSemicolon(); + return finishNode(property); + } + + function parsePropertyOrMethodDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ClassElement { let asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); let name = parsePropertyName(); - + // Note: this is not legal as per the grammar. But we allow it in the parser and // report an error in the grammar checker. let questionToken = parseOptionalToken(SyntaxKind.QuestionToken); if (asteriskToken || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { - return parseMethodDeclaration(fullStart, modifiers, asteriskToken, name, questionToken, Diagnostics.or_expected); + return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, name, questionToken, Diagnostics.or_expected); } else { - let property = createNode(SyntaxKind.PropertyDeclaration, fullStart); - setModifiers(property, modifiers); - property.name = name; - property.questionToken = questionToken; - property.type = parseTypeAnnotation(); - property.initializer = allowInAnd(parseNonParameterInitializer); - parseSemicolon(); - return finishNode(property); + return parsePropertyDeclaration(fullStart, decorators, modifiers, name, questionToken); } } @@ -4406,8 +4502,9 @@ module ts { return parseInitializer(/*inParameter*/ false); } - function parseAccessorDeclaration(kind: SyntaxKind, fullStart: number, modifiers: ModifiersArray): AccessorDeclaration { + function parseAccessorDeclaration(kind: SyntaxKind, fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): AccessorDeclaration { let node = createNode(kind, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); node.name = parsePropertyName(); fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ false, /*requireCompleteParameterList:*/ false, node); @@ -4418,6 +4515,10 @@ module ts { function isClassMemberStart(): boolean { let idToken: SyntaxKind; + if (token === SyntaxKind.AtToken) { + return true; + } + // Eat up all modifiers, but hold on to the last one in case it is actually an identifier. while (isModifier(token)) { idToken = token; @@ -4439,7 +4540,7 @@ module ts { if (token === SyntaxKind.OpenBracketToken) { return true; } - + // If we were able to get any potential identifier... if (idToken !== undefined) { // If we have a non-keyword identifier, or if we have an accessor, then it's safe to parse. @@ -4469,6 +4570,29 @@ module ts { return false; } + function parseDecorators(): NodeArray { + let decorators: NodeArray; + while (true) { + let decoratorStart = getNodePos(); + if (!parseOptional(SyntaxKind.AtToken)) { + break; + } + + if (!decorators) { + decorators = >[]; + decorators.pos = scanner.getStartPos(); + } + + let decorator = createNode(SyntaxKind.Decorator, decoratorStart); + decorator.expression = doInDecoratorContext(parseLeftHandSideExpressionOrHigher); + decorators.push(finishNode(decorator)); + } + if (decorators) { + decorators.end = getNodeEnd(); + } + return decorators; + } + function parseModifiers(): ModifiersArray { let flags = 0; let modifiers: ModifiersArray; @@ -4496,19 +4620,20 @@ module ts { function parseClassElement(): ClassElement { let fullStart = getNodePos(); + let decorators = parseDecorators(); let modifiers = parseModifiers(); - let accessor = tryParseAccessorDeclaration(fullStart, modifiers); + let accessor = tryParseAccessorDeclaration(fullStart, decorators, modifiers); if (accessor) { return accessor; } if (token === SyntaxKind.ConstructorKeyword) { - return parseConstructorDeclaration(fullStart, modifiers); + return parseConstructorDeclaration(fullStart, decorators, modifiers); } if (isIndexSignature()) { - return parseIndexSignatureDeclaration(modifiers); + return parseIndexSignatureDeclaration(fullStart, decorators, modifiers); } // It is very important that we check this *after* checking indexers because @@ -4519,15 +4644,28 @@ module ts { token === SyntaxKind.AsteriskToken || token === SyntaxKind.OpenBracketToken) { - return parsePropertyOrMethodDeclaration(fullStart, modifiers); + return parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers); + } + + if (decorators) { + // treat this as a property declaration with a missing name. + let name = createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected); + return parsePropertyDeclaration(fullStart, decorators, modifiers, name, /*questionToken*/ undefined); } // 'isClassMemberStart' should have hinted not to attempt parsing. Debug.fail("Should not have attempted to parse class member declaration."); } - function parseClassDeclaration(fullStart: number, modifiers: ModifiersArray): ClassDeclaration { - let node = createNode(SyntaxKind.ClassDeclaration, fullStart); + function parseClassDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ClassDeclaration { + // In ES6 specification, All parts of a ClassDeclaration or a ClassExpression are strict mode code + let savedStrictModeContext = inStrictModeContext(); + if (languageVersion >= ScriptTarget.ES6) { + setStrictModeContext(true); + } + + var node = createNode(SyntaxKind.ClassDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.ClassKeyword); node.name = node.flags & NodeFlags.Default ? parseOptionalIdentifier() : parseIdentifier(); @@ -4547,7 +4685,10 @@ module ts { else { node.members = createMissingList(); } - return finishNode(node); + + var finishedNode = finishNode(node); + setStrictModeContext(savedStrictModeContext); + return finishedNode; } function parseHeritageClauses(isClassHeritageClause: boolean): NodeArray { @@ -4588,8 +4729,9 @@ module ts { return parseList(ParsingContext.ClassMembers, /*checkForStrictMode*/ false, parseClassElement); } - function parseInterfaceDeclaration(fullStart: number, modifiers: ModifiersArray): InterfaceDeclaration { + function parseInterfaceDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): InterfaceDeclaration { let node = createNode(SyntaxKind.InterfaceDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.InterfaceKeyword); node.name = parseIdentifier(); @@ -4599,8 +4741,9 @@ module ts { return finishNode(node); } - function parseTypeAliasDeclaration(fullStart: number, modifiers: ModifiersArray): TypeAliasDeclaration { + function parseTypeAliasDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): TypeAliasDeclaration { let node = createNode(SyntaxKind.TypeAliasDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.TypeKeyword); node.name = parseIdentifier(); @@ -4621,8 +4764,9 @@ module ts { return finishNode(node); } - function parseEnumDeclaration(fullStart: number, modifiers: ModifiersArray): EnumDeclaration { + function parseEnumDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): EnumDeclaration { let node = createNode(SyntaxKind.EnumDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.EnumKeyword); node.name = parseIdentifier(); @@ -4648,30 +4792,32 @@ module ts { return finishNode(node); } - function parseInternalModuleTail(fullStart: number, modifiers: ModifiersArray, flags: NodeFlags): ModuleDeclaration { + function parseInternalModuleTail(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray, flags: NodeFlags): ModuleDeclaration { let node = createNode(SyntaxKind.ModuleDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); node.flags |= flags; node.name = parseIdentifier(); node.body = parseOptional(SyntaxKind.DotToken) - ? parseInternalModuleTail(getNodePos(), /*modifiers:*/undefined, NodeFlags.Export) + ? parseInternalModuleTail(getNodePos(), /*decorators*/ undefined, /*modifiers:*/undefined, NodeFlags.Export) : parseModuleBlock(); return finishNode(node); } - function parseAmbientExternalModuleDeclaration(fullStart: number, modifiers: ModifiersArray): ModuleDeclaration { + function parseAmbientExternalModuleDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ModuleDeclaration { let node = createNode(SyntaxKind.ModuleDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); node.name = parseLiteralNode(/*internName:*/ true); node.body = parseModuleBlock(); return finishNode(node); } - function parseModuleDeclaration(fullStart: number, modifiers: ModifiersArray): ModuleDeclaration { + function parseModuleDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ModuleDeclaration { parseExpected(SyntaxKind.ModuleKeyword); return token === SyntaxKind.StringLiteral - ? parseAmbientExternalModuleDeclaration(fullStart, modifiers) - : parseInternalModuleTail(fullStart, modifiers, modifiers ? modifiers.flags : 0); + ? parseAmbientExternalModuleDeclaration(fullStart, decorators, modifiers) + : parseInternalModuleTail(fullStart, decorators, modifiers, modifiers ? modifiers.flags : 0); } function isExternalModuleReference() { @@ -4689,7 +4835,7 @@ module ts { token === SyntaxKind.FromKeyword; } - function parseImportDeclarationOrImportEqualsDeclaration(fullStart: number, modifiers: ModifiersArray): ImportEqualsDeclaration | ImportDeclaration { + function parseImportDeclarationOrImportEqualsDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ImportEqualsDeclaration | ImportDeclaration { parseExpected(SyntaxKind.ImportKeyword); let afterImportPos = scanner.getStartPos(); @@ -4701,6 +4847,7 @@ module ts { // import x = require("mod"); or // import x = M.x; let importEqualsDeclaration = createNode(SyntaxKind.ImportEqualsDeclaration, fullStart); + importEqualsDeclaration.decorators = decorators; setModifiers(importEqualsDeclaration, modifiers); importEqualsDeclaration.name = identifier; parseExpected(SyntaxKind.EqualsToken); @@ -4712,13 +4859,14 @@ module ts { // Import statement let importDeclaration = createNode(SyntaxKind.ImportDeclaration, fullStart); + importDeclaration.decorators = decorators; setModifiers(importDeclaration, modifiers); // ImportDeclaration: // import ImportClause from ModuleSpecifier ; // import ModuleSpecifier; if (identifier || // import id - token === SyntaxKind.AsteriskToken || // import * + token === SyntaxKind.AsteriskToken || // import * token === SyntaxKind.OpenBraceToken) { // import { importDeclaration.importClause = parseImportClause(identifier, afterImportPos); parseExpected(SyntaxKind.FromKeyword); @@ -4744,7 +4892,7 @@ module ts { importClause.name = identifier; } - // If there was no default import or if there is comma token after default import + // If there was no default import or if there is comma token after default import // parse namespace or named imports if (!importClause.name || parseOptional(SyntaxKind.CommaToken)) { @@ -4770,11 +4918,11 @@ module ts { } function parseModuleSpecifier(): Expression { - // We allow arbitrary expressions here, even though the grammar only allows string + // We allow arbitrary expressions here, even though the grammar only allows string // literals. We check to ensure that it is only a string literal later in the grammar // walker. let result = parseExpression(); - // Ensure the string being required is in our 'identifier' table. This will ensure + // Ensure the string being required is in our 'identifier' table. This will ensure // that features like 'find refs' will look inside this file when search for its name. if (result.kind === SyntaxKind.StringLiteral) { internIdentifier((result).text); @@ -4847,8 +4995,9 @@ module ts { return finishNode(node); } - function parseExportDeclaration(fullStart: number, modifiers: ModifiersArray): ExportDeclaration { + function parseExportDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ExportDeclaration { let node = createNode(SyntaxKind.ExportDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); if (parseOptional(SyntaxKind.AsteriskToken)) { parseExpected(SyntaxKind.FromKeyword); @@ -4864,17 +5013,23 @@ module ts { return finishNode(node); } - function parseExportAssignment(fullStart: number, modifiers: ModifiersArray): ExportAssignment { + function parseExportAssignment(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ExportAssignment { let node = createNode(SyntaxKind.ExportAssignment, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); if (parseOptional(SyntaxKind.EqualsToken)) { node.isExportEquals = true; + node.expression = parseAssignmentExpressionOrHigher(); } else { parseExpected(SyntaxKind.DefaultKeyword); + if (parseOptional(SyntaxKind.ColonToken)) { + node.type = parseType(); + } + else { + node.expression = parseAssignmentExpressionOrHigher(); + } } - //node.exportName = parseIdentifier(); - node.expression = parseAssignmentExpressionOrHigher(); parseSemicolon(); return finishNode(node); } @@ -4885,7 +5040,7 @@ module ts { return inStrictModeContext() || lookAhead(nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine); } - function isDeclarationStart(): boolean { + function isDeclarationStart(followsModifier?: boolean): boolean { switch (token) { case SyntaxKind.VarKeyword: case SyntaxKind.ConstKeyword: @@ -4915,6 +5070,10 @@ module ts { case SyntaxKind.StaticKeyword: // Check for modifier on source element return lookAhead(nextTokenIsDeclarationStart); + case SyntaxKind.AtToken: + // a lookahead here is too costly, and decorators are only valid on a declaration. + // We will assume we are parsing a declaration here and report an error later + return !followsModifier; } } @@ -4941,12 +5100,12 @@ module ts { function nextTokenCanFollowExportKeyword() { nextToken(); return token === SyntaxKind.EqualsToken || token === SyntaxKind.AsteriskToken || - token === SyntaxKind.OpenBraceToken || token === SyntaxKind.DefaultKeyword || isDeclarationStart(); + token === SyntaxKind.OpenBraceToken || token === SyntaxKind.DefaultKeyword || isDeclarationStart(/*followsModifier*/ true); } function nextTokenIsDeclarationStart() { nextToken(); - return isDeclarationStart(); + return isDeclarationStart(/*followsModifier*/ true); } function nextTokenIsAsKeyword() { @@ -4955,14 +5114,15 @@ module ts { function parseDeclaration(): ModuleElement { let fullStart = getNodePos(); + let decorators = parseDecorators(); let modifiers = parseModifiers(); if (token === SyntaxKind.ExportKeyword) { nextToken(); if (token === SyntaxKind.DefaultKeyword || token === SyntaxKind.EqualsToken) { - return parseExportAssignment(fullStart, modifiers); + return parseExportAssignment(fullStart, decorators, modifiers); } if (token === SyntaxKind.AsteriskToken || token === SyntaxKind.OpenBraceToken) { - return parseExportDeclaration(fullStart, modifiers); + return parseExportDeclaration(fullStart, decorators, modifiers); } } @@ -4970,22 +5130,31 @@ module ts { case SyntaxKind.VarKeyword: case SyntaxKind.LetKeyword: case SyntaxKind.ConstKeyword: - return parseVariableStatement(fullStart, modifiers); + return parseVariableStatement(fullStart, decorators, modifiers); case SyntaxKind.FunctionKeyword: - return parseFunctionDeclaration(fullStart, modifiers); + return parseFunctionDeclaration(fullStart, decorators, modifiers); case SyntaxKind.ClassKeyword: - return parseClassDeclaration(fullStart, modifiers); + return parseClassDeclaration(fullStart, decorators, modifiers); case SyntaxKind.InterfaceKeyword: - return parseInterfaceDeclaration(fullStart, modifiers); + return parseInterfaceDeclaration(fullStart, decorators, modifiers); case SyntaxKind.TypeKeyword: - return parseTypeAliasDeclaration(fullStart, modifiers); + return parseTypeAliasDeclaration(fullStart, decorators, modifiers); case SyntaxKind.EnumKeyword: - return parseEnumDeclaration(fullStart, modifiers); + return parseEnumDeclaration(fullStart, decorators, modifiers); case SyntaxKind.ModuleKeyword: - return parseModuleDeclaration(fullStart, modifiers); + return parseModuleDeclaration(fullStart, decorators, modifiers); case SyntaxKind.ImportKeyword: - return parseImportDeclarationOrImportEqualsDeclaration(fullStart, modifiers); + return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers); default: + if (decorators) { + // We reached this point because we encountered an AtToken and assumed a declaration would + // follow. For recovery and error reporting purposes, return an incomplete declaration. + let node = createMissingNode(SyntaxKind.MissingDeclaration, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected); + node.pos = fullStart; + node.decorators = decorators; + setModifiers(node, modifiers); + return finishNode(node); + } Debug.fail("Mismatch between isDeclarationStart and parseDeclaration"); } } @@ -5014,8 +5183,8 @@ module ts { let amdDependencies: {path: string; name: string}[] = []; let amdModuleName: string; - // Keep scanning all the leading trivia in the file until we get to something that - // isn't trivia. Any single line comment will be analyzed to see if it is a + // Keep scanning all the leading trivia in the file until we get to something that + // isn't trivia. Any single line comment will be analyzed to see if it is a // reference comment. while (true) { let kind = triviaScanner.scan(); diff --git a/src/compiler/program.ts b/src/compiler/program.ts index b6bff3c0937b8..cb12e6da4d5db 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2,13 +2,31 @@ /// module ts { + /* @internal */ export let programTime = 0; /* @internal */ export let emitTime = 0; /* @internal */ export let ioReadTime = 0; + /* @internal */ export let ioWriteTime = 0; /** The version of the TypeScript compiler release */ export let version = "1.5.0.0"; - export function createCompilerHost(options: CompilerOptions): CompilerHost { + export function findConfigFile(searchPath: string): string { + var fileName = "tsconfig.json"; + while (true) { + if (sys.fileExists(fileName)) { + return fileName; + } + var parentPath = getDirectoryPath(searchPath); + if (parentPath === searchPath) { + break; + } + searchPath = parentPath; + fileName = "../" + fileName; + } + return undefined; + } + + export function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost { let currentDirectory: string; let existingDirectories: Map = {}; @@ -36,33 +54,34 @@ module ts { } text = ""; } - - return text !== undefined ? createSourceFile(fileName, text, languageVersion) : undefined; + return text !== undefined ? createSourceFile(fileName, text, languageVersion, setParentNodes) : undefined; } - function writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void) { - function directoryExists(directoryPath: string): boolean { - if (hasProperty(existingDirectories, directoryPath)) { - return true; - } - if (sys.directoryExists(directoryPath)) { - existingDirectories[directoryPath] = true; - return true; - } - return false; + function directoryExists(directoryPath: string): boolean { + if (hasProperty(existingDirectories, directoryPath)) { + return true; } + if (sys.directoryExists(directoryPath)) { + existingDirectories[directoryPath] = true; + return true; + } + return false; + } - function ensureDirectoriesExist(directoryPath: string) { - if (directoryPath.length > getRootLength(directoryPath) && !directoryExists(directoryPath)) { - let parentDirectory = getDirectoryPath(directoryPath); - ensureDirectoriesExist(parentDirectory); - sys.createDirectory(directoryPath); - } + function ensureDirectoriesExist(directoryPath: string) { + if (directoryPath.length > getRootLength(directoryPath) && !directoryExists(directoryPath)) { + let parentDirectory = getDirectoryPath(directoryPath); + ensureDirectoriesExist(parentDirectory); + sys.createDirectory(directoryPath); } + } + function writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void) { try { + var start = new Date().getTime(); ensureDirectoriesExist(getDirectoryPath(normalizePath(fileName))); sys.writeFile(fileName, data, writeByteOrderMark); + ioWriteTime += new Date().getTime() - start; } catch (e) { if (onError) { @@ -84,6 +103,11 @@ module ts { export function getPreEmitDiagnostics(program: Program): Diagnostic[] { let diagnostics = program.getSyntacticDiagnostics().concat(program.getGlobalDiagnostics()).concat(program.getSemanticDiagnostics()); + + if (program.getCompilerOptions().declaration) { + diagnostics.concat(program.getDeclarationDiagnostics()); + } + return sortAndDeduplicateDiagnostics(diagnostics); } @@ -120,16 +144,19 @@ module ts { let diagnostics = createDiagnosticCollection(); let seenNoDefaultLib = options.noLib; let commonSourceDirectory: string; - host = host || createCompilerHost(options); + let diagnosticsProducingTypeChecker: TypeChecker; + let noDiagnosticsTypeChecker: TypeChecker; + + let start = new Date().getTime(); + host = host || createCompilerHost(options); forEach(rootNames, name => processRootFile(name, false)); if (!seenNoDefaultLib) { processRootFile(host.getDefaultLibFileName(options), true); } verifyCompilerOptions(); - let diagnosticsProducingTypeChecker: TypeChecker; - let noDiagnosticsTypeChecker: TypeChecker; + programTime += new Date().getTime() - start; program = { getSourceFile: getSourceFile, @@ -172,11 +199,6 @@ module ts { return noDiagnosticsTypeChecker || (noDiagnosticsTypeChecker = createTypeChecker(program, /*produceDiagnostics:*/ false)); } - function getDeclarationDiagnostics(targetSourceFile: SourceFile): Diagnostic[] { - let resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(targetSourceFile); - return ts.getDeclarationDiagnostics(getEmitHost(), resolver, targetSourceFile); - } - function emit(sourceFile?: SourceFile, writeFileCallback?: WriteFileCallback): EmitResult { // If the noEmitOnError flag is set, then check if we have any errors so far. If so, // immediately bail out. @@ -226,6 +248,10 @@ module ts { return getDiagnosticsHelper(sourceFile, getSemanticDiagnosticsForFile); } + function getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[] { + return getDiagnosticsHelper(sourceFile, getDeclarationDiagnosticsForFile); + } + function getSyntacticDiagnosticsForFile(sourceFile: SourceFile): Diagnostic[] { return sourceFile.parseDiagnostics; } @@ -241,6 +267,15 @@ module ts { return bindDiagnostics.concat(checkDiagnostics).concat(programDiagnostics); } + function getDeclarationDiagnosticsForFile(sourceFile: SourceFile): Diagnostic[] { + if (!isDeclarationFile(sourceFile)) { + let resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile); + // Don't actually write any files since we're just getting diagnostics. + var writeFile: WriteFileCallback = () => { }; + return ts.getDeclarationDiagnostics(getEmitHost(writeFile), resolver, sourceFile); + } + } + function getGlobalDiagnostics(): Diagnostic[] { let typeChecker = getDiagnosticsProducingTypeChecker(); @@ -430,11 +465,20 @@ module ts { return; } + let languageVersion = options.target || ScriptTarget.ES3; + let firstExternalModuleSourceFile = forEach(files, f => isExternalModule(f) ? f : undefined); if (firstExternalModuleSourceFile && !options.module) { - // We cannot use createDiagnosticFromNode because nodes do not have parents yet - let span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); - diagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided)); + if (!options.module && languageVersion < ScriptTarget.ES6) { + // We cannot use createDiagnosticFromNode because nodes do not have parents yet + let span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); + diagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided)); + } + } + + // Cannot specify module gen target when in es6 or above + if (options.module && languageVersion >= ScriptTarget.ES6) { + diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_compile_external_modules_into_amd_or_commonjs_when_targeting_es6_or_higher)); } // there has to be common source directory if user specified --outdir || --sourcRoot diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index fbcadab8c1d85..3a208698c25f4 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -148,6 +148,7 @@ module ts { "&=": SyntaxKind.AmpersandEqualsToken, "|=": SyntaxKind.BarEqualsToken, "^=": SyntaxKind.CaretEqualsToken, + "@": SyntaxKind.AtToken, }; /* @@ -256,6 +257,11 @@ module ts { return tokenStrings[t]; } + /* @internal */ + export function stringToToken(s: string): SyntaxKind { + return textToToken[s]; + } + export function computeLineStarts(text: string): number[] { let result: number[] = new Array(); let pos = 0; @@ -318,13 +324,38 @@ module ts { let hasOwnProperty = Object.prototype.hasOwnProperty; export function isWhiteSpace(ch: number): boolean { - return ch === CharacterCodes.space || ch === CharacterCodes.tab || ch === CharacterCodes.verticalTab || ch === CharacterCodes.formFeed || - ch === CharacterCodes.nonBreakingSpace || ch === CharacterCodes.ogham || ch >= CharacterCodes.enQuad && ch <= CharacterCodes.zeroWidthSpace || - ch === CharacterCodes.narrowNoBreakSpace || ch === CharacterCodes.mathematicalSpace || ch === CharacterCodes.ideographicSpace || ch === CharacterCodes.byteOrderMark; + // Note: nextLine is in the Zs space, and should be considered to be a whitespace. + // It is explicitly not a line-break as it isn't in the exact set specified by EcmaScript. + return ch === CharacterCodes.space || + ch === CharacterCodes.tab || + ch === CharacterCodes.verticalTab || + ch === CharacterCodes.formFeed || + ch === CharacterCodes.nonBreakingSpace || + ch === CharacterCodes.nextLine || + ch === CharacterCodes.ogham || + ch >= CharacterCodes.enQuad && ch <= CharacterCodes.zeroWidthSpace || + ch === CharacterCodes.narrowNoBreakSpace || + ch === CharacterCodes.mathematicalSpace || + ch === CharacterCodes.ideographicSpace || + ch === CharacterCodes.byteOrderMark; } export function isLineBreak(ch: number): boolean { - return ch === CharacterCodes.lineFeed || ch === CharacterCodes.carriageReturn || ch === CharacterCodes.lineSeparator || ch === CharacterCodes.paragraphSeparator || ch === CharacterCodes.nextLine; + // ES5 7.3: + // The ECMAScript line terminator characters are listed in Table 3. + // Table 3 Line Terminator Characters + // Code Unit Value Name Formal Name + // \u000A Line Feed + // \u000D Carriage Return + // \u2028 Line separator + // \u2029 Paragraph separator + // Only the characters in Table 3 are treated as line terminators. Other new line or line + // breaking characters are treated as white space but not as line terminators. + + return ch === CharacterCodes.lineFeed || + ch === CharacterCodes.carriageReturn || + ch === CharacterCodes.lineSeparator || + ch === CharacterCodes.paragraphSeparator; } function isDigit(ch: number): boolean { @@ -455,11 +486,13 @@ module ts { return pos; } - // Extract comments from the given source text starting at the given position. If trailing is false, whitespace is skipped until - // the first line break and comments between that location and the next token are returned. If trailing is true, comments occurring - // between the given position and the next line break are returned. The return value is an array containing a TextRange for each - // comment. Single-line comment ranges include the beginning '//' characters but not the ending line break. Multi-line comment - // ranges include the beginning '/* and ending '*/' characters. The return value is undefined if no comments were found. + // Extract comments from the given source text starting at the given position. If trailing is + // false, whitespace is skipped until the first line break and comments between that location + // and the next token are returned.If trailing is true, comments occurring between the given + // position and the next line break are returned.The return value is an array containing a + // TextRange for each comment. Single-line comment ranges include the beginning '//' characters + // but not the ending line break. Multi - line comment ranges include the beginning '/* and + // ending '*/' characters.The return value is undefined if no comments were found. function getCommentRanges(text: string, pos: number, trailing: boolean): CommentRange[] { let result: CommentRange[]; let collecting = trailing || pos === 0; @@ -467,7 +500,9 @@ module ts { let ch = text.charCodeAt(pos); switch (ch) { case CharacterCodes.carriageReturn: - if (text.charCodeAt(pos + 1) === CharacterCodes.lineFeed) pos++; + if (text.charCodeAt(pos + 1) === CharacterCodes.lineFeed) { + pos++; + } case CharacterCodes.lineFeed: pos++; if (trailing) { @@ -509,7 +544,10 @@ module ts { } } if (collecting) { - if (!result) result = []; + if (!result) { + result = []; + } + result.push({ pos: startPos, end: pos, hasTrailingNewLine: hasTrailingNewLine }); } continue; @@ -1247,6 +1285,8 @@ module ts { return pos++, token = SyntaxKind.CloseBraceToken; case CharacterCodes.tilde: return pos++, token = SyntaxKind.TildeToken; + case CharacterCodes.at: + return pos++, token = SyntaxKind.AtToken; case CharacterCodes.backslash: let cookedChar = peekUnicodeEscape(); if (cookedChar >= 0 && isIdentifierStart(cookedChar)) { diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index e9c5e17c751ee..a0d21106f4357 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -132,23 +132,6 @@ module ts { return typeof JSON === "object" && typeof JSON.parse === "function"; } - function findConfigFile(): string { - var searchPath = normalizePath(sys.getCurrentDirectory()); - var fileName = "tsconfig.json"; - while (true) { - if (sys.fileExists(fileName)) { - return fileName; - } - var parentPath = getDirectoryPath(searchPath); - if (parentPath === searchPath) { - break; - } - searchPath = parentPath; - fileName = "../" + fileName; - } - return undefined; - } - export function executeCommandLine(args: string[]): void { var commandLine = parseCommandLine(args); var configFileName: string; // Configuration file name (if any) @@ -198,7 +181,8 @@ module ts { } } else if (commandLine.fileNames.length === 0 && isJSONSupported()) { - configFileName = findConfigFile(); + var searchPath = normalizePath(sys.getCurrentDirectory()); + configFileName = findConfigFile(searchPath); } if (commandLine.fileNames.length === 0 && !configFileName) { @@ -320,22 +304,16 @@ module ts { } function compile(fileNames: string[], compilerOptions: CompilerOptions, compilerHost: CompilerHost) { - ts.ioReadTime = 0; - ts.parseTime = 0; - ts.bindTime = 0; - ts.checkTime = 0; - ts.emitTime = 0; - - var start = new Date().getTime(); + ioReadTime = 0; + ioWriteTime = 0; + programTime = 0; + bindTime = 0; + checkTime = 0; + emitTime = 0; var program = createProgram(fileNames, compilerOptions, compilerHost); - var programTime = new Date().getTime() - start; - var exitStatus = compileProgram(); - var end = new Date().getTime() - start; - var compileTime = end - programTime; - if (compilerOptions.listFiles) { forEach(program.getSourceFiles(), file => { sys.write(file.fileName + sys.newLine); @@ -356,19 +334,16 @@ module ts { } // Individual component times. - // Note: we output 'programTime' as parseTime to match the tsc 1.3 behavior. tsc 1.3 - // measured parse time along with read IO as a single counter. We preserve that - // behavior so we can accurately compare times. For actual parse times (in isolation) - // is reported below. + // Note: To match the behavior of previous versions of the compiler, the reported parse time includes + // I/O read time and processing time for triple-slash references and module imports, and the reported + // emit time includes I/O write time. We preserve this behavior so we can accurately compare times. + reportTimeStatistic("I/O read", ioReadTime); + reportTimeStatistic("I/O write", ioWriteTime); reportTimeStatistic("Parse time", programTime); - reportTimeStatistic("Bind time", ts.bindTime); - reportTimeStatistic("Check time", ts.checkTime); - reportTimeStatistic("Emit time", ts.emitTime); - - reportTimeStatistic("Parse time w/o IO", ts.parseTime); - reportTimeStatistic("IO read", ts.ioReadTime); - reportTimeStatistic("Compile time", compileTime); - reportTimeStatistic("Total time", end); + reportTimeStatistic("Bind time", bindTime); + reportTimeStatistic("Check time", checkTime); + reportTimeStatistic("Emit time", emitTime); + reportTimeStatistic("Total time", programTime + bindTime + checkTime + emitTime); } return { program, exitStatus }; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 359af6828c19c..e5697f9f37239 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -67,6 +67,7 @@ module ts { BarBarToken, QuestionToken, ColonToken, + AtToken, // Assignments EqualsToken, PlusEqualsToken, @@ -154,6 +155,7 @@ module ts { // Signature elements TypeParameter, Parameter, + Decorator, // TypeMember PropertySignature, PropertyDeclaration, @@ -244,6 +246,7 @@ module ts { ExportDeclaration, NamedExports, ExportSpecifier, + MissingDeclaration, // Module references ExternalModuleReference, @@ -328,22 +331,25 @@ module ts { // If this node was parsed in the parameters of a generator. GeneratorParameter = 1 << 3, + // If this node was parsed as part of a decorator + Decorator = 1 << 4, + // If the parser encountered an error when parsing the code that created this node. Note // the parser only sets this directly on the node it creates right after encountering the - // error. - ThisNodeHasError = 1 << 4, + // error. + ThisNodeHasError = 1 << 5, // Context flags set directly by the parser. - ParserGeneratedFlags = StrictMode | DisallowIn | Yield | GeneratorParameter | ThisNodeHasError, + ParserGeneratedFlags = StrictMode | DisallowIn | Yield | GeneratorParameter | Decorator | ThisNodeHasError, // Context flags computed by aggregating child flags upwards. - // Used during incremental parsing to determine if this node or any of its children had an + // Used during incremental parsing to determine if this node or any of its children had an // error. Computed only once and then cached. - ThisNodeOrAnySubNodesHasError = 1 << 5, + ThisNodeOrAnySubNodesHasError = 1 << 6, // Used to know if we've computed data from children and cached it in this node. - HasAggregatedChildData = 1 << 6 + HasAggregatedChildData = 1 << 7 } export const enum RelationComparisonResult { @@ -355,16 +361,17 @@ module ts { export interface Node extends TextRange { kind: SyntaxKind; flags: NodeFlags; - // Specific context the parser was in when this node was created. Normally undefined. + // Specific context the parser was in when this node was created. Normally undefined. // Only set when the parser was in some interesting context (like async/yield). parserContextFlags?: ParserContextFlags; - modifiers?: ModifiersArray; // Array of modifiers - id?: number; // Unique id (used to look up NodeLinks) - parent?: Node; // Parent node (initialized by binding) - symbol?: Symbol; // Symbol declared by node (initialized by binding) - locals?: SymbolTable; // Locals associated with node (initialized by binding) - nextContainer?: Node; // Next container in declaration order (initialized by binding) - localSymbol?: Symbol; // Local symbol declared by node (initialized by binding only for exported nodes) + decorators?: NodeArray; // Array of decorators (in document order) + modifiers?: ModifiersArray; // Array of modifiers + id?: number; // Unique id (used to look up NodeLinks) + parent?: Node; // Parent node (initialized by binding) + symbol?: Symbol; // Symbol declared by node (initialized by binding) + locals?: SymbolTable; // Locals associated with node (initialized by binding) + nextContainer?: Node; // Next container in declaration order (initialized by binding) + localSymbol?: Symbol; // Local symbol declared by node (initialized by binding only for exported nodes) } export interface NodeArray extends Array, TextRange { @@ -398,6 +405,10 @@ module ts { expression: Expression; } + export interface Decorator extends Node { + expression: LeftHandSideExpression; + } + export interface TypeParameterDeclaration extends Declaration { name: Identifier; constraint?: TypeNode; @@ -525,7 +536,7 @@ module ts { body?: Block; } - // See the comment on MethodDeclaration for the intuition behind AccessorDeclaration being a + // See the comment on MethodDeclaration for the intuition behind AccessorDeclaration being a // ClassElement and an ObjectLiteralElement. export interface AccessorDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement { _accessorDeclarationBrand: any; @@ -576,12 +587,12 @@ module ts { export interface StringLiteralTypeNode extends LiteralExpression, TypeNode { } - // Note: 'brands' in our syntax nodes serve to give us a small amount of nominal typing. + // Note: 'brands' in our syntax nodes serve to give us a small amount of nominal typing. // Consider 'Expression'. Without the brand, 'Expression' is actually no different // (structurally) than 'Node'. Because of this you can pass any Node to a function that // takes an Expression without any error. By using the 'brands' we ensure that the type - // checker actually thinks you have something of the right type. Note: the brands are - // never actually given values. At runtime they have zero cost. + // checker actually thinks you have something of the right type. Note: the brands are + // never actually given values. At runtime they have zero cost. export interface Expression extends Node { _expressionBrand: any; @@ -654,6 +665,10 @@ module ts { body: Block | Expression; // Required, whereas the member inherited from FunctionDeclaration is optional } + export interface ArrowFunction extends Expression, FunctionLikeDeclaration { + equalsGreaterThanToken: Node; + } + // The text property of a LiteralExpression stores the interpreted value of the literal in text form. For a StringLiteral, // or any literal of a template, this means quotes have been removed and escapes have been converted to actual characters. // For a NumericLiteral, the stored value is the toString() representation of the number. For example 1, 1.00, and 1e0 are all stored as just "1". @@ -736,7 +751,7 @@ module ts { } export interface VariableStatement extends Statement { - declarationList: VariableDeclarationList; + declarationList: VariableDeclarationList; } export interface ExpressionStatement extends Statement { @@ -904,7 +919,7 @@ module ts { moduleSpecifier: Expression; } - // In case of: + // In case of: // import d from "mod" => name = d, namedBinding = undefined // import * as ns from "mod" => name = undefined, namedBinding: NamespaceImport = { name: ns } // import d, * as ns from "mod" => name = d, namedBinding: NamespaceImport = { name: ns } @@ -941,7 +956,8 @@ module ts { export interface ExportAssignment extends Declaration, ModuleElement { isExportEquals?: boolean; - expression: Expression; + expression?: Expression; + type?: TypeNode; } export interface FileReference extends TextRange { @@ -970,7 +986,7 @@ module ts { externalModuleIndicator: Node; languageVersion: ScriptTarget; identifiers: Map; - + /* @internal */ nodeCount: number; /* @internal */ identifierCount: number; /* @internal */ symbolCount: number; @@ -978,10 +994,10 @@ module ts { // File level diagnostics reported by the parser (includes diagnostics about /// references // as well as code diagnostics). /* @internal */ parseDiagnostics: Diagnostic[]; - + // File level diagnostics reported by the binder. /* @internal */ bindDiagnostics: Diagnostic[]; - + // Stores a line map for the file. // This field should never be used directly to obtain line map, use getLineMap function instead. /* @internal */ lineMap: number[]; @@ -1001,14 +1017,14 @@ module ts { getSourceFiles(): SourceFile[]; /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then - * the javascript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the javascript and declaration for that - * specific file will be generated. + * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then + * the JavaScript and declaration files will be produced for all the files in this program. + * If targetSourceFile is specified, then only the JavaScript and declaration for that + * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the javascript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; @@ -1022,7 +1038,7 @@ module ts { getCommonSourceDirectory(): string; - // For testing purposes only. Should not be used by any other consumers (including the + // For testing purposes only. Should not be used by any other consumers (including the // language service). /* @internal */ getDiagnosticsProducingTypeChecker(): TypeChecker; @@ -1059,7 +1075,7 @@ module ts { // when -version or -help was provided, or this was a normal compilation, no diagnostics // were produced, and all outputs were generated successfully. Success = 0, - + // Diagnostics were produced and because of them no code was generated. DiagnosticsPresent_OutputsSkipped = 1, @@ -1088,6 +1104,9 @@ module ts { getSignaturesOfType(type: Type, kind: SignatureKind): Signature[]; getIndexTypeOfType(type: Type, kind: IndexKind): Type; getReturnTypeOfSignature(signature: Signature): Type; + + // If 'predicate' is supplied, then only the first symbol in scope matching the predicate + // will be returned. Otherwise, all symbols in scope will be returned. getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[]; getSymbolAtLocation(node: Node): Symbol; getShorthandAssignmentValueSymbol(location: Node): Symbol; @@ -1169,12 +1188,12 @@ module ts { // Write symbols's type argument if it is instantiated symbol // eg. class C { p: T } <-- Show p as C.p here - // var a: C; + // var a: C; // var p = a.p; <--- Here p is property of C so show it as C.p instead of just C.p - WriteTypeParametersOrArguments = 0x00000001, + WriteTypeParametersOrArguments = 0x00000001, // Use only external alias information to get the symbol name in the given context - // eg. module m { export class c { } } import x = m.c; + // eg. module m { export class c { } } import x = m.c; // When this flag is specified m.c will be used to refer to the class instead of alias symbol x UseOnlyExternalAliasing = 0x00000002, } @@ -1185,9 +1204,11 @@ module ts { CannotBeNamed } + export type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; + export interface SymbolVisibilityResult { accessibility: SymbolAccessibility; - aliasesToMakeVisible?: ImportEqualsDeclaration[]; // aliases that need to have this symbol visible + aliasesToMakeVisible?: AnyImportSyntax[]; // aliases that need to have this symbol visible errorSymbolName?: string; // Optional symbol name that results in error errorNode?: Node; // optional node that results in error } @@ -1197,21 +1218,23 @@ module ts { } export interface EmitResolver { - getGeneratedNameForNode(node: Node): string; - getExpressionNameSubstitution(node: Identifier): string; + hasGlobalName(name: string): boolean; + getExpressionNameSubstitution(node: Identifier, getGeneratedNameForNode: (node: Node) => string): string; isValueAliasDeclaration(node: Node): boolean; - isReferencedAliasDeclaration(node: Node): boolean; + isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; + collectLinkedAliases(node: Identifier): Node[]; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; // Returns the constant value this property access resolves to, or 'undefined' for a non-constant getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; - isUnknownIdentifier(location: Node, name: string): boolean; + resolvesToSomeValue(location: Node, name: string): boolean; getBlockScopedVariableId(node: Identifier): number; } @@ -1326,17 +1349,18 @@ module ts { } export const enum NodeCheckFlags { - TypeChecked = 0x00000001, // Node has been type checked - LexicalThis = 0x00000002, // Lexical 'this' reference - CaptureThis = 0x00000004, // Lexical 'this' used in body - EmitExtends = 0x00000008, // Emit __extends - SuperInstance = 0x00000010, // Instance 'super' reference - SuperStatic = 0x00000020, // Static 'super' reference - ContextChecked = 0x00000040, // Contextual types have been assigned + TypeChecked = 0x00000001, // Node has been type checked + LexicalThis = 0x00000002, // Lexical 'this' reference + CaptureThis = 0x00000004, // Lexical 'this' used in body + EmitExtends = 0x00000008, // Emit __extends + SuperInstance = 0x00000010, // Instance 'super' reference + SuperStatic = 0x00000020, // Static 'super' reference + ContextChecked = 0x00000040, // Contextual types have been assigned // Values for enum members have been computed, and any errors have been reported for them. - EnumValuesComputed = 0x00000080, - BlockScopedBindingInLoop = 0x00000100, + EnumValuesComputed = 0x00000080, + BlockScopedBindingInLoop = 0x00000100, + EmitDecorate = 0x00000200, // Emit __decorate } export interface NodeLinks { @@ -1483,11 +1507,15 @@ module ts { (t: Type): Type; } + // @internal export interface TypeInferences { primary: Type[]; // Inferences made directly to a type parameter secondary: Type[]; // Inferences made to a type parameter in a union type + isFixed: boolean; // Whether the type parameter is fixed, as defined in section 4.12.2 of the TypeScript spec + // If a type parameter is fixed, no more inferences can be made for the type parameter } + // @internal export interface InferenceContext { typeParameters: TypeParameter[]; // Type parameters for which inferences are made inferUnionTypes: boolean; // Infer union types for disjoint candidates (otherwise undefinedType) @@ -1779,7 +1807,7 @@ module ts { // Gets a count of how many times this collection has been modified. This value changes // each time 'add' is called (regardless of whether or not an equivalent diagnostic was // already in the collection). As such, it can be used as a simple way to tell if any - // operation caused diagnostics to be returned by storing and comparing the return value + // operation caused diagnostics to be returned by storing and comparing the return value // of this method before/after the operation is performed. getModificationCount(): number; } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 3c61ad66f8392..9fa0674c25c07 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1,4 +1,4 @@ -/// +/// module ts { export interface ReferencePathMatchResult { @@ -361,16 +361,16 @@ module ts { return node.kind === SyntaxKind.ExpressionStatement && (node).expression.kind === SyntaxKind.StringLiteral; } - export function getLeadingCommentRangesOfNode(node: Node, sourceFileOfNode?: SourceFile) { - sourceFileOfNode = sourceFileOfNode || getSourceFileOfNode(node); - + export function getLeadingCommentRangesOfNode(node: Node, sourceFileOfNode: SourceFile) { // If parameter/type parameter, the prev token trailing comments are part of this node too if (node.kind === SyntaxKind.Parameter || node.kind === SyntaxKind.TypeParameter) { // e.g. (/** blah */ a, /** blah */ b); - return concatenate(getTrailingCommentRanges(sourceFileOfNode.text, node.pos), - // e.g.: ( - // /** blah */ a, - // /** blah */ b); + + // e.g.: ( + // /** blah */ a, + // /** blah */ b); + return concatenate( + getTrailingCommentRanges(sourceFileOfNode.text, node.pos), getLeadingCommentRanges(sourceFileOfNode.text, node.pos)); } else { @@ -575,6 +575,83 @@ module ts { return (node).expression; } + export function nodeCanBeDecorated(node: Node): boolean { + switch (node.kind) { + case SyntaxKind.ClassDeclaration: + // classes are valid targets + return true; + + case SyntaxKind.PropertyDeclaration: + // property declarations are valid if their parent is a class declaration. + return node.parent.kind === SyntaxKind.ClassDeclaration; + + case SyntaxKind.Parameter: + // if the parameter's parent has a body and its grandparent is a class declaration, this is a valid target; + return (node.parent).body && node.parent.parent.kind === SyntaxKind.ClassDeclaration; + + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.MethodDeclaration: + // if this method has a body and its parent is a class declaration, this is a valid target. + return (node).body && node.parent.kind === SyntaxKind.ClassDeclaration; + } + + return false; + } + + export function nodeIsDecorated(node: Node): boolean { + switch (node.kind) { + case SyntaxKind.ClassDeclaration: + if (node.decorators) { + return true; + } + + return false; + + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.Parameter: + if (node.decorators) { + return true; + } + + return false; + + case SyntaxKind.GetAccessor: + if ((node).body && node.decorators) { + return true; + } + + return false; + + case SyntaxKind.MethodDeclaration: + case SyntaxKind.SetAccessor: + if ((node).body && node.decorators) { + return true; + } + + return false; + } + + return false; + } + + export function childIsDecorated(node: Node): boolean { + switch (node.kind) { + case SyntaxKind.ClassDeclaration: + return forEach((node).members, nodeOrChildIsDecorated); + + case SyntaxKind.MethodDeclaration: + case SyntaxKind.SetAccessor: + return forEach((node).parameters, nodeIsDecorated); + } + + return false; + } + + export function nodeOrChildIsDecorated(node: Node): boolean { + return nodeIsDecorated(node) || childIsDecorated(node); + } + export function isExpression(node: Node): boolean { switch (node.kind) { case SyntaxKind.ThisKeyword: @@ -814,6 +891,20 @@ module ts { } } + export function isClassElement(n: Node): boolean { + switch (n.kind) { + case SyntaxKind.Constructor: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.IndexSignature: + return true; + default: + return false; + } + } + // True if the given identifier, string literal, or number literal is the name of a declaration node export function isDeclarationName(name: Node): boolean { if (name.kind !== SyntaxKind.Identifier && name.kind !== SyntaxKind.StringLiteral && name.kind !== SyntaxKind.NumericLiteral) { @@ -1229,28 +1320,6 @@ module ts { return node; } - export function generateUniqueName(baseName: string, isExistingName: (name: string) => boolean): string { - // First try '_name' - if (baseName.charCodeAt(0) !== CharacterCodes._) { - baseName = "_" + baseName; - if (!isExistingName(baseName)) { - return baseName; - } - } - // Find the first unique '_name_n', where n is a positive number - if (baseName.charCodeAt(baseName.length - 1) !== CharacterCodes._) { - baseName += "_"; - } - let i = 1; - while (true) { - let name = baseName + i; - if (!isExistingName(name)) { - return name; - } - i++; - } - } - // @internal export function createDiagnosticCollection(): DiagnosticCollection { let nonFileDiagnostics: Diagnostic[] = []; @@ -1381,4 +1450,322 @@ module ts { s.replace(nonAsciiCharacters, c => get16BitUnicodeEscapeSequence(c.charCodeAt(0))) : s; } + + export interface EmitTextWriter { + write(s: string): void; + writeTextOfNode(sourceFile: SourceFile, node: Node): void; + writeLine(): void; + increaseIndent(): void; + decreaseIndent(): void; + getText(): string; + rawWrite(s: string): void; + writeLiteral(s: string): void; + getTextPos(): number; + getLine(): number; + getColumn(): number; + getIndent(): number; + } + + let indentStrings: string[] = ["", " "]; + export function getIndentString(level: number) { + if (indentStrings[level] === undefined) { + indentStrings[level] = getIndentString(level - 1) + indentStrings[1]; + } + return indentStrings[level]; + } + + export function getIndentSize() { + return indentStrings[1].length; + } + + export function createTextWriter(newLine: String): EmitTextWriter { + let output = ""; + let indent = 0; + let lineStart = true; + let lineCount = 0; + let linePos = 0; + + function write(s: string) { + if (s && s.length) { + if (lineStart) { + output += getIndentString(indent); + lineStart = false; + } + output += s; + } + } + + function rawWrite(s: string) { + if (s !== undefined) { + if (lineStart) { + lineStart = false; + } + output += s; + } + } + + function writeLiteral(s: string) { + if (s && s.length) { + write(s); + let lineStartsOfS = computeLineStarts(s); + if (lineStartsOfS.length > 1) { + lineCount = lineCount + lineStartsOfS.length - 1; + linePos = output.length - s.length + lineStartsOfS[lineStartsOfS.length - 1]; + } + } + } + + function writeLine() { + if (!lineStart) { + output += newLine; + lineCount++; + linePos = output.length; + lineStart = true; + } + } + + function writeTextOfNode(sourceFile: SourceFile, node: Node) { + write(getSourceTextOfNodeFromSourceFile(sourceFile, node)); + } + + return { + write, + rawWrite, + writeTextOfNode, + writeLiteral, + writeLine, + increaseIndent: () => indent++, + decreaseIndent: () => indent--, + getIndent: () => indent, + getTextPos: () => output.length, + getLine: () => lineCount + 1, + getColumn: () => lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1, + getText: () => output, + }; + } + + export function getOwnEmitOutputFilePath(sourceFile: SourceFile, host: EmitHost, extension: string) { + let compilerOptions = host.getCompilerOptions(); + let emitOutputFilePathWithoutExtension: string; + if (compilerOptions.outDir) { + emitOutputFilePathWithoutExtension = removeFileExtension(getSourceFilePathInNewDir(sourceFile, host, compilerOptions.outDir)); + } + else { + emitOutputFilePathWithoutExtension = removeFileExtension(sourceFile.fileName); + } + + return emitOutputFilePathWithoutExtension + extension; + } + + export function getSourceFilePathInNewDir(sourceFile: SourceFile, host: EmitHost, newDirPath: string) { + let sourceFilePath = getNormalizedAbsolutePath(sourceFile.fileName, host.getCurrentDirectory()); + sourceFilePath = sourceFilePath.replace(host.getCommonSourceDirectory(), ""); + return combinePaths(newDirPath, sourceFilePath); + } + + export function writeFile(host: EmitHost, diagnostics: Diagnostic[], fileName: string, data: string, writeByteOrderMark: boolean) { + host.writeFile(fileName, data, writeByteOrderMark, hostErrorMessage => { + diagnostics.push(createCompilerDiagnostic(Diagnostics.Could_not_write_file_0_Colon_1, fileName, hostErrorMessage)); + }); + } + + export function getLineOfLocalPosition(currentSourceFile: SourceFile, pos: number) { + return getLineAndCharacterOfPosition(currentSourceFile, pos).line; + } + + export function getFirstConstructorWithBody(node: ClassDeclaration): ConstructorDeclaration { + return forEach(node.members, member => { + if (member.kind === SyntaxKind.Constructor && nodeIsPresent((member).body)) { + return member; + } + }); + } + + export function shouldEmitToOwnFile(sourceFile: SourceFile, compilerOptions: CompilerOptions): boolean { + if (!isDeclarationFile(sourceFile)) { + if ((isExternalModule(sourceFile) || !compilerOptions.out) && !fileExtensionIs(sourceFile.fileName, ".js")) { + return true; + } + return false; + } + return false; + } + + export function getAllAccessorDeclarations(declarations: NodeArray, accessor: AccessorDeclaration) { + let firstAccessor: AccessorDeclaration; + let secondAccessor: AccessorDeclaration; + let getAccessor: AccessorDeclaration; + let setAccessor: AccessorDeclaration; + if (hasDynamicName(accessor)) { + firstAccessor = accessor; + if (accessor.kind === SyntaxKind.GetAccessor) { + getAccessor = accessor; + } + else if (accessor.kind === SyntaxKind.SetAccessor) { + setAccessor = accessor; + } + else { + Debug.fail("Accessor has wrong kind"); + } + } + else { + forEach(declarations, (member: Declaration) => { + if ((member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) + && (member.flags & NodeFlags.Static) === (accessor.flags & NodeFlags.Static)) { + let memberName = getPropertyNameForPropertyNameNode(member.name); + let accessorName = getPropertyNameForPropertyNameNode(accessor.name); + if (memberName === accessorName) { + if (!firstAccessor) { + firstAccessor = member; + } + else if (!secondAccessor) { + secondAccessor = member; + } + + if (member.kind === SyntaxKind.GetAccessor && !getAccessor) { + getAccessor = member; + } + + if (member.kind === SyntaxKind.SetAccessor && !setAccessor) { + setAccessor = member; + } + } + } + }); + } + return { + firstAccessor, + secondAccessor, + getAccessor, + setAccessor + }; + } + + export function emitNewLineBeforeLeadingComments(currentSourceFile: SourceFile, writer: EmitTextWriter, node: TextRange, leadingComments: CommentRange[]) { + // If the leading comments start on different line than the start of node, write new line + if (leadingComments && leadingComments.length && node.pos !== leadingComments[0].pos && + getLineOfLocalPosition(currentSourceFile, node.pos) !== getLineOfLocalPosition(currentSourceFile, leadingComments[0].pos)) { + writer.writeLine(); + } + } + + export function emitComments(currentSourceFile: SourceFile, writer: EmitTextWriter, comments: CommentRange[], trailingSeparator: boolean, newLine: string, + writeComment: (currentSourceFile: SourceFile, writer: EmitTextWriter, comment: CommentRange, newLine: string) => void) { + let emitLeadingSpace = !trailingSeparator; + forEach(comments, comment => { + if (emitLeadingSpace) { + writer.write(" "); + emitLeadingSpace = false; + } + writeComment(currentSourceFile, writer, comment, newLine); + if (comment.hasTrailingNewLine) { + writer.writeLine(); + } + else if (trailingSeparator) { + writer.write(" "); + } + else { + // Emit leading space to separate comment during next comment emit + emitLeadingSpace = true; + } + }); + } + + export function writeCommentRange(currentSourceFile: SourceFile, writer: EmitTextWriter, comment: CommentRange, newLine: string) { + if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) { + let firstCommentLineAndCharacter = getLineAndCharacterOfPosition(currentSourceFile, comment.pos); + let lineCount = getLineStarts(currentSourceFile).length; + let firstCommentLineIndent: number; + for (let pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) { + let nextLineStart = (currentLine + 1) === lineCount + ? currentSourceFile.text.length + 1 + : getStartPositionOfLine(currentLine + 1, currentSourceFile); + + if (pos !== comment.pos) { + // If we are not emitting first line, we need to write the spaces to adjust the alignment + if (firstCommentLineIndent === undefined) { + firstCommentLineIndent = calculateIndent(getStartPositionOfLine(firstCommentLineAndCharacter.line, currentSourceFile), comment.pos); + } + + // These are number of spaces writer is going to write at current indent + let currentWriterIndentSpacing = writer.getIndent() * getIndentSize(); + + // Number of spaces we want to be writing + // eg: Assume writer indent + // module m { + // /* starts at character 9 this is line 1 + // * starts at character pos 4 line --1 = 8 - 8 + 3 + // More left indented comment */ --2 = 8 - 8 + 2 + // class c { } + // } + // module m { + // /* this is line 1 -- Assume current writer indent 8 + // * line --3 = 8 - 4 + 5 + // More right indented comment */ --4 = 8 - 4 + 11 + // class c { } + // } + let spacesToEmit = currentWriterIndentSpacing - firstCommentLineIndent + calculateIndent(pos, nextLineStart); + if (spacesToEmit > 0) { + let numberOfSingleSpacesToEmit = spacesToEmit % getIndentSize(); + let indentSizeSpaceString = getIndentString((spacesToEmit - numberOfSingleSpacesToEmit) / getIndentSize()); + + // Write indent size string ( in eg 1: = "", 2: "" , 3: string with 8 spaces 4: string with 12 spaces + writer.rawWrite(indentSizeSpaceString); + + // Emit the single spaces (in eg: 1: 3 spaces, 2: 2 spaces, 3: 1 space, 4: 3 spaces) + while (numberOfSingleSpacesToEmit) { + writer.rawWrite(" "); + numberOfSingleSpacesToEmit--; + } + } + else { + // No spaces to emit write empty string + writer.rawWrite(""); + } + } + + // Write the comment line text + writeTrimmedCurrentLine(pos, nextLineStart); + + pos = nextLineStart; + } + } + else { + // Single line comment of style //.... + writer.write(currentSourceFile.text.substring(comment.pos, comment.end)); + } + + function writeTrimmedCurrentLine(pos: number, nextLineStart: number) { + let end = Math.min(comment.end, nextLineStart - 1); + let currentLineText = currentSourceFile.text.substring(pos, end).replace(/^\s+|\s+$/g, ''); + if (currentLineText) { + // trimmed forward and ending spaces text + writer.write(currentLineText); + if (end !== comment.end) { + writer.writeLine(); + } + } + else { + // Empty string - make sure we write empty line + writer.writeLiteral(newLine); + } + } + + function calculateIndent(pos: number, end: number) { + let currentLineIndent = 0; + for (; pos < end && isWhiteSpace(currentSourceFile.text.charCodeAt(pos)); pos++) { + if (currentSourceFile.text.charCodeAt(pos) === CharacterCodes.tab) { + // Tabs = TabSize = indent size and go to next tabStop + currentLineIndent += getIndentSize() - (currentLineIndent % getIndentSize()); + } + else { + // Single space + currentLineIndent++; + } + } + + return currentLineIndent; + } + } + } diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index d8b7c358a5548..5d488259a365b 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -620,7 +620,7 @@ module FourSlash { this.scenarioActions.push(''); var members = this.getMemberListAtCaret(); - if (members.entries.filter(e => e.name === symbol).length !== 0) { + if (members && members.entries.filter(e => e.name === symbol).length !== 0) { this.raiseError('Member list did contain ' + symbol); } } @@ -691,7 +691,12 @@ module FourSlash { public verifyCompletionListContains(symbol: string, text?: string, documentation?: string, kind?: string) { var completions = this.getCompletionListAtCaret(); - this.assertItemInCompletionList(completions.entries, symbol, text, documentation, kind); + if (completions) { + this.assertItemInCompletionList(completions.entries, symbol, text, documentation, kind); + } + else { + this.raiseError(`No completions at position '${ this.currentCaretPosition }' when looking for '${ symbol }'.`); + } } public verifyCompletionListDoesNotContain(symbol: string) { @@ -699,7 +704,7 @@ module FourSlash { this.scenarioActions.push(''); var completions = this.getCompletionListAtCaret(); - if (completions && completions.entries && completions.entries.filter(e => e.name === symbol).length !== 0) { + if (completions && completions.entries.filter(e => e.name === symbol).length !== 0) { this.raiseError('Completion list did contain ' + symbol); } } @@ -1621,8 +1626,9 @@ module FourSlash { this.taoInvalidReason = 'verifyIndentationAtCurrentPosition NYI'; var actual = this.getIndentation(this.activeFile.fileName, this.currentCaretPosition); - if (actual != numberOfSpaces) { - this.raiseError('verifyIndentationAtCurrentPosition failed - expected: ' + numberOfSpaces + ', actual: ' + actual); + var lineCol = this.getLineColStringAtPosition(this.currentCaretPosition); + if (actual !== numberOfSpaces) { + this.raiseError('verifyIndentationAtCurrentPosition failed at ' + lineCol + ' - expected: ' + numberOfSpaces + ', actual: ' + actual); } } @@ -1630,8 +1636,9 @@ module FourSlash { this.taoInvalidReason = 'verifyIndentationAtPosition NYI'; var actual = this.getIndentation(fileName, position); + var lineCol = this.getLineColStringAtPosition(position); if (actual !== numberOfSpaces) { - this.raiseError('verifyIndentationAtPosition failed - expected: ' + numberOfSpaces + ', actual: ' + actual); + this.raiseError('verifyIndentationAtPosition failed at ' + lineCol + ' - expected: ' + numberOfSpaces + ', actual: ' + actual); } } diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 68ac8d916fbcc..299ba52bdebd9 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -330,6 +330,9 @@ module Harness.LanguageService { getReferencesAtPosition(fileName: string, position: number): ts.ReferenceEntry[] { return unwrapJSONCallResult(this.shim.getReferencesAtPosition(fileName, position)); } + findReferences(fileName: string, position: number): ts.ReferencedSymbol[] { + return unwrapJSONCallResult(this.shim.findReferences(fileName, position)); + } getOccurrencesAtPosition(fileName: string, position: number): ts.ReferenceEntry[] { return unwrapJSONCallResult(this.shim.getOccurrencesAtPosition(fileName, position)); } diff --git a/src/lib/core.d.ts b/src/lib/core.d.ts index 040eb69ae9613..2096fa839dfcc 100644 --- a/src/lib/core.d.ts +++ b/src/lib/core.d.ts @@ -1155,3 +1155,17 @@ interface ArrayConstructor { } declare var Array: ArrayConstructor; + +interface TypedPropertyDescriptor { + enumerable?: boolean; + configurable?: boolean; + writable?: boolean; + value?: T; + get?: () => T; + set?: (value: T) => void; +} + +declare type ClassDecorator = (target: TFunction) => TFunction | void; +declare type PropertyDecorator = (target: Object, propertyKey: string | symbol) => void; +declare type MethodDecorator = (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void; +declare type ParameterDecorator = (target: Function, propertyKey: string | symbol, parameterIndex: number) => void; diff --git a/src/server/client.ts b/src/server/client.ts index c8e7f2fdcb1a6..875e3ffdb5b7b 100644 --- a/src/server/client.ts +++ b/src/server/client.ts @@ -46,21 +46,21 @@ module ts.server { return lineMap; } - private lineColToPosition(fileName: string, lineCol: protocol.Location): number { - return ts.computePositionOfLineAndCharacter(this.getLineMap(fileName), lineCol.line - 1, lineCol.col - 1); + private lineOffsetToPosition(fileName: string, lineOffset: protocol.Location): number { + return ts.computePositionOfLineAndCharacter(this.getLineMap(fileName), lineOffset.line - 1, lineOffset.offset - 1); } - private positionToOneBasedLineCol(fileName: string, position: number): protocol.Location { - var lineCol = ts.computeLineAndCharacterOfPosition(this.getLineMap(fileName), position); + private positionToOneBasedLineOffset(fileName: string, position: number): protocol.Location { + var lineOffset = ts.computeLineAndCharacterOfPosition(this.getLineMap(fileName), position); return { - line: lineCol.line + 1, - col: lineCol.character + 1 + line: lineOffset.line + 1, + offset: lineOffset.character + 1 }; } private convertCodeEditsToTextChange(fileName: string, codeEdit: protocol.CodeEdit): ts.TextChange { - var start = this.lineColToPosition(fileName, codeEdit.start); - var end = this.lineColToPosition(fileName, codeEdit.end); + var start = this.lineOffsetToPosition(fileName, codeEdit.start); + var end = this.lineOffsetToPosition(fileName, codeEdit.end); return { span: ts.createTextSpanFromBounds(start, end), @@ -134,15 +134,15 @@ module ts.server { // clear the line map after an edit this.lineMaps[fileName] = undefined; - var lineCol = this.positionToOneBasedLineCol(fileName, start); - var endLineCol = this.positionToOneBasedLineCol(fileName, end); + var lineOffset = this.positionToOneBasedLineOffset(fileName, start); + var endLineOffset = this.positionToOneBasedLineOffset(fileName, end); var args: protocol.ChangeRequestArgs = { file: fileName, - line: lineCol.line, - col: lineCol.col, - endLine: endLineCol.line, - endCol: endLineCol.col, + line: lineOffset.line, + offset: lineOffset.offset, + endLine: endLineOffset.line, + endOffset: endLineOffset.offset, insertString: newText }; @@ -150,18 +150,18 @@ module ts.server { } getQuickInfoAtPosition(fileName: string, position: number): QuickInfo { - var lineCol = this.positionToOneBasedLineCol(fileName, position); + var lineOffset = this.positionToOneBasedLineOffset(fileName, position); var args: protocol.FileLocationRequestArgs = { file: fileName, - line: lineCol.line, - col: lineCol.col + line: lineOffset.line, + offset: lineOffset.offset }; var request = this.processRequest(CommandNames.Quickinfo, args); var response = this.processResponse(request); - var start = this.lineColToPosition(fileName, response.body.start); - var end = this.lineColToPosition(fileName, response.body.end); + var start = this.lineOffsetToPosition(fileName, response.body.start); + var end = this.lineOffsetToPosition(fileName, response.body.end); return { kind: response.body.kind, @@ -173,11 +173,11 @@ module ts.server { } getCompletionsAtPosition(fileName: string, position: number): CompletionInfo { - var lineCol = this.positionToOneBasedLineCol(fileName, position); + var lineOffset = this.positionToOneBasedLineOffset(fileName, position); var args: protocol.CompletionsRequestArgs = { file: fileName, - line: lineCol.line, - col: lineCol.col, + line: lineOffset.line, + offset: lineOffset.offset, prefix: undefined }; @@ -194,11 +194,11 @@ module ts.server { } getCompletionEntryDetails(fileName: string, position: number, entryName: string): CompletionEntryDetails { - var lineCol = this.positionToOneBasedLineCol(fileName, position); + var lineOffset = this.positionToOneBasedLineOffset(fileName, position); var args: protocol.CompletionDetailsRequestArgs = { file: fileName, - line: lineCol.line, - col: lineCol.col, + line: lineOffset.line, + offset: lineOffset.offset, entryNames: [entryName] }; @@ -219,8 +219,8 @@ module ts.server { return response.body.map(entry => { var fileName = entry.file; - var start = this.lineColToPosition(fileName, entry.start); - var end = this.lineColToPosition(fileName, entry.end); + var start = this.lineOffsetToPosition(fileName, entry.start); + var end = this.lineOffsetToPosition(fileName, entry.end); return { name: entry.name, @@ -237,14 +237,14 @@ module ts.server { } getFormattingEditsForRange(fileName: string, start: number, end: number, options: ts.FormatCodeOptions): ts.TextChange[] { - var startLineCol = this.positionToOneBasedLineCol(fileName, start); - var endLineCol = this.positionToOneBasedLineCol(fileName, end); + var startLineOffset = this.positionToOneBasedLineOffset(fileName, start); + var endLineOffset = this.positionToOneBasedLineOffset(fileName, end); var args: protocol.FormatRequestArgs = { file: fileName, - line: startLineCol.line, - col: startLineCol.col, - endLine: endLineCol.line, - endCol: endLineCol.col, + line: startLineOffset.line, + offset: startLineOffset.offset, + endLine: endLineOffset.line, + endOffset: endLineOffset.offset, }; // TODO: handle FormatCodeOptions @@ -259,11 +259,11 @@ module ts.server { } getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions): ts.TextChange[] { - var lineCol = this.positionToOneBasedLineCol(fileName, position); + var lineOffset = this.positionToOneBasedLineOffset(fileName, position); var args: protocol.FormatOnKeyRequestArgs = { file: fileName, - line: lineCol.line, - col: lineCol.col, + line: lineOffset.line, + offset: lineOffset.offset, key: key }; @@ -275,11 +275,11 @@ module ts.server { } getDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[] { - var lineCol = this.positionToOneBasedLineCol(fileName, position); + var lineOffset = this.positionToOneBasedLineOffset(fileName, position); var args: protocol.FileLocationRequestArgs = { file: fileName, - line: lineCol.line, - col: lineCol.col, + line: lineOffset.line, + offset: lineOffset.offset, }; var request = this.processRequest(CommandNames.Definition, args); @@ -287,8 +287,8 @@ module ts.server { return response.body.map(entry => { var fileName = entry.file; - var start = this.lineColToPosition(fileName, entry.start); - var end = this.lineColToPosition(fileName, entry.end); + var start = this.lineOffsetToPosition(fileName, entry.start); + var end = this.lineOffsetToPosition(fileName, entry.end); return { containerKind: "", containerName: "", @@ -300,12 +300,17 @@ module ts.server { }); } + findReferences(fileName: string, position: number): ReferencedSymbol[]{ + // Not yet implemented. + return []; + } + getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[] { - var lineCol = this.positionToOneBasedLineCol(fileName, position); + var lineOffset = this.positionToOneBasedLineOffset(fileName, position); var args: protocol.FileLocationRequestArgs = { file: fileName, - line: lineCol.line, - col: lineCol.col, + line: lineOffset.line, + offset: lineOffset.offset, }; var request = this.processRequest(CommandNames.References, args); @@ -313,8 +318,8 @@ module ts.server { return response.body.refs.map(entry => { var fileName = entry.file; - var start = this.lineColToPosition(fileName, entry.start); - var end = this.lineColToPosition(fileName, entry.end); + var start = this.lineOffsetToPosition(fileName, entry.start); + var end = this.lineOffsetToPosition(fileName, entry.end); return { fileName: fileName, textSpan: ts.createTextSpanFromBounds(start, end), @@ -340,11 +345,11 @@ module ts.server { } getRenameInfo(fileName: string, position: number, findInStrings?: boolean, findInComments?: boolean): RenameInfo { - var lineCol = this.positionToOneBasedLineCol(fileName, position); + var lineOffset = this.positionToOneBasedLineOffset(fileName, position); var args: protocol.RenameRequestArgs = { file: fileName, - line: lineCol.line, - col: lineCol.col, + line: lineOffset.line, + offset: lineOffset.offset, findInStrings, findInComments }; @@ -355,8 +360,8 @@ module ts.server { response.body.locs.map((entry: protocol.SpanGroup) => { var fileName = entry.file; entry.locs.map((loc: protocol.TextSpan) => { - var start = this.lineColToPosition(fileName, loc.start); - var end = this.lineColToPosition(fileName, loc.end); + var start = this.lineOffsetToPosition(fileName, loc.start); + var end = this.lineOffsetToPosition(fileName, loc.end); locations.push({ textSpan: ts.createTextSpanFromBounds(start, end), fileName: fileName @@ -400,7 +405,7 @@ module ts.server { text: item.text, kind: item.kind, kindModifiers: item.kindModifiers || "", - spans: item.spans.map(span=> createTextSpanFromBounds(this.lineColToPosition(fileName, span.start), this.lineColToPosition(fileName, span.end))), + spans: item.spans.map(span=> createTextSpanFromBounds(this.lineOffsetToPosition(fileName, span.start), this.lineOffsetToPosition(fileName, span.end))), childItems: this.decodeNavigationBarItems(item.childItems, fileName), indent: 0, bolded: false, @@ -444,19 +449,19 @@ module ts.server { } getBraceMatchingAtPosition(fileName: string, position: number): TextSpan[] { - var lineCol = this.positionToOneBasedLineCol(fileName, position); + var lineOffset = this.positionToOneBasedLineOffset(fileName, position); var args: protocol.FileLocationRequestArgs = { file: fileName, - line: lineCol.line, - col: lineCol.col, + line: lineOffset.line, + offset: lineOffset.offset, }; var request = this.processRequest(CommandNames.Brace, args); var response = this.processResponse(request); return response.body.map(entry => { - var start = this.lineColToPosition(fileName, entry.start); - var end = this.lineColToPosition(fileName, entry.end); + var start = this.lineOffsetToPosition(fileName, entry.start); + var end = this.lineOffsetToPosition(fileName, entry.end); return { start: start, length: end - start, diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 7c9ccfa785464..034549ab464fe 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -19,15 +19,23 @@ module ts.server { class ScriptInfo { svc: ScriptVersionCache; children: ScriptInfo[] = []; // files referenced by this file - defaultProject: Project; // project to use by default for file - fileWatcher: FileWatcher; + formatCodeOptions = ts.clone(CompilerService.defaultFormatCodeOptions); constructor(private host: ServerHost, public fileName: string, public content: string, public isOpen = false) { this.svc = ScriptVersionCache.fromString(content); } + setFormatOptions(tabSize?: number, indentSize?: number) { + if (tabSize) { + this.formatCodeOptions.TabSize = tabSize; + } + if (indentSize) { + this.formatCodeOptions.IndentSize = indentSize; + } + } + close() { this.isOpen = false; } @@ -200,33 +208,33 @@ module ts.server { } else { var nextLineInfo = index.lineNumberToInfo(line + 2); - len = nextLineInfo.col - lineInfo.col; + len = nextLineInfo.offset - lineInfo.offset; } - return ts.createTextSpan(lineInfo.col, len); + return ts.createTextSpan(lineInfo.offset, len); } /** * @param line 1 based index - * @param col 1 based index + * @param offset 1 based index */ - lineColToPosition(filename: string, line: number, col: number): number { + lineOffsetToPosition(filename: string, line: number, offset: number): number { var script: ScriptInfo = this.filenameToScript[filename]; var index = script.snap().index; var lineInfo = index.lineNumberToInfo(line); - // TODO: assert this column is actually on the line - return (lineInfo.col + col - 1); + // TODO: assert this offset is actually on the line + return (lineInfo.offset + offset - 1); } /** * @param line 1-based index - * @param col 1-based index + * @param offset 1-based index */ - positionToLineCol(filename: string, position: number): ILineInfo { + positionToLineOffset(filename: string, position: number): ILineInfo { var script: ScriptInfo = this.filenameToScript[filename]; var index = script.snap().index; - var lineCol = index.charOffsetToLineNumberAndPos(position); - return { line: lineCol.line, col: lineCol.col + 1 }; + var lineOffset = index.charOffsetToLineNumberAndPos(position); + return { line: lineOffset.line, offset: lineOffset.offset + 1 }; } } @@ -259,20 +267,29 @@ module ts.server { interface ProjectOptions { // these fields can be present in the project file files?: string[]; - formatCodeOptions?: ts.FormatCodeOptions; compilerOptions?: ts.CompilerOptions; } export class Project { compilerService: CompilerService; - projectOptions: ProjectOptions; projectFilename: string; program: ts.Program; filenameToSourceFile: ts.Map = {}; updateGraphSeq = 0; + /** Used for configured projects which may have multiple open roots */ + openRefCount = 0; - constructor(public projectService: ProjectService) { - this.compilerService = new CompilerService(this); + constructor(public projectService: ProjectService, public projectOptions?: ProjectOptions) { + this.compilerService = new CompilerService(this,projectOptions && projectOptions.compilerOptions); + } + + addOpenRef() { + this.openRefCount++; + } + + deleteOpenRef() { + this.openRefCount--; + return this.openRefCount; } openReferencedFile(filename: string) { @@ -292,6 +309,10 @@ module ts.server { } } + isRoot(info: ScriptInfo) { + return this.compilerService.host.roots.some(root => root === info); + } + removeReferencedFile(info: ScriptInfo) { this.compilerService.host.removeReferencedFile(info); this.updateGraph(); @@ -338,7 +359,6 @@ module ts.server { if (projectOptions.compilerOptions) { this.compilerService.setCompilerOptions(projectOptions.compilerOptions); } - // TODO: format code options } } @@ -362,16 +382,45 @@ module ts.server { (eventName: string, project: Project, fileName: string): void; } + interface HostConfiguration { + formatCodeOptions: ts.FormatCodeOptions; + hostInfo: string; + } + export class ProjectService { filenameToScriptInfo: ts.Map = {}; - // open, non-configured files in two lists + // open, non-configured root files openFileRoots: ScriptInfo[] = []; - openFilesReferenced: ScriptInfo[] = []; - // projects covering open files + // projects built from openFileRoots inferredProjects: Project[] = []; + // projects specified by a tsconfig.json file + configuredProjects: Project[] = []; + // open files referenced by a project + openFilesReferenced: ScriptInfo[] = []; + // open files that are roots of a configured project + openFileRootsConfigured: ScriptInfo[] = []; + hostConfiguration: HostConfiguration; constructor(public host: ServerHost, public psLogger: Logger, public eventHandler?: ProjectServiceEventHandler) { // ts.disableIncrementalParsing = true; + this.addDefaultHostConfiguration(); + } + + addDefaultHostConfiguration() { + this.hostConfiguration = { + formatCodeOptions: ts.clone(CompilerService.defaultFormatCodeOptions), + hostInfo: "Unknown host" + } + } + + getFormatCodeOptions(file?: string) { + if (file) { + var info = this.filenameToScriptInfo[file]; + if (info) { + return info.formatCodeOptions; + } + } + return this.hostConfiguration.formatCodeOptions; } watchedFileChanged(fileName: string) { @@ -395,6 +444,22 @@ module ts.server { this.psLogger.msg(msg, type); } + setHostConfiguration(args: ts.server.protocol.ConfigureRequestArguments) { + if (args.file) { + var info = this.filenameToScriptInfo[args.file]; + if (info) { + info.setFormatOptions(args.tabSize, args.indentSize); + this.log("Host configuration update for file " + args.file + " tab size " + args.tabSize); + } + } + else { + this.hostConfiguration.formatCodeOptions.TabSize = args.tabSize; + this.hostConfiguration.formatCodeOptions.IndentSize = args.indentSize; + this.hostConfiguration.hostInfo = args.hostInfo; + this.log("Host information " + args.hostInfo, "Info"); + } + } + closeLog() { this.psLogger.close(); } @@ -438,44 +503,77 @@ module ts.server { this.printProjects(); } + updateConfiguredProjectList() { + var configuredProjects: Project[] = []; + for (var i = 0, len = this.configuredProjects.length; i < len; i++) { + if (this.configuredProjects[i].openRefCount > 0) { + configuredProjects.push(this.configuredProjects[i]); + } + } + this.configuredProjects = configuredProjects; + } + + setConfiguredProjectRoot(info: ScriptInfo) { + for (var i = 0, len = this.configuredProjects.length; i < len; i++) { + let configuredProject = this.configuredProjects[i]; + if (configuredProject.isRoot(info)) { + info.defaultProject = configuredProject; + configuredProject.addOpenRef(); + return true; + } + } + return false; + } + addOpenFile(info: ScriptInfo) { - this.findReferencingProjects(info); - if (info.defaultProject) { - this.openFilesReferenced.push(info); + if (this.setConfiguredProjectRoot(info)) { + this.openFileRootsConfigured.push(info); } else { - // create new inferred project p with the newly opened file as root - info.defaultProject = this.createInferredProject(info); - var openFileRoots: ScriptInfo[] = []; - // for each inferred project root r - for (var i = 0, len = this.openFileRoots.length; i < len; i++) { - var r = this.openFileRoots[i]; - // if r referenced by the new project - if (info.defaultProject.getSourceFile(r)) { - // remove project rooted at r - this.inferredProjects = - copyListRemovingItem(r.defaultProject, this.inferredProjects); - // put r in referenced open file list - this.openFilesReferenced.push(r); - // set default project of r to the new project - r.defaultProject = info.defaultProject; - } - else { - // otherwise, keep r as root of inferred project - openFileRoots.push(r); + this.findReferencingProjects(info); + if (info.defaultProject) { + this.openFilesReferenced.push(info); + } + else { + // create new inferred project p with the newly opened file as root + info.defaultProject = this.createInferredProject(info); + var openFileRoots: ScriptInfo[] = []; + // for each inferred project root r + for (var i = 0, len = this.openFileRoots.length; i < len; i++) { + var r = this.openFileRoots[i]; + // if r referenced by the new project + if (info.defaultProject.getSourceFile(r)) { + // remove project rooted at r + this.inferredProjects = + copyListRemovingItem(r.defaultProject, this.inferredProjects); + // put r in referenced open file list + this.openFilesReferenced.push(r); + // set default project of r to the new project + r.defaultProject = info.defaultProject; + } + else { + // otherwise, keep r as root of inferred project + openFileRoots.push(r); + } } + this.openFileRoots = openFileRoots; + this.openFileRoots.push(info); } - this.openFileRoots = openFileRoots; - this.openFileRoots.push(info); } + this.updateConfiguredProjectList(); } + /** + * Remove this file from the set of open, non-configured files. + * @param info The file that has been closed or newly configured + * @param openedByConfig True if info has become a root of a configured project + */ closeOpenFile(info: ScriptInfo) { var openFileRoots: ScriptInfo[] = []; var removedProject: Project; for (var i = 0, len = this.openFileRoots.length; i < len; i++) { // if closed file is root of project - if (info == this.openFileRoots[i]) { + if (info === this.openFileRoots[i]) { // remove that project and remember it removedProject = info.defaultProject; } @@ -484,9 +582,29 @@ module ts.server { } } this.openFileRoots = openFileRoots; + if (!removedProject) { + var openFileRootsConfigured: ScriptInfo[] = []; + + for (var i = 0, len = this.openFileRootsConfigured.length; i < len; i++) { + if (info === this.openFileRootsConfigured[i]) { + if (info.defaultProject.deleteOpenRef() === 0) { + removedProject = info.defaultProject; + } + } + else { + openFileRootsConfigured.push(this.openFileRootsConfigured[i]); + } + } + + this.openFileRootsConfigured = openFileRootsConfigured; + } if (removedProject) { - // remove project from inferred projects list - this.inferredProjects = copyListRemovingItem(removedProject, this.inferredProjects); + if (removedProject.isConfiguredProject()) { + this.configuredProjects = copyListRemovingItem(removedProject, this.configuredProjects); + } + else { + this.inferredProjects = copyListRemovingItem(removedProject, this.inferredProjects); + } var openFilesReferenced: ScriptInfo[] = []; var orphanFiles: ScriptInfo[] = []; // for all open, referenced files f @@ -518,14 +636,22 @@ module ts.server { var referencingProjects: Project[] = []; info.defaultProject = undefined; for (var i = 0, len = this.inferredProjects.length; i < len; i++) { - this.inferredProjects[i].updateGraph(); - if (this.inferredProjects[i] != excludedProject) { - if (this.inferredProjects[i].getSourceFile(info)) { - info.defaultProject = this.inferredProjects[i]; - referencingProjects.push(this.inferredProjects[i]); + var inferredProject = this.inferredProjects[i]; + inferredProject.updateGraph(); + if (inferredProject != excludedProject) { + if (inferredProject.getSourceFile(info)) { + info.defaultProject = inferredProject; + referencingProjects.push(inferredProject); } } } + for (var i = 0, len = this.configuredProjects.length; i < len; i++) { + var configuredProject = this.configuredProjects[i]; + configuredProject.updateGraph(); + if (configuredProject.getSourceFile(info)) { + info.defaultProject = configuredProject; + } + } return referencingProjects; } @@ -595,7 +721,7 @@ module ts.server { /** * @param filename is absolute pathname */ - openFile(fileName: string, openedByClient = false) { + openFile(fileName: string, openedByClient: boolean) { fileName = ts.normalizePath(fileName); var info = ts.lookUp(this.filenameToScriptInfo, fileName); if (!info) { @@ -609,6 +735,7 @@ module ts.server { } } if (content !== undefined) { + var indentSize: number; info = new ScriptInfo(this.host, fileName, content, openedByClient); this.filenameToScriptInfo[fileName] = info; if (!info.isOpen) { @@ -629,9 +756,23 @@ module ts.server { * @param filename is absolute pathname */ - openClientFile(filename: string) { - // TODO: tsconfig check - var info = this.openFile(filename, true); + openClientFile(fileName: string) { + var searchPath = ts.normalizePath(getDirectoryPath(fileName)); + var configFileName = ts.findConfigFile(searchPath); + if (configFileName) { + configFileName = getAbsolutePath(configFileName, searchPath); + } + if (configFileName && (!this.configProjectIsActive(configFileName))) { + var configResult = this.openConfigFile(configFileName, fileName); + if (!configResult.success) { + this.log("Error opening config file " + configFileName + " " + configResult.errorMsg); + } + else { + this.log("Opened configuration file " + configFileName,"Info"); + this.configuredProjects.push(configResult.project); + } + } + var info = this.openFile(fileName, true); this.addOpenFile(info); this.printProjects(); return info; @@ -652,19 +793,6 @@ module ts.server { this.printProjects(); } - getProjectsReferencingFile(filename: string) { - var scriptInfo = ts.lookUp(this.filenameToScriptInfo, filename); - if (scriptInfo) { - var projects: Project[] = []; - for (var i = 0, len = this.inferredProjects.length; i < len; i++) { - if (this.inferredProjects[i].getSourceFile(scriptInfo)) { - projects.push(this.inferredProjects[i]); - } - } - return projects; - } - } - getProjectForFile(filename: string) { var scriptInfo = ts.lookUp(this.filenameToScriptInfo, filename); if (scriptInfo) { @@ -677,9 +805,9 @@ module ts.server { if (scriptInfo) { this.psLogger.startGroup(); this.psLogger.info("Projects for " + filename) - var projects = this.getProjectsReferencingFile(filename); + var projects = this.findReferencingProjects(scriptInfo); for (var i = 0, len = projects.length; i < len; i++) { - this.psLogger.info("Inferred Project " + i.toString()); + this.psLogger.info("Project " + i.toString()); } this.psLogger.endGroup(); } @@ -697,18 +825,42 @@ module ts.server { this.psLogger.info(project.filesToString()); this.psLogger.info("-----------------------------------------------"); } - this.psLogger.info("Open file roots: ") + for (var i = 0, len = this.configuredProjects.length; i < len; i++) { + var project = this.configuredProjects[i]; + project.updateGraph(); + this.psLogger.info("Project (configured) " + (i+this.inferredProjects.length).toString()); + this.psLogger.info(project.filesToString()); + this.psLogger.info("-----------------------------------------------"); + } + this.psLogger.info("Open file roots of inferred projects: ") for (var i = 0, len = this.openFileRoots.length; i < len; i++) { this.psLogger.info(this.openFileRoots[i].fileName); } - this.psLogger.info("Open files referenced: ") + this.psLogger.info("Open files referenced by inferred or configured projects: ") for (var i = 0, len = this.openFilesReferenced.length; i < len; i++) { - this.psLogger.info(this.openFilesReferenced[i].fileName); + var fileInfo = this.openFilesReferenced[i].fileName; + if (this.openFilesReferenced[i].defaultProject.isConfiguredProject()) { + fileInfo += " (configured)"; + } + this.psLogger.info(fileInfo); + } + this.psLogger.info("Open file roots of configured projects: ") + for (var i = 0, len = this.openFileRootsConfigured.length; i < len; i++) { + this.psLogger.info(this.openFileRootsConfigured[i].fileName); } this.psLogger.endGroup(); } - openConfigFile(configFilename: string): ProjectOpenResult { + configProjectIsActive(fileName: string) { + for (var i = 0, len = this.configuredProjects.length; i < len; i++) { + if (this.configuredProjects[i].projectFilename == fileName) { + return true; + } + } + return false; + } + + openConfigFile(configFilename: string, clientFileName?: string): ProjectOpenResult { configFilename = ts.normalizePath(configFilename); // file references will be relative to dirPath (or absolute) var dirPath = ts.getDirectoryPath(configFilename); @@ -717,35 +869,27 @@ module ts.server { return { errorMsg: "tsconfig syntax error" }; } else { - // REVIEW: specify no base path so can get absolute path below - var parsedCommandLine = ts.parseConfigFile(rawConfig); - - if (parsedCommandLine.errors) { - // TODO: gather diagnostics and transmit + var parsedCommandLine = ts.parseConfigFile(rawConfig, dirPath); + if (parsedCommandLine.errors && (parsedCommandLine.errors.length > 0)) { return { errorMsg: "tsconfig option errors" }; } else if (parsedCommandLine.fileNames) { - var proj = this.createProject(configFilename); + var projectOptions: ProjectOptions = { + files: parsedCommandLine.fileNames, + compilerOptions: parsedCommandLine.options + }; + var proj = this.createProject(configFilename, projectOptions); for (var i = 0, len = parsedCommandLine.fileNames.length; i < len; i++) { var rootFilename = parsedCommandLine.fileNames[i]; - var normRootFilename = ts.normalizePath(rootFilename); - normRootFilename = getAbsolutePath(normRootFilename, dirPath); - if (this.host.fileExists(normRootFilename)) { - var info = this.openFile(normRootFilename); + if (ts.sys.fileExists(rootFilename)) { + var info = this.openFile(rootFilename, clientFileName == rootFilename); proj.addRoot(info); } else { return { errorMsg: "specified file " + rootFilename + " not found" }; } } - var projectOptions: ProjectOptions = { - files: parsedCommandLine.fileNames, - compilerOptions: parsedCommandLine.options - }; - if (rawConfig.formatCodeOptions) { - projectOptions.formatCodeOptions = rawConfig.formatCodeOptions; - } - proj.setProjectOptions(projectOptions); + proj.finishGraph(); return { success: true, project: proj }; } else { @@ -754,10 +898,10 @@ module ts.server { } } - createProject(projectFilename: string) { - var eproj = new Project(this); - eproj.projectFilename = projectFilename; - return eproj; + createProject(projectFilename: string, projectOptions?: ProjectOptions) { + var project = new Project(this, projectOptions); + project.projectFilename = projectFilename; + return project; } } @@ -766,15 +910,17 @@ module ts.server { host: LSHost; languageService: ts.LanguageService; classifier: ts.Classifier; - settings = ts.getDefaultCompilerOptions(); + settings: ts.CompilerOptions; documentRegistry = ts.createDocumentRegistry(); - formatCodeOptions: ts.FormatCodeOptions = CompilerService.defaultFormatCodeOptions; - constructor(public project: Project) { + constructor(public project: Project, opt?: ts.CompilerOptions) { this.host = new LSHost(project.projectService.host, project); - // override default ES6 (remove when compiler default back at ES5) - this.settings.target = ts.ScriptTarget.ES5; - this.host.setCompilationSettings(this.settings); + if (opt) { + this.setCompilerOptions(opt); + } + else { + this.setCompilerOptions(ts.getDefaultCompilerOptions()); + } this.languageService = ts.createLanguageService(this.host, this.documentRegistry); this.classifier = ts.createClassifier(); } @@ -815,7 +961,7 @@ module ts.server { export interface ILineInfo { line: number; - col: number; + offset: number; text?: string; leaf?: LineLeaf; } @@ -1208,7 +1354,7 @@ module ts.server { getLineMapper() { return ((line: number) => { - return this.index.lineNumberToInfo(line).col; + return this.index.lineNumberToInfo(line).offset; }); } @@ -1245,7 +1391,7 @@ module ts.server { else { return { line: lineNumber, - col: this.root.charCount() + offset: this.root.charCount() } } } @@ -1331,7 +1477,7 @@ module ts.server { // check whether last characters deleted are line break var e = pos + deleteLength; var lineInfo = this.charOffsetToLineNumberAndPos(e); - if ((lineInfo && (lineInfo.col == 0))) { + if ((lineInfo && (lineInfo.offset == 0))) { // move range end just past line that will merge with previous line deleteLength += lineInfo.text.length; // store text by appending to end of insertedText @@ -1507,14 +1653,14 @@ module ts.server { if (!childInfo.child) { return { line: lineNumber, - col: charOffset, + offset: charOffset, } } else if (childInfo.childIndex < this.children.length) { if (childInfo.child.isLeaf()) { return { line: childInfo.lineNumber, - col: childInfo.charOffset, + offset: childInfo.charOffset, text: ((childInfo.child)).text, leaf: ((childInfo.child)) }; @@ -1526,7 +1672,7 @@ module ts.server { } else { var lineInfo = this.lineNumberToInfo(this.lineCount(), 0); - return { line: this.lineCount(), col: lineInfo.leaf.charCount() }; + return { line: this.lineCount(), offset: lineInfo.leaf.charCount() }; } } @@ -1535,13 +1681,13 @@ module ts.server { if (!childInfo.child) { return { line: lineNumber, - col: charOffset + offset: charOffset } - } + } else if (childInfo.child.isLeaf()) { return { line: lineNumber, - col: childInfo.charOffset, + offset: childInfo.charOffset, text: ((childInfo.child)).text, leaf: ((childInfo.child)) } diff --git a/src/server/protocol.d.ts b/src/server/protocol.d.ts index 23ef00d6b44c7..d63aa53ba125b 100644 --- a/src/server/protocol.d.ts +++ b/src/server/protocol.d.ts @@ -96,7 +96,7 @@ declare module ts.server.protocol { /** * Instances of this interface specify a location in a source file: - * (file, line, col), where line and column are 1-based. + * (file, line, character offset), where line and character offset are 1-based. */ export interface FileLocationRequestArgs extends FileRequestArgs { /** @@ -105,9 +105,9 @@ declare module ts.server.protocol { line: number; /** - * The column for the request (1-based). + * The character offset (on the line) for the request (1-based). */ - col: number; + offset: number; } /** @@ -126,11 +126,11 @@ declare module ts.server.protocol { } /** - * Location in source code expressed as (one-based) line and column. + * Location in source code expressed as (one-based) line and character offset. */ export interface Location { line: number; - col: number; + offset: number; } /** @@ -202,9 +202,9 @@ declare module ts.server.protocol { symbolName: string; /** - * The start column of the symbol (on the line provided by the references request). + * The start character offset of the symbol (on the line provided by the references request). */ - symbolStartCol: number; + symbolStartOffset: number; /** * The full display name of the symbol. @@ -299,6 +299,50 @@ declare module ts.server.protocol { body?: RenameResponseBody; } + /** + * Information found in a configure request. + */ + export interface ConfigureRequestArguments { + /** Number of spaces for each tab */ + tabSize: number; + /** Number of spaces to indent during formatting */ + indentSize: number; + /** + * Information about the host, for example 'Emacs 24.4' or + * 'Sublime Text version 3075' + */ + hostInfo: string; + /** + * If present, tab settings apply only to this file. + */ + file?: string; + } + + /** + * Configure request; value of command field is "configure". Specifies + * host information, such as host type, tab size, and indent size. + */ + export interface ConfigureRequest extends Request { + arguments: ConfigureRequestArguments; + } + + /** + * Response to "configure" request. This is just an acknowledgement, so + * no body field is required. + */ + export interface ConfigureResponse extends Response { + } + + /** + * Information found in an "open" request. + */ + export interface OpenRequestArgs extends FileRequestArgs { + /** Initial tab size of file. */ + tabSize?: number; + /** Number of spaces to indent during formatting */ + indentSize?: number; + } + /** * Open request; value of command field is "open". Notify the * server that the client has file open. The server will not @@ -307,7 +351,8 @@ declare module ts.server.protocol { * reload messages) when the file changes. Server does not currently * send a response to an open request. */ - export interface OpenRequest extends FileRequest { + export interface OpenRequest extends Request { + arguments: OpenRequestArgs; } /** @@ -381,9 +426,9 @@ declare module ts.server.protocol { endLine: number; /** - * Last column of range for which to format text in file. + * Character offset on last line of range for which to format text in file. */ - endCol: number; + endOffset: number; } /** @@ -762,7 +807,7 @@ declare module ts.server.protocol { */ export interface ChangeRequestArgs extends FormatRequestArgs { /** - * Optional string to insert at location (file, line, col). + * Optional string to insert at location (file, line, offset). */ insertString?: string; } @@ -786,7 +831,7 @@ declare module ts.server.protocol { /** * Brace matching request; value of command field is "brace". * Return response giving the file locations of matching braces - * found in file at location line, col. + * found in file at location line, offset. */ export interface BraceRequest extends FileLocationRequest { } diff --git a/src/server/session.ts b/src/server/session.ts index cc705d64d5e93..47ef40a880977 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -5,13 +5,13 @@ /// module ts.server { - var spaceCache = [" ", " ", " ", " "]; + var spaceCache:string[] = []; interface StackTraceError extends Error { stack?: string; } - function generateSpaces(n: number): string { + export function generateSpaces(n: number): string { if (!spaceCache[n]) { var strBuilder = ""; for (var i = 0; i < n; i++) { @@ -44,7 +44,7 @@ module ts.server { else if (a.file == b.file) { var n = compareNumber(a.start.line, b.start.line); if (n == 0) { - return compareNumber(a.start.col, b.start.col); + return compareNumber(a.start.offset, b.start.offset); } else return n; } @@ -55,8 +55,8 @@ module ts.server { function formatDiag(fileName: string, project: Project, diag: ts.Diagnostic) { return { - start: project.compilerService.host.positionToLineCol(fileName, diag.start), - end: project.compilerService.host.positionToLineCol(fileName, diag.start + diag.length), + start: project.compilerService.host.positionToLineOffset(fileName, diag.start), + end: project.compilerService.host.positionToLineOffset(fileName, diag.start + diag.length), text: ts.flattenDiagnosticMessageText(diag.messageText, "\n") }; } @@ -80,6 +80,7 @@ module ts.server { export var Close = "close"; export var Completions = "completions"; export var CompletionDetails = "completionEntryDetails"; + export var Configure = "configure"; export var Definition = "definition"; export var Format = "format"; export var Formatonkey = "formatonkey"; @@ -259,7 +260,7 @@ module ts.server { } } - getDefinition(line: number, col: number, fileName: string): protocol.FileSpan[] { + getDefinition(line: number, offset: number, fileName: string): protocol.FileSpan[] { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -267,7 +268,7 @@ module ts.server { } var compilerService = project.compilerService; - var position = compilerService.host.lineColToPosition(file, line, col); + var position = compilerService.host.lineOffsetToPosition(file, line, offset); var definitions = compilerService.languageService.getDefinitionAtPosition(file, position); if (!definitions) { @@ -276,12 +277,12 @@ module ts.server { return definitions.map(def => ({ file: def.fileName, - start: compilerService.host.positionToLineCol(def.fileName, def.textSpan.start), - end: compilerService.host.positionToLineCol(def.fileName, ts.textSpanEnd(def.textSpan)) + start: compilerService.host.positionToLineOffset(def.fileName, def.textSpan.start), + end: compilerService.host.positionToLineOffset(def.fileName, ts.textSpanEnd(def.textSpan)) })); } - getRenameLocations(line: number, col: number, fileName: string,findInComments: boolean, findInStrings: boolean): protocol.RenameResponseBody { + getRenameLocations(line: number, offset: number, fileName: string,findInComments: boolean, findInStrings: boolean): protocol.RenameResponseBody { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -289,7 +290,7 @@ module ts.server { } var compilerService = project.compilerService; - var position = compilerService.host.lineColToPosition(file, line, col); + var position = compilerService.host.lineOffsetToPosition(file, line, offset); var renameInfo = compilerService.languageService.getRenameInfo(file, position); if (!renameInfo) { return undefined; @@ -309,8 +310,8 @@ module ts.server { var bakedRenameLocs = renameLocations.map(location => ({ file: location.fileName, - start: compilerService.host.positionToLineCol(location.fileName, location.textSpan.start), - end: compilerService.host.positionToLineCol(location.fileName, ts.textSpanEnd(location.textSpan)), + start: compilerService.host.positionToLineOffset(location.fileName, location.textSpan.start), + end: compilerService.host.positionToLineOffset(location.fileName, ts.textSpanEnd(location.textSpan)), })).sort((a, b) => { if (a.file < b.file) { return -1; @@ -327,7 +328,7 @@ module ts.server { return -1; } else { - return b.start.col - a.start.col; + return b.start.offset - a.start.offset; } } }).reduce((accum: protocol.SpanGroup[], cur: protocol.FileSpan) => { @@ -349,7 +350,7 @@ module ts.server { return { info: renameInfo, locs: bakedRenameLocs }; } - getReferences(line: number, col: number, fileName: string): protocol.ReferencesResponseBody { + getReferences(line: number, offset: number, fileName: string): protocol.ReferencesResponseBody { // TODO: get all projects for this file; report refs for all projects deleting duplicates // can avoid duplicates by eliminating same ref file from subsequent projects var file = ts.normalizePath(fileName); @@ -359,7 +360,7 @@ module ts.server { } var compilerService = project.compilerService; - var position = compilerService.host.lineColToPosition(file, line, col); + var position = compilerService.host.lineOffsetToPosition(file, line, offset); var references = compilerService.languageService.getReferencesAtPosition(file, position); if (!references) { @@ -373,10 +374,10 @@ module ts.server { var displayString = ts.displayPartsToString(nameInfo.displayParts); var nameSpan = nameInfo.textSpan; - var nameColStart = compilerService.host.positionToLineCol(file, nameSpan.start).col; + var nameColStart = compilerService.host.positionToLineOffset(file, nameSpan.start).offset; var nameText = compilerService.host.getScriptSnapshot(file).getText(nameSpan.start, ts.textSpanEnd(nameSpan)); var bakedRefs: protocol.ReferencesResponseItem[] = references.map((ref) => { - var start = compilerService.host.positionToLineCol(ref.fileName, ref.textSpan.start); + var start = compilerService.host.positionToLineOffset(ref.fileName, ref.textSpan.start); var refLineSpan = compilerService.host.lineToTextSpan(ref.fileName, start.line - 1); var snap = compilerService.host.getScriptSnapshot(ref.fileName); var lineText = snap.getText(refLineSpan.start, ts.textSpanEnd(refLineSpan)).replace(/\r|\n/g, ""); @@ -384,24 +385,27 @@ module ts.server { file: ref.fileName, start: start, lineText: lineText, - end: compilerService.host.positionToLineCol(ref.fileName, ts.textSpanEnd(ref.textSpan)), + end: compilerService.host.positionToLineOffset(ref.fileName, ts.textSpanEnd(ref.textSpan)), isWriteAccess: ref.isWriteAccess }; }).sort(compareFileStart); return { refs: bakedRefs, symbolName: nameText, - symbolStartCol: nameColStart, + symbolStartOffset: nameColStart, symbolDisplayString: displayString }; } - openClientFile(fileName: string) { + openClientFile(fileName: string, tabSize?: number, indentSize?: number) { var file = ts.normalizePath(fileName); - this.projectService.openClientFile(file); + var info = this.projectService.openClientFile(file); + if (info) { + info.setFormatOptions(tabSize, indentSize); + } } - getQuickInfo(line: number, col: number, fileName: string): protocol.QuickInfoResponseBody { + getQuickInfo(line: number, offset: number, fileName: string): protocol.QuickInfoResponseBody { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -409,7 +413,7 @@ module ts.server { } var compilerService = project.compilerService; - var position = compilerService.host.lineColToPosition(file, line, col); + var position = compilerService.host.lineOffsetToPosition(file, line, offset); var quickInfo = compilerService.languageService.getQuickInfoAtPosition(file, position); if (!quickInfo) { return undefined; @@ -420,14 +424,14 @@ module ts.server { return { kind: quickInfo.kind, kindModifiers: quickInfo.kindModifiers, - start: compilerService.host.positionToLineCol(file, quickInfo.textSpan.start), - end: compilerService.host.positionToLineCol(file, ts.textSpanEnd(quickInfo.textSpan)), + start: compilerService.host.positionToLineOffset(file, quickInfo.textSpan.start), + end: compilerService.host.positionToLineOffset(file, ts.textSpanEnd(quickInfo.textSpan)), displayString: displayString, documentation: docString, }; } - getFormattingEditsForRange(line: number, col: number, endLine: number, endCol: number, fileName: string): protocol.CodeEdit[] { + getFormattingEditsForRange(line: number, offset: number, endLine: number, endOffset: number, fileName: string): protocol.CodeEdit[] { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -435,25 +439,26 @@ module ts.server { } var compilerService = project.compilerService; - var startPosition = compilerService.host.lineColToPosition(file, line, col); - var endPosition = compilerService.host.lineColToPosition(file, endLine, endCol); + var startPosition = compilerService.host.lineOffsetToPosition(file, line, offset); + var endPosition = compilerService.host.lineOffsetToPosition(file, endLine, endOffset); // TODO: avoid duplicate code (with formatonkey) - var edits = compilerService.languageService.getFormattingEditsForRange(file, startPosition, endPosition, compilerService.formatCodeOptions); + var edits = compilerService.languageService.getFormattingEditsForRange(file, startPosition, endPosition, + this.projectService.getFormatCodeOptions(file)); if (!edits) { return undefined; } return edits.map((edit) => { return { - start: compilerService.host.positionToLineCol(file, edit.span.start), - end: compilerService.host.positionToLineCol(file, ts.textSpanEnd(edit.span)), + start: compilerService.host.positionToLineOffset(file, edit.span.start), + end: compilerService.host.positionToLineOffset(file, ts.textSpanEnd(edit.span)), newText: edit.newText ? edit.newText : "" }; }); } - getFormattingEditsAfterKeystroke(line: number, col: number, key: string, fileName: string): protocol.CodeEdit[] { + getFormattingEditsAfterKeystroke(line: number, offset: number, key: string, fileName: string): protocol.CodeEdit[] { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); @@ -462,9 +467,10 @@ module ts.server { } var compilerService = project.compilerService; - var position = compilerService.host.lineColToPosition(file, line, col); + var position = compilerService.host.lineOffsetToPosition(file, line, offset); + var formatOptions = this.projectService.getFormatCodeOptions(file); var edits = compilerService.languageService.getFormattingEditsAfterKeystroke(file, position, key, - compilerService.formatCodeOptions); + formatOptions); // Check whether we should auto-indent. This will be when // the position is on a line containing only whitespace. // This should leave the edits returned from @@ -480,8 +486,8 @@ module ts.server { if (lineText.search("\\S") < 0) { // TODO: get these options from host var editorOptions: ts.EditorOptions = { - IndentSize: 4, - TabSize: 4, + IndentSize: formatOptions.IndentSize, + TabSize: formatOptions.TabSize, NewLineCharacter: "\n", ConvertTabsToSpaces: true, }; @@ -516,16 +522,16 @@ module ts.server { return edits.map((edit) => { return { - start: compilerService.host.positionToLineCol(file, + start: compilerService.host.positionToLineOffset(file, edit.span.start), - end: compilerService.host.positionToLineCol(file, + end: compilerService.host.positionToLineOffset(file, ts.textSpanEnd(edit.span)), newText: edit.newText ? edit.newText : "" }; }); } - getCompletions(line: number, col: number, prefix: string, fileName: string): protocol.CompletionEntry[] { + getCompletions(line: number, offset: number, prefix: string, fileName: string): protocol.CompletionEntry[] { if (!prefix) { prefix = ""; } @@ -536,7 +542,7 @@ module ts.server { } var compilerService = project.compilerService; - var position = compilerService.host.lineColToPosition(file, line, col); + var position = compilerService.host.lineOffsetToPosition(file, line, offset); var completions = compilerService.languageService.getCompletionsAtPosition(file, position); if (!completions) { @@ -544,14 +550,14 @@ module ts.server { } return completions.entries.reduce((result: protocol.CompletionEntry[], entry: ts.CompletionEntry) => { - if (completions.isMemberCompletion || entry.name.indexOf(prefix) == 0) { + if (completions.isMemberCompletion || (entry.name.toLowerCase().indexOf(prefix.toLowerCase()) == 0)) { result.push(entry); } return result; - }, []); + }, []).sort((a, b) => a.name.localeCompare(b.name)); } - getCompletionEntryDetails(line: number, col: number, + getCompletionEntryDetails(line: number, offset: number, entryNames: string[], fileName: string): protocol.CompletionEntryDetails[] { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); @@ -560,7 +566,7 @@ module ts.server { } var compilerService = project.compilerService; - var position = compilerService.host.lineColToPosition(file, line, col); + var position = compilerService.host.lineOffsetToPosition(file, line, offset); return entryNames.reduce((accum: protocol.CompletionEntryDetails[], entryName: string) => { var details = compilerService.languageService.getCompletionEntryDetails(file, position, entryName); @@ -586,13 +592,13 @@ module ts.server { } } - change(line: number, col: number, endLine: number, endCol: number, insertString: string, fileName: string) { + change(line: number, offset: number, endLine: number, endOffset: number, insertString: string, fileName: string) { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (project) { var compilerService = project.compilerService; - var start = compilerService.host.lineColToPosition(file, line, col); - var end = compilerService.host.lineColToPosition(file, endLine, endCol); + var start = compilerService.host.lineOffsetToPosition(file, line, offset); + var end = compilerService.host.lineOffsetToPosition(file, endLine, endOffset); if (start >= 0) { compilerService.host.editScript(file, start, end, insertString); this.changeSeq++; @@ -608,7 +614,7 @@ module ts.server { if (project) { this.changeSeq++; // make sure no changes happen before this one is finished - project.compilerService.host.reloadScript(file, tmpfile,() => { + project.compilerService.host.reloadScript(file, tmpfile, () => { this.output(undefined, CommandNames.Reload, reqSeq); }); } @@ -641,8 +647,8 @@ module ts.server { kind: item.kind, kindModifiers: item.kindModifiers, spans: item.spans.map(span => ({ - start: compilerService.host.positionToLineCol(fileName, span.start), - end: compilerService.host.positionToLineCol(fileName, ts.textSpanEnd(span)) + start: compilerService.host.positionToLineOffset(fileName, span.start), + end: compilerService.host.positionToLineOffset(fileName, ts.textSpanEnd(span)) })), childItems: this.decorateNavigationBarItem(project, fileName, item.childItems) })); @@ -678,8 +684,8 @@ module ts.server { } return navItems.map((navItem) => { - var start = compilerService.host.positionToLineCol(navItem.fileName, navItem.textSpan.start); - var end = compilerService.host.positionToLineCol(navItem.fileName, ts.textSpanEnd(navItem.textSpan)); + var start = compilerService.host.positionToLineOffset(navItem.fileName, navItem.textSpan.start); + var end = compilerService.host.positionToLineOffset(navItem.fileName, ts.textSpanEnd(navItem.textSpan)); var bakedItem: protocol.NavtoItem = { name: navItem.name, kind: navItem.kind, @@ -703,7 +709,7 @@ module ts.server { }); } - getBraceMatching(line: number, col: number, fileName: string): protocol.TextSpan[] { + getBraceMatching(line: number, offset: number, fileName: string): protocol.TextSpan[] { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); @@ -712,7 +718,7 @@ module ts.server { } var compilerService = project.compilerService; - var position = compilerService.host.lineColToPosition(file, line, col); + var position = compilerService.host.lineOffsetToPosition(file, line, offset); var spans = compilerService.languageService.getBraceMatchingAtPosition(file, position); if (!spans) { @@ -720,8 +726,8 @@ module ts.server { } return spans.map(span => ({ - start: compilerService.host.positionToLineCol(file, span.start), - end: compilerService.host.positionToLineCol(file, span.start + span.length) + start: compilerService.host.positionToLineOffset(file, span.start), + end: compilerService.host.positionToLineOffset(file, span.start + span.length) })); } @@ -738,49 +744,50 @@ module ts.server { switch (request.command) { case CommandNames.Definition: { var defArgs = request.arguments; - response = this.getDefinition(defArgs.line, defArgs.col, defArgs.file); + response = this.getDefinition(defArgs.line, defArgs.offset, defArgs.file); break; } case CommandNames.References: { var refArgs = request.arguments; - response = this.getReferences(refArgs.line, refArgs.col, refArgs.file); + response = this.getReferences(refArgs.line, refArgs.offset, refArgs.file); break; } case CommandNames.Rename: { var renameArgs = request.arguments; - response = this.getRenameLocations(renameArgs.line, renameArgs.col, renameArgs.file, renameArgs.findInComments, renameArgs.findInStrings); + response = this.getRenameLocations(renameArgs.line, renameArgs.offset, renameArgs.file, renameArgs.findInComments, renameArgs.findInStrings); break; } case CommandNames.Open: { - var openArgs = request.arguments; - this.openClientFile(openArgs.file); + var openArgs = request.arguments; + this.openClientFile(openArgs.file,openArgs.tabSize, openArgs.indentSize); responseRequired = false; break; } case CommandNames.Quickinfo: { var quickinfoArgs = request.arguments; - response = this.getQuickInfo(quickinfoArgs.line, quickinfoArgs.col, quickinfoArgs.file); + response = this.getQuickInfo(quickinfoArgs.line, quickinfoArgs.offset, quickinfoArgs.file); break; } case CommandNames.Format: { var formatArgs = request.arguments; - response = this.getFormattingEditsForRange(formatArgs.line, formatArgs.col, formatArgs.endLine, formatArgs.endCol, formatArgs.file); + response = this.getFormattingEditsForRange(formatArgs.line, formatArgs.offset, formatArgs.endLine, formatArgs.endOffset, formatArgs.file); break; } case CommandNames.Formatonkey: { var formatOnKeyArgs = request.arguments; - response = this.getFormattingEditsAfterKeystroke(formatOnKeyArgs.line, formatOnKeyArgs.col, formatOnKeyArgs.key, formatOnKeyArgs.file); + response = this.getFormattingEditsAfterKeystroke(formatOnKeyArgs.line, formatOnKeyArgs.offset, formatOnKeyArgs.key, formatOnKeyArgs.file); break; } case CommandNames.Completions: { var completionsArgs = request.arguments; - response = this.getCompletions(request.arguments.line, request.arguments.col, completionsArgs.prefix, request.arguments.file); + response = this.getCompletions(completionsArgs.line, completionsArgs.offset, completionsArgs.prefix, completionsArgs.file); break; } case CommandNames.CompletionDetails: { var completionDetailsArgs = request.arguments; - response = this.getCompletionEntryDetails(request.arguments.line, request.arguments.col, completionDetailsArgs.entryNames, - request.arguments.file); + response = + this.getCompletionEntryDetails(completionDetailsArgs.line,completionDetailsArgs.offset, + completionDetailsArgs.entryNames,completionDetailsArgs.file); break; } case CommandNames.Geterr: { @@ -791,14 +798,22 @@ module ts.server { } case CommandNames.Change: { var changeArgs = request.arguments; - this.change(changeArgs.line, changeArgs.col, changeArgs.endLine, changeArgs.endCol, + this.change(changeArgs.line, changeArgs.offset, changeArgs.endLine, changeArgs.endOffset, changeArgs.insertString, changeArgs.file); responseRequired = false; break; } + case CommandNames.Configure: { + var configureArgs = request.arguments; + this.projectService.setHostConfiguration(configureArgs); + this.output(undefined, CommandNames.Configure, request.seq); + responseRequired = false; + break; + } case CommandNames.Reload: { var reloadArgs = request.arguments; this.reload(reloadArgs.file, reloadArgs.tmpfile, request.seq); + responseRequired = false; break; } case CommandNames.Saveto: { @@ -820,7 +835,7 @@ module ts.server { } case CommandNames.Brace: { var braceArguments = request.arguments; - response = this.getBraceMatching(braceArguments.line, braceArguments.col, braceArguments.file); + response = this.getBraceMatching(braceArguments.line, braceArguments.offset, braceArguments.file); break; } case CommandNames.NavBar: { diff --git a/src/server/tsconfig.json b/src/server/tsconfig.json new file mode 100644 index 0000000000000..2c8538c61e32a --- /dev/null +++ b/src/server/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "module": "commonjs", + "noImplicitAny": true, + "removeComments": true, + "preserveConstEnums": true, + "out": "../../built/local/tsserver.js", + "sourceMap": true + }, + "files": [ + "node.d.ts", + "editorServices.ts", + "protocol.d.ts", + "server.ts", + "session.ts" + ] +} diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index c56ea72cd6659..395141cc4cc50 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -173,6 +173,10 @@ module ts.BreakpointResolver { return textSpan(node, (node).expression); case SyntaxKind.ExportAssignment: + if (!(node).expression) { + return undefined; + } + // span on export = id return textSpan(node, (node).expression); diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 24ddabc2b2b14..6a5ed25459e9d 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -419,6 +419,29 @@ module ts.formatting { } } + function getFirstNonDecoratorTokenOfNode(node: Node) { + if (node.modifiers && node.modifiers.length) { + return node.modifiers[0].kind; + } + switch (node.kind) { + case SyntaxKind.ClassDeclaration: return SyntaxKind.ClassKeyword; + case SyntaxKind.InterfaceDeclaration: return SyntaxKind.InterfaceKeyword; + case SyntaxKind.FunctionDeclaration: return SyntaxKind.FunctionKeyword; + case SyntaxKind.EnumDeclaration: return SyntaxKind.EnumDeclaration; + case SyntaxKind.GetAccessor: return SyntaxKind.GetKeyword; + case SyntaxKind.SetAccessor: return SyntaxKind.SetKeyword; + case SyntaxKind.MethodDeclaration: + if ((node).asteriskToken) { + return SyntaxKind.AsteriskToken; + } + // fall-through + + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.Parameter: + return (node).name.kind; + } + } + function getDynamicIndentation(node: Node, nodeStartLine: number, indentation: number, delta: number): DynamicIndentation { return { getIndentationForComment: kind => { @@ -434,6 +457,12 @@ module ts.formatting { return indentation; }, getIndentationForToken: (line, kind) => { + if (nodeStartLine !== line && node.decorators) { + if (kind === getFirstNonDecoratorTokenOfNode(node)) { + // if this token is the first token following the list of decorators, we do not need to indent + return indentation; + } + } switch (kind) { // open and close brace, 'else' and 'while' (in do statement) tokens has indentation of the parent case SyntaxKind.OpenBraceToken: @@ -442,6 +471,7 @@ module ts.formatting { case SyntaxKind.CloseBracketToken: case SyntaxKind.ElseKeyword: case SyntaxKind.WhileKeyword: + case SyntaxKind.AtToken: return indentation; default: // if token line equals to the line of containing node (this is a first token in the node) - use node indentation @@ -1008,10 +1038,20 @@ module ts.formatting { return SyntaxKind.Unknown; } - let internedTabsIndentation: string[]; - let internedSpacesIndentation: string[]; + var internedSizes: { tabSize: number; indentSize: number }; + var internedTabsIndentation: string[]; + var internedSpacesIndentation: string[]; export function getIndentationString(indentation: number, options: FormatCodeOptions): string { + // reset interned strings if FormatCodeOptions were changed + let resetInternedStrings = + !internedSizes || (internedSizes.tabSize !== options.TabSize || internedSizes.indentSize !== options.IndentSize); + + if (resetInternedStrings) { + internedSizes = { tabSize: options.TabSize, indentSize: options.IndentSize }; + internedTabsIndentation = internedSpacesIndentation = undefined; + } + if (!options.ConvertTabsToSpaces) { let tabs = Math.floor(indentation / options.TabSize); let spaces = indentation - tabs * options.TabSize; diff --git a/src/services/formatting/indentation.ts b/src/services/formatting/indentation.ts deleted file mode 100644 index f6f8fc0319fe6..0000000000000 --- a/src/services/formatting/indentation.ts +++ /dev/null @@ -1,54 +0,0 @@ -module ts.formatting { - - var internedTabsIndentation: string[]; - var internedSpacesIndentation: string[]; - - export function getIndentationString(indentation: number, options: FormatCodeOptions): string { - if (!options.ConvertTabsToSpaces) { - var tabs = Math.floor(indentation / options.TabSize); - var spaces = indentation - tabs * options.TabSize; - - var tabString: string; - if (!internedTabsIndentation) { - internedTabsIndentation = []; - } - - if (internedTabsIndentation[tabs] === undefined) { - internedTabsIndentation[tabs] = tabString = repeat('\t', tabs); - } - else { - tabString = internedTabsIndentation[tabs]; - } - - return spaces ? tabString + repeat(" ", spaces) : tabString; - } - else { - var spacesString: string; - var quotient = Math.floor(indentation / options.IndentSize); - var remainder = indentation % options.IndentSize; - if (!internedSpacesIndentation) { - internedSpacesIndentation = []; - } - - if (internedSpacesIndentation[quotient] === undefined) { - spacesString = repeat(" ", options.IndentSize * quotient); - internedSpacesIndentation[quotient] = spacesString; - } - else { - spacesString = internedSpacesIndentation[quotient]; - } - - - return remainder ? spacesString + repeat(" ", remainder) : spacesString; - } - - function repeat(value: string, count: number): string { - var s = ""; - for (var i = 0; i < count; ++i) { - s += value; - } - - return s; - } - } -} \ No newline at end of file diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index e7beebf68668b..8508e3b932d73 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -215,11 +215,7 @@ module ts.formatting { function getStartLineAndCharacterForNode(n: Node, sourceFile: SourceFile): LineAndCharacter { return sourceFile.getLineAndCharacterOfPosition(n.getStart(sourceFile)); } - - function positionBelongsToNode(candidate: Node, position: number, sourceFile: SourceFile): boolean { - return candidate.end > position || !isCompletedNode(candidate, sourceFile); - } - + export function childStartsOnTheSameLineWithElseInIfStatement(parent: Node, child: TextRangeWithKind, childStartLine: number, sourceFile: SourceFile): boolean { if (parent.kind === SyntaxKind.IfStatement && (parent).elseStatement === child) { let elseKeyword = findChildOfKind(parent, SyntaxKind.ElseKeyword, sourceFile); @@ -359,6 +355,7 @@ module ts.formatting { case SyntaxKind.ModuleBlock: case SyntaxKind.ObjectLiteralExpression: case SyntaxKind.TypeLiteral: + case SyntaxKind.TupleType: case SyntaxKind.CaseBlock: case SyntaxKind.DefaultClause: case SyntaxKind.CaseClause: @@ -370,6 +367,8 @@ module ts.formatting { case SyntaxKind.ExportAssignment: case SyntaxKind.ReturnStatement: case SyntaxKind.ConditionalExpression: + case SyntaxKind.ArrayBindingPattern: + case SyntaxKind.ObjectBindingPattern: return true; } return false; @@ -390,6 +389,7 @@ module ts.formatting { case SyntaxKind.FunctionExpression: case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: + case SyntaxKind.CallSignature: case SyntaxKind.ArrowFunction: case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: @@ -399,88 +399,5 @@ module ts.formatting { return false; } } - - /* - * Checks if node ends with 'expectedLastToken'. - * If child at position 'length - 1' is 'SemicolonToken' it is skipped and 'expectedLastToken' is compared with child at position 'length - 2'. - */ - function nodeEndsWith(n: Node, expectedLastToken: SyntaxKind, sourceFile: SourceFile): boolean { - let children = n.getChildren(sourceFile); - if (children.length) { - let last = children[children.length - 1]; - if (last.kind === expectedLastToken) { - return true; - } - else if (last.kind === SyntaxKind.SemicolonToken && children.length !== 1) { - return children[children.length - 2].kind === expectedLastToken; - } - } - return false; - } - - /* - * This function is always called when position of the cursor is located after the node - */ - function isCompletedNode(n: Node, sourceFile: SourceFile): boolean { - if (n.getFullWidth() === 0) { - return false; - } - - switch (n.kind) { - case SyntaxKind.ClassDeclaration: - case SyntaxKind.InterfaceDeclaration: - case SyntaxKind.EnumDeclaration: - case SyntaxKind.ObjectLiteralExpression: - case SyntaxKind.Block: - case SyntaxKind.ModuleBlock: - case SyntaxKind.CaseBlock: - return nodeEndsWith(n, SyntaxKind.CloseBraceToken, sourceFile); - case SyntaxKind.CatchClause: - return isCompletedNode((n).block, sourceFile); - case SyntaxKind.ParenthesizedExpression: - case SyntaxKind.CallSignature: - case SyntaxKind.CallExpression: - case SyntaxKind.ConstructSignature: - return nodeEndsWith(n, SyntaxKind.CloseParenToken, sourceFile); - case SyntaxKind.FunctionDeclaration: - case SyntaxKind.FunctionExpression: - case SyntaxKind.MethodDeclaration: - case SyntaxKind.MethodSignature: - case SyntaxKind.ArrowFunction: - return !(n).body || isCompletedNode((n).body, sourceFile); - case SyntaxKind.ModuleDeclaration: - return (n).body && isCompletedNode((n).body, sourceFile); - case SyntaxKind.IfStatement: - if ((n).elseStatement) { - return isCompletedNode((n).elseStatement, sourceFile); - } - return isCompletedNode((n).thenStatement, sourceFile); - case SyntaxKind.ExpressionStatement: - return isCompletedNode((n).expression, sourceFile); - case SyntaxKind.ArrayLiteralExpression: - return nodeEndsWith(n, SyntaxKind.CloseBracketToken, sourceFile); - case SyntaxKind.CaseClause: - case SyntaxKind.DefaultClause: - // there is no such thing as terminator token for CaseClause\DefaultClause so for simplicitly always consider them non-completed - return false; - case SyntaxKind.ForStatement: - return isCompletedNode((n).statement, sourceFile); - case SyntaxKind.ForInStatement: - return isCompletedNode((n).statement, sourceFile); - case SyntaxKind.ForOfStatement: - return isCompletedNode((n).statement, sourceFile); - case SyntaxKind.WhileStatement: - return isCompletedNode((n).statement, sourceFile); - case SyntaxKind.DoStatement: - // rough approximation: if DoStatement has While keyword - then if node is completed is checking the presence of ')'; - let hasWhileKeyword = findChildOfKind(n, SyntaxKind.WhileKeyword, sourceFile); - if (hasWhileKeyword) { - return nodeEndsWith(n, SyntaxKind.CloseParenToken, sourceFile); - } - return isCompletedNode((n).statement, sourceFile); - default: - return true; - } - } } } \ No newline at end of file diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 06eaa481dfb12..c6463aba7333c 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -418,10 +418,10 @@ module ts.NavigationBar { } function createFunctionItem(node: FunctionDeclaration) { - if (node.name && node.body && node.body.kind === SyntaxKind.Block) { + if ((node.name || node.flags & NodeFlags.Default) && node.body && node.body.kind === SyntaxKind.Block) { let childItems = getItemsWorker(sortNodes((node.body).statements), createChildItem); - return getNavigationBarItem(node.name.text, + return getNavigationBarItem((!node.name && node.flags & NodeFlags.Default) ? "default": node.name.text , ts.ScriptElementKind.functionElement, getNodeModifiers(node), [getNodeSpan(node)], @@ -452,11 +452,6 @@ module ts.NavigationBar { } function createClassItem(node: ClassDeclaration): ts.NavigationBarItem { - if (!node.name) { - // An export default class may be nameless - return undefined; - } - let childItems: NavigationBarItem[]; if (node.members) { @@ -475,8 +470,10 @@ module ts.NavigationBar { childItems = getItemsWorker(sortNodes(nodes), createChildItem); } + var nodeName = !node.name && (node.flags & NodeFlags.Default) ? "default" : node.name.text; + return getNavigationBarItem( - node.name.text, + nodeName, ts.ScriptElementKind.classElement, getNodeModifiers(node), [getNodeSpan(node)], diff --git a/src/services/services.ts b/src/services/services.ts index 1bf5f6336d4c9..58fba22a71f07 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -418,7 +418,10 @@ module ts { function pushDocCommentLineText(docComments: SymbolDisplayPart[], text: string, blankLineCount: number) { // Add the empty lines in between texts - while (blankLineCount--) docComments.push(textPart("")); + while (blankLineCount--) { + docComments.push(textPart("")); + } + docComments.push(textPart(text)); } @@ -937,6 +940,7 @@ module ts { getDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[]; getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[]; getOccurrencesAtPosition(fileName: string, position: number): ReferenceEntry[]; + findReferences(fileName: string, position: number): ReferencedSymbol[]; getNavigateToItems(searchValue: string, maxResultCount?: number): NavigateToItem[]; getNavigationBarItems(fileName: string): NavigationBarItem[]; @@ -1042,6 +1046,11 @@ module ts { containerName: string; } + export interface ReferencedSymbol { + definition: DefinitionInfo; + references: ReferenceEntry[]; + } + export enum SymbolDisplayPartKind { aliasName, className, @@ -1409,14 +1418,6 @@ module ts { /// Language Service - interface CompletionSession { - fileName: string; // the file where the completion was requested - position: number; // position in the file where the completion was requested - entries: CompletionEntry[]; // entries for this completion - symbols: Map; // symbols by entry name map - typeChecker: TypeChecker; // the typeChecker used to generate this completion - } - interface FormattingOptions { useTabs: boolean; spacesPerTab: number; @@ -2180,7 +2181,6 @@ module ts { let typeInfoResolver: TypeChecker; let useCaseSensitivefileNames = false; let cancellationToken = new CancellationTokenObject(host.getCancellationToken && host.getCancellationToken()); - let activeCompletionSession: CompletionSession; // The current active completion session, used to get the completion entry details // Check if the localized messages json is set, otherwise query the host for it if (!localizedDiagnosticMessages && host.getLocalizedDiagnosticMessages) { @@ -2389,7 +2389,7 @@ module ts { // If '-d' is enabled, check for emitter error. One example of emitter error is export class implements non-export interface let declarationDiagnostics = program.getDeclarationDiagnostics(targetSourceFile); - return semanticDiagnostics.concat(declarationDiagnostics); + return concatenate(semanticDiagnostics, declarationDiagnostics); } function getCompilerOptionsDiagnostics() { @@ -2398,43 +2398,51 @@ module ts { } /// Completion - function getValidCompletionEntryDisplayName(symbol: Symbol, target: ScriptTarget): string { + function getCompletionEntryDisplayName(symbol: Symbol, target: ScriptTarget, performCharacterChecks: boolean): string { let displayName = symbol.getName(); - if (displayName && displayName.length > 0) { - let firstCharCode = displayName.charCodeAt(0); - // First check of the displayName is not external module; if it is an external module, it is not valid entry - if ((symbol.flags & SymbolFlags.Namespace) && (firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) { - // If the symbol is external module, don't show it in the completion list - // (i.e declare module "http" { let x; } | // <= request completion here, "http" should not be there) - return undefined; - } + if (!displayName) { + return undefined; + } - if (displayName && displayName.length >= 2 && firstCharCode === displayName.charCodeAt(displayName.length - 1) && - (firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) { - // If the user entered name for the symbol was quoted, removing the quotes is not enough, as the name could be an - // invalid identifier name. We need to check if whatever was inside the quotes is actually a valid identifier name. - displayName = displayName.substring(1, displayName.length - 1); - } + let firstCharCode = displayName.charCodeAt(0); + // First check of the displayName is not external module; if it is an external module, it is not valid entry + if ((symbol.flags & SymbolFlags.Namespace) && (firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) { + // If the symbol is external module, don't show it in the completion list + // (i.e declare module "http" { let x; } | // <= request completion here, "http" should not be there) + return undefined; + } - let isValid = isIdentifierStart(displayName.charCodeAt(0), target); - for (let i = 1, n = displayName.length; isValid && i < n; i++) { - isValid = isIdentifierPart(displayName.charCodeAt(i), target); - } + if (displayName && displayName.length >= 2 && firstCharCode === displayName.charCodeAt(displayName.length - 1) && + (firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) { + // If the user entered name for the symbol was quoted, removing the quotes is not enough, as the name could be an + // invalid identifier name. We need to check if whatever was inside the quotes is actually a valid identifier name. + displayName = displayName.substring(1, displayName.length - 1); + } + if (!displayName) { + return undefined; + } - if (isValid) { - return unescapeIdentifier(displayName); + if (performCharacterChecks) { + if (!isIdentifierStart(displayName.charCodeAt(0), target)) { + return undefined; + } + + for (let i = 1, n = displayName.length; i < n; i++) { + if (!isIdentifierPart(displayName.charCodeAt(i), target)) { + return undefined; + } } } - return undefined; + return unescapeIdentifier(displayName); } function createCompletionEntry(symbol: Symbol, typeChecker: TypeChecker, location: Node): CompletionEntry { // Try to get a valid display name for this symbol, if we could not find one, then ignore it. // We would like to only show things that can be added after a dot, so for instance numeric properties can // not be accessed with a dot (a.1 <- invalid) - let displayName = getValidCompletionEntryDisplayName(symbol, program.getCompilerOptions().target); + let displayName = getCompletionEntryDisplayName(symbol, program.getCompilerOptions().target, /*performCharacterChecks:*/ true); if (!displayName) { return undefined; } @@ -2450,20 +2458,18 @@ module ts { }; } - function getCompletionsAtPosition(fileName: string, position: number) { - synchronizeHostData(); - + function getCompletionData(fileName: string, position: number) { let syntacticStart = new Date().getTime(); let sourceFile = getValidSourceFile(fileName); let start = new Date().getTime(); let currentToken = getTokenAtPosition(sourceFile, position); - log("getCompletionsAtPosition: Get current token: " + (new Date().getTime() - start)); + log("getCompletionData: Get current token: " + (new Date().getTime() - start)); start = new Date().getTime(); // Completion not allowed inside comments, bail out if this is the case let insideComment = isInsideComment(sourceFile, currentToken, position); - log("getCompletionsAtPosition: Is inside comment: " + (new Date().getTime() - start)); + log("getCompletionData: Is inside comment: " + (new Date().getTime() - start)); if (insideComment) { log("Returning an empty list because completion was inside a comment."); @@ -2474,14 +2480,14 @@ module ts { // Note: previousToken can be undefined if we are the beginning of the file start = new Date().getTime(); let previousToken = findPrecedingToken(position, sourceFile); - log("getCompletionsAtPosition: Get previous token 1: " + (new Date().getTime() - start)); + log("getCompletionData: Get previous token 1: " + (new Date().getTime() - start)); // The caret is at the end of an identifier; this is a partial identifier that we want to complete: e.g. a.toS| // Skip this partial identifier to the previous token if (previousToken && position <= previousToken.end && previousToken.kind === SyntaxKind.Identifier) { let start = new Date().getTime(); previousToken = findPrecedingToken(previousToken.pos, sourceFile); - log("getCompletionsAtPosition: Get previous token 2: " + (new Date().getTime() - start)); + log("getCompletionData: Get previous token 2: " + (new Date().getTime() - start)); } // Check if this is a valid completion location @@ -2492,8 +2498,8 @@ module ts { // Find the node where completion is requested on, in the case of a completion after a dot, it is the member access expression // other wise, it is a request for all visible symbols in the scope, and the node is the current location - let node: Node; - let isRightOfDot: boolean; + let node = currentToken; + let isRightOfDot = false; if (previousToken && previousToken.kind === SyntaxKind.DotToken && previousToken.parent.kind === SyntaxKind.PropertyAccessExpression) { node = (previousToken.parent).expression; isRightOfDot = true; @@ -2502,30 +2508,18 @@ module ts { node = (previousToken.parent).left; isRightOfDot = true; } - else { - node = currentToken; - isRightOfDot = false; - } - - // Clear the current activeCompletionSession for this session - activeCompletionSession = { - fileName: fileName, - position: position, - entries: [], - symbols: {}, - typeChecker: typeInfoResolver - }; - log("getCompletionsAtPosition: Syntactic work: " + (new Date().getTime() - syntacticStart)); let location = getTouchingPropertyName(sourceFile, position); - // Populate the completion list + var target = program.getCompilerOptions().target; + let semanticStart = new Date().getTime(); let isMemberCompletion: boolean; let isNewIdentifierLocation: boolean; + let symbols: Symbol[]; if (isRightOfDot) { // Right of dot member completion list - let symbols: Symbol[] = []; + symbols = []; isMemberCompletion = true; isNewIdentifierLocation = false; @@ -2556,8 +2550,6 @@ module ts { } }); } - - getCompletionEntriesFromSymbols(symbols, activeCompletionSession); } else { let containingObjectLiteral = getContainingObjectLiteralApplicableForCompletion(previousToken); @@ -2574,8 +2566,7 @@ module ts { let contextualTypeMembers = typeInfoResolver.getPropertiesOfType(contextualType); if (contextualTypeMembers && contextualTypeMembers.length > 0) { // Add filtered items to the completion list - let filteredMembers = filterContextualMembersList(contextualTypeMembers, containingObjectLiteral.properties); - getCompletionEntriesFromSymbols(filteredMembers, activeCompletionSession); + symbols = filterContextualMembersList(contextualTypeMembers, containingObjectLiteral.properties); } } else if (getAncestor(previousToken, SyntaxKind.ImportClause)) { @@ -2587,8 +2578,7 @@ module ts { let importDeclaration = getAncestor(previousToken, SyntaxKind.ImportDeclaration); Debug.assert(importDeclaration !== undefined); let exports = typeInfoResolver.getExportsOfExternalModule(importDeclaration); - let filteredExports = filterModuleExports(exports, importDeclaration); - getCompletionEntriesFromSymbols(filteredExports, activeCompletionSession); + symbols = filterModuleExports(exports, importDeclaration); } } else { @@ -2597,39 +2587,27 @@ module ts { isNewIdentifierLocation = isNewIdentifierDefinitionLocation(previousToken); /// TODO filter meaning based on the current context + let scopeNode = getScopeNode(previousToken, position, sourceFile); let symbolMeanings = SymbolFlags.Type | SymbolFlags.Value | SymbolFlags.Namespace | SymbolFlags.Alias; - let symbols = typeInfoResolver.getSymbolsInScope(node, symbolMeanings); - - getCompletionEntriesFromSymbols(symbols, activeCompletionSession); + + symbols = typeInfoResolver.getSymbolsInScope(scopeNode, symbolMeanings); } } - // Add keywords if this is not a member completion list - if (!isMemberCompletion) { - Array.prototype.push.apply(activeCompletionSession.entries, keywordCompletions); - } - log("getCompletionsAtPosition: Semantic work: " + (new Date().getTime() - semanticStart)); + log("getCompletionData: Semantic work: " + (new Date().getTime() - semanticStart)); - return { - isMemberCompletion, - isNewIdentifierLocation, - isBuilder : isNewIdentifierDefinitionLocation, // temporary property used to match VS implementation - entries: activeCompletionSession.entries - }; + return { symbols, isMemberCompletion, isNewIdentifierLocation, location }; - function getCompletionEntriesFromSymbols(symbols: Symbol[], session: CompletionSession): void { - let start = new Date().getTime(); - forEach(symbols, symbol => { - let entry = createCompletionEntry(symbol, session.typeChecker, location); - if (entry) { - let id = escapeIdentifier(entry.name); - if (!lookUp(session.symbols, id)) { - session.entries.push(entry); - session.symbols[id] = symbol; - } - } - }); - log("getCompletionsAtPosition: getCompletionEntriesFromSymbols: " + (new Date().getTime() - start)); + /** + * Finds the first node that "embraces" the position, so that one may + * accurately aggregate locals from the closest containing scope. + */ + function getScopeNode(initialToken: Node, position: number, sourceFile: SourceFile) { + var scope = initialToken; + while (scope && !positionBelongsToNode(scope, position, sourceFile)) { + scope = scope.parent; + } + return scope; } function isCompletionListBlocker(previousToken: Node): boolean { @@ -2685,7 +2663,7 @@ module ts { case SyntaxKind.EqualsToken: return containingNodeKind === SyntaxKind.VariableDeclaration // let x = a| - || containingNodeKind === SyntaxKind.BinaryExpression; // x = a| + || containingNodeKind === SyntaxKind.BinaryExpression; // x = a| case SyntaxKind.TemplateHead: return containingNodeKind === SyntaxKind.TemplateExpression; // `aa ${| @@ -2802,7 +2780,7 @@ module ts { case SyntaxKind.SemicolonToken: return containingNodeKind === SyntaxKind.PropertySignature && (previousToken.parent.parent.kind === SyntaxKind.InterfaceDeclaration || // interface a { f; | - previousToken.parent.parent.kind === SyntaxKind.TypeLiteral); // let x : { a; | + previousToken.parent.parent.kind === SyntaxKind.TypeLiteral); // let x : { a; | case SyntaxKind.LessThanToken: return containingNodeKind === SyntaxKind.ClassDeclaration || // class A< | @@ -2918,38 +2896,78 @@ module ts { } } - function getCompletionEntryDetails(fileName: string, position: number, entryName: string): CompletionEntryDetails { - // Note: No need to call synchronizeHostData, as we have captured all the data we need - // in the getCompletionsAtPosition earlier - let sourceFile = getValidSourceFile(fileName); - - let session = activeCompletionSession; + function getCompletionsAtPosition(fileName: string, position: number): CompletionInfo { + synchronizeHostData(); + + let completionData = getCompletionData(fileName, position); + if (!completionData) { + return undefined; + } - // Ensure that the current active completion session is still valid for this request - if (!session || session.fileName !== fileName || session.position !== position) { + let { symbols, isMemberCompletion, isNewIdentifierLocation, location } = completionData; + if (!symbols || symbols.length === 0) { return undefined; } - let symbol = lookUp(activeCompletionSession.symbols, escapeIdentifier(entryName)); - if (symbol) { - let location = getTouchingPropertyName(sourceFile, position); - let completionEntry = createCompletionEntry(symbol, session.typeChecker, location); - // TODO(drosen): Right now we just permit *all* semantic meanings when calling 'getSymbolKind' - // which is permissible given that it is backwards compatible; but really we should consider - // passing the meaning for the node so that we don't report that a suggestion for a value is an interface. - // We COULD also just do what 'getSymbolModifiers' does, which is to use the first declaration. - Debug.assert(session.typeChecker.getTypeOfSymbolAtLocation(symbol, location) !== undefined, "Could not find type for symbol"); - let displayPartsDocumentationsAndSymbolKind = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, getValidSourceFile(fileName), location, session.typeChecker, location, SemanticMeaning.All); - return { - name: entryName, - kind: displayPartsDocumentationsAndSymbolKind.symbolKind, - kindModifiers: completionEntry.kindModifiers, - displayParts: displayPartsDocumentationsAndSymbolKind.displayParts, - documentation: displayPartsDocumentationsAndSymbolKind.documentation - }; + var entries = getCompletionEntriesFromSymbols(symbols); + + // Add keywords if this is not a member completion list + if (!isMemberCompletion) { + addRange(entries, keywordCompletions); } - else { - // No symbol, it is a keyword + + return { isMemberCompletion, isNewIdentifierLocation, entries }; + + function getCompletionEntriesFromSymbols(symbols: Symbol[]): CompletionEntry[] { + let start = new Date().getTime(); + var entries: CompletionEntry[] = []; + var nameToSymbol: Map = {}; + + for (let symbol of symbols) { + let entry = createCompletionEntry(symbol, typeInfoResolver, location); + if (entry) { + let id = escapeIdentifier(entry.name); + if (!lookUp(nameToSymbol, id)) { + entries.push(entry); + nameToSymbol[id] = symbol; + } + } + } + log("getCompletionsAtPosition: getCompletionEntriesFromSymbols: " + (new Date().getTime() - start)); + return entries; + } + } + + function getCompletionEntryDetails(fileName: string, position: number, entryName: string): CompletionEntryDetails { + synchronizeHostData(); + + // Compute all the completion symbols again. + let completionData = getCompletionData(fileName, position); + if (completionData) { + let { symbols, location } = completionData; + + // Find the symbol with the matching entry name. + let target = program.getCompilerOptions().target; + // We don't need to perform character checks here because we're only comparing the + // name against 'entryName' (which is known to be good), not building a new + // completion entry. + let symbol = forEach(symbols, s => getCompletionEntryDisplayName(s, target, /*performCharacterChecks:*/ false) === entryName ? s : undefined); + + if (symbol) { + let displayPartsDocumentationsAndSymbolKind = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, getValidSourceFile(fileName), location, typeInfoResolver, location, SemanticMeaning.All); + return { + name: entryName, + kind: displayPartsDocumentationsAndSymbolKind.symbolKind, + kindModifiers: getSymbolModifiers(symbol), + displayParts: displayPartsDocumentationsAndSymbolKind.displayParts, + documentation: displayPartsDocumentationsAndSymbolKind.documentation + }; + } + } + + // Didn't find a symbol with this name. See if we can find a keyword instead. + let keywordCompletion = forEach(keywordCompletions, c => c.name === entryName); + if (keywordCompletion) { return { name: entryName, kind: ScriptElementKind.keyword, @@ -2958,6 +2976,8 @@ module ts { documentation: undefined }; } + + return undefined; } // TODO(drosen): use contextual SemanticMeaning. @@ -3056,12 +3076,14 @@ module ts { typeResolver: TypeChecker, location: Node, // TODO(drosen): Currently completion entry details passes the SemanticMeaning.All instead of using semanticMeaning of location semanticMeaning = getMeaningFromLocation(location)) { + let displayParts: SymbolDisplayPart[] = []; let documentation: SymbolDisplayPart[]; let symbolFlags = symbol.flags; let symbolKind = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, symbolFlags, typeResolver, location); let hasAddedSymbolInfo: boolean; let type: Type; + // Class at constructor site need to be shown as constructor apart from property,method, vars if (symbolKind !== ScriptElementKind.unknown || symbolFlags & SymbolFlags.Class || symbolFlags & SymbolFlags.Alias) { // If it is accessor they are allowed only if location is at name of the accessor @@ -3113,9 +3135,7 @@ module ts { } else if (symbolFlags & SymbolFlags.Alias) { symbolKind = ScriptElementKind.alias; - displayParts.push(punctuationPart(SyntaxKind.OpenParenToken)); - displayParts.push(textPart(symbolKind)); - displayParts.push(punctuationPart(SyntaxKind.CloseParenToken)); + pushTypePart(symbolKind); displayParts.push(spacePart()); if (useConstructSignatures) { displayParts.push(keywordPart(SyntaxKind.NewKeyword)); @@ -3351,14 +3371,29 @@ module ts { function addPrefixForAnyFunctionOrVar(symbol: Symbol, symbolKind: string) { addNewLineIfDisplayPartsExist(); if (symbolKind) { - displayParts.push(punctuationPart(SyntaxKind.OpenParenToken)); - displayParts.push(textPart(symbolKind)); - displayParts.push(punctuationPart(SyntaxKind.CloseParenToken)); + pushTypePart(symbolKind); displayParts.push(spacePart()); addFullSymbolName(symbol); } } + function pushTypePart(symbolKind: string) { + switch (symbolKind) { + case ScriptElementKind.variableElement: + case ScriptElementKind.functionElement: + case ScriptElementKind.letElement: + case ScriptElementKind.constElement: + case ScriptElementKind.constructorImplementationElement: + displayParts.push(textOrKeywordPart(symbolKind)); + return; + default: + displayParts.push(punctuationPart(SyntaxKind.OpenParenToken)); + displayParts.push(textOrKeywordPart(symbolKind)); + displayParts.push(punctuationPart(SyntaxKind.CloseParenToken)); + return; + } + } + function addSignatureDisplayParts(signature: Signature, allSignatures: Signature[], flags?: TypeFormatFlags) { displayParts.push.apply(displayParts, signatureToDisplayParts(typeResolver, signature, enclosingDeclaration, flags | TypeFormatFlags.WriteTypeArgumentsOfSignature)); if (allSignatures.length > 1) { @@ -3425,6 +3460,17 @@ module ts { }; } + function createDefinitionInfo(node: Node, symbolKind: string, symbolName: string, containerName: string): DefinitionInfo { + return { + fileName: node.getSourceFile().fileName, + textSpan: createTextSpanFromBounds(node.getStart(), node.getEnd()), + kind: symbolKind, + name: symbolName, + containerKind: undefined, + containerName + }; + } + /// Goto definition function getDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[] { synchronizeHostData(); @@ -3440,7 +3486,7 @@ module ts { if (isJumpStatementTarget(node)) { let labelName = (node).text; let label = getTargetLabel((node.parent), (node).text); - return label ? [getDefinitionInfo(label, ScriptElementKind.label, labelName, /*containerName*/ undefined)] : undefined; + return label ? [createDefinitionInfo(label, ScriptElementKind.label, labelName, /*containerName*/ undefined)] : undefined; } /// Triple slash reference comments @@ -3471,7 +3517,7 @@ module ts { // If this is an alias, and the request came at the declaration location // get the aliased symbol instead. This allows for goto def on an import e.g. // import {A, B} from "mod"; - // to jump to the implementation directelly. + // to jump to the implementation directly. if (symbol.flags & SymbolFlags.Alias) { let declaration = symbol.declarations[0]; if (node.kind === SyntaxKind.Identifier && node.parent === declaration) { @@ -3479,8 +3525,6 @@ module ts { } } - let result: DefinitionInfo[] = []; - // Because name in short-hand property assignment has two different meanings: property name and property value, // using go-to-definition at such position should go to the variable declaration of the property value rather than // go to the declaration of the property name (in this case stay at the same position). However, if go-to-definition @@ -3488,16 +3532,19 @@ module ts { // assignment. This case and others are handled by the following code. if (node.parent.kind === SyntaxKind.ShorthandPropertyAssignment) { let shorthandSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(symbol.valueDeclaration); + if (!shorthandSymbol) { + return []; + } + let shorthandDeclarations = shorthandSymbol.getDeclarations(); let shorthandSymbolKind = getSymbolKind(shorthandSymbol, typeInfoResolver, node); let shorthandSymbolName = typeInfoResolver.symbolToString(shorthandSymbol); let shorthandContainerName = typeInfoResolver.symbolToString(symbol.parent, node); - forEach(shorthandDeclarations, declaration => { - result.push(getDefinitionInfo(declaration, shorthandSymbolKind, shorthandSymbolName, shorthandContainerName)); - }); - return result + return map(shorthandDeclarations, + declaration => createDefinitionInfo(declaration, shorthandSymbolKind, shorthandSymbolName, shorthandContainerName)); } + let result: DefinitionInfo[] = []; let declarations = symbol.getDeclarations(); let symbolName = typeInfoResolver.symbolToString(symbol); // Do not get scoped name, just the name of the symbol let symbolKind = getSymbolKind(symbol, typeInfoResolver, node); @@ -3508,21 +3555,31 @@ module ts { !tryAddCallSignature(symbol, node, symbolKind, symbolName, containerName, result)) { // Just add all the declarations. forEach(declarations, declaration => { - result.push(getDefinitionInfo(declaration, symbolKind, symbolName, containerName)); + result.push(createDefinitionInfo(declaration, symbolKind, symbolName, containerName)); }); } return result; - function getDefinitionInfo(node: Node, symbolKind: string, symbolName: string, containerName: string): DefinitionInfo { - return { - fileName: node.getSourceFile().fileName, - textSpan: createTextSpanFromBounds(node.getStart(), node.getEnd()), - kind: symbolKind, - name: symbolName, - containerKind: undefined, - containerName - }; + function tryAddConstructSignature(symbol: Symbol, location: Node, symbolKind: string, symbolName: string, containerName: string, result: DefinitionInfo[]) { + // Applicable only if we are in a new expression, or we are on a constructor declaration + // and in either case the symbol has a construct signature definition, i.e. class + if (isNewExpressionTarget(location) || location.kind === SyntaxKind.ConstructorKeyword) { + if (symbol.flags & SymbolFlags.Class) { + let classDeclaration = symbol.getDeclarations()[0]; + Debug.assert(classDeclaration && classDeclaration.kind === SyntaxKind.ClassDeclaration); + + return tryAddSignature(classDeclaration.members, /*selectConstructors*/ true, symbolKind, symbolName, containerName, result); + } + } + return false; + } + + function tryAddCallSignature(symbol: Symbol, location: Node, symbolKind: string, symbolName: string, containerName: string, result: DefinitionInfo[]) { + if (isCallExpressionTarget(location) || isNewExpressionTarget(location) || isNameOfFunctionDeclaration(location)) { + return tryAddSignature(symbol.declarations, /*selectConstructors*/ false, symbolKind, symbolName, containerName, result); + } + return false; } function tryAddSignature(signatureDeclarations: Declaration[], selectConstructors: boolean, symbolKind: string, symbolName: string, containerName: string, result: DefinitionInfo[]) { @@ -3538,37 +3595,16 @@ module ts { }); if (definition) { - result.push(getDefinitionInfo(definition, symbolKind, symbolName, containerName)); + result.push(createDefinitionInfo(definition, symbolKind, symbolName, containerName)); return true; } else if (declarations.length) { - result.push(getDefinitionInfo(declarations[declarations.length - 1], symbolKind, symbolName, containerName)); + result.push(createDefinitionInfo(declarations[declarations.length - 1], symbolKind, symbolName, containerName)); return true; } return false; } - - function tryAddConstructSignature(symbol: Symbol, location: Node, symbolKind: string, symbolName: string, containerName: string, result: DefinitionInfo[]) { - // Applicable only if we are in a new expression, or we are on a constructor declaration - // and in either case the symbol has a construct signature definition, i.e. class - if (isNewExpressionTarget(location) || location.kind === SyntaxKind.ConstructorKeyword) { - if (symbol.flags & SymbolFlags.Class) { - let classDeclaration = symbol.getDeclarations()[0]; - Debug.assert(classDeclaration && classDeclaration.kind === SyntaxKind.ClassDeclaration); - - return tryAddSignature(classDeclaration.members, /*selectConstructors*/ true, symbolKind, symbolName, containerName, result); - } - } - return false; - } - - function tryAddCallSignature(symbol: Symbol, location: Node, symbolKind: string, symbolName: string, containerName: string, result: DefinitionInfo[]) { - if (isCallExpressionTarget(location) || isNewExpressionTarget(location) || isNameOfFunctionDeclaration(location)) { - return tryAddSignature(symbol.declarations, /*selectConstructors*/ false, symbolKind, symbolName, containerName, result); - } - return false; - } } /// References and Occurrences @@ -3584,7 +3620,7 @@ module ts { if (node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.ThisKeyword || node.kind === SyntaxKind.SuperKeyword || isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || isNameOfExternalModuleImportOrDeclaration(node)) { - return getReferencesForNode(node, [sourceFile], /*searchOnlyInCurrentFile*/ true, /*findInStrings:*/ false, /*findInComments:*/ false); + return convertReferences(getReferencesForNode(node, [sourceFile], /*searchOnlyInCurrentFile*/ true, /*findInStrings:*/ false, /*findInComments:*/ false)); } switch (node.kind) { @@ -3884,7 +3920,7 @@ module ts { return map(keywords, getReferenceEntryFromNode); } - function getSwitchCaseDefaultOccurrences(switchStatement: SwitchStatement) { + function getSwitchCaseDefaultOccurrences(switchStatement: SwitchStatement): ReferenceEntry[] { let keywords: Node[] = []; pushKeywordIf(keywords, switchStatement.getFirstToken(), SyntaxKind.SwitchKeyword); @@ -4007,22 +4043,22 @@ module ts { } } - function getModifierOccurrences(modifier: SyntaxKind, declaration: Node) { + function getModifierOccurrences(modifier: SyntaxKind, declaration: Node): ReferenceEntry[] { let container = declaration.parent; // Make sure we only highlight the keyword when it makes sense to do so. - if (declaration.flags & NodeFlags.AccessibilityModifier) { + if (isAccessibilityModifier(modifier)) { if (!(container.kind === SyntaxKind.ClassDeclaration || (declaration.kind === SyntaxKind.Parameter && hasKind(container, SyntaxKind.Constructor)))) { return undefined; } } - else if (declaration.flags & NodeFlags.Static) { + else if (modifier === SyntaxKind.StaticKeyword) { if (container.kind !== SyntaxKind.ClassDeclaration) { return undefined; } } - else if (declaration.flags & (NodeFlags.Export | NodeFlags.Ambient)) { + else if (modifier === SyntaxKind.ExportKeyword || modifier === SyntaxKind.DeclareKeyword) { if (!(container.kind === SyntaxKind.ModuleBlock || container.kind === SyntaxKind.SourceFile)) { return undefined; } @@ -4063,7 +4099,7 @@ module ts { default: Debug.fail("Invalid container kind.") } - + forEach(nodes, node => { if (node.modifiers && node.flags & modifierFlag) { forEach(node.modifiers, child => pushKeywordIf(keywords, child, modifier)); @@ -4112,15 +4148,36 @@ module ts { } } - function findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): RenameLocation[] { - return findReferences(fileName, position, findInStrings, findInComments); + function convertReferences(referenceSymbols: ReferencedSymbol[]): ReferenceEntry[]{ + if (!referenceSymbols) { + return undefined; + } + + let referenceEntries: ReferenceEntry[] = []; + for (let referenceSymbol of referenceSymbols) { + addRange(referenceEntries, referenceSymbol.references); + } + return referenceEntries; + } + + function findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): RenameLocation[]{ + var referencedSymbols = findReferencedSymbols(fileName, position, findInStrings, findInComments); + return convertReferences(referencedSymbols); } function getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[] { - return findReferences(fileName, position, /*findInStrings:*/ false, /*findInComments:*/ false); + var referencedSymbols = findReferencedSymbols(fileName, position, /*findInStrings:*/ false, /*findInComments:*/ false); + return convertReferences(referencedSymbols); + } + + function findReferences(fileName: string, position: number): ReferencedSymbol[]{ + var referencedSymbols = findReferencedSymbols(fileName, position, /*findInStrings:*/ false, /*findInComments:*/ false); + + // Only include referenced symbols that have a valid definition. + return filter(referencedSymbols, rs => !!rs.definition); } - function findReferences(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): ReferenceEntry[] { + function findReferencedSymbols(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): ReferencedSymbol[] { synchronizeHostData(); let sourceFile = getValidSourceFile(fileName); @@ -4143,14 +4200,14 @@ module ts { return getReferencesForNode(node, program.getSourceFiles(), /*searchOnlyInCurrentFile*/ false, findInStrings, findInComments); } - function getReferencesForNode(node: Node, sourceFiles: SourceFile[], searchOnlyInCurrentFile: boolean, findInStrings: boolean, findInComments: boolean): ReferenceEntry[] { + function getReferencesForNode(node: Node, sourceFiles: SourceFile[], searchOnlyInCurrentFile: boolean, findInStrings: boolean, findInComments: boolean): ReferencedSymbol[]{ // Labels if (isLabelName(node)) { if (isJumpStatementTarget(node)) { let labelDefinition = getTargetLabel((node.parent), (node).text); // if we have a label definition, look within its statement for references, if not, then - // the label is undefined, just return a set of one for the current node. - return labelDefinition ? getLabelReferencesInNode(labelDefinition.parent, labelDefinition) : [getReferenceEntryFromNode(node)]; + // the label is undefined and we have no results.. + return labelDefinition ? getLabelReferencesInNode(labelDefinition.parent, labelDefinition) : undefined; } else { // it is a label definition and not a target, search within the parent labeledStatement @@ -4170,9 +4227,8 @@ module ts { // Could not find a symbol e.g. unknown identifier if (!symbol) { - // Even if we did not find a symbol, we have an identifier, so there is at least - // one reference that we know of. return that instead of undefined. - return [getReferenceEntryFromNode(node)]; + // Can't have references to something that we have no symbol for. + return undefined; } let declarations = symbol.declarations; @@ -4182,7 +4238,7 @@ module ts { return undefined; } - let result: ReferenceEntry[]; + let result: ReferencedSymbol[]; // Compute the meaning from the location and the symbol it references let searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), declarations); @@ -4194,15 +4250,18 @@ module ts { // otherwise we'll need to search globally (i.e. include each file). let scope = getSymbolScope(symbol); + // Maps from a symbol ID to the ReferencedSymbol entry in 'result'. + let symbolToIndex: number[] = []; + if (scope) { result = []; - getReferencesInNode(scope, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result); + getReferencesInNode(scope, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result, symbolToIndex); } else { if (searchOnlyInCurrentFile) { Debug.assert(sourceFiles.length === 1); result = []; - getReferencesInNode(sourceFiles[0], symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result); + getReferencesInNode(sourceFiles[0], symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result, symbolToIndex); } else { let internedName = getInternedName(symbol, node, declarations) @@ -4213,7 +4272,7 @@ module ts { if (lookUp(nameTable, internedName)) { result = result || []; - getReferencesInNode(sourceFile, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result); + getReferencesInNode(sourceFile, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result, symbolToIndex); } }); } @@ -4221,6 +4280,24 @@ module ts { return result; + function getDefinition(symbol: Symbol): DefinitionInfo { + let info = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, node.getSourceFile(), getContainerNode(node), typeInfoResolver, node); + let name = map(info.displayParts, p => p.text).join(""); + let declarations = symbol.declarations; + if (!declarations || declarations.length === 0) { + return undefined; + } + + return { + containerKind: "", + containerName: "", + name, + kind: info.symbolKind, + fileName: declarations[0].getSourceFile().fileName, + textSpan: createTextSpan(declarations[0].getStart(), 0) + }; + } + function isImportOrExportSpecifierName(location: Node): boolean { return location.parent && (location.parent.kind === SyntaxKind.ImportSpecifier || location.parent.kind === SyntaxKind.ExportSpecifier) && @@ -4378,8 +4455,8 @@ module ts { return positions; } - function getLabelReferencesInNode(container: Node, targetLabel: Identifier): ReferenceEntry[] { - let result: ReferenceEntry[] = []; + function getLabelReferencesInNode(container: Node, targetLabel: Identifier): ReferencedSymbol[] { + let references: ReferenceEntry[] = []; let sourceFile = container.getSourceFile(); let labelName = targetLabel.text; let possiblePositions = getPossibleSymbolReferencePositions(sourceFile, labelName, container.getStart(), container.getEnd()); @@ -4394,10 +4471,20 @@ module ts { // Only pick labels that are either the target label, or have a target that is the target label if (node === targetLabel || (isJumpStatementTarget(node) && getTargetLabel(node, labelName) === targetLabel)) { - result.push(getReferenceEntryFromNode(node)); + references.push(getReferenceEntryFromNode(node)); } }); - return result; + + var definition: DefinitionInfo = { + containerKind: "", + containerName: "", + fileName: targetLabel.getSourceFile().fileName, + kind: ScriptElementKind.label, + name: labelName, + textSpan: createTextSpanFromBounds(targetLabel.getStart(), targetLabel.getEnd()) + } + + return [{ definition, references }]; } function isValidReferencePosition(node: Node, searchSymbolName: string): boolean { @@ -4437,7 +4524,9 @@ module ts { searchMeaning: SemanticMeaning, findInStrings: boolean, findInComments: boolean, - result: ReferenceEntry[]): void { + result: ReferencedSymbol[], + symbolToIndex: number[]): void { + let sourceFile = container.getSourceFile(); let tripleSlashDirectivePrefixRegex = /^\/\/\/\s*= 0) { - result.push(getReferenceEntryFromNode(referenceSymbolDeclaration.name)); + var referencedSymbol = getReferencedSymbol(shorthandValueSymbol); + referencedSymbol.references.push(getReferenceEntryFromNode(referenceSymbolDeclaration.name)); } } }); } + return; + + function getReferencedSymbol(symbol: Symbol): ReferencedSymbol { + var symbolId = getSymbolId(symbol); + var index = symbolToIndex[symbolId]; + if (index === undefined) { + index = result.length; + symbolToIndex[symbolId] = index; + + result.push({ + definition: getDefinition(symbol), + references: [] + }); + } + + return result[index]; + } + function isInString(position: number) { let token = getTokenAtPosition(sourceFile, position); return token && token.kind === SyntaxKind.StringLiteral && position > token.getStart(); @@ -4517,7 +4636,7 @@ module ts { } } - function getReferencesForSuperKeyword(superKeyword: Node): ReferenceEntry[] { + function getReferencesForSuperKeyword(superKeyword: Node): ReferencedSymbol[] { let searchSpaceNode = getSuperContainer(superKeyword, /*includeFunctions*/ false); if (!searchSpaceNode) { return undefined; @@ -4540,7 +4659,7 @@ module ts { return undefined; } - let result: ReferenceEntry[] = []; + let references: ReferenceEntry[] = []; let sourceFile = searchSpaceNode.getSourceFile(); let possiblePositions = getPossibleSymbolReferencePositions(sourceFile, "super", searchSpaceNode.getStart(), searchSpaceNode.getEnd()); @@ -4559,14 +4678,15 @@ module ts { // Now make sure the owning class is the same as the search-space // and has the same static qualifier as the original 'super's owner. if (container && (NodeFlags.Static & container.flags) === staticFlag && container.parent.symbol === searchSpaceNode.symbol) { - result.push(getReferenceEntryFromNode(node)); + references.push(getReferenceEntryFromNode(node)); } }); - return result; + var definition = getDefinition(searchSpaceNode.symbol); + return [{ definition, references }]; } - function getReferencesForThisKeyword(thisOrSuperKeyword: Node, sourceFiles: SourceFile[]): ReferenceEntry[] { + function getReferencesForThisKeyword(thisOrSuperKeyword: Node, sourceFiles: SourceFile[]): ReferencedSymbol[] { let searchSpaceNode = getThisContainer(thisOrSuperKeyword, /* includeArrowFunctions */ false); // Whether 'this' occurs in a static context within a class. @@ -4601,22 +4721,32 @@ module ts { return undefined; } - let result: ReferenceEntry[] = []; + let references: ReferenceEntry[] = []; let possiblePositions: number[]; if (searchSpaceNode.kind === SyntaxKind.SourceFile) { forEach(sourceFiles, sourceFile => { possiblePositions = getPossibleSymbolReferencePositions(sourceFile, "this", sourceFile.getStart(), sourceFile.getEnd()); - getThisReferencesInFile(sourceFile, sourceFile, possiblePositions, result); + getThisReferencesInFile(sourceFile, sourceFile, possiblePositions, references); }); } else { let sourceFile = searchSpaceNode.getSourceFile(); possiblePositions = getPossibleSymbolReferencePositions(sourceFile, "this", searchSpaceNode.getStart(), searchSpaceNode.getEnd()); - getThisReferencesInFile(sourceFile, searchSpaceNode, possiblePositions, result); + getThisReferencesInFile(sourceFile, searchSpaceNode, possiblePositions, references); } - return result; + return [{ + definition: { + containerKind: "", + containerName: "", + fileName: node.getSourceFile().fileName, + kind: ScriptElementKind.variableElement, + name: "this", + textSpan: createTextSpanFromBounds(node.getStart(), node.getEnd()) + }, + references: references + }]; function getThisReferencesInFile(sourceFile: SourceFile, searchSpaceNode: Node, possiblePositions: number[], result: ReferenceEntry[]): void { forEach(possiblePositions, position => { @@ -4739,16 +4869,18 @@ module ts { } } - function isRelatableToSearchSet(searchSymbols: Symbol[], referenceSymbol: Symbol, referenceLocation: Node): boolean { + function getRelatedSymbol(searchSymbols: Symbol[], referenceSymbol: Symbol, referenceLocation: Node): Symbol { if (searchSymbols.indexOf(referenceSymbol) >= 0) { - return true; + return referenceSymbol; } // If the reference symbol is an alias, check if what it is aliasing is one of the search // symbols. - if (isImportOrExportSpecifierImportSymbol(referenceSymbol) && - searchSymbols.indexOf(typeInfoResolver.getAliasedSymbol(referenceSymbol)) >= 0) { - return true; + if (isImportOrExportSpecifierImportSymbol(referenceSymbol)) { + var aliasedSymbol = typeInfoResolver.getAliasedSymbol(referenceSymbol); + if (searchSymbols.indexOf(aliasedSymbol) >= 0) { + return aliasedSymbol; + } } // If the reference location is in an object literal, try to get the contextual type for the @@ -4756,7 +4888,7 @@ module ts { // compare to our searchSymbol if (isNameOfPropertyAssignment(referenceLocation)) { return forEach(getPropertySymbolsFromContextualType(referenceLocation), contextualSymbol => { - return forEach(typeInfoResolver.getRootSymbols(contextualSymbol), s => searchSymbols.indexOf(s) >= 0); + return forEach(typeInfoResolver.getRootSymbols(contextualSymbol), s => searchSymbols.indexOf(s) >= 0 ? s : undefined); }); } @@ -4765,7 +4897,7 @@ module ts { return forEach(typeInfoResolver.getRootSymbols(referenceSymbol), rootSymbol => { // if it is in the list, then we are done if (searchSymbols.indexOf(rootSymbol) >= 0) { - return true; + return rootSymbol; } // Finally, try all properties with the same name in any type the containing type extended or implemented, and @@ -4773,10 +4905,10 @@ module ts { if (rootSymbol.parent && rootSymbol.parent.flags & (SymbolFlags.Class | SymbolFlags.Interface)) { let result: Symbol[] = []; getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getName(), result); - return forEach(result, s => searchSymbols.indexOf(s) >= 0); + return forEach(result, s => searchSymbols.indexOf(s) >= 0 ? s : undefined); } - return false; + return undefined; }); } @@ -4899,7 +5031,6 @@ module ts { synchronizeHostData(); let sourceFile = getValidSourceFile(fileName); - let outputFiles: OutputFile[] = []; function writeFile(fileName: string, data: string, writeByteOrderMark: boolean) { @@ -5733,6 +5864,7 @@ module ts { getQuickInfoAtPosition, getDefinitionAtPosition, getReferencesAtPosition, + findReferences, getOccurrencesAtPosition, getNameOrDottedNameSpan, getBreakpointStatementAtPosition, @@ -5843,17 +5975,6 @@ module ts { // a string literal, and a template end consisting of '} } `'. let templateStack: SyntaxKind[] = []; - function isAccessibilityModifier(kind: SyntaxKind) { - switch (kind) { - case SyntaxKind.PublicKeyword: - case SyntaxKind.PrivateKeyword: - case SyntaxKind.ProtectedKeyword: - return true; - } - - return false; - } - /** Returns true if 'keyword2' can legally follow 'keyword1' in any language construct. */ function canFollow(keyword1: SyntaxKind, keyword2: SyntaxKind) { if (isAccessibilityModifier(keyword1)) { diff --git a/src/services/shims.ts b/src/services/shims.ts index fc47ff95280e7..adcec5ada2b60 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -127,6 +127,12 @@ module ts { * { fileName: string; textSpan: { start: number; length: number}; isWriteAccess: boolean }[] */ getReferencesAtPosition(fileName: string, position: number): string; + + /** + * Returns a JSON-encoded value of the type: + * { definition: ; references: [] }[] + */ + findReferences(fileName: string, position: number): string; /** * Returns a JSON-encoded value of the type: @@ -555,11 +561,6 @@ module ts { /// GET REFERENCES - /** - * Return references to a symbol at the requested position. - * References are separated by "\n". - * Each reference is a "fileindex min lim" sub-string. - */ public getReferencesAtPosition(fileName: string, position: number): string { return this.forwardJSONCall( "getReferencesAtPosition('" + fileName + "', " + position + ")", @@ -568,6 +569,14 @@ module ts { }); } + public findReferences(fileName: string, position: number): string { + return this.forwardJSONCall( + "findReferences('" + fileName + "', " + position + ")", + () => { + return this.languageService.findReferences(fileName, position); + }); + } + public getOccurrencesAtPosition(fileName: string, position: number): string { return this.forwardJSONCall( "getOccurrencesAtPosition('" + fileName + "', " + position + ")", @@ -833,3 +842,5 @@ module ts { module TypeScript.Services { export var TypeScriptServicesFactory = ts.TypeScriptServicesFactory; } + +let toolsVersion = "1.4"; diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 452395f454a23..756fbb42597f6 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -59,6 +59,157 @@ module ts { return start < end; } + export function positionBelongsToNode(candidate: Node, position: number, sourceFile: SourceFile): boolean { + return candidate.end > position || !isCompletedNode(candidate, sourceFile); + } + + export function isCompletedNode(n: Node, sourceFile: SourceFile): boolean { + if (nodeIsMissing(n)) { + return false; + } + + switch (n.kind) { + case SyntaxKind.ClassDeclaration: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.EnumDeclaration: + case SyntaxKind.ObjectLiteralExpression: + case SyntaxKind.ObjectBindingPattern: + case SyntaxKind.TypeLiteral: + case SyntaxKind.Block: + case SyntaxKind.ModuleBlock: + case SyntaxKind.CaseBlock: + return nodeEndsWith(n, SyntaxKind.CloseBraceToken, sourceFile); + case SyntaxKind.CatchClause: + return isCompletedNode((n).block, sourceFile); + case SyntaxKind.NewExpression: + if (!(n).arguments) { + return true; + } + // fall through + case SyntaxKind.CallExpression: + case SyntaxKind.ParenthesizedExpression: + case SyntaxKind.ParenthesizedType: + return nodeEndsWith(n, SyntaxKind.CloseParenToken, sourceFile); + + case SyntaxKind.FunctionType: + case SyntaxKind.ConstructorType: + return isCompletedNode((n).type, sourceFile); + + case SyntaxKind.Constructor: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.FunctionExpression: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + case SyntaxKind.ConstructSignature: + case SyntaxKind.CallSignature: + case SyntaxKind.ArrowFunction: + if ((n).body) { + return isCompletedNode((n).body, sourceFile); + } + + if ((n).type) { + return isCompletedNode((n).type, sourceFile); + } + + // Even though type parameters can be unclosed, we can get away with + // having at least a closing paren. + return hasChildOfKind(n, SyntaxKind.CloseParenToken, sourceFile); + + case SyntaxKind.ModuleDeclaration: + return (n).body && isCompletedNode((n).body, sourceFile); + + case SyntaxKind.IfStatement: + if ((n).elseStatement) { + return isCompletedNode((n).elseStatement, sourceFile); + } + return isCompletedNode((n).thenStatement, sourceFile); + + case SyntaxKind.ExpressionStatement: + return isCompletedNode((n).expression, sourceFile); + + case SyntaxKind.ArrayLiteralExpression: + case SyntaxKind.ArrayBindingPattern: + case SyntaxKind.ElementAccessExpression: + case SyntaxKind.ComputedPropertyName: + case SyntaxKind.TupleType: + return nodeEndsWith(n, SyntaxKind.CloseBracketToken, sourceFile); + + case SyntaxKind.IndexSignature: + if ((n).type) { + return isCompletedNode((n).type, sourceFile); + } + + return hasChildOfKind(n, SyntaxKind.CloseBracketToken, sourceFile); + + case SyntaxKind.CaseClause: + case SyntaxKind.DefaultClause: + // there is no such thing as terminator token for CaseClause/DefaultClause so for simplicitly always consider them non-completed + return false; + + case SyntaxKind.ForStatement: + case SyntaxKind.ForInStatement: + case SyntaxKind.ForOfStatement: + case SyntaxKind.WhileStatement: + return isCompletedNode((n).statement, sourceFile); + case SyntaxKind.DoStatement: + // rough approximation: if DoStatement has While keyword - then if node is completed is checking the presence of ')'; + let hasWhileKeyword = findChildOfKind(n, SyntaxKind.WhileKeyword, sourceFile); + if (hasWhileKeyword) { + return nodeEndsWith(n, SyntaxKind.CloseParenToken, sourceFile); + } + return isCompletedNode((n).statement, sourceFile); + + case SyntaxKind.TypeQuery: + return isCompletedNode((n).exprName, sourceFile); + + case SyntaxKind.TypeOfExpression: + case SyntaxKind.DeleteExpression: + case SyntaxKind.VoidExpression: + case SyntaxKind.YieldExpression: + case SyntaxKind.SpreadElementExpression: + let unaryWordExpression = (n); + return isCompletedNode(unaryWordExpression.expression, sourceFile); + + case SyntaxKind.TaggedTemplateExpression: + return isCompletedNode((n).template, sourceFile); + case SyntaxKind.TemplateExpression: + let lastSpan = lastOrUndefined((n).templateSpans); + return isCompletedNode(lastSpan, sourceFile); + case SyntaxKind.TemplateSpan: + return nodeIsPresent((n).literal); + + case SyntaxKind.PrefixUnaryExpression: + return isCompletedNode((n).operand, sourceFile); + case SyntaxKind.BinaryExpression: + return isCompletedNode((n).right, sourceFile); + case SyntaxKind.ConditionalExpression: + return isCompletedNode((n).whenFalse, sourceFile); + + default: + return true; + } + } + + /* + * Checks if node ends with 'expectedLastToken'. + * If child at position 'length - 1' is 'SemicolonToken' it is skipped and 'expectedLastToken' is compared with child at position 'length - 2'. + */ + function nodeEndsWith(n: Node, expectedLastToken: SyntaxKind, sourceFile: SourceFile): boolean { + let children = n.getChildren(sourceFile); + if (children.length) { + let last = children[children.length - 1]; + if (last.kind === expectedLastToken) { + return true; + } + else if (last.kind === SyntaxKind.SemicolonToken && children.length !== 1) { + return children[children.length - 2].kind === expectedLastToken; + } + } + return false; + } + export function findListItemInfo(node: Node): ListItemInfo { let list = findContainingList(node); @@ -79,6 +230,10 @@ module ts { }; } + export function hasChildOfKind(n: Node, kind: SyntaxKind, sourceFile?: SourceFile): boolean { + return !!findChildOfKind(n, kind, sourceFile); + } + export function findChildOfKind(n: Node, kind: SyntaxKind, sourceFile?: SourceFile): Node { return forEach(n.getChildren(sourceFile), c => c.kind === kind && c); } @@ -316,6 +471,17 @@ module ts { && (node.getStart() < position && position < node.getEnd()) || (!!node.isUnterminated && position === node.getEnd()); } + export function isAccessibilityModifier(kind: SyntaxKind) { + switch (kind) { + case SyntaxKind.PublicKeyword: + case SyntaxKind.PrivateKeyword: + case SyntaxKind.ProtectedKeyword: + return true; + } + + return false; + } + export function compareDataObjects(dst: any, src: any): boolean { for (let e in dst) { if (typeof dst[e] === "object") { @@ -445,6 +611,13 @@ module ts { return displayPart(tokenToString(kind), SymbolDisplayPartKind.operator); } + export function textOrKeywordPart(text: string) { + var kind = stringToToken(text); + return kind === undefined + ? textPart(text) + : keywordPart(kind); + } + export function textPart(text: string) { return displayPart(text, SymbolDisplayPartKind.text); } diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 86cd5b5ff44ac..07d5e4337a69e 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -111,192 +111,195 @@ declare module "typescript" { BarBarToken = 49, QuestionToken = 50, ColonToken = 51, - EqualsToken = 52, - PlusEqualsToken = 53, - MinusEqualsToken = 54, - AsteriskEqualsToken = 55, - SlashEqualsToken = 56, - PercentEqualsToken = 57, - LessThanLessThanEqualsToken = 58, - GreaterThanGreaterThanEqualsToken = 59, - GreaterThanGreaterThanGreaterThanEqualsToken = 60, - AmpersandEqualsToken = 61, - BarEqualsToken = 62, - CaretEqualsToken = 63, - Identifier = 64, - BreakKeyword = 65, - CaseKeyword = 66, - CatchKeyword = 67, - ClassKeyword = 68, - ConstKeyword = 69, - ContinueKeyword = 70, - DebuggerKeyword = 71, - DefaultKeyword = 72, - DeleteKeyword = 73, - DoKeyword = 74, - ElseKeyword = 75, - EnumKeyword = 76, - ExportKeyword = 77, - ExtendsKeyword = 78, - FalseKeyword = 79, - FinallyKeyword = 80, - ForKeyword = 81, - FunctionKeyword = 82, - IfKeyword = 83, - ImportKeyword = 84, - InKeyword = 85, - InstanceOfKeyword = 86, - NewKeyword = 87, - NullKeyword = 88, - ReturnKeyword = 89, - SuperKeyword = 90, - SwitchKeyword = 91, - ThisKeyword = 92, - ThrowKeyword = 93, - TrueKeyword = 94, - TryKeyword = 95, - TypeOfKeyword = 96, - VarKeyword = 97, - VoidKeyword = 98, - WhileKeyword = 99, - WithKeyword = 100, - AsKeyword = 101, - ImplementsKeyword = 102, - InterfaceKeyword = 103, - LetKeyword = 104, - PackageKeyword = 105, - PrivateKeyword = 106, - ProtectedKeyword = 107, - PublicKeyword = 108, - StaticKeyword = 109, - YieldKeyword = 110, - AnyKeyword = 111, - BooleanKeyword = 112, - ConstructorKeyword = 113, - DeclareKeyword = 114, - GetKeyword = 115, - ModuleKeyword = 116, - RequireKeyword = 117, - NumberKeyword = 118, - SetKeyword = 119, - StringKeyword = 120, - SymbolKeyword = 121, - TypeKeyword = 122, - FromKeyword = 123, - OfKeyword = 124, - QualifiedName = 125, - ComputedPropertyName = 126, - TypeParameter = 127, - Parameter = 128, - PropertySignature = 129, - PropertyDeclaration = 130, - MethodSignature = 131, - MethodDeclaration = 132, - Constructor = 133, - GetAccessor = 134, - SetAccessor = 135, - CallSignature = 136, - ConstructSignature = 137, - IndexSignature = 138, - TypeReference = 139, - FunctionType = 140, - ConstructorType = 141, - TypeQuery = 142, - TypeLiteral = 143, - ArrayType = 144, - TupleType = 145, - UnionType = 146, - ParenthesizedType = 147, - ObjectBindingPattern = 148, - ArrayBindingPattern = 149, - BindingElement = 150, - ArrayLiteralExpression = 151, - ObjectLiteralExpression = 152, - PropertyAccessExpression = 153, - ElementAccessExpression = 154, - CallExpression = 155, - NewExpression = 156, - TaggedTemplateExpression = 157, - TypeAssertionExpression = 158, - ParenthesizedExpression = 159, - FunctionExpression = 160, - ArrowFunction = 161, - DeleteExpression = 162, - TypeOfExpression = 163, - VoidExpression = 164, - PrefixUnaryExpression = 165, - PostfixUnaryExpression = 166, - BinaryExpression = 167, - ConditionalExpression = 168, - TemplateExpression = 169, - YieldExpression = 170, - SpreadElementExpression = 171, - OmittedExpression = 172, - TemplateSpan = 173, - Block = 174, - VariableStatement = 175, - EmptyStatement = 176, - ExpressionStatement = 177, - IfStatement = 178, - DoStatement = 179, - WhileStatement = 180, - ForStatement = 181, - ForInStatement = 182, - ForOfStatement = 183, - ContinueStatement = 184, - BreakStatement = 185, - ReturnStatement = 186, - WithStatement = 187, - SwitchStatement = 188, - LabeledStatement = 189, - ThrowStatement = 190, - TryStatement = 191, - DebuggerStatement = 192, - VariableDeclaration = 193, - VariableDeclarationList = 194, - FunctionDeclaration = 195, - ClassDeclaration = 196, - InterfaceDeclaration = 197, - TypeAliasDeclaration = 198, - EnumDeclaration = 199, - ModuleDeclaration = 200, - ModuleBlock = 201, - CaseBlock = 202, - ImportEqualsDeclaration = 203, - ImportDeclaration = 204, - ImportClause = 205, - NamespaceImport = 206, - NamedImports = 207, - ImportSpecifier = 208, - ExportAssignment = 209, - ExportDeclaration = 210, - NamedExports = 211, - ExportSpecifier = 212, - ExternalModuleReference = 213, - CaseClause = 214, - DefaultClause = 215, - HeritageClause = 216, - CatchClause = 217, - PropertyAssignment = 218, - ShorthandPropertyAssignment = 219, - EnumMember = 220, - SourceFile = 221, - SyntaxList = 222, - Count = 223, - FirstAssignment = 52, - LastAssignment = 63, - FirstReservedWord = 65, - LastReservedWord = 100, - FirstKeyword = 65, - LastKeyword = 124, - FirstFutureReservedWord = 102, - LastFutureReservedWord = 110, - FirstTypeNode = 139, - LastTypeNode = 147, + AtToken = 52, + EqualsToken = 53, + PlusEqualsToken = 54, + MinusEqualsToken = 55, + AsteriskEqualsToken = 56, + SlashEqualsToken = 57, + PercentEqualsToken = 58, + LessThanLessThanEqualsToken = 59, + GreaterThanGreaterThanEqualsToken = 60, + GreaterThanGreaterThanGreaterThanEqualsToken = 61, + AmpersandEqualsToken = 62, + BarEqualsToken = 63, + CaretEqualsToken = 64, + Identifier = 65, + BreakKeyword = 66, + CaseKeyword = 67, + CatchKeyword = 68, + ClassKeyword = 69, + ConstKeyword = 70, + ContinueKeyword = 71, + DebuggerKeyword = 72, + DefaultKeyword = 73, + DeleteKeyword = 74, + DoKeyword = 75, + ElseKeyword = 76, + EnumKeyword = 77, + ExportKeyword = 78, + ExtendsKeyword = 79, + FalseKeyword = 80, + FinallyKeyword = 81, + ForKeyword = 82, + FunctionKeyword = 83, + IfKeyword = 84, + ImportKeyword = 85, + InKeyword = 86, + InstanceOfKeyword = 87, + NewKeyword = 88, + NullKeyword = 89, + ReturnKeyword = 90, + SuperKeyword = 91, + SwitchKeyword = 92, + ThisKeyword = 93, + ThrowKeyword = 94, + TrueKeyword = 95, + TryKeyword = 96, + TypeOfKeyword = 97, + VarKeyword = 98, + VoidKeyword = 99, + WhileKeyword = 100, + WithKeyword = 101, + AsKeyword = 102, + ImplementsKeyword = 103, + InterfaceKeyword = 104, + LetKeyword = 105, + PackageKeyword = 106, + PrivateKeyword = 107, + ProtectedKeyword = 108, + PublicKeyword = 109, + StaticKeyword = 110, + YieldKeyword = 111, + AnyKeyword = 112, + BooleanKeyword = 113, + ConstructorKeyword = 114, + DeclareKeyword = 115, + GetKeyword = 116, + ModuleKeyword = 117, + RequireKeyword = 118, + NumberKeyword = 119, + SetKeyword = 120, + StringKeyword = 121, + SymbolKeyword = 122, + TypeKeyword = 123, + FromKeyword = 124, + OfKeyword = 125, + QualifiedName = 126, + ComputedPropertyName = 127, + TypeParameter = 128, + Parameter = 129, + Decorator = 130, + PropertySignature = 131, + PropertyDeclaration = 132, + MethodSignature = 133, + MethodDeclaration = 134, + Constructor = 135, + GetAccessor = 136, + SetAccessor = 137, + CallSignature = 138, + ConstructSignature = 139, + IndexSignature = 140, + TypeReference = 141, + FunctionType = 142, + ConstructorType = 143, + TypeQuery = 144, + TypeLiteral = 145, + ArrayType = 146, + TupleType = 147, + UnionType = 148, + ParenthesizedType = 149, + ObjectBindingPattern = 150, + ArrayBindingPattern = 151, + BindingElement = 152, + ArrayLiteralExpression = 153, + ObjectLiteralExpression = 154, + PropertyAccessExpression = 155, + ElementAccessExpression = 156, + CallExpression = 157, + NewExpression = 158, + TaggedTemplateExpression = 159, + TypeAssertionExpression = 160, + ParenthesizedExpression = 161, + FunctionExpression = 162, + ArrowFunction = 163, + DeleteExpression = 164, + TypeOfExpression = 165, + VoidExpression = 166, + PrefixUnaryExpression = 167, + PostfixUnaryExpression = 168, + BinaryExpression = 169, + ConditionalExpression = 170, + TemplateExpression = 171, + YieldExpression = 172, + SpreadElementExpression = 173, + OmittedExpression = 174, + TemplateSpan = 175, + Block = 176, + VariableStatement = 177, + EmptyStatement = 178, + ExpressionStatement = 179, + IfStatement = 180, + DoStatement = 181, + WhileStatement = 182, + ForStatement = 183, + ForInStatement = 184, + ForOfStatement = 185, + ContinueStatement = 186, + BreakStatement = 187, + ReturnStatement = 188, + WithStatement = 189, + SwitchStatement = 190, + LabeledStatement = 191, + ThrowStatement = 192, + TryStatement = 193, + DebuggerStatement = 194, + VariableDeclaration = 195, + VariableDeclarationList = 196, + FunctionDeclaration = 197, + ClassDeclaration = 198, + InterfaceDeclaration = 199, + TypeAliasDeclaration = 200, + EnumDeclaration = 201, + ModuleDeclaration = 202, + ModuleBlock = 203, + CaseBlock = 204, + ImportEqualsDeclaration = 205, + ImportDeclaration = 206, + ImportClause = 207, + NamespaceImport = 208, + NamedImports = 209, + ImportSpecifier = 210, + ExportAssignment = 211, + ExportDeclaration = 212, + NamedExports = 213, + ExportSpecifier = 214, + MissingDeclaration = 215, + ExternalModuleReference = 216, + CaseClause = 217, + DefaultClause = 218, + HeritageClause = 219, + CatchClause = 220, + PropertyAssignment = 221, + ShorthandPropertyAssignment = 222, + EnumMember = 223, + SourceFile = 224, + SyntaxList = 225, + Count = 226, + FirstAssignment = 53, + LastAssignment = 64, + FirstReservedWord = 66, + LastReservedWord = 101, + FirstKeyword = 66, + LastKeyword = 125, + FirstFutureReservedWord = 103, + LastFutureReservedWord = 111, + FirstTypeNode = 141, + LastTypeNode = 149, FirstPunctuation = 14, - LastPunctuation = 63, + LastPunctuation = 64, FirstToken = 0, - LastToken = 124, + LastToken = 125, FirstTriviaToken = 2, LastTriviaToken = 6, FirstLiteralToken = 7, @@ -304,8 +307,8 @@ declare module "typescript" { FirstTemplateToken = 10, LastTemplateToken = 13, FirstBinaryOperator = 24, - LastBinaryOperator = 63, - FirstNode = 125, + LastBinaryOperator = 64, + FirstNode = 126, } const enum NodeFlags { Export = 1, @@ -331,10 +334,11 @@ declare module "typescript" { DisallowIn = 2, Yield = 4, GeneratorParameter = 8, - ThisNodeHasError = 16, - ParserGeneratedFlags = 31, - ThisNodeOrAnySubNodesHasError = 32, - HasAggregatedChildData = 64, + Decorator = 16, + ThisNodeHasError = 32, + ParserGeneratedFlags = 63, + ThisNodeOrAnySubNodesHasError = 64, + HasAggregatedChildData = 128, } const enum RelationComparisonResult { Succeeded = 1, @@ -345,6 +349,7 @@ declare module "typescript" { kind: SyntaxKind; flags: NodeFlags; parserContextFlags?: ParserContextFlags; + decorators?: NodeArray; modifiers?: ModifiersArray; id?: number; parent?: Node; @@ -375,6 +380,9 @@ declare module "typescript" { interface ComputedPropertyName extends Node { expression: Expression; } + interface Decorator extends Node { + expression: LeftHandSideExpression; + } interface TypeParameterDeclaration extends Declaration { name: Identifier; constraint?: TypeNode; @@ -554,6 +562,9 @@ declare module "typescript" { name?: Identifier; body: Block | Expression; } + interface ArrowFunction extends Expression, FunctionLikeDeclaration { + equalsGreaterThanToken: Node; + } interface LiteralExpression extends PrimaryExpression { text: string; isUnterminated?: boolean; @@ -763,7 +774,8 @@ declare module "typescript" { type ExportSpecifier = ImportOrExportSpecifier; interface ExportAssignment extends Declaration, ModuleElement { isExportEquals?: boolean; - expression: Expression; + expression?: Expression; + type?: TypeNode; } interface FileReference extends TextRange { fileName: string; @@ -798,14 +810,14 @@ declare module "typescript" { interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then - * the javascript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the javascript and declaration for that + * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then + * the JavaScript and declaration files will be produced for all the files in this program. + * If targetSourceFile is specified, then only the JavaScript and declaration for that * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the javascript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; @@ -924,9 +936,10 @@ declare module "typescript" { NotAccessible = 1, CannotBeNamed = 2, } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; interface SymbolVisibilityResult { accessibility: SymbolAccessibility; - aliasesToMakeVisible?: ImportEqualsDeclaration[]; + aliasesToMakeVisible?: AnyImportSyntax[]; errorSymbolName?: string; errorNode?: Node; } @@ -934,20 +947,22 @@ declare module "typescript" { errorModuleName?: string; } interface EmitResolver { - getGeneratedNameForNode(node: Node): string; - getExpressionNameSubstitution(node: Identifier): string; + hasGlobalName(name: string): boolean; + getExpressionNameSubstitution(node: Identifier, getGeneratedNameForNode: (node: Node) => string): string; isValueAliasDeclaration(node: Node): boolean; - isReferencedAliasDeclaration(node: Node): boolean; + isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; + collectLinkedAliases(node: Identifier): Node[]; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; - isUnknownIdentifier(location: Node, name: string): boolean; + resolvesToSomeValue(location: Node, name: string): boolean; getBlockScopedVariableId(node: Identifier): number; } const enum SymbolFlags { @@ -1054,6 +1069,7 @@ declare module "typescript" { ContextChecked = 64, EnumValuesComputed = 128, BlockScopedBindingInLoop = 256, + EmitDecorate = 512, } interface NodeLinks { resolvedType?: Type; @@ -1173,17 +1189,6 @@ declare module "typescript" { interface TypeMapper { (t: Type): Type; } - interface TypeInferences { - primary: Type[]; - secondary: Type[]; - } - interface InferenceContext { - typeParameters: TypeParameter[]; - inferUnionTypes: boolean; - inferences: TypeInferences[]; - inferredTypes: Type[]; - failedTypeParameterIndex?: number; - } interface DiagnosticMessage { key: string; category: DiagnosticCategory; @@ -1480,7 +1485,8 @@ declare module "typescript" { declare module "typescript" { /** The version of the TypeScript compiler release */ let version: string; - function createCompilerHost(options: CompilerOptions): CompilerHost; + function findConfigFile(searchPath: string): string; + function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; function getPreEmitDiagnostics(program: Program): Diagnostic[]; function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; @@ -1594,6 +1600,7 @@ declare module "typescript" { getDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[]; getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[]; getOccurrencesAtPosition(fileName: string, position: number): ReferenceEntry[]; + findReferences(fileName: string, position: number): ReferencedSymbol[]; getNavigateToItems(searchValue: string, maxResultCount?: number): NavigateToItem[]; getNavigationBarItems(fileName: string): NavigationBarItem[]; getOutliningSpans(fileName: string): OutliningSpan[]; @@ -1680,6 +1687,10 @@ declare module "typescript" { containerKind: string; containerName: string; } + interface ReferencedSymbol { + definition: DefinitionInfo; + references: ReferenceEntry[]; + } enum SymbolDisplayPartKind { aliasName = 0, className = 1, diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 33b0ab2228b8b..eff47a4cb7bf1 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -351,562 +351,571 @@ declare module "typescript" { ColonToken = 51, >ColonToken : SyntaxKind - EqualsToken = 52, + AtToken = 52, +>AtToken : SyntaxKind + + EqualsToken = 53, >EqualsToken : SyntaxKind - PlusEqualsToken = 53, + PlusEqualsToken = 54, >PlusEqualsToken : SyntaxKind - MinusEqualsToken = 54, + MinusEqualsToken = 55, >MinusEqualsToken : SyntaxKind - AsteriskEqualsToken = 55, + AsteriskEqualsToken = 56, >AsteriskEqualsToken : SyntaxKind - SlashEqualsToken = 56, + SlashEqualsToken = 57, >SlashEqualsToken : SyntaxKind - PercentEqualsToken = 57, + PercentEqualsToken = 58, >PercentEqualsToken : SyntaxKind - LessThanLessThanEqualsToken = 58, + LessThanLessThanEqualsToken = 59, >LessThanLessThanEqualsToken : SyntaxKind - GreaterThanGreaterThanEqualsToken = 59, + GreaterThanGreaterThanEqualsToken = 60, >GreaterThanGreaterThanEqualsToken : SyntaxKind - GreaterThanGreaterThanGreaterThanEqualsToken = 60, + GreaterThanGreaterThanGreaterThanEqualsToken = 61, >GreaterThanGreaterThanGreaterThanEqualsToken : SyntaxKind - AmpersandEqualsToken = 61, + AmpersandEqualsToken = 62, >AmpersandEqualsToken : SyntaxKind - BarEqualsToken = 62, + BarEqualsToken = 63, >BarEqualsToken : SyntaxKind - CaretEqualsToken = 63, + CaretEqualsToken = 64, >CaretEqualsToken : SyntaxKind - Identifier = 64, + Identifier = 65, >Identifier : SyntaxKind - BreakKeyword = 65, + BreakKeyword = 66, >BreakKeyword : SyntaxKind - CaseKeyword = 66, + CaseKeyword = 67, >CaseKeyword : SyntaxKind - CatchKeyword = 67, + CatchKeyword = 68, >CatchKeyword : SyntaxKind - ClassKeyword = 68, + ClassKeyword = 69, >ClassKeyword : SyntaxKind - ConstKeyword = 69, + ConstKeyword = 70, >ConstKeyword : SyntaxKind - ContinueKeyword = 70, + ContinueKeyword = 71, >ContinueKeyword : SyntaxKind - DebuggerKeyword = 71, + DebuggerKeyword = 72, >DebuggerKeyword : SyntaxKind - DefaultKeyword = 72, + DefaultKeyword = 73, >DefaultKeyword : SyntaxKind - DeleteKeyword = 73, + DeleteKeyword = 74, >DeleteKeyword : SyntaxKind - DoKeyword = 74, + DoKeyword = 75, >DoKeyword : SyntaxKind - ElseKeyword = 75, + ElseKeyword = 76, >ElseKeyword : SyntaxKind - EnumKeyword = 76, + EnumKeyword = 77, >EnumKeyword : SyntaxKind - ExportKeyword = 77, + ExportKeyword = 78, >ExportKeyword : SyntaxKind - ExtendsKeyword = 78, + ExtendsKeyword = 79, >ExtendsKeyword : SyntaxKind - FalseKeyword = 79, + FalseKeyword = 80, >FalseKeyword : SyntaxKind - FinallyKeyword = 80, + FinallyKeyword = 81, >FinallyKeyword : SyntaxKind - ForKeyword = 81, + ForKeyword = 82, >ForKeyword : SyntaxKind - FunctionKeyword = 82, + FunctionKeyword = 83, >FunctionKeyword : SyntaxKind - IfKeyword = 83, + IfKeyword = 84, >IfKeyword : SyntaxKind - ImportKeyword = 84, + ImportKeyword = 85, >ImportKeyword : SyntaxKind - InKeyword = 85, + InKeyword = 86, >InKeyword : SyntaxKind - InstanceOfKeyword = 86, + InstanceOfKeyword = 87, >InstanceOfKeyword : SyntaxKind - NewKeyword = 87, + NewKeyword = 88, >NewKeyword : SyntaxKind - NullKeyword = 88, + NullKeyword = 89, >NullKeyword : SyntaxKind - ReturnKeyword = 89, + ReturnKeyword = 90, >ReturnKeyword : SyntaxKind - SuperKeyword = 90, + SuperKeyword = 91, >SuperKeyword : SyntaxKind - SwitchKeyword = 91, + SwitchKeyword = 92, >SwitchKeyword : SyntaxKind - ThisKeyword = 92, + ThisKeyword = 93, >ThisKeyword : SyntaxKind - ThrowKeyword = 93, + ThrowKeyword = 94, >ThrowKeyword : SyntaxKind - TrueKeyword = 94, + TrueKeyword = 95, >TrueKeyword : SyntaxKind - TryKeyword = 95, + TryKeyword = 96, >TryKeyword : SyntaxKind - TypeOfKeyword = 96, + TypeOfKeyword = 97, >TypeOfKeyword : SyntaxKind - VarKeyword = 97, + VarKeyword = 98, >VarKeyword : SyntaxKind - VoidKeyword = 98, + VoidKeyword = 99, >VoidKeyword : SyntaxKind - WhileKeyword = 99, + WhileKeyword = 100, >WhileKeyword : SyntaxKind - WithKeyword = 100, + WithKeyword = 101, >WithKeyword : SyntaxKind - AsKeyword = 101, + AsKeyword = 102, >AsKeyword : SyntaxKind - ImplementsKeyword = 102, + ImplementsKeyword = 103, >ImplementsKeyword : SyntaxKind - InterfaceKeyword = 103, + InterfaceKeyword = 104, >InterfaceKeyword : SyntaxKind - LetKeyword = 104, + LetKeyword = 105, >LetKeyword : SyntaxKind - PackageKeyword = 105, + PackageKeyword = 106, >PackageKeyword : SyntaxKind - PrivateKeyword = 106, + PrivateKeyword = 107, >PrivateKeyword : SyntaxKind - ProtectedKeyword = 107, + ProtectedKeyword = 108, >ProtectedKeyword : SyntaxKind - PublicKeyword = 108, + PublicKeyword = 109, >PublicKeyword : SyntaxKind - StaticKeyword = 109, + StaticKeyword = 110, >StaticKeyword : SyntaxKind - YieldKeyword = 110, + YieldKeyword = 111, >YieldKeyword : SyntaxKind - AnyKeyword = 111, + AnyKeyword = 112, >AnyKeyword : SyntaxKind - BooleanKeyword = 112, + BooleanKeyword = 113, >BooleanKeyword : SyntaxKind - ConstructorKeyword = 113, + ConstructorKeyword = 114, >ConstructorKeyword : SyntaxKind - DeclareKeyword = 114, + DeclareKeyword = 115, >DeclareKeyword : SyntaxKind - GetKeyword = 115, + GetKeyword = 116, >GetKeyword : SyntaxKind - ModuleKeyword = 116, + ModuleKeyword = 117, >ModuleKeyword : SyntaxKind - RequireKeyword = 117, + RequireKeyword = 118, >RequireKeyword : SyntaxKind - NumberKeyword = 118, + NumberKeyword = 119, >NumberKeyword : SyntaxKind - SetKeyword = 119, + SetKeyword = 120, >SetKeyword : SyntaxKind - StringKeyword = 120, + StringKeyword = 121, >StringKeyword : SyntaxKind - SymbolKeyword = 121, + SymbolKeyword = 122, >SymbolKeyword : SyntaxKind - TypeKeyword = 122, + TypeKeyword = 123, >TypeKeyword : SyntaxKind - FromKeyword = 123, + FromKeyword = 124, >FromKeyword : SyntaxKind - OfKeyword = 124, + OfKeyword = 125, >OfKeyword : SyntaxKind - QualifiedName = 125, + QualifiedName = 126, >QualifiedName : SyntaxKind - ComputedPropertyName = 126, + ComputedPropertyName = 127, >ComputedPropertyName : SyntaxKind - TypeParameter = 127, + TypeParameter = 128, >TypeParameter : SyntaxKind - Parameter = 128, + Parameter = 129, >Parameter : SyntaxKind - PropertySignature = 129, + Decorator = 130, +>Decorator : SyntaxKind + + PropertySignature = 131, >PropertySignature : SyntaxKind - PropertyDeclaration = 130, + PropertyDeclaration = 132, >PropertyDeclaration : SyntaxKind - MethodSignature = 131, + MethodSignature = 133, >MethodSignature : SyntaxKind - MethodDeclaration = 132, + MethodDeclaration = 134, >MethodDeclaration : SyntaxKind - Constructor = 133, + Constructor = 135, >Constructor : SyntaxKind - GetAccessor = 134, + GetAccessor = 136, >GetAccessor : SyntaxKind - SetAccessor = 135, + SetAccessor = 137, >SetAccessor : SyntaxKind - CallSignature = 136, + CallSignature = 138, >CallSignature : SyntaxKind - ConstructSignature = 137, + ConstructSignature = 139, >ConstructSignature : SyntaxKind - IndexSignature = 138, + IndexSignature = 140, >IndexSignature : SyntaxKind - TypeReference = 139, + TypeReference = 141, >TypeReference : SyntaxKind - FunctionType = 140, + FunctionType = 142, >FunctionType : SyntaxKind - ConstructorType = 141, + ConstructorType = 143, >ConstructorType : SyntaxKind - TypeQuery = 142, + TypeQuery = 144, >TypeQuery : SyntaxKind - TypeLiteral = 143, + TypeLiteral = 145, >TypeLiteral : SyntaxKind - ArrayType = 144, + ArrayType = 146, >ArrayType : SyntaxKind - TupleType = 145, + TupleType = 147, >TupleType : SyntaxKind - UnionType = 146, + UnionType = 148, >UnionType : SyntaxKind - ParenthesizedType = 147, + ParenthesizedType = 149, >ParenthesizedType : SyntaxKind - ObjectBindingPattern = 148, + ObjectBindingPattern = 150, >ObjectBindingPattern : SyntaxKind - ArrayBindingPattern = 149, + ArrayBindingPattern = 151, >ArrayBindingPattern : SyntaxKind - BindingElement = 150, + BindingElement = 152, >BindingElement : SyntaxKind - ArrayLiteralExpression = 151, + ArrayLiteralExpression = 153, >ArrayLiteralExpression : SyntaxKind - ObjectLiteralExpression = 152, + ObjectLiteralExpression = 154, >ObjectLiteralExpression : SyntaxKind - PropertyAccessExpression = 153, + PropertyAccessExpression = 155, >PropertyAccessExpression : SyntaxKind - ElementAccessExpression = 154, + ElementAccessExpression = 156, >ElementAccessExpression : SyntaxKind - CallExpression = 155, + CallExpression = 157, >CallExpression : SyntaxKind - NewExpression = 156, + NewExpression = 158, >NewExpression : SyntaxKind - TaggedTemplateExpression = 157, + TaggedTemplateExpression = 159, >TaggedTemplateExpression : SyntaxKind - TypeAssertionExpression = 158, + TypeAssertionExpression = 160, >TypeAssertionExpression : SyntaxKind - ParenthesizedExpression = 159, + ParenthesizedExpression = 161, >ParenthesizedExpression : SyntaxKind - FunctionExpression = 160, + FunctionExpression = 162, >FunctionExpression : SyntaxKind - ArrowFunction = 161, + ArrowFunction = 163, >ArrowFunction : SyntaxKind - DeleteExpression = 162, + DeleteExpression = 164, >DeleteExpression : SyntaxKind - TypeOfExpression = 163, + TypeOfExpression = 165, >TypeOfExpression : SyntaxKind - VoidExpression = 164, + VoidExpression = 166, >VoidExpression : SyntaxKind - PrefixUnaryExpression = 165, + PrefixUnaryExpression = 167, >PrefixUnaryExpression : SyntaxKind - PostfixUnaryExpression = 166, + PostfixUnaryExpression = 168, >PostfixUnaryExpression : SyntaxKind - BinaryExpression = 167, + BinaryExpression = 169, >BinaryExpression : SyntaxKind - ConditionalExpression = 168, + ConditionalExpression = 170, >ConditionalExpression : SyntaxKind - TemplateExpression = 169, + TemplateExpression = 171, >TemplateExpression : SyntaxKind - YieldExpression = 170, + YieldExpression = 172, >YieldExpression : SyntaxKind - SpreadElementExpression = 171, + SpreadElementExpression = 173, >SpreadElementExpression : SyntaxKind - OmittedExpression = 172, + OmittedExpression = 174, >OmittedExpression : SyntaxKind - TemplateSpan = 173, + TemplateSpan = 175, >TemplateSpan : SyntaxKind - Block = 174, + Block = 176, >Block : SyntaxKind - VariableStatement = 175, + VariableStatement = 177, >VariableStatement : SyntaxKind - EmptyStatement = 176, + EmptyStatement = 178, >EmptyStatement : SyntaxKind - ExpressionStatement = 177, + ExpressionStatement = 179, >ExpressionStatement : SyntaxKind - IfStatement = 178, + IfStatement = 180, >IfStatement : SyntaxKind - DoStatement = 179, + DoStatement = 181, >DoStatement : SyntaxKind - WhileStatement = 180, + WhileStatement = 182, >WhileStatement : SyntaxKind - ForStatement = 181, + ForStatement = 183, >ForStatement : SyntaxKind - ForInStatement = 182, + ForInStatement = 184, >ForInStatement : SyntaxKind - ForOfStatement = 183, + ForOfStatement = 185, >ForOfStatement : SyntaxKind - ContinueStatement = 184, + ContinueStatement = 186, >ContinueStatement : SyntaxKind - BreakStatement = 185, + BreakStatement = 187, >BreakStatement : SyntaxKind - ReturnStatement = 186, + ReturnStatement = 188, >ReturnStatement : SyntaxKind - WithStatement = 187, + WithStatement = 189, >WithStatement : SyntaxKind - SwitchStatement = 188, + SwitchStatement = 190, >SwitchStatement : SyntaxKind - LabeledStatement = 189, + LabeledStatement = 191, >LabeledStatement : SyntaxKind - ThrowStatement = 190, + ThrowStatement = 192, >ThrowStatement : SyntaxKind - TryStatement = 191, + TryStatement = 193, >TryStatement : SyntaxKind - DebuggerStatement = 192, + DebuggerStatement = 194, >DebuggerStatement : SyntaxKind - VariableDeclaration = 193, + VariableDeclaration = 195, >VariableDeclaration : SyntaxKind - VariableDeclarationList = 194, + VariableDeclarationList = 196, >VariableDeclarationList : SyntaxKind - FunctionDeclaration = 195, + FunctionDeclaration = 197, >FunctionDeclaration : SyntaxKind - ClassDeclaration = 196, + ClassDeclaration = 198, >ClassDeclaration : SyntaxKind - InterfaceDeclaration = 197, + InterfaceDeclaration = 199, >InterfaceDeclaration : SyntaxKind - TypeAliasDeclaration = 198, + TypeAliasDeclaration = 200, >TypeAliasDeclaration : SyntaxKind - EnumDeclaration = 199, + EnumDeclaration = 201, >EnumDeclaration : SyntaxKind - ModuleDeclaration = 200, + ModuleDeclaration = 202, >ModuleDeclaration : SyntaxKind - ModuleBlock = 201, + ModuleBlock = 203, >ModuleBlock : SyntaxKind - CaseBlock = 202, + CaseBlock = 204, >CaseBlock : SyntaxKind - ImportEqualsDeclaration = 203, + ImportEqualsDeclaration = 205, >ImportEqualsDeclaration : SyntaxKind - ImportDeclaration = 204, + ImportDeclaration = 206, >ImportDeclaration : SyntaxKind - ImportClause = 205, + ImportClause = 207, >ImportClause : SyntaxKind - NamespaceImport = 206, + NamespaceImport = 208, >NamespaceImport : SyntaxKind - NamedImports = 207, + NamedImports = 209, >NamedImports : SyntaxKind - ImportSpecifier = 208, + ImportSpecifier = 210, >ImportSpecifier : SyntaxKind - ExportAssignment = 209, + ExportAssignment = 211, >ExportAssignment : SyntaxKind - ExportDeclaration = 210, + ExportDeclaration = 212, >ExportDeclaration : SyntaxKind - NamedExports = 211, + NamedExports = 213, >NamedExports : SyntaxKind - ExportSpecifier = 212, + ExportSpecifier = 214, >ExportSpecifier : SyntaxKind - ExternalModuleReference = 213, + MissingDeclaration = 215, +>MissingDeclaration : SyntaxKind + + ExternalModuleReference = 216, >ExternalModuleReference : SyntaxKind - CaseClause = 214, + CaseClause = 217, >CaseClause : SyntaxKind - DefaultClause = 215, + DefaultClause = 218, >DefaultClause : SyntaxKind - HeritageClause = 216, + HeritageClause = 219, >HeritageClause : SyntaxKind - CatchClause = 217, + CatchClause = 220, >CatchClause : SyntaxKind - PropertyAssignment = 218, + PropertyAssignment = 221, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 219, + ShorthandPropertyAssignment = 222, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 220, + EnumMember = 223, >EnumMember : SyntaxKind - SourceFile = 221, + SourceFile = 224, >SourceFile : SyntaxKind - SyntaxList = 222, + SyntaxList = 225, >SyntaxList : SyntaxKind - Count = 223, + Count = 226, >Count : SyntaxKind - FirstAssignment = 52, + FirstAssignment = 53, >FirstAssignment : SyntaxKind - LastAssignment = 63, + LastAssignment = 64, >LastAssignment : SyntaxKind - FirstReservedWord = 65, + FirstReservedWord = 66, >FirstReservedWord : SyntaxKind - LastReservedWord = 100, + LastReservedWord = 101, >LastReservedWord : SyntaxKind - FirstKeyword = 65, + FirstKeyword = 66, >FirstKeyword : SyntaxKind - LastKeyword = 124, + LastKeyword = 125, >LastKeyword : SyntaxKind - FirstFutureReservedWord = 102, + FirstFutureReservedWord = 103, >FirstFutureReservedWord : SyntaxKind - LastFutureReservedWord = 110, + LastFutureReservedWord = 111, >LastFutureReservedWord : SyntaxKind - FirstTypeNode = 139, + FirstTypeNode = 141, >FirstTypeNode : SyntaxKind - LastTypeNode = 147, + LastTypeNode = 149, >LastTypeNode : SyntaxKind FirstPunctuation = 14, >FirstPunctuation : SyntaxKind - LastPunctuation = 63, + LastPunctuation = 64, >LastPunctuation : SyntaxKind FirstToken = 0, >FirstToken : SyntaxKind - LastToken = 124, + LastToken = 125, >LastToken : SyntaxKind FirstTriviaToken = 2, @@ -930,10 +939,10 @@ declare module "typescript" { FirstBinaryOperator = 24, >FirstBinaryOperator : SyntaxKind - LastBinaryOperator = 63, + LastBinaryOperator = 64, >LastBinaryOperator : SyntaxKind - FirstNode = 125, + FirstNode = 126, >FirstNode : SyntaxKind } const enum NodeFlags { @@ -1005,16 +1014,19 @@ declare module "typescript" { GeneratorParameter = 8, >GeneratorParameter : ParserContextFlags - ThisNodeHasError = 16, + Decorator = 16, +>Decorator : ParserContextFlags + + ThisNodeHasError = 32, >ThisNodeHasError : ParserContextFlags - ParserGeneratedFlags = 31, + ParserGeneratedFlags = 63, >ParserGeneratedFlags : ParserContextFlags - ThisNodeOrAnySubNodesHasError = 32, + ThisNodeOrAnySubNodesHasError = 64, >ThisNodeOrAnySubNodesHasError : ParserContextFlags - HasAggregatedChildData = 64, + HasAggregatedChildData = 128, >HasAggregatedChildData : ParserContextFlags } const enum RelationComparisonResult { @@ -1045,6 +1057,11 @@ declare module "typescript" { >parserContextFlags : ParserContextFlags >ParserContextFlags : ParserContextFlags + decorators?: NodeArray; +>decorators : NodeArray +>NodeArray : NodeArray +>Decorator : Decorator + modifiers?: ModifiersArray; >modifiers : ModifiersArray >ModifiersArray : ModifiersArray @@ -1139,6 +1156,14 @@ declare module "typescript" { expression: Expression; >expression : Expression >Expression : Expression + } + interface Decorator extends Node { +>Decorator : Decorator +>Node : Node + + expression: LeftHandSideExpression; +>expression : LeftHandSideExpression +>LeftHandSideExpression : LeftHandSideExpression } interface TypeParameterDeclaration extends Declaration { >TypeParameterDeclaration : TypeParameterDeclaration @@ -1671,6 +1696,15 @@ declare module "typescript" { >body : Expression | Block >Block : Block >Expression : Expression + } + interface ArrowFunction extends Expression, FunctionLikeDeclaration { +>ArrowFunction : ArrowFunction +>Expression : Expression +>FunctionLikeDeclaration : FunctionLikeDeclaration + + equalsGreaterThanToken: Node; +>equalsGreaterThanToken : Node +>Node : Node } interface LiteralExpression extends PrimaryExpression { >LiteralExpression : LiteralExpression @@ -2327,9 +2361,13 @@ declare module "typescript" { isExportEquals?: boolean; >isExportEquals : boolean - expression: Expression; + expression?: Expression; >expression : Expression >Expression : Expression + + type?: TypeNode; +>type : TypeNode +>TypeNode : TypeNode } interface FileReference extends TextRange { >FileReference : FileReference @@ -2430,14 +2468,14 @@ declare module "typescript" { >SourceFile : SourceFile /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then - * the javascript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the javascript and declaration for that + * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then + * the JavaScript and declaration files will be produced for all the files in this program. + * If targetSourceFile is specified, then only the JavaScript and declaration for that * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the javascript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; >emit : (targetSourceFile?: SourceFile, writeFile?: WriteFileCallback) => EmitResult @@ -2960,6 +2998,11 @@ declare module "typescript" { CannotBeNamed = 2, >CannotBeNamed : SymbolAccessibility } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration +>ImportDeclaration : ImportDeclaration +>ImportEqualsDeclaration : ImportEqualsDeclaration + interface SymbolVisibilityResult { >SymbolVisibilityResult : SymbolVisibilityResult @@ -2967,9 +3010,9 @@ declare module "typescript" { >accessibility : SymbolAccessibility >SymbolAccessibility : SymbolAccessibility - aliasesToMakeVisible?: ImportEqualsDeclaration[]; ->aliasesToMakeVisible : ImportEqualsDeclaration[] ->ImportEqualsDeclaration : ImportEqualsDeclaration + aliasesToMakeVisible?: AnyImportSyntax[]; +>aliasesToMakeVisible : (ImportEqualsDeclaration | ImportDeclaration)[] +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration errorSymbolName?: string; >errorSymbolName : string @@ -2988,25 +3031,28 @@ declare module "typescript" { interface EmitResolver { >EmitResolver : EmitResolver - getGeneratedNameForNode(node: Node): string; ->getGeneratedNameForNode : (node: Node) => string ->node : Node ->Node : Node + hasGlobalName(name: string): boolean; +>hasGlobalName : (name: string) => boolean +>name : string - getExpressionNameSubstitution(node: Identifier): string; ->getExpressionNameSubstitution : (node: Identifier) => string + getExpressionNameSubstitution(node: Identifier, getGeneratedNameForNode: (node: Node) => string): string; +>getExpressionNameSubstitution : (node: Identifier, getGeneratedNameForNode: (node: Node) => string) => string >node : Identifier >Identifier : Identifier +>getGeneratedNameForNode : (node: Node) => string +>node : Node +>Node : Node isValueAliasDeclaration(node: Node): boolean; >isValueAliasDeclaration : (node: Node) => boolean >node : Node >Node : Node - isReferencedAliasDeclaration(node: Node): boolean; ->isReferencedAliasDeclaration : (node: Node) => boolean + isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean; +>isReferencedAliasDeclaration : (node: Node, checkChildren?: boolean) => boolean >node : Node >Node : Node +>checkChildren : boolean isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; >isTopLevelValueImportEqualsWithEntityName : (node: ImportEqualsDeclaration) => boolean @@ -3024,6 +3070,12 @@ declare module "typescript" { >node : Declaration >Declaration : Declaration + collectLinkedAliases(node: Identifier): Node[]; +>collectLinkedAliases : (node: Identifier) => Node[] +>node : Identifier +>Identifier : Identifier +>Node : Node + isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; >isImplementationOfOverload : (node: FunctionLikeDeclaration) => boolean >node : FunctionLikeDeclaration @@ -3050,6 +3102,17 @@ declare module "typescript" { >flags : TypeFormatFlags >TypeFormatFlags : TypeFormatFlags >writer : SymbolWriter +>SymbolWriter : SymbolWriter + + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; +>writeTypeOfExpression : (expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) => void +>expr : Expression +>Expression : Expression +>enclosingDeclaration : Node +>Node : Node +>flags : TypeFormatFlags +>TypeFormatFlags : TypeFormatFlags +>writer : SymbolWriter >SymbolWriter : SymbolWriter isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; @@ -3077,8 +3140,8 @@ declare module "typescript" { >PropertyAccessExpression : PropertyAccessExpression >ElementAccessExpression : ElementAccessExpression - isUnknownIdentifier(location: Node, name: string): boolean; ->isUnknownIdentifier : (location: Node, name: string) => boolean + resolvesToSomeValue(location: Node, name: string): boolean; +>resolvesToSomeValue : (location: Node, name: string) => boolean >location : Node >Node : Node >name : string @@ -3400,6 +3463,9 @@ declare module "typescript" { BlockScopedBindingInLoop = 256, >BlockScopedBindingInLoop : NodeCheckFlags + + EmitDecorate = 512, +>EmitDecorate : NodeCheckFlags } interface NodeLinks { >NodeLinks : NodeLinks @@ -3759,38 +3825,6 @@ declare module "typescript" { >t : Type >Type : Type >Type : Type - } - interface TypeInferences { ->TypeInferences : TypeInferences - - primary: Type[]; ->primary : Type[] ->Type : Type - - secondary: Type[]; ->secondary : Type[] ->Type : Type - } - interface InferenceContext { ->InferenceContext : InferenceContext - - typeParameters: TypeParameter[]; ->typeParameters : TypeParameter[] ->TypeParameter : TypeParameter - - inferUnionTypes: boolean; ->inferUnionTypes : boolean - - inferences: TypeInferences[]; ->inferences : TypeInferences[] ->TypeInferences : TypeInferences - - inferredTypes: Type[]; ->inferredTypes : Type[] ->Type : Type - - failedTypeParameterIndex?: number; ->failedTypeParameterIndex : number } interface DiagnosticMessage { >DiagnosticMessage : DiagnosticMessage @@ -4736,10 +4770,15 @@ declare module "typescript" { let version: string; >version : string - function createCompilerHost(options: CompilerOptions): CompilerHost; ->createCompilerHost : (options: CompilerOptions) => CompilerHost + function findConfigFile(searchPath: string): string; +>findConfigFile : (searchPath: string) => string +>searchPath : string + + function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; +>createCompilerHost : (options: CompilerOptions, setParentNodes?: boolean) => CompilerHost >options : CompilerOptions >CompilerOptions : CompilerOptions +>setParentNodes : boolean >CompilerHost : CompilerHost function getPreEmitDiagnostics(program: Program): Diagnostic[]; @@ -5153,6 +5192,12 @@ declare module "typescript" { >position : number >ReferenceEntry : ReferenceEntry + findReferences(fileName: string, position: number): ReferencedSymbol[]; +>findReferences : (fileName: string, position: number) => ReferencedSymbol[] +>fileName : string +>position : number +>ReferencedSymbol : ReferencedSymbol + getNavigateToItems(searchValue: string, maxResultCount?: number): NavigateToItem[]; >getNavigateToItems : (searchValue: string, maxResultCount?: number) => NavigateToItem[] >searchValue : string @@ -5423,6 +5468,17 @@ declare module "typescript" { containerName: string; >containerName : string + } + interface ReferencedSymbol { +>ReferencedSymbol : ReferencedSymbol + + definition: DefinitionInfo; +>definition : DefinitionInfo +>DefinitionInfo : DefinitionInfo + + references: ReferenceEntry[]; +>references : ReferenceEntry[] +>ReferenceEntry : ReferenceEntry } enum SymbolDisplayPartKind { >SymbolDisplayPartKind : SymbolDisplayPartKind diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index 6c57165bdb431..b57acaf0e9c1b 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -142,192 +142,195 @@ declare module "typescript" { BarBarToken = 49, QuestionToken = 50, ColonToken = 51, - EqualsToken = 52, - PlusEqualsToken = 53, - MinusEqualsToken = 54, - AsteriskEqualsToken = 55, - SlashEqualsToken = 56, - PercentEqualsToken = 57, - LessThanLessThanEqualsToken = 58, - GreaterThanGreaterThanEqualsToken = 59, - GreaterThanGreaterThanGreaterThanEqualsToken = 60, - AmpersandEqualsToken = 61, - BarEqualsToken = 62, - CaretEqualsToken = 63, - Identifier = 64, - BreakKeyword = 65, - CaseKeyword = 66, - CatchKeyword = 67, - ClassKeyword = 68, - ConstKeyword = 69, - ContinueKeyword = 70, - DebuggerKeyword = 71, - DefaultKeyword = 72, - DeleteKeyword = 73, - DoKeyword = 74, - ElseKeyword = 75, - EnumKeyword = 76, - ExportKeyword = 77, - ExtendsKeyword = 78, - FalseKeyword = 79, - FinallyKeyword = 80, - ForKeyword = 81, - FunctionKeyword = 82, - IfKeyword = 83, - ImportKeyword = 84, - InKeyword = 85, - InstanceOfKeyword = 86, - NewKeyword = 87, - NullKeyword = 88, - ReturnKeyword = 89, - SuperKeyword = 90, - SwitchKeyword = 91, - ThisKeyword = 92, - ThrowKeyword = 93, - TrueKeyword = 94, - TryKeyword = 95, - TypeOfKeyword = 96, - VarKeyword = 97, - VoidKeyword = 98, - WhileKeyword = 99, - WithKeyword = 100, - AsKeyword = 101, - ImplementsKeyword = 102, - InterfaceKeyword = 103, - LetKeyword = 104, - PackageKeyword = 105, - PrivateKeyword = 106, - ProtectedKeyword = 107, - PublicKeyword = 108, - StaticKeyword = 109, - YieldKeyword = 110, - AnyKeyword = 111, - BooleanKeyword = 112, - ConstructorKeyword = 113, - DeclareKeyword = 114, - GetKeyword = 115, - ModuleKeyword = 116, - RequireKeyword = 117, - NumberKeyword = 118, - SetKeyword = 119, - StringKeyword = 120, - SymbolKeyword = 121, - TypeKeyword = 122, - FromKeyword = 123, - OfKeyword = 124, - QualifiedName = 125, - ComputedPropertyName = 126, - TypeParameter = 127, - Parameter = 128, - PropertySignature = 129, - PropertyDeclaration = 130, - MethodSignature = 131, - MethodDeclaration = 132, - Constructor = 133, - GetAccessor = 134, - SetAccessor = 135, - CallSignature = 136, - ConstructSignature = 137, - IndexSignature = 138, - TypeReference = 139, - FunctionType = 140, - ConstructorType = 141, - TypeQuery = 142, - TypeLiteral = 143, - ArrayType = 144, - TupleType = 145, - UnionType = 146, - ParenthesizedType = 147, - ObjectBindingPattern = 148, - ArrayBindingPattern = 149, - BindingElement = 150, - ArrayLiteralExpression = 151, - ObjectLiteralExpression = 152, - PropertyAccessExpression = 153, - ElementAccessExpression = 154, - CallExpression = 155, - NewExpression = 156, - TaggedTemplateExpression = 157, - TypeAssertionExpression = 158, - ParenthesizedExpression = 159, - FunctionExpression = 160, - ArrowFunction = 161, - DeleteExpression = 162, - TypeOfExpression = 163, - VoidExpression = 164, - PrefixUnaryExpression = 165, - PostfixUnaryExpression = 166, - BinaryExpression = 167, - ConditionalExpression = 168, - TemplateExpression = 169, - YieldExpression = 170, - SpreadElementExpression = 171, - OmittedExpression = 172, - TemplateSpan = 173, - Block = 174, - VariableStatement = 175, - EmptyStatement = 176, - ExpressionStatement = 177, - IfStatement = 178, - DoStatement = 179, - WhileStatement = 180, - ForStatement = 181, - ForInStatement = 182, - ForOfStatement = 183, - ContinueStatement = 184, - BreakStatement = 185, - ReturnStatement = 186, - WithStatement = 187, - SwitchStatement = 188, - LabeledStatement = 189, - ThrowStatement = 190, - TryStatement = 191, - DebuggerStatement = 192, - VariableDeclaration = 193, - VariableDeclarationList = 194, - FunctionDeclaration = 195, - ClassDeclaration = 196, - InterfaceDeclaration = 197, - TypeAliasDeclaration = 198, - EnumDeclaration = 199, - ModuleDeclaration = 200, - ModuleBlock = 201, - CaseBlock = 202, - ImportEqualsDeclaration = 203, - ImportDeclaration = 204, - ImportClause = 205, - NamespaceImport = 206, - NamedImports = 207, - ImportSpecifier = 208, - ExportAssignment = 209, - ExportDeclaration = 210, - NamedExports = 211, - ExportSpecifier = 212, - ExternalModuleReference = 213, - CaseClause = 214, - DefaultClause = 215, - HeritageClause = 216, - CatchClause = 217, - PropertyAssignment = 218, - ShorthandPropertyAssignment = 219, - EnumMember = 220, - SourceFile = 221, - SyntaxList = 222, - Count = 223, - FirstAssignment = 52, - LastAssignment = 63, - FirstReservedWord = 65, - LastReservedWord = 100, - FirstKeyword = 65, - LastKeyword = 124, - FirstFutureReservedWord = 102, - LastFutureReservedWord = 110, - FirstTypeNode = 139, - LastTypeNode = 147, + AtToken = 52, + EqualsToken = 53, + PlusEqualsToken = 54, + MinusEqualsToken = 55, + AsteriskEqualsToken = 56, + SlashEqualsToken = 57, + PercentEqualsToken = 58, + LessThanLessThanEqualsToken = 59, + GreaterThanGreaterThanEqualsToken = 60, + GreaterThanGreaterThanGreaterThanEqualsToken = 61, + AmpersandEqualsToken = 62, + BarEqualsToken = 63, + CaretEqualsToken = 64, + Identifier = 65, + BreakKeyword = 66, + CaseKeyword = 67, + CatchKeyword = 68, + ClassKeyword = 69, + ConstKeyword = 70, + ContinueKeyword = 71, + DebuggerKeyword = 72, + DefaultKeyword = 73, + DeleteKeyword = 74, + DoKeyword = 75, + ElseKeyword = 76, + EnumKeyword = 77, + ExportKeyword = 78, + ExtendsKeyword = 79, + FalseKeyword = 80, + FinallyKeyword = 81, + ForKeyword = 82, + FunctionKeyword = 83, + IfKeyword = 84, + ImportKeyword = 85, + InKeyword = 86, + InstanceOfKeyword = 87, + NewKeyword = 88, + NullKeyword = 89, + ReturnKeyword = 90, + SuperKeyword = 91, + SwitchKeyword = 92, + ThisKeyword = 93, + ThrowKeyword = 94, + TrueKeyword = 95, + TryKeyword = 96, + TypeOfKeyword = 97, + VarKeyword = 98, + VoidKeyword = 99, + WhileKeyword = 100, + WithKeyword = 101, + AsKeyword = 102, + ImplementsKeyword = 103, + InterfaceKeyword = 104, + LetKeyword = 105, + PackageKeyword = 106, + PrivateKeyword = 107, + ProtectedKeyword = 108, + PublicKeyword = 109, + StaticKeyword = 110, + YieldKeyword = 111, + AnyKeyword = 112, + BooleanKeyword = 113, + ConstructorKeyword = 114, + DeclareKeyword = 115, + GetKeyword = 116, + ModuleKeyword = 117, + RequireKeyword = 118, + NumberKeyword = 119, + SetKeyword = 120, + StringKeyword = 121, + SymbolKeyword = 122, + TypeKeyword = 123, + FromKeyword = 124, + OfKeyword = 125, + QualifiedName = 126, + ComputedPropertyName = 127, + TypeParameter = 128, + Parameter = 129, + Decorator = 130, + PropertySignature = 131, + PropertyDeclaration = 132, + MethodSignature = 133, + MethodDeclaration = 134, + Constructor = 135, + GetAccessor = 136, + SetAccessor = 137, + CallSignature = 138, + ConstructSignature = 139, + IndexSignature = 140, + TypeReference = 141, + FunctionType = 142, + ConstructorType = 143, + TypeQuery = 144, + TypeLiteral = 145, + ArrayType = 146, + TupleType = 147, + UnionType = 148, + ParenthesizedType = 149, + ObjectBindingPattern = 150, + ArrayBindingPattern = 151, + BindingElement = 152, + ArrayLiteralExpression = 153, + ObjectLiteralExpression = 154, + PropertyAccessExpression = 155, + ElementAccessExpression = 156, + CallExpression = 157, + NewExpression = 158, + TaggedTemplateExpression = 159, + TypeAssertionExpression = 160, + ParenthesizedExpression = 161, + FunctionExpression = 162, + ArrowFunction = 163, + DeleteExpression = 164, + TypeOfExpression = 165, + VoidExpression = 166, + PrefixUnaryExpression = 167, + PostfixUnaryExpression = 168, + BinaryExpression = 169, + ConditionalExpression = 170, + TemplateExpression = 171, + YieldExpression = 172, + SpreadElementExpression = 173, + OmittedExpression = 174, + TemplateSpan = 175, + Block = 176, + VariableStatement = 177, + EmptyStatement = 178, + ExpressionStatement = 179, + IfStatement = 180, + DoStatement = 181, + WhileStatement = 182, + ForStatement = 183, + ForInStatement = 184, + ForOfStatement = 185, + ContinueStatement = 186, + BreakStatement = 187, + ReturnStatement = 188, + WithStatement = 189, + SwitchStatement = 190, + LabeledStatement = 191, + ThrowStatement = 192, + TryStatement = 193, + DebuggerStatement = 194, + VariableDeclaration = 195, + VariableDeclarationList = 196, + FunctionDeclaration = 197, + ClassDeclaration = 198, + InterfaceDeclaration = 199, + TypeAliasDeclaration = 200, + EnumDeclaration = 201, + ModuleDeclaration = 202, + ModuleBlock = 203, + CaseBlock = 204, + ImportEqualsDeclaration = 205, + ImportDeclaration = 206, + ImportClause = 207, + NamespaceImport = 208, + NamedImports = 209, + ImportSpecifier = 210, + ExportAssignment = 211, + ExportDeclaration = 212, + NamedExports = 213, + ExportSpecifier = 214, + MissingDeclaration = 215, + ExternalModuleReference = 216, + CaseClause = 217, + DefaultClause = 218, + HeritageClause = 219, + CatchClause = 220, + PropertyAssignment = 221, + ShorthandPropertyAssignment = 222, + EnumMember = 223, + SourceFile = 224, + SyntaxList = 225, + Count = 226, + FirstAssignment = 53, + LastAssignment = 64, + FirstReservedWord = 66, + LastReservedWord = 101, + FirstKeyword = 66, + LastKeyword = 125, + FirstFutureReservedWord = 103, + LastFutureReservedWord = 111, + FirstTypeNode = 141, + LastTypeNode = 149, FirstPunctuation = 14, - LastPunctuation = 63, + LastPunctuation = 64, FirstToken = 0, - LastToken = 124, + LastToken = 125, FirstTriviaToken = 2, LastTriviaToken = 6, FirstLiteralToken = 7, @@ -335,8 +338,8 @@ declare module "typescript" { FirstTemplateToken = 10, LastTemplateToken = 13, FirstBinaryOperator = 24, - LastBinaryOperator = 63, - FirstNode = 125, + LastBinaryOperator = 64, + FirstNode = 126, } const enum NodeFlags { Export = 1, @@ -362,10 +365,11 @@ declare module "typescript" { DisallowIn = 2, Yield = 4, GeneratorParameter = 8, - ThisNodeHasError = 16, - ParserGeneratedFlags = 31, - ThisNodeOrAnySubNodesHasError = 32, - HasAggregatedChildData = 64, + Decorator = 16, + ThisNodeHasError = 32, + ParserGeneratedFlags = 63, + ThisNodeOrAnySubNodesHasError = 64, + HasAggregatedChildData = 128, } const enum RelationComparisonResult { Succeeded = 1, @@ -376,6 +380,7 @@ declare module "typescript" { kind: SyntaxKind; flags: NodeFlags; parserContextFlags?: ParserContextFlags; + decorators?: NodeArray; modifiers?: ModifiersArray; id?: number; parent?: Node; @@ -406,6 +411,9 @@ declare module "typescript" { interface ComputedPropertyName extends Node { expression: Expression; } + interface Decorator extends Node { + expression: LeftHandSideExpression; + } interface TypeParameterDeclaration extends Declaration { name: Identifier; constraint?: TypeNode; @@ -585,6 +593,9 @@ declare module "typescript" { name?: Identifier; body: Block | Expression; } + interface ArrowFunction extends Expression, FunctionLikeDeclaration { + equalsGreaterThanToken: Node; + } interface LiteralExpression extends PrimaryExpression { text: string; isUnterminated?: boolean; @@ -794,7 +805,8 @@ declare module "typescript" { type ExportSpecifier = ImportOrExportSpecifier; interface ExportAssignment extends Declaration, ModuleElement { isExportEquals?: boolean; - expression: Expression; + expression?: Expression; + type?: TypeNode; } interface FileReference extends TextRange { fileName: string; @@ -829,14 +841,14 @@ declare module "typescript" { interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then - * the javascript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the javascript and declaration for that + * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then + * the JavaScript and declaration files will be produced for all the files in this program. + * If targetSourceFile is specified, then only the JavaScript and declaration for that * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the javascript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; @@ -955,9 +967,10 @@ declare module "typescript" { NotAccessible = 1, CannotBeNamed = 2, } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; interface SymbolVisibilityResult { accessibility: SymbolAccessibility; - aliasesToMakeVisible?: ImportEqualsDeclaration[]; + aliasesToMakeVisible?: AnyImportSyntax[]; errorSymbolName?: string; errorNode?: Node; } @@ -965,20 +978,22 @@ declare module "typescript" { errorModuleName?: string; } interface EmitResolver { - getGeneratedNameForNode(node: Node): string; - getExpressionNameSubstitution(node: Identifier): string; + hasGlobalName(name: string): boolean; + getExpressionNameSubstitution(node: Identifier, getGeneratedNameForNode: (node: Node) => string): string; isValueAliasDeclaration(node: Node): boolean; - isReferencedAliasDeclaration(node: Node): boolean; + isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; + collectLinkedAliases(node: Identifier): Node[]; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; - isUnknownIdentifier(location: Node, name: string): boolean; + resolvesToSomeValue(location: Node, name: string): boolean; getBlockScopedVariableId(node: Identifier): number; } const enum SymbolFlags { @@ -1085,6 +1100,7 @@ declare module "typescript" { ContextChecked = 64, EnumValuesComputed = 128, BlockScopedBindingInLoop = 256, + EmitDecorate = 512, } interface NodeLinks { resolvedType?: Type; @@ -1204,17 +1220,6 @@ declare module "typescript" { interface TypeMapper { (t: Type): Type; } - interface TypeInferences { - primary: Type[]; - secondary: Type[]; - } - interface InferenceContext { - typeParameters: TypeParameter[]; - inferUnionTypes: boolean; - inferences: TypeInferences[]; - inferredTypes: Type[]; - failedTypeParameterIndex?: number; - } interface DiagnosticMessage { key: string; category: DiagnosticCategory; @@ -1511,7 +1516,8 @@ declare module "typescript" { declare module "typescript" { /** The version of the TypeScript compiler release */ let version: string; - function createCompilerHost(options: CompilerOptions): CompilerHost; + function findConfigFile(searchPath: string): string; + function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; function getPreEmitDiagnostics(program: Program): Diagnostic[]; function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; @@ -1625,6 +1631,7 @@ declare module "typescript" { getDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[]; getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[]; getOccurrencesAtPosition(fileName: string, position: number): ReferenceEntry[]; + findReferences(fileName: string, position: number): ReferencedSymbol[]; getNavigateToItems(searchValue: string, maxResultCount?: number): NavigateToItem[]; getNavigationBarItems(fileName: string): NavigationBarItem[]; getOutliningSpans(fileName: string): OutliningSpan[]; @@ -1711,6 +1718,10 @@ declare module "typescript" { containerKind: string; containerName: string; } + interface ReferencedSymbol { + definition: DefinitionInfo; + references: ReferenceEntry[]; + } enum SymbolDisplayPartKind { aliasName = 0, className = 1, @@ -2031,24 +2042,24 @@ function delint(sourceFile) { delintNode(sourceFile); function delintNode(node) { switch (node.kind) { - case 181 /* ForStatement */: - case 182 /* ForInStatement */: - case 180 /* WhileStatement */: - case 179 /* DoStatement */: - if (node.statement.kind !== 174 /* Block */) { + case 183 /* ForStatement */: + case 184 /* ForInStatement */: + case 182 /* WhileStatement */: + case 181 /* DoStatement */: + if (node.statement.kind !== 176 /* Block */) { report(node, "A looping statement's contents should be wrapped in a block body."); } break; - case 178 /* IfStatement */: + case 180 /* IfStatement */: var ifStatement = node; - if (ifStatement.thenStatement.kind !== 174 /* Block */) { + if (ifStatement.thenStatement.kind !== 176 /* Block */) { report(ifStatement.thenStatement, "An if statement's contents should be wrapped in a block body."); } - if (ifStatement.elseStatement && ifStatement.elseStatement.kind !== 174 /* Block */ && ifStatement.elseStatement.kind !== 178 /* IfStatement */) { + if (ifStatement.elseStatement && ifStatement.elseStatement.kind !== 176 /* Block */ && ifStatement.elseStatement.kind !== 180 /* IfStatement */) { report(ifStatement.elseStatement, "An else statement's contents should be wrapped in a block body."); } break; - case 167 /* BinaryExpression */: + case 169 /* BinaryExpression */: var op = node.operatorToken.kind; if (op === 28 /* EqualsEqualsToken */ || op === 29 /* ExclamationEqualsToken */) { report(node, "Use '===' and '!=='."); diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index f6ed3b80eafe9..600bf5c6adc72 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -497,562 +497,571 @@ declare module "typescript" { ColonToken = 51, >ColonToken : SyntaxKind - EqualsToken = 52, + AtToken = 52, +>AtToken : SyntaxKind + + EqualsToken = 53, >EqualsToken : SyntaxKind - PlusEqualsToken = 53, + PlusEqualsToken = 54, >PlusEqualsToken : SyntaxKind - MinusEqualsToken = 54, + MinusEqualsToken = 55, >MinusEqualsToken : SyntaxKind - AsteriskEqualsToken = 55, + AsteriskEqualsToken = 56, >AsteriskEqualsToken : SyntaxKind - SlashEqualsToken = 56, + SlashEqualsToken = 57, >SlashEqualsToken : SyntaxKind - PercentEqualsToken = 57, + PercentEqualsToken = 58, >PercentEqualsToken : SyntaxKind - LessThanLessThanEqualsToken = 58, + LessThanLessThanEqualsToken = 59, >LessThanLessThanEqualsToken : SyntaxKind - GreaterThanGreaterThanEqualsToken = 59, + GreaterThanGreaterThanEqualsToken = 60, >GreaterThanGreaterThanEqualsToken : SyntaxKind - GreaterThanGreaterThanGreaterThanEqualsToken = 60, + GreaterThanGreaterThanGreaterThanEqualsToken = 61, >GreaterThanGreaterThanGreaterThanEqualsToken : SyntaxKind - AmpersandEqualsToken = 61, + AmpersandEqualsToken = 62, >AmpersandEqualsToken : SyntaxKind - BarEqualsToken = 62, + BarEqualsToken = 63, >BarEqualsToken : SyntaxKind - CaretEqualsToken = 63, + CaretEqualsToken = 64, >CaretEqualsToken : SyntaxKind - Identifier = 64, + Identifier = 65, >Identifier : SyntaxKind - BreakKeyword = 65, + BreakKeyword = 66, >BreakKeyword : SyntaxKind - CaseKeyword = 66, + CaseKeyword = 67, >CaseKeyword : SyntaxKind - CatchKeyword = 67, + CatchKeyword = 68, >CatchKeyword : SyntaxKind - ClassKeyword = 68, + ClassKeyword = 69, >ClassKeyword : SyntaxKind - ConstKeyword = 69, + ConstKeyword = 70, >ConstKeyword : SyntaxKind - ContinueKeyword = 70, + ContinueKeyword = 71, >ContinueKeyword : SyntaxKind - DebuggerKeyword = 71, + DebuggerKeyword = 72, >DebuggerKeyword : SyntaxKind - DefaultKeyword = 72, + DefaultKeyword = 73, >DefaultKeyword : SyntaxKind - DeleteKeyword = 73, + DeleteKeyword = 74, >DeleteKeyword : SyntaxKind - DoKeyword = 74, + DoKeyword = 75, >DoKeyword : SyntaxKind - ElseKeyword = 75, + ElseKeyword = 76, >ElseKeyword : SyntaxKind - EnumKeyword = 76, + EnumKeyword = 77, >EnumKeyword : SyntaxKind - ExportKeyword = 77, + ExportKeyword = 78, >ExportKeyword : SyntaxKind - ExtendsKeyword = 78, + ExtendsKeyword = 79, >ExtendsKeyword : SyntaxKind - FalseKeyword = 79, + FalseKeyword = 80, >FalseKeyword : SyntaxKind - FinallyKeyword = 80, + FinallyKeyword = 81, >FinallyKeyword : SyntaxKind - ForKeyword = 81, + ForKeyword = 82, >ForKeyword : SyntaxKind - FunctionKeyword = 82, + FunctionKeyword = 83, >FunctionKeyword : SyntaxKind - IfKeyword = 83, + IfKeyword = 84, >IfKeyword : SyntaxKind - ImportKeyword = 84, + ImportKeyword = 85, >ImportKeyword : SyntaxKind - InKeyword = 85, + InKeyword = 86, >InKeyword : SyntaxKind - InstanceOfKeyword = 86, + InstanceOfKeyword = 87, >InstanceOfKeyword : SyntaxKind - NewKeyword = 87, + NewKeyword = 88, >NewKeyword : SyntaxKind - NullKeyword = 88, + NullKeyword = 89, >NullKeyword : SyntaxKind - ReturnKeyword = 89, + ReturnKeyword = 90, >ReturnKeyword : SyntaxKind - SuperKeyword = 90, + SuperKeyword = 91, >SuperKeyword : SyntaxKind - SwitchKeyword = 91, + SwitchKeyword = 92, >SwitchKeyword : SyntaxKind - ThisKeyword = 92, + ThisKeyword = 93, >ThisKeyword : SyntaxKind - ThrowKeyword = 93, + ThrowKeyword = 94, >ThrowKeyword : SyntaxKind - TrueKeyword = 94, + TrueKeyword = 95, >TrueKeyword : SyntaxKind - TryKeyword = 95, + TryKeyword = 96, >TryKeyword : SyntaxKind - TypeOfKeyword = 96, + TypeOfKeyword = 97, >TypeOfKeyword : SyntaxKind - VarKeyword = 97, + VarKeyword = 98, >VarKeyword : SyntaxKind - VoidKeyword = 98, + VoidKeyword = 99, >VoidKeyword : SyntaxKind - WhileKeyword = 99, + WhileKeyword = 100, >WhileKeyword : SyntaxKind - WithKeyword = 100, + WithKeyword = 101, >WithKeyword : SyntaxKind - AsKeyword = 101, + AsKeyword = 102, >AsKeyword : SyntaxKind - ImplementsKeyword = 102, + ImplementsKeyword = 103, >ImplementsKeyword : SyntaxKind - InterfaceKeyword = 103, + InterfaceKeyword = 104, >InterfaceKeyword : SyntaxKind - LetKeyword = 104, + LetKeyword = 105, >LetKeyword : SyntaxKind - PackageKeyword = 105, + PackageKeyword = 106, >PackageKeyword : SyntaxKind - PrivateKeyword = 106, + PrivateKeyword = 107, >PrivateKeyword : SyntaxKind - ProtectedKeyword = 107, + ProtectedKeyword = 108, >ProtectedKeyword : SyntaxKind - PublicKeyword = 108, + PublicKeyword = 109, >PublicKeyword : SyntaxKind - StaticKeyword = 109, + StaticKeyword = 110, >StaticKeyword : SyntaxKind - YieldKeyword = 110, + YieldKeyword = 111, >YieldKeyword : SyntaxKind - AnyKeyword = 111, + AnyKeyword = 112, >AnyKeyword : SyntaxKind - BooleanKeyword = 112, + BooleanKeyword = 113, >BooleanKeyword : SyntaxKind - ConstructorKeyword = 113, + ConstructorKeyword = 114, >ConstructorKeyword : SyntaxKind - DeclareKeyword = 114, + DeclareKeyword = 115, >DeclareKeyword : SyntaxKind - GetKeyword = 115, + GetKeyword = 116, >GetKeyword : SyntaxKind - ModuleKeyword = 116, + ModuleKeyword = 117, >ModuleKeyword : SyntaxKind - RequireKeyword = 117, + RequireKeyword = 118, >RequireKeyword : SyntaxKind - NumberKeyword = 118, + NumberKeyword = 119, >NumberKeyword : SyntaxKind - SetKeyword = 119, + SetKeyword = 120, >SetKeyword : SyntaxKind - StringKeyword = 120, + StringKeyword = 121, >StringKeyword : SyntaxKind - SymbolKeyword = 121, + SymbolKeyword = 122, >SymbolKeyword : SyntaxKind - TypeKeyword = 122, + TypeKeyword = 123, >TypeKeyword : SyntaxKind - FromKeyword = 123, + FromKeyword = 124, >FromKeyword : SyntaxKind - OfKeyword = 124, + OfKeyword = 125, >OfKeyword : SyntaxKind - QualifiedName = 125, + QualifiedName = 126, >QualifiedName : SyntaxKind - ComputedPropertyName = 126, + ComputedPropertyName = 127, >ComputedPropertyName : SyntaxKind - TypeParameter = 127, + TypeParameter = 128, >TypeParameter : SyntaxKind - Parameter = 128, + Parameter = 129, >Parameter : SyntaxKind - PropertySignature = 129, + Decorator = 130, +>Decorator : SyntaxKind + + PropertySignature = 131, >PropertySignature : SyntaxKind - PropertyDeclaration = 130, + PropertyDeclaration = 132, >PropertyDeclaration : SyntaxKind - MethodSignature = 131, + MethodSignature = 133, >MethodSignature : SyntaxKind - MethodDeclaration = 132, + MethodDeclaration = 134, >MethodDeclaration : SyntaxKind - Constructor = 133, + Constructor = 135, >Constructor : SyntaxKind - GetAccessor = 134, + GetAccessor = 136, >GetAccessor : SyntaxKind - SetAccessor = 135, + SetAccessor = 137, >SetAccessor : SyntaxKind - CallSignature = 136, + CallSignature = 138, >CallSignature : SyntaxKind - ConstructSignature = 137, + ConstructSignature = 139, >ConstructSignature : SyntaxKind - IndexSignature = 138, + IndexSignature = 140, >IndexSignature : SyntaxKind - TypeReference = 139, + TypeReference = 141, >TypeReference : SyntaxKind - FunctionType = 140, + FunctionType = 142, >FunctionType : SyntaxKind - ConstructorType = 141, + ConstructorType = 143, >ConstructorType : SyntaxKind - TypeQuery = 142, + TypeQuery = 144, >TypeQuery : SyntaxKind - TypeLiteral = 143, + TypeLiteral = 145, >TypeLiteral : SyntaxKind - ArrayType = 144, + ArrayType = 146, >ArrayType : SyntaxKind - TupleType = 145, + TupleType = 147, >TupleType : SyntaxKind - UnionType = 146, + UnionType = 148, >UnionType : SyntaxKind - ParenthesizedType = 147, + ParenthesizedType = 149, >ParenthesizedType : SyntaxKind - ObjectBindingPattern = 148, + ObjectBindingPattern = 150, >ObjectBindingPattern : SyntaxKind - ArrayBindingPattern = 149, + ArrayBindingPattern = 151, >ArrayBindingPattern : SyntaxKind - BindingElement = 150, + BindingElement = 152, >BindingElement : SyntaxKind - ArrayLiteralExpression = 151, + ArrayLiteralExpression = 153, >ArrayLiteralExpression : SyntaxKind - ObjectLiteralExpression = 152, + ObjectLiteralExpression = 154, >ObjectLiteralExpression : SyntaxKind - PropertyAccessExpression = 153, + PropertyAccessExpression = 155, >PropertyAccessExpression : SyntaxKind - ElementAccessExpression = 154, + ElementAccessExpression = 156, >ElementAccessExpression : SyntaxKind - CallExpression = 155, + CallExpression = 157, >CallExpression : SyntaxKind - NewExpression = 156, + NewExpression = 158, >NewExpression : SyntaxKind - TaggedTemplateExpression = 157, + TaggedTemplateExpression = 159, >TaggedTemplateExpression : SyntaxKind - TypeAssertionExpression = 158, + TypeAssertionExpression = 160, >TypeAssertionExpression : SyntaxKind - ParenthesizedExpression = 159, + ParenthesizedExpression = 161, >ParenthesizedExpression : SyntaxKind - FunctionExpression = 160, + FunctionExpression = 162, >FunctionExpression : SyntaxKind - ArrowFunction = 161, + ArrowFunction = 163, >ArrowFunction : SyntaxKind - DeleteExpression = 162, + DeleteExpression = 164, >DeleteExpression : SyntaxKind - TypeOfExpression = 163, + TypeOfExpression = 165, >TypeOfExpression : SyntaxKind - VoidExpression = 164, + VoidExpression = 166, >VoidExpression : SyntaxKind - PrefixUnaryExpression = 165, + PrefixUnaryExpression = 167, >PrefixUnaryExpression : SyntaxKind - PostfixUnaryExpression = 166, + PostfixUnaryExpression = 168, >PostfixUnaryExpression : SyntaxKind - BinaryExpression = 167, + BinaryExpression = 169, >BinaryExpression : SyntaxKind - ConditionalExpression = 168, + ConditionalExpression = 170, >ConditionalExpression : SyntaxKind - TemplateExpression = 169, + TemplateExpression = 171, >TemplateExpression : SyntaxKind - YieldExpression = 170, + YieldExpression = 172, >YieldExpression : SyntaxKind - SpreadElementExpression = 171, + SpreadElementExpression = 173, >SpreadElementExpression : SyntaxKind - OmittedExpression = 172, + OmittedExpression = 174, >OmittedExpression : SyntaxKind - TemplateSpan = 173, + TemplateSpan = 175, >TemplateSpan : SyntaxKind - Block = 174, + Block = 176, >Block : SyntaxKind - VariableStatement = 175, + VariableStatement = 177, >VariableStatement : SyntaxKind - EmptyStatement = 176, + EmptyStatement = 178, >EmptyStatement : SyntaxKind - ExpressionStatement = 177, + ExpressionStatement = 179, >ExpressionStatement : SyntaxKind - IfStatement = 178, + IfStatement = 180, >IfStatement : SyntaxKind - DoStatement = 179, + DoStatement = 181, >DoStatement : SyntaxKind - WhileStatement = 180, + WhileStatement = 182, >WhileStatement : SyntaxKind - ForStatement = 181, + ForStatement = 183, >ForStatement : SyntaxKind - ForInStatement = 182, + ForInStatement = 184, >ForInStatement : SyntaxKind - ForOfStatement = 183, + ForOfStatement = 185, >ForOfStatement : SyntaxKind - ContinueStatement = 184, + ContinueStatement = 186, >ContinueStatement : SyntaxKind - BreakStatement = 185, + BreakStatement = 187, >BreakStatement : SyntaxKind - ReturnStatement = 186, + ReturnStatement = 188, >ReturnStatement : SyntaxKind - WithStatement = 187, + WithStatement = 189, >WithStatement : SyntaxKind - SwitchStatement = 188, + SwitchStatement = 190, >SwitchStatement : SyntaxKind - LabeledStatement = 189, + LabeledStatement = 191, >LabeledStatement : SyntaxKind - ThrowStatement = 190, + ThrowStatement = 192, >ThrowStatement : SyntaxKind - TryStatement = 191, + TryStatement = 193, >TryStatement : SyntaxKind - DebuggerStatement = 192, + DebuggerStatement = 194, >DebuggerStatement : SyntaxKind - VariableDeclaration = 193, + VariableDeclaration = 195, >VariableDeclaration : SyntaxKind - VariableDeclarationList = 194, + VariableDeclarationList = 196, >VariableDeclarationList : SyntaxKind - FunctionDeclaration = 195, + FunctionDeclaration = 197, >FunctionDeclaration : SyntaxKind - ClassDeclaration = 196, + ClassDeclaration = 198, >ClassDeclaration : SyntaxKind - InterfaceDeclaration = 197, + InterfaceDeclaration = 199, >InterfaceDeclaration : SyntaxKind - TypeAliasDeclaration = 198, + TypeAliasDeclaration = 200, >TypeAliasDeclaration : SyntaxKind - EnumDeclaration = 199, + EnumDeclaration = 201, >EnumDeclaration : SyntaxKind - ModuleDeclaration = 200, + ModuleDeclaration = 202, >ModuleDeclaration : SyntaxKind - ModuleBlock = 201, + ModuleBlock = 203, >ModuleBlock : SyntaxKind - CaseBlock = 202, + CaseBlock = 204, >CaseBlock : SyntaxKind - ImportEqualsDeclaration = 203, + ImportEqualsDeclaration = 205, >ImportEqualsDeclaration : SyntaxKind - ImportDeclaration = 204, + ImportDeclaration = 206, >ImportDeclaration : SyntaxKind - ImportClause = 205, + ImportClause = 207, >ImportClause : SyntaxKind - NamespaceImport = 206, + NamespaceImport = 208, >NamespaceImport : SyntaxKind - NamedImports = 207, + NamedImports = 209, >NamedImports : SyntaxKind - ImportSpecifier = 208, + ImportSpecifier = 210, >ImportSpecifier : SyntaxKind - ExportAssignment = 209, + ExportAssignment = 211, >ExportAssignment : SyntaxKind - ExportDeclaration = 210, + ExportDeclaration = 212, >ExportDeclaration : SyntaxKind - NamedExports = 211, + NamedExports = 213, >NamedExports : SyntaxKind - ExportSpecifier = 212, + ExportSpecifier = 214, >ExportSpecifier : SyntaxKind - ExternalModuleReference = 213, + MissingDeclaration = 215, +>MissingDeclaration : SyntaxKind + + ExternalModuleReference = 216, >ExternalModuleReference : SyntaxKind - CaseClause = 214, + CaseClause = 217, >CaseClause : SyntaxKind - DefaultClause = 215, + DefaultClause = 218, >DefaultClause : SyntaxKind - HeritageClause = 216, + HeritageClause = 219, >HeritageClause : SyntaxKind - CatchClause = 217, + CatchClause = 220, >CatchClause : SyntaxKind - PropertyAssignment = 218, + PropertyAssignment = 221, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 219, + ShorthandPropertyAssignment = 222, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 220, + EnumMember = 223, >EnumMember : SyntaxKind - SourceFile = 221, + SourceFile = 224, >SourceFile : SyntaxKind - SyntaxList = 222, + SyntaxList = 225, >SyntaxList : SyntaxKind - Count = 223, + Count = 226, >Count : SyntaxKind - FirstAssignment = 52, + FirstAssignment = 53, >FirstAssignment : SyntaxKind - LastAssignment = 63, + LastAssignment = 64, >LastAssignment : SyntaxKind - FirstReservedWord = 65, + FirstReservedWord = 66, >FirstReservedWord : SyntaxKind - LastReservedWord = 100, + LastReservedWord = 101, >LastReservedWord : SyntaxKind - FirstKeyword = 65, + FirstKeyword = 66, >FirstKeyword : SyntaxKind - LastKeyword = 124, + LastKeyword = 125, >LastKeyword : SyntaxKind - FirstFutureReservedWord = 102, + FirstFutureReservedWord = 103, >FirstFutureReservedWord : SyntaxKind - LastFutureReservedWord = 110, + LastFutureReservedWord = 111, >LastFutureReservedWord : SyntaxKind - FirstTypeNode = 139, + FirstTypeNode = 141, >FirstTypeNode : SyntaxKind - LastTypeNode = 147, + LastTypeNode = 149, >LastTypeNode : SyntaxKind FirstPunctuation = 14, >FirstPunctuation : SyntaxKind - LastPunctuation = 63, + LastPunctuation = 64, >LastPunctuation : SyntaxKind FirstToken = 0, >FirstToken : SyntaxKind - LastToken = 124, + LastToken = 125, >LastToken : SyntaxKind FirstTriviaToken = 2, @@ -1076,10 +1085,10 @@ declare module "typescript" { FirstBinaryOperator = 24, >FirstBinaryOperator : SyntaxKind - LastBinaryOperator = 63, + LastBinaryOperator = 64, >LastBinaryOperator : SyntaxKind - FirstNode = 125, + FirstNode = 126, >FirstNode : SyntaxKind } const enum NodeFlags { @@ -1151,16 +1160,19 @@ declare module "typescript" { GeneratorParameter = 8, >GeneratorParameter : ParserContextFlags - ThisNodeHasError = 16, + Decorator = 16, +>Decorator : ParserContextFlags + + ThisNodeHasError = 32, >ThisNodeHasError : ParserContextFlags - ParserGeneratedFlags = 31, + ParserGeneratedFlags = 63, >ParserGeneratedFlags : ParserContextFlags - ThisNodeOrAnySubNodesHasError = 32, + ThisNodeOrAnySubNodesHasError = 64, >ThisNodeOrAnySubNodesHasError : ParserContextFlags - HasAggregatedChildData = 64, + HasAggregatedChildData = 128, >HasAggregatedChildData : ParserContextFlags } const enum RelationComparisonResult { @@ -1191,6 +1203,11 @@ declare module "typescript" { >parserContextFlags : ParserContextFlags >ParserContextFlags : ParserContextFlags + decorators?: NodeArray; +>decorators : NodeArray +>NodeArray : NodeArray +>Decorator : Decorator + modifiers?: ModifiersArray; >modifiers : ModifiersArray >ModifiersArray : ModifiersArray @@ -1285,6 +1302,14 @@ declare module "typescript" { expression: Expression; >expression : Expression >Expression : Expression + } + interface Decorator extends Node { +>Decorator : Decorator +>Node : Node + + expression: LeftHandSideExpression; +>expression : LeftHandSideExpression +>LeftHandSideExpression : LeftHandSideExpression } interface TypeParameterDeclaration extends Declaration { >TypeParameterDeclaration : TypeParameterDeclaration @@ -1817,6 +1842,15 @@ declare module "typescript" { >body : Expression | Block >Block : Block >Expression : Expression + } + interface ArrowFunction extends Expression, FunctionLikeDeclaration { +>ArrowFunction : ArrowFunction +>Expression : Expression +>FunctionLikeDeclaration : FunctionLikeDeclaration + + equalsGreaterThanToken: Node; +>equalsGreaterThanToken : Node +>Node : Node } interface LiteralExpression extends PrimaryExpression { >LiteralExpression : LiteralExpression @@ -2473,9 +2507,13 @@ declare module "typescript" { isExportEquals?: boolean; >isExportEquals : boolean - expression: Expression; + expression?: Expression; >expression : Expression >Expression : Expression + + type?: TypeNode; +>type : TypeNode +>TypeNode : TypeNode } interface FileReference extends TextRange { >FileReference : FileReference @@ -2576,14 +2614,14 @@ declare module "typescript" { >SourceFile : SourceFile /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then - * the javascript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the javascript and declaration for that + * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then + * the JavaScript and declaration files will be produced for all the files in this program. + * If targetSourceFile is specified, then only the JavaScript and declaration for that * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the javascript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; >emit : (targetSourceFile?: SourceFile, writeFile?: WriteFileCallback) => EmitResult @@ -3106,6 +3144,11 @@ declare module "typescript" { CannotBeNamed = 2, >CannotBeNamed : SymbolAccessibility } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration +>ImportDeclaration : ImportDeclaration +>ImportEqualsDeclaration : ImportEqualsDeclaration + interface SymbolVisibilityResult { >SymbolVisibilityResult : SymbolVisibilityResult @@ -3113,9 +3156,9 @@ declare module "typescript" { >accessibility : SymbolAccessibility >SymbolAccessibility : SymbolAccessibility - aliasesToMakeVisible?: ImportEqualsDeclaration[]; ->aliasesToMakeVisible : ImportEqualsDeclaration[] ->ImportEqualsDeclaration : ImportEqualsDeclaration + aliasesToMakeVisible?: AnyImportSyntax[]; +>aliasesToMakeVisible : (ImportEqualsDeclaration | ImportDeclaration)[] +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration errorSymbolName?: string; >errorSymbolName : string @@ -3134,25 +3177,28 @@ declare module "typescript" { interface EmitResolver { >EmitResolver : EmitResolver - getGeneratedNameForNode(node: Node): string; ->getGeneratedNameForNode : (node: Node) => string ->node : Node ->Node : Node + hasGlobalName(name: string): boolean; +>hasGlobalName : (name: string) => boolean +>name : string - getExpressionNameSubstitution(node: Identifier): string; ->getExpressionNameSubstitution : (node: Identifier) => string + getExpressionNameSubstitution(node: Identifier, getGeneratedNameForNode: (node: Node) => string): string; +>getExpressionNameSubstitution : (node: Identifier, getGeneratedNameForNode: (node: Node) => string) => string >node : Identifier >Identifier : Identifier +>getGeneratedNameForNode : (node: Node) => string +>node : Node +>Node : Node isValueAliasDeclaration(node: Node): boolean; >isValueAliasDeclaration : (node: Node) => boolean >node : Node >Node : Node - isReferencedAliasDeclaration(node: Node): boolean; ->isReferencedAliasDeclaration : (node: Node) => boolean + isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean; +>isReferencedAliasDeclaration : (node: Node, checkChildren?: boolean) => boolean >node : Node >Node : Node +>checkChildren : boolean isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; >isTopLevelValueImportEqualsWithEntityName : (node: ImportEqualsDeclaration) => boolean @@ -3170,6 +3216,12 @@ declare module "typescript" { >node : Declaration >Declaration : Declaration + collectLinkedAliases(node: Identifier): Node[]; +>collectLinkedAliases : (node: Identifier) => Node[] +>node : Identifier +>Identifier : Identifier +>Node : Node + isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; >isImplementationOfOverload : (node: FunctionLikeDeclaration) => boolean >node : FunctionLikeDeclaration @@ -3196,6 +3248,17 @@ declare module "typescript" { >flags : TypeFormatFlags >TypeFormatFlags : TypeFormatFlags >writer : SymbolWriter +>SymbolWriter : SymbolWriter + + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; +>writeTypeOfExpression : (expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) => void +>expr : Expression +>Expression : Expression +>enclosingDeclaration : Node +>Node : Node +>flags : TypeFormatFlags +>TypeFormatFlags : TypeFormatFlags +>writer : SymbolWriter >SymbolWriter : SymbolWriter isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; @@ -3223,8 +3286,8 @@ declare module "typescript" { >PropertyAccessExpression : PropertyAccessExpression >ElementAccessExpression : ElementAccessExpression - isUnknownIdentifier(location: Node, name: string): boolean; ->isUnknownIdentifier : (location: Node, name: string) => boolean + resolvesToSomeValue(location: Node, name: string): boolean; +>resolvesToSomeValue : (location: Node, name: string) => boolean >location : Node >Node : Node >name : string @@ -3546,6 +3609,9 @@ declare module "typescript" { BlockScopedBindingInLoop = 256, >BlockScopedBindingInLoop : NodeCheckFlags + + EmitDecorate = 512, +>EmitDecorate : NodeCheckFlags } interface NodeLinks { >NodeLinks : NodeLinks @@ -3905,38 +3971,6 @@ declare module "typescript" { >t : Type >Type : Type >Type : Type - } - interface TypeInferences { ->TypeInferences : TypeInferences - - primary: Type[]; ->primary : Type[] ->Type : Type - - secondary: Type[]; ->secondary : Type[] ->Type : Type - } - interface InferenceContext { ->InferenceContext : InferenceContext - - typeParameters: TypeParameter[]; ->typeParameters : TypeParameter[] ->TypeParameter : TypeParameter - - inferUnionTypes: boolean; ->inferUnionTypes : boolean - - inferences: TypeInferences[]; ->inferences : TypeInferences[] ->TypeInferences : TypeInferences - - inferredTypes: Type[]; ->inferredTypes : Type[] ->Type : Type - - failedTypeParameterIndex?: number; ->failedTypeParameterIndex : number } interface DiagnosticMessage { >DiagnosticMessage : DiagnosticMessage @@ -4882,10 +4916,15 @@ declare module "typescript" { let version: string; >version : string - function createCompilerHost(options: CompilerOptions): CompilerHost; ->createCompilerHost : (options: CompilerOptions) => CompilerHost + function findConfigFile(searchPath: string): string; +>findConfigFile : (searchPath: string) => string +>searchPath : string + + function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; +>createCompilerHost : (options: CompilerOptions, setParentNodes?: boolean) => CompilerHost >options : CompilerOptions >CompilerOptions : CompilerOptions +>setParentNodes : boolean >CompilerHost : CompilerHost function getPreEmitDiagnostics(program: Program): Diagnostic[]; @@ -5299,6 +5338,12 @@ declare module "typescript" { >position : number >ReferenceEntry : ReferenceEntry + findReferences(fileName: string, position: number): ReferencedSymbol[]; +>findReferences : (fileName: string, position: number) => ReferencedSymbol[] +>fileName : string +>position : number +>ReferencedSymbol : ReferencedSymbol + getNavigateToItems(searchValue: string, maxResultCount?: number): NavigateToItem[]; >getNavigateToItems : (searchValue: string, maxResultCount?: number) => NavigateToItem[] >searchValue : string @@ -5569,6 +5614,17 @@ declare module "typescript" { containerName: string; >containerName : string + } + interface ReferencedSymbol { +>ReferencedSymbol : ReferencedSymbol + + definition: DefinitionInfo; +>definition : DefinitionInfo +>DefinitionInfo : DefinitionInfo + + references: ReferenceEntry[]; +>references : ReferenceEntry[] +>ReferenceEntry : ReferenceEntry } enum SymbolDisplayPartKind { >SymbolDisplayPartKind : SymbolDisplayPartKind diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index b18b0e385c019..4004007508ab0 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -143,192 +143,195 @@ declare module "typescript" { BarBarToken = 49, QuestionToken = 50, ColonToken = 51, - EqualsToken = 52, - PlusEqualsToken = 53, - MinusEqualsToken = 54, - AsteriskEqualsToken = 55, - SlashEqualsToken = 56, - PercentEqualsToken = 57, - LessThanLessThanEqualsToken = 58, - GreaterThanGreaterThanEqualsToken = 59, - GreaterThanGreaterThanGreaterThanEqualsToken = 60, - AmpersandEqualsToken = 61, - BarEqualsToken = 62, - CaretEqualsToken = 63, - Identifier = 64, - BreakKeyword = 65, - CaseKeyword = 66, - CatchKeyword = 67, - ClassKeyword = 68, - ConstKeyword = 69, - ContinueKeyword = 70, - DebuggerKeyword = 71, - DefaultKeyword = 72, - DeleteKeyword = 73, - DoKeyword = 74, - ElseKeyword = 75, - EnumKeyword = 76, - ExportKeyword = 77, - ExtendsKeyword = 78, - FalseKeyword = 79, - FinallyKeyword = 80, - ForKeyword = 81, - FunctionKeyword = 82, - IfKeyword = 83, - ImportKeyword = 84, - InKeyword = 85, - InstanceOfKeyword = 86, - NewKeyword = 87, - NullKeyword = 88, - ReturnKeyword = 89, - SuperKeyword = 90, - SwitchKeyword = 91, - ThisKeyword = 92, - ThrowKeyword = 93, - TrueKeyword = 94, - TryKeyword = 95, - TypeOfKeyword = 96, - VarKeyword = 97, - VoidKeyword = 98, - WhileKeyword = 99, - WithKeyword = 100, - AsKeyword = 101, - ImplementsKeyword = 102, - InterfaceKeyword = 103, - LetKeyword = 104, - PackageKeyword = 105, - PrivateKeyword = 106, - ProtectedKeyword = 107, - PublicKeyword = 108, - StaticKeyword = 109, - YieldKeyword = 110, - AnyKeyword = 111, - BooleanKeyword = 112, - ConstructorKeyword = 113, - DeclareKeyword = 114, - GetKeyword = 115, - ModuleKeyword = 116, - RequireKeyword = 117, - NumberKeyword = 118, - SetKeyword = 119, - StringKeyword = 120, - SymbolKeyword = 121, - TypeKeyword = 122, - FromKeyword = 123, - OfKeyword = 124, - QualifiedName = 125, - ComputedPropertyName = 126, - TypeParameter = 127, - Parameter = 128, - PropertySignature = 129, - PropertyDeclaration = 130, - MethodSignature = 131, - MethodDeclaration = 132, - Constructor = 133, - GetAccessor = 134, - SetAccessor = 135, - CallSignature = 136, - ConstructSignature = 137, - IndexSignature = 138, - TypeReference = 139, - FunctionType = 140, - ConstructorType = 141, - TypeQuery = 142, - TypeLiteral = 143, - ArrayType = 144, - TupleType = 145, - UnionType = 146, - ParenthesizedType = 147, - ObjectBindingPattern = 148, - ArrayBindingPattern = 149, - BindingElement = 150, - ArrayLiteralExpression = 151, - ObjectLiteralExpression = 152, - PropertyAccessExpression = 153, - ElementAccessExpression = 154, - CallExpression = 155, - NewExpression = 156, - TaggedTemplateExpression = 157, - TypeAssertionExpression = 158, - ParenthesizedExpression = 159, - FunctionExpression = 160, - ArrowFunction = 161, - DeleteExpression = 162, - TypeOfExpression = 163, - VoidExpression = 164, - PrefixUnaryExpression = 165, - PostfixUnaryExpression = 166, - BinaryExpression = 167, - ConditionalExpression = 168, - TemplateExpression = 169, - YieldExpression = 170, - SpreadElementExpression = 171, - OmittedExpression = 172, - TemplateSpan = 173, - Block = 174, - VariableStatement = 175, - EmptyStatement = 176, - ExpressionStatement = 177, - IfStatement = 178, - DoStatement = 179, - WhileStatement = 180, - ForStatement = 181, - ForInStatement = 182, - ForOfStatement = 183, - ContinueStatement = 184, - BreakStatement = 185, - ReturnStatement = 186, - WithStatement = 187, - SwitchStatement = 188, - LabeledStatement = 189, - ThrowStatement = 190, - TryStatement = 191, - DebuggerStatement = 192, - VariableDeclaration = 193, - VariableDeclarationList = 194, - FunctionDeclaration = 195, - ClassDeclaration = 196, - InterfaceDeclaration = 197, - TypeAliasDeclaration = 198, - EnumDeclaration = 199, - ModuleDeclaration = 200, - ModuleBlock = 201, - CaseBlock = 202, - ImportEqualsDeclaration = 203, - ImportDeclaration = 204, - ImportClause = 205, - NamespaceImport = 206, - NamedImports = 207, - ImportSpecifier = 208, - ExportAssignment = 209, - ExportDeclaration = 210, - NamedExports = 211, - ExportSpecifier = 212, - ExternalModuleReference = 213, - CaseClause = 214, - DefaultClause = 215, - HeritageClause = 216, - CatchClause = 217, - PropertyAssignment = 218, - ShorthandPropertyAssignment = 219, - EnumMember = 220, - SourceFile = 221, - SyntaxList = 222, - Count = 223, - FirstAssignment = 52, - LastAssignment = 63, - FirstReservedWord = 65, - LastReservedWord = 100, - FirstKeyword = 65, - LastKeyword = 124, - FirstFutureReservedWord = 102, - LastFutureReservedWord = 110, - FirstTypeNode = 139, - LastTypeNode = 147, + AtToken = 52, + EqualsToken = 53, + PlusEqualsToken = 54, + MinusEqualsToken = 55, + AsteriskEqualsToken = 56, + SlashEqualsToken = 57, + PercentEqualsToken = 58, + LessThanLessThanEqualsToken = 59, + GreaterThanGreaterThanEqualsToken = 60, + GreaterThanGreaterThanGreaterThanEqualsToken = 61, + AmpersandEqualsToken = 62, + BarEqualsToken = 63, + CaretEqualsToken = 64, + Identifier = 65, + BreakKeyword = 66, + CaseKeyword = 67, + CatchKeyword = 68, + ClassKeyword = 69, + ConstKeyword = 70, + ContinueKeyword = 71, + DebuggerKeyword = 72, + DefaultKeyword = 73, + DeleteKeyword = 74, + DoKeyword = 75, + ElseKeyword = 76, + EnumKeyword = 77, + ExportKeyword = 78, + ExtendsKeyword = 79, + FalseKeyword = 80, + FinallyKeyword = 81, + ForKeyword = 82, + FunctionKeyword = 83, + IfKeyword = 84, + ImportKeyword = 85, + InKeyword = 86, + InstanceOfKeyword = 87, + NewKeyword = 88, + NullKeyword = 89, + ReturnKeyword = 90, + SuperKeyword = 91, + SwitchKeyword = 92, + ThisKeyword = 93, + ThrowKeyword = 94, + TrueKeyword = 95, + TryKeyword = 96, + TypeOfKeyword = 97, + VarKeyword = 98, + VoidKeyword = 99, + WhileKeyword = 100, + WithKeyword = 101, + AsKeyword = 102, + ImplementsKeyword = 103, + InterfaceKeyword = 104, + LetKeyword = 105, + PackageKeyword = 106, + PrivateKeyword = 107, + ProtectedKeyword = 108, + PublicKeyword = 109, + StaticKeyword = 110, + YieldKeyword = 111, + AnyKeyword = 112, + BooleanKeyword = 113, + ConstructorKeyword = 114, + DeclareKeyword = 115, + GetKeyword = 116, + ModuleKeyword = 117, + RequireKeyword = 118, + NumberKeyword = 119, + SetKeyword = 120, + StringKeyword = 121, + SymbolKeyword = 122, + TypeKeyword = 123, + FromKeyword = 124, + OfKeyword = 125, + QualifiedName = 126, + ComputedPropertyName = 127, + TypeParameter = 128, + Parameter = 129, + Decorator = 130, + PropertySignature = 131, + PropertyDeclaration = 132, + MethodSignature = 133, + MethodDeclaration = 134, + Constructor = 135, + GetAccessor = 136, + SetAccessor = 137, + CallSignature = 138, + ConstructSignature = 139, + IndexSignature = 140, + TypeReference = 141, + FunctionType = 142, + ConstructorType = 143, + TypeQuery = 144, + TypeLiteral = 145, + ArrayType = 146, + TupleType = 147, + UnionType = 148, + ParenthesizedType = 149, + ObjectBindingPattern = 150, + ArrayBindingPattern = 151, + BindingElement = 152, + ArrayLiteralExpression = 153, + ObjectLiteralExpression = 154, + PropertyAccessExpression = 155, + ElementAccessExpression = 156, + CallExpression = 157, + NewExpression = 158, + TaggedTemplateExpression = 159, + TypeAssertionExpression = 160, + ParenthesizedExpression = 161, + FunctionExpression = 162, + ArrowFunction = 163, + DeleteExpression = 164, + TypeOfExpression = 165, + VoidExpression = 166, + PrefixUnaryExpression = 167, + PostfixUnaryExpression = 168, + BinaryExpression = 169, + ConditionalExpression = 170, + TemplateExpression = 171, + YieldExpression = 172, + SpreadElementExpression = 173, + OmittedExpression = 174, + TemplateSpan = 175, + Block = 176, + VariableStatement = 177, + EmptyStatement = 178, + ExpressionStatement = 179, + IfStatement = 180, + DoStatement = 181, + WhileStatement = 182, + ForStatement = 183, + ForInStatement = 184, + ForOfStatement = 185, + ContinueStatement = 186, + BreakStatement = 187, + ReturnStatement = 188, + WithStatement = 189, + SwitchStatement = 190, + LabeledStatement = 191, + ThrowStatement = 192, + TryStatement = 193, + DebuggerStatement = 194, + VariableDeclaration = 195, + VariableDeclarationList = 196, + FunctionDeclaration = 197, + ClassDeclaration = 198, + InterfaceDeclaration = 199, + TypeAliasDeclaration = 200, + EnumDeclaration = 201, + ModuleDeclaration = 202, + ModuleBlock = 203, + CaseBlock = 204, + ImportEqualsDeclaration = 205, + ImportDeclaration = 206, + ImportClause = 207, + NamespaceImport = 208, + NamedImports = 209, + ImportSpecifier = 210, + ExportAssignment = 211, + ExportDeclaration = 212, + NamedExports = 213, + ExportSpecifier = 214, + MissingDeclaration = 215, + ExternalModuleReference = 216, + CaseClause = 217, + DefaultClause = 218, + HeritageClause = 219, + CatchClause = 220, + PropertyAssignment = 221, + ShorthandPropertyAssignment = 222, + EnumMember = 223, + SourceFile = 224, + SyntaxList = 225, + Count = 226, + FirstAssignment = 53, + LastAssignment = 64, + FirstReservedWord = 66, + LastReservedWord = 101, + FirstKeyword = 66, + LastKeyword = 125, + FirstFutureReservedWord = 103, + LastFutureReservedWord = 111, + FirstTypeNode = 141, + LastTypeNode = 149, FirstPunctuation = 14, - LastPunctuation = 63, + LastPunctuation = 64, FirstToken = 0, - LastToken = 124, + LastToken = 125, FirstTriviaToken = 2, LastTriviaToken = 6, FirstLiteralToken = 7, @@ -336,8 +339,8 @@ declare module "typescript" { FirstTemplateToken = 10, LastTemplateToken = 13, FirstBinaryOperator = 24, - LastBinaryOperator = 63, - FirstNode = 125, + LastBinaryOperator = 64, + FirstNode = 126, } const enum NodeFlags { Export = 1, @@ -363,10 +366,11 @@ declare module "typescript" { DisallowIn = 2, Yield = 4, GeneratorParameter = 8, - ThisNodeHasError = 16, - ParserGeneratedFlags = 31, - ThisNodeOrAnySubNodesHasError = 32, - HasAggregatedChildData = 64, + Decorator = 16, + ThisNodeHasError = 32, + ParserGeneratedFlags = 63, + ThisNodeOrAnySubNodesHasError = 64, + HasAggregatedChildData = 128, } const enum RelationComparisonResult { Succeeded = 1, @@ -377,6 +381,7 @@ declare module "typescript" { kind: SyntaxKind; flags: NodeFlags; parserContextFlags?: ParserContextFlags; + decorators?: NodeArray; modifiers?: ModifiersArray; id?: number; parent?: Node; @@ -407,6 +412,9 @@ declare module "typescript" { interface ComputedPropertyName extends Node { expression: Expression; } + interface Decorator extends Node { + expression: LeftHandSideExpression; + } interface TypeParameterDeclaration extends Declaration { name: Identifier; constraint?: TypeNode; @@ -586,6 +594,9 @@ declare module "typescript" { name?: Identifier; body: Block | Expression; } + interface ArrowFunction extends Expression, FunctionLikeDeclaration { + equalsGreaterThanToken: Node; + } interface LiteralExpression extends PrimaryExpression { text: string; isUnterminated?: boolean; @@ -795,7 +806,8 @@ declare module "typescript" { type ExportSpecifier = ImportOrExportSpecifier; interface ExportAssignment extends Declaration, ModuleElement { isExportEquals?: boolean; - expression: Expression; + expression?: Expression; + type?: TypeNode; } interface FileReference extends TextRange { fileName: string; @@ -830,14 +842,14 @@ declare module "typescript" { interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then - * the javascript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the javascript and declaration for that + * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then + * the JavaScript and declaration files will be produced for all the files in this program. + * If targetSourceFile is specified, then only the JavaScript and declaration for that * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the javascript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; @@ -956,9 +968,10 @@ declare module "typescript" { NotAccessible = 1, CannotBeNamed = 2, } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; interface SymbolVisibilityResult { accessibility: SymbolAccessibility; - aliasesToMakeVisible?: ImportEqualsDeclaration[]; + aliasesToMakeVisible?: AnyImportSyntax[]; errorSymbolName?: string; errorNode?: Node; } @@ -966,20 +979,22 @@ declare module "typescript" { errorModuleName?: string; } interface EmitResolver { - getGeneratedNameForNode(node: Node): string; - getExpressionNameSubstitution(node: Identifier): string; + hasGlobalName(name: string): boolean; + getExpressionNameSubstitution(node: Identifier, getGeneratedNameForNode: (node: Node) => string): string; isValueAliasDeclaration(node: Node): boolean; - isReferencedAliasDeclaration(node: Node): boolean; + isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; + collectLinkedAliases(node: Identifier): Node[]; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; - isUnknownIdentifier(location: Node, name: string): boolean; + resolvesToSomeValue(location: Node, name: string): boolean; getBlockScopedVariableId(node: Identifier): number; } const enum SymbolFlags { @@ -1086,6 +1101,7 @@ declare module "typescript" { ContextChecked = 64, EnumValuesComputed = 128, BlockScopedBindingInLoop = 256, + EmitDecorate = 512, } interface NodeLinks { resolvedType?: Type; @@ -1205,17 +1221,6 @@ declare module "typescript" { interface TypeMapper { (t: Type): Type; } - interface TypeInferences { - primary: Type[]; - secondary: Type[]; - } - interface InferenceContext { - typeParameters: TypeParameter[]; - inferUnionTypes: boolean; - inferences: TypeInferences[]; - inferredTypes: Type[]; - failedTypeParameterIndex?: number; - } interface DiagnosticMessage { key: string; category: DiagnosticCategory; @@ -1512,7 +1517,8 @@ declare module "typescript" { declare module "typescript" { /** The version of the TypeScript compiler release */ let version: string; - function createCompilerHost(options: CompilerOptions): CompilerHost; + function findConfigFile(searchPath: string): string; + function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; function getPreEmitDiagnostics(program: Program): Diagnostic[]; function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; @@ -1626,6 +1632,7 @@ declare module "typescript" { getDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[]; getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[]; getOccurrencesAtPosition(fileName: string, position: number): ReferenceEntry[]; + findReferences(fileName: string, position: number): ReferencedSymbol[]; getNavigateToItems(searchValue: string, maxResultCount?: number): NavigateToItem[]; getNavigationBarItems(fileName: string): NavigationBarItem[]; getOutliningSpans(fileName: string): OutliningSpan[]; @@ -1712,6 +1719,10 @@ declare module "typescript" { containerKind: string; containerName: string; } + interface ReferencedSymbol { + definition: DefinitionInfo; + references: ReferenceEntry[]; + } enum SymbolDisplayPartKind { aliasName = 0, className = 1, diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index 55064457fad26..4ea9c49d7587d 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -447,562 +447,571 @@ declare module "typescript" { ColonToken = 51, >ColonToken : SyntaxKind - EqualsToken = 52, + AtToken = 52, +>AtToken : SyntaxKind + + EqualsToken = 53, >EqualsToken : SyntaxKind - PlusEqualsToken = 53, + PlusEqualsToken = 54, >PlusEqualsToken : SyntaxKind - MinusEqualsToken = 54, + MinusEqualsToken = 55, >MinusEqualsToken : SyntaxKind - AsteriskEqualsToken = 55, + AsteriskEqualsToken = 56, >AsteriskEqualsToken : SyntaxKind - SlashEqualsToken = 56, + SlashEqualsToken = 57, >SlashEqualsToken : SyntaxKind - PercentEqualsToken = 57, + PercentEqualsToken = 58, >PercentEqualsToken : SyntaxKind - LessThanLessThanEqualsToken = 58, + LessThanLessThanEqualsToken = 59, >LessThanLessThanEqualsToken : SyntaxKind - GreaterThanGreaterThanEqualsToken = 59, + GreaterThanGreaterThanEqualsToken = 60, >GreaterThanGreaterThanEqualsToken : SyntaxKind - GreaterThanGreaterThanGreaterThanEqualsToken = 60, + GreaterThanGreaterThanGreaterThanEqualsToken = 61, >GreaterThanGreaterThanGreaterThanEqualsToken : SyntaxKind - AmpersandEqualsToken = 61, + AmpersandEqualsToken = 62, >AmpersandEqualsToken : SyntaxKind - BarEqualsToken = 62, + BarEqualsToken = 63, >BarEqualsToken : SyntaxKind - CaretEqualsToken = 63, + CaretEqualsToken = 64, >CaretEqualsToken : SyntaxKind - Identifier = 64, + Identifier = 65, >Identifier : SyntaxKind - BreakKeyword = 65, + BreakKeyword = 66, >BreakKeyword : SyntaxKind - CaseKeyword = 66, + CaseKeyword = 67, >CaseKeyword : SyntaxKind - CatchKeyword = 67, + CatchKeyword = 68, >CatchKeyword : SyntaxKind - ClassKeyword = 68, + ClassKeyword = 69, >ClassKeyword : SyntaxKind - ConstKeyword = 69, + ConstKeyword = 70, >ConstKeyword : SyntaxKind - ContinueKeyword = 70, + ContinueKeyword = 71, >ContinueKeyword : SyntaxKind - DebuggerKeyword = 71, + DebuggerKeyword = 72, >DebuggerKeyword : SyntaxKind - DefaultKeyword = 72, + DefaultKeyword = 73, >DefaultKeyword : SyntaxKind - DeleteKeyword = 73, + DeleteKeyword = 74, >DeleteKeyword : SyntaxKind - DoKeyword = 74, + DoKeyword = 75, >DoKeyword : SyntaxKind - ElseKeyword = 75, + ElseKeyword = 76, >ElseKeyword : SyntaxKind - EnumKeyword = 76, + EnumKeyword = 77, >EnumKeyword : SyntaxKind - ExportKeyword = 77, + ExportKeyword = 78, >ExportKeyword : SyntaxKind - ExtendsKeyword = 78, + ExtendsKeyword = 79, >ExtendsKeyword : SyntaxKind - FalseKeyword = 79, + FalseKeyword = 80, >FalseKeyword : SyntaxKind - FinallyKeyword = 80, + FinallyKeyword = 81, >FinallyKeyword : SyntaxKind - ForKeyword = 81, + ForKeyword = 82, >ForKeyword : SyntaxKind - FunctionKeyword = 82, + FunctionKeyword = 83, >FunctionKeyword : SyntaxKind - IfKeyword = 83, + IfKeyword = 84, >IfKeyword : SyntaxKind - ImportKeyword = 84, + ImportKeyword = 85, >ImportKeyword : SyntaxKind - InKeyword = 85, + InKeyword = 86, >InKeyword : SyntaxKind - InstanceOfKeyword = 86, + InstanceOfKeyword = 87, >InstanceOfKeyword : SyntaxKind - NewKeyword = 87, + NewKeyword = 88, >NewKeyword : SyntaxKind - NullKeyword = 88, + NullKeyword = 89, >NullKeyword : SyntaxKind - ReturnKeyword = 89, + ReturnKeyword = 90, >ReturnKeyword : SyntaxKind - SuperKeyword = 90, + SuperKeyword = 91, >SuperKeyword : SyntaxKind - SwitchKeyword = 91, + SwitchKeyword = 92, >SwitchKeyword : SyntaxKind - ThisKeyword = 92, + ThisKeyword = 93, >ThisKeyword : SyntaxKind - ThrowKeyword = 93, + ThrowKeyword = 94, >ThrowKeyword : SyntaxKind - TrueKeyword = 94, + TrueKeyword = 95, >TrueKeyword : SyntaxKind - TryKeyword = 95, + TryKeyword = 96, >TryKeyword : SyntaxKind - TypeOfKeyword = 96, + TypeOfKeyword = 97, >TypeOfKeyword : SyntaxKind - VarKeyword = 97, + VarKeyword = 98, >VarKeyword : SyntaxKind - VoidKeyword = 98, + VoidKeyword = 99, >VoidKeyword : SyntaxKind - WhileKeyword = 99, + WhileKeyword = 100, >WhileKeyword : SyntaxKind - WithKeyword = 100, + WithKeyword = 101, >WithKeyword : SyntaxKind - AsKeyword = 101, + AsKeyword = 102, >AsKeyword : SyntaxKind - ImplementsKeyword = 102, + ImplementsKeyword = 103, >ImplementsKeyword : SyntaxKind - InterfaceKeyword = 103, + InterfaceKeyword = 104, >InterfaceKeyword : SyntaxKind - LetKeyword = 104, + LetKeyword = 105, >LetKeyword : SyntaxKind - PackageKeyword = 105, + PackageKeyword = 106, >PackageKeyword : SyntaxKind - PrivateKeyword = 106, + PrivateKeyword = 107, >PrivateKeyword : SyntaxKind - ProtectedKeyword = 107, + ProtectedKeyword = 108, >ProtectedKeyword : SyntaxKind - PublicKeyword = 108, + PublicKeyword = 109, >PublicKeyword : SyntaxKind - StaticKeyword = 109, + StaticKeyword = 110, >StaticKeyword : SyntaxKind - YieldKeyword = 110, + YieldKeyword = 111, >YieldKeyword : SyntaxKind - AnyKeyword = 111, + AnyKeyword = 112, >AnyKeyword : SyntaxKind - BooleanKeyword = 112, + BooleanKeyword = 113, >BooleanKeyword : SyntaxKind - ConstructorKeyword = 113, + ConstructorKeyword = 114, >ConstructorKeyword : SyntaxKind - DeclareKeyword = 114, + DeclareKeyword = 115, >DeclareKeyword : SyntaxKind - GetKeyword = 115, + GetKeyword = 116, >GetKeyword : SyntaxKind - ModuleKeyword = 116, + ModuleKeyword = 117, >ModuleKeyword : SyntaxKind - RequireKeyword = 117, + RequireKeyword = 118, >RequireKeyword : SyntaxKind - NumberKeyword = 118, + NumberKeyword = 119, >NumberKeyword : SyntaxKind - SetKeyword = 119, + SetKeyword = 120, >SetKeyword : SyntaxKind - StringKeyword = 120, + StringKeyword = 121, >StringKeyword : SyntaxKind - SymbolKeyword = 121, + SymbolKeyword = 122, >SymbolKeyword : SyntaxKind - TypeKeyword = 122, + TypeKeyword = 123, >TypeKeyword : SyntaxKind - FromKeyword = 123, + FromKeyword = 124, >FromKeyword : SyntaxKind - OfKeyword = 124, + OfKeyword = 125, >OfKeyword : SyntaxKind - QualifiedName = 125, + QualifiedName = 126, >QualifiedName : SyntaxKind - ComputedPropertyName = 126, + ComputedPropertyName = 127, >ComputedPropertyName : SyntaxKind - TypeParameter = 127, + TypeParameter = 128, >TypeParameter : SyntaxKind - Parameter = 128, + Parameter = 129, >Parameter : SyntaxKind - PropertySignature = 129, + Decorator = 130, +>Decorator : SyntaxKind + + PropertySignature = 131, >PropertySignature : SyntaxKind - PropertyDeclaration = 130, + PropertyDeclaration = 132, >PropertyDeclaration : SyntaxKind - MethodSignature = 131, + MethodSignature = 133, >MethodSignature : SyntaxKind - MethodDeclaration = 132, + MethodDeclaration = 134, >MethodDeclaration : SyntaxKind - Constructor = 133, + Constructor = 135, >Constructor : SyntaxKind - GetAccessor = 134, + GetAccessor = 136, >GetAccessor : SyntaxKind - SetAccessor = 135, + SetAccessor = 137, >SetAccessor : SyntaxKind - CallSignature = 136, + CallSignature = 138, >CallSignature : SyntaxKind - ConstructSignature = 137, + ConstructSignature = 139, >ConstructSignature : SyntaxKind - IndexSignature = 138, + IndexSignature = 140, >IndexSignature : SyntaxKind - TypeReference = 139, + TypeReference = 141, >TypeReference : SyntaxKind - FunctionType = 140, + FunctionType = 142, >FunctionType : SyntaxKind - ConstructorType = 141, + ConstructorType = 143, >ConstructorType : SyntaxKind - TypeQuery = 142, + TypeQuery = 144, >TypeQuery : SyntaxKind - TypeLiteral = 143, + TypeLiteral = 145, >TypeLiteral : SyntaxKind - ArrayType = 144, + ArrayType = 146, >ArrayType : SyntaxKind - TupleType = 145, + TupleType = 147, >TupleType : SyntaxKind - UnionType = 146, + UnionType = 148, >UnionType : SyntaxKind - ParenthesizedType = 147, + ParenthesizedType = 149, >ParenthesizedType : SyntaxKind - ObjectBindingPattern = 148, + ObjectBindingPattern = 150, >ObjectBindingPattern : SyntaxKind - ArrayBindingPattern = 149, + ArrayBindingPattern = 151, >ArrayBindingPattern : SyntaxKind - BindingElement = 150, + BindingElement = 152, >BindingElement : SyntaxKind - ArrayLiteralExpression = 151, + ArrayLiteralExpression = 153, >ArrayLiteralExpression : SyntaxKind - ObjectLiteralExpression = 152, + ObjectLiteralExpression = 154, >ObjectLiteralExpression : SyntaxKind - PropertyAccessExpression = 153, + PropertyAccessExpression = 155, >PropertyAccessExpression : SyntaxKind - ElementAccessExpression = 154, + ElementAccessExpression = 156, >ElementAccessExpression : SyntaxKind - CallExpression = 155, + CallExpression = 157, >CallExpression : SyntaxKind - NewExpression = 156, + NewExpression = 158, >NewExpression : SyntaxKind - TaggedTemplateExpression = 157, + TaggedTemplateExpression = 159, >TaggedTemplateExpression : SyntaxKind - TypeAssertionExpression = 158, + TypeAssertionExpression = 160, >TypeAssertionExpression : SyntaxKind - ParenthesizedExpression = 159, + ParenthesizedExpression = 161, >ParenthesizedExpression : SyntaxKind - FunctionExpression = 160, + FunctionExpression = 162, >FunctionExpression : SyntaxKind - ArrowFunction = 161, + ArrowFunction = 163, >ArrowFunction : SyntaxKind - DeleteExpression = 162, + DeleteExpression = 164, >DeleteExpression : SyntaxKind - TypeOfExpression = 163, + TypeOfExpression = 165, >TypeOfExpression : SyntaxKind - VoidExpression = 164, + VoidExpression = 166, >VoidExpression : SyntaxKind - PrefixUnaryExpression = 165, + PrefixUnaryExpression = 167, >PrefixUnaryExpression : SyntaxKind - PostfixUnaryExpression = 166, + PostfixUnaryExpression = 168, >PostfixUnaryExpression : SyntaxKind - BinaryExpression = 167, + BinaryExpression = 169, >BinaryExpression : SyntaxKind - ConditionalExpression = 168, + ConditionalExpression = 170, >ConditionalExpression : SyntaxKind - TemplateExpression = 169, + TemplateExpression = 171, >TemplateExpression : SyntaxKind - YieldExpression = 170, + YieldExpression = 172, >YieldExpression : SyntaxKind - SpreadElementExpression = 171, + SpreadElementExpression = 173, >SpreadElementExpression : SyntaxKind - OmittedExpression = 172, + OmittedExpression = 174, >OmittedExpression : SyntaxKind - TemplateSpan = 173, + TemplateSpan = 175, >TemplateSpan : SyntaxKind - Block = 174, + Block = 176, >Block : SyntaxKind - VariableStatement = 175, + VariableStatement = 177, >VariableStatement : SyntaxKind - EmptyStatement = 176, + EmptyStatement = 178, >EmptyStatement : SyntaxKind - ExpressionStatement = 177, + ExpressionStatement = 179, >ExpressionStatement : SyntaxKind - IfStatement = 178, + IfStatement = 180, >IfStatement : SyntaxKind - DoStatement = 179, + DoStatement = 181, >DoStatement : SyntaxKind - WhileStatement = 180, + WhileStatement = 182, >WhileStatement : SyntaxKind - ForStatement = 181, + ForStatement = 183, >ForStatement : SyntaxKind - ForInStatement = 182, + ForInStatement = 184, >ForInStatement : SyntaxKind - ForOfStatement = 183, + ForOfStatement = 185, >ForOfStatement : SyntaxKind - ContinueStatement = 184, + ContinueStatement = 186, >ContinueStatement : SyntaxKind - BreakStatement = 185, + BreakStatement = 187, >BreakStatement : SyntaxKind - ReturnStatement = 186, + ReturnStatement = 188, >ReturnStatement : SyntaxKind - WithStatement = 187, + WithStatement = 189, >WithStatement : SyntaxKind - SwitchStatement = 188, + SwitchStatement = 190, >SwitchStatement : SyntaxKind - LabeledStatement = 189, + LabeledStatement = 191, >LabeledStatement : SyntaxKind - ThrowStatement = 190, + ThrowStatement = 192, >ThrowStatement : SyntaxKind - TryStatement = 191, + TryStatement = 193, >TryStatement : SyntaxKind - DebuggerStatement = 192, + DebuggerStatement = 194, >DebuggerStatement : SyntaxKind - VariableDeclaration = 193, + VariableDeclaration = 195, >VariableDeclaration : SyntaxKind - VariableDeclarationList = 194, + VariableDeclarationList = 196, >VariableDeclarationList : SyntaxKind - FunctionDeclaration = 195, + FunctionDeclaration = 197, >FunctionDeclaration : SyntaxKind - ClassDeclaration = 196, + ClassDeclaration = 198, >ClassDeclaration : SyntaxKind - InterfaceDeclaration = 197, + InterfaceDeclaration = 199, >InterfaceDeclaration : SyntaxKind - TypeAliasDeclaration = 198, + TypeAliasDeclaration = 200, >TypeAliasDeclaration : SyntaxKind - EnumDeclaration = 199, + EnumDeclaration = 201, >EnumDeclaration : SyntaxKind - ModuleDeclaration = 200, + ModuleDeclaration = 202, >ModuleDeclaration : SyntaxKind - ModuleBlock = 201, + ModuleBlock = 203, >ModuleBlock : SyntaxKind - CaseBlock = 202, + CaseBlock = 204, >CaseBlock : SyntaxKind - ImportEqualsDeclaration = 203, + ImportEqualsDeclaration = 205, >ImportEqualsDeclaration : SyntaxKind - ImportDeclaration = 204, + ImportDeclaration = 206, >ImportDeclaration : SyntaxKind - ImportClause = 205, + ImportClause = 207, >ImportClause : SyntaxKind - NamespaceImport = 206, + NamespaceImport = 208, >NamespaceImport : SyntaxKind - NamedImports = 207, + NamedImports = 209, >NamedImports : SyntaxKind - ImportSpecifier = 208, + ImportSpecifier = 210, >ImportSpecifier : SyntaxKind - ExportAssignment = 209, + ExportAssignment = 211, >ExportAssignment : SyntaxKind - ExportDeclaration = 210, + ExportDeclaration = 212, >ExportDeclaration : SyntaxKind - NamedExports = 211, + NamedExports = 213, >NamedExports : SyntaxKind - ExportSpecifier = 212, + ExportSpecifier = 214, >ExportSpecifier : SyntaxKind - ExternalModuleReference = 213, + MissingDeclaration = 215, +>MissingDeclaration : SyntaxKind + + ExternalModuleReference = 216, >ExternalModuleReference : SyntaxKind - CaseClause = 214, + CaseClause = 217, >CaseClause : SyntaxKind - DefaultClause = 215, + DefaultClause = 218, >DefaultClause : SyntaxKind - HeritageClause = 216, + HeritageClause = 219, >HeritageClause : SyntaxKind - CatchClause = 217, + CatchClause = 220, >CatchClause : SyntaxKind - PropertyAssignment = 218, + PropertyAssignment = 221, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 219, + ShorthandPropertyAssignment = 222, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 220, + EnumMember = 223, >EnumMember : SyntaxKind - SourceFile = 221, + SourceFile = 224, >SourceFile : SyntaxKind - SyntaxList = 222, + SyntaxList = 225, >SyntaxList : SyntaxKind - Count = 223, + Count = 226, >Count : SyntaxKind - FirstAssignment = 52, + FirstAssignment = 53, >FirstAssignment : SyntaxKind - LastAssignment = 63, + LastAssignment = 64, >LastAssignment : SyntaxKind - FirstReservedWord = 65, + FirstReservedWord = 66, >FirstReservedWord : SyntaxKind - LastReservedWord = 100, + LastReservedWord = 101, >LastReservedWord : SyntaxKind - FirstKeyword = 65, + FirstKeyword = 66, >FirstKeyword : SyntaxKind - LastKeyword = 124, + LastKeyword = 125, >LastKeyword : SyntaxKind - FirstFutureReservedWord = 102, + FirstFutureReservedWord = 103, >FirstFutureReservedWord : SyntaxKind - LastFutureReservedWord = 110, + LastFutureReservedWord = 111, >LastFutureReservedWord : SyntaxKind - FirstTypeNode = 139, + FirstTypeNode = 141, >FirstTypeNode : SyntaxKind - LastTypeNode = 147, + LastTypeNode = 149, >LastTypeNode : SyntaxKind FirstPunctuation = 14, >FirstPunctuation : SyntaxKind - LastPunctuation = 63, + LastPunctuation = 64, >LastPunctuation : SyntaxKind FirstToken = 0, >FirstToken : SyntaxKind - LastToken = 124, + LastToken = 125, >LastToken : SyntaxKind FirstTriviaToken = 2, @@ -1026,10 +1035,10 @@ declare module "typescript" { FirstBinaryOperator = 24, >FirstBinaryOperator : SyntaxKind - LastBinaryOperator = 63, + LastBinaryOperator = 64, >LastBinaryOperator : SyntaxKind - FirstNode = 125, + FirstNode = 126, >FirstNode : SyntaxKind } const enum NodeFlags { @@ -1101,16 +1110,19 @@ declare module "typescript" { GeneratorParameter = 8, >GeneratorParameter : ParserContextFlags - ThisNodeHasError = 16, + Decorator = 16, +>Decorator : ParserContextFlags + + ThisNodeHasError = 32, >ThisNodeHasError : ParserContextFlags - ParserGeneratedFlags = 31, + ParserGeneratedFlags = 63, >ParserGeneratedFlags : ParserContextFlags - ThisNodeOrAnySubNodesHasError = 32, + ThisNodeOrAnySubNodesHasError = 64, >ThisNodeOrAnySubNodesHasError : ParserContextFlags - HasAggregatedChildData = 64, + HasAggregatedChildData = 128, >HasAggregatedChildData : ParserContextFlags } const enum RelationComparisonResult { @@ -1141,6 +1153,11 @@ declare module "typescript" { >parserContextFlags : ParserContextFlags >ParserContextFlags : ParserContextFlags + decorators?: NodeArray; +>decorators : NodeArray +>NodeArray : NodeArray +>Decorator : Decorator + modifiers?: ModifiersArray; >modifiers : ModifiersArray >ModifiersArray : ModifiersArray @@ -1235,6 +1252,14 @@ declare module "typescript" { expression: Expression; >expression : Expression >Expression : Expression + } + interface Decorator extends Node { +>Decorator : Decorator +>Node : Node + + expression: LeftHandSideExpression; +>expression : LeftHandSideExpression +>LeftHandSideExpression : LeftHandSideExpression } interface TypeParameterDeclaration extends Declaration { >TypeParameterDeclaration : TypeParameterDeclaration @@ -1767,6 +1792,15 @@ declare module "typescript" { >body : Expression | Block >Block : Block >Expression : Expression + } + interface ArrowFunction extends Expression, FunctionLikeDeclaration { +>ArrowFunction : ArrowFunction +>Expression : Expression +>FunctionLikeDeclaration : FunctionLikeDeclaration + + equalsGreaterThanToken: Node; +>equalsGreaterThanToken : Node +>Node : Node } interface LiteralExpression extends PrimaryExpression { >LiteralExpression : LiteralExpression @@ -2423,9 +2457,13 @@ declare module "typescript" { isExportEquals?: boolean; >isExportEquals : boolean - expression: Expression; + expression?: Expression; >expression : Expression >Expression : Expression + + type?: TypeNode; +>type : TypeNode +>TypeNode : TypeNode } interface FileReference extends TextRange { >FileReference : FileReference @@ -2526,14 +2564,14 @@ declare module "typescript" { >SourceFile : SourceFile /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then - * the javascript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the javascript and declaration for that + * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then + * the JavaScript and declaration files will be produced for all the files in this program. + * If targetSourceFile is specified, then only the JavaScript and declaration for that * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the javascript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; >emit : (targetSourceFile?: SourceFile, writeFile?: WriteFileCallback) => EmitResult @@ -3056,6 +3094,11 @@ declare module "typescript" { CannotBeNamed = 2, >CannotBeNamed : SymbolAccessibility } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration +>ImportDeclaration : ImportDeclaration +>ImportEqualsDeclaration : ImportEqualsDeclaration + interface SymbolVisibilityResult { >SymbolVisibilityResult : SymbolVisibilityResult @@ -3063,9 +3106,9 @@ declare module "typescript" { >accessibility : SymbolAccessibility >SymbolAccessibility : SymbolAccessibility - aliasesToMakeVisible?: ImportEqualsDeclaration[]; ->aliasesToMakeVisible : ImportEqualsDeclaration[] ->ImportEqualsDeclaration : ImportEqualsDeclaration + aliasesToMakeVisible?: AnyImportSyntax[]; +>aliasesToMakeVisible : (ImportEqualsDeclaration | ImportDeclaration)[] +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration errorSymbolName?: string; >errorSymbolName : string @@ -3084,25 +3127,28 @@ declare module "typescript" { interface EmitResolver { >EmitResolver : EmitResolver - getGeneratedNameForNode(node: Node): string; ->getGeneratedNameForNode : (node: Node) => string ->node : Node ->Node : Node + hasGlobalName(name: string): boolean; +>hasGlobalName : (name: string) => boolean +>name : string - getExpressionNameSubstitution(node: Identifier): string; ->getExpressionNameSubstitution : (node: Identifier) => string + getExpressionNameSubstitution(node: Identifier, getGeneratedNameForNode: (node: Node) => string): string; +>getExpressionNameSubstitution : (node: Identifier, getGeneratedNameForNode: (node: Node) => string) => string >node : Identifier >Identifier : Identifier +>getGeneratedNameForNode : (node: Node) => string +>node : Node +>Node : Node isValueAliasDeclaration(node: Node): boolean; >isValueAliasDeclaration : (node: Node) => boolean >node : Node >Node : Node - isReferencedAliasDeclaration(node: Node): boolean; ->isReferencedAliasDeclaration : (node: Node) => boolean + isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean; +>isReferencedAliasDeclaration : (node: Node, checkChildren?: boolean) => boolean >node : Node >Node : Node +>checkChildren : boolean isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; >isTopLevelValueImportEqualsWithEntityName : (node: ImportEqualsDeclaration) => boolean @@ -3120,6 +3166,12 @@ declare module "typescript" { >node : Declaration >Declaration : Declaration + collectLinkedAliases(node: Identifier): Node[]; +>collectLinkedAliases : (node: Identifier) => Node[] +>node : Identifier +>Identifier : Identifier +>Node : Node + isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; >isImplementationOfOverload : (node: FunctionLikeDeclaration) => boolean >node : FunctionLikeDeclaration @@ -3146,6 +3198,17 @@ declare module "typescript" { >flags : TypeFormatFlags >TypeFormatFlags : TypeFormatFlags >writer : SymbolWriter +>SymbolWriter : SymbolWriter + + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; +>writeTypeOfExpression : (expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) => void +>expr : Expression +>Expression : Expression +>enclosingDeclaration : Node +>Node : Node +>flags : TypeFormatFlags +>TypeFormatFlags : TypeFormatFlags +>writer : SymbolWriter >SymbolWriter : SymbolWriter isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; @@ -3173,8 +3236,8 @@ declare module "typescript" { >PropertyAccessExpression : PropertyAccessExpression >ElementAccessExpression : ElementAccessExpression - isUnknownIdentifier(location: Node, name: string): boolean; ->isUnknownIdentifier : (location: Node, name: string) => boolean + resolvesToSomeValue(location: Node, name: string): boolean; +>resolvesToSomeValue : (location: Node, name: string) => boolean >location : Node >Node : Node >name : string @@ -3496,6 +3559,9 @@ declare module "typescript" { BlockScopedBindingInLoop = 256, >BlockScopedBindingInLoop : NodeCheckFlags + + EmitDecorate = 512, +>EmitDecorate : NodeCheckFlags } interface NodeLinks { >NodeLinks : NodeLinks @@ -3855,38 +3921,6 @@ declare module "typescript" { >t : Type >Type : Type >Type : Type - } - interface TypeInferences { ->TypeInferences : TypeInferences - - primary: Type[]; ->primary : Type[] ->Type : Type - - secondary: Type[]; ->secondary : Type[] ->Type : Type - } - interface InferenceContext { ->InferenceContext : InferenceContext - - typeParameters: TypeParameter[]; ->typeParameters : TypeParameter[] ->TypeParameter : TypeParameter - - inferUnionTypes: boolean; ->inferUnionTypes : boolean - - inferences: TypeInferences[]; ->inferences : TypeInferences[] ->TypeInferences : TypeInferences - - inferredTypes: Type[]; ->inferredTypes : Type[] ->Type : Type - - failedTypeParameterIndex?: number; ->failedTypeParameterIndex : number } interface DiagnosticMessage { >DiagnosticMessage : DiagnosticMessage @@ -4832,10 +4866,15 @@ declare module "typescript" { let version: string; >version : string - function createCompilerHost(options: CompilerOptions): CompilerHost; ->createCompilerHost : (options: CompilerOptions) => CompilerHost + function findConfigFile(searchPath: string): string; +>findConfigFile : (searchPath: string) => string +>searchPath : string + + function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; +>createCompilerHost : (options: CompilerOptions, setParentNodes?: boolean) => CompilerHost >options : CompilerOptions >CompilerOptions : CompilerOptions +>setParentNodes : boolean >CompilerHost : CompilerHost function getPreEmitDiagnostics(program: Program): Diagnostic[]; @@ -5249,6 +5288,12 @@ declare module "typescript" { >position : number >ReferenceEntry : ReferenceEntry + findReferences(fileName: string, position: number): ReferencedSymbol[]; +>findReferences : (fileName: string, position: number) => ReferencedSymbol[] +>fileName : string +>position : number +>ReferencedSymbol : ReferencedSymbol + getNavigateToItems(searchValue: string, maxResultCount?: number): NavigateToItem[]; >getNavigateToItems : (searchValue: string, maxResultCount?: number) => NavigateToItem[] >searchValue : string @@ -5519,6 +5564,17 @@ declare module "typescript" { containerName: string; >containerName : string + } + interface ReferencedSymbol { +>ReferencedSymbol : ReferencedSymbol + + definition: DefinitionInfo; +>definition : DefinitionInfo +>DefinitionInfo : DefinitionInfo + + references: ReferenceEntry[]; +>references : ReferenceEntry[] +>ReferenceEntry : ReferenceEntry } enum SymbolDisplayPartKind { >SymbolDisplayPartKind : SymbolDisplayPartKind diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index b61ed3fdc9f6c..34503a0d81a22 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -180,192 +180,195 @@ declare module "typescript" { BarBarToken = 49, QuestionToken = 50, ColonToken = 51, - EqualsToken = 52, - PlusEqualsToken = 53, - MinusEqualsToken = 54, - AsteriskEqualsToken = 55, - SlashEqualsToken = 56, - PercentEqualsToken = 57, - LessThanLessThanEqualsToken = 58, - GreaterThanGreaterThanEqualsToken = 59, - GreaterThanGreaterThanGreaterThanEqualsToken = 60, - AmpersandEqualsToken = 61, - BarEqualsToken = 62, - CaretEqualsToken = 63, - Identifier = 64, - BreakKeyword = 65, - CaseKeyword = 66, - CatchKeyword = 67, - ClassKeyword = 68, - ConstKeyword = 69, - ContinueKeyword = 70, - DebuggerKeyword = 71, - DefaultKeyword = 72, - DeleteKeyword = 73, - DoKeyword = 74, - ElseKeyword = 75, - EnumKeyword = 76, - ExportKeyword = 77, - ExtendsKeyword = 78, - FalseKeyword = 79, - FinallyKeyword = 80, - ForKeyword = 81, - FunctionKeyword = 82, - IfKeyword = 83, - ImportKeyword = 84, - InKeyword = 85, - InstanceOfKeyword = 86, - NewKeyword = 87, - NullKeyword = 88, - ReturnKeyword = 89, - SuperKeyword = 90, - SwitchKeyword = 91, - ThisKeyword = 92, - ThrowKeyword = 93, - TrueKeyword = 94, - TryKeyword = 95, - TypeOfKeyword = 96, - VarKeyword = 97, - VoidKeyword = 98, - WhileKeyword = 99, - WithKeyword = 100, - AsKeyword = 101, - ImplementsKeyword = 102, - InterfaceKeyword = 103, - LetKeyword = 104, - PackageKeyword = 105, - PrivateKeyword = 106, - ProtectedKeyword = 107, - PublicKeyword = 108, - StaticKeyword = 109, - YieldKeyword = 110, - AnyKeyword = 111, - BooleanKeyword = 112, - ConstructorKeyword = 113, - DeclareKeyword = 114, - GetKeyword = 115, - ModuleKeyword = 116, - RequireKeyword = 117, - NumberKeyword = 118, - SetKeyword = 119, - StringKeyword = 120, - SymbolKeyword = 121, - TypeKeyword = 122, - FromKeyword = 123, - OfKeyword = 124, - QualifiedName = 125, - ComputedPropertyName = 126, - TypeParameter = 127, - Parameter = 128, - PropertySignature = 129, - PropertyDeclaration = 130, - MethodSignature = 131, - MethodDeclaration = 132, - Constructor = 133, - GetAccessor = 134, - SetAccessor = 135, - CallSignature = 136, - ConstructSignature = 137, - IndexSignature = 138, - TypeReference = 139, - FunctionType = 140, - ConstructorType = 141, - TypeQuery = 142, - TypeLiteral = 143, - ArrayType = 144, - TupleType = 145, - UnionType = 146, - ParenthesizedType = 147, - ObjectBindingPattern = 148, - ArrayBindingPattern = 149, - BindingElement = 150, - ArrayLiteralExpression = 151, - ObjectLiteralExpression = 152, - PropertyAccessExpression = 153, - ElementAccessExpression = 154, - CallExpression = 155, - NewExpression = 156, - TaggedTemplateExpression = 157, - TypeAssertionExpression = 158, - ParenthesizedExpression = 159, - FunctionExpression = 160, - ArrowFunction = 161, - DeleteExpression = 162, - TypeOfExpression = 163, - VoidExpression = 164, - PrefixUnaryExpression = 165, - PostfixUnaryExpression = 166, - BinaryExpression = 167, - ConditionalExpression = 168, - TemplateExpression = 169, - YieldExpression = 170, - SpreadElementExpression = 171, - OmittedExpression = 172, - TemplateSpan = 173, - Block = 174, - VariableStatement = 175, - EmptyStatement = 176, - ExpressionStatement = 177, - IfStatement = 178, - DoStatement = 179, - WhileStatement = 180, - ForStatement = 181, - ForInStatement = 182, - ForOfStatement = 183, - ContinueStatement = 184, - BreakStatement = 185, - ReturnStatement = 186, - WithStatement = 187, - SwitchStatement = 188, - LabeledStatement = 189, - ThrowStatement = 190, - TryStatement = 191, - DebuggerStatement = 192, - VariableDeclaration = 193, - VariableDeclarationList = 194, - FunctionDeclaration = 195, - ClassDeclaration = 196, - InterfaceDeclaration = 197, - TypeAliasDeclaration = 198, - EnumDeclaration = 199, - ModuleDeclaration = 200, - ModuleBlock = 201, - CaseBlock = 202, - ImportEqualsDeclaration = 203, - ImportDeclaration = 204, - ImportClause = 205, - NamespaceImport = 206, - NamedImports = 207, - ImportSpecifier = 208, - ExportAssignment = 209, - ExportDeclaration = 210, - NamedExports = 211, - ExportSpecifier = 212, - ExternalModuleReference = 213, - CaseClause = 214, - DefaultClause = 215, - HeritageClause = 216, - CatchClause = 217, - PropertyAssignment = 218, - ShorthandPropertyAssignment = 219, - EnumMember = 220, - SourceFile = 221, - SyntaxList = 222, - Count = 223, - FirstAssignment = 52, - LastAssignment = 63, - FirstReservedWord = 65, - LastReservedWord = 100, - FirstKeyword = 65, - LastKeyword = 124, - FirstFutureReservedWord = 102, - LastFutureReservedWord = 110, - FirstTypeNode = 139, - LastTypeNode = 147, + AtToken = 52, + EqualsToken = 53, + PlusEqualsToken = 54, + MinusEqualsToken = 55, + AsteriskEqualsToken = 56, + SlashEqualsToken = 57, + PercentEqualsToken = 58, + LessThanLessThanEqualsToken = 59, + GreaterThanGreaterThanEqualsToken = 60, + GreaterThanGreaterThanGreaterThanEqualsToken = 61, + AmpersandEqualsToken = 62, + BarEqualsToken = 63, + CaretEqualsToken = 64, + Identifier = 65, + BreakKeyword = 66, + CaseKeyword = 67, + CatchKeyword = 68, + ClassKeyword = 69, + ConstKeyword = 70, + ContinueKeyword = 71, + DebuggerKeyword = 72, + DefaultKeyword = 73, + DeleteKeyword = 74, + DoKeyword = 75, + ElseKeyword = 76, + EnumKeyword = 77, + ExportKeyword = 78, + ExtendsKeyword = 79, + FalseKeyword = 80, + FinallyKeyword = 81, + ForKeyword = 82, + FunctionKeyword = 83, + IfKeyword = 84, + ImportKeyword = 85, + InKeyword = 86, + InstanceOfKeyword = 87, + NewKeyword = 88, + NullKeyword = 89, + ReturnKeyword = 90, + SuperKeyword = 91, + SwitchKeyword = 92, + ThisKeyword = 93, + ThrowKeyword = 94, + TrueKeyword = 95, + TryKeyword = 96, + TypeOfKeyword = 97, + VarKeyword = 98, + VoidKeyword = 99, + WhileKeyword = 100, + WithKeyword = 101, + AsKeyword = 102, + ImplementsKeyword = 103, + InterfaceKeyword = 104, + LetKeyword = 105, + PackageKeyword = 106, + PrivateKeyword = 107, + ProtectedKeyword = 108, + PublicKeyword = 109, + StaticKeyword = 110, + YieldKeyword = 111, + AnyKeyword = 112, + BooleanKeyword = 113, + ConstructorKeyword = 114, + DeclareKeyword = 115, + GetKeyword = 116, + ModuleKeyword = 117, + RequireKeyword = 118, + NumberKeyword = 119, + SetKeyword = 120, + StringKeyword = 121, + SymbolKeyword = 122, + TypeKeyword = 123, + FromKeyword = 124, + OfKeyword = 125, + QualifiedName = 126, + ComputedPropertyName = 127, + TypeParameter = 128, + Parameter = 129, + Decorator = 130, + PropertySignature = 131, + PropertyDeclaration = 132, + MethodSignature = 133, + MethodDeclaration = 134, + Constructor = 135, + GetAccessor = 136, + SetAccessor = 137, + CallSignature = 138, + ConstructSignature = 139, + IndexSignature = 140, + TypeReference = 141, + FunctionType = 142, + ConstructorType = 143, + TypeQuery = 144, + TypeLiteral = 145, + ArrayType = 146, + TupleType = 147, + UnionType = 148, + ParenthesizedType = 149, + ObjectBindingPattern = 150, + ArrayBindingPattern = 151, + BindingElement = 152, + ArrayLiteralExpression = 153, + ObjectLiteralExpression = 154, + PropertyAccessExpression = 155, + ElementAccessExpression = 156, + CallExpression = 157, + NewExpression = 158, + TaggedTemplateExpression = 159, + TypeAssertionExpression = 160, + ParenthesizedExpression = 161, + FunctionExpression = 162, + ArrowFunction = 163, + DeleteExpression = 164, + TypeOfExpression = 165, + VoidExpression = 166, + PrefixUnaryExpression = 167, + PostfixUnaryExpression = 168, + BinaryExpression = 169, + ConditionalExpression = 170, + TemplateExpression = 171, + YieldExpression = 172, + SpreadElementExpression = 173, + OmittedExpression = 174, + TemplateSpan = 175, + Block = 176, + VariableStatement = 177, + EmptyStatement = 178, + ExpressionStatement = 179, + IfStatement = 180, + DoStatement = 181, + WhileStatement = 182, + ForStatement = 183, + ForInStatement = 184, + ForOfStatement = 185, + ContinueStatement = 186, + BreakStatement = 187, + ReturnStatement = 188, + WithStatement = 189, + SwitchStatement = 190, + LabeledStatement = 191, + ThrowStatement = 192, + TryStatement = 193, + DebuggerStatement = 194, + VariableDeclaration = 195, + VariableDeclarationList = 196, + FunctionDeclaration = 197, + ClassDeclaration = 198, + InterfaceDeclaration = 199, + TypeAliasDeclaration = 200, + EnumDeclaration = 201, + ModuleDeclaration = 202, + ModuleBlock = 203, + CaseBlock = 204, + ImportEqualsDeclaration = 205, + ImportDeclaration = 206, + ImportClause = 207, + NamespaceImport = 208, + NamedImports = 209, + ImportSpecifier = 210, + ExportAssignment = 211, + ExportDeclaration = 212, + NamedExports = 213, + ExportSpecifier = 214, + MissingDeclaration = 215, + ExternalModuleReference = 216, + CaseClause = 217, + DefaultClause = 218, + HeritageClause = 219, + CatchClause = 220, + PropertyAssignment = 221, + ShorthandPropertyAssignment = 222, + EnumMember = 223, + SourceFile = 224, + SyntaxList = 225, + Count = 226, + FirstAssignment = 53, + LastAssignment = 64, + FirstReservedWord = 66, + LastReservedWord = 101, + FirstKeyword = 66, + LastKeyword = 125, + FirstFutureReservedWord = 103, + LastFutureReservedWord = 111, + FirstTypeNode = 141, + LastTypeNode = 149, FirstPunctuation = 14, - LastPunctuation = 63, + LastPunctuation = 64, FirstToken = 0, - LastToken = 124, + LastToken = 125, FirstTriviaToken = 2, LastTriviaToken = 6, FirstLiteralToken = 7, @@ -373,8 +376,8 @@ declare module "typescript" { FirstTemplateToken = 10, LastTemplateToken = 13, FirstBinaryOperator = 24, - LastBinaryOperator = 63, - FirstNode = 125, + LastBinaryOperator = 64, + FirstNode = 126, } const enum NodeFlags { Export = 1, @@ -400,10 +403,11 @@ declare module "typescript" { DisallowIn = 2, Yield = 4, GeneratorParameter = 8, - ThisNodeHasError = 16, - ParserGeneratedFlags = 31, - ThisNodeOrAnySubNodesHasError = 32, - HasAggregatedChildData = 64, + Decorator = 16, + ThisNodeHasError = 32, + ParserGeneratedFlags = 63, + ThisNodeOrAnySubNodesHasError = 64, + HasAggregatedChildData = 128, } const enum RelationComparisonResult { Succeeded = 1, @@ -414,6 +418,7 @@ declare module "typescript" { kind: SyntaxKind; flags: NodeFlags; parserContextFlags?: ParserContextFlags; + decorators?: NodeArray; modifiers?: ModifiersArray; id?: number; parent?: Node; @@ -444,6 +449,9 @@ declare module "typescript" { interface ComputedPropertyName extends Node { expression: Expression; } + interface Decorator extends Node { + expression: LeftHandSideExpression; + } interface TypeParameterDeclaration extends Declaration { name: Identifier; constraint?: TypeNode; @@ -623,6 +631,9 @@ declare module "typescript" { name?: Identifier; body: Block | Expression; } + interface ArrowFunction extends Expression, FunctionLikeDeclaration { + equalsGreaterThanToken: Node; + } interface LiteralExpression extends PrimaryExpression { text: string; isUnterminated?: boolean; @@ -832,7 +843,8 @@ declare module "typescript" { type ExportSpecifier = ImportOrExportSpecifier; interface ExportAssignment extends Declaration, ModuleElement { isExportEquals?: boolean; - expression: Expression; + expression?: Expression; + type?: TypeNode; } interface FileReference extends TextRange { fileName: string; @@ -867,14 +879,14 @@ declare module "typescript" { interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then - * the javascript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the javascript and declaration for that + * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then + * the JavaScript and declaration files will be produced for all the files in this program. + * If targetSourceFile is specified, then only the JavaScript and declaration for that * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the javascript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; @@ -993,9 +1005,10 @@ declare module "typescript" { NotAccessible = 1, CannotBeNamed = 2, } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; interface SymbolVisibilityResult { accessibility: SymbolAccessibility; - aliasesToMakeVisible?: ImportEqualsDeclaration[]; + aliasesToMakeVisible?: AnyImportSyntax[]; errorSymbolName?: string; errorNode?: Node; } @@ -1003,20 +1016,22 @@ declare module "typescript" { errorModuleName?: string; } interface EmitResolver { - getGeneratedNameForNode(node: Node): string; - getExpressionNameSubstitution(node: Identifier): string; + hasGlobalName(name: string): boolean; + getExpressionNameSubstitution(node: Identifier, getGeneratedNameForNode: (node: Node) => string): string; isValueAliasDeclaration(node: Node): boolean; - isReferencedAliasDeclaration(node: Node): boolean; + isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; + collectLinkedAliases(node: Identifier): Node[]; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; - isUnknownIdentifier(location: Node, name: string): boolean; + resolvesToSomeValue(location: Node, name: string): boolean; getBlockScopedVariableId(node: Identifier): number; } const enum SymbolFlags { @@ -1123,6 +1138,7 @@ declare module "typescript" { ContextChecked = 64, EnumValuesComputed = 128, BlockScopedBindingInLoop = 256, + EmitDecorate = 512, } interface NodeLinks { resolvedType?: Type; @@ -1242,17 +1258,6 @@ declare module "typescript" { interface TypeMapper { (t: Type): Type; } - interface TypeInferences { - primary: Type[]; - secondary: Type[]; - } - interface InferenceContext { - typeParameters: TypeParameter[]; - inferUnionTypes: boolean; - inferences: TypeInferences[]; - inferredTypes: Type[]; - failedTypeParameterIndex?: number; - } interface DiagnosticMessage { key: string; category: DiagnosticCategory; @@ -1549,7 +1554,8 @@ declare module "typescript" { declare module "typescript" { /** The version of the TypeScript compiler release */ let version: string; - function createCompilerHost(options: CompilerOptions): CompilerHost; + function findConfigFile(searchPath: string): string; + function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; function getPreEmitDiagnostics(program: Program): Diagnostic[]; function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; @@ -1663,6 +1669,7 @@ declare module "typescript" { getDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[]; getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[]; getOccurrencesAtPosition(fileName: string, position: number): ReferenceEntry[]; + findReferences(fileName: string, position: number): ReferencedSymbol[]; getNavigateToItems(searchValue: string, maxResultCount?: number): NavigateToItem[]; getNavigationBarItems(fileName: string): NavigationBarItem[]; getOutliningSpans(fileName: string): OutliningSpan[]; @@ -1749,6 +1756,10 @@ declare module "typescript" { containerKind: string; containerName: string; } + interface ReferencedSymbol { + definition: DefinitionInfo; + references: ReferenceEntry[]; + } enum SymbolDisplayPartKind { aliasName = 0, className = 1, diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index aaba39c6b8d23..3903e169b4e3b 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -620,562 +620,571 @@ declare module "typescript" { ColonToken = 51, >ColonToken : SyntaxKind - EqualsToken = 52, + AtToken = 52, +>AtToken : SyntaxKind + + EqualsToken = 53, >EqualsToken : SyntaxKind - PlusEqualsToken = 53, + PlusEqualsToken = 54, >PlusEqualsToken : SyntaxKind - MinusEqualsToken = 54, + MinusEqualsToken = 55, >MinusEqualsToken : SyntaxKind - AsteriskEqualsToken = 55, + AsteriskEqualsToken = 56, >AsteriskEqualsToken : SyntaxKind - SlashEqualsToken = 56, + SlashEqualsToken = 57, >SlashEqualsToken : SyntaxKind - PercentEqualsToken = 57, + PercentEqualsToken = 58, >PercentEqualsToken : SyntaxKind - LessThanLessThanEqualsToken = 58, + LessThanLessThanEqualsToken = 59, >LessThanLessThanEqualsToken : SyntaxKind - GreaterThanGreaterThanEqualsToken = 59, + GreaterThanGreaterThanEqualsToken = 60, >GreaterThanGreaterThanEqualsToken : SyntaxKind - GreaterThanGreaterThanGreaterThanEqualsToken = 60, + GreaterThanGreaterThanGreaterThanEqualsToken = 61, >GreaterThanGreaterThanGreaterThanEqualsToken : SyntaxKind - AmpersandEqualsToken = 61, + AmpersandEqualsToken = 62, >AmpersandEqualsToken : SyntaxKind - BarEqualsToken = 62, + BarEqualsToken = 63, >BarEqualsToken : SyntaxKind - CaretEqualsToken = 63, + CaretEqualsToken = 64, >CaretEqualsToken : SyntaxKind - Identifier = 64, + Identifier = 65, >Identifier : SyntaxKind - BreakKeyword = 65, + BreakKeyword = 66, >BreakKeyword : SyntaxKind - CaseKeyword = 66, + CaseKeyword = 67, >CaseKeyword : SyntaxKind - CatchKeyword = 67, + CatchKeyword = 68, >CatchKeyword : SyntaxKind - ClassKeyword = 68, + ClassKeyword = 69, >ClassKeyword : SyntaxKind - ConstKeyword = 69, + ConstKeyword = 70, >ConstKeyword : SyntaxKind - ContinueKeyword = 70, + ContinueKeyword = 71, >ContinueKeyword : SyntaxKind - DebuggerKeyword = 71, + DebuggerKeyword = 72, >DebuggerKeyword : SyntaxKind - DefaultKeyword = 72, + DefaultKeyword = 73, >DefaultKeyword : SyntaxKind - DeleteKeyword = 73, + DeleteKeyword = 74, >DeleteKeyword : SyntaxKind - DoKeyword = 74, + DoKeyword = 75, >DoKeyword : SyntaxKind - ElseKeyword = 75, + ElseKeyword = 76, >ElseKeyword : SyntaxKind - EnumKeyword = 76, + EnumKeyword = 77, >EnumKeyword : SyntaxKind - ExportKeyword = 77, + ExportKeyword = 78, >ExportKeyword : SyntaxKind - ExtendsKeyword = 78, + ExtendsKeyword = 79, >ExtendsKeyword : SyntaxKind - FalseKeyword = 79, + FalseKeyword = 80, >FalseKeyword : SyntaxKind - FinallyKeyword = 80, + FinallyKeyword = 81, >FinallyKeyword : SyntaxKind - ForKeyword = 81, + ForKeyword = 82, >ForKeyword : SyntaxKind - FunctionKeyword = 82, + FunctionKeyword = 83, >FunctionKeyword : SyntaxKind - IfKeyword = 83, + IfKeyword = 84, >IfKeyword : SyntaxKind - ImportKeyword = 84, + ImportKeyword = 85, >ImportKeyword : SyntaxKind - InKeyword = 85, + InKeyword = 86, >InKeyword : SyntaxKind - InstanceOfKeyword = 86, + InstanceOfKeyword = 87, >InstanceOfKeyword : SyntaxKind - NewKeyword = 87, + NewKeyword = 88, >NewKeyword : SyntaxKind - NullKeyword = 88, + NullKeyword = 89, >NullKeyword : SyntaxKind - ReturnKeyword = 89, + ReturnKeyword = 90, >ReturnKeyword : SyntaxKind - SuperKeyword = 90, + SuperKeyword = 91, >SuperKeyword : SyntaxKind - SwitchKeyword = 91, + SwitchKeyword = 92, >SwitchKeyword : SyntaxKind - ThisKeyword = 92, + ThisKeyword = 93, >ThisKeyword : SyntaxKind - ThrowKeyword = 93, + ThrowKeyword = 94, >ThrowKeyword : SyntaxKind - TrueKeyword = 94, + TrueKeyword = 95, >TrueKeyword : SyntaxKind - TryKeyword = 95, + TryKeyword = 96, >TryKeyword : SyntaxKind - TypeOfKeyword = 96, + TypeOfKeyword = 97, >TypeOfKeyword : SyntaxKind - VarKeyword = 97, + VarKeyword = 98, >VarKeyword : SyntaxKind - VoidKeyword = 98, + VoidKeyword = 99, >VoidKeyword : SyntaxKind - WhileKeyword = 99, + WhileKeyword = 100, >WhileKeyword : SyntaxKind - WithKeyword = 100, + WithKeyword = 101, >WithKeyword : SyntaxKind - AsKeyword = 101, + AsKeyword = 102, >AsKeyword : SyntaxKind - ImplementsKeyword = 102, + ImplementsKeyword = 103, >ImplementsKeyword : SyntaxKind - InterfaceKeyword = 103, + InterfaceKeyword = 104, >InterfaceKeyword : SyntaxKind - LetKeyword = 104, + LetKeyword = 105, >LetKeyword : SyntaxKind - PackageKeyword = 105, + PackageKeyword = 106, >PackageKeyword : SyntaxKind - PrivateKeyword = 106, + PrivateKeyword = 107, >PrivateKeyword : SyntaxKind - ProtectedKeyword = 107, + ProtectedKeyword = 108, >ProtectedKeyword : SyntaxKind - PublicKeyword = 108, + PublicKeyword = 109, >PublicKeyword : SyntaxKind - StaticKeyword = 109, + StaticKeyword = 110, >StaticKeyword : SyntaxKind - YieldKeyword = 110, + YieldKeyword = 111, >YieldKeyword : SyntaxKind - AnyKeyword = 111, + AnyKeyword = 112, >AnyKeyword : SyntaxKind - BooleanKeyword = 112, + BooleanKeyword = 113, >BooleanKeyword : SyntaxKind - ConstructorKeyword = 113, + ConstructorKeyword = 114, >ConstructorKeyword : SyntaxKind - DeclareKeyword = 114, + DeclareKeyword = 115, >DeclareKeyword : SyntaxKind - GetKeyword = 115, + GetKeyword = 116, >GetKeyword : SyntaxKind - ModuleKeyword = 116, + ModuleKeyword = 117, >ModuleKeyword : SyntaxKind - RequireKeyword = 117, + RequireKeyword = 118, >RequireKeyword : SyntaxKind - NumberKeyword = 118, + NumberKeyword = 119, >NumberKeyword : SyntaxKind - SetKeyword = 119, + SetKeyword = 120, >SetKeyword : SyntaxKind - StringKeyword = 120, + StringKeyword = 121, >StringKeyword : SyntaxKind - SymbolKeyword = 121, + SymbolKeyword = 122, >SymbolKeyword : SyntaxKind - TypeKeyword = 122, + TypeKeyword = 123, >TypeKeyword : SyntaxKind - FromKeyword = 123, + FromKeyword = 124, >FromKeyword : SyntaxKind - OfKeyword = 124, + OfKeyword = 125, >OfKeyword : SyntaxKind - QualifiedName = 125, + QualifiedName = 126, >QualifiedName : SyntaxKind - ComputedPropertyName = 126, + ComputedPropertyName = 127, >ComputedPropertyName : SyntaxKind - TypeParameter = 127, + TypeParameter = 128, >TypeParameter : SyntaxKind - Parameter = 128, + Parameter = 129, >Parameter : SyntaxKind - PropertySignature = 129, + Decorator = 130, +>Decorator : SyntaxKind + + PropertySignature = 131, >PropertySignature : SyntaxKind - PropertyDeclaration = 130, + PropertyDeclaration = 132, >PropertyDeclaration : SyntaxKind - MethodSignature = 131, + MethodSignature = 133, >MethodSignature : SyntaxKind - MethodDeclaration = 132, + MethodDeclaration = 134, >MethodDeclaration : SyntaxKind - Constructor = 133, + Constructor = 135, >Constructor : SyntaxKind - GetAccessor = 134, + GetAccessor = 136, >GetAccessor : SyntaxKind - SetAccessor = 135, + SetAccessor = 137, >SetAccessor : SyntaxKind - CallSignature = 136, + CallSignature = 138, >CallSignature : SyntaxKind - ConstructSignature = 137, + ConstructSignature = 139, >ConstructSignature : SyntaxKind - IndexSignature = 138, + IndexSignature = 140, >IndexSignature : SyntaxKind - TypeReference = 139, + TypeReference = 141, >TypeReference : SyntaxKind - FunctionType = 140, + FunctionType = 142, >FunctionType : SyntaxKind - ConstructorType = 141, + ConstructorType = 143, >ConstructorType : SyntaxKind - TypeQuery = 142, + TypeQuery = 144, >TypeQuery : SyntaxKind - TypeLiteral = 143, + TypeLiteral = 145, >TypeLiteral : SyntaxKind - ArrayType = 144, + ArrayType = 146, >ArrayType : SyntaxKind - TupleType = 145, + TupleType = 147, >TupleType : SyntaxKind - UnionType = 146, + UnionType = 148, >UnionType : SyntaxKind - ParenthesizedType = 147, + ParenthesizedType = 149, >ParenthesizedType : SyntaxKind - ObjectBindingPattern = 148, + ObjectBindingPattern = 150, >ObjectBindingPattern : SyntaxKind - ArrayBindingPattern = 149, + ArrayBindingPattern = 151, >ArrayBindingPattern : SyntaxKind - BindingElement = 150, + BindingElement = 152, >BindingElement : SyntaxKind - ArrayLiteralExpression = 151, + ArrayLiteralExpression = 153, >ArrayLiteralExpression : SyntaxKind - ObjectLiteralExpression = 152, + ObjectLiteralExpression = 154, >ObjectLiteralExpression : SyntaxKind - PropertyAccessExpression = 153, + PropertyAccessExpression = 155, >PropertyAccessExpression : SyntaxKind - ElementAccessExpression = 154, + ElementAccessExpression = 156, >ElementAccessExpression : SyntaxKind - CallExpression = 155, + CallExpression = 157, >CallExpression : SyntaxKind - NewExpression = 156, + NewExpression = 158, >NewExpression : SyntaxKind - TaggedTemplateExpression = 157, + TaggedTemplateExpression = 159, >TaggedTemplateExpression : SyntaxKind - TypeAssertionExpression = 158, + TypeAssertionExpression = 160, >TypeAssertionExpression : SyntaxKind - ParenthesizedExpression = 159, + ParenthesizedExpression = 161, >ParenthesizedExpression : SyntaxKind - FunctionExpression = 160, + FunctionExpression = 162, >FunctionExpression : SyntaxKind - ArrowFunction = 161, + ArrowFunction = 163, >ArrowFunction : SyntaxKind - DeleteExpression = 162, + DeleteExpression = 164, >DeleteExpression : SyntaxKind - TypeOfExpression = 163, + TypeOfExpression = 165, >TypeOfExpression : SyntaxKind - VoidExpression = 164, + VoidExpression = 166, >VoidExpression : SyntaxKind - PrefixUnaryExpression = 165, + PrefixUnaryExpression = 167, >PrefixUnaryExpression : SyntaxKind - PostfixUnaryExpression = 166, + PostfixUnaryExpression = 168, >PostfixUnaryExpression : SyntaxKind - BinaryExpression = 167, + BinaryExpression = 169, >BinaryExpression : SyntaxKind - ConditionalExpression = 168, + ConditionalExpression = 170, >ConditionalExpression : SyntaxKind - TemplateExpression = 169, + TemplateExpression = 171, >TemplateExpression : SyntaxKind - YieldExpression = 170, + YieldExpression = 172, >YieldExpression : SyntaxKind - SpreadElementExpression = 171, + SpreadElementExpression = 173, >SpreadElementExpression : SyntaxKind - OmittedExpression = 172, + OmittedExpression = 174, >OmittedExpression : SyntaxKind - TemplateSpan = 173, + TemplateSpan = 175, >TemplateSpan : SyntaxKind - Block = 174, + Block = 176, >Block : SyntaxKind - VariableStatement = 175, + VariableStatement = 177, >VariableStatement : SyntaxKind - EmptyStatement = 176, + EmptyStatement = 178, >EmptyStatement : SyntaxKind - ExpressionStatement = 177, + ExpressionStatement = 179, >ExpressionStatement : SyntaxKind - IfStatement = 178, + IfStatement = 180, >IfStatement : SyntaxKind - DoStatement = 179, + DoStatement = 181, >DoStatement : SyntaxKind - WhileStatement = 180, + WhileStatement = 182, >WhileStatement : SyntaxKind - ForStatement = 181, + ForStatement = 183, >ForStatement : SyntaxKind - ForInStatement = 182, + ForInStatement = 184, >ForInStatement : SyntaxKind - ForOfStatement = 183, + ForOfStatement = 185, >ForOfStatement : SyntaxKind - ContinueStatement = 184, + ContinueStatement = 186, >ContinueStatement : SyntaxKind - BreakStatement = 185, + BreakStatement = 187, >BreakStatement : SyntaxKind - ReturnStatement = 186, + ReturnStatement = 188, >ReturnStatement : SyntaxKind - WithStatement = 187, + WithStatement = 189, >WithStatement : SyntaxKind - SwitchStatement = 188, + SwitchStatement = 190, >SwitchStatement : SyntaxKind - LabeledStatement = 189, + LabeledStatement = 191, >LabeledStatement : SyntaxKind - ThrowStatement = 190, + ThrowStatement = 192, >ThrowStatement : SyntaxKind - TryStatement = 191, + TryStatement = 193, >TryStatement : SyntaxKind - DebuggerStatement = 192, + DebuggerStatement = 194, >DebuggerStatement : SyntaxKind - VariableDeclaration = 193, + VariableDeclaration = 195, >VariableDeclaration : SyntaxKind - VariableDeclarationList = 194, + VariableDeclarationList = 196, >VariableDeclarationList : SyntaxKind - FunctionDeclaration = 195, + FunctionDeclaration = 197, >FunctionDeclaration : SyntaxKind - ClassDeclaration = 196, + ClassDeclaration = 198, >ClassDeclaration : SyntaxKind - InterfaceDeclaration = 197, + InterfaceDeclaration = 199, >InterfaceDeclaration : SyntaxKind - TypeAliasDeclaration = 198, + TypeAliasDeclaration = 200, >TypeAliasDeclaration : SyntaxKind - EnumDeclaration = 199, + EnumDeclaration = 201, >EnumDeclaration : SyntaxKind - ModuleDeclaration = 200, + ModuleDeclaration = 202, >ModuleDeclaration : SyntaxKind - ModuleBlock = 201, + ModuleBlock = 203, >ModuleBlock : SyntaxKind - CaseBlock = 202, + CaseBlock = 204, >CaseBlock : SyntaxKind - ImportEqualsDeclaration = 203, + ImportEqualsDeclaration = 205, >ImportEqualsDeclaration : SyntaxKind - ImportDeclaration = 204, + ImportDeclaration = 206, >ImportDeclaration : SyntaxKind - ImportClause = 205, + ImportClause = 207, >ImportClause : SyntaxKind - NamespaceImport = 206, + NamespaceImport = 208, >NamespaceImport : SyntaxKind - NamedImports = 207, + NamedImports = 209, >NamedImports : SyntaxKind - ImportSpecifier = 208, + ImportSpecifier = 210, >ImportSpecifier : SyntaxKind - ExportAssignment = 209, + ExportAssignment = 211, >ExportAssignment : SyntaxKind - ExportDeclaration = 210, + ExportDeclaration = 212, >ExportDeclaration : SyntaxKind - NamedExports = 211, + NamedExports = 213, >NamedExports : SyntaxKind - ExportSpecifier = 212, + ExportSpecifier = 214, >ExportSpecifier : SyntaxKind - ExternalModuleReference = 213, + MissingDeclaration = 215, +>MissingDeclaration : SyntaxKind + + ExternalModuleReference = 216, >ExternalModuleReference : SyntaxKind - CaseClause = 214, + CaseClause = 217, >CaseClause : SyntaxKind - DefaultClause = 215, + DefaultClause = 218, >DefaultClause : SyntaxKind - HeritageClause = 216, + HeritageClause = 219, >HeritageClause : SyntaxKind - CatchClause = 217, + CatchClause = 220, >CatchClause : SyntaxKind - PropertyAssignment = 218, + PropertyAssignment = 221, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 219, + ShorthandPropertyAssignment = 222, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 220, + EnumMember = 223, >EnumMember : SyntaxKind - SourceFile = 221, + SourceFile = 224, >SourceFile : SyntaxKind - SyntaxList = 222, + SyntaxList = 225, >SyntaxList : SyntaxKind - Count = 223, + Count = 226, >Count : SyntaxKind - FirstAssignment = 52, + FirstAssignment = 53, >FirstAssignment : SyntaxKind - LastAssignment = 63, + LastAssignment = 64, >LastAssignment : SyntaxKind - FirstReservedWord = 65, + FirstReservedWord = 66, >FirstReservedWord : SyntaxKind - LastReservedWord = 100, + LastReservedWord = 101, >LastReservedWord : SyntaxKind - FirstKeyword = 65, + FirstKeyword = 66, >FirstKeyword : SyntaxKind - LastKeyword = 124, + LastKeyword = 125, >LastKeyword : SyntaxKind - FirstFutureReservedWord = 102, + FirstFutureReservedWord = 103, >FirstFutureReservedWord : SyntaxKind - LastFutureReservedWord = 110, + LastFutureReservedWord = 111, >LastFutureReservedWord : SyntaxKind - FirstTypeNode = 139, + FirstTypeNode = 141, >FirstTypeNode : SyntaxKind - LastTypeNode = 147, + LastTypeNode = 149, >LastTypeNode : SyntaxKind FirstPunctuation = 14, >FirstPunctuation : SyntaxKind - LastPunctuation = 63, + LastPunctuation = 64, >LastPunctuation : SyntaxKind FirstToken = 0, >FirstToken : SyntaxKind - LastToken = 124, + LastToken = 125, >LastToken : SyntaxKind FirstTriviaToken = 2, @@ -1199,10 +1208,10 @@ declare module "typescript" { FirstBinaryOperator = 24, >FirstBinaryOperator : SyntaxKind - LastBinaryOperator = 63, + LastBinaryOperator = 64, >LastBinaryOperator : SyntaxKind - FirstNode = 125, + FirstNode = 126, >FirstNode : SyntaxKind } const enum NodeFlags { @@ -1274,16 +1283,19 @@ declare module "typescript" { GeneratorParameter = 8, >GeneratorParameter : ParserContextFlags - ThisNodeHasError = 16, + Decorator = 16, +>Decorator : ParserContextFlags + + ThisNodeHasError = 32, >ThisNodeHasError : ParserContextFlags - ParserGeneratedFlags = 31, + ParserGeneratedFlags = 63, >ParserGeneratedFlags : ParserContextFlags - ThisNodeOrAnySubNodesHasError = 32, + ThisNodeOrAnySubNodesHasError = 64, >ThisNodeOrAnySubNodesHasError : ParserContextFlags - HasAggregatedChildData = 64, + HasAggregatedChildData = 128, >HasAggregatedChildData : ParserContextFlags } const enum RelationComparisonResult { @@ -1314,6 +1326,11 @@ declare module "typescript" { >parserContextFlags : ParserContextFlags >ParserContextFlags : ParserContextFlags + decorators?: NodeArray; +>decorators : NodeArray +>NodeArray : NodeArray +>Decorator : Decorator + modifiers?: ModifiersArray; >modifiers : ModifiersArray >ModifiersArray : ModifiersArray @@ -1408,6 +1425,14 @@ declare module "typescript" { expression: Expression; >expression : Expression >Expression : Expression + } + interface Decorator extends Node { +>Decorator : Decorator +>Node : Node + + expression: LeftHandSideExpression; +>expression : LeftHandSideExpression +>LeftHandSideExpression : LeftHandSideExpression } interface TypeParameterDeclaration extends Declaration { >TypeParameterDeclaration : TypeParameterDeclaration @@ -1940,6 +1965,15 @@ declare module "typescript" { >body : Expression | Block >Block : Block >Expression : Expression + } + interface ArrowFunction extends Expression, FunctionLikeDeclaration { +>ArrowFunction : ArrowFunction +>Expression : Expression +>FunctionLikeDeclaration : FunctionLikeDeclaration + + equalsGreaterThanToken: Node; +>equalsGreaterThanToken : Node +>Node : Node } interface LiteralExpression extends PrimaryExpression { >LiteralExpression : LiteralExpression @@ -2596,9 +2630,13 @@ declare module "typescript" { isExportEquals?: boolean; >isExportEquals : boolean - expression: Expression; + expression?: Expression; >expression : Expression >Expression : Expression + + type?: TypeNode; +>type : TypeNode +>TypeNode : TypeNode } interface FileReference extends TextRange { >FileReference : FileReference @@ -2699,14 +2737,14 @@ declare module "typescript" { >SourceFile : SourceFile /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then - * the javascript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the javascript and declaration for that + * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then + * the JavaScript and declaration files will be produced for all the files in this program. + * If targetSourceFile is specified, then only the JavaScript and declaration for that * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the javascript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; >emit : (targetSourceFile?: SourceFile, writeFile?: WriteFileCallback) => EmitResult @@ -3229,6 +3267,11 @@ declare module "typescript" { CannotBeNamed = 2, >CannotBeNamed : SymbolAccessibility } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration +>ImportDeclaration : ImportDeclaration +>ImportEqualsDeclaration : ImportEqualsDeclaration + interface SymbolVisibilityResult { >SymbolVisibilityResult : SymbolVisibilityResult @@ -3236,9 +3279,9 @@ declare module "typescript" { >accessibility : SymbolAccessibility >SymbolAccessibility : SymbolAccessibility - aliasesToMakeVisible?: ImportEqualsDeclaration[]; ->aliasesToMakeVisible : ImportEqualsDeclaration[] ->ImportEqualsDeclaration : ImportEqualsDeclaration + aliasesToMakeVisible?: AnyImportSyntax[]; +>aliasesToMakeVisible : (ImportEqualsDeclaration | ImportDeclaration)[] +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration errorSymbolName?: string; >errorSymbolName : string @@ -3257,25 +3300,28 @@ declare module "typescript" { interface EmitResolver { >EmitResolver : EmitResolver - getGeneratedNameForNode(node: Node): string; ->getGeneratedNameForNode : (node: Node) => string ->node : Node ->Node : Node + hasGlobalName(name: string): boolean; +>hasGlobalName : (name: string) => boolean +>name : string - getExpressionNameSubstitution(node: Identifier): string; ->getExpressionNameSubstitution : (node: Identifier) => string + getExpressionNameSubstitution(node: Identifier, getGeneratedNameForNode: (node: Node) => string): string; +>getExpressionNameSubstitution : (node: Identifier, getGeneratedNameForNode: (node: Node) => string) => string >node : Identifier >Identifier : Identifier +>getGeneratedNameForNode : (node: Node) => string +>node : Node +>Node : Node isValueAliasDeclaration(node: Node): boolean; >isValueAliasDeclaration : (node: Node) => boolean >node : Node >Node : Node - isReferencedAliasDeclaration(node: Node): boolean; ->isReferencedAliasDeclaration : (node: Node) => boolean + isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean; +>isReferencedAliasDeclaration : (node: Node, checkChildren?: boolean) => boolean >node : Node >Node : Node +>checkChildren : boolean isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; >isTopLevelValueImportEqualsWithEntityName : (node: ImportEqualsDeclaration) => boolean @@ -3293,6 +3339,12 @@ declare module "typescript" { >node : Declaration >Declaration : Declaration + collectLinkedAliases(node: Identifier): Node[]; +>collectLinkedAliases : (node: Identifier) => Node[] +>node : Identifier +>Identifier : Identifier +>Node : Node + isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; >isImplementationOfOverload : (node: FunctionLikeDeclaration) => boolean >node : FunctionLikeDeclaration @@ -3319,6 +3371,17 @@ declare module "typescript" { >flags : TypeFormatFlags >TypeFormatFlags : TypeFormatFlags >writer : SymbolWriter +>SymbolWriter : SymbolWriter + + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; +>writeTypeOfExpression : (expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) => void +>expr : Expression +>Expression : Expression +>enclosingDeclaration : Node +>Node : Node +>flags : TypeFormatFlags +>TypeFormatFlags : TypeFormatFlags +>writer : SymbolWriter >SymbolWriter : SymbolWriter isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; @@ -3346,8 +3409,8 @@ declare module "typescript" { >PropertyAccessExpression : PropertyAccessExpression >ElementAccessExpression : ElementAccessExpression - isUnknownIdentifier(location: Node, name: string): boolean; ->isUnknownIdentifier : (location: Node, name: string) => boolean + resolvesToSomeValue(location: Node, name: string): boolean; +>resolvesToSomeValue : (location: Node, name: string) => boolean >location : Node >Node : Node >name : string @@ -3669,6 +3732,9 @@ declare module "typescript" { BlockScopedBindingInLoop = 256, >BlockScopedBindingInLoop : NodeCheckFlags + + EmitDecorate = 512, +>EmitDecorate : NodeCheckFlags } interface NodeLinks { >NodeLinks : NodeLinks @@ -4028,38 +4094,6 @@ declare module "typescript" { >t : Type >Type : Type >Type : Type - } - interface TypeInferences { ->TypeInferences : TypeInferences - - primary: Type[]; ->primary : Type[] ->Type : Type - - secondary: Type[]; ->secondary : Type[] ->Type : Type - } - interface InferenceContext { ->InferenceContext : InferenceContext - - typeParameters: TypeParameter[]; ->typeParameters : TypeParameter[] ->TypeParameter : TypeParameter - - inferUnionTypes: boolean; ->inferUnionTypes : boolean - - inferences: TypeInferences[]; ->inferences : TypeInferences[] ->TypeInferences : TypeInferences - - inferredTypes: Type[]; ->inferredTypes : Type[] ->Type : Type - - failedTypeParameterIndex?: number; ->failedTypeParameterIndex : number } interface DiagnosticMessage { >DiagnosticMessage : DiagnosticMessage @@ -5005,10 +5039,15 @@ declare module "typescript" { let version: string; >version : string - function createCompilerHost(options: CompilerOptions): CompilerHost; ->createCompilerHost : (options: CompilerOptions) => CompilerHost + function findConfigFile(searchPath: string): string; +>findConfigFile : (searchPath: string) => string +>searchPath : string + + function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; +>createCompilerHost : (options: CompilerOptions, setParentNodes?: boolean) => CompilerHost >options : CompilerOptions >CompilerOptions : CompilerOptions +>setParentNodes : boolean >CompilerHost : CompilerHost function getPreEmitDiagnostics(program: Program): Diagnostic[]; @@ -5422,6 +5461,12 @@ declare module "typescript" { >position : number >ReferenceEntry : ReferenceEntry + findReferences(fileName: string, position: number): ReferencedSymbol[]; +>findReferences : (fileName: string, position: number) => ReferencedSymbol[] +>fileName : string +>position : number +>ReferencedSymbol : ReferencedSymbol + getNavigateToItems(searchValue: string, maxResultCount?: number): NavigateToItem[]; >getNavigateToItems : (searchValue: string, maxResultCount?: number) => NavigateToItem[] >searchValue : string @@ -5692,6 +5737,17 @@ declare module "typescript" { containerName: string; >containerName : string + } + interface ReferencedSymbol { +>ReferencedSymbol : ReferencedSymbol + + definition: DefinitionInfo; +>definition : DefinitionInfo +>DefinitionInfo : DefinitionInfo + + references: ReferenceEntry[]; +>references : ReferenceEntry[] +>ReferenceEntry : ReferenceEntry } enum SymbolDisplayPartKind { >SymbolDisplayPartKind : SymbolDisplayPartKind diff --git a/tests/baselines/reference/ES5For-of15.js b/tests/baselines/reference/ES5For-of15.js index 46d3dbd1d6e3e..5a1b8327107c7 100644 --- a/tests/baselines/reference/ES5For-of15.js +++ b/tests/baselines/reference/ES5For-of15.js @@ -11,7 +11,7 @@ for (var _i = 0, _a = []; _i < _a.length; _i++) { var v = _a[_i]; v; for (var _b = 0, _c = []; _b < _c.length; _b++) { - var _v = _c[_b]; - var x = _v; + var v_1 = _c[_b]; + var x = v_1; } } diff --git a/tests/baselines/reference/ES5For-of16.js b/tests/baselines/reference/ES5For-of16.js index 1649e4481f27d..88f2c39414aa4 100644 --- a/tests/baselines/reference/ES5For-of16.js +++ b/tests/baselines/reference/ES5For-of16.js @@ -12,8 +12,8 @@ for (var _i = 0, _a = []; _i < _a.length; _i++) { var v = _a[_i]; v; for (var _b = 0, _c = []; _b < _c.length; _b++) { - var _v = _c[_b]; - var x = _v; - _v++; + var v_1 = _c[_b]; + var x = v_1; + v_1++; } } diff --git a/tests/baselines/reference/ES5For-of17.js b/tests/baselines/reference/ES5For-of17.js index b728074ae939d..4752f1be90f30 100644 --- a/tests/baselines/reference/ES5For-of17.js +++ b/tests/baselines/reference/ES5For-of17.js @@ -14,8 +14,8 @@ for (var _i = 0, _a = []; _i < _a.length; _i++) { for (var _b = 0, _c = [ v ]; _b < _c.length; _b++) { - var _v = _c[_b]; - var x = _v; - _v++; + var v_1 = _c[_b]; + var x = v_1; + v_1++; } } diff --git a/tests/baselines/reference/ES5For-of18.js b/tests/baselines/reference/ES5For-of18.js index a135b8b04639e..0d4809ed72d06 100644 --- a/tests/baselines/reference/ES5For-of18.js +++ b/tests/baselines/reference/ES5For-of18.js @@ -13,6 +13,6 @@ for (var _i = 0, _a = []; _i < _a.length; _i++) { v; } for (var _b = 0, _c = []; _b < _c.length; _b++) { - var _v = _c[_b]; - _v; + var v = _c[_b]; + v; } diff --git a/tests/baselines/reference/ES5For-of19.js b/tests/baselines/reference/ES5For-of19.js index 7af9418f04f69..2714574ab5bc8 100644 --- a/tests/baselines/reference/ES5For-of19.js +++ b/tests/baselines/reference/ES5For-of19.js @@ -14,9 +14,9 @@ for (var _i = 0, _a = []; _i < _a.length; _i++) { var v = _a[_i]; v; function foo() { - for (var _b = 0, _c = []; _b < _c.length; _b++) { - var _v = _c[_b]; - _v; + for (var _i = 0, _a = []; _i < _a.length; _i++) { + var v_1 = _a[_i]; + v_1; } } } diff --git a/tests/baselines/reference/ES5For-of20.js b/tests/baselines/reference/ES5For-of20.js index 3dd707805d8bc..d3f44e4922a1e 100644 --- a/tests/baselines/reference/ES5For-of20.js +++ b/tests/baselines/reference/ES5For-of20.js @@ -9,11 +9,11 @@ for (let v of []) { //// [ES5For-of20.js] for (var _i = 0, _a = []; _i < _a.length; _i++) { var v = _a[_i]; - var _v; + var v_1; for (var _b = 0, _c = [ v ]; _b < _c.length; _b++) { - var _v_1 = _c[_b]; - var _v_2; + var v_2 = _c[_b]; + var v_3; } } diff --git a/tests/baselines/reference/ES5For-of24.js b/tests/baselines/reference/ES5For-of24.js index 418ccc2005c47..00cd24ea28062 100644 --- a/tests/baselines/reference/ES5For-of24.js +++ b/tests/baselines/reference/ES5For-of24.js @@ -12,5 +12,5 @@ var a = [ ]; for (var _i = 0; _i < a.length; _i++) { var v = a[_i]; - var _a = 0; + var a_1 = 0; } diff --git a/tests/baselines/reference/ES5For-ofTypeCheck10.errors.txt b/tests/baselines/reference/ES5For-ofTypeCheck10.errors.txt index 9551d0467e9ba..b762db8a04b4b 100644 --- a/tests/baselines/reference/ES5For-ofTypeCheck10.errors.txt +++ b/tests/baselines/reference/ES5For-ofTypeCheck10.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck10.ts(1,15): error TS2461: Type 'StringIterator' is not an array type or a string type. +tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck10.ts(1,15): error TS2495: Type 'StringIterator' is not an array type or a string type. tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck10.ts(11,6): error TS2304: Cannot find name 'Symbol'. ==== tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck10.ts (2 errors) ==== for (var v of new StringIterator) { } ~~~~~~~~~~~~~~~~~~ -!!! error TS2461: Type 'StringIterator' is not an array type or a string type. +!!! error TS2495: Type 'StringIterator' is not an array type or a string type. // In ES3/5, you cannot for...of over an arbitrary iterable. class StringIterator { diff --git a/tests/baselines/reference/ES5For-ofTypeCheck12.errors.txt b/tests/baselines/reference/ES5For-ofTypeCheck12.errors.txt index b726aaad6c7c5..67af1f4f40116 100644 --- a/tests/baselines/reference/ES5For-ofTypeCheck12.errors.txt +++ b/tests/baselines/reference/ES5For-ofTypeCheck12.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck12.ts(1,17): error TS2461: Type 'number' is not an array type or a string type. +tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck12.ts(1,17): error TS2495: Type 'number' is not an array type or a string type. ==== tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck12.ts (1 errors) ==== for (const v of 0) { } ~ -!!! error TS2461: Type 'number' is not an array type or a string type. \ No newline at end of file +!!! error TS2495: Type 'number' is not an array type or a string type. \ No newline at end of file diff --git a/tests/baselines/reference/EnumAndModuleWithSameNameAndCommonRoot.js b/tests/baselines/reference/EnumAndModuleWithSameNameAndCommonRoot.js index d9fdb511fa213..4ca0b4cd5f740 100644 --- a/tests/baselines/reference/EnumAndModuleWithSameNameAndCommonRoot.js +++ b/tests/baselines/reference/EnumAndModuleWithSameNameAndCommonRoot.js @@ -34,6 +34,6 @@ var enumdule; enumdule.Point = Point; })(enumdule || (enumdule = {})); var x; -var x = 0 /* Red */; +var x = enumdule.Red; var y; var y = new enumdule.Point(0, 0); diff --git a/tests/baselines/reference/ModuleAndEnumWithSameNameAndCommonRoot.js b/tests/baselines/reference/ModuleAndEnumWithSameNameAndCommonRoot.js index 533843d294732..96df9812bc638 100644 --- a/tests/baselines/reference/ModuleAndEnumWithSameNameAndCommonRoot.js +++ b/tests/baselines/reference/ModuleAndEnumWithSameNameAndCommonRoot.js @@ -34,6 +34,6 @@ var enumdule; enumdule[enumdule["Blue"] = 1] = "Blue"; })(enumdule || (enumdule = {})); var x; -var x = 0 /* Red */; +var x = enumdule.Red; var y; var y = new enumdule.Point(0, 0); diff --git a/tests/baselines/reference/ModuleWithExportedAndNonExportedClasses.js b/tests/baselines/reference/ModuleWithExportedAndNonExportedClasses.js index 7555ae217e575..06e5427a87958 100644 --- a/tests/baselines/reference/ModuleWithExportedAndNonExportedClasses.js +++ b/tests/baselines/reference/ModuleWithExportedAndNonExportedClasses.js @@ -35,19 +35,19 @@ var ag2 = new A.A2(); //// [ModuleWithExportedAndNonExportedClasses.js] var A; -(function (_A) { +(function (A_1) { var A = (function () { function A() { } return A; })(); - _A.A = A; + A_1.A = A; var AG = (function () { function AG() { } return AG; })(); - _A.AG = AG; + A_1.AG = AG; var A2 = (function () { function A2() { } diff --git a/tests/baselines/reference/ModuleWithExportedAndNonExportedEnums.js b/tests/baselines/reference/ModuleWithExportedAndNonExportedEnums.js index afcef6bbb5c3c..3cd522d3c2c2f 100644 --- a/tests/baselines/reference/ModuleWithExportedAndNonExportedEnums.js +++ b/tests/baselines/reference/ModuleWithExportedAndNonExportedEnums.js @@ -26,6 +26,6 @@ var A; })(Day || (Day = {})); })(A || (A = {})); // not an error since exported -var a = 0 /* Red */; +var a = A.Color.Red; // error not exported var b = A.Day.Monday; diff --git a/tests/baselines/reference/additionOperatorWithAnyAndEveryType.js b/tests/baselines/reference/additionOperatorWithAnyAndEveryType.js index ca3e8435e0570..d68af6c23c3b6 100644 --- a/tests/baselines/reference/additionOperatorWithAnyAndEveryType.js +++ b/tests/baselines/reference/additionOperatorWithAnyAndEveryType.js @@ -81,7 +81,7 @@ var r11 = a + foo(); var r12 = a + C; var r13 = a + new C(); var r14 = a + E; -var r15 = a + 0 /* a */; +var r15 = a + E.a; var r16 = a + M; var r17 = a + ''; var r18 = a + 123; diff --git a/tests/baselines/reference/additionOperatorWithInvalidOperands.js b/tests/baselines/reference/additionOperatorWithInvalidOperands.js index baf4fadedb30e..f2403bc16708f 100644 --- a/tests/baselines/reference/additionOperatorWithInvalidOperands.js +++ b/tests/baselines/reference/additionOperatorWithInvalidOperands.js @@ -85,6 +85,6 @@ var r14 = b + d; var r15 = b + foo; var r16 = b + foo(); var r17 = b + C; -var r18 = 0 /* a */ + new C(); -var r19 = 0 /* a */ + C.foo(); -var r20 = 0 /* a */ + M; +var r18 = E.a + new C(); +var r19 = E.a + C.foo(); +var r20 = E.a + M; diff --git a/tests/baselines/reference/additionOperatorWithNullValueAndValidOperator.js b/tests/baselines/reference/additionOperatorWithNullValueAndValidOperator.js index 1ba54d47f1cb3..1b5cb877d21bc 100644 --- a/tests/baselines/reference/additionOperatorWithNullValueAndValidOperator.js +++ b/tests/baselines/reference/additionOperatorWithNullValueAndValidOperator.js @@ -49,13 +49,13 @@ var r2 = a + null; var r3 = null + b; var r4 = null + 1; var r5 = null + c; -var r6 = null + 0 /* a */; -var r7 = null + 0 /* 'a' */; +var r6 = null + E.a; +var r7 = null + E['a']; var r8 = b + null; var r9 = 1 + null; var r10 = c + null; -var r11 = 0 /* a */ + null; -var r12 = 0 /* 'a' */ + null; +var r11 = E.a + null; +var r12 = E['a'] + null; // null + string var r13 = null + d; var r14 = null + ''; diff --git a/tests/baselines/reference/additionOperatorWithNumberAndEnum.js b/tests/baselines/reference/additionOperatorWithNumberAndEnum.js index 231831518e6c7..d559e98dc3eff 100644 --- a/tests/baselines/reference/additionOperatorWithNumberAndEnum.js +++ b/tests/baselines/reference/additionOperatorWithNumberAndEnum.js @@ -43,10 +43,10 @@ var r2 = a + b; var r3 = b + a; var r4 = b + b; var r5 = 0 + a; -var r6 = 0 /* a */ + 0; -var r7 = 0 /* a */ + 1 /* b */; -var r8 = 0 /* 'a' */ + 1 /* 'b' */; -var r9 = 0 /* 'a' */ + 0 /* 'c' */; +var r6 = E.a + 0; +var r7 = E.a + E.b; +var r8 = E['a'] + E['b']; +var r9 = E['a'] + F['c']; var r10 = a + c; var r11 = c + a; var r12 = b + c; diff --git a/tests/baselines/reference/additionOperatorWithStringAndEveryType.js b/tests/baselines/reference/additionOperatorWithStringAndEveryType.js index 35c6056574e73..56949533e0922 100644 --- a/tests/baselines/reference/additionOperatorWithStringAndEveryType.js +++ b/tests/baselines/reference/additionOperatorWithStringAndEveryType.js @@ -72,7 +72,7 @@ var r13 = f + x; var r14 = g + x; // other cases var r15 = x + E; -var r16 = x + 0 /* a */; +var r16 = x + E.a; var r17 = x + ''; var r18 = x + 0; var r19 = x + { diff --git a/tests/baselines/reference/additionOperatorWithUndefinedValueAndValidOperator.js b/tests/baselines/reference/additionOperatorWithUndefinedValueAndValidOperator.js index cb89d242a18a6..68804694449e1 100644 --- a/tests/baselines/reference/additionOperatorWithUndefinedValueAndValidOperator.js +++ b/tests/baselines/reference/additionOperatorWithUndefinedValueAndValidOperator.js @@ -49,13 +49,13 @@ var r2 = a + undefined; var r3 = undefined + b; var r4 = undefined + 1; var r5 = undefined + c; -var r6 = undefined + 0 /* a */; -var r7 = undefined + 0 /* 'a' */; +var r6 = undefined + E.a; +var r7 = undefined + E['a']; var r8 = b + undefined; var r9 = 1 + undefined; var r10 = c + undefined; -var r11 = 0 /* a */ + undefined; -var r12 = 0 /* 'a' */ + undefined; +var r11 = E.a + undefined; +var r12 = E['a'] + undefined; // undefined + string var r13 = undefined + d; var r14 = undefined + ''; diff --git a/tests/baselines/reference/amdImportAsPrimaryExpression.js b/tests/baselines/reference/amdImportAsPrimaryExpression.js index 4704b32d9891c..fc8d0420842e7 100644 --- a/tests/baselines/reference/amdImportAsPrimaryExpression.js +++ b/tests/baselines/reference/amdImportAsPrimaryExpression.js @@ -23,6 +23,6 @@ define(["require", "exports"], function (require, exports) { }); //// [foo_1.js] define(["require", "exports", "./foo_0"], function (require, exports, foo) { - if (0 /* A */ === 0) { + if (foo.E1.A === 0) { } }); diff --git a/tests/baselines/reference/arithmeticOperatorWithEnum.js b/tests/baselines/reference/arithmeticOperatorWithEnum.js index 9ef2790b4cef1..3572f3ecc41e4 100644 --- a/tests/baselines/reference/arithmeticOperatorWithEnum.js +++ b/tests/baselines/reference/arithmeticOperatorWithEnum.js @@ -166,127 +166,127 @@ var ra2 = c * b; var ra3 = c * c; var ra4 = a * c; var ra5 = b * c; -var ra6 = 0 /* a */ * a; -var ra7 = 0 /* a */ * b; -var ra8 = 0 /* a */ * 1 /* b */; -var ra9 = 0 /* a */ * 1; -var ra10 = a * 1 /* b */; -var ra11 = b * 1 /* b */; -var ra12 = 1 * 1 /* b */; +var ra6 = E.a * a; +var ra7 = E.a * b; +var ra8 = E.a * E.b; +var ra9 = E.a * 1; +var ra10 = a * E.b; +var ra11 = b * E.b; +var ra12 = 1 * E.b; // operator / var rb1 = c / a; var rb2 = c / b; var rb3 = c / c; var rb4 = a / c; var rb5 = b / c; -var rb6 = 0 /* a */ / a; -var rb7 = 0 /* a */ / b; -var rb8 = 0 /* a */ / 1 /* b */; -var rb9 = 0 /* a */ / 1; -var rb10 = a / 1 /* b */; -var rb11 = b / 1 /* b */; -var rb12 = 1 / 1 /* b */; +var rb6 = E.a / a; +var rb7 = E.a / b; +var rb8 = E.a / E.b; +var rb9 = E.a / 1; +var rb10 = a / E.b; +var rb11 = b / E.b; +var rb12 = 1 / E.b; // operator % var rc1 = c % a; var rc2 = c % b; var rc3 = c % c; var rc4 = a % c; var rc5 = b % c; -var rc6 = 0 /* a */ % a; -var rc7 = 0 /* a */ % b; -var rc8 = 0 /* a */ % 1 /* b */; -var rc9 = 0 /* a */ % 1; -var rc10 = a % 1 /* b */; -var rc11 = b % 1 /* b */; -var rc12 = 1 % 1 /* b */; +var rc6 = E.a % a; +var rc7 = E.a % b; +var rc8 = E.a % E.b; +var rc9 = E.a % 1; +var rc10 = a % E.b; +var rc11 = b % E.b; +var rc12 = 1 % E.b; // operator - var rd1 = c - a; var rd2 = c - b; var rd3 = c - c; var rd4 = a - c; var rd5 = b - c; -var rd6 = 0 /* a */ - a; -var rd7 = 0 /* a */ - b; -var rd8 = 0 /* a */ - 1 /* b */; -var rd9 = 0 /* a */ - 1; -var rd10 = a - 1 /* b */; -var rd11 = b - 1 /* b */; -var rd12 = 1 - 1 /* b */; +var rd6 = E.a - a; +var rd7 = E.a - b; +var rd8 = E.a - E.b; +var rd9 = E.a - 1; +var rd10 = a - E.b; +var rd11 = b - E.b; +var rd12 = 1 - E.b; // operator << var re1 = c << a; var re2 = c << b; var re3 = c << c; var re4 = a << c; var re5 = b << c; -var re6 = 0 /* a */ << a; -var re7 = 0 /* a */ << b; -var re8 = 0 /* a */ << 1 /* b */; -var re9 = 0 /* a */ << 1; -var re10 = a << 1 /* b */; -var re11 = b << 1 /* b */; -var re12 = 1 << 1 /* b */; +var re6 = E.a << a; +var re7 = E.a << b; +var re8 = E.a << E.b; +var re9 = E.a << 1; +var re10 = a << E.b; +var re11 = b << E.b; +var re12 = 1 << E.b; // operator >> var rf1 = c >> a; var rf2 = c >> b; var rf3 = c >> c; var rf4 = a >> c; var rf5 = b >> c; -var rf6 = 0 /* a */ >> a; -var rf7 = 0 /* a */ >> b; -var rf8 = 0 /* a */ >> 1 /* b */; -var rf9 = 0 /* a */ >> 1; -var rf10 = a >> 1 /* b */; -var rf11 = b >> 1 /* b */; -var rf12 = 1 >> 1 /* b */; +var rf6 = E.a >> a; +var rf7 = E.a >> b; +var rf8 = E.a >> E.b; +var rf9 = E.a >> 1; +var rf10 = a >> E.b; +var rf11 = b >> E.b; +var rf12 = 1 >> E.b; // operator >>> var rg1 = c >>> a; var rg2 = c >>> b; var rg3 = c >>> c; var rg4 = a >>> c; var rg5 = b >>> c; -var rg6 = 0 /* a */ >>> a; -var rg7 = 0 /* a */ >>> b; -var rg8 = 0 /* a */ >>> 1 /* b */; -var rg9 = 0 /* a */ >>> 1; -var rg10 = a >>> 1 /* b */; -var rg11 = b >>> 1 /* b */; -var rg12 = 1 >>> 1 /* b */; +var rg6 = E.a >>> a; +var rg7 = E.a >>> b; +var rg8 = E.a >>> E.b; +var rg9 = E.a >>> 1; +var rg10 = a >>> E.b; +var rg11 = b >>> E.b; +var rg12 = 1 >>> E.b; // operator & var rh1 = c & a; var rh2 = c & b; var rh3 = c & c; var rh4 = a & c; var rh5 = b & c; -var rh6 = 0 /* a */ & a; -var rh7 = 0 /* a */ & b; -var rh8 = 0 /* a */ & 1 /* b */; -var rh9 = 0 /* a */ & 1; -var rh10 = a & 1 /* b */; -var rh11 = b & 1 /* b */; -var rh12 = 1 & 1 /* b */; +var rh6 = E.a & a; +var rh7 = E.a & b; +var rh8 = E.a & E.b; +var rh9 = E.a & 1; +var rh10 = a & E.b; +var rh11 = b & E.b; +var rh12 = 1 & E.b; // operator ^ var ri1 = c ^ a; var ri2 = c ^ b; var ri3 = c ^ c; var ri4 = a ^ c; var ri5 = b ^ c; -var ri6 = 0 /* a */ ^ a; -var ri7 = 0 /* a */ ^ b; -var ri8 = 0 /* a */ ^ 1 /* b */; -var ri9 = 0 /* a */ ^ 1; -var ri10 = a ^ 1 /* b */; -var ri11 = b ^ 1 /* b */; -var ri12 = 1 ^ 1 /* b */; +var ri6 = E.a ^ a; +var ri7 = E.a ^ b; +var ri8 = E.a ^ E.b; +var ri9 = E.a ^ 1; +var ri10 = a ^ E.b; +var ri11 = b ^ E.b; +var ri12 = 1 ^ E.b; // operator | var rj1 = c | a; var rj2 = c | b; var rj3 = c | c; var rj4 = a | c; var rj5 = b | c; -var rj6 = 0 /* a */ | a; -var rj7 = 0 /* a */ | b; -var rj8 = 0 /* a */ | 1 /* b */; -var rj9 = 0 /* a */ | 1; -var rj10 = a | 1 /* b */; -var rj11 = b | 1 /* b */; -var rj12 = 1 | 1 /* b */; +var rj6 = E.a | a; +var rj7 = E.a | b; +var rj8 = E.a | E.b; +var rj9 = E.a | 1; +var rj10 = a | E.b; +var rj11 = b | E.b; +var rj12 = 1 | E.b; diff --git a/tests/baselines/reference/arithmeticOperatorWithEnumUnion.js b/tests/baselines/reference/arithmeticOperatorWithEnumUnion.js index 315f7dd237b7f..95bc0b866c91c 100644 --- a/tests/baselines/reference/arithmeticOperatorWithEnumUnion.js +++ b/tests/baselines/reference/arithmeticOperatorWithEnumUnion.js @@ -175,127 +175,127 @@ var ra2 = c * b; var ra3 = c * c; var ra4 = a * c; var ra5 = b * c; -var ra6 = 0 /* a */ * a; -var ra7 = 0 /* a */ * b; -var ra8 = 0 /* a */ * 1 /* b */; -var ra9 = 0 /* a */ * 1; -var ra10 = a * 1 /* b */; -var ra11 = b * 1 /* b */; -var ra12 = 1 * 1 /* b */; +var ra6 = E.a * a; +var ra7 = E.a * b; +var ra8 = E.a * E.b; +var ra9 = E.a * 1; +var ra10 = a * E.b; +var ra11 = b * E.b; +var ra12 = 1 * E.b; // operator / var rb1 = c / a; var rb2 = c / b; var rb3 = c / c; var rb4 = a / c; var rb5 = b / c; -var rb6 = 0 /* a */ / a; -var rb7 = 0 /* a */ / b; -var rb8 = 0 /* a */ / 1 /* b */; -var rb9 = 0 /* a */ / 1; -var rb10 = a / 1 /* b */; -var rb11 = b / 1 /* b */; -var rb12 = 1 / 1 /* b */; +var rb6 = E.a / a; +var rb7 = E.a / b; +var rb8 = E.a / E.b; +var rb9 = E.a / 1; +var rb10 = a / E.b; +var rb11 = b / E.b; +var rb12 = 1 / E.b; // operator % var rc1 = c % a; var rc2 = c % b; var rc3 = c % c; var rc4 = a % c; var rc5 = b % c; -var rc6 = 0 /* a */ % a; -var rc7 = 0 /* a */ % b; -var rc8 = 0 /* a */ % 1 /* b */; -var rc9 = 0 /* a */ % 1; -var rc10 = a % 1 /* b */; -var rc11 = b % 1 /* b */; -var rc12 = 1 % 1 /* b */; +var rc6 = E.a % a; +var rc7 = E.a % b; +var rc8 = E.a % E.b; +var rc9 = E.a % 1; +var rc10 = a % E.b; +var rc11 = b % E.b; +var rc12 = 1 % E.b; // operator - var rd1 = c - a; var rd2 = c - b; var rd3 = c - c; var rd4 = a - c; var rd5 = b - c; -var rd6 = 0 /* a */ - a; -var rd7 = 0 /* a */ - b; -var rd8 = 0 /* a */ - 1 /* b */; -var rd9 = 0 /* a */ - 1; -var rd10 = a - 1 /* b */; -var rd11 = b - 1 /* b */; -var rd12 = 1 - 1 /* b */; +var rd6 = E.a - a; +var rd7 = E.a - b; +var rd8 = E.a - E.b; +var rd9 = E.a - 1; +var rd10 = a - E.b; +var rd11 = b - E.b; +var rd12 = 1 - E.b; // operator << var re1 = c << a; var re2 = c << b; var re3 = c << c; var re4 = a << c; var re5 = b << c; -var re6 = 0 /* a */ << a; -var re7 = 0 /* a */ << b; -var re8 = 0 /* a */ << 1 /* b */; -var re9 = 0 /* a */ << 1; -var re10 = a << 1 /* b */; -var re11 = b << 1 /* b */; -var re12 = 1 << 1 /* b */; +var re6 = E.a << a; +var re7 = E.a << b; +var re8 = E.a << E.b; +var re9 = E.a << 1; +var re10 = a << E.b; +var re11 = b << E.b; +var re12 = 1 << E.b; // operator >> var rf1 = c >> a; var rf2 = c >> b; var rf3 = c >> c; var rf4 = a >> c; var rf5 = b >> c; -var rf6 = 0 /* a */ >> a; -var rf7 = 0 /* a */ >> b; -var rf8 = 0 /* a */ >> 1 /* b */; -var rf9 = 0 /* a */ >> 1; -var rf10 = a >> 1 /* b */; -var rf11 = b >> 1 /* b */; -var rf12 = 1 >> 1 /* b */; +var rf6 = E.a >> a; +var rf7 = E.a >> b; +var rf8 = E.a >> E.b; +var rf9 = E.a >> 1; +var rf10 = a >> E.b; +var rf11 = b >> E.b; +var rf12 = 1 >> E.b; // operator >>> var rg1 = c >>> a; var rg2 = c >>> b; var rg3 = c >>> c; var rg4 = a >>> c; var rg5 = b >>> c; -var rg6 = 0 /* a */ >>> a; -var rg7 = 0 /* a */ >>> b; -var rg8 = 0 /* a */ >>> 1 /* b */; -var rg9 = 0 /* a */ >>> 1; -var rg10 = a >>> 1 /* b */; -var rg11 = b >>> 1 /* b */; -var rg12 = 1 >>> 1 /* b */; +var rg6 = E.a >>> a; +var rg7 = E.a >>> b; +var rg8 = E.a >>> E.b; +var rg9 = E.a >>> 1; +var rg10 = a >>> E.b; +var rg11 = b >>> E.b; +var rg12 = 1 >>> E.b; // operator & var rh1 = c & a; var rh2 = c & b; var rh3 = c & c; var rh4 = a & c; var rh5 = b & c; -var rh6 = 0 /* a */ & a; -var rh7 = 0 /* a */ & b; -var rh8 = 0 /* a */ & 1 /* b */; -var rh9 = 0 /* a */ & 1; -var rh10 = a & 1 /* b */; -var rh11 = b & 1 /* b */; -var rh12 = 1 & 1 /* b */; +var rh6 = E.a & a; +var rh7 = E.a & b; +var rh8 = E.a & E.b; +var rh9 = E.a & 1; +var rh10 = a & E.b; +var rh11 = b & E.b; +var rh12 = 1 & E.b; // operator ^ var ri1 = c ^ a; var ri2 = c ^ b; var ri3 = c ^ c; var ri4 = a ^ c; var ri5 = b ^ c; -var ri6 = 0 /* a */ ^ a; -var ri7 = 0 /* a */ ^ b; -var ri8 = 0 /* a */ ^ 1 /* b */; -var ri9 = 0 /* a */ ^ 1; -var ri10 = a ^ 1 /* b */; -var ri11 = b ^ 1 /* b */; -var ri12 = 1 ^ 1 /* b */; +var ri6 = E.a ^ a; +var ri7 = E.a ^ b; +var ri8 = E.a ^ E.b; +var ri9 = E.a ^ 1; +var ri10 = a ^ E.b; +var ri11 = b ^ E.b; +var ri12 = 1 ^ E.b; // operator | var rj1 = c | a; var rj2 = c | b; var rj3 = c | c; var rj4 = a | c; var rj5 = b | c; -var rj6 = 0 /* a */ | a; -var rj7 = 0 /* a */ | b; -var rj8 = 0 /* a */ | 1 /* b */; -var rj9 = 0 /* a */ | 1; -var rj10 = a | 1 /* b */; -var rj11 = b | 1 /* b */; -var rj12 = 1 | 1 /* b */; +var rj6 = E.a | a; +var rj7 = E.a | b; +var rj8 = E.a | E.b; +var rj9 = E.a | 1; +var rj10 = a | E.b; +var rj11 = b | E.b; +var rj12 = 1 | E.b; diff --git a/tests/baselines/reference/arithmeticOperatorWithInvalidOperands.js b/tests/baselines/reference/arithmeticOperatorWithInvalidOperands.js index 8a9e65491446b..974e9930103d7 100644 --- a/tests/baselines/reference/arithmeticOperatorWithInvalidOperands.js +++ b/tests/baselines/reference/arithmeticOperatorWithInvalidOperands.js @@ -634,18 +634,18 @@ var r1f3 = f * c; var r1f4 = f * d; var r1f5 = f * e; var r1f6 = f * f; -var r1g1 = 0 /* a */ * a; //ok -var r1g2 = 0 /* a */ * b; -var r1g3 = 0 /* a */ * c; //ok -var r1g4 = 0 /* a */ * d; -var r1g5 = 0 /* a */ * e; -var r1g6 = 0 /* a */ * f; -var r1h1 = a * 1 /* b */; //ok -var r1h2 = b * 1 /* b */; -var r1h3 = c * 1 /* b */; //ok -var r1h4 = d * 1 /* b */; -var r1h5 = e * 1 /* b */; -var r1h6 = f * 1 /* b */; +var r1g1 = E.a * a; //ok +var r1g2 = E.a * b; +var r1g3 = E.a * c; //ok +var r1g4 = E.a * d; +var r1g5 = E.a * e; +var r1g6 = E.a * f; +var r1h1 = a * E.b; //ok +var r1h2 = b * E.b; +var r1h3 = c * E.b; //ok +var r1h4 = d * E.b; +var r1h5 = e * E.b; +var r1h6 = f * E.b; // operator / var r2a1 = a / a; //ok var r2a2 = a / b; @@ -683,18 +683,18 @@ var r2f3 = f / c; var r2f4 = f / d; var r2f5 = f / e; var r2f6 = f / f; -var r2g1 = 0 /* a */ / a; //ok -var r2g2 = 0 /* a */ / b; -var r2g3 = 0 /* a */ / c; //ok -var r2g4 = 0 /* a */ / d; -var r2g5 = 0 /* a */ / e; -var r2g6 = 0 /* a */ / f; -var r2h1 = a / 1 /* b */; //ok -var r2h2 = b / 1 /* b */; -var r2h3 = c / 1 /* b */; //ok -var r2h4 = d / 1 /* b */; -var r2h5 = e / 1 /* b */; -var r2h6 = f / 1 /* b */; +var r2g1 = E.a / a; //ok +var r2g2 = E.a / b; +var r2g3 = E.a / c; //ok +var r2g4 = E.a / d; +var r2g5 = E.a / e; +var r2g6 = E.a / f; +var r2h1 = a / E.b; //ok +var r2h2 = b / E.b; +var r2h3 = c / E.b; //ok +var r2h4 = d / E.b; +var r2h5 = e / E.b; +var r2h6 = f / E.b; // operator % var r3a1 = a % a; //ok var r3a2 = a % b; @@ -732,18 +732,18 @@ var r3f3 = f % c; var r3f4 = f % d; var r3f5 = f % e; var r3f6 = f % f; -var r3g1 = 0 /* a */ % a; //ok -var r3g2 = 0 /* a */ % b; -var r3g3 = 0 /* a */ % c; //ok -var r3g4 = 0 /* a */ % d; -var r3g5 = 0 /* a */ % e; -var r3g6 = 0 /* a */ % f; -var r3h1 = a % 1 /* b */; //ok -var r3h2 = b % 1 /* b */; -var r3h3 = c % 1 /* b */; //ok -var r3h4 = d % 1 /* b */; -var r3h5 = e % 1 /* b */; -var r3h6 = f % 1 /* b */; +var r3g1 = E.a % a; //ok +var r3g2 = E.a % b; +var r3g3 = E.a % c; //ok +var r3g4 = E.a % d; +var r3g5 = E.a % e; +var r3g6 = E.a % f; +var r3h1 = a % E.b; //ok +var r3h2 = b % E.b; +var r3h3 = c % E.b; //ok +var r3h4 = d % E.b; +var r3h5 = e % E.b; +var r3h6 = f % E.b; // operator - var r4a1 = a - a; //ok var r4a2 = a - b; @@ -781,18 +781,18 @@ var r4f3 = f - c; var r4f4 = f - d; var r4f5 = f - e; var r4f6 = f - f; -var r4g1 = 0 /* a */ - a; //ok -var r4g2 = 0 /* a */ - b; -var r4g3 = 0 /* a */ - c; //ok -var r4g4 = 0 /* a */ - d; -var r4g5 = 0 /* a */ - e; -var r4g6 = 0 /* a */ - f; -var r4h1 = a - 1 /* b */; //ok -var r4h2 = b - 1 /* b */; -var r4h3 = c - 1 /* b */; //ok -var r4h4 = d - 1 /* b */; -var r4h5 = e - 1 /* b */; -var r4h6 = f - 1 /* b */; +var r4g1 = E.a - a; //ok +var r4g2 = E.a - b; +var r4g3 = E.a - c; //ok +var r4g4 = E.a - d; +var r4g5 = E.a - e; +var r4g6 = E.a - f; +var r4h1 = a - E.b; //ok +var r4h2 = b - E.b; +var r4h3 = c - E.b; //ok +var r4h4 = d - E.b; +var r4h5 = e - E.b; +var r4h6 = f - E.b; // operator << var r5a1 = a << a; //ok var r5a2 = a << b; @@ -830,18 +830,18 @@ var r5f3 = f << c; var r5f4 = f << d; var r5f5 = f << e; var r5f6 = f << f; -var r5g1 = 0 /* a */ << a; //ok -var r5g2 = 0 /* a */ << b; -var r5g3 = 0 /* a */ << c; //ok -var r5g4 = 0 /* a */ << d; -var r5g5 = 0 /* a */ << e; -var r5g6 = 0 /* a */ << f; -var r5h1 = a << 1 /* b */; //ok -var r5h2 = b << 1 /* b */; -var r5h3 = c << 1 /* b */; //ok -var r5h4 = d << 1 /* b */; -var r5h5 = e << 1 /* b */; -var r5h6 = f << 1 /* b */; +var r5g1 = E.a << a; //ok +var r5g2 = E.a << b; +var r5g3 = E.a << c; //ok +var r5g4 = E.a << d; +var r5g5 = E.a << e; +var r5g6 = E.a << f; +var r5h1 = a << E.b; //ok +var r5h2 = b << E.b; +var r5h3 = c << E.b; //ok +var r5h4 = d << E.b; +var r5h5 = e << E.b; +var r5h6 = f << E.b; // operator >> var r6a1 = a >> a; //ok var r6a2 = a >> b; @@ -879,18 +879,18 @@ var r6f3 = f >> c; var r6f4 = f >> d; var r6f5 = f >> e; var r6f6 = f >> f; -var r6g1 = 0 /* a */ >> a; //ok -var r6g2 = 0 /* a */ >> b; -var r6g3 = 0 /* a */ >> c; //ok -var r6g4 = 0 /* a */ >> d; -var r6g5 = 0 /* a */ >> e; -var r6g6 = 0 /* a */ >> f; -var r6h1 = a >> 1 /* b */; //ok -var r6h2 = b >> 1 /* b */; -var r6h3 = c >> 1 /* b */; //ok -var r6h4 = d >> 1 /* b */; -var r6h5 = e >> 1 /* b */; -var r6h6 = f >> 1 /* b */; +var r6g1 = E.a >> a; //ok +var r6g2 = E.a >> b; +var r6g3 = E.a >> c; //ok +var r6g4 = E.a >> d; +var r6g5 = E.a >> e; +var r6g6 = E.a >> f; +var r6h1 = a >> E.b; //ok +var r6h2 = b >> E.b; +var r6h3 = c >> E.b; //ok +var r6h4 = d >> E.b; +var r6h5 = e >> E.b; +var r6h6 = f >> E.b; // operator >>> var r7a1 = a >>> a; //ok var r7a2 = a >>> b; @@ -928,18 +928,18 @@ var r7f3 = f >>> c; var r7f4 = f >>> d; var r7f5 = f >>> e; var r7f6 = f >>> f; -var r7g1 = 0 /* a */ >>> a; //ok -var r7g2 = 0 /* a */ >>> b; -var r7g3 = 0 /* a */ >>> c; //ok -var r7g4 = 0 /* a */ >>> d; -var r7g5 = 0 /* a */ >>> e; -var r7g6 = 0 /* a */ >>> f; -var r7h1 = a >>> 1 /* b */; //ok -var r7h2 = b >>> 1 /* b */; -var r7h3 = c >>> 1 /* b */; //ok -var r7h4 = d >>> 1 /* b */; -var r7h5 = e >>> 1 /* b */; -var r7h6 = f >>> 1 /* b */; +var r7g1 = E.a >>> a; //ok +var r7g2 = E.a >>> b; +var r7g3 = E.a >>> c; //ok +var r7g4 = E.a >>> d; +var r7g5 = E.a >>> e; +var r7g6 = E.a >>> f; +var r7h1 = a >>> E.b; //ok +var r7h2 = b >>> E.b; +var r7h3 = c >>> E.b; //ok +var r7h4 = d >>> E.b; +var r7h5 = e >>> E.b; +var r7h6 = f >>> E.b; // operator & var r8a1 = a & a; //ok var r8a2 = a & b; @@ -977,18 +977,18 @@ var r8f3 = f & c; var r8f4 = f & d; var r8f5 = f & e; var r8f6 = f & f; -var r8g1 = 0 /* a */ & a; //ok -var r8g2 = 0 /* a */ & b; -var r8g3 = 0 /* a */ & c; //ok -var r8g4 = 0 /* a */ & d; -var r8g5 = 0 /* a */ & e; -var r8g6 = 0 /* a */ & f; -var r8h1 = a & 1 /* b */; //ok -var r8h2 = b & 1 /* b */; -var r8h3 = c & 1 /* b */; //ok -var r8h4 = d & 1 /* b */; -var r8h5 = e & 1 /* b */; -var r8h6 = f & 1 /* b */; +var r8g1 = E.a & a; //ok +var r8g2 = E.a & b; +var r8g3 = E.a & c; //ok +var r8g4 = E.a & d; +var r8g5 = E.a & e; +var r8g6 = E.a & f; +var r8h1 = a & E.b; //ok +var r8h2 = b & E.b; +var r8h3 = c & E.b; //ok +var r8h4 = d & E.b; +var r8h5 = e & E.b; +var r8h6 = f & E.b; // operator ^ var r9a1 = a ^ a; //ok var r9a2 = a ^ b; @@ -1026,18 +1026,18 @@ var r9f3 = f ^ c; var r9f4 = f ^ d; var r9f5 = f ^ e; var r9f6 = f ^ f; -var r9g1 = 0 /* a */ ^ a; //ok -var r9g2 = 0 /* a */ ^ b; -var r9g3 = 0 /* a */ ^ c; //ok -var r9g4 = 0 /* a */ ^ d; -var r9g5 = 0 /* a */ ^ e; -var r9g6 = 0 /* a */ ^ f; -var r9h1 = a ^ 1 /* b */; //ok -var r9h2 = b ^ 1 /* b */; -var r9h3 = c ^ 1 /* b */; //ok -var r9h4 = d ^ 1 /* b */; -var r9h5 = e ^ 1 /* b */; -var r9h6 = f ^ 1 /* b */; +var r9g1 = E.a ^ a; //ok +var r9g2 = E.a ^ b; +var r9g3 = E.a ^ c; //ok +var r9g4 = E.a ^ d; +var r9g5 = E.a ^ e; +var r9g6 = E.a ^ f; +var r9h1 = a ^ E.b; //ok +var r9h2 = b ^ E.b; +var r9h3 = c ^ E.b; //ok +var r9h4 = d ^ E.b; +var r9h5 = e ^ E.b; +var r9h6 = f ^ E.b; // operator | var r10a1 = a | a; //ok var r10a2 = a | b; @@ -1075,15 +1075,15 @@ var r10f3 = f | c; var r10f4 = f | d; var r10f5 = f | e; var r10f6 = f | f; -var r10g1 = 0 /* a */ | a; //ok -var r10g2 = 0 /* a */ | b; -var r10g3 = 0 /* a */ | c; //ok -var r10g4 = 0 /* a */ | d; -var r10g5 = 0 /* a */ | e; -var r10g6 = 0 /* a */ | f; -var r10h1 = a | 1 /* b */; //ok -var r10h2 = b | 1 /* b */; -var r10h3 = c | 1 /* b */; //ok -var r10h4 = d | 1 /* b */; -var r10h5 = e | 1 /* b */; -var r10h6 = f | 1 /* b */; +var r10g1 = E.a | a; //ok +var r10g2 = E.a | b; +var r10g3 = E.a | c; //ok +var r10g4 = E.a | d; +var r10g5 = E.a | e; +var r10g6 = E.a | f; +var r10h1 = a | E.b; //ok +var r10h2 = b | E.b; +var r10h3 = c | E.b; //ok +var r10h4 = d | E.b; +var r10h5 = e | E.b; +var r10h6 = f | E.b; diff --git a/tests/baselines/reference/arithmeticOperatorWithNullValueAndValidOperands.js b/tests/baselines/reference/arithmeticOperatorWithNullValueAndValidOperands.js index 40676ef449586..0c30e8d048492 100644 --- a/tests/baselines/reference/arithmeticOperatorWithNullValueAndValidOperands.js +++ b/tests/baselines/reference/arithmeticOperatorWithNullValueAndValidOperands.js @@ -124,89 +124,89 @@ var b; var ra1 = null * a; var ra2 = null * b; var ra3 = null * 1; -var ra4 = null * 0 /* a */; +var ra4 = null * E.a; var ra5 = a * null; var ra6 = b * null; var ra7 = 0 * null; -var ra8 = 1 /* b */ * null; +var ra8 = E.b * null; // operator / var rb1 = null / a; var rb2 = null / b; var rb3 = null / 1; -var rb4 = null / 0 /* a */; +var rb4 = null / E.a; var rb5 = a / null; var rb6 = b / null; var rb7 = 0 / null; -var rb8 = 1 /* b */ / null; +var rb8 = E.b / null; // operator % var rc1 = null % a; var rc2 = null % b; var rc3 = null % 1; -var rc4 = null % 0 /* a */; +var rc4 = null % E.a; var rc5 = a % null; var rc6 = b % null; var rc7 = 0 % null; -var rc8 = 1 /* b */ % null; +var rc8 = E.b % null; // operator - var rd1 = null - a; var rd2 = null - b; var rd3 = null - 1; -var rd4 = null - 0 /* a */; +var rd4 = null - E.a; var rd5 = a - null; var rd6 = b - null; var rd7 = 0 - null; -var rd8 = 1 /* b */ - null; +var rd8 = E.b - null; // operator << var re1 = null << a; var re2 = null << b; var re3 = null << 1; -var re4 = null << 0 /* a */; +var re4 = null << E.a; var re5 = a << null; var re6 = b << null; var re7 = 0 << null; -var re8 = 1 /* b */ << null; +var re8 = E.b << null; // operator >> var rf1 = null >> a; var rf2 = null >> b; var rf3 = null >> 1; -var rf4 = null >> 0 /* a */; +var rf4 = null >> E.a; var rf5 = a >> null; var rf6 = b >> null; var rf7 = 0 >> null; -var rf8 = 1 /* b */ >> null; +var rf8 = E.b >> null; // operator >>> var rg1 = null >>> a; var rg2 = null >>> b; var rg3 = null >>> 1; -var rg4 = null >>> 0 /* a */; +var rg4 = null >>> E.a; var rg5 = a >>> null; var rg6 = b >>> null; var rg7 = 0 >>> null; -var rg8 = 1 /* b */ >>> null; +var rg8 = E.b >>> null; // operator & var rh1 = null & a; var rh2 = null & b; var rh3 = null & 1; -var rh4 = null & 0 /* a */; +var rh4 = null & E.a; var rh5 = a & null; var rh6 = b & null; var rh7 = 0 & null; -var rh8 = 1 /* b */ & null; +var rh8 = E.b & null; // operator ^ var ri1 = null ^ a; var ri2 = null ^ b; var ri3 = null ^ 1; -var ri4 = null ^ 0 /* a */; +var ri4 = null ^ E.a; var ri5 = a ^ null; var ri6 = b ^ null; var ri7 = 0 ^ null; -var ri8 = 1 /* b */ ^ null; +var ri8 = E.b ^ null; // operator | var rj1 = null | a; var rj2 = null | b; var rj3 = null | 1; -var rj4 = null | 0 /* a */; +var rj4 = null | E.a; var rj5 = a | null; var rj6 = b | null; var rj7 = 0 | null; -var rj8 = 1 /* b */ | null; +var rj8 = E.b | null; diff --git a/tests/baselines/reference/arithmeticOperatorWithUndefinedValueAndValidOperands.js b/tests/baselines/reference/arithmeticOperatorWithUndefinedValueAndValidOperands.js index ddc2c87dd7a60..60ea9af32c2b5 100644 --- a/tests/baselines/reference/arithmeticOperatorWithUndefinedValueAndValidOperands.js +++ b/tests/baselines/reference/arithmeticOperatorWithUndefinedValueAndValidOperands.js @@ -124,89 +124,89 @@ var b; var ra1 = undefined * a; var ra2 = undefined * b; var ra3 = undefined * 1; -var ra4 = undefined * 0 /* a */; +var ra4 = undefined * E.a; var ra5 = a * undefined; var ra6 = b * undefined; var ra7 = 0 * undefined; -var ra8 = 1 /* b */ * undefined; +var ra8 = E.b * undefined; // operator / var rb1 = undefined / a; var rb2 = undefined / b; var rb3 = undefined / 1; -var rb4 = undefined / 0 /* a */; +var rb4 = undefined / E.a; var rb5 = a / undefined; var rb6 = b / undefined; var rb7 = 0 / undefined; -var rb8 = 1 /* b */ / undefined; +var rb8 = E.b / undefined; // operator % var rc1 = undefined % a; var rc2 = undefined % b; var rc3 = undefined % 1; -var rc4 = undefined % 0 /* a */; +var rc4 = undefined % E.a; var rc5 = a % undefined; var rc6 = b % undefined; var rc7 = 0 % undefined; -var rc8 = 1 /* b */ % undefined; +var rc8 = E.b % undefined; // operator - var rd1 = undefined - a; var rd2 = undefined - b; var rd3 = undefined - 1; -var rd4 = undefined - 0 /* a */; +var rd4 = undefined - E.a; var rd5 = a - undefined; var rd6 = b - undefined; var rd7 = 0 - undefined; -var rd8 = 1 /* b */ - undefined; +var rd8 = E.b - undefined; // operator << var re1 = undefined << a; var re2 = undefined << b; var re3 = undefined << 1; -var re4 = undefined << 0 /* a */; +var re4 = undefined << E.a; var re5 = a << undefined; var re6 = b << undefined; var re7 = 0 << undefined; -var re8 = 1 /* b */ << undefined; +var re8 = E.b << undefined; // operator >> var rf1 = undefined >> a; var rf2 = undefined >> b; var rf3 = undefined >> 1; -var rf4 = undefined >> 0 /* a */; +var rf4 = undefined >> E.a; var rf5 = a >> undefined; var rf6 = b >> undefined; var rf7 = 0 >> undefined; -var rf8 = 1 /* b */ >> undefined; +var rf8 = E.b >> undefined; // operator >>> var rg1 = undefined >>> a; var rg2 = undefined >>> b; var rg3 = undefined >>> 1; -var rg4 = undefined >>> 0 /* a */; +var rg4 = undefined >>> E.a; var rg5 = a >>> undefined; var rg6 = b >>> undefined; var rg7 = 0 >>> undefined; -var rg8 = 1 /* b */ >>> undefined; +var rg8 = E.b >>> undefined; // operator & var rh1 = undefined & a; var rh2 = undefined & b; var rh3 = undefined & 1; -var rh4 = undefined & 0 /* a */; +var rh4 = undefined & E.a; var rh5 = a & undefined; var rh6 = b & undefined; var rh7 = 0 & undefined; -var rh8 = 1 /* b */ & undefined; +var rh8 = E.b & undefined; // operator ^ var ri1 = undefined ^ a; var ri2 = undefined ^ b; var ri3 = undefined ^ 1; -var ri4 = undefined ^ 0 /* a */; +var ri4 = undefined ^ E.a; var ri5 = a ^ undefined; var ri6 = b ^ undefined; var ri7 = 0 ^ undefined; -var ri8 = 1 /* b */ ^ undefined; +var ri8 = E.b ^ undefined; // operator | var rj1 = undefined | a; var rj2 = undefined | b; var rj3 = undefined | 1; -var rj4 = undefined | 0 /* a */; +var rj4 = undefined | E.a; var rj5 = a | undefined; var rj6 = b | undefined; var rj7 = 0 | undefined; -var rj8 = 1 /* b */ | undefined; +var rj8 = E.b | undefined; diff --git a/tests/baselines/reference/assignAnyToEveryType.js b/tests/baselines/reference/assignAnyToEveryType.js index 47093cd085290..94b8067ddd786 100644 --- a/tests/baselines/reference/assignAnyToEveryType.js +++ b/tests/baselines/reference/assignAnyToEveryType.js @@ -61,7 +61,7 @@ var E; E[E["A"] = 0] = "A"; })(E || (E = {})); var g = x; -var g2 = 0 /* A */; +var g2 = E.A; g2 = x; var C = (function () { function C() { diff --git a/tests/baselines/reference/assignEveryTypeToAny.js b/tests/baselines/reference/assignEveryTypeToAny.js index afe0d17cea1c2..ed1911ef99541 100644 --- a/tests/baselines/reference/assignEveryTypeToAny.js +++ b/tests/baselines/reference/assignEveryTypeToAny.js @@ -77,8 +77,8 @@ var E; (function (E) { E[E["A"] = 0] = "A"; })(E || (E = {})); -x = 0 /* A */; -var f = 0 /* A */; +x = E.A; +var f = E.A; x = f; var g; x = g; diff --git a/tests/baselines/reference/assignToEnum.js b/tests/baselines/reference/assignToEnum.js index 153068738d197..5f7048894fa32 100644 --- a/tests/baselines/reference/assignToEnum.js +++ b/tests/baselines/reference/assignToEnum.js @@ -14,6 +14,6 @@ var A; A[A["bar"] = 1] = "bar"; })(A || (A = {})); A = undefined; // invalid LHS -A = 1 /* bar */; // invalid LHS -0 /* foo */ = 1; // invalid LHS -0 /* foo */ = 1 /* bar */; // invalid LHS +A = A.bar; // invalid LHS +A.foo = 1; // invalid LHS +A.foo = A.bar; // invalid LHS diff --git a/tests/baselines/reference/assignments.js b/tests/baselines/reference/assignments.js index f9bb008ccacb3..f6ca508384b53 100644 --- a/tests/baselines/reference/assignments.js +++ b/tests/baselines/reference/assignments.js @@ -52,7 +52,7 @@ var E; E[E["A"] = 0] = "A"; })(E || (E = {})); E = null; // Error -0 /* A */ = null; // OK per spec, Error per implementation (509581) +E.A = null; // OK per spec, Error per implementation (509581) function fn() { } fn = null; // Should be error diff --git a/tests/baselines/reference/bestCommonTypeOfTuple.js b/tests/baselines/reference/bestCommonTypeOfTuple.js index 704cae200a4e5..d5cbe7e67c826 100644 --- a/tests/baselines/reference/bestCommonTypeOfTuple.js +++ b/tests/baselines/reference/bestCommonTypeOfTuple.js @@ -53,16 +53,16 @@ t1 = [ f2 ]; t2 = [ - 0 /* one */, - 0 /* two */ + E1.one, + E2.two ]; t3 = [ 5, undefined ]; t4 = [ - 0 /* one */, - 0 /* two */, + E1.one, + E2.two, 20 ]; var e1 = t1[2]; // {} diff --git a/tests/baselines/reference/bitwiseNotOperatorWithEnumType.js b/tests/baselines/reference/bitwiseNotOperatorWithEnumType.js index 710af4edfa779..0bcf2fa39569b 100644 --- a/tests/baselines/reference/bitwiseNotOperatorWithEnumType.js +++ b/tests/baselines/reference/bitwiseNotOperatorWithEnumType.js @@ -30,11 +30,11 @@ var ENUM1; // enum type var var ResultIsNumber1 = ~ENUM1; // enum type expressions -var ResultIsNumber2 = ~0 /* "A" */; -var ResultIsNumber3 = ~(0 /* A */ + 1 /* "B" */); +var ResultIsNumber2 = ~ENUM1["A"]; +var ResultIsNumber3 = ~(ENUM1.A + ENUM1["B"]); // multiple ~ operators -var ResultIsNumber4 = ~~~(0 /* "A" */ + 1 /* B */); +var ResultIsNumber4 = ~~~(ENUM1["A"] + ENUM1.B); // miss assignment operators ~ENUM1; -~0 /* "A" */; -~0 /* A */, ~1 /* "B" */; +~ENUM1["A"]; +~ENUM1.A, ~ENUM1["B"]; diff --git a/tests/baselines/reference/callWithSpreadES6.js b/tests/baselines/reference/callWithSpreadES6.js index 0becb4c6e3e0d..d1589d7f6fad1 100644 --- a/tests/baselines/reference/callWithSpreadES6.js +++ b/tests/baselines/reference/callWithSpreadES6.js @@ -55,12 +55,6 @@ var c = new C(1, 2, ...a); //// [callWithSpreadES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; function foo(x, y, ...z) { } var a; @@ -84,26 +78,23 @@ xa[1].foo(...[ 2, "abc" ]); -var C = (function () { - function C(x, y, ...z) { +class C { + constructor(x, y, ...z) { this.foo(x, y); this.foo(x, y, ...z); } - C.prototype.foo = function (x, y, ...z) { - }; - return C; -})(); -var D = (function (_super) { - __extends(D, _super); - function D() { - _super.call(this, 1, 2); - _super.call(this, 1, 2, ...a); + foo(x, y, ...z) { } - D.prototype.foo = function () { - _super.prototype.foo.call(this, 1, 2); - _super.prototype.foo.call(this, 1, 2, ...a); - }; - return D; -})(C); +} +class D extends C { + constructor() { + super(1, 2); + super(1, 2, ...a); + } + foo() { + super.foo(1, 2); + super.foo(1, 2, ...a); + } +} // Only supported in when target is ES6 var c = new C(1, 2, ...a); diff --git a/tests/baselines/reference/castingTuple.js b/tests/baselines/reference/castingTuple.js index bea141968a6d2..e615590ea7d96 100644 --- a/tests/baselines/reference/castingTuple.js +++ b/tests/baselines/reference/castingTuple.js @@ -97,8 +97,8 @@ var classCDATuple = classCDTuple; var eleFromCDA1 = classCDATuple[2]; // A var eleFromCDA2 = classCDATuple[5]; // C | D | A var t10 = [ - 0 /* one */, - 0 /* one */ + E1.one, + E2.one ]; var t11 = t10; var array1 = emptyObjTuple; diff --git a/tests/baselines/reference/cloduleWithRecursiveReference.js b/tests/baselines/reference/cloduleWithRecursiveReference.js index 1b8a91b3c6817..1a688712270e1 100644 --- a/tests/baselines/reference/cloduleWithRecursiveReference.js +++ b/tests/baselines/reference/cloduleWithRecursiveReference.js @@ -17,7 +17,7 @@ var M; })(); M.C = C; var C; - (function (_C) { - _C.C = M.C; + (function (C_1) { + C_1.C = M.C; })(C = M.C || (M.C = {})); })(M || (M = {})); diff --git a/tests/baselines/reference/collisionCodeGenEnumWithEnumMemberConflict.js b/tests/baselines/reference/collisionCodeGenEnumWithEnumMemberConflict.js index 454fddf6fa87c..1e56eb8bd9f3d 100644 --- a/tests/baselines/reference/collisionCodeGenEnumWithEnumMemberConflict.js +++ b/tests/baselines/reference/collisionCodeGenEnumWithEnumMemberConflict.js @@ -8,5 +8,5 @@ enum Color { var Color; (function (Color) { Color[Color["Color"] = 0] = "Color"; - Color[Color["Thing"] = Color.Color] = "Thing"; + Color[Color["Thing"] = 0] = "Thing"; })(Color || (Color = {})); diff --git a/tests/baselines/reference/collisionCodeGenModuleWithAccessorChildren.js b/tests/baselines/reference/collisionCodeGenModuleWithAccessorChildren.js index 141ef285f037a..8152a9c27215e 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithAccessorChildren.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithAccessorChildren.js @@ -47,14 +47,14 @@ module M { // Shouldnt be _M //// [collisionCodeGenModuleWithAccessorChildren.js] var M; -(function (_M) { - _M.x = 3; +(function (M_1) { + M_1.x = 3; var c = (function () { function c() { } Object.defineProperty(c.prototype, "Z", { set: function (M) { - this.y = _M.x; + this.y = M_1.x; }, enumerable: true, configurable: true @@ -63,14 +63,14 @@ var M; })(); })(M || (M = {})); var M; -(function (_M_1) { +(function (M_2) { var d = (function () { function d() { } Object.defineProperty(d.prototype, "Z", { set: function (p) { var M = 10; - this.y = _M_1.x; + this.y = M_2.x; }, enumerable: true, configurable: true @@ -94,14 +94,14 @@ var M; })(); })(M || (M = {})); var M; -(function (_M_2) { +(function (M_3) { var f = (function () { function f() { } Object.defineProperty(f.prototype, "Z", { get: function () { var M = 10; - return _M_2.x; + return M_3.x; }, enumerable: true, configurable: true diff --git a/tests/baselines/reference/collisionCodeGenModuleWithConstructorChildren.js b/tests/baselines/reference/collisionCodeGenModuleWithConstructorChildren.js index 2158a0562ea2d..2aa705c914123 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithConstructorChildren.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithConstructorChildren.js @@ -25,31 +25,31 @@ module M { //// [collisionCodeGenModuleWithConstructorChildren.js] var M; -(function (_M) { - _M.x = 3; +(function (M_1) { + M_1.x = 3; var c = (function () { function c(M, p) { - if (p === void 0) { p = _M.x; } + if (p === void 0) { p = M_1.x; } } return c; })(); })(M || (M = {})); var M; -(function (_M_1) { +(function (M_2) { var d = (function () { function d(M, p) { - if (p === void 0) { p = _M_1.x; } + if (p === void 0) { p = M_2.x; } this.M = M; } return d; })(); })(M || (M = {})); var M; -(function (_M_2) { +(function (M_3) { var d2 = (function () { function d2() { var M = 10; - var p = _M_2.x; + var p = M_3.x; } return d2; })(); diff --git a/tests/baselines/reference/collisionCodeGenModuleWithEnumMemberConflict.js b/tests/baselines/reference/collisionCodeGenModuleWithEnumMemberConflict.js index 0dc8e508d45ca..3662f5d6ddd44 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithEnumMemberConflict.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithEnumMemberConflict.js @@ -12,6 +12,6 @@ var m1; var e; (function (e) { e[e["m1"] = 0] = "m1"; - e[e["m2"] = e.m1] = "m2"; + e[e["m2"] = 0] = "m2"; })(e || (e = {})); })(m1 || (m1 = {})); diff --git a/tests/baselines/reference/collisionCodeGenModuleWithFunctionChildren.js b/tests/baselines/reference/collisionCodeGenModuleWithFunctionChildren.js index caaa6a59da525..252ad2c63dc65 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithFunctionChildren.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithFunctionChildren.js @@ -21,24 +21,24 @@ module M { //// [collisionCodeGenModuleWithFunctionChildren.js] var M; -(function (_M) { - _M.x = 3; +(function (M_1) { + M_1.x = 3; function fn(M, p) { - if (p === void 0) { p = _M.x; } + if (p === void 0) { p = M_1.x; } } })(M || (M = {})); var M; -(function (_M_1) { +(function (M_2) { function fn2() { var M; - var p = _M_1.x; + var p = M_2.x; } })(M || (M = {})); var M; -(function (_M_2) { +(function (M_3) { function fn3() { function M() { - var p = _M_2.x; + var p = M_3.x; } } })(M || (M = {})); diff --git a/tests/baselines/reference/collisionCodeGenModuleWithMemberClassConflict.js b/tests/baselines/reference/collisionCodeGenModuleWithMemberClassConflict.js index 59c2ebf295d52..05ae475e7d234 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithMemberClassConflict.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithMemberClassConflict.js @@ -17,29 +17,29 @@ var foo = new m2._m2(); //// [collisionCodeGenModuleWithMemberClassConflict.js] var m1; -(function (_m1) { +(function (m1_1) { var m1 = (function () { function m1() { } return m1; })(); - _m1.m1 = m1; + m1_1.m1 = m1; })(m1 || (m1 = {})); var foo = new m1.m1(); var m2; -(function (_m2_1) { +(function (m2_1) { var m2 = (function () { function m2() { } return m2; })(); - _m2_1.m2 = m2; + m2_1.m2 = m2; var _m2 = (function () { function _m2() { } return _m2; })(); - _m2_1._m2 = _m2; + m2_1._m2 = _m2; })(m2 || (m2 = {})); var foo = new m2.m2(); var foo = new m2._m2(); diff --git a/tests/baselines/reference/collisionCodeGenModuleWithMemberVariable.js b/tests/baselines/reference/collisionCodeGenModuleWithMemberVariable.js index d57de06dfa73d..1a23b81c139e2 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithMemberVariable.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithMemberVariable.js @@ -7,8 +7,8 @@ var foo = m1.m1; //// [collisionCodeGenModuleWithMemberVariable.js] var m1; -(function (_m1) { - _m1.m1 = 10; - var b = _m1.m1; +(function (m1_1) { + m1_1.m1 = 10; + var b = m1_1.m1; })(m1 || (m1 = {})); var foo = m1.m1; diff --git a/tests/baselines/reference/collisionCodeGenModuleWithMethodChildren.js b/tests/baselines/reference/collisionCodeGenModuleWithMethodChildren.js index 212364ed30b00..53807f1cabd52 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithMethodChildren.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithMethodChildren.js @@ -34,37 +34,37 @@ module M { // Shouldnt bn _M //// [collisionCodeGenModuleWithMethodChildren.js] var M; -(function (_M) { - _M.x = 3; +(function (M_1) { + M_1.x = 3; var c = (function () { function c() { } c.prototype.fn = function (M, p) { - if (p === void 0) { p = _M.x; } + if (p === void 0) { p = M_1.x; } }; return c; })(); })(M || (M = {})); var M; -(function (_M_1) { +(function (M_2) { var d = (function () { function d() { } d.prototype.fn2 = function () { var M; - var p = _M_1.x; + var p = M_2.x; }; return d; })(); })(M || (M = {})); var M; -(function (_M_2) { +(function (M_3) { var e = (function () { function e() { } e.prototype.fn3 = function () { function M() { - var p = _M_2.x; + var p = M_3.x; } }; return e; diff --git a/tests/baselines/reference/collisionCodeGenModuleWithModuleChildren.js b/tests/baselines/reference/collisionCodeGenModuleWithModuleChildren.js index 3c8b17deadd68..2862a84406786 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithModuleChildren.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithModuleChildren.js @@ -44,16 +44,16 @@ module M { //// [collisionCodeGenModuleWithModuleChildren.js] var M; -(function (_M) { - _M.x = 3; +(function (M_1) { + M_1.x = 3; var m1; (function (m1) { var M = 10; - var p = _M.x; + var p = M_1.x; })(m1 || (m1 = {})); })(M || (M = {})); var M; -(function (_M_1) { +(function (M_2) { var m2; (function (m2) { var M = (function () { @@ -61,17 +61,17 @@ var M; } return M; })(); - var p = _M_1.x; + var p = M_2.x; var p2 = new M(); })(m2 || (m2 = {})); })(M || (M = {})); var M; -(function (_M_2) { +(function (M_3) { var m3; (function (m3) { function M() { } - var p = _M_2.x; + var p = M_3.x; var p2 = M(); })(m3 || (m3 = {})); })(M || (M = {})); @@ -84,12 +84,12 @@ var M; })(m3 || (m3 = {})); })(M || (M = {})); var M; -(function (_M_3) { +(function (M_4) { var m4; (function (m4) { var M; (function (M) { - var p = _M_3.x; + var p = M_4.x; })(M || (M = {})); })(m4 || (m4 = {})); })(M || (M = {})); diff --git a/tests/baselines/reference/collisionCodeGenModuleWithModuleReopening.js b/tests/baselines/reference/collisionCodeGenModuleWithModuleReopening.js index 4c3d60230635d..710c09e4558ae 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithModuleReopening.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithModuleReopening.js @@ -31,13 +31,13 @@ var foo2 = new m2.m2(); //// [collisionCodeGenModuleWithModuleReopening.js] var m1; -(function (_m1) { +(function (m1_1) { var m1 = (function () { function m1() { } return m1; })(); - _m1.m1 = m1; + m1_1.m1 = m1; })(m1 || (m1 = {})); var foo = new m1.m1(); var m1; @@ -65,16 +65,16 @@ var m2; })(m2 || (m2 = {})); var foo3 = new m2.c1(); var m2; -(function (_m2) { +(function (m2_1) { var m2 = (function () { function m2() { } return m2; })(); - _m2.m2 = m2; + m2_1.m2 = m2; var b = new m2(); - var d = _m2.b10; - var c = new _m2.c1(); + var d = m2_1.b10; + var c = new m2_1.c1(); })(m2 || (m2 = {})); var foo3 = new m2.c1(); var foo2 = new m2.m2(); diff --git a/tests/baselines/reference/collisionCodeGenModuleWithPrivateMember.js b/tests/baselines/reference/collisionCodeGenModuleWithPrivateMember.js index 28901bd11e829..4b4d6aa7afb1b 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithPrivateMember.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithPrivateMember.js @@ -10,7 +10,7 @@ var foo = new m1.c1(); //// [collisionCodeGenModuleWithPrivateMember.js] var m1; -(function (_m1) { +(function (m1_1) { var m1 = (function () { function m1() { } @@ -22,6 +22,6 @@ var m1; } return c1; })(); - _m1.c1 = c1; + m1_1.c1 = c1; })(m1 || (m1 = {})); var foo = new m1.c1(); diff --git a/tests/baselines/reference/collisionCodeGenModuleWithUnicodeNames.js b/tests/baselines/reference/collisionCodeGenModuleWithUnicodeNames.js index d4e919e0a17ae..3204a05bc7575 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithUnicodeNames.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithUnicodeNames.js @@ -11,12 +11,12 @@ var x = new 才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكو //// [collisionCodeGenModuleWithUnicodeNames.js] var 才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123; -(function (_才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123) { +(function (才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123_1) { var 才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123 = (function () { function 才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123() { } return 才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123; })(); - _才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123.才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123 = 才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123; + 才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123_1.才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123 = 才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123; })(才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123 || (才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123 = {})); var x = new 才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123.才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123(); diff --git a/tests/baselines/reference/commentsEnums.js b/tests/baselines/reference/commentsEnums.js index c8bba8a4f776d..7be17f085b0ac 100644 --- a/tests/baselines/reference/commentsEnums.js +++ b/tests/baselines/reference/commentsEnums.js @@ -21,8 +21,8 @@ var Colors; /** Fancy name for 'pink'*/ Colors[Colors["FancyPink"] = 1] = "FancyPink"; })(Colors || (Colors = {})); // trailing comment -var x = 0 /* Cornflower */; -x = 1 /* FancyPink */; +var x = Colors.Cornflower; +x = Colors.FancyPink; //// [commentsEnums.d.ts] diff --git a/tests/baselines/reference/comparisonOperatorWithSubtypeEnumAndNumber.js b/tests/baselines/reference/comparisonOperatorWithSubtypeEnumAndNumber.js index e0c1f33cb4ada..fc0323a89aa08 100644 --- a/tests/baselines/reference/comparisonOperatorWithSubtypeEnumAndNumber.js +++ b/tests/baselines/reference/comparisonOperatorWithSubtypeEnumAndNumber.js @@ -80,56 +80,56 @@ var b; // operator < var ra1 = a < b; var ra2 = b < a; -var ra3 = 0 /* a */ < b; -var ra4 = b < 0 /* a */; -var ra5 = 0 /* a */ < 0; -var ra6 = 0 < 0 /* a */; +var ra3 = E.a < b; +var ra4 = b < E.a; +var ra5 = E.a < 0; +var ra6 = 0 < E.a; // operator > var rb1 = a > b; var rb2 = b > a; -var rb3 = 0 /* a */ > b; -var rb4 = b > 0 /* a */; -var rb5 = 0 /* a */ > 0; -var rb6 = 0 > 0 /* a */; +var rb3 = E.a > b; +var rb4 = b > E.a; +var rb5 = E.a > 0; +var rb6 = 0 > E.a; // operator <= var rc1 = a <= b; var rc2 = b <= a; -var rc3 = 0 /* a */ <= b; -var rc4 = b <= 0 /* a */; -var rc5 = 0 /* a */ <= 0; -var rc6 = 0 <= 0 /* a */; +var rc3 = E.a <= b; +var rc4 = b <= E.a; +var rc5 = E.a <= 0; +var rc6 = 0 <= E.a; // operator >= var rd1 = a >= b; var rd2 = b >= a; -var rd3 = 0 /* a */ >= b; -var rd4 = b >= 0 /* a */; -var rd5 = 0 /* a */ >= 0; -var rd6 = 0 >= 0 /* a */; +var rd3 = E.a >= b; +var rd4 = b >= E.a; +var rd5 = E.a >= 0; +var rd6 = 0 >= E.a; // operator == var re1 = a == b; var re2 = b == a; -var re3 = 0 /* a */ == b; -var re4 = b == 0 /* a */; -var re5 = 0 /* a */ == 0; -var re6 = 0 == 0 /* a */; +var re3 = E.a == b; +var re4 = b == E.a; +var re5 = E.a == 0; +var re6 = 0 == E.a; // operator != var rf1 = a != b; var rf2 = b != a; -var rf3 = 0 /* a */ != b; -var rf4 = b != 0 /* a */; -var rf5 = 0 /* a */ != 0; -var rf6 = 0 != 0 /* a */; +var rf3 = E.a != b; +var rf4 = b != E.a; +var rf5 = E.a != 0; +var rf6 = 0 != E.a; // operator === var rg1 = a === b; var rg2 = b === a; -var rg3 = 0 /* a */ === b; -var rg4 = b === 0 /* a */; -var rg5 = 0 /* a */ === 0; -var rg6 = 0 === 0 /* a */; +var rg3 = E.a === b; +var rg4 = b === E.a; +var rg5 = E.a === 0; +var rg6 = 0 === E.a; // operator !== var rh1 = a !== b; var rh2 = b !== a; -var rh3 = 0 /* a */ !== b; -var rh4 = b !== 0 /* a */; -var rh5 = 0 /* a */ !== 0; -var rh6 = 0 !== 0 /* a */; +var rh3 = E.a !== b; +var rh4 = b !== E.a; +var rh5 = E.a !== 0; +var rh6 = 0 !== E.a; diff --git a/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.js b/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.js index aebacb8882780..ae53d0641783a 100644 --- a/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.js +++ b/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.js @@ -64,7 +64,7 @@ x1 += b; x1 += true; x1 += 0; x1 += ''; -x1 += 0 /* a */; +x1 += E.a; x1 += {}; x1 += null; x1 += undefined; @@ -74,20 +74,20 @@ x2 += b; x2 += true; x2 += 0; x2 += ''; -x2 += 0 /* a */; +x2 += E.a; x2 += {}; x2 += null; x2 += undefined; var x3; x3 += a; x3 += 0; -x3 += 0 /* a */; +x3 += E.a; x3 += null; x3 += undefined; var x4; x4 += a; x4 += 0; -x4 += 0 /* a */; +x4 += E.a; x4 += null; x4 += undefined; var x5; diff --git a/tests/baselines/reference/compoundAdditionAssignmentWithInvalidOperands.js b/tests/baselines/reference/compoundAdditionAssignmentWithInvalidOperands.js index af4f1bc152193..cef1d3e424e97 100644 --- a/tests/baselines/reference/compoundAdditionAssignmentWithInvalidOperands.js +++ b/tests/baselines/reference/compoundAdditionAssignmentWithInvalidOperands.js @@ -51,7 +51,7 @@ var x1; x1 += a; x1 += true; x1 += 0; -x1 += 0 /* a */; +x1 += E.a; x1 += {}; x1 += null; x1 += undefined; @@ -59,7 +59,7 @@ var x2; x2 += a; x2 += true; x2 += 0; -x2 += 0 /* a */; +x2 += E.a; x2 += {}; x2 += null; x2 += undefined; @@ -67,7 +67,7 @@ var x3; x3 += a; x3 += true; x3 += 0; -x3 += 0 /* a */; +x3 += E.a; x3 += {}; x3 += null; x3 += undefined; diff --git a/tests/baselines/reference/compoundArithmeticAssignmentWithInvalidOperands.js b/tests/baselines/reference/compoundArithmeticAssignmentWithInvalidOperands.js index 61722df0fb043..5c71f717bb237 100644 --- a/tests/baselines/reference/compoundArithmeticAssignmentWithInvalidOperands.js +++ b/tests/baselines/reference/compoundArithmeticAssignmentWithInvalidOperands.js @@ -74,7 +74,7 @@ x1 *= b; x1 *= true; x1 *= 0; x1 *= ''; -x1 *= 0 /* a */; +x1 *= E.a; x1 *= {}; x1 *= null; x1 *= undefined; @@ -84,7 +84,7 @@ x2 *= b; x2 *= true; x2 *= 0; x2 *= ''; -x2 *= 0 /* a */; +x2 *= E.a; x2 *= {}; x2 *= null; x2 *= undefined; @@ -94,7 +94,7 @@ x3 *= b; x3 *= true; x3 *= 0; x3 *= ''; -x3 *= 0 /* a */; +x3 *= E.a; x3 *= {}; x3 *= null; x3 *= undefined; @@ -104,7 +104,7 @@ x4 *= b; x4 *= true; x4 *= 0; x4 *= ''; -x4 *= 0 /* a */; +x4 *= E.a; x4 *= {}; x4 *= null; x4 *= undefined; diff --git a/tests/baselines/reference/computedPropertyNames12_ES6.js b/tests/baselines/reference/computedPropertyNames12_ES6.js index 5ab6e4c09b312..fd6ccb6e4860f 100644 --- a/tests/baselines/reference/computedPropertyNames12_ES6.js +++ b/tests/baselines/reference/computedPropertyNames12_ES6.js @@ -20,12 +20,11 @@ class C { var s; var n; var a; -var C = (function () { - function C() { +class C { + constructor() { this[n] = n; this[s + n] = 2; this[`hello bye`] = 0; } - C[`hello ${a} bye`] = 0; - return C; -})(); +} +C[`hello ${a} bye`] = 0; diff --git a/tests/baselines/reference/computedPropertyNames13_ES6.js b/tests/baselines/reference/computedPropertyNames13_ES6.js index 07aa1673aba27..18d81fcec59e4 100644 --- a/tests/baselines/reference/computedPropertyNames13_ES6.js +++ b/tests/baselines/reference/computedPropertyNames13_ES6.js @@ -20,30 +20,27 @@ class C { var s; var n; var a; -var C = (function () { - function C() { - } - C.prototype[s] = function () { - }; - C.prototype[n] = function () { - }; - C[s + s] = function () { - }; - C.prototype[s + n] = function () { - }; - C.prototype[+s] = function () { - }; - C[""] = function () { - }; - C.prototype[0] = function () { - }; - C.prototype[a] = function () { - }; - C[true] = function () { - }; - C.prototype[`hello bye`] = function () { - }; - C[`hello ${a} bye`] = function () { - }; - return C; -})(); +class C { + [s]() { + } + [n]() { + } + static [s + s]() { + } + [s + n]() { + } + [+s]() { + } + static [""]() { + } + [0]() { + } + [a]() { + } + static [true]() { + } + [`hello bye`]() { + } + static [`hello ${a} bye`]() { + } +} diff --git a/tests/baselines/reference/computedPropertyNames14_ES6.js b/tests/baselines/reference/computedPropertyNames14_ES6.js index 7a58ad9a80a19..b1b2a9bf28542 100644 --- a/tests/baselines/reference/computedPropertyNames14_ES6.js +++ b/tests/baselines/reference/computedPropertyNames14_ES6.js @@ -11,20 +11,17 @@ class C { //// [computedPropertyNames14_ES6.js] var b; -var C = (function () { - function C() { +class C { + [b]() { } - C.prototype[b] = function () { - }; - C[true] = function () { - }; - C.prototype[[]] = function () { - }; - C[{}] = function () { - }; - C.prototype[undefined] = function () { - }; - C[null] = function () { - }; - return C; -})(); + static [true]() { + } + [[]]() { + } + static [{}]() { + } + [undefined]() { + } + static [null]() { + } +} diff --git a/tests/baselines/reference/computedPropertyNames15_ES6.js b/tests/baselines/reference/computedPropertyNames15_ES6.js index 70c2e7b451c3a..1a9141ab13d74 100644 --- a/tests/baselines/reference/computedPropertyNames15_ES6.js +++ b/tests/baselines/reference/computedPropertyNames15_ES6.js @@ -12,14 +12,11 @@ class C { var p1; var p2; var p3; -var C = (function () { - function C() { +class C { + [p1]() { } - C.prototype[p1] = function () { - }; - C.prototype[p2] = function () { - }; - C.prototype[p3] = function () { - }; - return C; -})(); + [p2]() { + } + [p3]() { + } +} diff --git a/tests/baselines/reference/computedPropertyNames16_ES6.js b/tests/baselines/reference/computedPropertyNames16_ES6.js index 90f15f6cf2e2e..96e175976da1e 100644 --- a/tests/baselines/reference/computedPropertyNames16_ES6.js +++ b/tests/baselines/reference/computedPropertyNames16_ES6.js @@ -20,80 +20,33 @@ class C { var s; var n; var a; -var C = (function () { - function C() { +class C { + get [s]() { + return 0; } - Object.defineProperty(C.prototype, s, { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, n, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, s + s, { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, s + n, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, +s, { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, "", { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, 0, { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, a, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, true, { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, `hello bye`, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, `hello ${a} bye`, { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - return C; -})(); + set [n](v) { + } + static get [s + s]() { + return 0; + } + set [s + n](v) { + } + get [+s]() { + return 0; + } + static set [""](v) { + } + get [0]() { + return 0; + } + set [a](v) { + } + static get [true]() { + return 0; + } + set [`hello bye`](v) { + } + get [`hello ${a} bye`]() { + return 0; + } +} diff --git a/tests/baselines/reference/computedPropertyNames17_ES6.js b/tests/baselines/reference/computedPropertyNames17_ES6.js index e9b19202e088a..a181a61004eda 100644 --- a/tests/baselines/reference/computedPropertyNames17_ES6.js +++ b/tests/baselines/reference/computedPropertyNames17_ES6.js @@ -11,47 +11,20 @@ class C { //// [computedPropertyNames17_ES6.js] var b; -var C = (function () { - function C() { +class C { + get [b]() { + return 0; } - Object.defineProperty(C.prototype, b, { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, true, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, [], { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, {}, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, undefined, { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, null, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); + static set [true](v) { + } + get [[]]() { + return 0; + } + set [{}](v) { + } + static get [undefined]() { + return 0; + } + set [null](v) { + } +} diff --git a/tests/baselines/reference/computedPropertyNames21_ES6.js b/tests/baselines/reference/computedPropertyNames21_ES6.js index f51f6faed2424..c5f6b4e22b199 100644 --- a/tests/baselines/reference/computedPropertyNames21_ES6.js +++ b/tests/baselines/reference/computedPropertyNames21_ES6.js @@ -7,13 +7,10 @@ class C { } //// [computedPropertyNames21_ES6.js] -var C = (function () { - function C() { - } - C.prototype.bar = function () { +class C { + bar() { return 0; - }; - C.prototype[this.bar()] = function () { - }; - return C; -})(); + } + [this.bar()]() { + } +} diff --git a/tests/baselines/reference/computedPropertyNames22_ES6.js b/tests/baselines/reference/computedPropertyNames22_ES6.js index 9872605c20ed0..c88ceb6bc8f53 100644 --- a/tests/baselines/reference/computedPropertyNames22_ES6.js +++ b/tests/baselines/reference/computedPropertyNames22_ES6.js @@ -9,15 +9,12 @@ class C { } //// [computedPropertyNames22_ES6.js] -var C = (function () { - function C() { - } - C.prototype.bar = function () { +class C { + bar() { var obj = { [this.bar()]() { } }; return 0; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/computedPropertyNames23_ES5.js b/tests/baselines/reference/computedPropertyNames23_ES5.js index c3024a7fbbfde..34eb0896376df 100644 --- a/tests/baselines/reference/computedPropertyNames23_ES5.js +++ b/tests/baselines/reference/computedPropertyNames23_ES5.js @@ -20,5 +20,5 @@ var C = (function () { _a)[0]] = function () { }; return C; + var _a; })(); -var _a; diff --git a/tests/baselines/reference/computedPropertyNames23_ES6.js b/tests/baselines/reference/computedPropertyNames23_ES6.js index f5687952b88da..0bae1abdad2c1 100644 --- a/tests/baselines/reference/computedPropertyNames23_ES6.js +++ b/tests/baselines/reference/computedPropertyNames23_ES6.js @@ -9,15 +9,12 @@ class C { } //// [computedPropertyNames23_ES6.js] -var C = (function () { - function C() { - } - C.prototype.bar = function () { +class C { + bar() { return 0; - }; - C.prototype[{ + } + [{ [this.bar()]: 1 - }[0]] = function () { - }; - return C; -})(); + }[0]]() { + } +} diff --git a/tests/baselines/reference/computedPropertyNames24_ES5.errors.txt b/tests/baselines/reference/computedPropertyNames24_ES5.errors.txt index a1290e06956cb..121b39450a61d 100644 --- a/tests/baselines/reference/computedPropertyNames24_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNames24_ES5.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES5.ts(9,6): error TS2466: 'super' cannot be referenced in a computed property name. +tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES5.ts(7,6): error TS2466: 'super' cannot be referenced in a computed property name. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES5.ts (1 errors) ==== @@ -8,8 +8,6 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES5.ts(9, } } class C extends Base { - // Gets emitted as super, not _super, which is consistent with - // use of super in static properties initializers. [super.bar()]() { } ~~~~~ !!! error TS2466: 'super' cannot be referenced in a computed property name. diff --git a/tests/baselines/reference/computedPropertyNames24_ES5.js b/tests/baselines/reference/computedPropertyNames24_ES5.js index d24f406c1adb1..cea5240003b2e 100644 --- a/tests/baselines/reference/computedPropertyNames24_ES5.js +++ b/tests/baselines/reference/computedPropertyNames24_ES5.js @@ -5,8 +5,6 @@ class Base { } } class C extends Base { - // Gets emitted as super, not _super, which is consistent with - // use of super in static properties initializers. [super.bar()]() { } } @@ -30,9 +28,7 @@ var C = (function (_super) { function C() { _super.apply(this, arguments); } - // Gets emitted as super, not _super, which is consistent with - // use of super in static properties initializers. - C.prototype[super.bar.call(this)] = function () { + C.prototype[_super.bar.call(this)] = function () { }; return C; })(Base); diff --git a/tests/baselines/reference/computedPropertyNames24_ES6.js b/tests/baselines/reference/computedPropertyNames24_ES6.js index 12aef63396342..8d33db10f71ba 100644 --- a/tests/baselines/reference/computedPropertyNames24_ES6.js +++ b/tests/baselines/reference/computedPropertyNames24_ES6.js @@ -11,28 +11,14 @@ class C extends Base { } //// [computedPropertyNames24_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Base = (function () { - function Base() { - } - Base.prototype.bar = function () { +class Base { + bar() { return 0; - }; - return Base; -})(); -var C = (function (_super) { - __extends(C, _super); - function C() { - _super.apply(this, arguments); } +} +class C extends Base { // Gets emitted as super, not _super, which is consistent with // use of super in static properties initializers. - C.prototype[super.bar.call(this)] = function () { - }; - return C; -})(Base); + [super.bar()]() { + } +} diff --git a/tests/baselines/reference/computedPropertyNames25_ES6.js b/tests/baselines/reference/computedPropertyNames25_ES6.js index 1a600df5040cf..cc6a0670b2186 100644 --- a/tests/baselines/reference/computedPropertyNames25_ES6.js +++ b/tests/baselines/reference/computedPropertyNames25_ES6.js @@ -14,31 +14,17 @@ class C extends Base { } //// [computedPropertyNames25_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Base = (function () { - function Base() { - } - Base.prototype.bar = function () { +class Base { + bar() { return 0; - }; - return Base; -})(); -var C = (function (_super) { - __extends(C, _super); - function C() { - _super.apply(this, arguments); } - C.prototype.foo = function () { +} +class C extends Base { + foo() { var obj = { - [_super.prototype.bar.call(this)]() { + [super.bar()]() { } }; return 0; - }; - return C; -})(Base); + } +} diff --git a/tests/baselines/reference/computedPropertyNames26_ES5.errors.txt b/tests/baselines/reference/computedPropertyNames26_ES5.errors.txt index 77408f0a9f895..e703971273469 100644 --- a/tests/baselines/reference/computedPropertyNames26_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNames26_ES5.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES5.ts(10,12): error TS2466: 'super' cannot be referenced in a computed property name. +tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES5.ts(8,12): error TS2466: 'super' cannot be referenced in a computed property name. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES5.ts (1 errors) ==== @@ -8,8 +8,6 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES5.ts(10 } } class C extends Base { - // Gets emitted as super, not _super, which is consistent with - // use of super in static properties initializers. [ { [super.bar()]: 1 }[0] ~~~~~ diff --git a/tests/baselines/reference/computedPropertyNames26_ES5.js b/tests/baselines/reference/computedPropertyNames26_ES5.js index 217a0dfc74cff..cac71f734a693 100644 --- a/tests/baselines/reference/computedPropertyNames26_ES5.js +++ b/tests/baselines/reference/computedPropertyNames26_ES5.js @@ -5,8 +5,6 @@ class Base { } } class C extends Base { - // Gets emitted as super, not _super, which is consistent with - // use of super in static properties initializers. [ { [super.bar()]: 1 }[0] ]() { } @@ -32,12 +30,10 @@ var C = (function (_super) { function C() { _super.apply(this, arguments); } - // Gets emitted as super, not _super, which is consistent with - // use of super in static properties initializers. C.prototype[(_a = {}, - _a[super.bar.call(this)] = 1, + _a[_super.bar.call(this)] = 1, _a)[0]] = function () { }; return C; + var _a; })(Base); -var _a; diff --git a/tests/baselines/reference/computedPropertyNames26_ES6.js b/tests/baselines/reference/computedPropertyNames26_ES6.js index fc53d91e627dd..4526368de7a0a 100644 --- a/tests/baselines/reference/computedPropertyNames26_ES6.js +++ b/tests/baselines/reference/computedPropertyNames26_ES6.js @@ -13,30 +13,16 @@ class C extends Base { } //// [computedPropertyNames26_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Base = (function () { - function Base() { - } - Base.prototype.bar = function () { +class Base { + bar() { return 0; - }; - return Base; -})(); -var C = (function (_super) { - __extends(C, _super); - function C() { - _super.apply(this, arguments); } +} +class C extends Base { // Gets emitted as super, not _super, which is consistent with // use of super in static properties initializers. - C.prototype[{ - [super.bar.call(this)]: 1 - }[0]] = function () { - }; - return C; -})(Base); + [{ + [super.bar()]: 1 + }[0]]() { + } +} diff --git a/tests/baselines/reference/computedPropertyNames27_ES6.js b/tests/baselines/reference/computedPropertyNames27_ES6.js index 54a20a5220058..57589dfcaf507 100644 --- a/tests/baselines/reference/computedPropertyNames27_ES6.js +++ b/tests/baselines/reference/computedPropertyNames27_ES6.js @@ -6,23 +6,9 @@ class C extends Base { } //// [computedPropertyNames27_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Base = (function () { - function Base() { - } - return Base; -})(); -var C = (function (_super) { - __extends(C, _super); - function C() { - _super.apply(this, arguments); +class Base { +} +class C extends Base { + [(super(), "prop")]() { } - C.prototype[(_super.call(this), "prop")] = function () { - }; - return C; -})(Base); +} diff --git a/tests/baselines/reference/computedPropertyNames28_ES6.js b/tests/baselines/reference/computedPropertyNames28_ES6.js index 09e1b33bf981d..bc0e32593de1f 100644 --- a/tests/baselines/reference/computedPropertyNames28_ES6.js +++ b/tests/baselines/reference/computedPropertyNames28_ES6.js @@ -11,25 +11,14 @@ class C extends Base { } //// [computedPropertyNames28_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Base = (function () { - function Base() { - } - return Base; -})(); -var C = (function (_super) { - __extends(C, _super); - function C() { - _super.call(this); +class Base { +} +class C extends Base { + constructor() { + super(); var obj = { - [(_super.call(this), "prop")]() { + [(super(), "prop")]() { } }; } - return C; -})(Base); +} diff --git a/tests/baselines/reference/computedPropertyNames29_ES6.js b/tests/baselines/reference/computedPropertyNames29_ES6.js index e1e6be51b2155..35958b372b09c 100644 --- a/tests/baselines/reference/computedPropertyNames29_ES6.js +++ b/tests/baselines/reference/computedPropertyNames29_ES6.js @@ -11,10 +11,8 @@ class C { } //// [computedPropertyNames29_ES6.js] -var C = (function () { - function C() { - } - C.prototype.bar = function () { +class C { + bar() { (() => { var obj = { [this.bar()]() { @@ -22,6 +20,5 @@ var C = (function () { }; }); return 0; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/computedPropertyNames2_ES6.js b/tests/baselines/reference/computedPropertyNames2_ES6.js index e5fcfaac8f927..4287cb2c4b8d7 100644 --- a/tests/baselines/reference/computedPropertyNames2_ES6.js +++ b/tests/baselines/reference/computedPropertyNames2_ES6.js @@ -13,36 +13,17 @@ class C { //// [computedPropertyNames2_ES6.js] var methodName = "method"; var accessorName = "accessor"; -var C = (function () { - function C() { +class C { + [methodName]() { } - C.prototype[methodName] = function () { - }; - C[methodName] = function () { - }; - Object.defineProperty(C.prototype, accessorName, { - get: function () { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, accessorName, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, accessorName, { - get: function () { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, accessorName, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); + static [methodName]() { + } + get [accessorName]() { + } + set [accessorName](v) { + } + static get [accessorName]() { + } + static set [accessorName](v) { + } +} diff --git a/tests/baselines/reference/computedPropertyNames30_ES6.js b/tests/baselines/reference/computedPropertyNames30_ES6.js index c88fa98be5e86..cda2a278d47aa 100644 --- a/tests/baselines/reference/computedPropertyNames30_ES6.js +++ b/tests/baselines/reference/computedPropertyNames30_ES6.js @@ -16,30 +16,19 @@ class C extends Base { } //// [computedPropertyNames30_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Base = (function () { - function Base() { - } - return Base; -})(); -var C = (function (_super) { - __extends(C, _super); - function C() { - _super.call(this); +class Base { +} +class C extends Base { + constructor() { + super(); (() => { var obj = { // Ideally, we would capture this. But the reference is // illegal, and not capturing this is consistent with //treatment of other similar violations. - [(_super.call(this), "prop")]() { + [(super(), "prop")]() { } }; }); } - return C; -})(Base); +} diff --git a/tests/baselines/reference/computedPropertyNames31_ES6.js b/tests/baselines/reference/computedPropertyNames31_ES6.js index 33f5319ded98b..777e03bbcacad 100644 --- a/tests/baselines/reference/computedPropertyNames31_ES6.js +++ b/tests/baselines/reference/computedPropertyNames31_ES6.js @@ -16,34 +16,20 @@ class C extends Base { } //// [computedPropertyNames31_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Base = (function () { - function Base() { - } - Base.prototype.bar = function () { +class Base { + bar() { return 0; - }; - return Base; -})(); -var C = (function (_super) { - __extends(C, _super); - function C() { - _super.apply(this, arguments); } - C.prototype.foo = function () { +} +class C extends Base { + foo() { var _this = this; (() => { var obj = { - [_super.prototype.bar.call(_this)]() { + [super.bar()]() { } // needs capture }; }); return 0; - }; - return C; -})(Base); + } +} diff --git a/tests/baselines/reference/computedPropertyNames32_ES6.js b/tests/baselines/reference/computedPropertyNames32_ES6.js index a87f7715d890e..198c5e9981e58 100644 --- a/tests/baselines/reference/computedPropertyNames32_ES6.js +++ b/tests/baselines/reference/computedPropertyNames32_ES6.js @@ -11,13 +11,10 @@ class C { function foo() { return ''; } -var C = (function () { - function C() { - } - C.prototype.bar = function () { +class C { + bar() { return 0; - }; - C.prototype[foo()] = function () { - }; - return C; -})(); + } + [foo()]() { + } +} diff --git a/tests/baselines/reference/computedPropertyNames33_ES6.js b/tests/baselines/reference/computedPropertyNames33_ES6.js index 03c503caec45d..7fb08d2852d8d 100644 --- a/tests/baselines/reference/computedPropertyNames33_ES6.js +++ b/tests/baselines/reference/computedPropertyNames33_ES6.js @@ -13,15 +13,12 @@ class C { function foo() { return ''; } -var C = (function () { - function C() { - } - C.prototype.bar = function () { +class C { + bar() { var obj = { [foo()]() { } }; return 0; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/computedPropertyNames34_ES6.js b/tests/baselines/reference/computedPropertyNames34_ES6.js index 62e2e151cd3ac..e73d349bcd73f 100644 --- a/tests/baselines/reference/computedPropertyNames34_ES6.js +++ b/tests/baselines/reference/computedPropertyNames34_ES6.js @@ -13,15 +13,12 @@ class C { function foo() { return ''; } -var C = (function () { - function C() { - } - C.bar = function () { +class C { + static bar() { var obj = { [foo()]() { } }; return 0; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/computedPropertyNames36_ES6.js b/tests/baselines/reference/computedPropertyNames36_ES6.js index 5b71326fbc459..573b8fa0c17b4 100644 --- a/tests/baselines/reference/computedPropertyNames36_ES6.js +++ b/tests/baselines/reference/computedPropertyNames36_ES6.js @@ -11,32 +11,15 @@ class C { } //// [computedPropertyNames36_ES6.js] -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { +class Foo { +} +class Foo2 { +} +class C { + // Computed properties + get ["get1"]() { + return new Foo; } - return Foo2; -})(); -var C = (function () { - function C() { + set ["set1"](p) { } - Object.defineProperty(C.prototype, "get1", { - // Computed properties - get: function () { - return new Foo; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, "set1", { - set: function (p) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); +} diff --git a/tests/baselines/reference/computedPropertyNames37_ES6.js b/tests/baselines/reference/computedPropertyNames37_ES6.js index 992035f68657d..d62c95e6f8c12 100644 --- a/tests/baselines/reference/computedPropertyNames37_ES6.js +++ b/tests/baselines/reference/computedPropertyNames37_ES6.js @@ -11,32 +11,15 @@ class C { } //// [computedPropertyNames37_ES6.js] -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { +class Foo { +} +class Foo2 { +} +class C { + // Computed properties + get ["get1"]() { + return new Foo; } - return Foo2; -})(); -var C = (function () { - function C() { + set ["set1"](p) { } - Object.defineProperty(C.prototype, "get1", { - // Computed properties - get: function () { - return new Foo; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, "set1", { - set: function (p) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); +} diff --git a/tests/baselines/reference/computedPropertyNames38_ES6.js b/tests/baselines/reference/computedPropertyNames38_ES6.js index 0fdcdb1d63cb9..cf1d01873f296 100644 --- a/tests/baselines/reference/computedPropertyNames38_ES6.js +++ b/tests/baselines/reference/computedPropertyNames38_ES6.js @@ -11,32 +11,15 @@ class C { } //// [computedPropertyNames38_ES6.js] -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { +class Foo { +} +class Foo2 { +} +class C { + // Computed properties + get [1 << 6]() { + return new Foo; } - return Foo2; -})(); -var C = (function () { - function C() { + set [1 << 6](p) { } - Object.defineProperty(C.prototype, 1 << 6, { - // Computed properties - get: function () { - return new Foo; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, 1 << 6, { - set: function (p) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); +} diff --git a/tests/baselines/reference/computedPropertyNames39_ES6.js b/tests/baselines/reference/computedPropertyNames39_ES6.js index 8e458ad83d7df..9afd60b6464ef 100644 --- a/tests/baselines/reference/computedPropertyNames39_ES6.js +++ b/tests/baselines/reference/computedPropertyNames39_ES6.js @@ -11,32 +11,15 @@ class C { } //// [computedPropertyNames39_ES6.js] -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { +class Foo { +} +class Foo2 { +} +class C { + // Computed properties + get [1 << 6]() { + return new Foo; } - return Foo2; -})(); -var C = (function () { - function C() { + set [1 << 6](p) { } - Object.defineProperty(C.prototype, 1 << 6, { - // Computed properties - get: function () { - return new Foo; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, 1 << 6, { - set: function (p) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); +} diff --git a/tests/baselines/reference/computedPropertyNames3_ES6.errors.txt b/tests/baselines/reference/computedPropertyNames3_ES6.errors.txt index 3df6d6d97440d..b90091123473a 100644 --- a/tests/baselines/reference/computedPropertyNames3_ES6.errors.txt +++ b/tests/baselines/reference/computedPropertyNames3_ES6.errors.txt @@ -1,12 +1,13 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(4,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(5,9): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(5,9): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(5,17): error TS1102: 'delete' cannot be called on an identifier in strict mode. tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(6,9): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(7,16): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(7,16): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. -==== tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts (6 errors) ==== +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts (7 errors) ==== var id; class C { [0 + 1]() { } @@ -18,6 +19,8 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(7,1 !!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. ~~~~~~~~~~~ !!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. + ~~ +!!! error TS1102: 'delete' cannot be called on an identifier in strict mode. set [[0, 1]](v) { } ~~~~~~~~ !!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. diff --git a/tests/baselines/reference/computedPropertyNames3_ES6.js b/tests/baselines/reference/computedPropertyNames3_ES6.js index 1a9c9ee465b2e..b5fb9e88001f4 100644 --- a/tests/baselines/reference/computedPropertyNames3_ES6.js +++ b/tests/baselines/reference/computedPropertyNames3_ES6.js @@ -11,40 +11,21 @@ class C { //// [computedPropertyNames3_ES6.js] var id; -var C = (function () { - function C() { +class C { + [0 + 1]() { } - C.prototype[0 + 1] = function () { - }; - C[() => { - }] = function () { - }; - Object.defineProperty(C.prototype, delete id, { - get: function () { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, [ + static [() => { + }]() { + } + get [delete id]() { + } + set [[ 0, 1 - ], { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, "", { - get: function () { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, id.toString(), { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); + ]](v) { + } + static get [""]() { + } + static set [id.toString()](v) { + } +} diff --git a/tests/baselines/reference/computedPropertyNames40_ES6.js b/tests/baselines/reference/computedPropertyNames40_ES6.js index 99d28688a298f..c4820e0ca9823 100644 --- a/tests/baselines/reference/computedPropertyNames40_ES6.js +++ b/tests/baselines/reference/computedPropertyNames40_ES6.js @@ -11,25 +11,16 @@ class C { } //// [computedPropertyNames40_ES6.js] -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { - } - return Foo2; -})(); -var C = (function () { - function C() { - } +class Foo { +} +class Foo2 { +} +class C { // Computed properties - C.prototype[""] = function () { + [""]() { return new Foo; - }; - C.prototype[""] = function () { + } + [""]() { return new Foo2; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/computedPropertyNames41_ES6.js b/tests/baselines/reference/computedPropertyNames41_ES6.js index f0c386706a3f7..5773f892fd597 100644 --- a/tests/baselines/reference/computedPropertyNames41_ES6.js +++ b/tests/baselines/reference/computedPropertyNames41_ES6.js @@ -10,22 +10,13 @@ class C { } //// [computedPropertyNames41_ES6.js] -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { - } - return Foo2; -})(); -var C = (function () { - function C() { - } +class Foo { +} +class Foo2 { +} +class C { // Computed properties - C[""] = function () { + static [""]() { return new Foo; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/computedPropertyNames42_ES6.js b/tests/baselines/reference/computedPropertyNames42_ES6.js index 8538088f4500a..b6114f06bac84 100644 --- a/tests/baselines/reference/computedPropertyNames42_ES6.js +++ b/tests/baselines/reference/computedPropertyNames42_ES6.js @@ -10,18 +10,9 @@ class C { } //// [computedPropertyNames42_ES6.js] -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { - } - return Foo2; -})(); -var C = (function () { - function C() { - } - return C; -})(); +class Foo { +} +class Foo2 { +} +class C { +} diff --git a/tests/baselines/reference/computedPropertyNames43_ES6.js b/tests/baselines/reference/computedPropertyNames43_ES6.js index ba0c228c30738..ab9d09834d20a 100644 --- a/tests/baselines/reference/computedPropertyNames43_ES6.js +++ b/tests/baselines/reference/computedPropertyNames43_ES6.js @@ -13,45 +13,17 @@ class D extends C { } //// [computedPropertyNames43_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { - } - return Foo2; -})(); -var C = (function () { - function C() { +class Foo { +} +class Foo2 { +} +class C { +} +class D extends C { + // Computed properties + get ["get1"]() { + return new Foo; } - return C; -})(); -var D = (function (_super) { - __extends(D, _super); - function D() { - _super.apply(this, arguments); + set ["set1"](p) { } - Object.defineProperty(D.prototype, "get1", { - // Computed properties - get: function () { - return new Foo; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(D.prototype, "set1", { - set: function (p) { - }, - enumerable: true, - configurable: true - }); - return D; -})(C); +} diff --git a/tests/baselines/reference/computedPropertyNames44_ES6.js b/tests/baselines/reference/computedPropertyNames44_ES6.js index 72729054e076f..13d46131e924b 100644 --- a/tests/baselines/reference/computedPropertyNames44_ES6.js +++ b/tests/baselines/reference/computedPropertyNames44_ES6.js @@ -12,44 +12,16 @@ class D extends C { } //// [computedPropertyNames44_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { - } - return Foo2; -})(); -var C = (function () { - function C() { +class Foo { +} +class Foo2 { +} +class C { + get ["get1"]() { + return new Foo; } - Object.defineProperty(C.prototype, "get1", { - get: function () { - return new Foo; - }, - enumerable: true, - configurable: true - }); - return C; -})(); -var D = (function (_super) { - __extends(D, _super); - function D() { - _super.apply(this, arguments); +} +class D extends C { + set ["set1"](p) { } - Object.defineProperty(D.prototype, "set1", { - set: function (p) { - }, - enumerable: true, - configurable: true - }); - return D; -})(C); +} diff --git a/tests/baselines/reference/computedPropertyNames45_ES6.js b/tests/baselines/reference/computedPropertyNames45_ES6.js index 23dccc7795691..bea5f5211ea7d 100644 --- a/tests/baselines/reference/computedPropertyNames45_ES6.js +++ b/tests/baselines/reference/computedPropertyNames45_ES6.js @@ -13,44 +13,16 @@ class D extends C { } //// [computedPropertyNames45_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { - } - return Foo2; -})(); -var C = (function () { - function C() { +class Foo { +} +class Foo2 { +} +class C { + get ["get1"]() { + return new Foo; } - Object.defineProperty(C.prototype, "get1", { - get: function () { - return new Foo; - }, - enumerable: true, - configurable: true - }); - return C; -})(); -var D = (function (_super) { - __extends(D, _super); - function D() { - _super.apply(this, arguments); +} +class D extends C { + set ["set1"](p) { } - Object.defineProperty(D.prototype, "set1", { - set: function (p) { - }, - enumerable: true, - configurable: true - }); - return D; -})(C); +} diff --git a/tests/baselines/reference/computedPropertyNames47_ES5.js b/tests/baselines/reference/computedPropertyNames47_ES5.js index 7d839e16ffb7d..a2fff2110b49f 100644 --- a/tests/baselines/reference/computedPropertyNames47_ES5.js +++ b/tests/baselines/reference/computedPropertyNames47_ES5.js @@ -15,6 +15,6 @@ var E2; E2[E2["x"] = 0] = "x"; })(E2 || (E2 = {})); var o = (_a = {}, - _a[0 /* x */ || 0 /* x */] = 0, + _a[E1.x || E2.x] = 0, _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames47_ES6.js b/tests/baselines/reference/computedPropertyNames47_ES6.js index e104d33e7d37c..0b6cb352999c3 100644 --- a/tests/baselines/reference/computedPropertyNames47_ES6.js +++ b/tests/baselines/reference/computedPropertyNames47_ES6.js @@ -15,5 +15,5 @@ var E2; E2[E2["x"] = 0] = "x"; })(E2 || (E2 = {})); var o = { - [0 /* x */ || 0 /* x */]: 0 + [E1.x || E2.x]: 0 }; diff --git a/tests/baselines/reference/computedPropertyNames48_ES5.js b/tests/baselines/reference/computedPropertyNames48_ES5.js index c5ca0d5b241a2..55b08ef8301d3 100644 --- a/tests/baselines/reference/computedPropertyNames48_ES5.js +++ b/tests/baselines/reference/computedPropertyNames48_ES5.js @@ -27,7 +27,7 @@ extractIndexer((_a = {}, _a[a] = "", _a)); // Should return string extractIndexer((_b = {}, - _b[0 /* x */] = "", + _b[E.x] = "", _b)); // Should return string extractIndexer((_c = {}, _c["" || 0] = "", diff --git a/tests/baselines/reference/computedPropertyNames48_ES6.js b/tests/baselines/reference/computedPropertyNames48_ES6.js index 2782164756580..8e54d67238c21 100644 --- a/tests/baselines/reference/computedPropertyNames48_ES6.js +++ b/tests/baselines/reference/computedPropertyNames48_ES6.js @@ -27,7 +27,7 @@ extractIndexer({ [a]: "" }); // Should return string extractIndexer({ - [0 /* x */]: "" + [E.x]: "" }); // Should return string extractIndexer({ ["" || 0]: "" diff --git a/tests/baselines/reference/computedPropertyNames7_ES5.js b/tests/baselines/reference/computedPropertyNames7_ES5.js index 9c23dcab20d04..01cf2efc030b8 100644 --- a/tests/baselines/reference/computedPropertyNames7_ES5.js +++ b/tests/baselines/reference/computedPropertyNames7_ES5.js @@ -12,6 +12,6 @@ var E; E[E["member"] = 0] = "member"; })(E || (E = {})); var v = (_a = {}, - _a[0 /* member */] = 0, + _a[E.member] = 0, _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames7_ES6.js b/tests/baselines/reference/computedPropertyNames7_ES6.js index 5714fb747a6a3..ee1e1c85c06a8 100644 --- a/tests/baselines/reference/computedPropertyNames7_ES6.js +++ b/tests/baselines/reference/computedPropertyNames7_ES6.js @@ -12,5 +12,5 @@ var E; E[E["member"] = 0] = "member"; })(E || (E = {})); var v = { - [0 /* member */]: 0 + [E.member]: 0 }; diff --git a/tests/baselines/reference/computedPropertyNamesDeclarationEmit1_ES6.js b/tests/baselines/reference/computedPropertyNamesDeclarationEmit1_ES6.js index eb7dab0b660f4..f234ae0d97e2b 100644 --- a/tests/baselines/reference/computedPropertyNamesDeclarationEmit1_ES6.js +++ b/tests/baselines/reference/computedPropertyNamesDeclarationEmit1_ES6.js @@ -6,26 +6,15 @@ class C { } //// [computedPropertyNamesDeclarationEmit1_ES6.js] -var C = (function () { - function C() { +class C { + ["" + ""]() { } - C.prototype["" + ""] = function () { - }; - Object.defineProperty(C.prototype, "" + "", { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, "" + "", { - set: function (x) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); + get ["" + ""]() { + return 0; + } + set ["" + ""](x) { + } +} //// [computedPropertyNamesDeclarationEmit1_ES6.d.ts] diff --git a/tests/baselines/reference/computedPropertyNamesDeclarationEmit2_ES6.js b/tests/baselines/reference/computedPropertyNamesDeclarationEmit2_ES6.js index 3912113905c84..b5e70193b0d11 100644 --- a/tests/baselines/reference/computedPropertyNamesDeclarationEmit2_ES6.js +++ b/tests/baselines/reference/computedPropertyNamesDeclarationEmit2_ES6.js @@ -6,26 +6,15 @@ class C { } //// [computedPropertyNamesDeclarationEmit2_ES6.js] -var C = (function () { - function C() { +class C { + static ["" + ""]() { } - C["" + ""] = function () { - }; - Object.defineProperty(C, "" + "", { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, "" + "", { - set: function (x) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); + static get ["" + ""]() { + return 0; + } + static set ["" + ""](x) { + } +} //// [computedPropertyNamesDeclarationEmit2_ES6.d.ts] diff --git a/tests/baselines/reference/computedPropertyNamesOnOverloads_ES6.js b/tests/baselines/reference/computedPropertyNamesOnOverloads_ES6.js index 264a6a75074b1..ced0a8d449a2e 100644 --- a/tests/baselines/reference/computedPropertyNamesOnOverloads_ES6.js +++ b/tests/baselines/reference/computedPropertyNamesOnOverloads_ES6.js @@ -10,10 +10,7 @@ class C { //// [computedPropertyNamesOnOverloads_ES6.js] var methodName = "method"; var accessorName = "accessor"; -var C = (function () { - function C() { +class C { + [methodName](v) { } - C.prototype[methodName] = function (v) { - }; - return C; -})(); +} diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js index f7dc9e1783690..749ab99b18b02 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js +++ b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js @@ -6,12 +6,9 @@ class C { } //// [computedPropertyNamesSourceMap1_ES6.js] -var C = (function () { - function C() { - } - C.prototype["hello"] = function () { +class C { + ["hello"]() { debugger; - }; - return C; -})(); + } +} //# sourceMappingURL=computedPropertyNamesSourceMap1_ES6.js.map \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js.map b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js.map index 20765a5b2d4e2..9a2dd60999ef8 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js.map +++ b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js.map @@ -1,2 +1,2 @@ //// [computedPropertyNamesSourceMap1_ES6.js.map] -{"version":3,"file":"computedPropertyNamesSourceMap1_ES6.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap1_ES6.ts"],"names":["C","C.constructor","C[\"hello\"]"],"mappings":"AAAA;IAAAA;IAIAC,CAACA;IAHGD,YAACA,OAAOA,CAACA,GAATA;QACIE,QAAQA,CAACA;IACbA,CAACA;IACLF,QAACA;AAADA,CAACA,AAJD,IAIC"} \ No newline at end of file +{"version":3,"file":"computedPropertyNamesSourceMap1_ES6.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap1_ES6.ts"],"names":["C","C[\"hello\"]"],"mappings":"AAAA;IACIA,CAACA,OAAOA,CAACA;QACLC,QAAQA,CAACA;IACbA,CAACA;AACLD,CAACA;AAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.sourcemap.txt b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.sourcemap.txt index 64713447e4333..30493b9734737 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.sourcemap.txt +++ b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.sourcemap.txt @@ -8,96 +8,61 @@ sources: computedPropertyNamesSourceMap1_ES6.ts emittedFile:tests/cases/conformance/es6/computedProperties/computedPropertyNamesSourceMap1_ES6.js sourceFile:computedPropertyNamesSourceMap1_ES6.ts ------------------------------------------------------------------- ->>>var C = (function () { +>>>class C { 1 > -2 >^^^^^^^^^^^^^^^^^^^-> +2 >^^^^^^^^^^^^^^^^^^-> 1 > 1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0) --- ->>> function C() { -1->^^^^ -2 > ^^-> -1-> -1->Emitted(2, 5) Source(1, 1) + SourceIndex(0) name (C) ---- ->>> } +>>> ["hello"]() { 1->^^^^ 2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^^^ +4 > ^ +5 > ^^^^^-> 1->class C { - > ["hello"]() { - > debugger; - > } - > -2 > } -1->Emitted(3, 5) Source(5, 1) + SourceIndex(0) name (C.constructor) -2 >Emitted(3, 6) Source(5, 2) + SourceIndex(0) name (C.constructor) ---- ->>> C.prototype["hello"] = function () { -1->^^^^ -2 > ^^^^^^^^^^^^ -3 > ^^^^^^^ -4 > ^ -5 > ^^^ -1-> + > 2 > [ -3 > "hello" -4 > ] -5 > -1->Emitted(4, 5) Source(2, 5) + SourceIndex(0) name (C) -2 >Emitted(4, 17) Source(2, 6) + SourceIndex(0) name (C) -3 >Emitted(4, 24) Source(2, 13) + SourceIndex(0) name (C) -4 >Emitted(4, 25) Source(2, 14) + SourceIndex(0) name (C) -5 >Emitted(4, 28) Source(2, 5) + SourceIndex(0) name (C) +3 > "hello" +4 > ] +1->Emitted(2, 5) Source(2, 5) + SourceIndex(0) name (C) +2 >Emitted(2, 6) Source(2, 6) + SourceIndex(0) name (C) +3 >Emitted(2, 13) Source(2, 13) + SourceIndex(0) name (C) +4 >Emitted(2, 14) Source(2, 14) + SourceIndex(0) name (C) --- >>> debugger; -1 >^^^^^^^^ +1->^^^^^^^^ 2 > ^^^^^^^^ 3 > ^ -1 >["hello"]() { +1->() { > 2 > debugger 3 > ; -1 >Emitted(5, 9) Source(3, 9) + SourceIndex(0) name (C["hello"]) -2 >Emitted(5, 17) Source(3, 17) + SourceIndex(0) name (C["hello"]) -3 >Emitted(5, 18) Source(3, 18) + SourceIndex(0) name (C["hello"]) +1->Emitted(3, 9) Source(3, 9) + SourceIndex(0) name (C["hello"]) +2 >Emitted(3, 17) Source(3, 17) + SourceIndex(0) name (C["hello"]) +3 >Emitted(3, 18) Source(3, 18) + SourceIndex(0) name (C["hello"]) --- ->>> }; +>>> } 1 >^^^^ 2 > ^ -3 > ^^^^^^^^^-> 1 > > 2 > } -1 >Emitted(6, 5) Source(4, 5) + SourceIndex(0) name (C["hello"]) -2 >Emitted(6, 6) Source(4, 6) + SourceIndex(0) name (C["hello"]) ---- ->>> return C; -1->^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(7, 5) Source(5, 1) + SourceIndex(0) name (C) -2 >Emitted(7, 13) Source(5, 2) + SourceIndex(0) name (C) +1 >Emitted(4, 5) Source(4, 5) + SourceIndex(0) name (C["hello"]) +2 >Emitted(4, 6) Source(4, 6) + SourceIndex(0) name (C["hello"]) --- ->>>})(); +>>>} 1 > 2 >^ -3 > -4 > ^^^^ -5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > 2 >} -3 > -4 > class C { - > ["hello"]() { - > debugger; - > } - > } -1 >Emitted(8, 1) Source(5, 1) + SourceIndex(0) name (C) -2 >Emitted(8, 2) Source(5, 2) + SourceIndex(0) name (C) -3 >Emitted(8, 2) Source(1, 1) + SourceIndex(0) -4 >Emitted(8, 6) Source(5, 2) + SourceIndex(0) +1 >Emitted(5, 1) Source(5, 1) + SourceIndex(0) name (C) +2 >Emitted(5, 2) Source(5, 2) + SourceIndex(0) name (C) --- ->>>//# sourceMappingURL=computedPropertyNamesSourceMap1_ES6.js.map \ No newline at end of file +>>>//# sourceMappingURL=computedPropertyNamesSourceMap1_ES6.js.map1-> +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1-> +1->Emitted(6, 1) Source(5, 2) + SourceIndex(0) +--- \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesWithStaticProperty.js b/tests/baselines/reference/computedPropertyNamesWithStaticProperty.js new file mode 100644 index 0000000000000..e6b7bd5aae2de --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesWithStaticProperty.js @@ -0,0 +1,24 @@ +//// [computedPropertyNamesWithStaticProperty.ts] +class C { + static staticProp = 10; + get [C.staticProp]() { + return "hello"; + } + set [C.staticProp](x: string) { + var y = x; + } + [C.staticProp]() { } +} + +//// [computedPropertyNamesWithStaticProperty.js] +class C { + get [C.staticProp]() { + return "hello"; + } + set [C.staticProp](x) { + var y = x; + } + [C.staticProp]() { + } +} +C.staticProp = 10; diff --git a/tests/baselines/reference/computedPropertyNamesWithStaticProperty.types b/tests/baselines/reference/computedPropertyNamesWithStaticProperty.types new file mode 100644 index 0000000000000..b23d986f89450 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesWithStaticProperty.types @@ -0,0 +1,29 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNamesWithStaticProperty.ts === +class C { +>C : C + + static staticProp = 10; +>staticProp : number + + get [C.staticProp]() { +>C.staticProp : number +>C : typeof C +>staticProp : number + + return "hello"; + } + set [C.staticProp](x: string) { +>C.staticProp : number +>C : typeof C +>staticProp : number +>x : string + + var y = x; +>y : string +>x : string + } + [C.staticProp]() { } +>C.staticProp : number +>C : typeof C +>staticProp : number +} diff --git a/tests/baselines/reference/constDeclarations-access5.errors.txt b/tests/baselines/reference/constDeclarations-access5.errors.txt index 23200e50ee42b..a098b0e72c672 100644 --- a/tests/baselines/reference/constDeclarations-access5.errors.txt +++ b/tests/baselines/reference/constDeclarations-access5.errors.txt @@ -1,3 +1,5 @@ +error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +tests/cases/compiler/constDeclarations_access_2.ts(2,1): error TS1202: Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead. tests/cases/compiler/constDeclarations_access_2.ts(4,1): error TS2450: Left-hand side of assignment expression cannot be a constant. tests/cases/compiler/constDeclarations_access_2.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant. tests/cases/compiler/constDeclarations_access_2.ts(6,1): error TS2450: Left-hand side of assignment expression cannot be a constant. @@ -18,9 +20,12 @@ tests/cases/compiler/constDeclarations_access_2.ts(22,3): error TS2449: The oper tests/cases/compiler/constDeclarations_access_2.ts(24,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -==== tests/cases/compiler/constDeclarations_access_2.ts (18 errors) ==== +!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +==== tests/cases/compiler/constDeclarations_access_2.ts (19 errors) ==== /// import m = require('constDeclarations_access_1'); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1202: Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead. // Errors m.x = 1; ~~~ diff --git a/tests/baselines/reference/constDeclarations-access5.js b/tests/baselines/reference/constDeclarations-access5.js index 7acc95ad05501..313ce3db21a8c 100644 --- a/tests/baselines/reference/constDeclarations-access5.js +++ b/tests/baselines/reference/constDeclarations-access5.js @@ -49,41 +49,37 @@ m.x.toString(); //// [constDeclarations_access_1.js] -define(["require", "exports"], function (require, exports) { - exports.x = 0; -}); +export const x = 0; //// [constDeclarations_access_2.js] -define(["require", "exports", 'constDeclarations_access_1'], function (require, exports, m) { - // Errors - m.x = 1; - m.x += 2; - m.x -= 3; - m.x *= 4; - m.x /= 5; - m.x %= 6; - m.x <<= 7; - m.x >>= 8; - m.x >>>= 9; - m.x &= 10; - m.x |= 11; - m.x ^= 12; - m; - m.x++; - m.x--; - ++m.x; - --m.x; - ++((m.x)); - m["x"] = 0; - // OK - var a = m.x + 1; - function f(v) { - } - f(m.x); - if (m.x) { - } - m.x; - (m.x); - -m.x; - +m.x; - m.x.toString(); -}); +// Errors +m.x = 1; +m.x += 2; +m.x -= 3; +m.x *= 4; +m.x /= 5; +m.x %= 6; +m.x <<= 7; +m.x >>= 8; +m.x >>>= 9; +m.x &= 10; +m.x |= 11; +m.x ^= 12; +m; +m.x++; +m.x--; +++m.x; +--m.x; +++((m.x)); +m["x"] = 0; +// OK +var a = m.x + 1; +function f(v) { +} +f(m.x); +if (m.x) { +} +m.x; +(m.x); +-m.x; ++m.x; +m.x.toString(); diff --git a/tests/baselines/reference/constDeclarations-scopes.js b/tests/baselines/reference/constDeclarations-scopes.js index f8fbc47312b1b..b144b4f83a553 100644 --- a/tests/baselines/reference/constDeclarations-scopes.js +++ b/tests/baselines/reference/constDeclarations-scopes.js @@ -242,30 +242,25 @@ var m; } })(m || (m = {})); // methods -var C = (function () { - function C() { +class C { + constructor() { const c = 0; n = c; } - C.prototype.method = function () { + method() { const c = 0; n = c; - }; - Object.defineProperty(C.prototype, "v", { - get: function () { - const c = 0; - n = c; - return n; - }, - set: function (value) { - const c = 0; - n = c; - }, - enumerable: true, - configurable: true - }); - return C; -})(); + } + get v() { + const c = 0; + n = c; + return n; + } + set v(value) { + const c = 0; + n = c; + } +} // object literals var o = { f() { diff --git a/tests/baselines/reference/constDeclarations-validContexts.js b/tests/baselines/reference/constDeclarations-validContexts.js index 5a54e915713ad..7d3269c66832d 100644 --- a/tests/baselines/reference/constDeclarations-validContexts.js +++ b/tests/baselines/reference/constDeclarations-validContexts.js @@ -201,26 +201,21 @@ var m; } })(m || (m = {})); // methods -var C = (function () { - function C() { +class C { + constructor() { const c24 = 0; } - C.prototype.method = function () { + method() { const c25 = 0; - }; - Object.defineProperty(C.prototype, "v", { - get: function () { - const c26 = 0; - return c26; - }, - set: function (value) { - const c27 = value; - }, - enumerable: true, - configurable: true - }); - return C; -})(); + } + get v() { + const c26 = 0; + return c26; + } + set v(value) { + const c27 = value; + } +} // object literals var o = { f() { diff --git a/tests/baselines/reference/constEnumOnlyModuleMerging.js b/tests/baselines/reference/constEnumOnlyModuleMerging.js new file mode 100644 index 0000000000000..1d32fe748ab1b --- /dev/null +++ b/tests/baselines/reference/constEnumOnlyModuleMerging.js @@ -0,0 +1,26 @@ +//// [constEnumOnlyModuleMerging.ts] +module Outer { + export var x = 1; +} + +module Outer { + export const enum A { X } +} + +module B { + import O = Outer; + var x = O.A.X; + var y = O.x; +} + +//// [constEnumOnlyModuleMerging.js] +var Outer; +(function (Outer) { + Outer.x = 1; +})(Outer || (Outer = {})); +var B; +(function (B) { + var O = Outer; + var x = 0 /* X */; + var y = O.x; +})(B || (B = {})); diff --git a/tests/baselines/reference/constEnumOnlyModuleMerging.types b/tests/baselines/reference/constEnumOnlyModuleMerging.types new file mode 100644 index 0000000000000..30426e3fa4ce9 --- /dev/null +++ b/tests/baselines/reference/constEnumOnlyModuleMerging.types @@ -0,0 +1,37 @@ +=== tests/cases/compiler/constEnumOnlyModuleMerging.ts === +module Outer { +>Outer : typeof Outer + + export var x = 1; +>x : number +} + +module Outer { +>Outer : typeof Outer + + export const enum A { X } +>A : A +>X : A +} + +module B { +>B : typeof B + + import O = Outer; +>O : typeof O +>Outer : typeof O + + var x = O.A.X; +>x : O.A +>O.A.X : O.A +>O.A : typeof O.A +>O : typeof O +>A : typeof O.A +>X : O.A + + var y = O.x; +>y : number +>O.x : number +>O : typeof O +>x : number +} diff --git a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.js b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.js index 566213887f46d..0bc51e90c5cce 100644 --- a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.js +++ b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.js @@ -369,7 +369,7 @@ var BasicFeatures = (function () { return 'objLit{42}'; } }; - var weekday = 0 /* Monday */; + var weekday = Weekdays.Monday; var con = char + f + hexchar + float.toString() + float2.toString() + reg.toString() + objLit + weekday; // var any = 0 ^= ; diff --git a/tests/baselines/reference/declFileEnums.js b/tests/baselines/reference/declFileEnums.js index 97559f05574bc..34f1e386a964a 100644 --- a/tests/baselines/reference/declFileEnums.js +++ b/tests/baselines/reference/declFileEnums.js @@ -46,14 +46,14 @@ var e1; var e2; (function (e2) { e2[e2["a"] = 10] = "a"; - e2[e2["b"] = e2.a + 2] = "b"; + e2[e2["b"] = 12] = "b"; e2[e2["c"] = 10] = "c"; })(e2 || (e2 = {})); var e3; (function (e3) { e3[e3["a"] = 10] = "a"; e3[e3["b"] = Math.PI] = "b"; - e3[e3["c"] = e3.a + 3] = "c"; + e3[e3["c"] = 13] = "c"; })(e3 || (e3 = {})); var e4; (function (e4) { @@ -80,13 +80,13 @@ declare enum e1 { } declare enum e2 { a = 10, - b, + b = 12, c = 10, } declare enum e3 { a = 10, b, - c, + c = 13, } declare enum e4 { a = 0, diff --git a/tests/baselines/reference/declFileImportChainInExportAssignment.js b/tests/baselines/reference/declFileImportChainInExportAssignment.js index c8773889a7d0b..4ec3893d02fa8 100644 --- a/tests/baselines/reference/declFileImportChainInExportAssignment.js +++ b/tests/baselines/reference/declFileImportChainInExportAssignment.js @@ -13,13 +13,13 @@ export = b; var m; (function (m) { var c; - (function (_c) { + (function (c_1) { var c = (function () { function c() { } return c; })(); - _c.c = c; + c_1.c = c; })(c = m.c || (m.c = {})); })(m || (m = {})); var a = m.c; diff --git a/tests/baselines/reference/declFileTypeofEnum.js b/tests/baselines/reference/declFileTypeofEnum.js index 8ced6f9e59554..5b1c697747230 100644 --- a/tests/baselines/reference/declFileTypeofEnum.js +++ b/tests/baselines/reference/declFileTypeofEnum.js @@ -25,7 +25,7 @@ var days; days[days["saturday"] = 5] = "saturday"; days[days["sunday"] = 6] = "sunday"; })(days || (days = {})); -var weekendDay = 5 /* saturday */; +var weekendDay = days.saturday; var daysOfMonth = days; var daysOfYear; diff --git a/tests/baselines/reference/declFileTypeofInAnonymousType.js b/tests/baselines/reference/declFileTypeofInAnonymousType.js index ab812720d9a21..1a5071fd2197d 100644 --- a/tests/baselines/reference/declFileTypeofInAnonymousType.js +++ b/tests/baselines/reference/declFileTypeofInAnonymousType.js @@ -56,7 +56,7 @@ var d = { me: { en: m1.e }, - mh: 2 /* holiday */ + mh: m1.e.holiday }; diff --git a/tests/baselines/reference/declarationEmitDefaultExport1.js b/tests/baselines/reference/declarationEmitDefaultExport1.js new file mode 100644 index 0000000000000..197e4fc9cc833 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport1.js @@ -0,0 +1,12 @@ +//// [declarationEmitDefaultExport1.ts] +export default class C { +} + +//// [declarationEmitDefaultExport1.js] +export default class C { +} + + +//// [declarationEmitDefaultExport1.d.ts] +export default class C { +} diff --git a/tests/baselines/reference/declarationEmitDefaultExport1.types b/tests/baselines/reference/declarationEmitDefaultExport1.types new file mode 100644 index 0000000000000..41dd3547b6d66 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport1.types @@ -0,0 +1,4 @@ +=== tests/cases/compiler/declarationEmitDefaultExport1.ts === +export default class C { +>C : C +} diff --git a/tests/baselines/reference/declarationEmitDefaultExport2.js b/tests/baselines/reference/declarationEmitDefaultExport2.js new file mode 100644 index 0000000000000..687c6d67cdbaf --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport2.js @@ -0,0 +1,12 @@ +//// [declarationEmitDefaultExport2.ts] +export default class { +} + +//// [declarationEmitDefaultExport2.js] +export default class { +} + + +//// [declarationEmitDefaultExport2.d.ts] +export default class { +} diff --git a/tests/baselines/reference/declarationEmitDefaultExport2.types b/tests/baselines/reference/declarationEmitDefaultExport2.types new file mode 100644 index 0000000000000..b82e6cfb92376 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport2.types @@ -0,0 +1,4 @@ +=== tests/cases/compiler/declarationEmitDefaultExport2.ts === +export default class { +No type information for this code.} +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDefaultExport3.js b/tests/baselines/reference/declarationEmitDefaultExport3.js new file mode 100644 index 0000000000000..ba412a1b4b727 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport3.js @@ -0,0 +1,13 @@ +//// [declarationEmitDefaultExport3.ts] +export default function foo() { + return "" +} + +//// [declarationEmitDefaultExport3.js] +export default function foo() { + return ""; +} + + +//// [declarationEmitDefaultExport3.d.ts] +export default function foo(): string; diff --git a/tests/baselines/reference/declarationEmitDefaultExport3.types b/tests/baselines/reference/declarationEmitDefaultExport3.types new file mode 100644 index 0000000000000..0bde6eff91587 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport3.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/declarationEmitDefaultExport3.ts === +export default function foo() { +>foo : () => string + + return "" +} diff --git a/tests/baselines/reference/declarationEmitDefaultExport4.js b/tests/baselines/reference/declarationEmitDefaultExport4.js new file mode 100644 index 0000000000000..92f8ef8bb8125 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport4.js @@ -0,0 +1,13 @@ +//// [declarationEmitDefaultExport4.ts] +export default function () { + return 1; +} + +//// [declarationEmitDefaultExport4.js] +export default function () { + return 1; +} + + +//// [declarationEmitDefaultExport4.d.ts] +export default function (): number; diff --git a/tests/baselines/reference/declarationEmitDefaultExport4.types b/tests/baselines/reference/declarationEmitDefaultExport4.types new file mode 100644 index 0000000000000..8043af36b7620 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport4.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/declarationEmitDefaultExport4.ts === +export default function () { +No type information for this code. return 1; +No type information for this code.} +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDefaultExport5.js b/tests/baselines/reference/declarationEmitDefaultExport5.js new file mode 100644 index 0000000000000..a8794d92c6386 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport5.js @@ -0,0 +1,10 @@ +//// [declarationEmitDefaultExport5.ts] +export default 1 + 2; + + +//// [declarationEmitDefaultExport5.js] +export default 1 + 2; + + +//// [declarationEmitDefaultExport5.d.ts] +export default : number; diff --git a/tests/baselines/reference/declarationEmitDefaultExport5.types b/tests/baselines/reference/declarationEmitDefaultExport5.types new file mode 100644 index 0000000000000..702cc51f71ebf --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport5.types @@ -0,0 +1,4 @@ +=== tests/cases/compiler/declarationEmitDefaultExport5.ts === +export default 1 + 2; +>1 + 2 : number + diff --git a/tests/baselines/reference/declarationEmitDefaultExport6.js b/tests/baselines/reference/declarationEmitDefaultExport6.js new file mode 100644 index 0000000000000..d328458366efb --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport6.js @@ -0,0 +1,15 @@ +//// [declarationEmitDefaultExport6.ts] +export class A {} +export default new A(); + + +//// [declarationEmitDefaultExport6.js] +export class A { +} +export default new A(); + + +//// [declarationEmitDefaultExport6.d.ts] +export declare class A { +} +export default : A; diff --git a/tests/baselines/reference/declarationEmitDefaultExport6.types b/tests/baselines/reference/declarationEmitDefaultExport6.types new file mode 100644 index 0000000000000..9c839edb1a9aa --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport6.types @@ -0,0 +1,8 @@ +=== tests/cases/compiler/declarationEmitDefaultExport6.ts === +export class A {} +>A : A + +export default new A(); +>new A() : A +>A : typeof A + diff --git a/tests/baselines/reference/declarationEmitDefaultExport7.errors.txt b/tests/baselines/reference/declarationEmitDefaultExport7.errors.txt new file mode 100644 index 0000000000000..f19766cbb0093 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport7.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/declarationEmitDefaultExport7.ts(2,1): error TS4082: Default export of the module has or is using private name 'A'. + + +==== tests/cases/compiler/declarationEmitDefaultExport7.ts (1 errors) ==== + class A {} + export default new A(); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS4082: Default export of the module has or is using private name 'A'. + \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDefaultExport7.js b/tests/baselines/reference/declarationEmitDefaultExport7.js new file mode 100644 index 0000000000000..99751113dd66d --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport7.js @@ -0,0 +1,9 @@ +//// [declarationEmitDefaultExport7.ts] +class A {} +export default new A(); + + +//// [declarationEmitDefaultExport7.js] +class A { +} +export default new A(); diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.js new file mode 100644 index 0000000000000..7ee32cab16c36 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.js @@ -0,0 +1,44 @@ +//// [declarationEmitDestructuringArrayPattern1.ts] + +var [] = [1, "hello"]; // Dont emit anything +var [x] = [1, "hello"]; // emit x: number +var [x1, y1] = [1, "hello"]; // emit x1: number, y1: string +var [, , z1] = [0, 1, 2]; // emit z1: number + +var a = [1, "hello"]; +var [x2] = a; // emit x2: number | string +var [x3, y3, z3] = a; // emit x3, y3, z3 + +//// [declarationEmitDestructuringArrayPattern1.js] +var _a = [ + 1, + "hello" +]; // Dont emit anything +var x = ([ + 1, + "hello" +])[0]; // emit x: number +var _b = [ + 1, + "hello" +], x1 = _b[0], y1 = _b[1]; // emit x1: number, y1: string +var _c = [ + 0, + 1, + 2 +], z1 = _c[2]; // emit z1: number +var a = [ + 1, + "hello" +]; +var x2 = a[0]; // emit x2: number | string +var x3 = a[0], y3 = a[1], z3 = a[2]; // emit x3, y3, z3 + + +//// [declarationEmitDestructuringArrayPattern1.d.ts] +declare var x: number; +declare var x1: number, y1: string; +declare var z1: number; +declare var a: (string | number)[]; +declare var x2: string | number; +declare var x3: string | number, y3: string | number, z3: string | number; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.types new file mode 100644 index 0000000000000..9f6f4c9857d7d --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/declarationEmitDestructuringArrayPattern1.ts === + +var [] = [1, "hello"]; // Dont emit anything +>[1, "hello"] : (string | number)[] + +var [x] = [1, "hello"]; // emit x: number +>x : number +>[1, "hello"] : [number, string] + +var [x1, y1] = [1, "hello"]; // emit x1: number, y1: string +>x1 : number +>y1 : string +>[1, "hello"] : [number, string] + +var [, , z1] = [0, 1, 2]; // emit z1: number +>z1 : number +>[0, 1, 2] : [number, number, number] + +var a = [1, "hello"]; +>a : (string | number)[] +>[1, "hello"] : (string | number)[] + +var [x2] = a; // emit x2: number | string +>x2 : string | number +>a : (string | number)[] + +var [x3, y3, z3] = a; // emit x3, y3, z3 +>x3 : string | number +>y3 : string | number +>z3 : string | number +>a : (string | number)[] + diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.js new file mode 100644 index 0000000000000..5734b9bc6f9db --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.js @@ -0,0 +1,69 @@ +//// [declarationEmitDestructuringArrayPattern2.ts] +var [x10, [y10, [z10]]] = [1, ["hello", [true]]]; + +var [x11 = 0, y11 = ""] = [1, "hello"]; +var [a11, b11, c11] = []; + +var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello", { x12: 5, y12: true }]]; + +var [x13, y13] = [1, "hello"]; +var [a3, b3] = [[x13, y13], { x: x13, y: y13 }]; + + +//// [declarationEmitDestructuringArrayPattern2.js] +var _a = [ + 1, + [ + "hello", + [ + true + ] + ] +], x10 = _a[0], _b = _a[1], y10 = _b[0], z10 = _b[1][0]; +var _c = [ + 1, + "hello" +], _d = _c[0], x11 = _d === void 0 ? 0 : _d, _e = _c[1], y11 = _e === void 0 ? "" : _e; +var _f = [], a11 = _f[0], b11 = _f[1], c11 = _f[2]; +var _g = [ + 1, + [ + "hello", + { + x12: 5, + y12: true + } + ] +], a2 = _g[0], _h = _g[1], _j = _h === void 0 ? [ + "abc", + { + x12: 10, + y12: false + } +] : _h, b2 = _j[0], _k = _j[1], x12 = _k.x12, c2 = _k.y12; +var _l = [ + 1, + "hello" +], x13 = _l[0], y13 = _l[1]; +var _m = [ + [ + x13, + y13 + ], + { + x: x13, + y: y13 + } +], a3 = _m[0], b3 = _m[1]; + + +//// [declarationEmitDestructuringArrayPattern2.d.ts] +declare var x10: number, y10: string, z10: boolean; +declare var x11: number, y11: string; +declare var a11: any, b11: any, c11: any; +declare var a2: number, b2: string, x12: number, c2: boolean; +declare var x13: number, y13: string; +declare var a3: (string | number)[], b3: { + x: number; + y: string; +}; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types new file mode 100644 index 0000000000000..2b40a388e3ba9 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types @@ -0,0 +1,54 @@ +=== tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts === +var [x10, [y10, [z10]]] = [1, ["hello", [true]]]; +>x10 : number +>y10 : string +>z10 : boolean +>[1, ["hello", [true]]] : [number, [string, [boolean]]] +>["hello", [true]] : [string, [boolean]] +>[true] : [boolean] + +var [x11 = 0, y11 = ""] = [1, "hello"]; +>x11 : number +>y11 : string +>[1, "hello"] : [number, string] + +var [a11, b11, c11] = []; +>a11 : any +>b11 : any +>c11 : any +>[] : undefined[] + +var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello", { x12: 5, y12: true }]]; +>a2 : number +>b2 : string +>x12 : number +>y12 : unknown +>c2 : boolean +>["abc", { x12: 10, y12: false }] : [string, { x12: number; y12: boolean; }] +>{ x12: 10, y12: false } : { x12: number; y12: boolean; } +>x12 : number +>y12 : boolean +>[1, ["hello", { x12: 5, y12: true }]] : [number, [string, { x12: number; y12: boolean; }]] +>["hello", { x12: 5, y12: true }] : [string, { x12: number; y12: boolean; }] +>{ x12: 5, y12: true } : { x12: number; y12: boolean; } +>x12 : number +>y12 : boolean + +var [x13, y13] = [1, "hello"]; +>x13 : number +>y13 : string +>[1, "hello"] : [number, string] + +var [a3, b3] = [[x13, y13], { x: x13, y: y13 }]; +>a3 : (string | number)[] +>b3 : { x: number; y: string; } +>[[x13, y13], { x: x13, y: y13 }] : [(string | number)[], { x: number; y: string; }] +>[x13, y13] : (string | number)[] +>x13 : number +>y13 : string +>{ x: x13, y: y13 } : { x: number; y: string; } +>x : number +>x13 : number +>y : string +>y13 : string + diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern3.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern3.js new file mode 100644 index 0000000000000..258fa17d7ffbe --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern3.js @@ -0,0 +1,20 @@ +//// [declarationEmitDestructuringArrayPattern3.ts] +module M { + export var [a, b] = [1, 2]; +} + +//// [declarationEmitDestructuringArrayPattern3.js] +var M; +(function (M) { + _a = [ + 1, + 2 + ], M.a = _a[0], M.b = _a[1]; + var _a; +})(M || (M = {})); + + +//// [declarationEmitDestructuringArrayPattern3.d.ts] +declare module M { + var a: number, b: number; +} diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern3.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern3.types new file mode 100644 index 0000000000000..4852a7e37fb02 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern3.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/declarationEmitDestructuringArrayPattern3.ts === +module M { +>M : typeof M + + export var [a, b] = [1, 2]; +>a : number +>b : number +>[1, 2] : [number, number] +} diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js new file mode 100644 index 0000000000000..97a8c20b73bc3 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js @@ -0,0 +1,63 @@ +//// [declarationEmitDestructuringArrayPattern4.ts] +var [...a5] = [1, 2, 3]; +var [x14, ...a6] = [1, 2, 3]; +var [x15, y15, ...a7] = [1, 2, 3]; +var [x16, y16, z16, ...a8] = [1, 2, 3]; + +var [...a9] = [1, "hello", true]; +var [x17, ...a10] = [1, "hello", true]; +var [x18, y18, ...a12] = [1, "hello", true]; +var [x19, y19, z19, ...a13] = [1, "hello", true]; + +//// [declarationEmitDestructuringArrayPattern4.js] +var _a = [ + 1, + 2, + 3 +], a5 = _a.slice(0); +var _b = [ + 1, + 2, + 3 +], x14 = _b[0], a6 = _b.slice(1); +var _c = [ + 1, + 2, + 3 +], x15 = _c[0], y15 = _c[1], a7 = _c.slice(2); +var _d = [ + 1, + 2, + 3 +], x16 = _d[0], y16 = _d[1], z16 = _d[2], a8 = _d.slice(3); +var _e = [ + 1, + "hello", + true +], a9 = _e.slice(0); +var _f = [ + 1, + "hello", + true +], x17 = _f[0], a10 = _f.slice(1); +var _g = [ + 1, + "hello", + true +], x18 = _g[0], y18 = _g[1], a12 = _g.slice(2); +var _h = [ + 1, + "hello", + true +], x19 = _h[0], y19 = _h[1], z19 = _h[2], a13 = _h.slice(3); + + +//// [declarationEmitDestructuringArrayPattern4.d.ts] +declare var a5: number[]; +declare var x14: number, a6: number[]; +declare var x15: number, y15: number, a7: number[]; +declare var x16: number, y16: number, z16: number, a8: number[]; +declare var a9: (string | number | boolean)[]; +declare var x17: string | number | boolean, a10: (string | number | boolean)[]; +declare var x18: string | number | boolean, y18: string | number | boolean, a12: (string | number | boolean)[]; +declare var x19: string | number | boolean, y19: string | number | boolean, z19: string | number | boolean, a13: (string | number | boolean)[]; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types new file mode 100644 index 0000000000000..d6d0fa758d7b2 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types @@ -0,0 +1,45 @@ +=== tests/cases/compiler/declarationEmitDestructuringArrayPattern4.ts === +var [...a5] = [1, 2, 3]; +>a5 : number[] +>[1, 2, 3] : number[] + +var [x14, ...a6] = [1, 2, 3]; +>x14 : number +>a6 : number[] +>[1, 2, 3] : number[] + +var [x15, y15, ...a7] = [1, 2, 3]; +>x15 : number +>y15 : number +>a7 : number[] +>[1, 2, 3] : number[] + +var [x16, y16, z16, ...a8] = [1, 2, 3]; +>x16 : number +>y16 : number +>z16 : number +>a8 : number[] +>[1, 2, 3] : number[] + +var [...a9] = [1, "hello", true]; +>a9 : (string | number | boolean)[] +>[1, "hello", true] : (string | number | boolean)[] + +var [x17, ...a10] = [1, "hello", true]; +>x17 : string | number | boolean +>a10 : (string | number | boolean)[] +>[1, "hello", true] : (string | number | boolean)[] + +var [x18, y18, ...a12] = [1, "hello", true]; +>x18 : string | number | boolean +>y18 : string | number | boolean +>a12 : (string | number | boolean)[] +>[1, "hello", true] : (string | number | boolean)[] + +var [x19, y19, z19, ...a13] = [1, "hello", true]; +>x19 : string | number | boolean +>y19 : string | number | boolean +>z19 : string | number | boolean +>a13 : (string | number | boolean)[] +>[1, "hello", true] : (string | number | boolean)[] + diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.js b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.js new file mode 100644 index 0000000000000..9b48f418f5ad5 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.js @@ -0,0 +1,97 @@ +//// [declarationEmitDestructuringObjectLiteralPattern.ts] + +var { } = { x: 5, y: "hello" }; +var { x4 } = { x4: 5, y4: "hello" }; +var { y5 } = { x5: 5, y5: "hello" }; +var { x6, y6 } = { x6: 5, y6: "hello" }; +var { x7: a1 } = { x7: 5, y7: "hello" }; +var { y8: b1 } = { x8: 5, y8: "hello" }; +var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; + +var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; + +function f15() { + var a4 = "hello"; + var b4 = 1; + var c4 = true; + return { a4, b4, c4 }; +} +var { a4, b4, c4 } = f15(); + +module m { + export var { a4, b4, c4 } = f15(); +} + +//// [declarationEmitDestructuringObjectLiteralPattern.js] +var _a = { + x: 5, + y: "hello" +}; +var x4 = ({ + x4: 5, + y4: "hello" +}).x4; +var y5 = ({ + x5: 5, + y5: "hello" +}).y5; +var _b = { + x6: 5, + y6: "hello" +}, x6 = _b.x6, y6 = _b.y6; +var a1 = ({ + x7: 5, + y7: "hello" +}).x7; +var b1 = ({ + x8: 5, + y8: "hello" +}).y8; +var _c = { + x9: 5, + y9: "hello" +}, a2 = _c.x9, b2 = _c.y9; +var _d = { + a: 1, + b: { + a: "hello", + b: { + a: true + } + } +}, x11 = _d.a, _e = _d.b, y11 = _e.a, z11 = _e.b.a; +function f15() { + var a4 = "hello"; + var b4 = 1; + var c4 = true; + return { + a4: a4, + b4: b4, + c4: c4 + }; +} +var _f = f15(), a4 = _f.a4, b4 = _f.b4, c4 = _f.c4; +var m; +(function (m) { + _a = f15(), m.a4 = _a.a4, m.b4 = _a.b4, m.c4 = _a.c4; + var _a; +})(m || (m = {})); + + +//// [declarationEmitDestructuringObjectLiteralPattern.d.ts] +declare var x4: number; +declare var y5: string; +declare var x6: number, y6: string; +declare var a1: number; +declare var b1: string; +declare var a2: number, b2: string; +declare var x11: number, y11: string, z11: boolean; +declare function f15(): { + a4: string; + b4: number; + c4: boolean; +}; +declare var a4: string, b4: number, c4: boolean; +declare module m { + var a4: string, b4: number, c4: boolean; +} diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types new file mode 100644 index 0000000000000..b3c422e495842 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types @@ -0,0 +1,102 @@ +=== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts === + +var { } = { x: 5, y: "hello" }; +>{ x: 5, y: "hello" } : { x: number; y: string; } +>x : number +>y : string + +var { x4 } = { x4: 5, y4: "hello" }; +>x4 : number +>{ x4: 5, y4: "hello" } : { x4: number; y4: string; } +>x4 : number +>y4 : string + +var { y5 } = { x5: 5, y5: "hello" }; +>y5 : string +>{ x5: 5, y5: "hello" } : { x5: number; y5: string; } +>x5 : number +>y5 : string + +var { x6, y6 } = { x6: 5, y6: "hello" }; +>x6 : number +>y6 : string +>{ x6: 5, y6: "hello" } : { x6: number; y6: string; } +>x6 : number +>y6 : string + +var { x7: a1 } = { x7: 5, y7: "hello" }; +>x7 : unknown +>a1 : number +>{ x7: 5, y7: "hello" } : { x7: number; y7: string; } +>x7 : number +>y7 : string + +var { y8: b1 } = { x8: 5, y8: "hello" }; +>y8 : unknown +>b1 : string +>{ x8: 5, y8: "hello" } : { x8: number; y8: string; } +>x8 : number +>y8 : string + +var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; +>x9 : unknown +>a2 : number +>y9 : unknown +>b2 : string +>{ x9: 5, y9: "hello" } : { x9: number; y9: string; } +>x9 : number +>y9 : string + +var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; +>a : unknown +>x11 : number +>b : unknown +>a : unknown +>y11 : string +>b : unknown +>a : unknown +>z11 : boolean +>{ a: 1, b: { a: "hello", b: { a: true } } } : { a: number; b: { a: string; b: { a: boolean; }; }; } +>a : number +>b : { a: string; b: { a: boolean; }; } +>{ a: "hello", b: { a: true } } : { a: string; b: { a: boolean; }; } +>a : string +>b : { a: boolean; } +>{ a: true } : { a: boolean; } +>a : boolean + +function f15() { +>f15 : () => { a4: string; b4: number; c4: boolean; } + + var a4 = "hello"; +>a4 : string + + var b4 = 1; +>b4 : number + + var c4 = true; +>c4 : boolean + + return { a4, b4, c4 }; +>{ a4, b4, c4 } : { a4: string; b4: number; c4: boolean; } +>a4 : string +>b4 : number +>c4 : boolean +} +var { a4, b4, c4 } = f15(); +>a4 : string +>b4 : number +>c4 : boolean +>f15() : { a4: string; b4: number; c4: boolean; } +>f15 : () => { a4: string; b4: number; c4: boolean; } + +module m { +>m : typeof m + + export var { a4, b4, c4 } = f15(); +>a4 : string +>b4 : number +>c4 : boolean +>f15() : { a4: string; b4: number; c4: boolean; } +>f15 : () => { a4: string; b4: number; c4: boolean; } +} diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.js b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.js new file mode 100644 index 0000000000000..889047185e7e0 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.js @@ -0,0 +1,48 @@ +//// [declarationEmitDestructuringObjectLiteralPattern1.ts] + +var { } = { x: 5, y: "hello" }; +var { x4 } = { x4: 5, y4: "hello" }; +var { y5 } = { x5: 5, y5: "hello" }; +var { x6, y6 } = { x6: 5, y6: "hello" }; +var { x7: a1 } = { x7: 5, y7: "hello" }; +var { y8: b1 } = { x8: 5, y8: "hello" }; +var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; + +//// [declarationEmitDestructuringObjectLiteralPattern1.js] +var _a = { + x: 5, + y: "hello" +}; +var x4 = ({ + x4: 5, + y4: "hello" +}).x4; +var y5 = ({ + x5: 5, + y5: "hello" +}).y5; +var _b = { + x6: 5, + y6: "hello" +}, x6 = _b.x6, y6 = _b.y6; +var a1 = ({ + x7: 5, + y7: "hello" +}).x7; +var b1 = ({ + x8: 5, + y8: "hello" +}).y8; +var _c = { + x9: 5, + y9: "hello" +}, a2 = _c.x9, b2 = _c.y9; + + +//// [declarationEmitDestructuringObjectLiteralPattern1.d.ts] +declare var x4: number; +declare var y5: string; +declare var x6: number, y6: string; +declare var a1: number; +declare var b1: string; +declare var a2: number, b2: string; diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.types b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.types new file mode 100644 index 0000000000000..cc2094c68f4d6 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.types @@ -0,0 +1,49 @@ +=== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts === + +var { } = { x: 5, y: "hello" }; +>{ x: 5, y: "hello" } : { x: number; y: string; } +>x : number +>y : string + +var { x4 } = { x4: 5, y4: "hello" }; +>x4 : number +>{ x4: 5, y4: "hello" } : { x4: number; y4: string; } +>x4 : number +>y4 : string + +var { y5 } = { x5: 5, y5: "hello" }; +>y5 : string +>{ x5: 5, y5: "hello" } : { x5: number; y5: string; } +>x5 : number +>y5 : string + +var { x6, y6 } = { x6: 5, y6: "hello" }; +>x6 : number +>y6 : string +>{ x6: 5, y6: "hello" } : { x6: number; y6: string; } +>x6 : number +>y6 : string + +var { x7: a1 } = { x7: 5, y7: "hello" }; +>x7 : unknown +>a1 : number +>{ x7: 5, y7: "hello" } : { x7: number; y7: string; } +>x7 : number +>y7 : string + +var { y8: b1 } = { x8: 5, y8: "hello" }; +>y8 : unknown +>b1 : string +>{ x8: 5, y8: "hello" } : { x8: number; y8: string; } +>x8 : number +>y8 : string + +var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; +>x9 : unknown +>a2 : number +>y9 : unknown +>b2 : string +>{ x9: 5, y9: "hello" } : { x9: number; y9: string; } +>x9 : number +>y9 : string + diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.js b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.js new file mode 100644 index 0000000000000..140fc03780a05 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.js @@ -0,0 +1,55 @@ +//// [declarationEmitDestructuringObjectLiteralPattern2.ts] + +var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; + +function f15() { + var a4 = "hello"; + var b4 = 1; + var c4 = true; + return { a4, b4, c4 }; +} +var { a4, b4, c4 } = f15(); + +module m { + export var { a4, b4, c4 } = f15(); +} + +//// [declarationEmitDestructuringObjectLiteralPattern2.js] +var _a = { + a: 1, + b: { + a: "hello", + b: { + a: true + } + } +}, x11 = _a.a, _b = _a.b, y11 = _b.a, z11 = _b.b.a; +function f15() { + var a4 = "hello"; + var b4 = 1; + var c4 = true; + return { + a4: a4, + b4: b4, + c4: c4 + }; +} +var _c = f15(), a4 = _c.a4, b4 = _c.b4, c4 = _c.c4; +var m; +(function (m) { + _a = f15(), m.a4 = _a.a4, m.b4 = _a.b4, m.c4 = _a.c4; + var _a; +})(m || (m = {})); + + +//// [declarationEmitDestructuringObjectLiteralPattern2.d.ts] +declare var x11: number, y11: string, z11: boolean; +declare function f15(): { + a4: string; + b4: number; + c4: boolean; +}; +declare var a4: string, b4: number, c4: boolean; +declare module m { + var a4: string, b4: number, c4: boolean; +} diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.types b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.types new file mode 100644 index 0000000000000..68394686e31a0 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.types @@ -0,0 +1,55 @@ +=== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern2.ts === + +var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; +>a : unknown +>x11 : number +>b : unknown +>a : unknown +>y11 : string +>b : unknown +>a : unknown +>z11 : boolean +>{ a: 1, b: { a: "hello", b: { a: true } } } : { a: number; b: { a: string; b: { a: boolean; }; }; } +>a : number +>b : { a: string; b: { a: boolean; }; } +>{ a: "hello", b: { a: true } } : { a: string; b: { a: boolean; }; } +>a : string +>b : { a: boolean; } +>{ a: true } : { a: boolean; } +>a : boolean + +function f15() { +>f15 : () => { a4: string; b4: number; c4: boolean; } + + var a4 = "hello"; +>a4 : string + + var b4 = 1; +>b4 : number + + var c4 = true; +>c4 : boolean + + return { a4, b4, c4 }; +>{ a4, b4, c4 } : { a4: string; b4: number; c4: boolean; } +>a4 : string +>b4 : number +>c4 : boolean +} +var { a4, b4, c4 } = f15(); +>a4 : string +>b4 : number +>c4 : boolean +>f15() : { a4: string; b4: number; c4: boolean; } +>f15 : () => { a4: string; b4: number; c4: boolean; } + +module m { +>m : typeof m + + export var { a4, b4, c4 } = f15(); +>a4 : string +>b4 : number +>c4 : boolean +>f15() : { a4: string; b4: number; c4: boolean; } +>f15 : () => { a4: string; b4: number; c4: boolean; } +} diff --git a/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js b/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js new file mode 100644 index 0000000000000..c907add11f776 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js @@ -0,0 +1,33 @@ +//// [declarationEmitDestructuringOptionalBindingParametersInOverloads.ts] + +function foo([x, y, z] ?: [string, number, boolean]); +function foo(...rest: any[]) { +} + +function foo2( { x, y, z }?: { x: string; y: number; z: boolean }); +function foo2(...rest: any[]) { + +} + +//// [declarationEmitDestructuringOptionalBindingParametersInOverloads.js] +function foo() { + var rest = []; + for (var _i = 0; _i < arguments.length; _i++) { + rest[_i - 0] = arguments[_i]; + } +} +function foo2() { + var rest = []; + for (var _i = 0; _i < arguments.length; _i++) { + rest[_i - 0] = arguments[_i]; + } +} + + +//// [declarationEmitDestructuringOptionalBindingParametersInOverloads.d.ts] +declare function foo(_0?: [string, number, boolean]): any; +declare function foo2(_0?: { + x: string; + y: number; + z: boolean; +}): any; diff --git a/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.types b/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.types new file mode 100644 index 0000000000000..1c75466f0c37c --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.types @@ -0,0 +1,27 @@ +=== tests/cases/compiler/declarationEmitDestructuringOptionalBindingParametersInOverloads.ts === + +function foo([x, y, z] ?: [string, number, boolean]); +>foo : ([x, y, z]?: [string, number, boolean]) => any +>x : string +>y : number +>z : boolean + +function foo(...rest: any[]) { +>foo : ([x, y, z]?: [string, number, boolean]) => any +>rest : any[] +} + +function foo2( { x, y, z }?: { x: string; y: number; z: boolean }); +>foo2 : ({ x, y, z }?: { x: string; y: number; z: boolean; }) => any +>x : string +>y : number +>z : boolean +>x : string +>y : number +>z : boolean + +function foo2(...rest: any[]) { +>foo2 : ({ x, y, z }?: { x: string; y: number; z: boolean; }) => any +>rest : any[] + +} diff --git a/tests/baselines/reference/declarationEmitDestructuringParameterProperties.errors.txt b/tests/baselines/reference/declarationEmitDestructuringParameterProperties.errors.txt new file mode 100644 index 0000000000000..83785e86f6585 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringParameterProperties.errors.txt @@ -0,0 +1,28 @@ +tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(2,17): error TS1187: A parameter property may not be a binding pattern. +tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(8,17): error TS1187: A parameter property may not be a binding pattern. +tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(14,17): error TS1187: A parameter property may not be a binding pattern. + + +==== tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts (3 errors) ==== + class C1 { + constructor(public [x, y, z]: string[]) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1187: A parameter property may not be a binding pattern. + } + } + + type TupleType1 =[string, number, boolean]; + class C2 { + constructor(public [x, y, z]: TupleType1) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1187: A parameter property may not be a binding pattern. + } + } + + type ObjType1 = { x: number; y: string; z: boolean } + class C3 { + constructor(public { x, y, z }: ObjType1) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1187: A parameter property may not be a binding pattern. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDestructuringParameterProperties.js b/tests/baselines/reference/declarationEmitDestructuringParameterProperties.js new file mode 100644 index 0000000000000..cfe4acc1733d0 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringParameterProperties.js @@ -0,0 +1,61 @@ +//// [declarationEmitDestructuringParameterProperties.ts] +class C1 { + constructor(public [x, y, z]: string[]) { + } +} + +type TupleType1 =[string, number, boolean]; +class C2 { + constructor(public [x, y, z]: TupleType1) { + } +} + +type ObjType1 = { x: number; y: string; z: boolean } +class C3 { + constructor(public { x, y, z }: ObjType1) { + } +} + +//// [declarationEmitDestructuringParameterProperties.js] +var C1 = (function () { + function C1(_a) { + var x = _a[0], y = _a[1], z = _a[2]; + this.[x, y, z] = [x, y, z]; + } + return C1; +})(); +var C2 = (function () { + function C2(_a) { + var x = _a[0], y = _a[1], z = _a[2]; + this.[x, y, z] = [x, y, z]; + } + return C2; +})(); +var C3 = (function () { + function C3(_a) { + var x = _a.x, y = _a.y, z = _a.z; + this.{ x, y, z } = { x, y, z }; + } + return C3; +})(); + + +//// [declarationEmitDestructuringParameterProperties.d.ts] +declare class C1 { + x: string, y: string, z: string; + constructor(_0: string[]); +} +declare type TupleType1 = [string, number, boolean]; +declare class C2 { + x: string, y: number, z: boolean; + constructor(_0: TupleType1); +} +declare type ObjType1 = { + x: number; + y: string; + z: boolean; +}; +declare class C3 { + x: number, y: string, z: boolean; + constructor(_0: ObjType1); +} diff --git a/tests/baselines/reference/declarationEmitDestructuringPrivacyError.errors.txt b/tests/baselines/reference/declarationEmitDestructuringPrivacyError.errors.txt new file mode 100644 index 0000000000000..e464b96a8bf77 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringPrivacyError.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/declarationEmitDestructuringPrivacyError.ts(4,20): error TS4025: Exported variable 'y' has or is using private name 'c'. + + +==== tests/cases/compiler/declarationEmitDestructuringPrivacyError.ts (1 errors) ==== + module m { + class c { + } + export var [x, y, z] = [10, new c(), 30]; + ~ +!!! error TS4025: Exported variable 'y' has or is using private name 'c'. + } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDestructuringPrivacyError.js b/tests/baselines/reference/declarationEmitDestructuringPrivacyError.js new file mode 100644 index 0000000000000..c076dca665add --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringPrivacyError.js @@ -0,0 +1,22 @@ +//// [declarationEmitDestructuringPrivacyError.ts] +module m { + class c { + } + export var [x, y, z] = [10, new c(), 30]; +} + +//// [declarationEmitDestructuringPrivacyError.js] +var m; +(function (m) { + var c = (function () { + function c() { + } + return c; + })(); + _a = [ + 10, + new c(), + 30 + ], m.x = _a[0], m.y = _a[1], m.z = _a[2]; + var _a; +})(m || (m = {})); diff --git a/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.errors.txt b/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.errors.txt new file mode 100644 index 0000000000000..7b8a70ae8f16c --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/declarationEmitDestructuringWithOptionalBindingParameters.ts(1,14): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. +tests/cases/compiler/declarationEmitDestructuringWithOptionalBindingParameters.ts(3,16): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. + + +==== tests/cases/compiler/declarationEmitDestructuringWithOptionalBindingParameters.ts (2 errors) ==== + function foo([x,y,z]?: [string, number, boolean]) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature. + } + function foo1( { x, y, z }?: { x: string; y: number; z: boolean }) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature. + } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.js b/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.js new file mode 100644 index 0000000000000..284cf107782f0 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.js @@ -0,0 +1,22 @@ +//// [declarationEmitDestructuringWithOptionalBindingParameters.ts] +function foo([x,y,z]?: [string, number, boolean]) { +} +function foo1( { x, y, z }?: { x: string; y: number; z: boolean }) { +} + +//// [declarationEmitDestructuringWithOptionalBindingParameters.js] +function foo(_a) { + var x = _a[0], y = _a[1], z = _a[2]; +} +function foo1(_a) { + var x = _a.x, y = _a.y, z = _a.z; +} + + +//// [declarationEmitDestructuringWithOptionalBindingParameters.d.ts] +declare function foo(_0?: [string, number, boolean]): void; +declare function foo1(_0?: { + x: string; + y: number; + z: boolean; +}): void; diff --git a/tests/baselines/reference/declarationEmitImportInExportAssignmentModule.js b/tests/baselines/reference/declarationEmitImportInExportAssignmentModule.js new file mode 100644 index 0000000000000..9b580bcd7a4e3 --- /dev/null +++ b/tests/baselines/reference/declarationEmitImportInExportAssignmentModule.js @@ -0,0 +1,39 @@ +//// [declarationEmitImportInExportAssignmentModule.ts] + +module m { + export module c { + export class c { + } + } + import x = c; + export var a: typeof x; +} +export = m; + +//// [declarationEmitImportInExportAssignmentModule.js] +var m; +(function (m) { + var c; + (function (c_1) { + var c = (function () { + function c() { + } + return c; + })(); + c_1.c = c; + })(c = m.c || (m.c = {})); + m.a; +})(m || (m = {})); +module.exports = m; + + +//// [declarationEmitImportInExportAssignmentModule.d.ts] +declare module m { + module c { + class c { + } + } + import x = c; + var a: typeof x; +} +export = m; diff --git a/tests/baselines/reference/declarationEmitImportInExportAssignmentModule.types b/tests/baselines/reference/declarationEmitImportInExportAssignmentModule.types new file mode 100644 index 0000000000000..23176a0abe2e1 --- /dev/null +++ b/tests/baselines/reference/declarationEmitImportInExportAssignmentModule.types @@ -0,0 +1,23 @@ +=== tests/cases/compiler/declarationEmitImportInExportAssignmentModule.ts === + +module m { +>m : typeof m + + export module c { +>c : typeof x + + export class c { +>c : c + } + } + import x = c; +>x : typeof x +>c : typeof x + + export var a: typeof x; +>a : typeof x +>x : typeof x +} +export = m; +>m : typeof m + diff --git a/tests/baselines/reference/decoratorOnArrowFunction.errors.txt b/tests/baselines/reference/decoratorOnArrowFunction.errors.txt new file mode 100644 index 0000000000000..14bde1e49bf27 --- /dev/null +++ b/tests/baselines/reference/decoratorOnArrowFunction.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/decorators/invalid/decoratorOnArrowFunction.ts(3,9): error TS1109: Expression expected. +tests/cases/conformance/decorators/invalid/decoratorOnArrowFunction.ts(3,16): error TS1146: Declaration expected. +tests/cases/conformance/decorators/invalid/decoratorOnArrowFunction.ts(3,17): error TS1128: Declaration or statement expected. + + +==== tests/cases/conformance/decorators/invalid/decoratorOnArrowFunction.ts (3 errors) ==== + declare function dec(target: T): T; + + var F = @dec () => { + ~ +!!! error TS1109: Expression expected. + +!!! error TS1146: Declaration expected. + ~~ +!!! error TS1128: Declaration or statement expected. + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnArrowFunction.js b/tests/baselines/reference/decoratorOnArrowFunction.js new file mode 100644 index 0000000000000..1a327e7fc9a9b --- /dev/null +++ b/tests/baselines/reference/decoratorOnArrowFunction.js @@ -0,0 +1,10 @@ +//// [decoratorOnArrowFunction.ts] +declare function dec(target: T): T; + +var F = @dec () => { +} + +//// [decoratorOnArrowFunction.js] +var F = ; +{ +} diff --git a/tests/baselines/reference/decoratorOnClass1.js b/tests/baselines/reference/decoratorOnClass1.js new file mode 100644 index 0000000000000..24be2517469fc --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass1.js @@ -0,0 +1,27 @@ +//// [decoratorOnClass1.ts] +declare function dec(target: T): T; + +@dec +class C { +} + +//// [decoratorOnClass1.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + C = __decorate([dec], C); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClass1.types b/tests/baselines/reference/decoratorOnClass1.types new file mode 100644 index 0000000000000..19e066586da2c --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass1.types @@ -0,0 +1,14 @@ +=== tests/cases/conformance/decorators/class/decoratorOnClass1.ts === +declare function dec(target: T): T; +>dec : (target: T) => T +>T : T +>target : T +>T : T +>T : T + +@dec +>dec : unknown + +class C { +>C : C +} diff --git a/tests/baselines/reference/decoratorOnClass2.js b/tests/baselines/reference/decoratorOnClass2.js new file mode 100644 index 0000000000000..92741819e9449 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass2.js @@ -0,0 +1,28 @@ +//// [decoratorOnClass2.ts] +declare function dec(target: T): T; + +@dec +export class C { +} + +//// [decoratorOnClass2.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + C = __decorate([dec], C); + return C; +})(); +exports.C = C; diff --git a/tests/baselines/reference/decoratorOnClass2.types b/tests/baselines/reference/decoratorOnClass2.types new file mode 100644 index 0000000000000..43102ee912299 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass2.types @@ -0,0 +1,14 @@ +=== tests/cases/conformance/decorators/class/decoratorOnClass2.ts === +declare function dec(target: T): T; +>dec : (target: T) => T +>T : T +>target : T +>T : T +>T : T + +@dec +>dec : unknown + +export class C { +>C : C +} diff --git a/tests/baselines/reference/decoratorOnClass3.errors.txt b/tests/baselines/reference/decoratorOnClass3.errors.txt new file mode 100644 index 0000000000000..dfa430dec0cd7 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass3.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/decorators/class/decoratorOnClass3.ts(3,1): error TS1128: Declaration or statement expected. + + +==== tests/cases/conformance/decorators/class/decoratorOnClass3.ts (1 errors) ==== + declare function dec(target: T): T; + + export + ~~~~~~ +!!! error TS1128: Declaration or statement expected. + @dec + class C { + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClass3.js b/tests/baselines/reference/decoratorOnClass3.js new file mode 100644 index 0000000000000..766acc42072ed --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass3.js @@ -0,0 +1,28 @@ +//// [decoratorOnClass3.ts] +declare function dec(target: T): T; + +export +@dec +class C { +} + +//// [decoratorOnClass3.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + C = __decorate([dec], C); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClass4.js b/tests/baselines/reference/decoratorOnClass4.js new file mode 100644 index 0000000000000..95bde549379e8 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass4.js @@ -0,0 +1,27 @@ +//// [decoratorOnClass4.ts] +declare function dec(): (target: T) => T; + +@dec() +class C { +} + +//// [decoratorOnClass4.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + C = __decorate([dec()], C); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClass4.types b/tests/baselines/reference/decoratorOnClass4.types new file mode 100644 index 0000000000000..425aa63ac213d --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass4.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/decorators/class/decoratorOnClass4.ts === +declare function dec(): (target: T) => T; +>dec : () => (target: T) => T +>T : T +>target : T +>T : T +>T : T + +@dec() +>dec() : (target: T) => T +>dec : () => (target: T) => T + +class C { +>C : C +} diff --git a/tests/baselines/reference/decoratorOnClass5.js b/tests/baselines/reference/decoratorOnClass5.js new file mode 100644 index 0000000000000..a93d625f49136 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass5.js @@ -0,0 +1,27 @@ +//// [decoratorOnClass5.ts] +declare function dec(): (target: T) => T; + +@dec() +class C { +} + +//// [decoratorOnClass5.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + C = __decorate([dec()], C); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClass5.types b/tests/baselines/reference/decoratorOnClass5.types new file mode 100644 index 0000000000000..1c967ffcc0011 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass5.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/decorators/class/decoratorOnClass5.ts === +declare function dec(): (target: T) => T; +>dec : () => (target: T) => T +>T : T +>target : T +>T : T +>T : T + +@dec() +>dec() : (target: T) => T +>dec : () => (target: T) => T + +class C { +>C : C +} diff --git a/tests/baselines/reference/decoratorOnClass8.errors.txt b/tests/baselines/reference/decoratorOnClass8.errors.txt new file mode 100644 index 0000000000000..0a9fbf2956c11 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass8.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/decorators/class/decoratorOnClass8.ts(3,1): error TS2322: Type '(target: Function, paramIndex: number) => void' is not assignable to type '(target: typeof C) => void | typeof C'. + + +==== tests/cases/conformance/decorators/class/decoratorOnClass8.ts (1 errors) ==== + declare function dec(): (target: Function, paramIndex: number) => void; + + @dec() + ~~~~~~ +!!! error TS2322: Type '(target: Function, paramIndex: number) => void' is not assignable to type '(target: typeof C) => void | typeof C'. + class C { + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClass8.js b/tests/baselines/reference/decoratorOnClass8.js new file mode 100644 index 0000000000000..0e782d45e1158 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass8.js @@ -0,0 +1,27 @@ +//// [decoratorOnClass8.ts] +declare function dec(): (target: Function, paramIndex: number) => void; + +@dec() +class C { +} + +//// [decoratorOnClass8.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + C = __decorate([dec()], C); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassAccessor1.js b/tests/baselines/reference/decoratorOnClassAccessor1.js new file mode 100644 index 0000000000000..d78e776cb96bc --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassAccessor1.js @@ -0,0 +1,34 @@ +//// [decoratorOnClassAccessor1.ts] +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + @dec get accessor() { return 1; } +} + +//// [decoratorOnClassAccessor1.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + Object.defineProperty(C.prototype, "accessor", { + get: function () { + return 1; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "accessor", __decorate([dec], C.prototype, "accessor", Object.getOwnPropertyDescriptor(C.prototype, "accessor"))); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassAccessor1.types b/tests/baselines/reference/decoratorOnClassAccessor1.types new file mode 100644 index 0000000000000..fd592d7d29449 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassAccessor1.types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor1.ts === +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; +>dec : (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +>T : T +>target : any +>propertyKey : string +>descriptor : TypedPropertyDescriptor +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T + +class C { +>C : C + + @dec get accessor() { return 1; } +>dec : unknown +>accessor : number +} diff --git a/tests/baselines/reference/decoratorOnClassAccessor2.js b/tests/baselines/reference/decoratorOnClassAccessor2.js new file mode 100644 index 0000000000000..f1bfce9ea6dce --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassAccessor2.js @@ -0,0 +1,34 @@ +//// [decoratorOnClassAccessor2.ts] +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + @dec public get accessor() { return 1; } +} + +//// [decoratorOnClassAccessor2.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + Object.defineProperty(C.prototype, "accessor", { + get: function () { + return 1; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "accessor", __decorate([dec], C.prototype, "accessor", Object.getOwnPropertyDescriptor(C.prototype, "accessor"))); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassAccessor2.types b/tests/baselines/reference/decoratorOnClassAccessor2.types new file mode 100644 index 0000000000000..32bb503d889ee --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassAccessor2.types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor2.ts === +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; +>dec : (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +>T : T +>target : any +>propertyKey : string +>descriptor : TypedPropertyDescriptor +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T + +class C { +>C : C + + @dec public get accessor() { return 1; } +>dec : unknown +>accessor : number +} diff --git a/tests/baselines/reference/decoratorOnClassAccessor3.errors.txt b/tests/baselines/reference/decoratorOnClassAccessor3.errors.txt new file mode 100644 index 0000000000000..b75b7e0d8b63a --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassAccessor3.errors.txt @@ -0,0 +1,35 @@ +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,5): error TS2304: Cannot find name 'public'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,12): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,16): error TS1146: Declaration expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,17): error TS2304: Cannot find name 'get'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,21): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,21): error TS2304: Cannot find name 'accessor'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,32): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(5,1): error TS1128: Declaration or statement expected. + + +==== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts (9 errors) ==== + declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + + class C { + public @dec get accessor() { return 1; } + ~~~~~~ +!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + ~ +!!! error TS1005: ';' expected. + +!!! error TS1146: Declaration expected. + ~~~ +!!! error TS2304: Cannot find name 'get'. + ~~~~~~~~ +!!! error TS1005: ';' expected. + ~~~~~~~~ +!!! error TS2304: Cannot find name 'accessor'. + ~ +!!! error TS1005: ';' expected. + } + ~ +!!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassAccessor3.js b/tests/baselines/reference/decoratorOnClassAccessor3.js new file mode 100644 index 0000000000000..f48a755953f3d --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassAccessor3.js @@ -0,0 +1,19 @@ +//// [decoratorOnClassAccessor3.ts] +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + public @dec get accessor() { return 1; } +} + +//// [decoratorOnClassAccessor3.js] +var C = (function () { + function C() { + } + return C; +})(); +public; +get; +accessor(); +{ + return 1; +} diff --git a/tests/baselines/reference/decoratorOnClassAccessor4.js b/tests/baselines/reference/decoratorOnClassAccessor4.js new file mode 100644 index 0000000000000..77dbc569e5aaa --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassAccessor4.js @@ -0,0 +1,33 @@ +//// [decoratorOnClassAccessor4.ts] +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + @dec set accessor(value: number) { } +} + +//// [decoratorOnClassAccessor4.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + Object.defineProperty(C.prototype, "accessor", { + set: function (value) { + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "accessor", __decorate([dec], C.prototype, "accessor", Object.getOwnPropertyDescriptor(C.prototype, "accessor"))); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassAccessor4.types b/tests/baselines/reference/decoratorOnClassAccessor4.types new file mode 100644 index 0000000000000..40dd43d7e6227 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassAccessor4.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor4.ts === +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; +>dec : (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +>T : T +>target : any +>propertyKey : string +>descriptor : TypedPropertyDescriptor +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T + +class C { +>C : C + + @dec set accessor(value: number) { } +>dec : unknown +>accessor : number +>value : number +} diff --git a/tests/baselines/reference/decoratorOnClassAccessor5.js b/tests/baselines/reference/decoratorOnClassAccessor5.js new file mode 100644 index 0000000000000..bfd6518c59bd6 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassAccessor5.js @@ -0,0 +1,33 @@ +//// [decoratorOnClassAccessor5.ts] +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + @dec public set accessor(value: number) { } +} + +//// [decoratorOnClassAccessor5.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + Object.defineProperty(C.prototype, "accessor", { + set: function (value) { + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "accessor", __decorate([dec], C.prototype, "accessor", Object.getOwnPropertyDescriptor(C.prototype, "accessor"))); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassAccessor5.types b/tests/baselines/reference/decoratorOnClassAccessor5.types new file mode 100644 index 0000000000000..4b167fe8df17c --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassAccessor5.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor5.ts === +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; +>dec : (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +>T : T +>target : any +>propertyKey : string +>descriptor : TypedPropertyDescriptor +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T + +class C { +>C : C + + @dec public set accessor(value: number) { } +>dec : unknown +>accessor : number +>value : number +} diff --git a/tests/baselines/reference/decoratorOnClassAccessor6.errors.txt b/tests/baselines/reference/decoratorOnClassAccessor6.errors.txt new file mode 100644 index 0000000000000..ec22ae0b3e139 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassAccessor6.errors.txt @@ -0,0 +1,44 @@ +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,5): error TS2304: Cannot find name 'public'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,12): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,16): error TS1146: Declaration expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,17): error TS2304: Cannot find name 'set'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,21): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,21): error TS2304: Cannot find name 'accessor'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,30): error TS2304: Cannot find name 'value'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,35): error TS1005: ',' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,37): error TS2304: Cannot find name 'number'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,45): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(5,1): error TS1128: Declaration or statement expected. + + +==== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts (12 errors) ==== + declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + + class C { + public @dec set accessor(value: number) { } + ~~~~~~ +!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + ~ +!!! error TS1005: ';' expected. + +!!! error TS1146: Declaration expected. + ~~~ +!!! error TS2304: Cannot find name 'set'. + ~~~~~~~~ +!!! error TS1005: ';' expected. + ~~~~~~~~ +!!! error TS2304: Cannot find name 'accessor'. + ~~~~~ +!!! error TS2304: Cannot find name 'value'. + ~ +!!! error TS1005: ',' expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'number'. + ~ +!!! error TS1005: ';' expected. + } + ~ +!!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassAccessor6.js b/tests/baselines/reference/decoratorOnClassAccessor6.js new file mode 100644 index 0000000000000..905e3d3b2db96 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassAccessor6.js @@ -0,0 +1,18 @@ +//// [decoratorOnClassAccessor6.ts] +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + public @dec set accessor(value: number) { } +} + +//// [decoratorOnClassAccessor6.js] +var C = (function () { + function C() { + } + return C; +})(); +public; +set; +accessor(value, number); +{ +} diff --git a/tests/baselines/reference/decoratorOnClassConstructor1.errors.txt b/tests/baselines/reference/decoratorOnClassConstructor1.errors.txt new file mode 100644 index 0000000000000..14a164eccb429 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassConstructor1.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/decorators/class/constructor/decoratorOnClassConstructor1.ts(4,5): error TS1206: Decorators are not valid here. + + +==== tests/cases/conformance/decorators/class/constructor/decoratorOnClassConstructor1.ts (1 errors) ==== + declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + + class C { + @dec constructor() {} + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1206: Decorators are not valid here. + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassConstructor1.js b/tests/baselines/reference/decoratorOnClassConstructor1.js new file mode 100644 index 0000000000000..c61d1d218a5de --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassConstructor1.js @@ -0,0 +1,13 @@ +//// [decoratorOnClassConstructor1.ts] +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + @dec constructor() {} +} + +//// [decoratorOnClassConstructor1.js] +var C = (function () { + function C() { + } + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassConstructorParameter1.js b/tests/baselines/reference/decoratorOnClassConstructorParameter1.js new file mode 100644 index 0000000000000..0c86a1ccf7aa7 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassConstructorParameter1.js @@ -0,0 +1,27 @@ +//// [decoratorOnClassConstructorParameter1.ts] +declare function dec(target: Function, propertyKey: string | symbol, parameterIndex: number): void; + +class C { + constructor(@dec p: number) {} +} + +//// [decoratorOnClassConstructorParameter1.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C(p) { + } + __decorate([dec], C, void 0, 0); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassConstructorParameter1.types b/tests/baselines/reference/decoratorOnClassConstructorParameter1.types new file mode 100644 index 0000000000000..d5ce51269bc3d --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassConstructorParameter1.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/decorators/class/constructor/parameter/decoratorOnClassConstructorParameter1.ts === +declare function dec(target: Function, propertyKey: string | symbol, parameterIndex: number): void; +>dec : (target: Function, propertyKey: string | symbol, parameterIndex: number) => void +>target : Function +>Function : Function +>propertyKey : string | symbol +>parameterIndex : number + +class C { +>C : C + + constructor(@dec p: number) {} +>dec : unknown +>p : number +} diff --git a/tests/baselines/reference/decoratorOnClassConstructorParameter4.errors.txt b/tests/baselines/reference/decoratorOnClassConstructorParameter4.errors.txt new file mode 100644 index 0000000000000..5969cfca06973 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassConstructorParameter4.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/decorators/class/constructor/parameter/decoratorOnClassConstructorParameter4.ts(4,24): error TS1005: ',' expected. + + +==== tests/cases/conformance/decorators/class/constructor/parameter/decoratorOnClassConstructorParameter4.ts (1 errors) ==== + declare function dec(target: Function, propertyKey: string | symbol, parameterIndex: number): void; + + class C { + constructor(public @dec p: number) {} + ~ +!!! error TS1005: ',' expected. + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassConstructorParameter4.js b/tests/baselines/reference/decoratorOnClassConstructorParameter4.js new file mode 100644 index 0000000000000..07dc7cae0750a --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassConstructorParameter4.js @@ -0,0 +1,27 @@ +//// [decoratorOnClassConstructorParameter4.ts] +declare function dec(target: Function, propertyKey: string | symbol, parameterIndex: number): void; + +class C { + constructor(public @dec p: number) {} +} + +//// [decoratorOnClassConstructorParameter4.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C(public, p) { + } + __decorate([dec], C, void 0, 1); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassMethod1.js b/tests/baselines/reference/decoratorOnClassMethod1.js new file mode 100644 index 0000000000000..be9c00290fbb9 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod1.js @@ -0,0 +1,29 @@ +//// [decoratorOnClassMethod1.ts] +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + @dec method() {} +} + +//// [decoratorOnClassMethod1.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + C.prototype.method = function () { + }; + Object.defineProperty(C.prototype, "method", __decorate([dec], C.prototype, "method", Object.getOwnPropertyDescriptor(C.prototype, "method"))); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassMethod1.types b/tests/baselines/reference/decoratorOnClassMethod1.types new file mode 100644 index 0000000000000..760f758bbff17 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod1.types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod1.ts === +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; +>dec : (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +>T : T +>target : any +>propertyKey : string +>descriptor : TypedPropertyDescriptor +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T + +class C { +>C : C + + @dec method() {} +>dec : unknown +>method : () => void +} diff --git a/tests/baselines/reference/decoratorOnClassMethod10.errors.txt b/tests/baselines/reference/decoratorOnClassMethod10.errors.txt new file mode 100644 index 0000000000000..cd331473b7cda --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod10.errors.txt @@ -0,0 +1,17 @@ +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod10.ts(4,5): error TS2322: Type '(target: Function, paramIndex: number) => void' is not assignable to type '(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<() => void>) => void | TypedPropertyDescriptor<() => void>'. + Types of parameters 'paramIndex' and 'propertyKey' are incompatible. + Type 'number' is not assignable to type 'string | symbol'. + Type 'number' is not assignable to type 'symbol'. + + +==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod10.ts (1 errors) ==== + declare function dec(target: Function, paramIndex: number): void; + + class C { + @dec method() {} + ~~~~ +!!! error TS2322: Type '(target: Function, paramIndex: number) => void' is not assignable to type '(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<() => void>) => void | TypedPropertyDescriptor<() => void>'. +!!! error TS2322: Types of parameters 'paramIndex' and 'propertyKey' are incompatible. +!!! error TS2322: Type 'number' is not assignable to type 'string | symbol'. +!!! error TS2322: Type 'number' is not assignable to type 'symbol'. + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassMethod10.js b/tests/baselines/reference/decoratorOnClassMethod10.js new file mode 100644 index 0000000000000..3dd38f806bdc6 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod10.js @@ -0,0 +1,29 @@ +//// [decoratorOnClassMethod10.ts] +declare function dec(target: Function, paramIndex: number): void; + +class C { + @dec method() {} +} + +//// [decoratorOnClassMethod10.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + C.prototype.method = function () { + }; + Object.defineProperty(C.prototype, "method", __decorate([dec], C.prototype, "method", Object.getOwnPropertyDescriptor(C.prototype, "method"))); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassMethod2.js b/tests/baselines/reference/decoratorOnClassMethod2.js new file mode 100644 index 0000000000000..b7df7b9ba9c4e --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod2.js @@ -0,0 +1,29 @@ +//// [decoratorOnClassMethod2.ts] +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + @dec public method() {} +} + +//// [decoratorOnClassMethod2.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + C.prototype.method = function () { + }; + Object.defineProperty(C.prototype, "method", __decorate([dec], C.prototype, "method", Object.getOwnPropertyDescriptor(C.prototype, "method"))); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassMethod2.types b/tests/baselines/reference/decoratorOnClassMethod2.types new file mode 100644 index 0000000000000..98539648cd03c --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod2.types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod2.ts === +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; +>dec : (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +>T : T +>target : any +>propertyKey : string +>descriptor : TypedPropertyDescriptor +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T + +class C { +>C : C + + @dec public method() {} +>dec : unknown +>method : () => void +} diff --git a/tests/baselines/reference/decoratorOnClassMethod3.errors.txt b/tests/baselines/reference/decoratorOnClassMethod3.errors.txt new file mode 100644 index 0000000000000..b2173dedf9ef9 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod3.errors.txt @@ -0,0 +1,29 @@ +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,5): error TS2304: Cannot find name 'public'. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,12): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,16): error TS1146: Declaration expected. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,17): error TS2304: Cannot find name 'method'. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,26): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(5,1): error TS1128: Declaration or statement expected. + + +==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts (7 errors) ==== + declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + + class C { + public @dec method() {} + ~~~~~~ +!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + ~ +!!! error TS1005: ';' expected. + +!!! error TS1146: Declaration expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'method'. + ~ +!!! error TS1005: ';' expected. + } + ~ +!!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassMethod3.js b/tests/baselines/reference/decoratorOnClassMethod3.js new file mode 100644 index 0000000000000..3a01184527531 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod3.js @@ -0,0 +1,17 @@ +//// [decoratorOnClassMethod3.ts] +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + public @dec method() {} +} + +//// [decoratorOnClassMethod3.js] +var C = (function () { + function C() { + } + return C; +})(); +public; +method(); +{ +} diff --git a/tests/baselines/reference/decoratorOnClassMethod4.js b/tests/baselines/reference/decoratorOnClassMethod4.js new file mode 100644 index 0000000000000..7021e5af32836 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod4.js @@ -0,0 +1,27 @@ +//// [decoratorOnClassMethod4.ts] +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + @dec ["method"]() {} +} + +//// [decoratorOnClassMethod4.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +class C { + [_a = "method"]() { + } +} +Object.defineProperty(C.prototype, _a, __decorate([dec], C.prototype, _a, Object.getOwnPropertyDescriptor(C.prototype, _a))); +var _a; diff --git a/tests/baselines/reference/decoratorOnClassMethod4.types b/tests/baselines/reference/decoratorOnClassMethod4.types new file mode 100644 index 0000000000000..6d55e01e97a86 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod4.types @@ -0,0 +1,18 @@ +=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod4.ts === +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; +>dec : (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +>T : T +>target : any +>propertyKey : string +>descriptor : TypedPropertyDescriptor +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T + +class C { +>C : C + + @dec ["method"]() {} +>dec : unknown +} diff --git a/tests/baselines/reference/decoratorOnClassMethod5.js b/tests/baselines/reference/decoratorOnClassMethod5.js new file mode 100644 index 0000000000000..3bde0968eab7b --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod5.js @@ -0,0 +1,27 @@ +//// [decoratorOnClassMethod5.ts] +declare function dec(): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor; + +class C { + @dec() ["method"]() {} +} + +//// [decoratorOnClassMethod5.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +class C { + [_a = "method"]() { + } +} +Object.defineProperty(C.prototype, _a, __decorate([dec()], C.prototype, _a, Object.getOwnPropertyDescriptor(C.prototype, _a))); +var _a; diff --git a/tests/baselines/reference/decoratorOnClassMethod5.types b/tests/baselines/reference/decoratorOnClassMethod5.types new file mode 100644 index 0000000000000..d87de2b351add --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod5.types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod5.ts === +declare function dec(): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor; +>dec : () => (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +>T : T +>target : any +>propertyKey : string +>descriptor : TypedPropertyDescriptor +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T + +class C { +>C : C + + @dec() ["method"]() {} +>dec() : (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +>dec : () => (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +} diff --git a/tests/baselines/reference/decoratorOnClassMethod6.js b/tests/baselines/reference/decoratorOnClassMethod6.js new file mode 100644 index 0000000000000..126dc47ad2f7b --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod6.js @@ -0,0 +1,27 @@ +//// [decoratorOnClassMethod6.ts] +declare function dec(): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor; + +class C { + @dec ["method"]() {} +} + +//// [decoratorOnClassMethod6.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +class C { + [_a = "method"]() { + } +} +Object.defineProperty(C.prototype, _a, __decorate([dec], C.prototype, _a, Object.getOwnPropertyDescriptor(C.prototype, _a))); +var _a; diff --git a/tests/baselines/reference/decoratorOnClassMethod6.types b/tests/baselines/reference/decoratorOnClassMethod6.types new file mode 100644 index 0000000000000..4e6629cd60aeb --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod6.types @@ -0,0 +1,18 @@ +=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts === +declare function dec(): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor; +>dec : () => (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +>T : T +>target : any +>propertyKey : string +>descriptor : TypedPropertyDescriptor +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T + +class C { +>C : C + + @dec ["method"]() {} +>dec : unknown +} diff --git a/tests/baselines/reference/decoratorOnClassMethod7.js b/tests/baselines/reference/decoratorOnClassMethod7.js new file mode 100644 index 0000000000000..34fbdb53ca5dd --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod7.js @@ -0,0 +1,27 @@ +//// [decoratorOnClassMethod7.ts] +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + @dec public ["method"]() {} +} + +//// [decoratorOnClassMethod7.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +class C { + [_a = "method"]() { + } +} +Object.defineProperty(C.prototype, _a, __decorate([dec], C.prototype, _a, Object.getOwnPropertyDescriptor(C.prototype, _a))); +var _a; diff --git a/tests/baselines/reference/decoratorOnClassMethod7.types b/tests/baselines/reference/decoratorOnClassMethod7.types new file mode 100644 index 0000000000000..7e426cb773c15 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod7.types @@ -0,0 +1,18 @@ +=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod7.ts === +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; +>dec : (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +>T : T +>target : any +>propertyKey : string +>descriptor : TypedPropertyDescriptor +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T + +class C { +>C : C + + @dec public ["method"]() {} +>dec : unknown +} diff --git a/tests/baselines/reference/decoratorOnClassMethod8.js b/tests/baselines/reference/decoratorOnClassMethod8.js new file mode 100644 index 0000000000000..629ff4e253bba --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod8.js @@ -0,0 +1,29 @@ +//// [decoratorOnClassMethod8.ts] +declare function dec(target: T): T; + +class C { + @dec method() {} +} + +//// [decoratorOnClassMethod8.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + C.prototype.method = function () { + }; + Object.defineProperty(C.prototype, "method", __decorate([dec], C.prototype, "method", Object.getOwnPropertyDescriptor(C.prototype, "method"))); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassMethod8.types b/tests/baselines/reference/decoratorOnClassMethod8.types new file mode 100644 index 0000000000000..f932ab8696fba --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod8.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod8.ts === +declare function dec(target: T): T; +>dec : (target: T) => T +>T : T +>target : T +>T : T +>T : T + +class C { +>C : C + + @dec method() {} +>dec : unknown +>method : () => void +} diff --git a/tests/baselines/reference/decoratorOnClassMethodParameter1.js b/tests/baselines/reference/decoratorOnClassMethodParameter1.js new file mode 100644 index 0000000000000..1dcb057e53038 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethodParameter1.js @@ -0,0 +1,29 @@ +//// [decoratorOnClassMethodParameter1.ts] +declare function dec(target: Function, propertyKey: string | symbol, parameterIndex: number): void; + +class C { + method(@dec p: number) {} +} + +//// [decoratorOnClassMethodParameter1.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + C.prototype.method = function (p) { + }; + __decorate([dec], C.prototype, "method", 0); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassMethodParameter1.types b/tests/baselines/reference/decoratorOnClassMethodParameter1.types new file mode 100644 index 0000000000000..cf7bfd352bfee --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethodParameter1.types @@ -0,0 +1,16 @@ +=== tests/cases/conformance/decorators/class/method/parameter/decoratorOnClassMethodParameter1.ts === +declare function dec(target: Function, propertyKey: string | symbol, parameterIndex: number): void; +>dec : (target: Function, propertyKey: string | symbol, parameterIndex: number) => void +>target : Function +>Function : Function +>propertyKey : string | symbol +>parameterIndex : number + +class C { +>C : C + + method(@dec p: number) {} +>method : (p: number) => void +>dec : unknown +>p : number +} diff --git a/tests/baselines/reference/decoratorOnClassProperty1.js b/tests/baselines/reference/decoratorOnClassProperty1.js new file mode 100644 index 0000000000000..efc6a2c04dbf5 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty1.js @@ -0,0 +1,27 @@ +//// [decoratorOnClassProperty1.ts] +declare function dec(target: any, propertyKey: string): void; + +class C { + @dec prop; +} + +//// [decoratorOnClassProperty1.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + __decorate([dec], C.prototype, "prop"); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassProperty1.types b/tests/baselines/reference/decoratorOnClassProperty1.types new file mode 100644 index 0000000000000..651085c7ac49b --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty1.types @@ -0,0 +1,13 @@ +=== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty1.ts === +declare function dec(target: any, propertyKey: string): void; +>dec : (target: any, propertyKey: string) => void +>target : any +>propertyKey : string + +class C { +>C : C + + @dec prop; +>dec : unknown +>prop : any +} diff --git a/tests/baselines/reference/decoratorOnClassProperty10.js b/tests/baselines/reference/decoratorOnClassProperty10.js new file mode 100644 index 0000000000000..d55eb71e3c637 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty10.js @@ -0,0 +1,27 @@ +//// [decoratorOnClassProperty10.ts] +declare function dec(): (target: any, propertyKey: string) => void; + +class C { + @dec() prop; +} + +//// [decoratorOnClassProperty10.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + __decorate([dec()], C.prototype, "prop"); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassProperty10.types b/tests/baselines/reference/decoratorOnClassProperty10.types new file mode 100644 index 0000000000000..d0aa05589ff13 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty10.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty10.ts === +declare function dec(): (target: any, propertyKey: string) => void; +>dec : () => (target: any, propertyKey: string) => void +>T : T +>target : any +>propertyKey : string + +class C { +>C : C + + @dec() prop; +>dec() : (target: any, propertyKey: string) => void +>dec : () => (target: any, propertyKey: string) => void +>prop : any +} diff --git a/tests/baselines/reference/decoratorOnClassProperty11.js b/tests/baselines/reference/decoratorOnClassProperty11.js new file mode 100644 index 0000000000000..63e5f8d02e94c --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty11.js @@ -0,0 +1,27 @@ +//// [decoratorOnClassProperty11.ts] +declare function dec(): (target: any, propertyKey: string) => void; + +class C { + @dec prop; +} + +//// [decoratorOnClassProperty11.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + __decorate([dec], C.prototype, "prop"); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassProperty11.types b/tests/baselines/reference/decoratorOnClassProperty11.types new file mode 100644 index 0000000000000..5377e53c31c4a --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty11.types @@ -0,0 +1,14 @@ +=== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts === +declare function dec(): (target: any, propertyKey: string) => void; +>dec : () => (target: any, propertyKey: string) => void +>T : T +>target : any +>propertyKey : string + +class C { +>C : C + + @dec prop; +>dec : unknown +>prop : any +} diff --git a/tests/baselines/reference/decoratorOnClassProperty2.js b/tests/baselines/reference/decoratorOnClassProperty2.js new file mode 100644 index 0000000000000..d52baa7920273 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty2.js @@ -0,0 +1,27 @@ +//// [decoratorOnClassProperty2.ts] +declare function dec(target: any, propertyKey: string): void; + +class C { + @dec public prop; +} + +//// [decoratorOnClassProperty2.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + __decorate([dec], C.prototype, "prop"); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassProperty2.types b/tests/baselines/reference/decoratorOnClassProperty2.types new file mode 100644 index 0000000000000..2d5c9fe07d770 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty2.types @@ -0,0 +1,13 @@ +=== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty2.ts === +declare function dec(target: any, propertyKey: string): void; +>dec : (target: any, propertyKey: string) => void +>target : any +>propertyKey : string + +class C { +>C : C + + @dec public prop; +>dec : unknown +>prop : any +} diff --git a/tests/baselines/reference/decoratorOnClassProperty3.errors.txt b/tests/baselines/reference/decoratorOnClassProperty3.errors.txt new file mode 100644 index 0000000000000..29438bd67a9e5 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty3.errors.txt @@ -0,0 +1,26 @@ +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,5): error TS2304: Cannot find name 'public'. +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,12): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,16): error TS1146: Declaration expected. +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,17): error TS2304: Cannot find name 'prop'. +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(5,1): error TS1128: Declaration or statement expected. + + +==== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts (6 errors) ==== + declare function dec(target: any, propertyKey: string): void; + + class C { + public @dec prop; + ~~~~~~ +!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + ~ +!!! error TS1005: ';' expected. + +!!! error TS1146: Declaration expected. + ~~~~ +!!! error TS2304: Cannot find name 'prop'. + } + ~ +!!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassProperty3.js b/tests/baselines/reference/decoratorOnClassProperty3.js new file mode 100644 index 0000000000000..6c9945677ca51 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty3.js @@ -0,0 +1,15 @@ +//// [decoratorOnClassProperty3.ts] +declare function dec(target: any, propertyKey: string): void; + +class C { + public @dec prop; +} + +//// [decoratorOnClassProperty3.js] +var C = (function () { + function C() { + } + return C; +})(); +public; +prop; diff --git a/tests/baselines/reference/decoratorOnClassProperty6.js b/tests/baselines/reference/decoratorOnClassProperty6.js new file mode 100644 index 0000000000000..7f087156bc7a1 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty6.js @@ -0,0 +1,27 @@ +//// [decoratorOnClassProperty6.ts] +declare function dec(target: Function): void; + +class C { + @dec prop; +} + +//// [decoratorOnClassProperty6.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + __decorate([dec], C.prototype, "prop"); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassProperty6.types b/tests/baselines/reference/decoratorOnClassProperty6.types new file mode 100644 index 0000000000000..2c8c41abf78e9 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty6.types @@ -0,0 +1,13 @@ +=== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty6.ts === +declare function dec(target: Function): void; +>dec : (target: Function) => void +>target : Function +>Function : Function + +class C { +>C : C + + @dec prop; +>dec : unknown +>prop : any +} diff --git a/tests/baselines/reference/decoratorOnClassProperty7.errors.txt b/tests/baselines/reference/decoratorOnClassProperty7.errors.txt new file mode 100644 index 0000000000000..8b93d0ab38ebc --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty7.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty7.ts(4,5): error TS2322: Type '(target: Function, propertyKey: string | symbol, paramIndex: number) => void' is not assignable to type '(target: Object, propertyKey: string | symbol) => void'. + + +==== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty7.ts (1 errors) ==== + declare function dec(target: Function, propertyKey: string | symbol, paramIndex: number): void; + + class C { + @dec prop; + ~~~~ +!!! error TS2322: Type '(target: Function, propertyKey: string | symbol, paramIndex: number) => void' is not assignable to type '(target: Object, propertyKey: string | symbol) => void'. + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassProperty7.js b/tests/baselines/reference/decoratorOnClassProperty7.js new file mode 100644 index 0000000000000..ba2c8383a2cce --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty7.js @@ -0,0 +1,27 @@ +//// [decoratorOnClassProperty7.ts] +declare function dec(target: Function, propertyKey: string | symbol, paramIndex: number): void; + +class C { + @dec prop; +} + +//// [decoratorOnClassProperty7.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + __decorate([dec], C.prototype, "prop"); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnEnum.errors.txt b/tests/baselines/reference/decoratorOnEnum.errors.txt new file mode 100644 index 0000000000000..21a6d39aab501 --- /dev/null +++ b/tests/baselines/reference/decoratorOnEnum.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/decorators/invalid/decoratorOnEnum.ts(4,6): error TS1206: Decorators are not valid here. + + +==== tests/cases/conformance/decorators/invalid/decoratorOnEnum.ts (1 errors) ==== + declare function dec(target: T): T; + + @dec + enum E { + ~ +!!! error TS1206: Decorators are not valid here. + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnEnum.js b/tests/baselines/reference/decoratorOnEnum.js new file mode 100644 index 0000000000000..14651b6592834 --- /dev/null +++ b/tests/baselines/reference/decoratorOnEnum.js @@ -0,0 +1,11 @@ +//// [decoratorOnEnum.ts] +declare function dec(target: T): T; + +@dec +enum E { +} + +//// [decoratorOnEnum.js] +var E; +(function (E) { +})(E || (E = {})); diff --git a/tests/baselines/reference/decoratorOnEnum2.errors.txt b/tests/baselines/reference/decoratorOnEnum2.errors.txt new file mode 100644 index 0000000000000..3a643bc861ada --- /dev/null +++ b/tests/baselines/reference/decoratorOnEnum2.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/decorators/invalid/decoratorOnEnum2.ts(4,5): error TS1132: Enum member expected. +tests/cases/conformance/decorators/invalid/decoratorOnEnum2.ts(4,9): error TS1146: Declaration expected. +tests/cases/conformance/decorators/invalid/decoratorOnEnum2.ts(4,10): error TS2304: Cannot find name 'A'. +tests/cases/conformance/decorators/invalid/decoratorOnEnum2.ts(5,1): error TS1128: Declaration or statement expected. + + +==== tests/cases/conformance/decorators/invalid/decoratorOnEnum2.ts (4 errors) ==== + declare function dec(target: T): T; + + enum E { + @dec A + ~ +!!! error TS1132: Enum member expected. + +!!! error TS1146: Declaration expected. + ~ +!!! error TS2304: Cannot find name 'A'. + } + ~ +!!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnEnum2.js b/tests/baselines/reference/decoratorOnEnum2.js new file mode 100644 index 0000000000000..fecff1f3413be --- /dev/null +++ b/tests/baselines/reference/decoratorOnEnum2.js @@ -0,0 +1,12 @@ +//// [decoratorOnEnum2.ts] +declare function dec(target: T): T; + +enum E { + @dec A +} + +//// [decoratorOnEnum2.js] +var E; +(function (E) { +})(E || (E = {})); +A; diff --git a/tests/baselines/reference/decoratorOnFunctionDeclaration.errors.txt b/tests/baselines/reference/decoratorOnFunctionDeclaration.errors.txt new file mode 100644 index 0000000000000..bda00f1a85f82 --- /dev/null +++ b/tests/baselines/reference/decoratorOnFunctionDeclaration.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/decorators/invalid/decoratorOnFunctionDeclaration.ts(4,10): error TS1206: Decorators are not valid here. + + +==== tests/cases/conformance/decorators/invalid/decoratorOnFunctionDeclaration.ts (1 errors) ==== + declare function dec(target: T): T; + + @dec + function F() { + ~ +!!! error TS1206: Decorators are not valid here. + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnFunctionDeclaration.js b/tests/baselines/reference/decoratorOnFunctionDeclaration.js new file mode 100644 index 0000000000000..7c1a1ff5bfe69 --- /dev/null +++ b/tests/baselines/reference/decoratorOnFunctionDeclaration.js @@ -0,0 +1,10 @@ +//// [decoratorOnFunctionDeclaration.ts] +declare function dec(target: T): T; + +@dec +function F() { +} + +//// [decoratorOnFunctionDeclaration.js] +function F() { +} diff --git a/tests/baselines/reference/decoratorOnFunctionExpression.errors.txt b/tests/baselines/reference/decoratorOnFunctionExpression.errors.txt new file mode 100644 index 0000000000000..71aae3e13eb23 --- /dev/null +++ b/tests/baselines/reference/decoratorOnFunctionExpression.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/decorators/invalid/decoratorOnFunctionExpression.ts(3,9): error TS1109: Expression expected. +tests/cases/conformance/decorators/invalid/decoratorOnFunctionExpression.ts(3,23): error TS1003: Identifier expected. + + +==== tests/cases/conformance/decorators/invalid/decoratorOnFunctionExpression.ts (2 errors) ==== + declare function dec(target: T): T; + + var F = @dec function () { + ~ +!!! error TS1109: Expression expected. + ~ +!!! error TS1003: Identifier expected. + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnFunctionExpression.js b/tests/baselines/reference/decoratorOnFunctionExpression.js new file mode 100644 index 0000000000000..f6808674ed4e7 --- /dev/null +++ b/tests/baselines/reference/decoratorOnFunctionExpression.js @@ -0,0 +1,10 @@ +//// [decoratorOnFunctionExpression.ts] +declare function dec(target: T): T; + +var F = @dec function () { +} + +//// [decoratorOnFunctionExpression.js] +var F = ; +function () { +} diff --git a/tests/baselines/reference/decoratorOnImportEquals1.errors.txt b/tests/baselines/reference/decoratorOnImportEquals1.errors.txt new file mode 100644 index 0000000000000..a09a0b014278d --- /dev/null +++ b/tests/baselines/reference/decoratorOnImportEquals1.errors.txt @@ -0,0 +1,17 @@ +tests/cases/conformance/decorators/invalid/decoratorOnImportEquals1.ts(8,5): error TS1206: Decorators are not valid here. + + +==== tests/cases/conformance/decorators/invalid/decoratorOnImportEquals1.ts (1 errors) ==== + declare function dec(target: T): T; + + module M1 { + export var X: number; + } + + module M2 { + @dec + ~~~~ + import X = M1.X; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS1206: Decorators are not valid here. + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnImportEquals1.js b/tests/baselines/reference/decoratorOnImportEquals1.js new file mode 100644 index 0000000000000..440fdb99bce3b --- /dev/null +++ b/tests/baselines/reference/decoratorOnImportEquals1.js @@ -0,0 +1,17 @@ +//// [decoratorOnImportEquals1.ts] +declare function dec(target: T): T; + +module M1 { + export var X: number; +} + +module M2 { + @dec + import X = M1.X; +} + +//// [decoratorOnImportEquals1.js] +var M1; +(function (M1) { + M1.X; +})(M1 || (M1 = {})); diff --git a/tests/baselines/reference/decoratorOnImportEquals2.errors.txt b/tests/baselines/reference/decoratorOnImportEquals2.errors.txt new file mode 100644 index 0000000000000..5701afe569be2 --- /dev/null +++ b/tests/baselines/reference/decoratorOnImportEquals2.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/decorators/invalid/decoratorOnImportEquals2_1.ts(1,1): error TS1206: Decorators are not valid here. + + +==== tests/cases/conformance/decorators/invalid/decoratorOnImportEquals2_1.ts (1 errors) ==== + @dec + ~~~~ + import lib = require('./decoratorOnImportEquals2_0'); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1206: Decorators are not valid here. + + declare function dec(target: T): T; +==== tests/cases/conformance/decorators/invalid/decoratorOnImportEquals2_0.ts (0 errors) ==== + export var X; + \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnImportEquals2.js b/tests/baselines/reference/decoratorOnImportEquals2.js new file mode 100644 index 0000000000000..7db2da6b2c2b9 --- /dev/null +++ b/tests/baselines/reference/decoratorOnImportEquals2.js @@ -0,0 +1,14 @@ +//// [tests/cases/conformance/decorators/invalid/decoratorOnImportEquals2.ts] //// + +//// [decoratorOnImportEquals2_0.ts] +export var X; + +//// [decoratorOnImportEquals2_1.ts] +@dec +import lib = require('./decoratorOnImportEquals2_0'); + +declare function dec(target: T): T; + +//// [decoratorOnImportEquals2_0.js] +exports.X; +//// [decoratorOnImportEquals2_1.js] diff --git a/tests/baselines/reference/decoratorOnInterface.errors.txt b/tests/baselines/reference/decoratorOnInterface.errors.txt new file mode 100644 index 0000000000000..055b43fa877a4 --- /dev/null +++ b/tests/baselines/reference/decoratorOnInterface.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/decorators/invalid/decoratorOnInterface.ts(4,11): error TS1206: Decorators are not valid here. + + +==== tests/cases/conformance/decorators/invalid/decoratorOnInterface.ts (1 errors) ==== + declare function dec(target: T): T; + + @dec + interface I { + ~ +!!! error TS1206: Decorators are not valid here. + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnInterface.js b/tests/baselines/reference/decoratorOnInterface.js new file mode 100644 index 0000000000000..10b01f299bfab --- /dev/null +++ b/tests/baselines/reference/decoratorOnInterface.js @@ -0,0 +1,8 @@ +//// [decoratorOnInterface.ts] +declare function dec(target: T): T; + +@dec +interface I { +} + +//// [decoratorOnInterface.js] diff --git a/tests/baselines/reference/decoratorOnInternalModule.errors.txt b/tests/baselines/reference/decoratorOnInternalModule.errors.txt new file mode 100644 index 0000000000000..2fd92dfb2500a --- /dev/null +++ b/tests/baselines/reference/decoratorOnInternalModule.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/decorators/invalid/decoratorOnInternalModule.ts(4,8): error TS1206: Decorators are not valid here. + + +==== tests/cases/conformance/decorators/invalid/decoratorOnInternalModule.ts (1 errors) ==== + declare function dec(target: T): T; + + @dec + module M { + ~ +!!! error TS1206: Decorators are not valid here. + + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnInternalModule.js b/tests/baselines/reference/decoratorOnInternalModule.js new file mode 100644 index 0000000000000..d69ab6f1a5622 --- /dev/null +++ b/tests/baselines/reference/decoratorOnInternalModule.js @@ -0,0 +1,9 @@ +//// [decoratorOnInternalModule.ts] +declare function dec(target: T): T; + +@dec +module M { + +} + +//// [decoratorOnInternalModule.js] diff --git a/tests/baselines/reference/decoratorOnTypeAlias.errors.txt b/tests/baselines/reference/decoratorOnTypeAlias.errors.txt new file mode 100644 index 0000000000000..0d3109fe463f2 --- /dev/null +++ b/tests/baselines/reference/decoratorOnTypeAlias.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/decorators/invalid/decoratorOnTypeAlias.ts(3,1): error TS1206: Decorators are not valid here. + + +==== tests/cases/conformance/decorators/invalid/decoratorOnTypeAlias.ts (1 errors) ==== + declare function dec(target: T): T; + + @dec + ~~~~ + type T = number; + ~~~~~~~~~~~~~~~~ +!!! error TS1206: Decorators are not valid here. \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnTypeAlias.js b/tests/baselines/reference/decoratorOnTypeAlias.js new file mode 100644 index 0000000000000..ef4fc51034f91 --- /dev/null +++ b/tests/baselines/reference/decoratorOnTypeAlias.js @@ -0,0 +1,7 @@ +//// [decoratorOnTypeAlias.ts] +declare function dec(target: T): T; + +@dec +type T = number; + +//// [decoratorOnTypeAlias.js] diff --git a/tests/baselines/reference/decoratorOnVar.errors.txt b/tests/baselines/reference/decoratorOnVar.errors.txt new file mode 100644 index 0000000000000..bd87357edad6a --- /dev/null +++ b/tests/baselines/reference/decoratorOnVar.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/decorators/invalid/decoratorOnVar.ts(3,1): error TS1206: Decorators are not valid here. + + +==== tests/cases/conformance/decorators/invalid/decoratorOnVar.ts (1 errors) ==== + declare function dec(target: T): T; + + @dec + ~~~~ + var x: number; + ~~~~~~~~~~~~~~ +!!! error TS1206: Decorators are not valid here. \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnVar.js b/tests/baselines/reference/decoratorOnVar.js new file mode 100644 index 0000000000000..5240d59fda041 --- /dev/null +++ b/tests/baselines/reference/decoratorOnVar.js @@ -0,0 +1,8 @@ +//// [decoratorOnVar.ts] +declare function dec(target: T): T; + +@dec +var x: number; + +//// [decoratorOnVar.js] +var x; diff --git a/tests/baselines/reference/decrementOperatorWithEnumType.js b/tests/baselines/reference/decrementOperatorWithEnumType.js index 15247ea4225b6..27cb376cc05d9 100644 --- a/tests/baselines/reference/decrementOperatorWithEnumType.js +++ b/tests/baselines/reference/decrementOperatorWithEnumType.js @@ -22,8 +22,8 @@ var ENUM1; })(ENUM1 || (ENUM1 = {})); ; // expression -var ResultIsNumber1 = --0 /* "A" */; -var ResultIsNumber2 = 0 /* A */--; +var ResultIsNumber1 = --ENUM1["A"]; +var ResultIsNumber2 = ENUM1.A--; // miss assignment operator ---0 /* "A" */; +--ENUM1["A"]; ENUM1[A]--; diff --git a/tests/baselines/reference/deleteOperatorWithEnumType.js b/tests/baselines/reference/deleteOperatorWithEnumType.js index b87ab8298a725..0a17b300d3d80 100644 --- a/tests/baselines/reference/deleteOperatorWithEnumType.js +++ b/tests/baselines/reference/deleteOperatorWithEnumType.js @@ -39,13 +39,13 @@ var ENUM1; var ResultIsBoolean1 = delete ENUM; var ResultIsBoolean2 = delete ENUM1; // enum type expressions -var ResultIsBoolean3 = delete 0 /* "A" */; -var ResultIsBoolean4 = delete (ENUM[0] + 1 /* "B" */); +var ResultIsBoolean3 = delete ENUM1["A"]; +var ResultIsBoolean4 = delete (ENUM[0] + ENUM1["B"]); // multiple delete operators var ResultIsBoolean5 = delete delete ENUM; -var ResultIsBoolean6 = delete delete delete (ENUM[0] + 1 /* "B" */); +var ResultIsBoolean6 = delete delete delete (ENUM[0] + ENUM1["B"]); // miss assignment operators delete ENUM; delete ENUM1; -delete 1 /* B */; +delete ENUM1.B; delete ENUM, ENUM1; diff --git a/tests/baselines/reference/destructuringParameterProperties4.js b/tests/baselines/reference/destructuringParameterProperties4.js index 6da6f53a4fe04..cd6334c8568cd 100644 --- a/tests/baselines/reference/destructuringParameterProperties4.js +++ b/tests/baselines/reference/destructuringParameterProperties4.js @@ -28,38 +28,26 @@ class C2 extends C1 { //// [destructuringParameterProperties4.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var C1 = (function () { - function C1(k, [a, b, c]) { +class C1 { + constructor(k, [a, b, c]) { this.k = k; this.[a, b, c] = [a, b, c]; if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { this.a = a || k; } } - C1.prototype.getA = function () { + getA() { return this.a; - }; - C1.prototype.getB = function () { + } + getB() { return this.b; - }; - C1.prototype.getC = function () { + } + getC() { return this.c; - }; - return C1; -})(); -var C2 = (function (_super) { - __extends(C2, _super); - function C2() { - _super.apply(this, arguments); } - C2.prototype.doSomethingWithSuperProperties = function () { +} +class C2 extends C1 { + doSomethingWithSuperProperties() { return `${this.a} ${this.b} ${this.c}`; - }; - return C2; -})(C1); + } +} diff --git a/tests/baselines/reference/disallowLineTerminatorBeforeArrow.errors.txt b/tests/baselines/reference/disallowLineTerminatorBeforeArrow.errors.txt new file mode 100644 index 0000000000000..fbd9be772faab --- /dev/null +++ b/tests/baselines/reference/disallowLineTerminatorBeforeArrow.errors.txt @@ -0,0 +1,131 @@ +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(2,5): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(4,7): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(6,5): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(8,7): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(10,5): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(12,7): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(14,5): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(16,7): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(18,5): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(21,5): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(23,8): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(26,8): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(52,5): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(54,5): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(59,13): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(63,13): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(68,13): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(72,9): error TS1200: Line terminator not permitted before arrow. + + +==== tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts (18 errors) ==== + var f1 = () + => { } + ~~ +!!! error TS1200: Line terminator not permitted before arrow. + var f2 = (x: string, y: string) /* + */ => { } + ~~ +!!! error TS1200: Line terminator not permitted before arrow. + var f3 = (x: string, y: number, ...rest) + => { } + ~~ +!!! error TS1200: Line terminator not permitted before arrow. + var f4 = (x: string, y: number, ...rest) /* + */ => { } + ~~ +!!! error TS1200: Line terminator not permitted before arrow. + var f5 = (...rest) + => { } + ~~ +!!! error TS1200: Line terminator not permitted before arrow. + var f6 = (...rest) /* + */ => { } + ~~ +!!! error TS1200: Line terminator not permitted before arrow. + var f7 = (x: string, y: number, z = 10) + => { } + ~~ +!!! error TS1200: Line terminator not permitted before arrow. + var f8 = (x: string, y: number, z = 10) /* + */ => { } + ~~ +!!! error TS1200: Line terminator not permitted before arrow. + var f9 = (a: number): number + => a; + ~~ +!!! error TS1200: Line terminator not permitted before arrow. + var f10 = (a: number) : + number + => a + ~~ +!!! error TS1200: Line terminator not permitted before arrow. + var f11 = (a: number): number /* + */ => a; + ~~ +!!! error TS1200: Line terminator not permitted before arrow. + var f12 = (a: number) : + number /* + */ => a + ~~ +!!! error TS1200: Line terminator not permitted before arrow. + + // Should be valid. + var f11 = (a: number + ) => a; + + // Should be valid. + var f12 = (a: number) + : number => a; + + // Should be valid. + var f13 = (a: number): + number => a; + + // Should be valid. + var f14 = () /* */ => {} + + // Should be valid. + var f15 = (a: number): number /* */ => a + + // Should be valid. + var f16 = (a: number, b = 10): + number /* */ => a + b; + + function foo(func: () => boolean) { } + foo(() + => true); + ~~ +!!! error TS1200: Line terminator not permitted before arrow. + foo(() + => { return false; }); + ~~ +!!! error TS1200: Line terminator not permitted before arrow. + + module m { + class City { + constructor(x: number, thing = () + => 100) { + ~~ +!!! error TS1200: Line terminator not permitted before arrow. + } + + public m = () + => 2 * 2 * 2 + ~~ +!!! error TS1200: Line terminator not permitted before arrow. + } + + export enum Enum { + claw = (() + => 10)() + ~~ +!!! error TS1200: Line terminator not permitted before arrow. + } + + export var v = x + => new City(Enum.claw); + ~~ +!!! error TS1200: Line terminator not permitted before arrow. + } + \ No newline at end of file diff --git a/tests/baselines/reference/disallowLineTerminatorBeforeArrow.js b/tests/baselines/reference/disallowLineTerminatorBeforeArrow.js new file mode 100644 index 0000000000000..610cbe62c1bd8 --- /dev/null +++ b/tests/baselines/reference/disallowLineTerminatorBeforeArrow.js @@ -0,0 +1,178 @@ +//// [disallowLineTerminatorBeforeArrow.ts] +var f1 = () + => { } +var f2 = (x: string, y: string) /* + */ => { } +var f3 = (x: string, y: number, ...rest) + => { } +var f4 = (x: string, y: number, ...rest) /* + */ => { } +var f5 = (...rest) + => { } +var f6 = (...rest) /* + */ => { } +var f7 = (x: string, y: number, z = 10) + => { } +var f8 = (x: string, y: number, z = 10) /* + */ => { } +var f9 = (a: number): number + => a; +var f10 = (a: number) : + number + => a +var f11 = (a: number): number /* + */ => a; +var f12 = (a: number) : + number /* + */ => a + +// Should be valid. +var f11 = (a: number + ) => a; + +// Should be valid. +var f12 = (a: number) + : number => a; + +// Should be valid. +var f13 = (a: number): + number => a; + +// Should be valid. +var f14 = () /* */ => {} + +// Should be valid. +var f15 = (a: number): number /* */ => a + +// Should be valid. +var f16 = (a: number, b = 10): + number /* */ => a + b; + +function foo(func: () => boolean) { } +foo(() + => true); +foo(() + => { return false; }); + +module m { + class City { + constructor(x: number, thing = () + => 100) { + } + + public m = () + => 2 * 2 * 2 + } + + export enum Enum { + claw = (() + => 10)() + } + + export var v = x + => new City(Enum.claw); +} + + +//// [disallowLineTerminatorBeforeArrow.js] +var f1 = function () { +}; +var f2 = function (x, y) { +}; +var f3 = function (x, y) { + var rest = []; + for (var _i = 2; _i < arguments.length; _i++) { + rest[_i - 2] = arguments[_i]; + } +}; +var f4 = function (x, y) { + var rest = []; + for (var _i = 2; _i < arguments.length; _i++) { + rest[_i - 2] = arguments[_i]; + } +}; +var f5 = function () { + var rest = []; + for (var _i = 0; _i < arguments.length; _i++) { + rest[_i - 0] = arguments[_i]; + } +}; +var f6 = function () { + var rest = []; + for (var _i = 0; _i < arguments.length; _i++) { + rest[_i - 0] = arguments[_i]; + } +}; +var f7 = function (x, y, z) { + if (z === void 0) { z = 10; } +}; +var f8 = function (x, y, z) { + if (z === void 0) { z = 10; } +}; +var f9 = function (a) { + return a; +}; +var f10 = function (a) { + return a; +}; +var f11 = function (a) { + return a; +}; +var f12 = function (a) { + return a; +}; +// Should be valid. +var f11 = function (a) { + return a; +}; +// Should be valid. +var f12 = function (a) { + return a; +}; +// Should be valid. +var f13 = function (a) { + return a; +}; +// Should be valid. +var f14 = function () { +}; +// Should be valid. +var f15 = function (a) { + return a; +}; +// Should be valid. +var f16 = function (a, b) { + if (b === void 0) { b = 10; } + return a + b; +}; +function foo(func) { +} +foo(function () { + return true; +}); +foo(function () { + return false; +}); +var m; +(function (m) { + var City = (function () { + function City(x, thing) { + if (thing === void 0) { thing = function () { + return 100; + }; } + this.m = function () { + return 2 * 2 * 2; + }; + } + return City; + })(); + (function (Enum) { + Enum[Enum["claw"] = (function () { + return 10; + })()] = "claw"; + })(m.Enum || (m.Enum = {})); + var Enum = m.Enum; + m.v = function (x) { + return new City(Enum.claw); + }; +})(m || (m = {})); diff --git a/tests/baselines/reference/downlevelLetConst14.js b/tests/baselines/reference/downlevelLetConst14.js index ffe667eda3f4c..ac9444f9facca 100644 --- a/tests/baselines/reference/downlevelLetConst14.js +++ b/tests/baselines/reference/downlevelLetConst14.js @@ -59,24 +59,24 @@ use(y); var x = 10; var z0, z1, z2, z3; { - var _x = 20; - use(_x); - var _z0 = ([ + var x_1 = 20; + use(x_1); + var z0_1 = ([ 1 ])[0]; - use(_z0); - var _z1 = ([ + use(z0_1); + var z1_1 = ([ 1 ])[0]; - use(_z1); - var _z2 = ({ + use(z1_1); + var z2_1 = ({ a: 1 }).a; - use(_z2); - var _z3 = ({ + use(z2_1); + var z3_1 = ({ a: 1 }).a; - use(_z3); + use(z3_1); } use(x); use(z0); @@ -86,38 +86,38 @@ use(z3); var z6; var y = true; { - var _y = ""; - var _z6 = ([ + var y_1 = ""; + var z6_1 = ([ true ])[0]; { - var _y_1 = 1; - var _z6_1 = ({ + var y_2 = 1; + var z6_2 = ({ a: 1 }).a; - use(_y_1); - use(_z6_1); + use(y_2); + use(z6_2); } - use(_y); - use(_z6); + use(y_1); + use(z6_1); } use(y); use(z6); var z = false; var z5 = 1; { - var _z = ""; - var _z5 = ([ + var z_1 = ""; + var z5_1 = ([ 5 ])[0]; { - var _z_1 = 1; - var _z5_1 = ({ + var _z = 1; + var _z5 = ({ a: 1 }).a; // try to step on generated name - use(_z_1); + use(_z); } - use(_z); + use(z_1); } use(y); diff --git a/tests/baselines/reference/downlevelLetConst15.js b/tests/baselines/reference/downlevelLetConst15.js index 94fcb1b03a008..f1b476c017612 100644 --- a/tests/baselines/reference/downlevelLetConst15.js +++ b/tests/baselines/reference/downlevelLetConst15.js @@ -59,28 +59,28 @@ use(y); var x = 10; var z0, z1, z2, z3; { - var _x = 20; - use(_x); - var _z0 = ([ + var x_1 = 20; + use(x_1); + var z0_1 = ([ 1 ])[0]; - use(_z0); - var _z1 = ([ + use(z0_1); + var z1_1 = ([ { a: 1 } ])[0].a; - use(_z1); - var _z2 = ({ + use(z1_1); + var z2_1 = ({ a: 1 }).a; - use(_z2); - var _z3 = ({ + use(z2_1); + var z3_1 = ({ a: { b: 1 } }).a.b; - use(_z3); + use(z3_1); } use(x); use(z0); @@ -90,38 +90,38 @@ use(z3); var z6; var y = true; { - var _y = ""; - var _z6 = ([ + var y_1 = ""; + var z6_1 = ([ true ])[0]; { - var _y_1 = 1; - var _z6_1 = ({ + var y_2 = 1; + var z6_2 = ({ a: 1 }).a; - use(_y_1); - use(_z6_1); + use(y_2); + use(z6_2); } - use(_y); - use(_z6); + use(y_1); + use(z6_1); } use(y); use(z6); var z = false; var z5 = 1; { - var _z = ""; - var _z5 = ([ + var z_1 = ""; + var z5_1 = ([ 5 ])[0]; { - var _z_1 = 1; - var _z5_1 = ({ + var _z = 1; + var _z5 = ({ a: 1 }).a; // try to step on generated name - use(_z_1); + use(_z); } - use(_z); + use(z_1); } use(y); diff --git a/tests/baselines/reference/downlevelLetConst16.js b/tests/baselines/reference/downlevelLetConst16.js index f83e745c55403..aefe2830adc2f 100644 --- a/tests/baselines/reference/downlevelLetConst16.js +++ b/tests/baselines/reference/downlevelLetConst16.js @@ -236,29 +236,29 @@ use(x); use(y); use(z); function foo1() { - var _x = 1; - use(_x); - var _y = ([ + var x = 1; + use(x); + var y = ([ 1 ])[0]; - use(_y); - var _z = ({ + use(y); + var z = ({ a: 1 }).a; - use(_z); + use(z); } function foo2() { { - var _x = 1; - use(_x); - var _y = ([ + var x_1 = 1; + use(x_1); + var y_1 = ([ 1 ])[0]; - use(_y); - var _z = ({ + use(y_1); + var z_1 = ({ a: 1 }).a; - use(_z); + use(z_1); } use(x); } @@ -266,29 +266,29 @@ var A = (function () { function A() { } A.prototype.m1 = function () { - var _x = 1; - use(_x); - var _y = ([ + var x = 1; + use(x); + var y = ([ 1 ])[0]; - use(_y); - var _z = ({ + use(y); + var z = ({ a: 1 }).a; - use(_z); + use(z); }; A.prototype.m2 = function () { { - var _x = 1; - use(_x); - var _y = ([ + var x_2 = 1; + use(x_2); + var y_2 = ([ 1 ])[0]; - use(_y); - var _z = ({ + use(y_2); + var z_2 = ({ a: 1 }).a; - use(_z); + use(z_2); } use(x); }; @@ -298,200 +298,200 @@ var B = (function () { function B() { } B.prototype.m1 = function () { - var _x = 1; - use(_x); - var _y = ([ + var x = 1; + use(x); + var y = ([ 1 ])[0]; - use(_y); - var _z = ({ + use(y); + var z = ({ a: 1 }).a; - use(_z); + use(z); }; B.prototype.m2 = function () { { - var _x = 1; - use(_x); - var _y = ([ + var x_3 = 1; + use(x_3); + var y_3 = ([ 1 ])[0]; - use(_y); - var _z = ({ + use(y_3); + var z_3 = ({ a: 1 }).a; - use(_z); + use(z_3); } use(x); }; return B; })(); function bar1() { - var _x = 1; - use(_x); - var _y = ([ + var x = 1; + use(x); + var y = ([ 1 ])[0]; - use(_y); - var _z = ({ + use(y); + var z = ({ a: 1 }).a; - use(_z); + use(z); } function bar2() { { - var _x = 1; - use(_x); - var _y = ([ + var x_4 = 1; + use(x_4); + var y_4 = ([ 1 ])[0]; - use(_y); - var _z = ({ + use(y_4); + var z_4 = ({ a: 1 }).a; - use(_z); + use(z_4); } use(x); } var M1; (function (M1) { - var _x = 1; - use(_x); - var _y = ([ + var x = 1; + use(x); + var y = ([ 1 ])[0]; - use(_y); - var _z = ({ + use(y); + var z = ({ a: 1 }).a; - use(_z); + use(z); })(M1 || (M1 = {})); var M2; (function (M2) { { - var _x = 1; - use(_x); - var _y = ([ + var x_5 = 1; + use(x_5); + var y_5 = ([ 1 ])[0]; - use(_y); - var _z = ({ + use(y_5); + var z_5 = ({ a: 1 }).a; - use(_z); + use(z_5); } use(x); })(M2 || (M2 = {})); var M3; (function (M3) { - var _x = 1; - use(_x); - var _y = ([ + var x = 1; + use(x); + var y = ([ 1 ])[0]; - use(_y); - var _z = ({ + use(y); + var z = ({ a: 1 }).a; - use(_z); + use(z); })(M3 || (M3 = {})); var M4; (function (M4) { { - var _x = 1; - use(_x); - var _y = ([ + var x_6 = 1; + use(x_6); + var y_6 = ([ 1 ])[0]; - use(_y); - var _z = ({ + use(y_6); + var z_6 = ({ a: 1 }).a; - use(_z); + use(z_6); } use(x); use(y); use(z); })(M4 || (M4 = {})); function foo3() { - for (var _x = void 0;;) { - use(_x); + for (var x_7 = void 0;;) { + use(x_7); } - for (var _y = ([])[0];;) { - use(_y); + for (var y_7 = ([])[0];;) { + use(y_7); } - for (var _z = ({ + for (var z_7 = ({ a: 1 }).a;;) { - use(_z); + use(z_7); } use(x); } function foo4() { - for (var _x = 1;;) { - use(_x); + for (var x_8 = 1;;) { + use(x_8); } - for (var _y = ([])[0];;) { - use(_y); + for (var y_8 = ([])[0];;) { + use(y_8); } - for (var _z = ({ + for (var z_8 = ({ a: 1 }).a;;) { - use(_z); + use(z_8); } use(x); } function foo5() { - for (var _x in []) { - use(_x); + for (var x_9 in []) { + use(x_9); } use(x); } function foo6() { - for (var _x in []) { - use(_x); + for (var x_10 in []) { + use(x_10); } use(x); } function foo7() { for (var _i = 0, _a = []; _i < _a.length; _i++) { - var _x = _a[_i]; - use(_x); + var x_11 = _a[_i]; + use(x_11); } use(x); } function foo8() { for (var _i = 0, _a = []; _i < _a.length; _i++) { - var _x = _a[_i][0]; - use(_x); + var x_12 = _a[_i][0]; + use(x_12); } use(x); } function foo9() { for (var _i = 0, _a = []; _i < _a.length; _i++) { - var _x = _a[_i].a; - use(_x); + var x_13 = _a[_i].a; + use(x_13); } use(x); } function foo10() { for (var _i = 0, _a = []; _i < _a.length; _i++) { - var _x = _a[_i]; - use(_x); + var x_14 = _a[_i]; + use(x_14); } use(x); } function foo11() { for (var _i = 0, _a = []; _i < _a.length; _i++) { - var _x = _a[_i][0]; - use(_x); + var x_15 = _a[_i][0]; + use(x_15); } use(x); } function foo12() { for (var _i = 0, _a = []; _i < _a.length; _i++) { - var _x = _a[_i].a; - use(_x); + var x_16 = _a[_i].a; + use(x_16); } use(x); } diff --git a/tests/baselines/reference/downlevelLetConst17.js b/tests/baselines/reference/downlevelLetConst17.js index d38ec3fde08c8..56ab1e6df54c6 100644 --- a/tests/baselines/reference/downlevelLetConst17.js +++ b/tests/baselines/reference/downlevelLetConst17.js @@ -70,54 +70,54 @@ for (const x of []) { //// [downlevelLetConst17.js] 'use strict'; var x; -for (var _x = 10;;) { - use(_x); +for (var x_1 = 10;;) { + use(x_1); } use(x); -for (var _x_1 = 10;;) { - use(_x_1); +for (var x_2 = 10;;) { + use(x_2); } for (;;) { - var _x_2 = 10; - use(_x_2); - _x_2 = 1; + var x_3 = 10; + use(x_3); + x_3 = 1; } for (;;) { - var _x_3 = 10; - use(_x_3); + var x_4 = 10; + use(x_4); } -for (var _x_4 = void 0;;) { - use(_x_4); - _x_4 = 1; +for (var x_5 = void 0;;) { + use(x_5); + x_5 = 1; } for (;;) { - var _x_5 = void 0; - use(_x_5); - _x_5 = 1; + var x_6 = void 0; + use(x_6); + x_6 = 1; } while (true) { - var _x_6 = void 0; - use(_x_6); + var x_7 = void 0; + use(x_7); } while (true) { - var _x_7 = true; - use(_x_7); + var x_8 = true; + use(x_8); } do { - var _x_8 = void 0; - use(_x_8); + var x_9 = void 0; + use(x_9); } while (true); do { - var _x_9 = void 0; - use(_x_9); + var x_10 = void 0; + use(x_10); } while (true); -for (var _x_10 in []) { - use(_x_10); +for (var x_11 in []) { + use(x_11); } -for (var _x_11 in []) { - use(_x_11); +for (var x_12 in []) { + use(x_12); } for (var _i = 0, _a = []; _i < _a.length; _i++) { - var _x_12 = _a[_i]; - use(_x_12); + var x_13 = _a[_i]; + use(x_13); } diff --git a/tests/baselines/reference/downlevelLetConst18.js b/tests/baselines/reference/downlevelLetConst18.js index 0c025573e209b..f3b2306d62b33 100644 --- a/tests/baselines/reference/downlevelLetConst18.js +++ b/tests/baselines/reference/downlevelLetConst18.js @@ -38,40 +38,40 @@ for (var x = void 0;;) { } ; } -for (var _x = void 0;;) { +for (var x = void 0;;) { function foo() { - _x; + x; } ; } -for (var _x_1 = void 0;;) { +for (var x = void 0;;) { (function () { - _x_1; + x; })(); } -for (var _x_2 = 1;;) { +for (var x = 1;;) { (function () { - _x_2; + x; })(); } -for (var _x_3 = void 0;;) { +for (var x = void 0;;) { ({ foo: function () { - _x_3; + x; } }); } -for (var _x_4 = void 0;;) { +for (var x = void 0;;) { ({ get foo() { - return _x_4; + return x; } }); } -for (var _x_5 = void 0;;) { +for (var x = void 0;;) { ({ set foo(v) { - _x_5; + x; } }); } diff --git a/tests/baselines/reference/downlevelLetConst19.js b/tests/baselines/reference/downlevelLetConst19.js index adcc2e256a81d..2b3ec8036cbdb 100644 --- a/tests/baselines/reference/downlevelLetConst19.js +++ b/tests/baselines/reference/downlevelLetConst19.js @@ -24,14 +24,14 @@ use(x) var x; function a() { { - var _x; - use(_x); + var x_1; + use(x_1); function b() { { - var _x_1; - use(_x_1); + var x_2; + use(x_2); } - use(_x); + use(x_1); } } use(x); diff --git a/tests/baselines/reference/duplicateExportAssignments.js b/tests/baselines/reference/duplicateExportAssignments.js index 7d2776962f7ad..3742a5f1fe54f 100644 --- a/tests/baselines/reference/duplicateExportAssignments.js +++ b/tests/baselines/reference/duplicateExportAssignments.js @@ -56,8 +56,8 @@ var y = (function () { module.exports = x; //// [foo3.js] var x; -(function (_x) { - _x.x = 10; +(function (x_1) { + x_1.x = 10; })(x || (x = {})); var y = (function () { function y() { diff --git a/tests/baselines/reference/duplicateLocalVariable4.js b/tests/baselines/reference/duplicateLocalVariable4.js index d7d67f28d5099..34fe30a1f1c12 100644 --- a/tests/baselines/reference/duplicateLocalVariable4.js +++ b/tests/baselines/reference/duplicateLocalVariable4.js @@ -12,4 +12,4 @@ var E; E[E["a"] = 0] = "a"; })(E || (E = {})); var x = E; -var x = 0 /* a */; +var x = E.a; diff --git a/tests/baselines/reference/emitArrowFunctionWhenUsingArguments.errors.txt b/tests/baselines/reference/emitArrowFunctionWhenUsingArguments.errors.txt index 3a0ab0e597c9b..2f5ca2a387c84 100644 --- a/tests/baselines/reference/emitArrowFunctionWhenUsingArguments.errors.txt +++ b/tests/baselines/reference/emitArrowFunctionWhenUsingArguments.errors.txt @@ -1,21 +1,21 @@ -tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(2,15): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. -tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(7,19): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. -tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(13,13): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. -tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(19,15): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(2,15): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(7,19): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(13,13): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(19,15): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. ==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts (4 errors) ==== var a = () => { var arg = arguments[0]; // error ~~~~~~~~~ -!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. } var b = function () { var a = () => { var arg = arguments[0]; // error ~~~~~~~~~ -!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. } } @@ -23,7 +23,7 @@ tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts () => { var arg = arguments[0]; ~~~~~~~~~ -!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. } } @@ -31,7 +31,7 @@ tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts foo(() => { var arg = arguments[0]; // error ~~~~~~~~~ -!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. }); function bar() { diff --git a/tests/baselines/reference/emitArrowFunctionWhenUsingArgumentsES6.errors.txt b/tests/baselines/reference/emitArrowFunctionWhenUsingArgumentsES6.errors.txt index f879f11799b15..26f204d3ee6e3 100644 --- a/tests/baselines/reference/emitArrowFunctionWhenUsingArgumentsES6.errors.txt +++ b/tests/baselines/reference/emitArrowFunctionWhenUsingArgumentsES6.errors.txt @@ -1,21 +1,21 @@ -tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(2,15): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. -tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(7,19): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. -tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(13,13): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. -tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(19,15): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(2,15): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(7,19): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(13,13): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(19,15): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. ==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts (4 errors) ==== var a = () => { var arg = arguments[0]; // error ~~~~~~~~~ -!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. } var b = function () { var a = () => { var arg = arguments[0]; // error ~~~~~~~~~ -!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. } } @@ -23,7 +23,7 @@ tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6 () => { var arg = arguments[0]; ~~~~~~~~~ -!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. } } @@ -31,7 +31,7 @@ tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6 foo(() => { var arg = arguments[0]; // error ~~~~~~~~~ -!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. }); function bar() { diff --git a/tests/baselines/reference/emitClassDeclarationOverloadInES6.js b/tests/baselines/reference/emitClassDeclarationOverloadInES6.js new file mode 100644 index 0000000000000..4cf96778f3f4d --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationOverloadInES6.js @@ -0,0 +1,21 @@ +//// [emitClassDeclarationOverloadInES6.ts] +class C { + constructor(y: any) + constructor(x: number) { + } +} + +class D { + constructor(y: any) + constructor(x: number, z="hello") {} +} + +//// [emitClassDeclarationOverloadInES6.js] +class C { + constructor(x) { + } +} +class D { + constructor(x, z = "hello") { + } +} diff --git a/tests/baselines/reference/emitClassDeclarationOverloadInES6.types b/tests/baselines/reference/emitClassDeclarationOverloadInES6.types new file mode 100644 index 0000000000000..850a5aa545621 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationOverloadInES6.types @@ -0,0 +1,22 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationOverloadInES6.ts === +class C { +>C : C + + constructor(y: any) +>y : any + + constructor(x: number) { +>x : number + } +} + +class D { +>D : D + + constructor(y: any) +>y : any + + constructor(x: number, z="hello") {} +>x : number +>z : string +} diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.js b/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.js new file mode 100644 index 0000000000000..8c115b17e9c2c --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.js @@ -0,0 +1,42 @@ +//// [emitClassDeclarationWithConstructorInES6.ts] +class A { + y: number; + constructor(x: number) { + } + foo(a: any); + foo() { } +} + +class B { + y: number; + x: string = "hello"; + _bar: string; + + constructor(x: number, z = "hello", ...args) { + this.y = 10; + } + baz(...args): string; + baz(z: string, v: number): string { + return this._bar; + } +} + + + + +//// [emitClassDeclarationWithConstructorInES6.js] +class A { + constructor(x) { + } + foo() { + } +} +class B { + constructor(x, z = "hello", ...args) { + this.x = "hello"; + this.y = 10; + } + baz(z, v) { + return this._bar; + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.types b/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.types new file mode 100644 index 0000000000000..10244bf61702d --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.types @@ -0,0 +1,59 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorInES6.ts === +class A { +>A : A + + y: number; +>y : number + + constructor(x: number) { +>x : number + } + foo(a: any); +>foo : (a: any) => any +>a : any + + foo() { } +>foo : (a: any) => any +} + +class B { +>B : B + + y: number; +>y : number + + x: string = "hello"; +>x : string + + _bar: string; +>_bar : string + + constructor(x: number, z = "hello", ...args) { +>x : number +>z : string +>args : any[] + + this.y = 10; +>this.y = 10 : number +>this.y : number +>this : B +>y : number + } + baz(...args): string; +>baz : (...args: any[]) => string +>args : any[] + + baz(z: string, v: number): string { +>baz : (...args: any[]) => string +>z : string +>v : number + + return this._bar; +>this._bar : string +>this : B +>_bar : string + } +} + + + diff --git a/tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.js b/tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.js new file mode 100644 index 0000000000000..cd217af6a81d3 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.js @@ -0,0 +1,24 @@ +//// [emitClassDeclarationWithExtensionAndTypeArgumentInES6.ts] +class B { + constructor(a: T) { } +} +class C extends B { } +class D extends B { + constructor(a: any) + constructor(b: number) { + super(b); + } +} + +//// [emitClassDeclarationWithExtensionAndTypeArgumentInES6.js] +class B { + constructor(a) { + } +} +class C extends B { +} +class D extends B { + constructor(b) { + super(b); + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.types b/tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.types new file mode 100644 index 0000000000000..0f546fa7b8620 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.types @@ -0,0 +1,29 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionAndTypeArgumentInES6.ts === +class B { +>B : B +>T : T + + constructor(a: T) { } +>a : T +>T : T +} +class C extends B { } +>C : C +>B : B + +class D extends B { +>D : D +>B : B + + constructor(a: any) +>a : any + + constructor(b: number) { +>b : number + + super(b); +>super(b) : void +>super : typeof B +>b : number + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.js b/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.js new file mode 100644 index 0000000000000..5c64aebd16a56 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.js @@ -0,0 +1,48 @@ +//// [emitClassDeclarationWithExtensionInES6.ts] +class B { + baz(a: string, y = 10) { } +} +class C extends B { + foo() { } + baz(a: string, y:number) { + super.baz(a, y); + } +} +class D extends C { + constructor() { + super(); + } + + foo() { + super.foo(); + } + + baz() { + super.baz("hello", 10); + } +} + + +//// [emitClassDeclarationWithExtensionInES6.js] +class B { + baz(a, y = 10) { + } +} +class C extends B { + foo() { + } + baz(a, y) { + super.baz(a, y); + } +} +class D extends C { + constructor() { + super(); + } + foo() { + super.foo(); + } + baz() { + super.baz("hello", 10); + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.types b/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.types new file mode 100644 index 0000000000000..a1549be5df4ac --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.types @@ -0,0 +1,61 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionInES6.ts === +class B { +>B : B + + baz(a: string, y = 10) { } +>baz : (a: string, y?: number) => void +>a : string +>y : number +} +class C extends B { +>C : C +>B : B + + foo() { } +>foo : () => void + + baz(a: string, y:number) { +>baz : (a: string, y: number) => void +>a : string +>y : number + + super.baz(a, y); +>super.baz(a, y) : void +>super.baz : (a: string, y?: number) => void +>super : B +>baz : (a: string, y?: number) => void +>a : string +>y : number + } +} +class D extends C { +>D : D +>C : C + + constructor() { + super(); +>super() : void +>super : typeof C + } + + foo() { +>foo : () => void + + super.foo(); +>super.foo() : void +>super.foo : () => void +>super : C +>foo : () => void + } + + baz() { +>baz : () => void + + super.baz("hello", 10); +>super.baz("hello", 10) : void +>super.baz : (a: string, y: number) => void +>super : C +>baz : (a: string, y: number) => void + } +} + diff --git a/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js b/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js new file mode 100644 index 0000000000000..68ccd1568edd7 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js @@ -0,0 +1,57 @@ +//// [emitClassDeclarationWithGetterSetterInES6.ts] +class C { + _name: string; + get name(): string { + return this._name; + } + static get name2(): string { + return "BYE"; + } + static get ["computedname"]() { + return ""; + } + get ["computedname"]() { + return ""; + } + get ["computedname"]() { + return ""; + } + + set ["computedname"](x: any) { + } + set ["computedname"](y: string) { + } + + set foo(a: string) { } + static set bar(b: number) { } + static set ["computedname"](b: string) { } +} + +//// [emitClassDeclarationWithGetterSetterInES6.js] +class C { + get name() { + return this._name; + } + static get name2() { + return "BYE"; + } + static get ["computedname"]() { + return ""; + } + get ["computedname"]() { + return ""; + } + get ["computedname"]() { + return ""; + } + set ["computedname"](x) { + } + set ["computedname"](y) { + } + set foo(a) { + } + static set bar(b) { + } + static set ["computedname"](b) { + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.types b/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.types new file mode 100644 index 0000000000000..83d4fcd0d802f --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.types @@ -0,0 +1,48 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithGetterSetterInES6.ts === +class C { +>C : C + + _name: string; +>_name : string + + get name(): string { +>name : string + + return this._name; +>this._name : string +>this : C +>_name : string + } + static get name2(): string { +>name2 : string + + return "BYE"; + } + static get ["computedname"]() { + return ""; + } + get ["computedname"]() { + return ""; + } + get ["computedname"]() { + return ""; + } + + set ["computedname"](x: any) { +>x : any + } + set ["computedname"](y: string) { +>y : string + } + + set foo(a: string) { } +>foo : string +>a : string + + static set bar(b: number) { } +>bar : number +>b : number + + static set ["computedname"](b: string) { } +>b : string +} diff --git a/tests/baselines/reference/emitClassDeclarationWithLiteralPropertyNameInES6.js b/tests/baselines/reference/emitClassDeclarationWithLiteralPropertyNameInES6.js new file mode 100644 index 0000000000000..d82750f276fcc --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithLiteralPropertyNameInES6.js @@ -0,0 +1,37 @@ +//// [emitClassDeclarationWithLiteralPropertyNameInES6.ts] +class B { + "hello" = 10; + 0b110 = "world"; + 0o23534 = "WORLD"; + 20 = "twenty"; + "foo"() { } + 0b1110() {} + 11() { } + interface() { } + static "hi" = 10000; + static 22 = "twenty-two"; + static 0b101 = "binary"; + static 0o3235 = "octal"; +} + +//// [emitClassDeclarationWithLiteralPropertyNameInES6.js] +class B { + constructor() { + this["hello"] = 10; + this[0b110] = "world"; + this[0o23534] = "WORLD"; + this[20] = "twenty"; + } + "foo"() { + } + 0b1110() { + } + 11() { + } + interface() { + } +} +B["hi"] = 10000; +B[22] = "twenty-two"; +B[0b101] = "binary"; +B[0o3235] = "octal"; diff --git a/tests/baselines/reference/emitClassDeclarationWithLiteralPropertyNameInES6.types b/tests/baselines/reference/emitClassDeclarationWithLiteralPropertyNameInES6.types new file mode 100644 index 0000000000000..65ba8f7d2b9b0 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithLiteralPropertyNameInES6.types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithLiteralPropertyNameInES6.ts === +class B { +>B : B + + "hello" = 10; + 0b110 = "world"; + 0o23534 = "WORLD"; + 20 = "twenty"; + "foo"() { } + 0b1110() {} + 11() { } + interface() { } +>interface : () => void + + static "hi" = 10000; + static 22 = "twenty-two"; + static 0b101 = "binary"; + static 0o3235 = "octal"; +} diff --git a/tests/baselines/reference/emitClassDeclarationWithMethodInES6.js b/tests/baselines/reference/emitClassDeclarationWithMethodInES6.js new file mode 100644 index 0000000000000..20f58b4274e1d --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithMethodInES6.js @@ -0,0 +1,58 @@ +//// [emitClassDeclarationWithMethodInES6.ts] +class D { + _bar: string; + foo() { } + ["computedName"]() { } + ["computedName"](a: string) { } + ["computedName"](a: string): number { return 1; } + bar(): string { + return this._bar; + } + baz(a: any, x: string): string { + return "HELLO"; + } + static ["computedname"]() { } + static ["computedname"](a: string) { } + static ["computedname"](a: string): boolean { return true; } + static staticMethod() { + var x = 1 + 2; + return x + } + static foo(a: string) { } + static bar(a: string): number { return 1; } +} + +//// [emitClassDeclarationWithMethodInES6.js] +class D { + foo() { + } + ["computedName"]() { + } + ["computedName"](a) { + } + ["computedName"](a) { + return 1; + } + bar() { + return this._bar; + } + baz(a, x) { + return "HELLO"; + } + static ["computedname"]() { + } + static ["computedname"](a) { + } + static ["computedname"](a) { + return true; + } + static staticMethod() { + var x = 1 + 2; + return x; + } + static foo(a) { + } + static bar(a) { + return 1; + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithMethodInES6.types b/tests/baselines/reference/emitClassDeclarationWithMethodInES6.types new file mode 100644 index 0000000000000..f26a9f87e6d25 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithMethodInES6.types @@ -0,0 +1,57 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodInES6.ts === +class D { +>D : D + + _bar: string; +>_bar : string + + foo() { } +>foo : () => void + + ["computedName"]() { } + ["computedName"](a: string) { } +>a : string + + ["computedName"](a: string): number { return 1; } +>a : string + + bar(): string { +>bar : () => string + + return this._bar; +>this._bar : string +>this : D +>_bar : string + } + baz(a: any, x: string): string { +>baz : (a: any, x: string) => string +>a : any +>x : string + + return "HELLO"; + } + static ["computedname"]() { } + static ["computedname"](a: string) { } +>a : string + + static ["computedname"](a: string): boolean { return true; } +>a : string + + static staticMethod() { +>staticMethod : () => number + + var x = 1 + 2; +>x : number +>1 + 2 : number + + return x +>x : number + } + static foo(a: string) { } +>foo : (a: string) => void +>a : string + + static bar(a: string): number { return 1; } +>bar : (a: string) => number +>a : string +} diff --git a/tests/baselines/reference/emitClassDeclarationWithPropertyAssignmentInES6.js b/tests/baselines/reference/emitClassDeclarationWithPropertyAssignmentInES6.js new file mode 100644 index 0000000000000..03fb45b806e3d --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithPropertyAssignmentInES6.js @@ -0,0 +1,51 @@ +//// [emitClassDeclarationWithPropertyAssignmentInES6.ts] +class C { + x: string = "Hello world"; +} + +class D { + x: string = "Hello world"; + y: number; + constructor() { + this.y = 10; + } +} + +class E extends D{ + z: boolean = true; +} + +class F extends D{ + z: boolean = true; + j: string; + constructor() { + super(); + this.j = "HI"; + } +} + +//// [emitClassDeclarationWithPropertyAssignmentInES6.js] +class C { + constructor() { + this.x = "Hello world"; + } +} +class D { + constructor() { + this.x = "Hello world"; + this.y = 10; + } +} +class E extends D { + constructor(...args) { + super(...args); + this.z = true; + } +} +class F extends D { + constructor() { + super(); + this.z = true; + this.j = "HI"; + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithPropertyAssignmentInES6.types b/tests/baselines/reference/emitClassDeclarationWithPropertyAssignmentInES6.types new file mode 100644 index 0000000000000..5e7ebbc167c70 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithPropertyAssignmentInES6.types @@ -0,0 +1,56 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithPropertyAssignmentInES6.ts === +class C { +>C : C + + x: string = "Hello world"; +>x : string +} + +class D { +>D : D + + x: string = "Hello world"; +>x : string + + y: number; +>y : number + + constructor() { + this.y = 10; +>this.y = 10 : number +>this.y : number +>this : D +>y : number + } +} + +class E extends D{ +>E : E +>D : D + + z: boolean = true; +>z : boolean +} + +class F extends D{ +>F : F +>D : D + + z: boolean = true; +>z : boolean + + j: string; +>j : string + + constructor() { + super(); +>super() : void +>super : typeof D + + this.j = "HI"; +>this.j = "HI" : string +>this.j : string +>this : F +>j : string + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.js b/tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.js new file mode 100644 index 0000000000000..8e0bf3de06bcd --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.js @@ -0,0 +1,21 @@ +//// [emitClassDeclarationWithStaticPropertyAssignmentInES6.ts] +class C { + static z: string = "Foo"; +} + +class D { + x = 20000; + static b = true; +} + + +//// [emitClassDeclarationWithStaticPropertyAssignmentInES6.js] +class C { +} +C.z = "Foo"; +class D { + constructor() { + this.x = 20000; + } +} +D.b = true; diff --git a/tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.types b/tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.types new file mode 100644 index 0000000000000..6003b85b590ee --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.types @@ -0,0 +1,18 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticPropertyAssignmentInES6.ts === +class C { +>C : C + + static z: string = "Foo"; +>z : string +} + +class D { +>D : D + + x = 20000; +>x : number + + static b = true; +>b : boolean +} + diff --git a/tests/baselines/reference/emitClassDeclarationWithThisKeywordInES6.js b/tests/baselines/reference/emitClassDeclarationWithThisKeywordInES6.js new file mode 100644 index 0000000000000..14f74682c008d --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithThisKeywordInES6.js @@ -0,0 +1,38 @@ +//// [emitClassDeclarationWithThisKeywordInES6.ts] +class B { + x = 10; + constructor() { + this.x = 10; + } + static log(a: number) { } + foo() { + B.log(this.x); + } + + get X() { + return this.x; + } + + set bX(y: number) { + this.x = y; + } +} + +//// [emitClassDeclarationWithThisKeywordInES6.js] +class B { + constructor() { + this.x = 10; + this.x = 10; + } + static log(a) { + } + foo() { + B.log(this.x); + } + get X() { + return this.x; + } + set bX(y) { + this.x = y; + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithThisKeywordInES6.types b/tests/baselines/reference/emitClassDeclarationWithThisKeywordInES6.types new file mode 100644 index 0000000000000..bb0f7e9993977 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithThisKeywordInES6.types @@ -0,0 +1,52 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeywordInES6.ts === +class B { +>B : B + + x = 10; +>x : number + + constructor() { + this.x = 10; +>this.x = 10 : number +>this.x : number +>this : B +>x : number + } + static log(a: number) { } +>log : (a: number) => void +>a : number + + foo() { +>foo : () => void + + B.log(this.x); +>B.log(this.x) : void +>B.log : (a: number) => void +>B : typeof B +>log : (a: number) => void +>this.x : number +>this : B +>x : number + } + + get X() { +>X : number + + return this.x; +>this.x : number +>this : B +>x : number + } + + set bX(y: number) { +>bX : number +>y : number + + this.x = y; +>this.x = y : number +>this.x : number +>this : B +>x : number +>y : number + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverloadInES6.js b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverloadInES6.js new file mode 100644 index 0000000000000..8dc5b6cddaabc --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverloadInES6.js @@ -0,0 +1,39 @@ +//// [emitClassDeclarationWithTypeArgumentAndOverloadInES6.ts] +class B { + x: T; + B: T; + + constructor(a: any) + constructor(a: any,b: T) + constructor(a: T) { this.B = a;} + + foo(a: T) + foo(a: any) + foo(b: string) + foo(): T { + return this.x; + } + + get BB(): T { + return this.B; + } + set BBWith(c: T) { + this.B = c; + } +} + +//// [emitClassDeclarationWithTypeArgumentAndOverloadInES6.js] +class B { + constructor(a) { + this.B = a; + } + foo() { + return this.x; + } + get BB() { + return this.B; + } + set BBWith(c) { + this.B = c; + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverloadInES6.types b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverloadInES6.types new file mode 100644 index 0000000000000..ba515168a5d7d --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverloadInES6.types @@ -0,0 +1,75 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentAndOverloadInES6.ts === +class B { +>B : B +>T : T + + x: T; +>x : T +>T : T + + B: T; +>B : T +>T : T + + constructor(a: any) +>a : any + + constructor(a: any,b: T) +>a : any +>b : T +>T : T + + constructor(a: T) { this.B = a;} +>a : T +>T : T +>this.B = a : T +>this.B : T +>this : B +>B : T +>a : T + + foo(a: T) +>foo : { (a: T): any; (a: any): any; (b: string): any; } +>a : T +>T : T + + foo(a: any) +>foo : { (a: T): any; (a: any): any; (b: string): any; } +>a : any + + foo(b: string) +>foo : { (a: T): any; (a: any): any; (b: string): any; } +>b : string + + foo(): T { +>foo : { (a: T): any; (a: any): any; (b: string): any; } +>T : T + + return this.x; +>this.x : T +>this : B +>x : T + } + + get BB(): T { +>BB : T +>T : T + + return this.B; +>this.B : T +>this : B +>B : T + } + set BBWith(c: T) { +>BBWith : T +>c : T +>T : T + + this.B = c; +>this.B = c : T +>this.B : T +>this : B +>B : T +>c : T + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithTypeArgumentInES6.js b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentInES6.js new file mode 100644 index 0000000000000..4e2872b4f0646 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentInES6.js @@ -0,0 +1,31 @@ +//// [emitClassDeclarationWithTypeArgumentInES6.ts] +class B { + x: T; + B: T; + constructor(a: T) { this.B = a;} + foo(): T { + return this.x; + } + get BB(): T { + return this.B; + } + set BBWith(c: T) { + this.B = c; + } +} + +//// [emitClassDeclarationWithTypeArgumentInES6.js] +class B { + constructor(a) { + this.B = a; + } + foo() { + return this.x; + } + get BB() { + return this.B; + } + set BBWith(c) { + this.B = c; + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithTypeArgumentInES6.types b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentInES6.types new file mode 100644 index 0000000000000..8081d044e359e --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentInES6.types @@ -0,0 +1,53 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentInES6.ts === +class B { +>B : B +>T : T + + x: T; +>x : T +>T : T + + B: T; +>B : T +>T : T + + constructor(a: T) { this.B = a;} +>a : T +>T : T +>this.B = a : T +>this.B : T +>this : B +>B : T +>a : T + + foo(): T { +>foo : () => T +>T : T + + return this.x; +>this.x : T +>this : B +>x : T + } + get BB(): T { +>BB : T +>T : T + + return this.B; +>this.B : T +>this : B +>B : T + } + set BBWith(c: T) { +>BBWith : T +>c : T +>T : T + + this.B = c; +>this.B = c : T +>this.B : T +>this : B +>B : T +>c : T + } +} diff --git a/tests/baselines/reference/emitDefaultParametersMethodES6.js b/tests/baselines/reference/emitDefaultParametersMethodES6.js index bf96e00e375fd..3981ddcba3cc6 100644 --- a/tests/baselines/reference/emitDefaultParametersMethodES6.js +++ b/tests/baselines/reference/emitDefaultParametersMethodES6.js @@ -17,26 +17,23 @@ class E { } //// [emitDefaultParametersMethodES6.js] -var C = (function () { - function C(t, z, x, y = "hello") { +class C { + constructor(t, z, x, y = "hello") { } - C.prototype.foo = function (x, t = false) { - }; - C.prototype.foo1 = function (x, t = false, ...rest) { - }; - C.prototype.bar = function (t = false) { - }; - C.prototype.boo = function (t = false, ...rest) { - }; - return C; -})(); -var D = (function () { - function D(y = "hello") { + foo(x, t = false) { } - return D; -})(); -var E = (function () { - function E(y = "hello", ...rest) { + foo1(x, t = false, ...rest) { } - return E; -})(); + bar(t = false) { + } + boo(t = false, ...rest) { + } +} +class D { + constructor(y = "hello") { + } +} +class E { + constructor(y = "hello", ...rest) { + } +} diff --git a/tests/baselines/reference/emitRestParametersMethodES6.js b/tests/baselines/reference/emitRestParametersMethodES6.js index d0a0e2a120ccc..fba6ed01e676f 100644 --- a/tests/baselines/reference/emitRestParametersMethodES6.js +++ b/tests/baselines/reference/emitRestParametersMethodES6.js @@ -15,21 +15,19 @@ class D { //// [emitRestParametersMethodES6.js] -var C = (function () { - function C(name, ...rest) { +class C { + constructor(name, ...rest) { } - C.prototype.bar = function (...rest) { - }; - C.prototype.foo = function (x, ...rest) { - }; - return C; -})(); -var D = (function () { - function D(...rest) { + bar(...rest) { } - D.prototype.bar = function (...rest) { - }; - D.prototype.foo = function (x, ...rest) { - }; - return D; -})(); + foo(x, ...rest) { + } +} +class D { + constructor(...rest) { + } + bar(...rest) { + } + foo(x, ...rest) { + } +} diff --git a/tests/baselines/reference/emitThisInSuperMethodCall.js b/tests/baselines/reference/emitThisInSuperMethodCall.js index 383da7d419f26..de47b0b95aff4 100644 --- a/tests/baselines/reference/emitThisInSuperMethodCall.js +++ b/tests/baselines/reference/emitThisInSuperMethodCall.js @@ -49,20 +49,20 @@ var RegisteredUser = (function (_super) { RegisteredUser.prototype.f = function () { (function () { function inner() { - super.sayHello.call(this); + _super.sayHello.call(this); } }); }; RegisteredUser.prototype.g = function () { function inner() { (function () { - super.sayHello.call(this); + _super.sayHello.call(this); }); } }; RegisteredUser.prototype.h = function () { function inner() { - super.sayHello.call(this); + _super.sayHello.call(this); } }; return RegisteredUser; diff --git a/tests/baselines/reference/enumAssignability.js b/tests/baselines/reference/enumAssignability.js index 874c177c4e6cd..5bf639d9cf1ad 100644 --- a/tests/baselines/reference/enumAssignability.js +++ b/tests/baselines/reference/enumAssignability.js @@ -64,8 +64,8 @@ var F; (function (F) { F[F["B"] = 0] = "B"; })(F || (F = {})); -var e = 0 /* A */; -var f = 0 /* B */; +var e = E.A; +var f = F.B; e = f; f = e; e = 1; // ok diff --git a/tests/baselines/reference/enumAssignabilityInInheritance.js b/tests/baselines/reference/enumAssignabilityInInheritance.js index bec59a3d0de9d..065c561d9eb01 100644 --- a/tests/baselines/reference/enumAssignabilityInInheritance.js +++ b/tests/baselines/reference/enumAssignabilityInInheritance.js @@ -115,42 +115,42 @@ var E; (function (E) { E[E["A"] = 0] = "A"; })(E || (E = {})); -var r = foo(0 /* A */); // E +var r = foo(E.A); // E var r2 = foo(1); // number var r3 = foo(null); // any -var r4 = foo2(0 /* A */); -var r4 = foo3(0 /* A */); -var r4 = foo4(0 /* A */); -var r4 = foo5(0 /* A */); -var r4 = foo6(0 /* A */); -var r4 = foo7(0 /* A */); -var r4 = foo8(0 /* A */); +var r4 = foo2(E.A); +var r4 = foo3(E.A); +var r4 = foo4(E.A); +var r4 = foo5(E.A); +var r4 = foo6(E.A); +var r4 = foo7(E.A); +var r4 = foo8(E.A); var A = (function () { function A() { } return A; })(); -var r4 = foo9(0 /* A */); +var r4 = foo9(E.A); var A2 = (function () { function A2() { } return A2; })(); -var r4 = foo10(0 /* A */); -var r4 = foo11(0 /* A */); -var r4 = foo12(0 /* A */); +var r4 = foo10(E.A); +var r4 = foo11(E.A); +var r4 = foo12(E.A); var E2; (function (E2) { E2[E2["A"] = 0] = "A"; })(E2 || (E2 = {})); -var r4 = foo13(0 /* A */); +var r4 = foo13(E.A); function f() { } var f; (function (f) { f.bar = 1; })(f || (f = {})); -var r4 = foo14(0 /* A */); +var r4 = foo14(E.A); var CC = (function () { function CC() { } @@ -160,6 +160,6 @@ var CC; (function (CC) { CC.bar = 1; })(CC || (CC = {})); -var r4 = foo15(0 /* A */); -var r4 = foo16(0 /* A */); -var r4 = foo16(0 /* A */); +var r4 = foo15(E.A); +var r4 = foo16(E.A); +var r4 = foo16(E.A); diff --git a/tests/baselines/reference/enumAssignmentCompat.js b/tests/baselines/reference/enumAssignmentCompat.js index 24f65bc96a96f..f56b1f300ed53 100644 --- a/tests/baselines/reference/enumAssignmentCompat.js +++ b/tests/baselines/reference/enumAssignmentCompat.js @@ -57,15 +57,15 @@ var W; var x = W; var y = W; var z = W; // error -var a = 0 /* a */; -var b = 0 /* a */; // error -var c = 0 /* a */; +var a = W.a; +var b = W.a; // error +var c = W.a; var d = 3; // error var e = 4; -var f = 0 /* a */; // error +var f = W.a; // error var g = 5; // error var h = 3; -var i = 0 /* a */; -i = 0 /* a */; +var i = W.a; +i = W.a; W.D; var p; diff --git a/tests/baselines/reference/enumAssignmentCompat2.js b/tests/baselines/reference/enumAssignmentCompat2.js index 7ded9416c1116..1fb7eb65e3696 100644 --- a/tests/baselines/reference/enumAssignmentCompat2.js +++ b/tests/baselines/reference/enumAssignmentCompat2.js @@ -56,15 +56,15 @@ var W; var x = W; var y = W; var z = W; // error -var a = 0 /* a */; -var b = 0 /* a */; // error -var c = 0 /* a */; +var a = W.a; +var b = W.a; // error +var c = W.a; var d = 3; // error var e = 4; -var f = 0 /* a */; // error +var f = W.a; // error var g = 5; // error var h = 3; -var i = 0 /* a */; -i = 0 /* a */; +var i = W.a; +i = W.a; W.D; var p; diff --git a/tests/baselines/reference/enumBasics.js b/tests/baselines/reference/enumBasics.js index 6f1a039ca6ea9..f6548f99b9582 100644 --- a/tests/baselines/reference/enumBasics.js +++ b/tests/baselines/reference/enumBasics.js @@ -89,13 +89,13 @@ var E1; E1[E1["C"] = 2] = "C"; })(E1 || (E1 = {})); // Enum type is a subtype of Number -var x = 0 /* A */; +var x = E1.A; // Enum object type is anonymous with properties of the enum type and numeric indexer var e = E1; var e; var e; // Reverse mapping of enum returns string name of property -var s = E1[0 /* A */]; +var s = E1[e.A]; var s; // Enum with only constant members var E2; @@ -108,7 +108,7 @@ var E2; var E3; (function (E3) { E3[E3["X"] = 'foo'.length] = "X"; - E3[E3["Y"] = 4 + 3] = "Y"; + E3[E3["Y"] = 7] = "Y"; E3[E3["Z"] = +'foo'] = "Z"; })(E3 || (E3 = {})); // Enum with constant members followed by computed members @@ -145,7 +145,7 @@ var E8; var E9; (function (E9) { E9[E9["A"] = 0] = "A"; - E9[E9["B"] = E9.A] = "B"; + E9[E9["B"] = 0] = "B"; })(E9 || (E9 = {})); // (refer to .js to validate) // Enum constant members are propagated @@ -159,12 +159,12 @@ var doNotPropagate = [ ]; // Enum computed members are not propagated var doPropagate = [ - 0 /* A */, + E9.A, E9.B, - 0 /* B */, - 1 /* C */, - 0 /* A */, - 0 /* A */, - 3 /* B */, - 4 /* C */ + E6.B, + E6.C, + E6.A, + E5.A, + E5.B, + E5.C ]; diff --git a/tests/baselines/reference/enumBasics1.js b/tests/baselines/reference/enumBasics1.js index 13b6da353b9b4..e5c9c6d29d4a6 100644 --- a/tests/baselines/reference/enumBasics1.js +++ b/tests/baselines/reference/enumBasics1.js @@ -63,7 +63,7 @@ class C { var e = E; // shouldn't error */ -1 /* A */.A; // should error +E.A.A; // should error var E2; (function (E2) { E2[E2["A"] = 0] = "A"; diff --git a/tests/baselines/reference/enumConflictsWithGlobalIdentifier.js b/tests/baselines/reference/enumConflictsWithGlobalIdentifier.js index 67d9a020bb60f..d463073bb81c5 100644 --- a/tests/baselines/reference/enumConflictsWithGlobalIdentifier.js +++ b/tests/baselines/reference/enumConflictsWithGlobalIdentifier.js @@ -12,4 +12,4 @@ var Position; Position[Position["IgnoreRulesSpecific"] = 0] = "IgnoreRulesSpecific"; })(Position || (Position = {})); var x = IgnoreRulesSpecific.; -var y = 0 /* IgnoreRulesSpecific */; +var y = Position.IgnoreRulesSpecific; diff --git a/tests/baselines/reference/enumErrors.errors.txt b/tests/baselines/reference/enumErrors.errors.txt index ca13ceba4aeff..14cad3cb53b06 100644 --- a/tests/baselines/reference/enumErrors.errors.txt +++ b/tests/baselines/reference/enumErrors.errors.txt @@ -3,15 +3,13 @@ tests/cases/conformance/enums/enumErrors.ts(3,6): error TS2431: Enum name cannot tests/cases/conformance/enums/enumErrors.ts(4,6): error TS2431: Enum name cannot be 'string' tests/cases/conformance/enums/enumErrors.ts(5,6): error TS2431: Enum name cannot be 'boolean' tests/cases/conformance/enums/enumErrors.ts(9,9): error TS2322: Type 'Number' is not assignable to type 'E5'. -tests/cases/conformance/enums/enumErrors.ts(20,9): error TS2322: Type 'E9' is not assignable to type 'E10'. -tests/cases/conformance/enums/enumErrors.ts(21,9): error TS2322: Type 'E9' is not assignable to type 'E10'. tests/cases/conformance/enums/enumErrors.ts(26,9): error TS2322: Type 'string' is not assignable to type 'E11'. tests/cases/conformance/enums/enumErrors.ts(27,9): error TS2322: Type 'Date' is not assignable to type 'E11'. tests/cases/conformance/enums/enumErrors.ts(28,9): error TS2304: Cannot find name 'window'. tests/cases/conformance/enums/enumErrors.ts(29,9): error TS2322: Type '{}' is not assignable to type 'E11'. -==== tests/cases/conformance/enums/enumErrors.ts (11 errors) ==== +==== tests/cases/conformance/enums/enumErrors.ts (9 errors) ==== // Enum named with PredefinedTypes enum any { } ~~~ @@ -42,11 +40,7 @@ tests/cases/conformance/enums/enumErrors.ts(29,9): error TS2322: Type '{}' is no // Bug 707850: This should be allowed enum E10 { A = E9.A, - ~~~~ -!!! error TS2322: Type 'E9' is not assignable to type 'E10'. B = E9.B - ~~~~ -!!! error TS2322: Type 'E9' is not assignable to type 'E10'. } // Enum with computed member intializer of other types diff --git a/tests/baselines/reference/enumErrors.js b/tests/baselines/reference/enumErrors.js index 44aa2f90162fe..a8ecdf2470a4c 100644 --- a/tests/baselines/reference/enumErrors.js +++ b/tests/baselines/reference/enumErrors.js @@ -53,14 +53,14 @@ var E5; var E9; (function (E9) { E9[E9["A"] = 0] = "A"; - E9[E9["B"] = E9.A] = "B"; + E9[E9["B"] = 0] = "B"; })(E9 || (E9 = {})); //Enum with computed member intializer of different enum type // Bug 707850: This should be allowed var E10; (function (E10) { - E10[E10["A"] = 0 /* A */] = "A"; - E10[E10["B"] = E9.B] = "B"; + E10[E10["A"] = 0] = "A"; + E10[E10["B"] = 0] = "B"; })(E10 || (E10 = {})); // Enum with computed member intializer of other types var E11; diff --git a/tests/baselines/reference/enumFromExternalModule.js b/tests/baselines/reference/enumFromExternalModule.js index 8e92cbbbda771..ed2a1f3926a34 100644 --- a/tests/baselines/reference/enumFromExternalModule.js +++ b/tests/baselines/reference/enumFromExternalModule.js @@ -18,4 +18,4 @@ var Mode = exports.Mode; //// [enumFromExternalModule_1.js] /// var f = require('enumFromExternalModule_0'); -var x = 0 /* Open */; +var x = f.Mode.Open; diff --git a/tests/baselines/reference/enumIndexer.js b/tests/baselines/reference/enumIndexer.js index 77c2708dab367..9862d787d233b 100644 --- a/tests/baselines/reference/enumIndexer.js +++ b/tests/baselines/reference/enumIndexer.js @@ -21,7 +21,7 @@ var _arr = [ key: 'bar' } ]; -var enumValue = 0 /* foo */; +var enumValue = MyEnumType.foo; var x = _arr.map(function (o) { return MyEnumType[o.key] === enumValue; }); // these are not same type diff --git a/tests/baselines/reference/enumMapBackIntoItself.js b/tests/baselines/reference/enumMapBackIntoItself.js index 2d177731b9572..80a4b88479f5d 100644 --- a/tests/baselines/reference/enumMapBackIntoItself.js +++ b/tests/baselines/reference/enumMapBackIntoItself.js @@ -16,7 +16,7 @@ var TShirtSize; TShirtSize[TShirtSize["Medium"] = 1] = "Medium"; TShirtSize[TShirtSize["Large"] = 2] = "Large"; })(TShirtSize || (TShirtSize = {})); -var mySize = 2 /* Large */; +var mySize = TShirtSize.Large; var test = TShirtSize[mySize]; // specifically checking output here, bug was that test used to be undefined at runtime test + ''; diff --git a/tests/baselines/reference/enumMemberResolution.js b/tests/baselines/reference/enumMemberResolution.js index e1d79ebeb92e8..c021eb8d47aed 100644 --- a/tests/baselines/reference/enumMemberResolution.js +++ b/tests/baselines/reference/enumMemberResolution.js @@ -14,4 +14,4 @@ var Position2; })(Position2 || (Position2 = {})); var x = IgnoreRulesSpecific.; // error var y = 1; -var z = 0 /* IgnoreRulesSpecific */; // no error +var z = Position2.IgnoreRulesSpecific; // no error diff --git a/tests/baselines/reference/enumMerging.js b/tests/baselines/reference/enumMerging.js index b76f789da1daf..d8d9373d3ffe5 100644 --- a/tests/baselines/reference/enumMerging.js +++ b/tests/baselines/reference/enumMerging.js @@ -96,12 +96,12 @@ var M1; })(M1.EConst1 || (M1.EConst1 = {})); var EConst1 = M1.EConst1; var x = [ - 3 /* A */, - 2 /* B */, - 1 /* C */, - 7 /* D */, - 9 /* E */, - 8 /* F */ + EConst1.A, + EConst1.B, + EConst1.C, + EConst1.D, + EConst1.E, + EConst1.F ]; })(M1 || (M1 = {})); // Enum with only computed members across 2 declarations with the same root module @@ -183,6 +183,6 @@ var M6; })(A.Color || (A.Color = {})); var Color = A.Color; })(A = M6.A || (M6.A = {})); - var t = 1 /* Yellow */; - t = 0 /* Red */; + var t = A.Color.Yellow; + t = A.Color.Red; })(M6 || (M6 = {})); diff --git a/tests/baselines/reference/enumOperations.js b/tests/baselines/reference/enumOperations.js index 902079c04c08d..96d9ace576c08 100644 --- a/tests/baselines/reference/enumOperations.js +++ b/tests/baselines/reference/enumOperations.js @@ -21,7 +21,7 @@ var Enum; (function (Enum) { Enum[Enum["None"] = 0] = "None"; })(Enum || (Enum = {})); -var enumType = 0 /* None */; +var enumType = Enum.None; var numberType = 0; var anyType = 0; enumType ^ numberType; diff --git a/tests/baselines/reference/enumPropertyAccess.js b/tests/baselines/reference/enumPropertyAccess.js index 4c2a7df3c94c9..1ac82b0a3de27 100644 --- a/tests/baselines/reference/enumPropertyAccess.js +++ b/tests/baselines/reference/enumPropertyAccess.js @@ -20,7 +20,7 @@ var Colors; Colors[Colors["Red"] = 0] = "Red"; Colors[Colors["Green"] = 1] = "Green"; })(Colors || (Colors = {})); -var x = 0 /* Red */; // type of 'x' should be 'Colors' +var x = Colors.Red; // type of 'x' should be 'Colors' var p = x.Green; // error x.toFixed(); // ok // Now with generics diff --git a/tests/baselines/reference/enumWithParenthesizedInitializer1.js b/tests/baselines/reference/enumWithParenthesizedInitializer1.js index 0c125b3d8b2b2..f81af2c4dda62 100644 --- a/tests/baselines/reference/enumWithParenthesizedInitializer1.js +++ b/tests/baselines/reference/enumWithParenthesizedInitializer1.js @@ -6,5 +6,5 @@ enum E { //// [enumWithParenthesizedInitializer1.js] var E; (function (E) { - E[E["e"] = -(3)] = "e"; + E[E["e"] = -3] = "e"; })(E || (E = {})); diff --git a/tests/baselines/reference/enumWithoutInitializerAfterComputedMember.js b/tests/baselines/reference/enumWithoutInitializerAfterComputedMember.js index ef9192c1c90f0..8d203e9fd71ae 100644 --- a/tests/baselines/reference/enumWithoutInitializerAfterComputedMember.js +++ b/tests/baselines/reference/enumWithoutInitializerAfterComputedMember.js @@ -9,6 +9,6 @@ enum E { var E; (function (E) { E[E["a"] = 0] = "a"; - E[E["b"] = E.a] = "b"; - E[E["c"] = undefined] = "c"; + E[E["b"] = 0] = "b"; + E[E["c"] = 1] = "c"; })(E || (E = {})); diff --git a/tests/baselines/reference/errorSuperPropertyAccess.js b/tests/baselines/reference/errorSuperPropertyAccess.js index 17cd2c265edef..4ddcca530f11a 100644 --- a/tests/baselines/reference/errorSuperPropertyAccess.js +++ b/tests/baselines/reference/errorSuperPropertyAccess.js @@ -140,27 +140,27 @@ var __extends = this.__extends || function (d, b) { //super property access in instance member accessor(get and set) of class with no base type var NoBase = (function () { function NoBase() { - this.m = super.prototype; - this.n = super.hasOwnProperty.call(this, ''); - var a = super.prototype; - var b = super.hasOwnProperty.call(this, ''); + this.m = _super.prototype; + this.n = _super.hasOwnProperty.call(this, ''); + var a = _super.prototype; + var b = _super.hasOwnProperty.call(this, ''); } NoBase.prototype.fn = function () { - var a = super.prototype; - var b = super.hasOwnProperty.call(this, ''); + var a = _super.prototype; + var b = _super.hasOwnProperty.call(this, ''); }; //super static property access in static member function of class with no base type //super static property access in static member accessor(get and set) of class with no base type NoBase.static1 = function () { - super.hasOwnProperty.call(this, ''); + _super.hasOwnProperty.call(this, ''); }; Object.defineProperty(NoBase, "static2", { get: function () { - super.hasOwnProperty.call(this, ''); + _super.hasOwnProperty.call(this, ''); return ''; }, set: function (n) { - super.hasOwnProperty.call(this, ''); + _super.hasOwnProperty.call(this, ''); }, enumerable: true, configurable: true @@ -210,11 +210,11 @@ var SomeDerived1 = (function (_super) { }); SomeDerived1.prototype.fn2 = function () { function inner() { - super.publicFunc.call(this); + _super.publicFunc.call(this); } var x = { test: function () { - return super.publicFunc.call(this); + return _super.publicFunc.call(this); } }; }; @@ -278,6 +278,6 @@ var SomeDerived3 = (function (_super) { })(SomeBase); // In object literal var obj = { - n: super.wat, - p: super.foo.call(this) + n: _super.wat, + p: _super.foo.call(this) }; diff --git a/tests/baselines/reference/es5ExportDefaultClassDeclaration.js b/tests/baselines/reference/es5ExportDefaultClassDeclaration.js new file mode 100644 index 0000000000000..9cf5098824749 --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration.js @@ -0,0 +1,22 @@ +//// [es5ExportDefaultClassDeclaration.ts] + +export default class C { + method() { } +} + + +//// [es5ExportDefaultClassDeclaration.js] +var C = (function () { + function C() { + } + C.prototype.method = function () { + }; + return C; +})(); +exports.C = C; + + +//// [es5ExportDefaultClassDeclaration.d.ts] +export default class C { + method(): void; +} diff --git a/tests/baselines/reference/es5ExportDefaultClassDeclaration.types b/tests/baselines/reference/es5ExportDefaultClassDeclaration.types new file mode 100644 index 0000000000000..34fb87fcbb2bb --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/es5ExportDefaultClassDeclaration.ts === + +export default class C { +>C : C + + method() { } +>method : () => void +} + diff --git a/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js b/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js new file mode 100644 index 0000000000000..4d29fce3c10d9 --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js @@ -0,0 +1,22 @@ +//// [es5ExportDefaultClassDeclaration2.ts] + +export default class { + method() { } +} + + +//// [es5ExportDefaultClassDeclaration2.js] +var default_1 = (function () { + function default_1() { + } + default_1.prototype.method = function () { + }; + return default_1; +})(); +exports.default = default_1; + + +//// [es5ExportDefaultClassDeclaration2.d.ts] +export default class { + method(): void; +} diff --git a/tests/baselines/reference/es5ExportDefaultClassDeclaration2.types b/tests/baselines/reference/es5ExportDefaultClassDeclaration2.types new file mode 100644 index 0000000000000..e4c7a59e0e740 --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration2.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/es5ExportDefaultClassDeclaration2.ts === + +export default class { + method() { } +>method : () => void +} + diff --git a/tests/baselines/reference/es5ExportDefaultExpression.js b/tests/baselines/reference/es5ExportDefaultExpression.js new file mode 100644 index 0000000000000..1e14ae0bffd19 --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultExpression.js @@ -0,0 +1,11 @@ +//// [es5ExportDefaultExpression.ts] + +export default (1 + 2); + + +//// [es5ExportDefaultExpression.js] +exports.default = (1 + 2); + + +//// [es5ExportDefaultExpression.d.ts] +export default : number; diff --git a/tests/baselines/reference/es5ExportDefaultExpression.types b/tests/baselines/reference/es5ExportDefaultExpression.types new file mode 100644 index 0000000000000..2f4e2b5728499 --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultExpression.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/es5ExportDefaultExpression.ts === + +export default (1 + 2); +>(1 + 2) : number +>1 + 2 : number + diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js new file mode 100644 index 0000000000000..980a5ccab0f83 --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js @@ -0,0 +1,13 @@ +//// [es5ExportDefaultFunctionDeclaration.ts] + +export default function f() { } + + +//// [es5ExportDefaultFunctionDeclaration.js] +function f() { +} +exports.f = f; + + +//// [es5ExportDefaultFunctionDeclaration.d.ts] +export default function f(): void; diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.types b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.types new file mode 100644 index 0000000000000..446bd8e2a3144 --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/es5ExportDefaultFunctionDeclaration.ts === + +export default function f() { } +>f : () => void + diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js new file mode 100644 index 0000000000000..61f167619eb9c --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js @@ -0,0 +1,13 @@ +//// [es5ExportDefaultFunctionDeclaration2.ts] + +export default function () { } + + +//// [es5ExportDefaultFunctionDeclaration2.js] +function () { +} +exports.default = default_1; + + +//// [es5ExportDefaultFunctionDeclaration2.d.ts] +export default function (): void; diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.types b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.types new file mode 100644 index 0000000000000..1b9f9d2615114 --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/es5ExportDefaultFunctionDeclaration2.ts === + +No type information for this code.export default function () { } +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es5ExportDefaultIdentifier.js b/tests/baselines/reference/es5ExportDefaultIdentifier.js new file mode 100644 index 0000000000000..81f2e9e0ace20 --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultIdentifier.js @@ -0,0 +1,17 @@ +//// [es5ExportDefaultIdentifier.ts] + +export function f() { } + +export default f; + + +//// [es5ExportDefaultIdentifier.js] +function f() { +} +exports.f = f; +exports.default = f; + + +//// [es5ExportDefaultIdentifier.d.ts] +export declare function f(): void; +export default f; diff --git a/tests/baselines/reference/es5ExportDefaultIdentifier.types b/tests/baselines/reference/es5ExportDefaultIdentifier.types new file mode 100644 index 0000000000000..d57f757507031 --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultIdentifier.types @@ -0,0 +1,8 @@ +=== tests/cases/compiler/es5ExportDefaultIdentifier.ts === + +export function f() { } +>f : () => void + +export default f; +>f : () => void + diff --git a/tests/baselines/reference/es5ExportEquals.errors.txt b/tests/baselines/reference/es5ExportEquals.errors.txt new file mode 100644 index 0000000000000..89197aca632c0 --- /dev/null +++ b/tests/baselines/reference/es5ExportEquals.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/es5ExportEquals.ts(4,1): error TS2309: An export assignment cannot be used in a module with other exported elements. + + +==== tests/cases/compiler/es5ExportEquals.ts (1 errors) ==== + + export function f() { } + + export = f; + ~~~~~~~~~~~ +!!! error TS2309: An export assignment cannot be used in a module with other exported elements. + \ No newline at end of file diff --git a/tests/baselines/reference/es5ExportEquals.js b/tests/baselines/reference/es5ExportEquals.js new file mode 100644 index 0000000000000..04a34b1e23b0e --- /dev/null +++ b/tests/baselines/reference/es5ExportEquals.js @@ -0,0 +1,17 @@ +//// [es5ExportEquals.ts] + +export function f() { } + +export = f; + + +//// [es5ExportEquals.js] +function f() { +} +exports.f = f; +module.exports = f; + + +//// [es5ExportEquals.d.ts] +export declare function f(): void; +export = f; diff --git a/tests/baselines/reference/es5ModuleInternalNamedImports.errors.txt b/tests/baselines/reference/es5ModuleInternalNamedImports.errors.txt new file mode 100644 index 0000000000000..65f29984d593a --- /dev/null +++ b/tests/baselines/reference/es5ModuleInternalNamedImports.errors.txt @@ -0,0 +1,59 @@ +tests/cases/compiler/es5ModuleInternalNamedImports.ts(23,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es5ModuleInternalNamedImports.ts(24,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es5ModuleInternalNamedImports.ts(25,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es5ModuleInternalNamedImports.ts(26,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es5ModuleInternalNamedImports.ts(27,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es5ModuleInternalNamedImports.ts(28,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es5ModuleInternalNamedImports.ts(29,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es5ModuleInternalNamedImports.ts(30,5): error TS1194: Export declarations are not permitted in an internal module. + + +==== tests/cases/compiler/es5ModuleInternalNamedImports.ts (8 errors) ==== + + export module M { + // variable + export var M_V = 0; + // interface + export interface M_I { } + //calss + export class M_C { } + // instantiated module + export module M_M { var x; } + // uninstantiated module + export module M_MU { } + // function + export function M_F() { } + // enum + export enum M_E { } + // type + export type M_T = number; + // alias + export import M_A = M_M; + + // Reexports + export {M_V as v}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_I as i}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_C as c}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_M as m}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_MU as mu}; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_F as f}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_E as e}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_A as a}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + } + \ No newline at end of file diff --git a/tests/baselines/reference/es5ModuleInternalNamedImports.js b/tests/baselines/reference/es5ModuleInternalNamedImports.js new file mode 100644 index 0000000000000..456ad30523b79 --- /dev/null +++ b/tests/baselines/reference/es5ModuleInternalNamedImports.js @@ -0,0 +1,65 @@ +//// [es5ModuleInternalNamedImports.ts] + +export module M { + // variable + export var M_V = 0; + // interface + export interface M_I { } + //calss + export class M_C { } + // instantiated module + export module M_M { var x; } + // uninstantiated module + export module M_MU { } + // function + export function M_F() { } + // enum + export enum M_E { } + // type + export type M_T = number; + // alias + export import M_A = M_M; + + // Reexports + export {M_V as v}; + export {M_I as i}; + export {M_C as c}; + export {M_M as m}; + export {M_MU as mu}; + export {M_F as f}; + export {M_E as e}; + export {M_A as a}; +} + + +//// [es5ModuleInternalNamedImports.js] +define(["require", "exports"], function (require, exports) { + var M; + (function (M) { + // variable + M.M_V = 0; + //calss + var M_C = (function () { + function M_C() { + } + return M_C; + })(); + M.M_C = M_C; + // instantiated module + var M_M; + (function (M_M) { + var x; + })(M_M = M.M_M || (M.M_M = {})); + // function + function M_F() { + } + M.M_F = M_F; + // enum + (function (M_E) { + })(M.M_E || (M.M_E = {})); + var M_E = M.M_E; + // alias + M.M_A = M_M; + // Reexports + })(M = exports.M || (exports.M = {})); +}); diff --git a/tests/baselines/reference/es5ModuleWithModuleGenAmd.js b/tests/baselines/reference/es5ModuleWithModuleGenAmd.js new file mode 100644 index 0000000000000..f4757b539eb49 --- /dev/null +++ b/tests/baselines/reference/es5ModuleWithModuleGenAmd.js @@ -0,0 +1,25 @@ +//// [es5ModuleWithModuleGenAmd.ts] +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} + +//// [es5ModuleWithModuleGenAmd.js] +define(["require", "exports"], function (require, exports) { + var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; + })(); + exports.A = A; +}); diff --git a/tests/baselines/reference/es6-declaration-amd.types b/tests/baselines/reference/es5ModuleWithModuleGenAmd.types similarity index 55% rename from tests/baselines/reference/es6-declaration-amd.types rename to tests/baselines/reference/es5ModuleWithModuleGenAmd.types index e275fc5243961..e3453587a121b 100644 --- a/tests/baselines/reference/es6-declaration-amd.types +++ b/tests/baselines/reference/es5ModuleWithModuleGenAmd.types @@ -1,11 +1,9 @@ -=== tests/cases/compiler/es6-declaration-amd.ts === - -class A +=== tests/cases/compiler/es5ModuleWithModuleGenAmd.ts === +export class A >A : A { constructor () { - } public B() diff --git a/tests/baselines/reference/es5ModuleWithModuleGenCommonjs.js b/tests/baselines/reference/es5ModuleWithModuleGenCommonjs.js new file mode 100644 index 0000000000000..b4ca020f56677 --- /dev/null +++ b/tests/baselines/reference/es5ModuleWithModuleGenCommonjs.js @@ -0,0 +1,23 @@ +//// [es5ModuleWithModuleGenCommonjs.ts] +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} + +//// [es5ModuleWithModuleGenCommonjs.js] +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +exports.A = A; diff --git a/tests/baselines/reference/es6-sourcemap-amd.types b/tests/baselines/reference/es5ModuleWithModuleGenCommonjs.types similarity index 53% rename from tests/baselines/reference/es6-sourcemap-amd.types rename to tests/baselines/reference/es5ModuleWithModuleGenCommonjs.types index 661ab2e7cddfc..721df9afe58ef 100644 --- a/tests/baselines/reference/es6-sourcemap-amd.types +++ b/tests/baselines/reference/es5ModuleWithModuleGenCommonjs.types @@ -1,11 +1,9 @@ -=== tests/cases/compiler/es6-sourcemap-amd.ts === - -class A +=== tests/cases/compiler/es5ModuleWithModuleGenCommonjs.ts === +export class A >A : A { constructor () { - } public B() diff --git a/tests/baselines/reference/es5ModuleWithoutModuleGenTarget.errors.txt b/tests/baselines/reference/es5ModuleWithoutModuleGenTarget.errors.txt new file mode 100644 index 0000000000000..25e64fc72d0b7 --- /dev/null +++ b/tests/baselines/reference/es5ModuleWithoutModuleGenTarget.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/es5ModuleWithoutModuleGenTarget.ts(1,14): error TS1148: Cannot compile external modules unless the '--module' flag is provided. + + +==== tests/cases/compiler/es5ModuleWithoutModuleGenTarget.ts (1 errors) ==== + export class A + ~ +!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. + { + constructor () + { + } + + public B() + { + return 42; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/es5ModuleWithoutModuleGenTarget.js b/tests/baselines/reference/es5ModuleWithoutModuleGenTarget.js new file mode 100644 index 0000000000000..4f663875adee9 --- /dev/null +++ b/tests/baselines/reference/es5ModuleWithoutModuleGenTarget.js @@ -0,0 +1,23 @@ +//// [es5ModuleWithoutModuleGenTarget.ts] +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} + +//// [es5ModuleWithoutModuleGenTarget.js] +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +exports.A = A; diff --git a/tests/baselines/reference/es6-amd.errors.txt b/tests/baselines/reference/es6-amd.errors.txt new file mode 100644 index 0000000000000..cb1ef4b1287aa --- /dev/null +++ b/tests/baselines/reference/es6-amd.errors.txt @@ -0,0 +1,18 @@ +error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. + + +!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +==== tests/cases/compiler/es6-amd.ts (0 errors) ==== + + class A + { + constructor () + { + + } + + public B() + { + return 42; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/es6-amd.js b/tests/baselines/reference/es6-amd.js index 0cce3af04463a..74f3037303e35 100644 --- a/tests/baselines/reference/es6-amd.js +++ b/tests/baselines/reference/es6-amd.js @@ -14,14 +14,13 @@ class A } //// [es6-amd.js] -var A = (function () { - function A() { +class A { + constructor() { } - A.prototype.B = function () { + B() { return 42; - }; - return A; -})(); + } +} //# sourceMappingURL=es6-amd.js.map //// [es6-amd.d.ts] diff --git a/tests/baselines/reference/es6-amd.js.map b/tests/baselines/reference/es6-amd.js.map index c9866d87884cb..fe234f8424b52 100644 --- a/tests/baselines/reference/es6-amd.js.map +++ b/tests/baselines/reference/es6-amd.js.map @@ -1,2 +1,2 @@ //// [es6-amd.js.map] -{"version":3,"file":"es6-amd.js","sourceRoot":"","sources":["es6-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file +{"version":3,"file":"es6-amd.js","sourceRoot":"","sources":["es6-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,CAACA;QAEJE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;AACLF,CAACA;AAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-amd.sourcemap.txt b/tests/baselines/reference/es6-amd.sourcemap.txt index 2b27109940124..1ab547073c61d 100644 --- a/tests/baselines/reference/es6-amd.sourcemap.txt +++ b/tests/baselines/reference/es6-amd.sourcemap.txt @@ -8,14 +8,14 @@ sources: es6-amd.ts emittedFile:tests/cases/compiler/es6-amd.js sourceFile:es6-amd.ts ------------------------------------------------------------------- ->>>var A = (function () { +>>>class A { 1 > -2 >^^^^^^^^^^^^^^^^^^^-> +2 >^^^^^^^^^^^^^^^^^^^^-> 1 > > 1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) --- ->>> function A() { +>>> constructor() { 1->^^^^ 2 > ^^-> 1->class A @@ -26,7 +26,7 @@ sourceFile:es6-amd.ts >>> } 1->^^^^ 2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^-> 1->constructor () > { > @@ -35,81 +35,57 @@ sourceFile:es6-amd.ts 1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) 2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) --- ->>> A.prototype.B = function () { +>>> B() { 1->^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^-> 1-> > > public 2 > B -3 > 1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) -3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) +2 >Emitted(4, 6) Source(9, 13) + SourceIndex(0) name (A) --- >>> return 42; -1 >^^^^^^^^ +1->^^^^^^^^ 2 > ^^^^^^ 3 > ^ 4 > ^^ 5 > ^ -1 >public B() +1->() > { > 2 > return 3 > 4 > 42 5 > ; -1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) +1->Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) 2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) 3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) 4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) 5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) --- ->>> }; +>>> } 1 >^^^^ 2 > ^ -3 > ^^^^^^^^^-> 1 > > 2 > } 1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) 2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) --- ->>> return A; -1->^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) ---- ->>>})(); +>>>} 1 > 2 >^ -3 > -4 > ^^^^ -5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > 2 >} -3 > -4 > class A - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) -3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) -4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) +1 >Emitted(7, 1) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(7, 2) Source(13, 2) + SourceIndex(0) name (A) --- ->>>//# sourceMappingURL=es6-amd.js.map \ No newline at end of file +>>>//# sourceMappingURL=es6-amd.js.map1-> +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1-> +1->Emitted(8, 1) Source(13, 2) + SourceIndex(0) +--- \ No newline at end of file diff --git a/tests/baselines/reference/es6-declaration-amd.errors.txt b/tests/baselines/reference/es6-declaration-amd.errors.txt new file mode 100644 index 0000000000000..18319504dc9fd --- /dev/null +++ b/tests/baselines/reference/es6-declaration-amd.errors.txt @@ -0,0 +1,18 @@ +error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. + + +!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +==== tests/cases/compiler/es6-declaration-amd.ts (0 errors) ==== + + class A + { + constructor () + { + + } + + public B() + { + return 42; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/es6-declaration-amd.js b/tests/baselines/reference/es6-declaration-amd.js index 471f96b223d1a..aeba23e0b6ede 100644 --- a/tests/baselines/reference/es6-declaration-amd.js +++ b/tests/baselines/reference/es6-declaration-amd.js @@ -14,14 +14,13 @@ class A } //// [es6-declaration-amd.js] -var A = (function () { - function A() { +class A { + constructor() { } - A.prototype.B = function () { + B() { return 42; - }; - return A; -})(); + } +} //# sourceMappingURL=es6-declaration-amd.js.map //// [es6-declaration-amd.d.ts] diff --git a/tests/baselines/reference/es6-declaration-amd.js.map b/tests/baselines/reference/es6-declaration-amd.js.map index 03f79f6c66778..ca1899e03f559 100644 --- a/tests/baselines/reference/es6-declaration-amd.js.map +++ b/tests/baselines/reference/es6-declaration-amd.js.map @@ -1,2 +1,2 @@ //// [es6-declaration-amd.js.map] -{"version":3,"file":"es6-declaration-amd.js","sourceRoot":"","sources":["es6-declaration-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file +{"version":3,"file":"es6-declaration-amd.js","sourceRoot":"","sources":["es6-declaration-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,CAACA;QAEJE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;AACLF,CAACA;AAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-declaration-amd.sourcemap.txt b/tests/baselines/reference/es6-declaration-amd.sourcemap.txt index 198a68633b1df..9061bc1ed7c48 100644 --- a/tests/baselines/reference/es6-declaration-amd.sourcemap.txt +++ b/tests/baselines/reference/es6-declaration-amd.sourcemap.txt @@ -8,14 +8,14 @@ sources: es6-declaration-amd.ts emittedFile:tests/cases/compiler/es6-declaration-amd.js sourceFile:es6-declaration-amd.ts ------------------------------------------------------------------- ->>>var A = (function () { +>>>class A { 1 > -2 >^^^^^^^^^^^^^^^^^^^-> +2 >^^^^^^^^^^^^^^^^^^^^-> 1 > > 1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) --- ->>> function A() { +>>> constructor() { 1->^^^^ 2 > ^^-> 1->class A @@ -26,7 +26,7 @@ sourceFile:es6-declaration-amd.ts >>> } 1->^^^^ 2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^-> 1->constructor () > { > @@ -35,81 +35,57 @@ sourceFile:es6-declaration-amd.ts 1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) 2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) --- ->>> A.prototype.B = function () { +>>> B() { 1->^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^-> 1-> > > public 2 > B -3 > 1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) -3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) +2 >Emitted(4, 6) Source(9, 13) + SourceIndex(0) name (A) --- >>> return 42; -1 >^^^^^^^^ +1->^^^^^^^^ 2 > ^^^^^^ 3 > ^ 4 > ^^ 5 > ^ -1 >public B() +1->() > { > 2 > return 3 > 4 > 42 5 > ; -1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) +1->Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) 2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) 3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) 4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) 5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) --- ->>> }; +>>> } 1 >^^^^ 2 > ^ -3 > ^^^^^^^^^-> 1 > > 2 > } 1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) 2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) --- ->>> return A; -1->^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) ---- ->>>})(); +>>>} 1 > 2 >^ -3 > -4 > ^^^^ -5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > 2 >} -3 > -4 > class A - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) -3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) -4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) +1 >Emitted(7, 1) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(7, 2) Source(13, 2) + SourceIndex(0) name (A) --- ->>>//# sourceMappingURL=es6-declaration-amd.js.map \ No newline at end of file +>>>//# sourceMappingURL=es6-declaration-amd.js.map1-> +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1-> +1->Emitted(8, 1) Source(13, 2) + SourceIndex(0) +--- \ No newline at end of file diff --git a/tests/baselines/reference/es6-sourcemap-amd.errors.txt b/tests/baselines/reference/es6-sourcemap-amd.errors.txt new file mode 100644 index 0000000000000..24a83f8ee12bf --- /dev/null +++ b/tests/baselines/reference/es6-sourcemap-amd.errors.txt @@ -0,0 +1,18 @@ +error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. + + +!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +==== tests/cases/compiler/es6-sourcemap-amd.ts (0 errors) ==== + + class A + { + constructor () + { + + } + + public B() + { + return 42; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/es6-sourcemap-amd.js b/tests/baselines/reference/es6-sourcemap-amd.js index 805e56cf830d0..106726c0f2cfb 100644 --- a/tests/baselines/reference/es6-sourcemap-amd.js +++ b/tests/baselines/reference/es6-sourcemap-amd.js @@ -14,12 +14,11 @@ class A } //// [es6-sourcemap-amd.js] -var A = (function () { - function A() { +class A { + constructor() { } - A.prototype.B = function () { + B() { return 42; - }; - return A; -})(); + } +} //# sourceMappingURL=es6-sourcemap-amd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es6-sourcemap-amd.js.map b/tests/baselines/reference/es6-sourcemap-amd.js.map index ef22eb4638c8b..779c13b129698 100644 --- a/tests/baselines/reference/es6-sourcemap-amd.js.map +++ b/tests/baselines/reference/es6-sourcemap-amd.js.map @@ -1,2 +1,2 @@ //// [es6-sourcemap-amd.js.map] -{"version":3,"file":"es6-sourcemap-amd.js","sourceRoot":"","sources":["es6-sourcemap-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file +{"version":3,"file":"es6-sourcemap-amd.js","sourceRoot":"","sources":["es6-sourcemap-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,CAACA;QAEJE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;AACLF,CAACA;AAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-sourcemap-amd.sourcemap.txt b/tests/baselines/reference/es6-sourcemap-amd.sourcemap.txt index bcfc33d04055c..179dd79ba1700 100644 --- a/tests/baselines/reference/es6-sourcemap-amd.sourcemap.txt +++ b/tests/baselines/reference/es6-sourcemap-amd.sourcemap.txt @@ -8,14 +8,14 @@ sources: es6-sourcemap-amd.ts emittedFile:tests/cases/compiler/es6-sourcemap-amd.js sourceFile:es6-sourcemap-amd.ts ------------------------------------------------------------------- ->>>var A = (function () { +>>>class A { 1 > -2 >^^^^^^^^^^^^^^^^^^^-> +2 >^^^^^^^^^^^^^^^^^^^^-> 1 > > 1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) --- ->>> function A() { +>>> constructor() { 1->^^^^ 2 > ^^-> 1->class A @@ -26,7 +26,7 @@ sourceFile:es6-sourcemap-amd.ts >>> } 1->^^^^ 2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^-> 1->constructor () > { > @@ -35,81 +35,57 @@ sourceFile:es6-sourcemap-amd.ts 1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) 2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) --- ->>> A.prototype.B = function () { +>>> B() { 1->^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^-> 1-> > > public 2 > B -3 > 1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) -3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) +2 >Emitted(4, 6) Source(9, 13) + SourceIndex(0) name (A) --- >>> return 42; -1 >^^^^^^^^ +1->^^^^^^^^ 2 > ^^^^^^ 3 > ^ 4 > ^^ 5 > ^ -1 >public B() +1->() > { > 2 > return 3 > 4 > 42 5 > ; -1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) +1->Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) 2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) 3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) 4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) 5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) --- ->>> }; +>>> } 1 >^^^^ 2 > ^ -3 > ^^^^^^^^^-> 1 > > 2 > } 1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) 2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) --- ->>> return A; -1->^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) ---- ->>>})(); +>>>} 1 > 2 >^ -3 > -4 > ^^^^ -5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > 2 >} -3 > -4 > class A - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) -3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) -4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) +1 >Emitted(7, 1) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(7, 2) Source(13, 2) + SourceIndex(0) name (A) --- ->>>//# sourceMappingURL=es6-sourcemap-amd.js.map \ No newline at end of file +>>>//# sourceMappingURL=es6-sourcemap-amd.js.map1-> +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1-> +1->Emitted(8, 1) Source(13, 2) + SourceIndex(0) +--- \ No newline at end of file diff --git a/tests/baselines/reference/es6ExportAll.js b/tests/baselines/reference/es6ExportAll.js new file mode 100644 index 0000000000000..afa07c39d8ff9 --- /dev/null +++ b/tests/baselines/reference/es6ExportAll.js @@ -0,0 +1,43 @@ +//// [tests/cases/compiler/es6ExportAll.ts] //// + +//// [server.ts] + +export class c { +} +export interface i { +} +export module m { + export var x = 10; +} +export var x = 10; +export module uninstantiated { +} + +//// [client.ts] +export * from "server"; + +//// [server.js] +export class c { +} +export var m; +(function (m) { + m.x = 10; +})(m || (m = {})); +export var x = 10; +//// [client.js] +export * from "server"; + + +//// [server.d.ts] +export declare class c { +} +export interface i { +} +export declare module m { + var x: number; +} +export declare var x: number; +export declare module uninstantiated { +} +//// [client.d.ts] +export * from "server"; diff --git a/tests/baselines/reference/es6ExportAll.types b/tests/baselines/reference/es6ExportAll.types new file mode 100644 index 0000000000000..99e8fde9d4047 --- /dev/null +++ b/tests/baselines/reference/es6ExportAll.types @@ -0,0 +1,24 @@ +=== tests/cases/compiler/server.ts === + +export class c { +>c : c +} +export interface i { +>i : i +} +export module m { +>m : typeof m + + export var x = 10; +>x : number +} +export var x = 10; +>x : number + +export module uninstantiated { +>uninstantiated : unknown +} + +=== tests/cases/compiler/client.ts === +export * from "server"; +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ExportAllInEs5.js b/tests/baselines/reference/es6ExportAllInEs5.js new file mode 100644 index 0000000000000..1be3fa1f1b2e2 --- /dev/null +++ b/tests/baselines/reference/es6ExportAllInEs5.js @@ -0,0 +1,50 @@ +//// [tests/cases/compiler/es6ExportAllInEs5.ts] //// + +//// [server.ts] + +export class c { +} +export interface i { +} +export module m { + export var x = 10; +} +export var x = 10; +export module uninstantiated { +} + +//// [client.ts] +export * from "server"; + +//// [server.js] +var c = (function () { + function c() { + } + return c; +})(); +exports.c = c; +var m; +(function (m) { + m.x = 10; +})(m = exports.m || (exports.m = {})); +exports.x = 10; +//// [client.js] +function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; +} +__export(require("server")); + + +//// [server.d.ts] +export declare class c { +} +export interface i { +} +export declare module m { + var x: number; +} +export declare var x: number; +export declare module uninstantiated { +} +//// [client.d.ts] +export * from "server"; diff --git a/tests/baselines/reference/es6ExportAllInEs5.types b/tests/baselines/reference/es6ExportAllInEs5.types new file mode 100644 index 0000000000000..99e8fde9d4047 --- /dev/null +++ b/tests/baselines/reference/es6ExportAllInEs5.types @@ -0,0 +1,24 @@ +=== tests/cases/compiler/server.ts === + +export class c { +>c : c +} +export interface i { +>i : i +} +export module m { +>m : typeof m + + export var x = 10; +>x : number +} +export var x = 10; +>x : number + +export module uninstantiated { +>uninstantiated : unknown +} + +=== tests/cases/compiler/client.ts === +export * from "server"; +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ExportAssignment.errors.txt b/tests/baselines/reference/es6ExportAssignment.errors.txt new file mode 100644 index 0000000000000..1db7d04e05e9f --- /dev/null +++ b/tests/baselines/reference/es6ExportAssignment.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/es6ExportAssignment.ts(3,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. + + +==== tests/cases/compiler/es6ExportAssignment.ts (1 errors) ==== + + var a = 10; + export = a; + ~~~~~~~~~~~ +!!! error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. \ No newline at end of file diff --git a/tests/baselines/reference/es6ExportAssignment.js b/tests/baselines/reference/es6ExportAssignment.js new file mode 100644 index 0000000000000..4a4e0368bb7e8 --- /dev/null +++ b/tests/baselines/reference/es6ExportAssignment.js @@ -0,0 +1,7 @@ +//// [es6ExportAssignment.ts] + +var a = 10; +export = a; + +//// [es6ExportAssignment.js] +var a = 10; diff --git a/tests/baselines/reference/es6ExportClause.js b/tests/baselines/reference/es6ExportClause.js new file mode 100644 index 0000000000000..f0d9bbe8cfffe --- /dev/null +++ b/tests/baselines/reference/es6ExportClause.js @@ -0,0 +1,48 @@ +//// [es6ExportClause.ts] + +class c { +} +interface i { +} +module m { + export var x = 10; +} +var x = 10; +module uninstantiated { +} +export { c }; +export { c as c2 }; +export { i, m as instantiatedModule }; +export { uninstantiated }; +export { x }; + +//// [es6ExportClause.js] +class c { +} +var m; +(function (m) { + m.x = 10; +})(m || (m = {})); +var x = 10; +export { c }; +export { c as c2 }; +export { m as instantiatedModule }; +export { x }; + + +//// [es6ExportClause.d.ts] +declare class c { +} +interface i { +} +declare module m { + var x: number; +} +declare var x: number; +declare module uninstantiated { +} +export { c }; +export { c as c2 }; +export { i, m as instantiatedModule }; +export { uninstantiated }; +export { x }; diff --git a/tests/baselines/reference/es6ExportClause.types b/tests/baselines/reference/es6ExportClause.types new file mode 100644 index 0000000000000..24b9859e0e84c --- /dev/null +++ b/tests/baselines/reference/es6ExportClause.types @@ -0,0 +1,38 @@ +=== tests/cases/compiler/es6ExportClause.ts === + +class c { +>c : c +} +interface i { +>i : i +} +module m { +>m : typeof m + + export var x = 10; +>x : number +} +var x = 10; +>x : number + +module uninstantiated { +>uninstantiated : unknown +} +export { c }; +>c : typeof c + +export { c as c2 }; +>c : typeof c +>c2 : typeof c + +export { i, m as instantiatedModule }; +>i : unknown +>m : typeof m +>instantiatedModule : typeof m + +export { uninstantiated }; +>uninstantiated : unknown + +export { x }; +>x : number + diff --git a/tests/baselines/reference/es6ExportClauseInEs5.js b/tests/baselines/reference/es6ExportClauseInEs5.js new file mode 100644 index 0000000000000..f987b48aecadd --- /dev/null +++ b/tests/baselines/reference/es6ExportClauseInEs5.js @@ -0,0 +1,51 @@ +//// [es6ExportClauseInEs5.ts] + +class c { +} +interface i { +} +module m { + export var x = 10; +} +var x = 10; +module uninstantiated { +} +export { c }; +export { c as c2 }; +export { i, m as instantiatedModule }; +export { uninstantiated }; +export { x }; + +//// [es6ExportClauseInEs5.js] +var c = (function () { + function c() { + } + return c; +})(); +exports.c = c; +exports.c2 = c; +var m; +(function (m) { + m.x = 10; +})(m || (m = {})); +exports.instantiatedModule = m; +var x = 10; +exports.x = x; + + +//// [es6ExportClauseInEs5.d.ts] +declare class c { +} +interface i { +} +declare module m { + var x: number; +} +declare var x: number; +declare module uninstantiated { +} +export { c }; +export { c as c2 }; +export { i, m as instantiatedModule }; +export { uninstantiated }; +export { x }; diff --git a/tests/baselines/reference/es6ExportClauseInEs5.types b/tests/baselines/reference/es6ExportClauseInEs5.types new file mode 100644 index 0000000000000..8caedfa5ceb9e --- /dev/null +++ b/tests/baselines/reference/es6ExportClauseInEs5.types @@ -0,0 +1,38 @@ +=== tests/cases/compiler/es6ExportClauseInEs5.ts === + +class c { +>c : c +} +interface i { +>i : i +} +module m { +>m : typeof m + + export var x = 10; +>x : number +} +var x = 10; +>x : number + +module uninstantiated { +>uninstantiated : unknown +} +export { c }; +>c : typeof c + +export { c as c2 }; +>c : typeof c +>c2 : typeof c + +export { i, m as instantiatedModule }; +>i : unknown +>m : typeof m +>instantiatedModule : typeof m + +export { uninstantiated }; +>uninstantiated : unknown + +export { x }; +>x : number + diff --git a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js new file mode 100644 index 0000000000000..ccdd32d99c0ad --- /dev/null +++ b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js @@ -0,0 +1,54 @@ +//// [tests/cases/compiler/es6ExportClauseWithoutModuleSpecifier.ts] //// + +//// [server.ts] + +export class c { +} +export interface i { +} +export module m { + export var x = 10; +} +export var x = 10; +export module uninstantiated { +} + +//// [client.ts] +export { c } from "server"; +export { c as c2 } from "server"; +export { i, m as instantiatedModule } from "server"; +export { uninstantiated } from "server"; +export { x } from "server"; + +//// [server.js] +export class c { +} +export var m; +(function (m) { + m.x = 10; +})(m || (m = {})); +export var x = 10; +//// [client.js] +export { c } from "server"; +export { c as c2 } from "server"; +export { m as instantiatedModule } from "server"; +export { x } from "server"; + + +//// [server.d.ts] +export declare class c { +} +export interface i { +} +export declare module m { + var x: number; +} +export declare var x: number; +export declare module uninstantiated { +} +//// [client.d.ts] +export { c } from "server"; +export { c as c2 } from "server"; +export { i, m as instantiatedModule } from "server"; +export { uninstantiated } from "server"; +export { x } from "server"; diff --git a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.types b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.types new file mode 100644 index 0000000000000..c0087dccd943a --- /dev/null +++ b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.types @@ -0,0 +1,40 @@ +=== tests/cases/compiler/server.ts === + +export class c { +>c : c +} +export interface i { +>i : i +} +export module m { +>m : typeof m + + export var x = 10; +>x : number +} +export var x = 10; +>x : number + +export module uninstantiated { +>uninstantiated : unknown +} + +=== tests/cases/compiler/client.ts === +export { c } from "server"; +>c : typeof c + +export { c as c2 } from "server"; +>c : typeof c +>c2 : typeof c + +export { i, m as instantiatedModule } from "server"; +>i : unknown +>m : typeof instantiatedModule +>instantiatedModule : typeof instantiatedModule + +export { uninstantiated } from "server"; +>uninstantiated : unknown + +export { x } from "server"; +>x : number + diff --git a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.js b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.js new file mode 100644 index 0000000000000..6250e0ce3264b --- /dev/null +++ b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.js @@ -0,0 +1,62 @@ +//// [tests/cases/compiler/es6ExportClauseWithoutModuleSpecifierInEs5.ts] //// + +//// [server.ts] + +export class c { +} +export interface i { +} +export module m { + export var x = 10; +} +export var x = 10; +export module uninstantiated { +} + +//// [client.ts] +export { c } from "server"; +export { c as c2 } from "server"; +export { i, m as instantiatedModule } from "server"; +export { uninstantiated } from "server"; +export { x } from "server"; + +//// [server.js] +var c = (function () { + function c() { + } + return c; +})(); +exports.c = c; +var m; +(function (m) { + m.x = 10; +})(m = exports.m || (exports.m = {})); +exports.x = 10; +//// [client.js] +var server_1 = require("server"); +exports.c = server_1.c; +var server_2 = require("server"); +exports.c2 = server_2.c; +var server_3 = require("server"); +exports.instantiatedModule = server_3.m; +var server_4 = require("server"); +exports.x = server_4.x; + + +//// [server.d.ts] +export declare class c { +} +export interface i { +} +export declare module m { + var x: number; +} +export declare var x: number; +export declare module uninstantiated { +} +//// [client.d.ts] +export { c } from "server"; +export { c as c2 } from "server"; +export { i, m as instantiatedModule } from "server"; +export { uninstantiated } from "server"; +export { x } from "server"; diff --git a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.types b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.types new file mode 100644 index 0000000000000..c0087dccd943a --- /dev/null +++ b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.types @@ -0,0 +1,40 @@ +=== tests/cases/compiler/server.ts === + +export class c { +>c : c +} +export interface i { +>i : i +} +export module m { +>m : typeof m + + export var x = 10; +>x : number +} +export var x = 10; +>x : number + +export module uninstantiated { +>uninstantiated : unknown +} + +=== tests/cases/compiler/client.ts === +export { c } from "server"; +>c : typeof c + +export { c as c2 } from "server"; +>c : typeof c +>c2 : typeof c + +export { i, m as instantiatedModule } from "server"; +>i : unknown +>m : typeof instantiatedModule +>instantiatedModule : typeof instantiatedModule + +export { uninstantiated } from "server"; +>uninstantiated : unknown + +export { x } from "server"; +>x : number + diff --git a/tests/baselines/reference/es6ExportDefaultClassDeclaration.js b/tests/baselines/reference/es6ExportDefaultClassDeclaration.js new file mode 100644 index 0000000000000..2a25b5ac34974 --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultClassDeclaration.js @@ -0,0 +1,18 @@ +//// [es6ExportDefaultClassDeclaration.ts] + +export default class C { + method() { } +} + + +//// [es6ExportDefaultClassDeclaration.js] +export default class C { + method() { + } +} + + +//// [es6ExportDefaultClassDeclaration.d.ts] +export default class C { + method(): void; +} diff --git a/tests/baselines/reference/es6ExportDefaultClassDeclaration.types b/tests/baselines/reference/es6ExportDefaultClassDeclaration.types new file mode 100644 index 0000000000000..59e74fc1257c5 --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultClassDeclaration.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/es6ExportDefaultClassDeclaration.ts === + +export default class C { +>C : C + + method() { } +>method : () => void +} + diff --git a/tests/baselines/reference/es6ExportDefaultClassDeclaration2.js b/tests/baselines/reference/es6ExportDefaultClassDeclaration2.js new file mode 100644 index 0000000000000..ac5d92b6c129d --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultClassDeclaration2.js @@ -0,0 +1,18 @@ +//// [es6ExportDefaultClassDeclaration2.ts] + +export default class { + method() { } +} + + +//// [es6ExportDefaultClassDeclaration2.js] +export default class { + method() { + } +} + + +//// [es6ExportDefaultClassDeclaration2.d.ts] +export default class { + method(): void; +} diff --git a/tests/baselines/reference/es6ExportDefaultClassDeclaration2.types b/tests/baselines/reference/es6ExportDefaultClassDeclaration2.types new file mode 100644 index 0000000000000..513cacf05e4d0 --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultClassDeclaration2.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/es6ExportDefaultClassDeclaration2.ts === + +export default class { + method() { } +>method : () => void +} + diff --git a/tests/baselines/reference/es6ExportDefaultExpression.js b/tests/baselines/reference/es6ExportDefaultExpression.js new file mode 100644 index 0000000000000..322e09bc46fe3 --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultExpression.js @@ -0,0 +1,11 @@ +//// [es6ExportDefaultExpression.ts] + +export default (1 + 2); + + +//// [es6ExportDefaultExpression.js] +export default (1 + 2); + + +//// [es6ExportDefaultExpression.d.ts] +export default : number; diff --git a/tests/baselines/reference/es6ExportDefaultExpression.types b/tests/baselines/reference/es6ExportDefaultExpression.types new file mode 100644 index 0000000000000..3b056b8d9f920 --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultExpression.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/es6ExportDefaultExpression.ts === + +export default (1 + 2); +>(1 + 2) : number +>1 + 2 : number + diff --git a/tests/baselines/reference/es6ExportDefaultFunctionDeclaration.js b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration.js new file mode 100644 index 0000000000000..ec5789203d0ae --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration.js @@ -0,0 +1,12 @@ +//// [es6ExportDefaultFunctionDeclaration.ts] + +export default function f() { } + + +//// [es6ExportDefaultFunctionDeclaration.js] +export default function f() { +} + + +//// [es6ExportDefaultFunctionDeclaration.d.ts] +export default function f(): void; diff --git a/tests/baselines/reference/es6ExportDefaultFunctionDeclaration.types b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration.types new file mode 100644 index 0000000000000..6179bde9613aa --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/es6ExportDefaultFunctionDeclaration.ts === + +export default function f() { } +>f : () => void + diff --git a/tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.js b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.js new file mode 100644 index 0000000000000..80e37f18d21b6 --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.js @@ -0,0 +1,12 @@ +//// [es6ExportDefaultFunctionDeclaration2.ts] + +export default function () { } + + +//// [es6ExportDefaultFunctionDeclaration2.js] +export default function () { +} + + +//// [es6ExportDefaultFunctionDeclaration2.d.ts] +export default function (): void; diff --git a/tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.types b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.types new file mode 100644 index 0000000000000..3cb2fc9b1cd0c --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/es6ExportDefaultFunctionDeclaration2.ts === + +No type information for this code.export default function () { } +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ExportDefaultIdentifier.js b/tests/baselines/reference/es6ExportDefaultIdentifier.js new file mode 100644 index 0000000000000..5785220dfeefb --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultIdentifier.js @@ -0,0 +1,16 @@ +//// [es6ExportDefaultIdentifier.ts] + +export function f() { } + +export default f; + + +//// [es6ExportDefaultIdentifier.js] +export function f() { +} +export default f; + + +//// [es6ExportDefaultIdentifier.d.ts] +export declare function f(): void; +export default f; diff --git a/tests/baselines/reference/es6ExportDefaultIdentifier.types b/tests/baselines/reference/es6ExportDefaultIdentifier.types new file mode 100644 index 0000000000000..81dc168efd0cf --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultIdentifier.types @@ -0,0 +1,8 @@ +=== tests/cases/compiler/es6ExportDefaultIdentifier.ts === + +export function f() { } +>f : () => void + +export default f; +>f : () => void + diff --git a/tests/baselines/reference/es6ExportEquals.errors.txt b/tests/baselines/reference/es6ExportEquals.errors.txt new file mode 100644 index 0000000000000..174c72341f6c9 --- /dev/null +++ b/tests/baselines/reference/es6ExportEquals.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/es6ExportEquals.ts(4,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. +tests/cases/compiler/es6ExportEquals.ts(4,1): error TS2309: An export assignment cannot be used in a module with other exported elements. + + +==== tests/cases/compiler/es6ExportEquals.ts (2 errors) ==== + + export function f() { } + + export = f; + ~~~~~~~~~~~ +!!! error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. + ~~~~~~~~~~~ +!!! error TS2309: An export assignment cannot be used in a module with other exported elements. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ExportEquals.js b/tests/baselines/reference/es6ExportEquals.js new file mode 100644 index 0000000000000..68c5788c89b04 --- /dev/null +++ b/tests/baselines/reference/es6ExportEquals.js @@ -0,0 +1,15 @@ +//// [es6ExportEquals.ts] + +export function f() { } + +export = f; + + +//// [es6ExportEquals.js] +export function f() { +} + + +//// [es6ExportEquals.d.ts] +export declare function f(): void; +export = f; diff --git a/tests/baselines/reference/es6ExportEqualsInterop.errors.txt b/tests/baselines/reference/es6ExportEqualsInterop.errors.txt index 6351a3ee89b9c..7cc8418714580 100644 --- a/tests/baselines/reference/es6ExportEqualsInterop.errors.txt +++ b/tests/baselines/reference/es6ExportEqualsInterop.errors.txt @@ -11,25 +11,25 @@ tests/cases/compiler/main.ts(33,8): error TS1192: External module '"function"' h tests/cases/compiler/main.ts(34,8): error TS1192: External module '"function-module"' has no default export. tests/cases/compiler/main.ts(35,8): error TS1192: External module '"class"' has no default export. tests/cases/compiler/main.ts(36,8): error TS1192: External module '"class-module"' has no default export. -tests/cases/compiler/main.ts(39,21): error TS2496: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. -tests/cases/compiler/main.ts(45,21): error TS2496: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. -tests/cases/compiler/main.ts(47,21): error TS2496: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. -tests/cases/compiler/main.ts(62,25): error TS2496: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. -tests/cases/compiler/main.ts(68,25): error TS2496: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. -tests/cases/compiler/main.ts(70,25): error TS2496: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. -tests/cases/compiler/main.ts(85,25): error TS2496: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. -tests/cases/compiler/main.ts(91,25): error TS2496: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. -tests/cases/compiler/main.ts(93,25): error TS2496: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. -tests/cases/compiler/main.ts(97,15): error TS2497: External module '"interface"' uses 'export =' and cannot be used with 'export *'. -tests/cases/compiler/main.ts(98,15): error TS2497: External module '"variable"' uses 'export =' and cannot be used with 'export *'. -tests/cases/compiler/main.ts(99,15): error TS2497: External module '"interface-variable"' uses 'export =' and cannot be used with 'export *'. -tests/cases/compiler/main.ts(100,15): error TS2497: External module '"module"' uses 'export =' and cannot be used with 'export *'. -tests/cases/compiler/main.ts(101,15): error TS2497: External module '"interface-module"' uses 'export =' and cannot be used with 'export *'. -tests/cases/compiler/main.ts(102,15): error TS2497: External module '"variable-module"' uses 'export =' and cannot be used with 'export *'. -tests/cases/compiler/main.ts(103,15): error TS2497: External module '"function"' uses 'export =' and cannot be used with 'export *'. -tests/cases/compiler/main.ts(104,15): error TS2497: External module '"function-module"' uses 'export =' and cannot be used with 'export *'. -tests/cases/compiler/main.ts(105,15): error TS2497: External module '"class"' uses 'export =' and cannot be used with 'export *'. -tests/cases/compiler/main.ts(106,15): error TS2497: External module '"class-module"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(39,21): error TS2497: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(45,21): error TS2497: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(47,21): error TS2497: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(62,25): error TS2497: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(68,25): error TS2497: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(70,25): error TS2497: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(85,25): error TS2497: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(91,25): error TS2497: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(93,25): error TS2497: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(97,15): error TS2498: External module '"interface"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(98,15): error TS2498: External module '"variable"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(99,15): error TS2498: External module '"interface-variable"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(100,15): error TS2498: External module '"module"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(101,15): error TS2498: External module '"interface-module"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(102,15): error TS2498: External module '"variable-module"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(103,15): error TS2498: External module '"function"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(104,15): error TS2498: External module '"function-module"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(105,15): error TS2498: External module '"class"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(106,15): error TS2498: External module '"class-module"' uses 'export =' and cannot be used with 'export *'. ==== tests/cases/compiler/main.ts (32 errors) ==== @@ -99,7 +99,7 @@ tests/cases/compiler/main.ts(106,15): error TS2497: External module '"class-modu // namespace import import * as y1 from "interface"; ~~~~~~~~~~~ -!!! error TS2496: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. +!!! error TS2497: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. import * as y2 from "variable"; import * as y3 from "interface-variable"; import * as y4 from "module"; @@ -107,11 +107,11 @@ tests/cases/compiler/main.ts(106,15): error TS2497: External module '"class-modu import * as y6 from "variable-module"; import * as y7 from "function"; ~~~~~~~~~~ -!!! error TS2496: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. +!!! error TS2497: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. import * as y8 from "function-module"; import * as y9 from "class"; ~~~~~~~ -!!! error TS2496: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. +!!! error TS2497: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. import * as y0 from "class-module"; y1.a; @@ -128,7 +128,7 @@ tests/cases/compiler/main.ts(106,15): error TS2497: External module '"class-modu // named import import { a as a1 } from "interface"; ~~~~~~~~~~~ -!!! error TS2496: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. +!!! error TS2497: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. import { a as a2 } from "variable"; import { a as a3 } from "interface-variable"; import { a as a4 } from "module"; @@ -136,11 +136,11 @@ tests/cases/compiler/main.ts(106,15): error TS2497: External module '"class-modu import { a as a6 } from "variable-module"; import { a as a7 } from "function"; ~~~~~~~~~~ -!!! error TS2496: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. +!!! error TS2497: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. import { a as a8 } from "function-module"; import { a as a9 } from "class"; ~~~~~~~ -!!! error TS2496: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. +!!! error TS2497: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. import { a as a0 } from "class-module"; a1; @@ -157,7 +157,7 @@ tests/cases/compiler/main.ts(106,15): error TS2497: External module '"class-modu // named export export { a as a1 } from "interface"; ~~~~~~~~~~~ -!!! error TS2496: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. +!!! error TS2497: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. export { a as a2 } from "variable"; export { a as a3 } from "interface-variable"; export { a as a4 } from "module"; @@ -165,44 +165,44 @@ tests/cases/compiler/main.ts(106,15): error TS2497: External module '"class-modu export { a as a6 } from "variable-module"; export { a as a7 } from "function"; ~~~~~~~~~~ -!!! error TS2496: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. +!!! error TS2497: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. export { a as a8 } from "function-module"; export { a as a9 } from "class"; ~~~~~~~ -!!! error TS2496: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. +!!! error TS2497: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. export { a as a0 } from "class-module"; // export-star export * from "interface"; ~~~~~~~~~~~ -!!! error TS2497: External module '"interface"' uses 'export =' and cannot be used with 'export *'. +!!! error TS2498: External module '"interface"' uses 'export =' and cannot be used with 'export *'. export * from "variable"; ~~~~~~~~~~ -!!! error TS2497: External module '"variable"' uses 'export =' and cannot be used with 'export *'. +!!! error TS2498: External module '"variable"' uses 'export =' and cannot be used with 'export *'. export * from "interface-variable"; ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2497: External module '"interface-variable"' uses 'export =' and cannot be used with 'export *'. +!!! error TS2498: External module '"interface-variable"' uses 'export =' and cannot be used with 'export *'. export * from "module"; ~~~~~~~~ -!!! error TS2497: External module '"module"' uses 'export =' and cannot be used with 'export *'. +!!! error TS2498: External module '"module"' uses 'export =' and cannot be used with 'export *'. export * from "interface-module"; ~~~~~~~~~~~~~~~~~~ -!!! error TS2497: External module '"interface-module"' uses 'export =' and cannot be used with 'export *'. +!!! error TS2498: External module '"interface-module"' uses 'export =' and cannot be used with 'export *'. export * from "variable-module"; ~~~~~~~~~~~~~~~~~ -!!! error TS2497: External module '"variable-module"' uses 'export =' and cannot be used with 'export *'. +!!! error TS2498: External module '"variable-module"' uses 'export =' and cannot be used with 'export *'. export * from "function"; ~~~~~~~~~~ -!!! error TS2497: External module '"function"' uses 'export =' and cannot be used with 'export *'. +!!! error TS2498: External module '"function"' uses 'export =' and cannot be used with 'export *'. export * from "function-module"; ~~~~~~~~~~~~~~~~~ -!!! error TS2497: External module '"function-module"' uses 'export =' and cannot be used with 'export *'. +!!! error TS2498: External module '"function-module"' uses 'export =' and cannot be used with 'export *'. export * from "class"; ~~~~~~~ -!!! error TS2497: External module '"class"' uses 'export =' and cannot be used with 'export *'. +!!! error TS2498: External module '"class"' uses 'export =' and cannot be used with 'export *'. export * from "class-module"; ~~~~~~~~~~~~~~ -!!! error TS2497: External module '"class-module"' uses 'export =' and cannot be used with 'export *'. +!!! error TS2498: External module '"class-module"' uses 'export =' and cannot be used with 'export *'. ==== tests/cases/compiler/modules.d.ts (0 errors) ==== diff --git a/tests/baselines/reference/es6ExportEqualsInterop.js b/tests/baselines/reference/es6ExportEqualsInterop.js index 6775bb8c6bbe6..747b0b2beb808 100644 --- a/tests/baselines/reference/es6ExportEqualsInterop.js +++ b/tests/baselines/reference/es6ExportEqualsInterop.js @@ -253,41 +253,41 @@ y8.a; y9.a; y0.a; // named import -var _interface_2 = require("interface"); -var _variable_2 = require("variable"); -var _interface_variable_2 = require("interface-variable"); -var _module_2 = require("module"); -var _interface_module_2 = require("interface-module"); -var _variable_module_2 = require("variable-module"); -var _function_2 = require("function"); -var _function_module_2 = require("function-module"); -var _class_2 = require("class"); -var _class_module_2 = require("class-module"); -_interface_2.a; -_variable_2.a; -_interface_variable_2.a; -_module_2.a; -_interface_module_2.a; -_variable_module_2.a; -_function_2.a; -_function_module_2.a; -_class_2.a; -_class_module_2.a; +var interface_1 = require("interface"); +var variable_1 = require("variable"); +var interface_variable_1 = require("interface-variable"); +var module_1 = require("module"); +var interface_module_1 = require("interface-module"); +var variable_module_1 = require("variable-module"); +var function_1 = require("function"); +var function_module_1 = require("function-module"); +var class_1 = require("class"); +var class_module_1 = require("class-module"); +interface_1.a; +variable_1.a; +interface_variable_1.a; +module_1.a; +interface_module_1.a; +variable_module_1.a; +function_1.a; +function_module_1.a; +class_1.a; +class_module_1.a; // named export -var _variable_3 = require("variable"); -exports.a2 = _variable_3.a; -var _interface_variable_3 = require("interface-variable"); -exports.a3 = _interface_variable_3.a; -var _module_3 = require("module"); -exports.a4 = _module_3.a; -var _interface_module_3 = require("interface-module"); -exports.a5 = _interface_module_3.a; -var _variable_module_3 = require("variable-module"); -exports.a6 = _variable_module_3.a; -var _function_module_3 = require("function-module"); -exports.a8 = _function_module_3.a; -var _class_module_3 = require("class-module"); -exports.a0 = _class_module_3.a; +var variable_2 = require("variable"); +exports.a2 = variable_2.a; +var interface_variable_2 = require("interface-variable"); +exports.a3 = interface_variable_2.a; +var module_2 = require("module"); +exports.a4 = module_2.a; +var interface_module_2 = require("interface-module"); +exports.a5 = interface_module_2.a; +var variable_module_2 = require("variable-module"); +exports.a6 = variable_module_2.a; +var function_module_2 = require("function-module"); +exports.a8 = function_module_2.a; +var class_module_2 = require("class-module"); +exports.a0 = class_module_2.a; // export-star __export(require("interface")); __export(require("variable")); diff --git a/tests/baselines/reference/es6ImportDefaultBinding.errors.txt b/tests/baselines/reference/es6ImportDefaultBinding.errors.txt deleted file mode 100644 index a35606749b3bb..0000000000000 --- a/tests/baselines/reference/es6ImportDefaultBinding.errors.txt +++ /dev/null @@ -1,11 +0,0 @@ -tests/cases/compiler/es6ImportDefaultBinding_1.ts(1,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBinding_0"' has no default export. - - -==== tests/cases/compiler/es6ImportDefaultBinding_0.ts (0 errors) ==== - - export var a = 10; - -==== tests/cases/compiler/es6ImportDefaultBinding_1.ts (1 errors) ==== - import defaultBinding from "es6ImportDefaultBinding_0"; - ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBinding_0"' has no default export. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBinding.js b/tests/baselines/reference/es6ImportDefaultBinding.js index d8d1fa8111dc3..2798d025894ba 100644 --- a/tests/baselines/reference/es6ImportDefaultBinding.js +++ b/tests/baselines/reference/es6ImportDefaultBinding.js @@ -2,11 +2,24 @@ //// [es6ImportDefaultBinding_0.ts] -export var a = 10; +var a = 10; +export default a; //// [es6ImportDefaultBinding_1.ts] -import defaultBinding from "es6ImportDefaultBinding_0"; +import defaultBinding from "es6ImportDefaultBinding_0"; +var x = defaultBinding; +import defaultBinding2 from "es6ImportDefaultBinding_0"; // elide this import since defaultBinding2 is not used + //// [es6ImportDefaultBinding_0.js] -exports.a = 10; +var a = 10; +export default a; //// [es6ImportDefaultBinding_1.js] +import defaultBinding from "es6ImportDefaultBinding_0"; +var x = defaultBinding; + + +//// [es6ImportDefaultBinding_0.d.ts] +declare var a: number; +export default a; +//// [es6ImportDefaultBinding_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBinding.types b/tests/baselines/reference/es6ImportDefaultBinding.types new file mode 100644 index 0000000000000..13504101a2c29 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBinding.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/es6ImportDefaultBinding_0.ts === + +var a = 10; +>a : number + +export default a; +>a : number + +=== tests/cases/compiler/es6ImportDefaultBinding_1.ts === +import defaultBinding from "es6ImportDefaultBinding_0"; +>defaultBinding : number + +var x = defaultBinding; +>x : number +>defaultBinding : number + +import defaultBinding2 from "es6ImportDefaultBinding_0"; // elide this import since defaultBinding2 is not used +>defaultBinding2 : number + diff --git a/tests/baselines/reference/es6ImportDefaultBindingAmd.js b/tests/baselines/reference/es6ImportDefaultBindingAmd.js new file mode 100644 index 0000000000000..70e4f7e2f57a1 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingAmd.js @@ -0,0 +1,28 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingAmd.ts] //// + +//// [es6ImportDefaultBindingAmd_0.ts] + +var a = 10; +export default a; + +//// [es6ImportDefaultBindingAmd_1.ts] +import defaultBinding from "es6ImportDefaultBindingAmd_0"; +var x = defaultBinding; +import defaultBinding2 from "es6ImportDefaultBindingAmd_0"; // elide this import since defaultBinding2 is not used + + +//// [es6ImportDefaultBindingAmd_0.js] +define(["require", "exports"], function (require, exports) { + var a = 10; + exports.default = a; +}); +//// [es6ImportDefaultBindingAmd_1.js] +define(["require", "exports", "es6ImportDefaultBindingAmd_0"], function (require, exports, es6ImportDefaultBindingAmd_0_1) { + var x = es6ImportDefaultBindingAmd_0_1.default; +}); + + +//// [es6ImportDefaultBindingAmd_0.d.ts] +declare var a: number; +export default a; +//// [es6ImportDefaultBindingAmd_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingAmd.types b/tests/baselines/reference/es6ImportDefaultBindingAmd.types new file mode 100644 index 0000000000000..323ed557d8b3d --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingAmd.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/es6ImportDefaultBindingAmd_0.ts === + +var a = 10; +>a : number + +export default a; +>a : number + +=== tests/cases/compiler/es6ImportDefaultBindingAmd_1.ts === +import defaultBinding from "es6ImportDefaultBindingAmd_0"; +>defaultBinding : number + +var x = defaultBinding; +>x : number +>defaultBinding : number + +import defaultBinding2 from "es6ImportDefaultBindingAmd_0"; // elide this import since defaultBinding2 is not used +>defaultBinding2 : number + diff --git a/tests/baselines/reference/es6ImportDefaultBindingDts.js b/tests/baselines/reference/es6ImportDefaultBindingDts.js new file mode 100644 index 0000000000000..caa46ed30efe2 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingDts.js @@ -0,0 +1,32 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingDts.ts] //// + +//// [server.ts] + +class c { } +export default c; + +//// [client.ts] +import defaultBinding from "server"; +export var x = new defaultBinding(); +import defaultBinding2 from "server"; // elide this import since defaultBinding2 is not used + + +//// [server.js] +var c = (function () { + function c() { + } + return c; +})(); +exports.default = c; +//// [client.js] +var server_1 = require("server"); +exports.x = new server_1.default(); + + +//// [server.d.ts] +declare class c { +} +export default c; +//// [client.d.ts] +import defaultBinding from "server"; +export declare var x: defaultBinding; diff --git a/tests/baselines/reference/es6ImportDefaultBindingDts.types b/tests/baselines/reference/es6ImportDefaultBindingDts.types new file mode 100644 index 0000000000000..65754d806802b --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingDts.types @@ -0,0 +1,20 @@ +=== tests/cases/compiler/server.ts === + +class c { } +>c : c + +export default c; +>c : c + +=== tests/cases/compiler/client.ts === +import defaultBinding from "server"; +>defaultBinding : typeof defaultBinding + +export var x = new defaultBinding(); +>x : defaultBinding +>new defaultBinding() : defaultBinding +>defaultBinding : typeof defaultBinding + +import defaultBinding2 from "server"; // elide this import since defaultBinding2 is not used +>defaultBinding2 : typeof defaultBinding + diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt index d9cc779419356..34bb303a571e4 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt @@ -1,51 +1,25 @@ -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(1,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(1,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(2,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(2,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(3,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(3,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(4,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(4,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(5,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(5,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(6,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(6,8): error TS2300: Duplicate identifier 'defaultBinding'. +error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. ==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0.ts (0 errors) ==== export var a = 10; export var x = a; export var m = a; + export default {}; -==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts (12 errors) ==== - import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; - ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; - ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; - ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; - ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; - ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; - ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. \ No newline at end of file +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts (0 errors) ==== + import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + var x1: number = a; + import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + var x1: number = b; + import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + var x1: number = x; + var x1: number = y; + import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + var x1: number = z; + import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + var x1: number = m; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js index a7402bfeb6a8e..eef2357921292 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js @@ -5,17 +5,45 @@ export var a = 10; export var x = a; export var m = a; +export default {}; //// [es6ImportDefaultBindingFollowedWithNamedImport_1.ts] -import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = a; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = b; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = x; +var x1: number = y; +import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = z; +import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = m; + //// [es6ImportDefaultBindingFollowedWithNamedImport_0.js] -exports.a = 10; -exports.x = exports.a; -exports.m = exports.a; +export var a = 10; +export var x = a; +export var m = a; +export default {}; //// [es6ImportDefaultBindingFollowedWithNamedImport_1.js] +import { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1 = a; +import { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1 = b; +import { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1 = x; +var x1 = y; +import { x as z } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1 = z; +import { m } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1 = m; + + +//// [es6ImportDefaultBindingFollowedWithNamedImport_0.d.ts] +export declare var a: number; +export declare var x: number; +export declare var m: number; +export default : {}; +//// [es6ImportDefaultBindingFollowedWithNamedImport_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.errors.txt new file mode 100644 index 0000000000000..21f488e9ca581 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.errors.txt @@ -0,0 +1,39 @@ +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts(3,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts(5,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts(7,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'x'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts(7,30): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts(9,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'x'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts(11,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'm'. + + +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0.ts (0 errors) ==== + + var a = 10; + export default a; + +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts (6 errors) ==== + import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; + var x1: number = defaultBinding1; + import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'a'. + var x1: number = defaultBinding2; + import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'a'. + var x1: number = defaultBinding3; + import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'x'. + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'a'. + var x1: number = defaultBinding4; + import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'x'. + var x1: number = defaultBinding5; + import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'm'. + var x1: number = defaultBinding6; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js new file mode 100644 index 0000000000000..755af6f4fdb85 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js @@ -0,0 +1,44 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1.ts] //// + +//// [es6ImportDefaultBindingFollowedWithNamedImport1_0.ts] + +var a = 10; +export default a; + +//// [es6ImportDefaultBindingFollowedWithNamedImport1_1.ts] +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding1; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding2; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding3; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding4; +import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding5; +import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding6; + + +//// [es6ImportDefaultBindingFollowedWithNamedImport1_0.js] +var a = 10; +export default a; +//// [es6ImportDefaultBindingFollowedWithNamedImport1_1.js] +import defaultBinding1 from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1 = defaultBinding1; +import defaultBinding2 from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1 = defaultBinding2; +import defaultBinding3 from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1 = defaultBinding3; +import defaultBinding4 from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1 = defaultBinding4; +import defaultBinding5 from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1 = defaultBinding5; +import defaultBinding6 from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1 = defaultBinding6; + + +//// [es6ImportDefaultBindingFollowedWithNamedImport1_0.d.ts] +declare var a: number; +export default a; +//// [es6ImportDefaultBindingFollowedWithNamedImport1_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.errors.txt new file mode 100644 index 0000000000000..5809e0874dc7e --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.errors.txt @@ -0,0 +1,39 @@ +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts(3,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts(5,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts(7,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'x'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts(7,30): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts(9,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'x'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts(11,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'm'. + + +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0.ts (0 errors) ==== + + var a = 10; + export default a; + +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts (6 errors) ==== + import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; + var x: number = defaultBinding1; + import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'a'. + var x: number = defaultBinding2; + import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'a'. + var x: number = defaultBinding3; + import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'x'. + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'a'. + var x: number = defaultBinding4; + import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'x'. + var x: number = defaultBinding5; + import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'm'. + var x: number = defaultBinding6; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js new file mode 100644 index 0000000000000..15ca1284a1e0b --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js @@ -0,0 +1,44 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.ts] //// + +//// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0.ts] + +var a = 10; +export default a; + +//// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts] +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding1; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding2; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding3; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding4; +import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding5; +import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding6; + + +//// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0.js] +var a = 10; +exports.default = a; +//// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.js] +var es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0_1 = require("es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"); +var x = es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0_1.default; +var es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0_2 = require("es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"); +var x = es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0_2.default; +var es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0_3 = require("es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"); +var x = es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0_3.default; +var es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0_4 = require("es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"); +var x = es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0_4.default; +var es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0_5 = require("es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"); +var x = es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0_5.default; +var es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0_6 = require("es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"); +var x = es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0_6.default; + + +//// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0.d.ts] +declare var a: number; +export default a; +//// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.errors.txt new file mode 100644 index 0000000000000..aa9e0cb3af373 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.errors.txt @@ -0,0 +1,57 @@ +tests/cases/compiler/client.ts(1,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(3,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(3,34): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. +tests/cases/compiler/client.ts(5,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(5,34): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. +tests/cases/compiler/client.ts(7,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(7,34): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. +tests/cases/compiler/client.ts(7,37): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. +tests/cases/compiler/client.ts(9,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(9,34): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. +tests/cases/compiler/client.ts(11,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(11,34): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'm'. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + var a = 10; + export default a; + +==== tests/cases/compiler/client.ts (12 errors) ==== + export import defaultBinding1, { } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var x1: number = defaultBinding1; + export import defaultBinding2, { a } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. + export var x1: number = defaultBinding2; + export import defaultBinding3, { a as b } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. + export var x1: number = defaultBinding3; + export import defaultBinding4, { x, a as y } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. + export var x1: number = defaultBinding4; + export import defaultBinding5, { x as z, } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. + export var x1: number = defaultBinding5; + export import defaultBinding6, { m, } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'm'. + export var x1: number = defaultBinding6; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.js new file mode 100644 index 0000000000000..b6b03176df115 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.js @@ -0,0 +1,50 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.ts] //// + +//// [server.ts] + +var a = 10; +export default a; + +//// [client.ts] +export import defaultBinding1, { } from "server"; +export var x1: number = defaultBinding1; +export import defaultBinding2, { a } from "server"; +export var x1: number = defaultBinding2; +export import defaultBinding3, { a as b } from "server"; +export var x1: number = defaultBinding3; +export import defaultBinding4, { x, a as y } from "server"; +export var x1: number = defaultBinding4; +export import defaultBinding5, { x as z, } from "server"; +export var x1: number = defaultBinding5; +export import defaultBinding6, { m, } from "server"; +export var x1: number = defaultBinding6; + + +//// [server.js] +var a = 10; +exports.default = a; +//// [client.js] +var server_1 = require("server"); +exports.x1 = server_1.default; +var server_2 = require("server"); +exports.x1 = server_2.default; +var server_3 = require("server"); +exports.x1 = server_3.default; +var server_4 = require("server"); +exports.x1 = server_4.default; +var server_5 = require("server"); +exports.x1 = server_5.default; +var server_6 = require("server"); +exports.x1 = server_6.default; + + +//// [server.d.ts] +declare var a: number; +export default a; +//// [client.d.ts] +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.errors.txt new file mode 100644 index 0000000000000..409c50d3a3fc9 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.errors.txt @@ -0,0 +1,43 @@ +tests/cases/compiler/client.ts(1,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export. +tests/cases/compiler/client.ts(2,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export. +tests/cases/compiler/client.ts(4,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export. +tests/cases/compiler/client.ts(6,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export. +tests/cases/compiler/client.ts(9,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export. +tests/cases/compiler/client.ts(11,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + export class a { } + export class x { } + export class m { } + export class a11 { } + export class a12 { } + export class x11 { } + +==== tests/cases/compiler/client.ts (6 errors) ==== + import defaultBinding1, { } from "server"; + ~~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export. + import defaultBinding2, { a } from "server"; + ~~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export. + export var x1 = new a(); + import defaultBinding3, { a11 as b } from "server"; + ~~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export. + export var x2 = new b(); + import defaultBinding4, { x, a12 as y } from "server"; + ~~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export. + export var x4 = new x(); + export var x5 = new y(); + import defaultBinding5, { x11 as z, } from "server"; + ~~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export. + export var x3 = new z(); + import defaultBinding6, { m, } from "server"; + ~~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export. + export var x6 = new m(); + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js new file mode 100644 index 0000000000000..8cf9ab1ffb129 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js @@ -0,0 +1,102 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts.ts] //// + +//// [server.ts] + +export class a { } +export class x { } +export class m { } +export class a11 { } +export class a12 { } +export class x11 { } + +//// [client.ts] +import defaultBinding1, { } from "server"; +import defaultBinding2, { a } from "server"; +export var x1 = new a(); +import defaultBinding3, { a11 as b } from "server"; +export var x2 = new b(); +import defaultBinding4, { x, a12 as y } from "server"; +export var x4 = new x(); +export var x5 = new y(); +import defaultBinding5, { x11 as z, } from "server"; +export var x3 = new z(); +import defaultBinding6, { m, } from "server"; +export var x6 = new m(); + + +//// [server.js] +var a = (function () { + function a() { + } + return a; +})(); +exports.a = a; +var x = (function () { + function x() { + } + return x; +})(); +exports.x = x; +var m = (function () { + function m() { + } + return m; +})(); +exports.m = m; +var a11 = (function () { + function a11() { + } + return a11; +})(); +exports.a11 = a11; +var a12 = (function () { + function a12() { + } + return a12; +})(); +exports.a12 = a12; +var x11 = (function () { + function x11() { + } + return x11; +})(); +exports.x11 = x11; +//// [client.js] +var server_1 = require("server"); +exports.x1 = new server_1.a(); +var server_2 = require("server"); +exports.x2 = new server_2.a11(); +var server_3 = require("server"); +exports.x4 = new server_3.x(); +exports.x5 = new server_3.a12(); +var server_4 = require("server"); +exports.x3 = new server_4.x11(); +var server_5 = require("server"); +exports.x6 = new server_5.m(); + + +//// [server.d.ts] +export declare class a { +} +export declare class x { +} +export declare class m { +} +export declare class a11 { +} +export declare class a12 { +} +export declare class x11 { +} +//// [client.d.ts] +import { a } from "server"; +export declare var x1: a; +import { a11 as b } from "server"; +export declare var x2: b; +import { x, a12 as y } from "server"; +export declare var x4: x; +export declare var x5: y; +import { x11 as z } from "server"; +export declare var x3: z; +import { m } from "server"; +export declare var x6: m; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.errors.txt new file mode 100644 index 0000000000000..0e259f142b607 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.errors.txt @@ -0,0 +1,38 @@ +tests/cases/compiler/client.ts(3,27): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. +tests/cases/compiler/client.ts(5,27): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. +tests/cases/compiler/client.ts(7,27): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. +tests/cases/compiler/client.ts(7,30): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. +tests/cases/compiler/client.ts(9,27): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. +tests/cases/compiler/client.ts(11,27): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'm'. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + class a { } + export default a; + +==== tests/cases/compiler/client.ts (6 errors) ==== + import defaultBinding1, { } from "server"; + export var x1 = new defaultBinding1(); + import defaultBinding2, { a } from "server"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. + export var x2 = new defaultBinding2(); + import defaultBinding3, { a as b } from "server"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. + export var x3 = new defaultBinding3(); + import defaultBinding4, { x, a as y } from "server"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. + export var x4 = new defaultBinding4(); + import defaultBinding5, { x as z, } from "server"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. + export var x5 = new defaultBinding5(); + import defaultBinding6, { m, } from "server"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'm'. + export var x6 = new defaultBinding6(); \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.js new file mode 100644 index 0000000000000..e6211ac1ebec0 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.js @@ -0,0 +1,55 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts1.ts] //// + +//// [server.ts] + +class a { } +export default a; + +//// [client.ts] +import defaultBinding1, { } from "server"; +export var x1 = new defaultBinding1(); +import defaultBinding2, { a } from "server"; +export var x2 = new defaultBinding2(); +import defaultBinding3, { a as b } from "server"; +export var x3 = new defaultBinding3(); +import defaultBinding4, { x, a as y } from "server"; +export var x4 = new defaultBinding4(); +import defaultBinding5, { x as z, } from "server"; +export var x5 = new defaultBinding5(); +import defaultBinding6, { m, } from "server"; +export var x6 = new defaultBinding6(); + +//// [server.js] +var a = (function () { + function a() { + } + return a; +})(); +exports.default = a; +//// [client.js] +var server_1 = require("server"); +exports.x1 = new server_1.default(); +var server_2 = require("server"); +exports.x2 = new server_2.default(); +var server_3 = require("server"); +exports.x3 = new server_3.default(); +var server_4 = require("server"); +exports.x4 = new server_4.default(); +var server_5 = require("server"); +exports.x5 = new server_5.default(); +var server_6 = require("server"); +exports.x6 = new server_6.default(); + + +//// [server.d.ts] +declare class a { +} +export default a; +//// [client.d.ts] +import defaultBinding1 from "server"; +export declare var x1: defaultBinding1; +export declare var x2: defaultBinding1; +export declare var x3: defaultBinding1; +export declare var x4: defaultBinding1; +export declare var x5: defaultBinding1; +export declare var x6: defaultBinding1; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.errors.txt index cc41e2c707d2e..502b1940576f1 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.errors.txt @@ -1,15 +1,9 @@ tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(1,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(1,8): error TS2300: Duplicate identifier 'defaultBinding'. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(2,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(2,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(3,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(3,8): error TS2300: Duplicate identifier 'defaultBinding'. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(4,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(4,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(5,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(5,8): error TS2300: Duplicate identifier 'defaultBinding'. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(6,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(6,8): error TS2300: Duplicate identifier 'defaultBinding'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(9,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(11,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export. ==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0.ts (0 errors) ==== @@ -18,34 +12,29 @@ tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(6, export var x = a; export var m = a; -==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts (12 errors) ==== - import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; - ~~~~~~~~~~~~~~ +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts (6 errors) ==== + import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; - ~~~~~~~~~~~~~~ + import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; - ~~~~~~~~~~~~~~ + var x1: number = a; + import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; - ~~~~~~~~~~~~~~ + var x1: number = b; + import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; - ~~~~~~~~~~~~~~ + var x1: number = x; + var x1: number = y; + import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; - ~~~~~~~~~~~~~~ + var x1: number = z; + import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. \ No newline at end of file + var x1: number = m; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js index 4cf3046532a0a..1c65fadbe1d43 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js @@ -7,15 +7,40 @@ export var x = a; export var m = a; //// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts] -import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = a; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = b; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = x; +var x1: number = y; +import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = z; +import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = m; + //// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_0.js] exports.a = 10; exports.x = exports.a; exports.m = exports.a; //// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.js] +var es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_1 = require("es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"); +var x1 = es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_1.a; +var es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_2 = require("es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"); +var x1 = es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_2.a; +var es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_3 = require("es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"); +var x1 = es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_3.x; +var x1 = es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_3.a; +var es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_4 = require("es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"); +var x1 = es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_4.x; +var es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_5 = require("es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"); +var x1 = es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_5.m; + + +//// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_0.d.ts] +export declare var a: number; +export declare var x: number; +export declare var m: number; +//// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.errors.txt new file mode 100644 index 0000000000000..83f91787b87fb --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.errors.txt @@ -0,0 +1,41 @@ +tests/cases/compiler/client.ts(1,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(2,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(4,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(6,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(9,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(11,1): error TS1191: An import declaration cannot have modifiers. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + export var a = 10; + export var x = a; + export var m = a; + export default {}; + +==== tests/cases/compiler/client.ts (6 errors) ==== + export import defaultBinding1, { } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export import defaultBinding2, { a } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var x1: number = a; + export import defaultBinding3, { a as b } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var x1: number = b; + export import defaultBinding4, { x, a as y } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var x1: number = x; + export var x1: number = y; + export import defaultBinding5, { x as z, } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var x1: number = z; + export import defaultBinding6, { m, } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var x1: number = m; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js new file mode 100644 index 0000000000000..0d5f38c0be43c --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js @@ -0,0 +1,54 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportWithExport.ts] //// + +//// [server.ts] + +export var a = 10; +export var x = a; +export var m = a; +export default {}; + +//// [client.ts] +export import defaultBinding1, { } from "server"; +export import defaultBinding2, { a } from "server"; +export var x1: number = a; +export import defaultBinding3, { a as b } from "server"; +export var x1: number = b; +export import defaultBinding4, { x, a as y } from "server"; +export var x1: number = x; +export var x1: number = y; +export import defaultBinding5, { x as z, } from "server"; +export var x1: number = z; +export import defaultBinding6, { m, } from "server"; +export var x1: number = m; + + +//// [server.js] +define(["require", "exports"], function (require, exports) { + exports.a = 10; + exports.x = exports.a; + exports.m = exports.a; + exports.default = {}; +}); +//// [client.js] +define(["require", "exports", "server", "server", "server", "server", "server"], function (require, exports, server_1, server_2, server_3, server_4, server_5) { + exports.x1 = server_1.a; + exports.x1 = server_2.a; + exports.x1 = server_3.x; + exports.x1 = server_3.a; + exports.x1 = server_4.x; + exports.x1 = server_5.m; +}); + + +//// [server.d.ts] +export declare var a: number; +export declare var x: number; +export declare var m: number; +export default : {}; +//// [client.d.ts] +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.errors.txt index 50302a5331dc0..ce7e8b1dc5dbf 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.errors.txt @@ -8,4 +8,5 @@ tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts(1, ==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts (1 errors) ==== import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_0"' has no default export. \ No newline at end of file +!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_0"' has no default export. + var x: number = nameSpaceBinding.a; \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js index 5ec91279306dd..2b24fda075559 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js @@ -5,8 +5,16 @@ export var a = 10; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts] -import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; +var x: number = nameSpaceBinding.a; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.js] -exports.a = 10; +export var a = 10; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.js] +import * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; +var x = nameSpaceBinding.a; + + +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.d.ts] +export declare var a: number; +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js new file mode 100644 index 0000000000000..a732cf9ec0a93 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js @@ -0,0 +1,23 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1.ts] //// + +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.ts] + +var a = 10; +export default a; + +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts] +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; +var x: number = defaultBinding; + +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.js] +var a = 10; +export default a; +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.js] +import defaultBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; +var x = defaultBinding; + + +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.d.ts] +declare var a: number; +export default a; +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.types b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.types new file mode 100644 index 0000000000000..c0c3f891c9e7d --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.types @@ -0,0 +1,17 @@ +=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_0.ts === + +var a = 10; +>a : number + +export default a; +>a : number + +=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts === +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; +>defaultBinding : number +>nameSpaceBinding : typeof nameSpaceBinding + +var x: number = defaultBinding; +>x : number +>defaultBinding : number + diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js new file mode 100644 index 0000000000000..c2bd5476a7c4e --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js @@ -0,0 +1,23 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.ts] //// + +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.ts] + +var a = 10; +export default a; + +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts] +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; +var x: number = defaultBinding; + +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.js] +var a = 10; +exports.default = a; +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.js] +var es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0_1 = require("es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"), nameSpaceBinding = es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0_1; +var x = es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0_1.default; + + +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.d.ts] +declare var a: number; +export default a; +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.types b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.types new file mode 100644 index 0000000000000..ad2b865bc01e1 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.types @@ -0,0 +1,17 @@ +=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.ts === + +var a = 10; +>a : number + +export default a; +>a : number + +=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts === +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; +>defaultBinding : number +>nameSpaceBinding : typeof nameSpaceBinding + +var x: number = defaultBinding; +>x : number +>defaultBinding : number + diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.errors.txt new file mode 100644 index 0000000000000..f738abc9bc1de --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/client.ts(1,1): error TS1191: An import declaration cannot have modifiers. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + var a = 10; + export default a; + +==== tests/cases/compiler/client.ts (1 errors) ==== + export import defaultBinding, * as nameSpaceBinding from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var x: number = defaultBinding; \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.js new file mode 100644 index 0000000000000..ed40582e9231d --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.js @@ -0,0 +1,28 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.ts] //// + +//// [server.ts] + +var a = 10; +export default a; + +//// [client.ts] +export import defaultBinding, * as nameSpaceBinding from "server"; +export var x: number = defaultBinding; + +//// [server.js] +define(["require", "exports"], function (require, exports) { + var a = 10; + exports.default = a; +}); +//// [client.js] +define(["require", "exports", "server"], function (require, exports, server_1) { + var nameSpaceBinding = server_1; + exports.x = server_1.default; +}); + + +//// [server.d.ts] +declare var a: number; +export default a; +//// [client.d.ts] +export declare var x: number; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.errors.txt new file mode 100644 index 0000000000000..8af978d3bb67c --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.errors.txt @@ -0,0 +1,12 @@ +tests/cases/compiler/client.ts(1,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + export class a { } + +==== tests/cases/compiler/client.ts (1 errors) ==== + import defaultBinding, * as nameSpaceBinding from "server"; + ~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export. + export var x = new nameSpaceBinding.a(); \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.js new file mode 100644 index 0000000000000..31ef01c464c80 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.js @@ -0,0 +1,28 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.ts] //// + +//// [server.ts] + +export class a { } + +//// [client.ts] +import defaultBinding, * as nameSpaceBinding from "server"; +export var x = new nameSpaceBinding.a(); + +//// [server.js] +var a = (function () { + function a() { + } + return a; +})(); +exports.a = a; +//// [client.js] +var server_1 = require("server"), nameSpaceBinding = server_1; +exports.x = new nameSpaceBinding.a(); + + +//// [server.d.ts] +export declare class a { +} +//// [client.d.ts] +import * as nameSpaceBinding from "server"; +export declare var x: nameSpaceBinding.a; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js new file mode 100644 index 0000000000000..e03ded5fd5aaf --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js @@ -0,0 +1,34 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.ts] //// + +//// [server.ts] + +class a { } +export default a; + +//// [client.ts] +import defaultBinding, * as nameSpaceBinding from "server"; +export var x = new defaultBinding(); + +//// [server.js] +define(["require", "exports"], function (require, exports) { + var a = (function () { + function a() { + } + return a; + })(); + exports.default = a; +}); +//// [client.js] +define(["require", "exports", "server"], function (require, exports, server_1) { + var nameSpaceBinding = server_1; + exports.x = new server_1.default(); +}); + + +//// [server.d.ts] +declare class a { +} +export default a; +//// [client.d.ts] +import defaultBinding from "server"; +export declare var x: defaultBinding; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.types b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.types new file mode 100644 index 0000000000000..990bae10af6d3 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/server.ts === + +class a { } +>a : a + +export default a; +>a : a + +=== tests/cases/compiler/client.ts === +import defaultBinding, * as nameSpaceBinding from "server"; +>defaultBinding : typeof defaultBinding +>nameSpaceBinding : typeof nameSpaceBinding + +export var x = new defaultBinding(); +>x : defaultBinding +>new defaultBinding() : defaultBinding +>defaultBinding : typeof defaultBinding + diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.errors.txt index ae4587e07dc9a..48829f8e719d6 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.errors.txt @@ -8,4 +8,5 @@ tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1. ==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts (1 errors) ==== import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"' has no default export. \ No newline at end of file +!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"' has no default export. + var x: number = nameSpaceBinding.a; \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js index abd4736fca706..4a49d3c2d6fd5 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js @@ -5,8 +5,16 @@ export var a = 10; //// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts] -import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; +var x: number = nameSpaceBinding.a; //// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.js] exports.a = 10; //// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.js] +var es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0_1 = require("es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"), nameSpaceBinding = es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0_1; +var x = nameSpaceBinding.a; + + +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.d.ts] +export declare var a: number; +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.errors.txt new file mode 100644 index 0000000000000..4730d493d8e99 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/client.ts(1,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(1,15): error TS1192: External module '"tests/cases/compiler/server"' has no default export. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/client.ts (2 errors) ==== + export import defaultBinding, * as nameSpaceBinding from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export. + export var x: number = nameSpaceBinding.a; \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.js new file mode 100644 index 0000000000000..df233fe18a5b3 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.js @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.ts] //// + +//// [server.ts] + +export var a = 10; + +//// [client.ts] +export import defaultBinding, * as nameSpaceBinding from "server"; +export var x: number = nameSpaceBinding.a; + +//// [server.js] +exports.a = 10; +//// [client.js] +var server_1 = require("server"), nameSpaceBinding = server_1; +exports.x = nameSpaceBinding.a; + + +//// [server.d.ts] +export declare var a: number; +//// [client.d.ts] +export declare var x: number; diff --git a/tests/baselines/reference/es6ImportDefaultBindingInEs5.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingInEs5.errors.txt index 506793103f810..5cccfd01094d2 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingInEs5.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingInEs5.errors.txt @@ -3,7 +3,8 @@ tests/cases/compiler/es6ImportDefaultBindingInEs5_1.ts(1,8): error TS1192: Exter ==== tests/cases/compiler/es6ImportDefaultBindingInEs5_0.ts (0 errors) ==== - export var a = 10; + var a = 10; + export = a; ==== tests/cases/compiler/es6ImportDefaultBindingInEs5_1.ts (1 errors) ==== import defaultBinding from "es6ImportDefaultBindingInEs5_0"; diff --git a/tests/baselines/reference/es6ImportDefaultBindingInEs5.js b/tests/baselines/reference/es6ImportDefaultBindingInEs5.js index b6d293225fd0b..0b703f829ca31 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingInEs5.js +++ b/tests/baselines/reference/es6ImportDefaultBindingInEs5.js @@ -2,11 +2,19 @@ //// [es6ImportDefaultBindingInEs5_0.ts] -export var a = 10; +var a = 10; +export = a; //// [es6ImportDefaultBindingInEs5_1.ts] import defaultBinding from "es6ImportDefaultBindingInEs5_0"; //// [es6ImportDefaultBindingInEs5_0.js] -exports.a = 10; +var a = 10; +module.exports = a; //// [es6ImportDefaultBindingInEs5_1.js] + + +//// [es6ImportDefaultBindingInEs5_0.d.ts] +declare var a: number; +export = a; +//// [es6ImportDefaultBindingInEs5_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.errors.txt new file mode 100644 index 0000000000000..cd0550609c73b --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.errors.txt @@ -0,0 +1,26 @@ +tests/cases/compiler/es6ImportDefaultBindingMergeErrors_1.ts(5,8): error TS2440: Import declaration conflicts with local declaration of 'defaultBinding2' +tests/cases/compiler/es6ImportDefaultBindingMergeErrors_1.ts(7,8): error TS2300: Duplicate identifier 'defaultBinding3'. +tests/cases/compiler/es6ImportDefaultBindingMergeErrors_1.ts(8,8): error TS2300: Duplicate identifier 'defaultBinding3'. + + +==== tests/cases/compiler/es6ImportDefaultBindingMergeErrors_0.ts (0 errors) ==== + + var a = 10; + export default a; + +==== tests/cases/compiler/es6ImportDefaultBindingMergeErrors_1.ts (3 errors) ==== + import defaultBinding from "es6ImportDefaultBindingMergeErrors_0"; + interface defaultBinding { // This is ok + } + var x = defaultBinding; + import defaultBinding2 from "es6ImportDefaultBindingMergeErrors_0"; // Should be error + ~~~~~~~~~~~~~~~ +!!! error TS2440: Import declaration conflicts with local declaration of 'defaultBinding2' + var defaultBinding2 = "hello world"; + import defaultBinding3 from "es6ImportDefaultBindingMergeErrors_0"; // Should be error + ~~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'defaultBinding3'. + import defaultBinding3 from "es6ImportDefaultBindingMergeErrors_0"; // SHould be error + ~~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'defaultBinding3'. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.js b/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.js new file mode 100644 index 0000000000000..1208ace5ddef4 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.js @@ -0,0 +1,25 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingMergeErrors.ts] //// + +//// [es6ImportDefaultBindingMergeErrors_0.ts] + +var a = 10; +export default a; + +//// [es6ImportDefaultBindingMergeErrors_1.ts] +import defaultBinding from "es6ImportDefaultBindingMergeErrors_0"; +interface defaultBinding { // This is ok +} +var x = defaultBinding; +import defaultBinding2 from "es6ImportDefaultBindingMergeErrors_0"; // Should be error +var defaultBinding2 = "hello world"; +import defaultBinding3 from "es6ImportDefaultBindingMergeErrors_0"; // Should be error +import defaultBinding3 from "es6ImportDefaultBindingMergeErrors_0"; // SHould be error + + +//// [es6ImportDefaultBindingMergeErrors_0.js] +var a = 10; +exports.default = a; +//// [es6ImportDefaultBindingMergeErrors_1.js] +var es6ImportDefaultBindingMergeErrors_0_1 = require("es6ImportDefaultBindingMergeErrors_0"); +var x = es6ImportDefaultBindingMergeErrors_0_1.default; +var defaultBinding2 = "hello world"; diff --git a/tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.errors.txt new file mode 100644 index 0000000000000..43eaa16f639a9 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.errors.txt @@ -0,0 +1,12 @@ +tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty_1.ts(1,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty_0"' has no default export. + + +==== tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty_0.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty_1.ts (1 errors) ==== + import defaultBinding from "es6ImportDefaultBindingNoDefaultProperty_0"; + ~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty_0"' has no default export. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.js b/tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.js new file mode 100644 index 0000000000000..f824dbf71d56e --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.js @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty.ts] //// + +//// [es6ImportDefaultBindingNoDefaultProperty_0.ts] + +export var a = 10; + +//// [es6ImportDefaultBindingNoDefaultProperty_1.ts] +import defaultBinding from "es6ImportDefaultBindingNoDefaultProperty_0"; + + +//// [es6ImportDefaultBindingNoDefaultProperty_0.js] +exports.a = 10; +//// [es6ImportDefaultBindingNoDefaultProperty_1.js] diff --git a/tests/baselines/reference/es6ImportDefaultBindingWithExport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingWithExport.errors.txt new file mode 100644 index 0000000000000..1bd24e8492662 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingWithExport.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/client.ts(1,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(3,1): error TS1191: An import declaration cannot have modifiers. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + var a = 10; + export default a; + +==== tests/cases/compiler/client.ts (2 errors) ==== + export import defaultBinding from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var x = defaultBinding; + export import defaultBinding2 from "server"; // non referenced + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingWithExport.js b/tests/baselines/reference/es6ImportDefaultBindingWithExport.js new file mode 100644 index 0000000000000..e2c5fab4c94b6 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingWithExport.js @@ -0,0 +1,28 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingWithExport.ts] //// + +//// [server.ts] + +var a = 10; +export default a; + +//// [client.ts] +export import defaultBinding from "server"; +export var x = defaultBinding; +export import defaultBinding2 from "server"; // non referenced + +//// [server.js] +define(["require", "exports"], function (require, exports) { + var a = 10; + exports.default = a; +}); +//// [client.js] +define(["require", "exports", "server"], function (require, exports, server_1) { + exports.x = server_1.default; +}); + + +//// [server.d.ts] +declare var a: number; +export default a; +//// [client.d.ts] +export declare var x: number; diff --git a/tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt b/tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt new file mode 100644 index 0000000000000..d3351ee97b22c --- /dev/null +++ b/tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/client.ts(1,1): error TS1202: Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead. +tests/cases/compiler/server.ts(3,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. + + +==== tests/cases/compiler/client.ts (1 errors) ==== + import a = require("server"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1202: Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead. +==== tests/cases/compiler/server.ts (1 errors) ==== + + var a = 10; + export = a; + ~~~~~~~~~~~ +!!! error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportEqualsDeclaration.js b/tests/baselines/reference/es6ImportEqualsDeclaration.js new file mode 100644 index 0000000000000..5195bdc631b30 --- /dev/null +++ b/tests/baselines/reference/es6ImportEqualsDeclaration.js @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/es6ImportEqualsDeclaration.ts] //// + +//// [server.ts] + +var a = 10; +export = a; + +//// [client.ts] +import a = require("server"); + +//// [server.js] +var a = 10; +//// [client.js] diff --git a/tests/baselines/reference/es6ImportNameSpaceImport.errors.txt b/tests/baselines/reference/es6ImportNameSpaceImport.errors.txt new file mode 100644 index 0000000000000..635bb955c00f6 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImport.errors.txt @@ -0,0 +1,13 @@ +error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. + + +!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +==== tests/cases/compiler/es6ImportNameSpaceImport_0.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/es6ImportNameSpaceImport_1.ts (0 errors) ==== + import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; + var x = nameSpaceBinding.a; + import * as nameSpaceBinding2 from "es6ImportNameSpaceImport_0"; // elide this + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNameSpaceImport.js b/tests/baselines/reference/es6ImportNameSpaceImport.js index c6daa3b122255..653feeb22b7c5 100644 --- a/tests/baselines/reference/es6ImportNameSpaceImport.js +++ b/tests/baselines/reference/es6ImportNameSpaceImport.js @@ -5,8 +5,18 @@ export var a = 10; //// [es6ImportNameSpaceImport_1.ts] -import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; +import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; +var x = nameSpaceBinding.a; +import * as nameSpaceBinding2 from "es6ImportNameSpaceImport_0"; // elide this + //// [es6ImportNameSpaceImport_0.js] -exports.a = 10; +export var a = 10; //// [es6ImportNameSpaceImport_1.js] +import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; +var x = nameSpaceBinding.a; + + +//// [es6ImportNameSpaceImport_0.d.ts] +export declare var a: number; +//// [es6ImportNameSpaceImport_1.d.ts] diff --git a/tests/baselines/reference/es6ImportNameSpaceImport.types b/tests/baselines/reference/es6ImportNameSpaceImport.types deleted file mode 100644 index 1e09de42ec6a2..0000000000000 --- a/tests/baselines/reference/es6ImportNameSpaceImport.types +++ /dev/null @@ -1,9 +0,0 @@ -=== tests/cases/compiler/es6ImportNameSpaceImport_0.ts === - -export var a = 10; ->a : number - -=== tests/cases/compiler/es6ImportNameSpaceImport_1.ts === -import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; ->nameSpaceBinding : typeof nameSpaceBinding - diff --git a/tests/baselines/reference/es6ImportNameSpaceImportAmd.js b/tests/baselines/reference/es6ImportNameSpaceImportAmd.js new file mode 100644 index 0000000000000..e7d0eae9ca96b --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportAmd.js @@ -0,0 +1,25 @@ +//// [tests/cases/compiler/es6ImportNameSpaceImportAmd.ts] //// + +//// [es6ImportNameSpaceImportAmd_0.ts] + +export var a = 10; + +//// [es6ImportNameSpaceImportAmd_1.ts] +import * as nameSpaceBinding from "es6ImportNameSpaceImportAmd_0"; +var x = nameSpaceBinding.a; +import * as nameSpaceBinding2 from "es6ImportNameSpaceImportAmd_0"; // elide this + + +//// [es6ImportNameSpaceImportAmd_0.js] +define(["require", "exports"], function (require, exports) { + exports.a = 10; +}); +//// [es6ImportNameSpaceImportAmd_1.js] +define(["require", "exports", "es6ImportNameSpaceImportAmd_0"], function (require, exports, nameSpaceBinding) { + var x = nameSpaceBinding.a; +}); + + +//// [es6ImportNameSpaceImportAmd_0.d.ts] +export declare var a: number; +//// [es6ImportNameSpaceImportAmd_1.d.ts] diff --git a/tests/baselines/reference/es6ImportNameSpaceImportAmd.types b/tests/baselines/reference/es6ImportNameSpaceImportAmd.types new file mode 100644 index 0000000000000..623a7e8e160df --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportAmd.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/es6ImportNameSpaceImportAmd_0.ts === + +export var a = 10; +>a : number + +=== tests/cases/compiler/es6ImportNameSpaceImportAmd_1.ts === +import * as nameSpaceBinding from "es6ImportNameSpaceImportAmd_0"; +>nameSpaceBinding : typeof nameSpaceBinding + +var x = nameSpaceBinding.a; +>x : number +>nameSpaceBinding.a : number +>nameSpaceBinding : typeof nameSpaceBinding +>a : number + +import * as nameSpaceBinding2 from "es6ImportNameSpaceImportAmd_0"; // elide this +>nameSpaceBinding2 : typeof nameSpaceBinding + diff --git a/tests/baselines/reference/es6ImportNameSpaceImportDts.js b/tests/baselines/reference/es6ImportNameSpaceImportDts.js new file mode 100644 index 0000000000000..91e927428a166 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportDts.js @@ -0,0 +1,30 @@ +//// [tests/cases/compiler/es6ImportNameSpaceImportDts.ts] //// + +//// [server.ts] + +export class c { }; + +//// [client.ts] +import * as nameSpaceBinding from "server"; +export var x = new nameSpaceBinding.c(); +import * as nameSpaceBinding2 from "server"; // unreferenced + +//// [server.js] +var c = (function () { + function c() { + } + return c; +})(); +exports.c = c; +; +//// [client.js] +var nameSpaceBinding = require("server"); +exports.x = new nameSpaceBinding.c(); + + +//// [server.d.ts] +export declare class c { +} +//// [client.d.ts] +import * as nameSpaceBinding from "server"; +export declare var x: nameSpaceBinding.c; diff --git a/tests/baselines/reference/es6ImportNameSpaceImportDts.types b/tests/baselines/reference/es6ImportNameSpaceImportDts.types new file mode 100644 index 0000000000000..345d593b1437b --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportDts.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/server.ts === + +export class c { }; +>c : c + +=== tests/cases/compiler/client.ts === +import * as nameSpaceBinding from "server"; +>nameSpaceBinding : typeof nameSpaceBinding + +export var x = new nameSpaceBinding.c(); +>x : nameSpaceBinding.c +>new nameSpaceBinding.c() : nameSpaceBinding.c +>nameSpaceBinding.c : typeof nameSpaceBinding.c +>nameSpaceBinding : typeof nameSpaceBinding +>c : typeof nameSpaceBinding.c + +import * as nameSpaceBinding2 from "server"; // unreferenced +>nameSpaceBinding2 : typeof nameSpaceBinding + diff --git a/tests/baselines/reference/es6ImportNameSpaceImportInEs5.js b/tests/baselines/reference/es6ImportNameSpaceImportInEs5.js index 2c7785dec6ed5..50a03972cc225 100644 --- a/tests/baselines/reference/es6ImportNameSpaceImportInEs5.js +++ b/tests/baselines/reference/es6ImportNameSpaceImportInEs5.js @@ -5,8 +5,18 @@ export var a = 10; //// [es6ImportNameSpaceImportInEs5_1.ts] -import * as nameSpaceBinding from "es6ImportNameSpaceImportInEs5_0"; +import * as nameSpaceBinding from "es6ImportNameSpaceImportInEs5_0"; +var x = nameSpaceBinding.a; +import * as nameSpaceBinding2 from "es6ImportNameSpaceImportInEs5_0"; // elide this + //// [es6ImportNameSpaceImportInEs5_0.js] exports.a = 10; //// [es6ImportNameSpaceImportInEs5_1.js] +var nameSpaceBinding = require("es6ImportNameSpaceImportInEs5_0"); +var x = nameSpaceBinding.a; + + +//// [es6ImportNameSpaceImportInEs5_0.d.ts] +export declare var a: number; +//// [es6ImportNameSpaceImportInEs5_1.d.ts] diff --git a/tests/baselines/reference/es6ImportNameSpaceImportInEs5.types b/tests/baselines/reference/es6ImportNameSpaceImportInEs5.types index cb7b669eea1c0..6ba725f2494ce 100644 --- a/tests/baselines/reference/es6ImportNameSpaceImportInEs5.types +++ b/tests/baselines/reference/es6ImportNameSpaceImportInEs5.types @@ -7,3 +7,12 @@ export var a = 10; import * as nameSpaceBinding from "es6ImportNameSpaceImportInEs5_0"; >nameSpaceBinding : typeof nameSpaceBinding +var x = nameSpaceBinding.a; +>x : number +>nameSpaceBinding.a : number +>nameSpaceBinding : typeof nameSpaceBinding +>a : number + +import * as nameSpaceBinding2 from "es6ImportNameSpaceImportInEs5_0"; // elide this +>nameSpaceBinding2 : typeof nameSpaceBinding + diff --git a/tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.errors.txt b/tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.errors.txt new file mode 100644 index 0000000000000..98a6887083390 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.errors.txt @@ -0,0 +1,25 @@ +tests/cases/compiler/es6ImportNameSpaceImportMergeErrors_1.ts(4,13): error TS2300: Duplicate identifier 'nameSpaceBinding1'. +tests/cases/compiler/es6ImportNameSpaceImportMergeErrors_1.ts(5,13): error TS2300: Duplicate identifier 'nameSpaceBinding1'. +tests/cases/compiler/es6ImportNameSpaceImportMergeErrors_1.ts(7,8): error TS2440: Import declaration conflicts with local declaration of 'nameSpaceBinding3' + + +==== tests/cases/compiler/es6ImportNameSpaceImportMergeErrors_0.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/es6ImportNameSpaceImportMergeErrors_1.ts (3 errors) ==== + import * as nameSpaceBinding from "es6ImportNameSpaceImportMergeErrors_0"; + interface nameSpaceBinding { } // this should be ok + + import * as nameSpaceBinding1 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error + ~~~~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'nameSpaceBinding1'. + import * as nameSpaceBinding1 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error + ~~~~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'nameSpaceBinding1'. + + import * as nameSpaceBinding3 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2440: Import declaration conflicts with local declaration of 'nameSpaceBinding3' + var nameSpaceBinding3 = 10; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.js b/tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.js new file mode 100644 index 0000000000000..3c8461fba2b70 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.js @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/es6ImportNameSpaceImportMergeErrors.ts] //// + +//// [es6ImportNameSpaceImportMergeErrors_0.ts] + +export var a = 10; + +//// [es6ImportNameSpaceImportMergeErrors_1.ts] +import * as nameSpaceBinding from "es6ImportNameSpaceImportMergeErrors_0"; +interface nameSpaceBinding { } // this should be ok + +import * as nameSpaceBinding1 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error +import * as nameSpaceBinding1 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error + +import * as nameSpaceBinding3 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error +var nameSpaceBinding3 = 10; + + +//// [es6ImportNameSpaceImportMergeErrors_0.js] +exports.a = 10; +//// [es6ImportNameSpaceImportMergeErrors_1.js] +var nameSpaceBinding3 = 10; diff --git a/tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.js b/tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.js new file mode 100644 index 0000000000000..3d6dab177851d --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.js @@ -0,0 +1,14 @@ +//// [tests/cases/compiler/es6ImportNameSpaceImportNoNamedExports.ts] //// + +//// [es6ImportNameSpaceImportNoNamedExports_0.ts] + +var a = 10; +export = a; + +//// [es6ImportNameSpaceImportNoNamedExports_1.ts] +import * as nameSpaceBinding from "es6ImportNameSpaceImportNoNamedExports_0"; // error + +//// [es6ImportNameSpaceImportNoNamedExports_0.js] +var a = 10; +module.exports = a; +//// [es6ImportNameSpaceImportNoNamedExports_1.js] diff --git a/tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.types b/tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.types new file mode 100644 index 0000000000000..e1f2e89bbd898 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.types @@ -0,0 +1,12 @@ +=== tests/cases/compiler/es6ImportNameSpaceImportNoNamedExports_0.ts === + +var a = 10; +>a : number + +export = a; +>a : number + +=== tests/cases/compiler/es6ImportNameSpaceImportNoNamedExports_1.ts === +import * as nameSpaceBinding from "es6ImportNameSpaceImportNoNamedExports_0"; // error +>nameSpaceBinding : number + diff --git a/tests/baselines/reference/es6ImportNameSpaceImportWithExport.errors.txt b/tests/baselines/reference/es6ImportNameSpaceImportWithExport.errors.txt new file mode 100644 index 0000000000000..901556e73bd73 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportWithExport.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/client.ts(1,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(3,1): error TS1191: An import declaration cannot have modifiers. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/client.ts (2 errors) ==== + export import * as nameSpaceBinding from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var x = nameSpaceBinding.a; + export import * as nameSpaceBinding2 from "server"; // Not referenced imports + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNameSpaceImportWithExport.js b/tests/baselines/reference/es6ImportNameSpaceImportWithExport.js new file mode 100644 index 0000000000000..84f6936d4b0f1 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportWithExport.js @@ -0,0 +1,26 @@ +//// [tests/cases/compiler/es6ImportNameSpaceImportWithExport.ts] //// + +//// [server.ts] + +export var a = 10; + +//// [client.ts] +export import * as nameSpaceBinding from "server"; +export var x = nameSpaceBinding.a; +export import * as nameSpaceBinding2 from "server"; // Not referenced imports + + +//// [server.js] +define(["require", "exports"], function (require, exports) { + exports.a = 10; +}); +//// [client.js] +define(["require", "exports", "server"], function (require, exports, nameSpaceBinding) { + exports.x = nameSpaceBinding.a; +}); + + +//// [server.d.ts] +export declare var a: number; +//// [client.d.ts] +export declare var x: number; diff --git a/tests/baselines/reference/es6ImportNamedImport.errors.txt b/tests/baselines/reference/es6ImportNamedImport.errors.txt new file mode 100644 index 0000000000000..5723b5c20d4f8 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImport.errors.txt @@ -0,0 +1,44 @@ +error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. + + +!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +==== tests/cases/compiler/es6ImportNamedImport_0.ts (0 errors) ==== + + export var a = 10; + export var x = a; + export var m = a; + export var a1 = 10; + export var x1 = 10; + export var z1 = 10; + export var z2 = 10; + export var aaaa = 10; + +==== tests/cases/compiler/es6ImportNamedImport_1.ts (0 errors) ==== + import { } from "es6ImportNamedImport_0"; + import { a } from "es6ImportNamedImport_0"; + var xxxx = a; + import { a as b } from "es6ImportNamedImport_0"; + var xxxx = b; + import { x, a as y } from "es6ImportNamedImport_0"; + var xxxx = x; + var xxxx = y; + import { x as z, } from "es6ImportNamedImport_0"; + var xxxx = z; + import { m, } from "es6ImportNamedImport_0"; + var xxxx = m; + import { a1, x1 } from "es6ImportNamedImport_0"; + var xxxx = a1; + var xxxx = x1; + import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; + var xxxx = a11; + var xxxx = x11; + import { z1 } from "es6ImportNamedImport_0"; + var z111 = z1; + import { z2 as z3 } from "es6ImportNamedImport_0"; + var z2 = z3; // z2 shouldn't give redeclare error + + // These are elided + import { aaaa } from "es6ImportNamedImport_0"; + // These are elided + import { aaaa as bbbb } from "es6ImportNamedImport_0"; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImport.js b/tests/baselines/reference/es6ImportNamedImport.js index c52499ef994a7..9606c59351b52 100644 --- a/tests/baselines/reference/es6ImportNamedImport.js +++ b/tests/baselines/reference/es6ImportNamedImport.js @@ -7,21 +7,80 @@ export var x = a; export var m = a; export var a1 = 10; export var x1 = 10; +export var z1 = 10; +export var z2 = 10; +export var aaaa = 10; //// [es6ImportNamedImport_1.ts] import { } from "es6ImportNamedImport_0"; import { a } from "es6ImportNamedImport_0"; +var xxxx = a; import { a as b } from "es6ImportNamedImport_0"; +var xxxx = b; import { x, a as y } from "es6ImportNamedImport_0"; +var xxxx = x; +var xxxx = y; import { x as z, } from "es6ImportNamedImport_0"; +var xxxx = z; import { m, } from "es6ImportNamedImport_0"; +var xxxx = m; import { a1, x1 } from "es6ImportNamedImport_0"; -import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; +var xxxx = a1; +var xxxx = x1; +import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; +var xxxx = a11; +var xxxx = x11; +import { z1 } from "es6ImportNamedImport_0"; +var z111 = z1; +import { z2 as z3 } from "es6ImportNamedImport_0"; +var z2 = z3; // z2 shouldn't give redeclare error + +// These are elided +import { aaaa } from "es6ImportNamedImport_0"; +// These are elided +import { aaaa as bbbb } from "es6ImportNamedImport_0"; + //// [es6ImportNamedImport_0.js] -exports.a = 10; -exports.x = exports.a; -exports.m = exports.a; -exports.a1 = 10; -exports.x1 = 10; +export var a = 10; +export var x = a; +export var m = a; +export var a1 = 10; +export var x1 = 10; +export var z1 = 10; +export var z2 = 10; +export var aaaa = 10; //// [es6ImportNamedImport_1.js] +import { a } from "es6ImportNamedImport_0"; +var xxxx = a; +import { a as b } from "es6ImportNamedImport_0"; +var xxxx = b; +import { x, a as y } from "es6ImportNamedImport_0"; +var xxxx = x; +var xxxx = y; +import { x as z } from "es6ImportNamedImport_0"; +var xxxx = z; +import { m } from "es6ImportNamedImport_0"; +var xxxx = m; +import { a1, x1 } from "es6ImportNamedImport_0"; +var xxxx = a1; +var xxxx = x1; +import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; +var xxxx = a11; +var xxxx = x11; +import { z1 } from "es6ImportNamedImport_0"; +var z111 = z1; +import { z2 as z3 } from "es6ImportNamedImport_0"; +var z2 = z3; // z2 shouldn't give redeclare error + + +//// [es6ImportNamedImport_0.d.ts] +export declare var a: number; +export declare var x: number; +export declare var m: number; +export declare var a1: number; +export declare var x1: number; +export declare var z1: number; +export declare var z2: number; +export declare var aaaa: number; +//// [es6ImportNamedImport_1.d.ts] diff --git a/tests/baselines/reference/es6ImportNamedImport.types b/tests/baselines/reference/es6ImportNamedImport.types deleted file mode 100644 index cb06c9918eab0..0000000000000 --- a/tests/baselines/reference/es6ImportNamedImport.types +++ /dev/null @@ -1,50 +0,0 @@ -=== tests/cases/compiler/es6ImportNamedImport_0.ts === - -export var a = 10; ->a : number - -export var x = a; ->x : number ->a : number - -export var m = a; ->m : number ->a : number - -export var a1 = 10; ->a1 : number - -export var x1 = 10; ->x1 : number - -=== tests/cases/compiler/es6ImportNamedImport_1.ts === -import { } from "es6ImportNamedImport_0"; -import { a } from "es6ImportNamedImport_0"; ->a : number - -import { a as b } from "es6ImportNamedImport_0"; ->a : number ->b : number - -import { x, a as y } from "es6ImportNamedImport_0"; ->x : number ->a : number ->y : number - -import { x as z, } from "es6ImportNamedImport_0"; ->x : number ->z : number - -import { m, } from "es6ImportNamedImport_0"; ->m : number - -import { a1, x1 } from "es6ImportNamedImport_0"; ->a1 : number ->x1 : number - -import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; ->a1 : number ->a11 : number ->x1 : number ->x11 : number - diff --git a/tests/baselines/reference/es6ImportNamedImportAmd.js b/tests/baselines/reference/es6ImportNamedImportAmd.js new file mode 100644 index 0000000000000..c335337325e51 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportAmd.js @@ -0,0 +1,81 @@ +//// [tests/cases/compiler/es6ImportNamedImportAmd.ts] //// + +//// [es6ImportNamedImportAmd_0.ts] + +export var a = 10; +export var x = a; +export var m = a; +export var a1 = 10; +export var x1 = 10; +export var z1 = 10; +export var z2 = 10; +export var aaaa = 10; + +//// [es6ImportNamedImportAmd_1.ts] +import { } from "es6ImportNamedImportAmd_0"; +import { a } from "es6ImportNamedImportAmd_0"; +var xxxx = a; +import { a as b } from "es6ImportNamedImportAmd_0"; +var xxxx = b; +import { x, a as y } from "es6ImportNamedImportAmd_0"; +var xxxx = x; +var xxxx = y; +import { x as z, } from "es6ImportNamedImportAmd_0"; +var xxxx = z; +import { m, } from "es6ImportNamedImportAmd_0"; +var xxxx = m; +import { a1, x1 } from "es6ImportNamedImportAmd_0"; +var xxxx = a1; +var xxxx = x1; +import { a1 as a11, x1 as x11 } from "es6ImportNamedImportAmd_0"; +var xxxx = a11; +var xxxx = x11; +import { z1 } from "es6ImportNamedImportAmd_0"; +var z111 = z1; +import { z2 as z3 } from "es6ImportNamedImportAmd_0"; +var z2 = z3; // z2 shouldn't give redeclare error + +// These are elided +import { aaaa } from "es6ImportNamedImportAmd_0"; +// These are elided +import { aaaa as bbbb } from "es6ImportNamedImportAmd_0"; + + +//// [es6ImportNamedImportAmd_0.js] +define(["require", "exports"], function (require, exports) { + exports.a = 10; + exports.x = exports.a; + exports.m = exports.a; + exports.a1 = 10; + exports.x1 = 10; + exports.z1 = 10; + exports.z2 = 10; + exports.aaaa = 10; +}); +//// [es6ImportNamedImportAmd_1.js] +define(["require", "exports", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0"], function (require, exports, es6ImportNamedImportAmd_0_1, es6ImportNamedImportAmd_0_2, es6ImportNamedImportAmd_0_3, es6ImportNamedImportAmd_0_4, es6ImportNamedImportAmd_0_5, es6ImportNamedImportAmd_0_6, es6ImportNamedImportAmd_0_7, es6ImportNamedImportAmd_0_8, es6ImportNamedImportAmd_0_9) { + var xxxx = es6ImportNamedImportAmd_0_1.a; + var xxxx = es6ImportNamedImportAmd_0_2.a; + var xxxx = es6ImportNamedImportAmd_0_3.x; + var xxxx = es6ImportNamedImportAmd_0_3.a; + var xxxx = es6ImportNamedImportAmd_0_4.x; + var xxxx = es6ImportNamedImportAmd_0_5.m; + var xxxx = es6ImportNamedImportAmd_0_6.a1; + var xxxx = es6ImportNamedImportAmd_0_6.x1; + var xxxx = es6ImportNamedImportAmd_0_7.a1; + var xxxx = es6ImportNamedImportAmd_0_7.x1; + var z111 = es6ImportNamedImportAmd_0_8.z1; + var z2 = es6ImportNamedImportAmd_0_9.z2; // z2 shouldn't give redeclare error +}); + + +//// [es6ImportNamedImportAmd_0.d.ts] +export declare var a: number; +export declare var x: number; +export declare var m: number; +export declare var a1: number; +export declare var x1: number; +export declare var z1: number; +export declare var z2: number; +export declare var aaaa: number; +//// [es6ImportNamedImportAmd_1.d.ts] diff --git a/tests/baselines/reference/es6ImportNamedImportAmd.types b/tests/baselines/reference/es6ImportNamedImportAmd.types new file mode 100644 index 0000000000000..4a0abe853e025 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportAmd.types @@ -0,0 +1,123 @@ +=== tests/cases/compiler/es6ImportNamedImportAmd_0.ts === + +export var a = 10; +>a : number + +export var x = a; +>x : number +>a : number + +export var m = a; +>m : number +>a : number + +export var a1 = 10; +>a1 : number + +export var x1 = 10; +>x1 : number + +export var z1 = 10; +>z1 : number + +export var z2 = 10; +>z2 : number + +export var aaaa = 10; +>aaaa : number + +=== tests/cases/compiler/es6ImportNamedImportAmd_1.ts === +import { } from "es6ImportNamedImportAmd_0"; +import { a } from "es6ImportNamedImportAmd_0"; +>a : number + +var xxxx = a; +>xxxx : number +>a : number + +import { a as b } from "es6ImportNamedImportAmd_0"; +>a : number +>b : number + +var xxxx = b; +>xxxx : number +>b : number + +import { x, a as y } from "es6ImportNamedImportAmd_0"; +>x : number +>a : number +>y : number + +var xxxx = x; +>xxxx : number +>x : number + +var xxxx = y; +>xxxx : number +>y : number + +import { x as z, } from "es6ImportNamedImportAmd_0"; +>x : number +>z : number + +var xxxx = z; +>xxxx : number +>z : number + +import { m, } from "es6ImportNamedImportAmd_0"; +>m : number + +var xxxx = m; +>xxxx : number +>m : number + +import { a1, x1 } from "es6ImportNamedImportAmd_0"; +>a1 : number +>x1 : number + +var xxxx = a1; +>xxxx : number +>a1 : number + +var xxxx = x1; +>xxxx : number +>x1 : number + +import { a1 as a11, x1 as x11 } from "es6ImportNamedImportAmd_0"; +>a1 : number +>a11 : number +>x1 : number +>x11 : number + +var xxxx = a11; +>xxxx : number +>a11 : number + +var xxxx = x11; +>xxxx : number +>x11 : number + +import { z1 } from "es6ImportNamedImportAmd_0"; +>z1 : number + +var z111 = z1; +>z111 : number +>z1 : number + +import { z2 as z3 } from "es6ImportNamedImportAmd_0"; +>z2 : number +>z3 : number + +var z2 = z3; // z2 shouldn't give redeclare error +>z2 : number +>z3 : number + +// These are elided +import { aaaa } from "es6ImportNamedImportAmd_0"; +>aaaa : number + +// These are elided +import { aaaa as bbbb } from "es6ImportNamedImportAmd_0"; +>aaaa : number +>bbbb : number + diff --git a/tests/baselines/reference/es6ImportNamedImportDts.js b/tests/baselines/reference/es6ImportNamedImportDts.js new file mode 100644 index 0000000000000..a72632a737e7a --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportDts.js @@ -0,0 +1,208 @@ +//// [tests/cases/compiler/es6ImportNamedImportDts.ts] //// + +//// [server.ts] + +export class a { } +export class a11 { } +export class a12 { } +export class x { } +export class x11 { } +export class m { } +export class a1 { } +export class x1 { } +export class a111 { } +export class x111 { } +export class z1 { } +export class z2 { } +export class aaaa { } +export class aaaa1 { } + +//// [client.ts] +import { } from "server"; +import { a } from "server"; +export var xxxx = new a(); +import { a11 as b } from "server"; +export var xxxx1 = new b(); +import { x, a12 as y } from "server"; +export var xxxx2 = new x(); +export var xxxx3 = new y(); +import { x11 as z, } from "server"; +export var xxxx4 = new z(); +import { m, } from "server"; +export var xxxx5 = new m(); +import { a1, x1 } from "server"; +export var xxxx6 = new a1(); +export var xxxx7 = new x1(); +import { a111 as a11, x111 as x11 } from "server"; +export var xxxx8 = new a11(); +export var xxxx9 = new x11(); +import { z1 } from "server"; +export var z111 = new z1(); +import { z2 as z3 } from "server"; +export var z2 = new z3(); // z2 shouldn't give redeclare error + +// not referenced +import { aaaa } from "server"; +import { aaaa1 as bbbb } from "server"; + + +//// [server.js] +var a = (function () { + function a() { + } + return a; +})(); +exports.a = a; +var a11 = (function () { + function a11() { + } + return a11; +})(); +exports.a11 = a11; +var a12 = (function () { + function a12() { + } + return a12; +})(); +exports.a12 = a12; +var x = (function () { + function x() { + } + return x; +})(); +exports.x = x; +var x11 = (function () { + function x11() { + } + return x11; +})(); +exports.x11 = x11; +var m = (function () { + function m() { + } + return m; +})(); +exports.m = m; +var a1 = (function () { + function a1() { + } + return a1; +})(); +exports.a1 = a1; +var x1 = (function () { + function x1() { + } + return x1; +})(); +exports.x1 = x1; +var a111 = (function () { + function a111() { + } + return a111; +})(); +exports.a111 = a111; +var x111 = (function () { + function x111() { + } + return x111; +})(); +exports.x111 = x111; +var z1 = (function () { + function z1() { + } + return z1; +})(); +exports.z1 = z1; +var z2 = (function () { + function z2() { + } + return z2; +})(); +exports.z2 = z2; +var aaaa = (function () { + function aaaa() { + } + return aaaa; +})(); +exports.aaaa = aaaa; +var aaaa1 = (function () { + function aaaa1() { + } + return aaaa1; +})(); +exports.aaaa1 = aaaa1; +//// [client.js] +var server_1 = require("server"); +exports.xxxx = new server_1.a(); +var server_2 = require("server"); +exports.xxxx1 = new server_2.a11(); +var server_3 = require("server"); +exports.xxxx2 = new server_3.x(); +exports.xxxx3 = new server_3.a12(); +var server_4 = require("server"); +exports.xxxx4 = new server_4.x11(); +var server_5 = require("server"); +exports.xxxx5 = new server_5.m(); +var server_6 = require("server"); +exports.xxxx6 = new server_6.a1(); +exports.xxxx7 = new server_6.x1(); +var server_7 = require("server"); +exports.xxxx8 = new server_7.a111(); +exports.xxxx9 = new server_7.x111(); +var server_8 = require("server"); +exports.z111 = new server_8.z1(); +var server_9 = require("server"); +exports.z2 = new server_9.z2(); // z2 shouldn't give redeclare error + + +//// [server.d.ts] +export declare class a { +} +export declare class a11 { +} +export declare class a12 { +} +export declare class x { +} +export declare class x11 { +} +export declare class m { +} +export declare class a1 { +} +export declare class x1 { +} +export declare class a111 { +} +export declare class x111 { +} +export declare class z1 { +} +export declare class z2 { +} +export declare class aaaa { +} +export declare class aaaa1 { +} +//// [client.d.ts] +import { a } from "server"; +export declare var xxxx: a; +import { a11 as b } from "server"; +export declare var xxxx1: b; +import { x, a12 as y } from "server"; +export declare var xxxx2: x; +export declare var xxxx3: y; +import { x11 as z } from "server"; +export declare var xxxx4: z; +import { m } from "server"; +export declare var xxxx5: m; +import { a1, x1 } from "server"; +export declare var xxxx6: a1; +export declare var xxxx7: x1; +import { a111 as a11, x111 as x11 } from "server"; +export declare var xxxx8: a11; +export declare var xxxx9: x11; +import { z1 } from "server"; +export declare var z111: z1; +import { z2 as z3 } from "server"; +export declare var z2: z3; diff --git a/tests/baselines/reference/es6ImportNamedImportDts.types b/tests/baselines/reference/es6ImportNamedImportDts.types new file mode 100644 index 0000000000000..93bd55716a514 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportDts.types @@ -0,0 +1,150 @@ +=== tests/cases/compiler/server.ts === + +export class a { } +>a : a + +export class a11 { } +>a11 : a11 + +export class a12 { } +>a12 : a12 + +export class x { } +>x : x + +export class x11 { } +>x11 : x11 + +export class m { } +>m : m + +export class a1 { } +>a1 : a1 + +export class x1 { } +>x1 : x1 + +export class a111 { } +>a111 : a111 + +export class x111 { } +>x111 : x111 + +export class z1 { } +>z1 : z1 + +export class z2 { } +>z2 : z2 + +export class aaaa { } +>aaaa : aaaa + +export class aaaa1 { } +>aaaa1 : aaaa1 + +=== tests/cases/compiler/client.ts === +import { } from "server"; +import { a } from "server"; +>a : typeof a + +export var xxxx = new a(); +>xxxx : a +>new a() : a +>a : typeof a + +import { a11 as b } from "server"; +>a11 : typeof b +>b : typeof b + +export var xxxx1 = new b(); +>xxxx1 : b +>new b() : b +>b : typeof b + +import { x, a12 as y } from "server"; +>x : typeof x +>a12 : typeof y +>y : typeof y + +export var xxxx2 = new x(); +>xxxx2 : x +>new x() : x +>x : typeof x + +export var xxxx3 = new y(); +>xxxx3 : y +>new y() : y +>y : typeof y + +import { x11 as z, } from "server"; +>x11 : typeof z +>z : typeof z + +export var xxxx4 = new z(); +>xxxx4 : z +>new z() : z +>z : typeof z + +import { m, } from "server"; +>m : typeof m + +export var xxxx5 = new m(); +>xxxx5 : m +>new m() : m +>m : typeof m + +import { a1, x1 } from "server"; +>a1 : typeof a1 +>x1 : typeof x1 + +export var xxxx6 = new a1(); +>xxxx6 : a1 +>new a1() : a1 +>a1 : typeof a1 + +export var xxxx7 = new x1(); +>xxxx7 : x1 +>new x1() : x1 +>x1 : typeof x1 + +import { a111 as a11, x111 as x11 } from "server"; +>a111 : typeof a11 +>a11 : typeof a11 +>x111 : typeof x11 +>x11 : typeof x11 + +export var xxxx8 = new a11(); +>xxxx8 : a11 +>new a11() : a11 +>a11 : typeof a11 + +export var xxxx9 = new x11(); +>xxxx9 : x11 +>new x11() : x11 +>x11 : typeof x11 + +import { z1 } from "server"; +>z1 : typeof z1 + +export var z111 = new z1(); +>z111 : z1 +>new z1() : z1 +>z1 : typeof z1 + +import { z2 as z3 } from "server"; +>z2 : typeof z3 +>z3 : typeof z3 + +export var z2 = new z3(); // z2 shouldn't give redeclare error +>z2 : z3 +>new z3() : z3 +>z3 : typeof z3 + +// not referenced +import { aaaa } from "server"; +>aaaa : typeof aaaa + +import { aaaa1 as bbbb } from "server"; +>aaaa1 : typeof bbbb +>bbbb : typeof bbbb + diff --git a/tests/baselines/reference/es6ImportNamedImportInEs5.js b/tests/baselines/reference/es6ImportNamedImportInEs5.js index 66f8ce0ef9268..9992508c00be5 100644 --- a/tests/baselines/reference/es6ImportNamedImportInEs5.js +++ b/tests/baselines/reference/es6ImportNamedImportInEs5.js @@ -7,16 +7,39 @@ export var x = a; export var m = a; export var a1 = 10; export var x1 = 10; +export var z1 = 10; +export var z2 = 10; +export var aaaa = 10; //// [es6ImportNamedImportInEs5_1.ts] import { } from "es6ImportNamedImportInEs5_0"; import { a } from "es6ImportNamedImportInEs5_0"; +var xxxx = a; import { a as b } from "es6ImportNamedImportInEs5_0"; +var xxxx = b; import { x, a as y } from "es6ImportNamedImportInEs5_0"; +var xxxx = x; +var xxxx = y; import { x as z, } from "es6ImportNamedImportInEs5_0"; +var xxxx = z; import { m, } from "es6ImportNamedImportInEs5_0"; +var xxxx = m; import { a1, x1 } from "es6ImportNamedImportInEs5_0"; -import { a1 as a11, x1 as x11 } from "es6ImportNamedImportInEs5_0"; +var xxxx = a1; +var xxxx = x1; +import { a1 as a11, x1 as x11 } from "es6ImportNamedImportInEs5_0"; +var xxxx = a11; +var xxxx = x11; +import { z1 } from "es6ImportNamedImportInEs5_0"; +var z111 = z1; +import { z2 as z3 } from "es6ImportNamedImportInEs5_0"; +var z2 = z3; // z2 shouldn't give redeclare error + +// These are elided +import { aaaa } from "es6ImportNamedImportInEs5_0"; +// These are elided +import { aaaa as bbbb } from "es6ImportNamedImportInEs5_0"; + //// [es6ImportNamedImportInEs5_0.js] exports.a = 10; @@ -24,4 +47,40 @@ exports.x = exports.a; exports.m = exports.a; exports.a1 = 10; exports.x1 = 10; +exports.z1 = 10; +exports.z2 = 10; +exports.aaaa = 10; //// [es6ImportNamedImportInEs5_1.js] +var es6ImportNamedImportInEs5_0_1 = require("es6ImportNamedImportInEs5_0"); +var xxxx = es6ImportNamedImportInEs5_0_1.a; +var es6ImportNamedImportInEs5_0_2 = require("es6ImportNamedImportInEs5_0"); +var xxxx = es6ImportNamedImportInEs5_0_2.a; +var es6ImportNamedImportInEs5_0_3 = require("es6ImportNamedImportInEs5_0"); +var xxxx = es6ImportNamedImportInEs5_0_3.x; +var xxxx = es6ImportNamedImportInEs5_0_3.a; +var es6ImportNamedImportInEs5_0_4 = require("es6ImportNamedImportInEs5_0"); +var xxxx = es6ImportNamedImportInEs5_0_4.x; +var es6ImportNamedImportInEs5_0_5 = require("es6ImportNamedImportInEs5_0"); +var xxxx = es6ImportNamedImportInEs5_0_5.m; +var es6ImportNamedImportInEs5_0_6 = require("es6ImportNamedImportInEs5_0"); +var xxxx = es6ImportNamedImportInEs5_0_6.a1; +var xxxx = es6ImportNamedImportInEs5_0_6.x1; +var es6ImportNamedImportInEs5_0_7 = require("es6ImportNamedImportInEs5_0"); +var xxxx = es6ImportNamedImportInEs5_0_7.a1; +var xxxx = es6ImportNamedImportInEs5_0_7.x1; +var es6ImportNamedImportInEs5_0_8 = require("es6ImportNamedImportInEs5_0"); +var z111 = es6ImportNamedImportInEs5_0_8.z1; +var es6ImportNamedImportInEs5_0_9 = require("es6ImportNamedImportInEs5_0"); +var z2 = es6ImportNamedImportInEs5_0_9.z2; // z2 shouldn't give redeclare error + + +//// [es6ImportNamedImportInEs5_0.d.ts] +export declare var a: number; +export declare var x: number; +export declare var m: number; +export declare var a1: number; +export declare var x1: number; +export declare var z1: number; +export declare var z2: number; +export declare var aaaa: number; +//// [es6ImportNamedImportInEs5_1.d.ts] diff --git a/tests/baselines/reference/es6ImportNamedImportInEs5.types b/tests/baselines/reference/es6ImportNamedImportInEs5.types index 334ae905e952e..f60644b262103 100644 --- a/tests/baselines/reference/es6ImportNamedImportInEs5.types +++ b/tests/baselines/reference/es6ImportNamedImportInEs5.types @@ -17,34 +17,107 @@ export var a1 = 10; export var x1 = 10; >x1 : number +export var z1 = 10; +>z1 : number + +export var z2 = 10; +>z2 : number + +export var aaaa = 10; +>aaaa : number + === tests/cases/compiler/es6ImportNamedImportInEs5_1.ts === import { } from "es6ImportNamedImportInEs5_0"; import { a } from "es6ImportNamedImportInEs5_0"; >a : number +var xxxx = a; +>xxxx : number +>a : number + import { a as b } from "es6ImportNamedImportInEs5_0"; >a : number >b : number +var xxxx = b; +>xxxx : number +>b : number + import { x, a as y } from "es6ImportNamedImportInEs5_0"; >x : number >a : number >y : number +var xxxx = x; +>xxxx : number +>x : number + +var xxxx = y; +>xxxx : number +>y : number + import { x as z, } from "es6ImportNamedImportInEs5_0"; >x : number >z : number +var xxxx = z; +>xxxx : number +>z : number + import { m, } from "es6ImportNamedImportInEs5_0"; >m : number +var xxxx = m; +>xxxx : number +>m : number + import { a1, x1 } from "es6ImportNamedImportInEs5_0"; >a1 : number >x1 : number +var xxxx = a1; +>xxxx : number +>a1 : number + +var xxxx = x1; +>xxxx : number +>x1 : number + import { a1 as a11, x1 as x11 } from "es6ImportNamedImportInEs5_0"; >a1 : number >a11 : number >x1 : number >x11 : number +var xxxx = a11; +>xxxx : number +>a11 : number + +var xxxx = x11; +>xxxx : number +>x11 : number + +import { z1 } from "es6ImportNamedImportInEs5_0"; +>z1 : number + +var z111 = z1; +>z111 : number +>z1 : number + +import { z2 as z3 } from "es6ImportNamedImportInEs5_0"; +>z2 : number +>z3 : number + +var z2 = z3; // z2 shouldn't give redeclare error +>z2 : number +>z3 : number + +// These are elided +import { aaaa } from "es6ImportNamedImportInEs5_0"; +>aaaa : number + +// These are elided +import { aaaa as bbbb } from "es6ImportNamedImportInEs5_0"; +>aaaa : number +>bbbb : number + diff --git a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt new file mode 100644 index 0000000000000..41d3f160938eb --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt @@ -0,0 +1,14 @@ +error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +tests/cases/compiler/es6ImportNamedImportInExportAssignment_1.ts(2,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. + + +!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +==== tests/cases/compiler/es6ImportNamedImportInExportAssignment_0.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/es6ImportNamedImportInExportAssignment_1.ts (1 errors) ==== + import { a } from "es6ImportNamedImportInExportAssignment_0"; + export = a; + ~~~~~~~~~~~ +!!! error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js new file mode 100644 index 0000000000000..eab345e4e7f30 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts] //// + +//// [es6ImportNamedImportInExportAssignment_0.ts] + +export var a = 10; + +//// [es6ImportNamedImportInExportAssignment_1.ts] +import { a } from "es6ImportNamedImportInExportAssignment_0"; +export = a; + +//// [es6ImportNamedImportInExportAssignment_0.js] +export var a = 10; +//// [es6ImportNamedImportInExportAssignment_1.js] +import { a } from "es6ImportNamedImportInExportAssignment_0"; + + +//// [es6ImportNamedImportInExportAssignment_0.d.ts] +export declare var a: number; +//// [es6ImportNamedImportInExportAssignment_1.d.ts] +import { a } from "es6ImportNamedImportInExportAssignment_0"; +export = a; diff --git a/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js new file mode 100644 index 0000000000000..f457e31f53c82 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js @@ -0,0 +1,39 @@ +//// [tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment.ts] //// + +//// [es6ImportNamedImportInIndirectExportAssignment_0.ts] + +export module a { + export class c { + } +} + +//// [es6ImportNamedImportInIndirectExportAssignment_1.ts] +import { a } from "es6ImportNamedImportInIndirectExportAssignment_0"; +import x = a; +export = x; + +//// [es6ImportNamedImportInIndirectExportAssignment_0.js] +var a; +(function (a) { + var c = (function () { + function c() { + } + return c; + })(); + a.c = c; +})(a = exports.a || (exports.a = {})); +//// [es6ImportNamedImportInIndirectExportAssignment_1.js] +var es6ImportNamedImportInIndirectExportAssignment_0_1 = require("es6ImportNamedImportInIndirectExportAssignment_0"); +var x = es6ImportNamedImportInIndirectExportAssignment_0_1.a; +module.exports = x; + + +//// [es6ImportNamedImportInIndirectExportAssignment_0.d.ts] +export declare module a { + class c { + } +} +//// [es6ImportNamedImportInIndirectExportAssignment_1.d.ts] +import { a } from "es6ImportNamedImportInIndirectExportAssignment_0"; +import x = a; +export = x; diff --git a/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.types b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.types new file mode 100644 index 0000000000000..36792ece82e45 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.types @@ -0,0 +1,21 @@ +=== tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment_0.ts === + +export module a { +>a : typeof a + + export class c { +>c : c + } +} + +=== tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment_1.ts === +import { a } from "es6ImportNamedImportInIndirectExportAssignment_0"; +>a : typeof a + +import x = a; +>x : typeof a +>a : typeof a + +export = x; +>x : typeof a + diff --git a/tests/baselines/reference/es6ImportNamedImportMergeErrors.errors.txt b/tests/baselines/reference/es6ImportNamedImportMergeErrors.errors.txt new file mode 100644 index 0000000000000..b9461b6caca06 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportMergeErrors.errors.txt @@ -0,0 +1,33 @@ +tests/cases/compiler/es6ImportNamedImportMergeErrors_1.ts(5,10): error TS2440: Import declaration conflicts with local declaration of 'x' +tests/cases/compiler/es6ImportNamedImportMergeErrors_1.ts(7,10): error TS2440: Import declaration conflicts with local declaration of 'x44' +tests/cases/compiler/es6ImportNamedImportMergeErrors_1.ts(9,10): error TS2300: Duplicate identifier 'z'. +tests/cases/compiler/es6ImportNamedImportMergeErrors_1.ts(10,16): error TS2300: Duplicate identifier 'z'. + + +==== tests/cases/compiler/es6ImportNamedImportMergeErrors_0.ts (0 errors) ==== + + export var a = 10; + export var x = a; + export var z = a; + export var z1 = a; + +==== tests/cases/compiler/es6ImportNamedImportMergeErrors_1.ts (4 errors) ==== + import { a } from "es6ImportNamedImportMergeErrors_0"; + interface a { } // shouldnt be error + import { x as x1 } from "es6ImportNamedImportMergeErrors_0"; + interface x1 { } // shouldnt be error + import { x } from "es6ImportNamedImportMergeErrors_0"; // should be error + ~ +!!! error TS2440: Import declaration conflicts with local declaration of 'x' + var x = 10; + import { x as x44 } from "es6ImportNamedImportMergeErrors_0"; // should be error + ~~~~~~~~ +!!! error TS2440: Import declaration conflicts with local declaration of 'x44' + var x44 = 10; + import { z } from "es6ImportNamedImportMergeErrors_0"; // should be error + ~ +!!! error TS2300: Duplicate identifier 'z'. + import { z1 as z } from "es6ImportNamedImportMergeErrors_0"; // should be error + ~ +!!! error TS2300: Duplicate identifier 'z'. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportMergeErrors.js b/tests/baselines/reference/es6ImportNamedImportMergeErrors.js new file mode 100644 index 0000000000000..fad411f557d55 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportMergeErrors.js @@ -0,0 +1,30 @@ +//// [tests/cases/compiler/es6ImportNamedImportMergeErrors.ts] //// + +//// [es6ImportNamedImportMergeErrors_0.ts] + +export var a = 10; +export var x = a; +export var z = a; +export var z1 = a; + +//// [es6ImportNamedImportMergeErrors_1.ts] +import { a } from "es6ImportNamedImportMergeErrors_0"; +interface a { } // shouldnt be error +import { x as x1 } from "es6ImportNamedImportMergeErrors_0"; +interface x1 { } // shouldnt be error +import { x } from "es6ImportNamedImportMergeErrors_0"; // should be error +var x = 10; +import { x as x44 } from "es6ImportNamedImportMergeErrors_0"; // should be error +var x44 = 10; +import { z } from "es6ImportNamedImportMergeErrors_0"; // should be error +import { z1 as z } from "es6ImportNamedImportMergeErrors_0"; // should be error + + +//// [es6ImportNamedImportMergeErrors_0.js] +exports.a = 10; +exports.x = exports.a; +exports.z = exports.a; +exports.z1 = exports.a; +//// [es6ImportNamedImportMergeErrors_1.js] +var x = 10; +var x44 = 10; diff --git a/tests/baselines/reference/es6ImportNamedImportNoExportMember.errors.txt b/tests/baselines/reference/es6ImportNamedImportNoExportMember.errors.txt new file mode 100644 index 0000000000000..57a77410cb24b --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportNoExportMember.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/es6ImportNamedImport_1.ts(1,10): error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoExportMember_0"' has no exported member 'a1'. +tests/cases/compiler/es6ImportNamedImport_1.ts(2,10): error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoExportMember_0"' has no exported member 'x1'. + + +==== tests/cases/compiler/es6ImportNamedImportNoExportMember_0.ts (0 errors) ==== + + export var a = 10; + export var x = a; + +==== tests/cases/compiler/es6ImportNamedImport_1.ts (2 errors) ==== + import { a1 } from "es6ImportNamedImportNoExportMember_0"; + ~~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoExportMember_0"' has no exported member 'a1'. + import { x1 as x } from "es6ImportNamedImportNoExportMember_0"; + ~~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoExportMember_0"' has no exported member 'x1'. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportNoExportMember.js b/tests/baselines/reference/es6ImportNamedImportNoExportMember.js new file mode 100644 index 0000000000000..da473fa42a38d --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportNoExportMember.js @@ -0,0 +1,15 @@ +//// [tests/cases/compiler/es6ImportNamedImportNoExportMember.ts] //// + +//// [es6ImportNamedImportNoExportMember_0.ts] + +export var a = 10; +export var x = a; + +//// [es6ImportNamedImport_1.ts] +import { a1 } from "es6ImportNamedImportNoExportMember_0"; +import { x1 as x } from "es6ImportNamedImportNoExportMember_0"; + +//// [es6ImportNamedImportNoExportMember_0.js] +exports.a = 10; +exports.x = exports.a; +//// [es6ImportNamedImport_1.js] diff --git a/tests/baselines/reference/es6ImportNamedImportNoNamedExports.errors.txt b/tests/baselines/reference/es6ImportNamedImportNoNamedExports.errors.txt new file mode 100644 index 0000000000000..a5abd986ee857 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportNoNamedExports.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/es6ImportNamedImportNoNamedExports_1.ts(1,10): error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoNamedExports_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportNamedImportNoNamedExports_1.ts(2,10): error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoNamedExports_0"' has no exported member 'a'. + + +==== tests/cases/compiler/es6ImportNamedImportNoNamedExports_0.ts (0 errors) ==== + + var a = 10; + export = a; + +==== tests/cases/compiler/es6ImportNamedImportNoNamedExports_1.ts (2 errors) ==== + import { a } from "es6ImportNamedImportNoNamedExports_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoNamedExports_0"' has no exported member 'a'. + import { a as x } from "es6ImportNamedImportNoNamedExports_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoNamedExports_0"' has no exported member 'a'. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportNoNamedExports.js b/tests/baselines/reference/es6ImportNamedImportNoNamedExports.js new file mode 100644 index 0000000000000..524860827e6e8 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportNoNamedExports.js @@ -0,0 +1,15 @@ +//// [tests/cases/compiler/es6ImportNamedImportNoNamedExports.ts] //// + +//// [es6ImportNamedImportNoNamedExports_0.ts] + +var a = 10; +export = a; + +//// [es6ImportNamedImportNoNamedExports_1.ts] +import { a } from "es6ImportNamedImportNoNamedExports_0"; +import { a as x } from "es6ImportNamedImportNoNamedExports_0"; + +//// [es6ImportNamedImportNoNamedExports_0.js] +var a = 10; +module.exports = a; +//// [es6ImportNamedImportNoNamedExports_1.js] diff --git a/tests/baselines/reference/es6ImportNamedImportParsingError.js b/tests/baselines/reference/es6ImportNamedImportParsingError.js index f9d8e90f707f1..81f141b3dd858 100644 --- a/tests/baselines/reference/es6ImportNamedImportParsingError.js +++ b/tests/baselines/reference/es6ImportNamedImportParsingError.js @@ -13,16 +13,16 @@ import , { a } from "es6ImportNamedImportParsingError_0"; import { a }, from "es6ImportNamedImportParsingError_0"; //// [es6ImportNamedImportParsingError_0.js] -exports.a = 10; -exports.x = exports.a; -exports.m = exports.a; +export var a = 10; +export var x = a; +export var m = a; //// [es6ImportNamedImportParsingError_1.js] from; "es6ImportNamedImportParsingError_0"; { - _module_1.a; + a; } from; "es6ImportNamedImportParsingError_0"; -var _module_1 = require(); +import { a } from , from; "es6ImportNamedImportParsingError_0"; diff --git a/tests/baselines/reference/es6ImportNamedImportWithExport.errors.txt b/tests/baselines/reference/es6ImportNamedImportWithExport.errors.txt new file mode 100644 index 0000000000000..ff8fe604622ea --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportWithExport.errors.txt @@ -0,0 +1,77 @@ +tests/cases/compiler/client.ts(1,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(2,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(4,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(6,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(9,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(11,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(13,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(16,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(19,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(21,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(25,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(26,1): error TS1191: An import declaration cannot have modifiers. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + export var a = 10; + export var x = a; + export var m = a; + export var a1 = 10; + export var x1 = 10; + export var z1 = 10; + export var z2 = 10; + export var aaaa = 10; + +==== tests/cases/compiler/client.ts (12 errors) ==== + export import { } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export import { a } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var xxxx = a; + export import { a as b } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var xxxx = b; + export import { x, a as y } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var xxxx = x; + export var xxxx = y; + export import { x as z, } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var xxxx = z; + export import { m, } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var xxxx = m; + export import { a1, x1 } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var xxxx = a1; + export var xxxx = x1; + export import { a1 as a11, x1 as x11 } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var xxxx = a11; + export var xxxx = x11; + export import { z1 } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var z111 = z1; + export import { z2 as z3 } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var z2 = z3; // z2 shouldn't give redeclare error + + // Non referenced imports + export import { aaaa } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export import { aaaa as bbbb } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportWithExport.js b/tests/baselines/reference/es6ImportNamedImportWithExport.js new file mode 100644 index 0000000000000..60ba6bf706be4 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportWithExport.js @@ -0,0 +1,97 @@ +//// [tests/cases/compiler/es6ImportNamedImportWithExport.ts] //// + +//// [server.ts] + +export var a = 10; +export var x = a; +export var m = a; +export var a1 = 10; +export var x1 = 10; +export var z1 = 10; +export var z2 = 10; +export var aaaa = 10; + +//// [client.ts] +export import { } from "server"; +export import { a } from "server"; +export var xxxx = a; +export import { a as b } from "server"; +export var xxxx = b; +export import { x, a as y } from "server"; +export var xxxx = x; +export var xxxx = y; +export import { x as z, } from "server"; +export var xxxx = z; +export import { m, } from "server"; +export var xxxx = m; +export import { a1, x1 } from "server"; +export var xxxx = a1; +export var xxxx = x1; +export import { a1 as a11, x1 as x11 } from "server"; +export var xxxx = a11; +export var xxxx = x11; +export import { z1 } from "server"; +export var z111 = z1; +export import { z2 as z3 } from "server"; +export var z2 = z3; // z2 shouldn't give redeclare error + +// Non referenced imports +export import { aaaa } from "server"; +export import { aaaa as bbbb } from "server"; + + +//// [server.js] +exports.a = 10; +exports.x = exports.a; +exports.m = exports.a; +exports.a1 = 10; +exports.x1 = 10; +exports.z1 = 10; +exports.z2 = 10; +exports.aaaa = 10; +//// [client.js] +var server_1 = require("server"); +exports.xxxx = server_1.a; +var server_2 = require("server"); +exports.xxxx = server_2.a; +var server_3 = require("server"); +exports.xxxx = server_3.x; +exports.xxxx = server_3.a; +var server_4 = require("server"); +exports.xxxx = server_4.x; +var server_5 = require("server"); +exports.xxxx = server_5.m; +var server_6 = require("server"); +exports.xxxx = server_6.a1; +exports.xxxx = server_6.x1; +var server_7 = require("server"); +exports.xxxx = server_7.a1; +exports.xxxx = server_7.x1; +var server_8 = require("server"); +exports.z111 = server_8.z1; +var server_9 = require("server"); +exports.z2 = server_9.z2; // z2 shouldn't give redeclare error + + +//// [server.d.ts] +export declare var a: number; +export declare var x: number; +export declare var m: number; +export declare var a1: number; +export declare var x1: number; +export declare var z1: number; +export declare var z2: number; +export declare var aaaa: number; +//// [client.d.ts] +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var z111: number; +export declare var z2: number; diff --git a/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.js b/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.js new file mode 100644 index 0000000000000..dcf99c5359a81 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.js @@ -0,0 +1,59 @@ +//// [tests/cases/compiler/es6ImportNamedImportWithTypesAndValues.ts] //// + +//// [server.ts] + +export interface I { + prop: string; +} +export interface I2 { + prop2: string; +} +export class C implements I { + prop = "hello"; +} +export class C2 implements I2 { + prop2 = "world"; +} + +//// [client.ts] +import { C, I, C2 } from "server"; // Shouldnt emit I and C2 into the js file and emit C and I in .d.ts file +export type cValInterface = I; +export var cVal = new C(); + +//// [server.js] +var C = (function () { + function C() { + this.prop = "hello"; + } + return C; +})(); +exports.C = C; +var C2 = (function () { + function C2() { + this.prop2 = "world"; + } + return C2; +})(); +exports.C2 = C2; +//// [client.js] +var server_1 = require("server"); // Shouldnt emit I and C2 into the js file and emit C and I in .d.ts file +exports.cVal = new server_1.C(); + + +//// [server.d.ts] +export interface I { + prop: string; +} +export interface I2 { + prop2: string; +} +export declare class C implements I { + prop: string; +} +export declare class C2 implements I2 { + prop2: string; +} +//// [client.d.ts] +import { C, I } from "server"; +export declare type cValInterface = I; +export declare var cVal: C; diff --git a/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.types b/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.types new file mode 100644 index 0000000000000..62917e5ff36b5 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.types @@ -0,0 +1,44 @@ +=== tests/cases/compiler/server.ts === + +export interface I { +>I : I + + prop: string; +>prop : string +} +export interface I2 { +>I2 : I2 + + prop2: string; +>prop2 : string +} +export class C implements I { +>C : C +>I : I + + prop = "hello"; +>prop : string +} +export class C2 implements I2 { +>C2 : C2 +>I2 : I2 + + prop2 = "world"; +>prop2 : string +} + +=== tests/cases/compiler/client.ts === +import { C, I, C2 } from "server"; // Shouldnt emit I and C2 into the js file and emit C and I in .d.ts file +>C : typeof C +>I : unknown +>C2 : typeof C2 + +export type cValInterface = I; +>cValInterface : I +>I : I + +export var cVal = new C(); +>cVal : C +>new C() : C +>C : typeof C + diff --git a/tests/baselines/reference/es6ImportWithoutFromClause.js b/tests/baselines/reference/es6ImportWithoutFromClause.js index 43d21885c2701..9666409b9249a 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClause.js +++ b/tests/baselines/reference/es6ImportWithoutFromClause.js @@ -5,9 +5,15 @@ export var a = 10; //// [es6ImportWithoutFromClause_1.ts] -import "es6ImportWithoutFromClause_0"; +import "es6ImportWithoutFromClause_0"; + //// [es6ImportWithoutFromClause_0.js] -exports.a = 10; +export var a = 10; //// [es6ImportWithoutFromClause_1.js] -require("es6ImportWithoutFromClause_0"); +import "es6ImportWithoutFromClause_0"; + + +//// [es6ImportWithoutFromClause_0.d.ts] +export declare var a: number; +//// [es6ImportWithoutFromClause_1.d.ts] diff --git a/tests/baselines/reference/es6ImportWithoutFromClause.types b/tests/baselines/reference/es6ImportWithoutFromClause.types index 1cd7df9962ee7..3cc5067891ad2 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClause.types +++ b/tests/baselines/reference/es6ImportWithoutFromClause.types @@ -5,4 +5,5 @@ export var a = 10; === tests/cases/compiler/es6ImportWithoutFromClause_1.ts === import "es6ImportWithoutFromClause_0"; +No type information for this code. No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseAmd.js b/tests/baselines/reference/es6ImportWithoutFromClauseAmd.js new file mode 100644 index 0000000000000..7b10da7cc9fc3 --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseAmd.js @@ -0,0 +1,35 @@ +//// [tests/cases/compiler/es6ImportWithoutFromClauseAmd.ts] //// + +//// [es6ImportWithoutFromClauseAmd_0.ts] + +export var a = 10; + +//// [es6ImportWithoutFromClauseAmd_1.ts] +export var b = 10; + +//// [es6ImportWithoutFromClauseAmd_2.ts] +import "es6ImportWithoutFromClauseAmd_0"; +import "es6ImportWithoutFromClauseAmd_2"; +var _a = 10; +var _b = 10; + +//// [es6ImportWithoutFromClauseAmd_0.js] +define(["require", "exports"], function (require, exports) { + exports.a = 10; +}); +//// [es6ImportWithoutFromClauseAmd_1.js] +define(["require", "exports"], function (require, exports) { + exports.b = 10; +}); +//// [es6ImportWithoutFromClauseAmd_2.js] +define(["require", "exports", "es6ImportWithoutFromClauseAmd_0", "es6ImportWithoutFromClauseAmd_2"], function (require, exports, , ) { + var _a = 10; + var _b = 10; +}); + + +//// [es6ImportWithoutFromClauseAmd_0.d.ts] +export declare var a: number; +//// [es6ImportWithoutFromClauseAmd_1.d.ts] +export declare var b: number; +//// [es6ImportWithoutFromClauseAmd_2.d.ts] diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseAmd.types b/tests/baselines/reference/es6ImportWithoutFromClauseAmd.types new file mode 100644 index 0000000000000..c3d09388916bc --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseAmd.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/es6ImportWithoutFromClauseAmd_0.ts === + +export var a = 10; +>a : number + +=== tests/cases/compiler/es6ImportWithoutFromClauseAmd_1.ts === +export var b = 10; +>b : number + +=== tests/cases/compiler/es6ImportWithoutFromClauseAmd_2.ts === +import "es6ImportWithoutFromClauseAmd_0"; +import "es6ImportWithoutFromClauseAmd_2"; +var _a = 10; +>_a : number + +var _b = 10; +>_b : number + diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js index f6610ac5ad295..aacb936ab3619 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js +++ b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js @@ -11,3 +11,8 @@ import "es6ImportWithoutFromClauseInEs5_0"; exports.a = 10; //// [es6ImportWithoutFromClauseInEs5_1.js] require("es6ImportWithoutFromClauseInEs5_0"); + + +//// [es6ImportWithoutFromClauseInEs5_0.d.ts] +export declare var a: number; +//// [es6ImportWithoutFromClauseInEs5_1.d.ts] diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js b/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js new file mode 100644 index 0000000000000..e63dd4bb53a0e --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js @@ -0,0 +1,19 @@ +//// [tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule.ts] //// + +//// [es6ImportWithoutFromClauseNonInstantiatedModule_0.ts] + +export interface i { +} + +//// [es6ImportWithoutFromClauseNonInstantiatedModule_1.ts] +import "es6ImportWithoutFromClauseNonInstantiatedModule_0"; + +//// [es6ImportWithoutFromClauseNonInstantiatedModule_0.js] +//// [es6ImportWithoutFromClauseNonInstantiatedModule_1.js] +import "es6ImportWithoutFromClauseNonInstantiatedModule_0"; + + +//// [es6ImportWithoutFromClauseNonInstantiatedModule_0.d.ts] +export interface i { +} +//// [es6ImportWithoutFromClauseNonInstantiatedModule_1.d.ts] diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.types b/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.types new file mode 100644 index 0000000000000..2be3f67f1e963 --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule_0.ts === + +export interface i { +>i : i +} + +=== tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule_1.ts === +import "es6ImportWithoutFromClauseNonInstantiatedModule_0"; +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.errors.txt b/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.errors.txt new file mode 100644 index 0000000000000..da865698e56a8 --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/client.ts(1,1): error TS1191: An import declaration cannot have modifiers. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/client.ts (1 errors) ==== + export import "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.js b/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.js new file mode 100644 index 0000000000000..208f71bcbfe9f --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.js @@ -0,0 +1,19 @@ +//// [tests/cases/compiler/es6ImportWithoutFromClauseWithExport.ts] //// + +//// [server.ts] + +export var a = 10; + +//// [client.ts] +export import "server"; + +//// [server.js] +exports.a = 10; +//// [client.js] +require("server"); + + +//// [server.d.ts] +export declare var a: number; +//// [client.d.ts] +export import "server"; diff --git a/tests/baselines/reference/es6Module.js b/tests/baselines/reference/es6Module.js new file mode 100644 index 0000000000000..d3141572c924a --- /dev/null +++ b/tests/baselines/reference/es6Module.js @@ -0,0 +1,21 @@ +//// [es6Module.ts] +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} + +//// [es6Module.js] +export class A { + constructor() { + } + B() { + return 42; + } +} diff --git a/tests/baselines/reference/es6-amd.types b/tests/baselines/reference/es6Module.types similarity index 60% rename from tests/baselines/reference/es6-amd.types rename to tests/baselines/reference/es6Module.types index 62815911f7f97..9391020021526 100644 --- a/tests/baselines/reference/es6-amd.types +++ b/tests/baselines/reference/es6Module.types @@ -1,11 +1,9 @@ -=== tests/cases/compiler/es6-amd.ts === - -class A +=== tests/cases/compiler/es6Module.ts === +export class A >A : A { constructor () { - } public B() diff --git a/tests/baselines/reference/es6ModuleClassDeclaration.js b/tests/baselines/reference/es6ModuleClassDeclaration.js new file mode 100644 index 0000000000000..a228739abbfb7 --- /dev/null +++ b/tests/baselines/reference/es6ModuleClassDeclaration.js @@ -0,0 +1,230 @@ +//// [es6ModuleClassDeclaration.ts] +export class c { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } +} +class c2 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } +} +new c(); +new c2(); + +export module m1 { + export class c3 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + class c4 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + new c(); + new c2(); + new c3(); + new c4(); +} +module m2 { + export class c3 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + class c4 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + new c(); + new c2(); + new c3(); + new c4(); + new m1.c3(); +} + +//// [es6ModuleClassDeclaration.js] +export class c { + constructor() { + this.x = 10; + this.y = 30; + } + method1() { + } + method2() { + } + static method3() { + } + static method4() { + } +} +c.k = 20; +c.l = 30; +class c2 { + constructor() { + this.x = 10; + this.y = 30; + } + method1() { + } + method2() { + } + static method3() { + } + static method4() { + } +} +c2.k = 20; +c2.l = 30; +new c(); +new c2(); +export var m1; +(function (m1) { + class c3 { + constructor() { + this.x = 10; + this.y = 30; + } + method1() { + } + method2() { + } + static method3() { + } + static method4() { + } + } + c3.k = 20; + c3.l = 30; + m1.c3 = c3; + class c4 { + constructor() { + this.x = 10; + this.y = 30; + } + method1() { + } + method2() { + } + static method3() { + } + static method4() { + } + } + c4.k = 20; + c4.l = 30; + new c(); + new c2(); + new c3(); + new c4(); +})(m1 || (m1 = {})); +var m2; +(function (m2) { + class c3 { + constructor() { + this.x = 10; + this.y = 30; + } + method1() { + } + method2() { + } + static method3() { + } + static method4() { + } + } + c3.k = 20; + c3.l = 30; + m2.c3 = c3; + class c4 { + constructor() { + this.x = 10; + this.y = 30; + } + method1() { + } + method2() { + } + static method3() { + } + static method4() { + } + } + c4.k = 20; + c4.l = 30; + new c(); + new c2(); + new c3(); + new c4(); + new m1.c3(); +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleClassDeclaration.types b/tests/baselines/reference/es6ModuleClassDeclaration.types new file mode 100644 index 0000000000000..09d50c4e542d5 --- /dev/null +++ b/tests/baselines/reference/es6ModuleClassDeclaration.types @@ -0,0 +1,233 @@ +=== tests/cases/compiler/es6ModuleClassDeclaration.ts === +export class c { +>c : c + + constructor() { + } + private x = 10; +>x : number + + public y = 30; +>y : number + + static k = 20; +>k : number + + private static l = 30; +>l : number + + private method1() { +>method1 : () => void + } + public method2() { +>method2 : () => void + } + static method3() { +>method3 : () => void + } + private static method4() { +>method4 : () => void + } +} +class c2 { +>c2 : c2 + + constructor() { + } + private x = 10; +>x : number + + public y = 30; +>y : number + + static k = 20; +>k : number + + private static l = 30; +>l : number + + private method1() { +>method1 : () => void + } + public method2() { +>method2 : () => void + } + static method3() { +>method3 : () => void + } + private static method4() { +>method4 : () => void + } +} +new c(); +>new c() : c +>c : typeof c + +new c2(); +>new c2() : c2 +>c2 : typeof c2 + +export module m1 { +>m1 : typeof m1 + + export class c3 { +>c3 : c3 + + constructor() { + } + private x = 10; +>x : number + + public y = 30; +>y : number + + static k = 20; +>k : number + + private static l = 30; +>l : number + + private method1() { +>method1 : () => void + } + public method2() { +>method2 : () => void + } + static method3() { +>method3 : () => void + } + private static method4() { +>method4 : () => void + } + } + class c4 { +>c4 : c4 + + constructor() { + } + private x = 10; +>x : number + + public y = 30; +>y : number + + static k = 20; +>k : number + + private static l = 30; +>l : number + + private method1() { +>method1 : () => void + } + public method2() { +>method2 : () => void + } + static method3() { +>method3 : () => void + } + private static method4() { +>method4 : () => void + } + } + new c(); +>new c() : c +>c : typeof c + + new c2(); +>new c2() : c2 +>c2 : typeof c2 + + new c3(); +>new c3() : c3 +>c3 : typeof c3 + + new c4(); +>new c4() : c4 +>c4 : typeof c4 +} +module m2 { +>m2 : typeof m2 + + export class c3 { +>c3 : c3 + + constructor() { + } + private x = 10; +>x : number + + public y = 30; +>y : number + + static k = 20; +>k : number + + private static l = 30; +>l : number + + private method1() { +>method1 : () => void + } + public method2() { +>method2 : () => void + } + static method3() { +>method3 : () => void + } + private static method4() { +>method4 : () => void + } + } + class c4 { +>c4 : c4 + + constructor() { + } + private x = 10; +>x : number + + public y = 30; +>y : number + + static k = 20; +>k : number + + private static l = 30; +>l : number + + private method1() { +>method1 : () => void + } + public method2() { +>method2 : () => void + } + static method3() { +>method3 : () => void + } + private static method4() { +>method4 : () => void + } + } + new c(); +>new c() : c +>c : typeof c + + new c2(); +>new c2() : c2 +>c2 : typeof c2 + + new c3(); +>new c3() : c3 +>c3 : typeof c3 + + new c4(); +>new c4() : c4 +>c4 : typeof c4 + + new m1.c3(); +>new m1.c3() : m1.c3 +>m1.c3 : typeof m1.c3 +>m1 : typeof m1 +>c3 : typeof m1.c3 +} diff --git a/tests/baselines/reference/es6ModuleConst.js b/tests/baselines/reference/es6ModuleConst.js new file mode 100644 index 0000000000000..117bf0fb4d0d2 --- /dev/null +++ b/tests/baselines/reference/es6ModuleConst.js @@ -0,0 +1,37 @@ +//// [es6ModuleConst.ts] +export const a = "hello"; +export const x: string = a, y = x; +const b = y; +const c: string = b, d = c; +export module m1 { + export const k = a; + export const l: string = b, m = k; + const n = m1.k; + const o: string = n, p = k; +} +module m2 { + export const k = a; + export const l: string = b, m = k; + const n = m1.k; + const o: string = n, p = k; +} + +//// [es6ModuleConst.js] +export const a = "hello"; +export const x = a, y = x; +const b = y; +const c = b, d = c; +export var m1; +(function (m1) { + m1.k = a; + m1.l = b, m1.m = m1.k; + const n = m1.k; + const o = n, p = m1.k; +})(m1 || (m1 = {})); +var m2; +(function (m2) { + m2.k = a; + m2.l = b, m2.m = m2.k; + const n = m1.k; + const o = n, p = m2.k; +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleConst.types b/tests/baselines/reference/es6ModuleConst.types new file mode 100644 index 0000000000000..cceb74a5e1ed5 --- /dev/null +++ b/tests/baselines/reference/es6ModuleConst.types @@ -0,0 +1,70 @@ +=== tests/cases/compiler/es6ModuleConst.ts === +export const a = "hello"; +>a : string + +export const x: string = a, y = x; +>x : string +>a : string +>y : string +>x : string + +const b = y; +>b : string +>y : string + +const c: string = b, d = c; +>c : string +>b : string +>d : string +>c : string + +export module m1 { +>m1 : typeof m1 + + export const k = a; +>k : string +>a : string + + export const l: string = b, m = k; +>l : string +>b : string +>m : string +>k : string + + const n = m1.k; +>n : string +>m1.k : string +>m1 : typeof m1 +>k : string + + const o: string = n, p = k; +>o : string +>n : string +>p : string +>k : string +} +module m2 { +>m2 : typeof m2 + + export const k = a; +>k : string +>a : string + + export const l: string = b, m = k; +>l : string +>b : string +>m : string +>k : string + + const n = m1.k; +>n : string +>m1.k : string +>m1 : typeof m1 +>k : string + + const o: string = n, p = k; +>o : string +>n : string +>p : string +>k : string +} diff --git a/tests/baselines/reference/es6ModuleConstEnumDeclaration.js b/tests/baselines/reference/es6ModuleConstEnumDeclaration.js new file mode 100644 index 0000000000000..1900db57b6037 --- /dev/null +++ b/tests/baselines/reference/es6ModuleConstEnumDeclaration.js @@ -0,0 +1,65 @@ +//// [es6ModuleConstEnumDeclaration.ts] +export const enum e1 { + a, + b, + c +} +const enum e2 { + x, + y, + z +} +var x = e1.a; +var y = e2.x; +export module m1 { + export const enum e3 { + a, + b, + c + } + const enum e4 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e3.a; + var y2 = e4.x; +} +module m2 { + export const enum e5 { + a, + b, + c + } + const enum e6 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e5.a; + var y2 = e6.x; + var x3 = m1.e3.a; +} + +//// [es6ModuleConstEnumDeclaration.js] +var x = 0 /* a */; +var y = 0 /* x */; +export var m1; +(function (m1) { + var x1 = 0 /* a */; + var y1 = 0 /* x */; + var x2 = 0 /* a */; + var y2 = 0 /* x */; +})(m1 || (m1 = {})); +var m2; +(function (m2) { + var x1 = 0 /* a */; + var y1 = 0 /* x */; + var x2 = 0 /* a */; + var y2 = 0 /* x */; + var x3 = 0 /* a */; +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleConstEnumDeclaration.types b/tests/baselines/reference/es6ModuleConstEnumDeclaration.types new file mode 100644 index 0000000000000..fae819f93b06f --- /dev/null +++ b/tests/baselines/reference/es6ModuleConstEnumDeclaration.types @@ -0,0 +1,147 @@ +=== tests/cases/compiler/es6ModuleConstEnumDeclaration.ts === +export const enum e1 { +>e1 : e1 + + a, +>a : e1 + + b, +>b : e1 + + c +>c : e1 +} +const enum e2 { +>e2 : e2 + + x, +>x : e2 + + y, +>y : e2 + + z +>z : e2 +} +var x = e1.a; +>x : e1 +>e1.a : e1 +>e1 : typeof e1 +>a : e1 + +var y = e2.x; +>y : e2 +>e2.x : e2 +>e2 : typeof e2 +>x : e2 + +export module m1 { +>m1 : typeof m1 + + export const enum e3 { +>e3 : e3 + + a, +>a : e3 + + b, +>b : e3 + + c +>c : e3 + } + const enum e4 { +>e4 : e4 + + x, +>x : e4 + + y, +>y : e4 + + z +>z : e4 + } + var x1 = e1.a; +>x1 : e1 +>e1.a : e1 +>e1 : typeof e1 +>a : e1 + + var y1 = e2.x; +>y1 : e2 +>e2.x : e2 +>e2 : typeof e2 +>x : e2 + + var x2 = e3.a; +>x2 : e3 +>e3.a : e3 +>e3 : typeof e3 +>a : e3 + + var y2 = e4.x; +>y2 : e4 +>e4.x : e4 +>e4 : typeof e4 +>x : e4 +} +module m2 { +>m2 : typeof m2 + + export const enum e5 { +>e5 : e5 + + a, +>a : e5 + + b, +>b : e5 + + c +>c : e5 + } + const enum e6 { +>e6 : e6 + + x, +>x : e6 + + y, +>y : e6 + + z +>z : e6 + } + var x1 = e1.a; +>x1 : e1 +>e1.a : e1 +>e1 : typeof e1 +>a : e1 + + var y1 = e2.x; +>y1 : e2 +>e2.x : e2 +>e2 : typeof e2 +>x : e2 + + var x2 = e5.a; +>x2 : e5 +>e5.a : e5 +>e5 : typeof e5 +>a : e5 + + var y2 = e6.x; +>y2 : e6 +>e6.x : e6 +>e6 : typeof e6 +>x : e6 + + var x3 = m1.e3.a; +>x3 : m1.e3 +>m1.e3.a : m1.e3 +>m1.e3 : typeof m1.e3 +>m1 : typeof m1 +>e3 : typeof m1.e3 +>a : m1.e3 +} diff --git a/tests/baselines/reference/es6ModuleConstEnumDeclaration2.js b/tests/baselines/reference/es6ModuleConstEnumDeclaration2.js new file mode 100644 index 0000000000000..539ec121b6b57 --- /dev/null +++ b/tests/baselines/reference/es6ModuleConstEnumDeclaration2.js @@ -0,0 +1,102 @@ +//// [es6ModuleConstEnumDeclaration2.ts] + +export const enum e1 { + a, + b, + c +} +const enum e2 { + x, + y, + z +} +var x = e1.a; +var y = e2.x; +export module m1 { + export const enum e3 { + a, + b, + c + } + const enum e4 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e3.a; + var y2 = e4.x; +} +module m2 { + export const enum e5 { + a, + b, + c + } + const enum e6 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e5.a; + var y2 = e6.x; + var x3 = m1.e3.a; +} + +//// [es6ModuleConstEnumDeclaration2.js] +export var e1; +(function (e1) { + e1[e1["a"] = 0] = "a"; + e1[e1["b"] = 1] = "b"; + e1[e1["c"] = 2] = "c"; +})(e1 || (e1 = {})); +var e2; +(function (e2) { + e2[e2["x"] = 0] = "x"; + e2[e2["y"] = 1] = "y"; + e2[e2["z"] = 2] = "z"; +})(e2 || (e2 = {})); +var x = 0 /* a */; +var y = 0 /* x */; +export var m1; +(function (m1) { + (function (e3) { + e3[e3["a"] = 0] = "a"; + e3[e3["b"] = 1] = "b"; + e3[e3["c"] = 2] = "c"; + })(m1.e3 || (m1.e3 = {})); + var e3 = m1.e3; + var e4; + (function (e4) { + e4[e4["x"] = 0] = "x"; + e4[e4["y"] = 1] = "y"; + e4[e4["z"] = 2] = "z"; + })(e4 || (e4 = {})); + var x1 = 0 /* a */; + var y1 = 0 /* x */; + var x2 = 0 /* a */; + var y2 = 0 /* x */; +})(m1 || (m1 = {})); +var m2; +(function (m2) { + (function (e5) { + e5[e5["a"] = 0] = "a"; + e5[e5["b"] = 1] = "b"; + e5[e5["c"] = 2] = "c"; + })(m2.e5 || (m2.e5 = {})); + var e5 = m2.e5; + var e6; + (function (e6) { + e6[e6["x"] = 0] = "x"; + e6[e6["y"] = 1] = "y"; + e6[e6["z"] = 2] = "z"; + })(e6 || (e6 = {})); + var x1 = 0 /* a */; + var y1 = 0 /* x */; + var x2 = 0 /* a */; + var y2 = 0 /* x */; + var x3 = 0 /* a */; +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleConstEnumDeclaration2.types b/tests/baselines/reference/es6ModuleConstEnumDeclaration2.types new file mode 100644 index 0000000000000..c43a938c9b6a8 --- /dev/null +++ b/tests/baselines/reference/es6ModuleConstEnumDeclaration2.types @@ -0,0 +1,148 @@ +=== tests/cases/compiler/es6ModuleConstEnumDeclaration2.ts === + +export const enum e1 { +>e1 : e1 + + a, +>a : e1 + + b, +>b : e1 + + c +>c : e1 +} +const enum e2 { +>e2 : e2 + + x, +>x : e2 + + y, +>y : e2 + + z +>z : e2 +} +var x = e1.a; +>x : e1 +>e1.a : e1 +>e1 : typeof e1 +>a : e1 + +var y = e2.x; +>y : e2 +>e2.x : e2 +>e2 : typeof e2 +>x : e2 + +export module m1 { +>m1 : typeof m1 + + export const enum e3 { +>e3 : e3 + + a, +>a : e3 + + b, +>b : e3 + + c +>c : e3 + } + const enum e4 { +>e4 : e4 + + x, +>x : e4 + + y, +>y : e4 + + z +>z : e4 + } + var x1 = e1.a; +>x1 : e1 +>e1.a : e1 +>e1 : typeof e1 +>a : e1 + + var y1 = e2.x; +>y1 : e2 +>e2.x : e2 +>e2 : typeof e2 +>x : e2 + + var x2 = e3.a; +>x2 : e3 +>e3.a : e3 +>e3 : typeof e3 +>a : e3 + + var y2 = e4.x; +>y2 : e4 +>e4.x : e4 +>e4 : typeof e4 +>x : e4 +} +module m2 { +>m2 : typeof m2 + + export const enum e5 { +>e5 : e5 + + a, +>a : e5 + + b, +>b : e5 + + c +>c : e5 + } + const enum e6 { +>e6 : e6 + + x, +>x : e6 + + y, +>y : e6 + + z +>z : e6 + } + var x1 = e1.a; +>x1 : e1 +>e1.a : e1 +>e1 : typeof e1 +>a : e1 + + var y1 = e2.x; +>y1 : e2 +>e2.x : e2 +>e2 : typeof e2 +>x : e2 + + var x2 = e5.a; +>x2 : e5 +>e5.a : e5 +>e5 : typeof e5 +>a : e5 + + var y2 = e6.x; +>y2 : e6 +>e6.x : e6 +>e6 : typeof e6 +>x : e6 + + var x3 = m1.e3.a; +>x3 : m1.e3 +>m1.e3.a : m1.e3 +>m1.e3 : typeof m1.e3 +>m1 : typeof m1 +>e3 : typeof m1.e3 +>a : m1.e3 +} diff --git a/tests/baselines/reference/es6ModuleEnumDeclaration.js b/tests/baselines/reference/es6ModuleEnumDeclaration.js new file mode 100644 index 0000000000000..30c382a4508bc --- /dev/null +++ b/tests/baselines/reference/es6ModuleEnumDeclaration.js @@ -0,0 +1,101 @@ +//// [es6ModuleEnumDeclaration.ts] +export enum e1 { + a, + b, + c +} +enum e2 { + x, + y, + z +} +var x = e1.a; +var y = e2.x; +export module m1 { + export enum e3 { + a, + b, + c + } + enum e4 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e3.a; + var y2 = e4.x; +} +module m2 { + export enum e5 { + a, + b, + c + } + enum e6 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e5.a; + var y2 = e6.x; + var x3 = m1.e3.a; +} + +//// [es6ModuleEnumDeclaration.js] +export var e1; +(function (e1) { + e1[e1["a"] = 0] = "a"; + e1[e1["b"] = 1] = "b"; + e1[e1["c"] = 2] = "c"; +})(e1 || (e1 = {})); +var e2; +(function (e2) { + e2[e2["x"] = 0] = "x"; + e2[e2["y"] = 1] = "y"; + e2[e2["z"] = 2] = "z"; +})(e2 || (e2 = {})); +var x = e1.a; +var y = e2.x; +export var m1; +(function (m1) { + (function (e3) { + e3[e3["a"] = 0] = "a"; + e3[e3["b"] = 1] = "b"; + e3[e3["c"] = 2] = "c"; + })(m1.e3 || (m1.e3 = {})); + var e3 = m1.e3; + var e4; + (function (e4) { + e4[e4["x"] = 0] = "x"; + e4[e4["y"] = 1] = "y"; + e4[e4["z"] = 2] = "z"; + })(e4 || (e4 = {})); + var x1 = e1.a; + var y1 = e2.x; + var x2 = e3.a; + var y2 = e4.x; +})(m1 || (m1 = {})); +var m2; +(function (m2) { + (function (e5) { + e5[e5["a"] = 0] = "a"; + e5[e5["b"] = 1] = "b"; + e5[e5["c"] = 2] = "c"; + })(m2.e5 || (m2.e5 = {})); + var e5 = m2.e5; + var e6; + (function (e6) { + e6[e6["x"] = 0] = "x"; + e6[e6["y"] = 1] = "y"; + e6[e6["z"] = 2] = "z"; + })(e6 || (e6 = {})); + var x1 = e1.a; + var y1 = e2.x; + var x2 = e5.a; + var y2 = e6.x; + var x3 = m1.e3.a; +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleEnumDeclaration.types b/tests/baselines/reference/es6ModuleEnumDeclaration.types new file mode 100644 index 0000000000000..4b856fee00902 --- /dev/null +++ b/tests/baselines/reference/es6ModuleEnumDeclaration.types @@ -0,0 +1,147 @@ +=== tests/cases/compiler/es6ModuleEnumDeclaration.ts === +export enum e1 { +>e1 : e1 + + a, +>a : e1 + + b, +>b : e1 + + c +>c : e1 +} +enum e2 { +>e2 : e2 + + x, +>x : e2 + + y, +>y : e2 + + z +>z : e2 +} +var x = e1.a; +>x : e1 +>e1.a : e1 +>e1 : typeof e1 +>a : e1 + +var y = e2.x; +>y : e2 +>e2.x : e2 +>e2 : typeof e2 +>x : e2 + +export module m1 { +>m1 : typeof m1 + + export enum e3 { +>e3 : e3 + + a, +>a : e3 + + b, +>b : e3 + + c +>c : e3 + } + enum e4 { +>e4 : e4 + + x, +>x : e4 + + y, +>y : e4 + + z +>z : e4 + } + var x1 = e1.a; +>x1 : e1 +>e1.a : e1 +>e1 : typeof e1 +>a : e1 + + var y1 = e2.x; +>y1 : e2 +>e2.x : e2 +>e2 : typeof e2 +>x : e2 + + var x2 = e3.a; +>x2 : e3 +>e3.a : e3 +>e3 : typeof e3 +>a : e3 + + var y2 = e4.x; +>y2 : e4 +>e4.x : e4 +>e4 : typeof e4 +>x : e4 +} +module m2 { +>m2 : typeof m2 + + export enum e5 { +>e5 : e5 + + a, +>a : e5 + + b, +>b : e5 + + c +>c : e5 + } + enum e6 { +>e6 : e6 + + x, +>x : e6 + + y, +>y : e6 + + z +>z : e6 + } + var x1 = e1.a; +>x1 : e1 +>e1.a : e1 +>e1 : typeof e1 +>a : e1 + + var y1 = e2.x; +>y1 : e2 +>e2.x : e2 +>e2 : typeof e2 +>x : e2 + + var x2 = e5.a; +>x2 : e5 +>e5.a : e5 +>e5 : typeof e5 +>a : e5 + + var y2 = e6.x; +>y2 : e6 +>e6.x : e6 +>e6 : typeof e6 +>x : e6 + + var x3 = m1.e3.a; +>x3 : m1.e3 +>m1.e3.a : m1.e3 +>m1.e3 : typeof m1.e3 +>m1 : typeof m1 +>e3 : typeof m1.e3 +>a : m1.e3 +} diff --git a/tests/baselines/reference/es6ModuleFunctionDeclaration.js b/tests/baselines/reference/es6ModuleFunctionDeclaration.js new file mode 100644 index 0000000000000..1305d0a4e1904 --- /dev/null +++ b/tests/baselines/reference/es6ModuleFunctionDeclaration.js @@ -0,0 +1,62 @@ +//// [es6ModuleFunctionDeclaration.ts] +export function foo() { +} +function foo2() { +} +foo(); +foo2(); + +export module m1 { + export function foo3() { + } + function foo4() { + } + foo(); + foo2(); + foo3(); + foo4(); +} +module m2 { + export function foo3() { + } + function foo4() { + } + foo(); + foo2(); + foo3(); + foo4(); + m1.foo3(); +} + +//// [es6ModuleFunctionDeclaration.js] +export function foo() { +} +function foo2() { +} +foo(); +foo2(); +export var m1; +(function (m1) { + function foo3() { + } + m1.foo3 = foo3; + function foo4() { + } + foo(); + foo2(); + foo3(); + foo4(); +})(m1 || (m1 = {})); +var m2; +(function (m2) { + function foo3() { + } + m2.foo3 = foo3; + function foo4() { + } + foo(); + foo2(); + foo3(); + foo4(); + m1.foo3(); +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleFunctionDeclaration.types b/tests/baselines/reference/es6ModuleFunctionDeclaration.types new file mode 100644 index 0000000000000..b1252c1e8bcd3 --- /dev/null +++ b/tests/baselines/reference/es6ModuleFunctionDeclaration.types @@ -0,0 +1,71 @@ +=== tests/cases/compiler/es6ModuleFunctionDeclaration.ts === +export function foo() { +>foo : () => void +} +function foo2() { +>foo2 : () => void +} +foo(); +>foo() : void +>foo : () => void + +foo2(); +>foo2() : void +>foo2 : () => void + +export module m1 { +>m1 : typeof m1 + + export function foo3() { +>foo3 : () => void + } + function foo4() { +>foo4 : () => void + } + foo(); +>foo() : void +>foo : () => void + + foo2(); +>foo2() : void +>foo2 : () => void + + foo3(); +>foo3() : void +>foo3 : () => void + + foo4(); +>foo4() : void +>foo4 : () => void +} +module m2 { +>m2 : typeof m2 + + export function foo3() { +>foo3 : () => void + } + function foo4() { +>foo4 : () => void + } + foo(); +>foo() : void +>foo : () => void + + foo2(); +>foo2() : void +>foo2 : () => void + + foo3(); +>foo3() : void +>foo3 : () => void + + foo4(); +>foo4() : void +>foo4 : () => void + + m1.foo3(); +>m1.foo3() : void +>m1.foo3 : () => void +>m1 : typeof m1 +>foo3 : () => void +} diff --git a/tests/baselines/reference/es6ModuleInternalImport.js b/tests/baselines/reference/es6ModuleInternalImport.js new file mode 100644 index 0000000000000..3f28ddb2b6095 --- /dev/null +++ b/tests/baselines/reference/es6ModuleInternalImport.js @@ -0,0 +1,44 @@ +//// [es6ModuleInternalImport.ts] +export module m { + export var a = 10; +} +export import a1 = m.a; +import a2 = m.a; +var x = a1 + a2; +export module m1 { + export import a3 = m.a; + import a4 = m.a; + var x = a1 + a2; + var x2 = a3 + a4; +} +module m2 { + export import a3 = m.a; + import a4 = m.a; + var x = a1 + a2; + var x2 = a3 + a4; + var x4 = m1.a3 + m2.a3; +} + +//// [es6ModuleInternalImport.js] +export var m; +(function (m) { + m.a = 10; +})(m || (m = {})); +export var a1 = m.a; +var a2 = m.a; +var x = a1 + a2; +export var m1; +(function (m1) { + m1.a3 = m.a; + var a4 = m.a; + var x = a1 + a2; + var x2 = m1.a3 + a4; +})(m1 || (m1 = {})); +var m2; +(function (m2) { + m2.a3 = m.a; + var a4 = m.a; + var x = a1 + a2; + var x2 = m2.a3 + a4; + var x4 = m1.a3 + m2.a3; +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleInternalImport.types b/tests/baselines/reference/es6ModuleInternalImport.types new file mode 100644 index 0000000000000..50db69d8edb22 --- /dev/null +++ b/tests/baselines/reference/es6ModuleInternalImport.types @@ -0,0 +1,83 @@ +=== tests/cases/compiler/es6ModuleInternalImport.ts === +export module m { +>m : typeof m + + export var a = 10; +>a : number +} +export import a1 = m.a; +>a1 : number +>m : typeof m +>a : number + +import a2 = m.a; +>a2 : number +>m : typeof m +>a : number + +var x = a1 + a2; +>x : number +>a1 + a2 : number +>a1 : number +>a2 : number + +export module m1 { +>m1 : typeof m1 + + export import a3 = m.a; +>a3 : number +>m : typeof m +>a : number + + import a4 = m.a; +>a4 : number +>m : typeof m +>a : number + + var x = a1 + a2; +>x : number +>a1 + a2 : number +>a1 : number +>a2 : number + + var x2 = a3 + a4; +>x2 : number +>a3 + a4 : number +>a3 : number +>a4 : number +} +module m2 { +>m2 : typeof m2 + + export import a3 = m.a; +>a3 : number +>m : typeof m +>a : number + + import a4 = m.a; +>a4 : number +>m : typeof m +>a : number + + var x = a1 + a2; +>x : number +>a1 + a2 : number +>a1 : number +>a2 : number + + var x2 = a3 + a4; +>x2 : number +>a3 + a4 : number +>a3 : number +>a4 : number + + var x4 = m1.a3 + m2.a3; +>x4 : number +>m1.a3 + m2.a3 : number +>m1.a3 : number +>m1 : typeof m1 +>a3 : number +>m2.a3 : number +>m2 : typeof m2 +>a3 : number +} diff --git a/tests/baselines/reference/es6ModuleInternalNamedImports.errors.txt b/tests/baselines/reference/es6ModuleInternalNamedImports.errors.txt new file mode 100644 index 0000000000000..4e097ec1a3383 --- /dev/null +++ b/tests/baselines/reference/es6ModuleInternalNamedImports.errors.txt @@ -0,0 +1,59 @@ +tests/cases/compiler/es6ModuleInternalNamedImports.ts(23,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports.ts(24,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports.ts(25,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports.ts(26,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports.ts(27,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports.ts(28,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports.ts(29,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports.ts(30,5): error TS1194: Export declarations are not permitted in an internal module. + + +==== tests/cases/compiler/es6ModuleInternalNamedImports.ts (8 errors) ==== + + export module M { + // variable + export var M_V = 0; + // interface + export interface M_I { } + //calss + export class M_C { } + // instantiated module + export module M_M { var x; } + // uninstantiated module + export module M_MU { } + // function + export function M_F() { } + // enum + export enum M_E { } + // type + export type M_T = number; + // alias + export import M_A = M_M; + + // Reexports + export {M_V as v}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_I as i}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_C as c}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_M as m}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_MU as mu}; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_F as f}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_E as e}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_A as a}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + } + \ No newline at end of file diff --git a/tests/baselines/reference/es6ModuleInternalNamedImports.js b/tests/baselines/reference/es6ModuleInternalNamedImports.js new file mode 100644 index 0000000000000..db7c771eaba21 --- /dev/null +++ b/tests/baselines/reference/es6ModuleInternalNamedImports.js @@ -0,0 +1,66 @@ +//// [es6ModuleInternalNamedImports.ts] + +export module M { + // variable + export var M_V = 0; + // interface + export interface M_I { } + //calss + export class M_C { } + // instantiated module + export module M_M { var x; } + // uninstantiated module + export module M_MU { } + // function + export function M_F() { } + // enum + export enum M_E { } + // type + export type M_T = number; + // alias + export import M_A = M_M; + + // Reexports + export {M_V as v}; + export {M_I as i}; + export {M_C as c}; + export {M_M as m}; + export {M_MU as mu}; + export {M_F as f}; + export {M_E as e}; + export {M_A as a}; +} + + +//// [es6ModuleInternalNamedImports.js] +export var M; +(function (M) { + // variable + M.M_V = 0; + //calss + class M_C { + } + M.M_C = M_C; + // instantiated module + var M_M; + (function (M_M) { + var x; + })(M_M = M.M_M || (M.M_M = {})); + // function + function M_F() { + } + M.M_F = M_F; + // enum + (function (M_E) { + })(M.M_E || (M.M_E = {})); + var M_E = M.M_E; + // alias + M.M_A = M_M; + // Reexports + export { M_V as v }; + export { M_C as c }; + export { M_M as m }; + export { M_F as f }; + export { M_E as e }; + export { M_A as a }; +})(M || (M = {})); diff --git a/tests/baselines/reference/es6ModuleInternalNamedImports2.errors.txt b/tests/baselines/reference/es6ModuleInternalNamedImports2.errors.txt new file mode 100644 index 0000000000000..77ee76cf9c86a --- /dev/null +++ b/tests/baselines/reference/es6ModuleInternalNamedImports2.errors.txt @@ -0,0 +1,61 @@ +tests/cases/compiler/es6ModuleInternalNamedImports2.ts(25,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports2.ts(26,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports2.ts(27,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports2.ts(28,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports2.ts(29,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports2.ts(30,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports2.ts(31,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports2.ts(32,5): error TS1194: Export declarations are not permitted in an internal module. + + +==== tests/cases/compiler/es6ModuleInternalNamedImports2.ts (8 errors) ==== + + export module M { + // variable + export var M_V = 0; + // interface + export interface M_I { } + //calss + export class M_C { } + // instantiated module + export module M_M { var x; } + // uninstantiated module + export module M_MU { } + // function + export function M_F() { } + // enum + export enum M_E { } + // type + export type M_T = number; + // alias + export import M_A = M_M; + } + + export module M { + // Reexports + export {M_V as v}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_I as i}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_C as c}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_M as m}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_MU as mu}; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_F as f}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_E as e}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_A as a}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + } + \ No newline at end of file diff --git a/tests/baselines/reference/es6ModuleInternalNamedImports2.js b/tests/baselines/reference/es6ModuleInternalNamedImports2.js new file mode 100644 index 0000000000000..b080064306067 --- /dev/null +++ b/tests/baselines/reference/es6ModuleInternalNamedImports2.js @@ -0,0 +1,71 @@ +//// [es6ModuleInternalNamedImports2.ts] + +export module M { + // variable + export var M_V = 0; + // interface + export interface M_I { } + //calss + export class M_C { } + // instantiated module + export module M_M { var x; } + // uninstantiated module + export module M_MU { } + // function + export function M_F() { } + // enum + export enum M_E { } + // type + export type M_T = number; + // alias + export import M_A = M_M; +} + +export module M { + // Reexports + export {M_V as v}; + export {M_I as i}; + export {M_C as c}; + export {M_M as m}; + export {M_MU as mu}; + export {M_F as f}; + export {M_E as e}; + export {M_A as a}; +} + + +//// [es6ModuleInternalNamedImports2.js] +export var M; +(function (M) { + // variable + M.M_V = 0; + //calss + class M_C { + } + M.M_C = M_C; + // instantiated module + var M_M; + (function (M_M) { + var x; + })(M_M = M.M_M || (M.M_M = {})); + // function + function M_F() { + } + M.M_F = M_F; + // enum + (function (M_E) { + })(M.M_E || (M.M_E = {})); + var M_E = M.M_E; + // alias + M.M_A = M_M; +})(M || (M = {})); +export var M; +(function (M) { + // Reexports + export { M_V as v }; + export { M_C as c }; + export { M_M as m }; + export { M_F as f }; + export { M_E as e }; + export { M_A as a }; +})(M || (M = {})); diff --git a/tests/baselines/reference/es6ModuleLet.js b/tests/baselines/reference/es6ModuleLet.js new file mode 100644 index 0000000000000..29d2a73bcf19d --- /dev/null +++ b/tests/baselines/reference/es6ModuleLet.js @@ -0,0 +1,37 @@ +//// [es6ModuleLet.ts] +export let a = "hello"; +export let x: string = a, y = x; +let b = y; +let c: string = b, d = c; +export module m1 { + export let k = a; + export let l: string = b, m = k; + let n = m1.k; + let o: string = n, p = k; +} +module m2 { + export let k = a; + export let l: string = b, m = k; + let n = m1.k; + let o: string = n, p = k; +} + +//// [es6ModuleLet.js] +export let a = "hello"; +export let x = a, y = x; +let b = y; +let c = b, d = c; +export var m1; +(function (m1) { + m1.k = a; + m1.l = b, m1.m = m1.k; + let n = m1.k; + let o = n, p = m1.k; +})(m1 || (m1 = {})); +var m2; +(function (m2) { + m2.k = a; + m2.l = b, m2.m = m2.k; + let n = m1.k; + let o = n, p = m2.k; +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleLet.types b/tests/baselines/reference/es6ModuleLet.types new file mode 100644 index 0000000000000..4b30c89cc819c --- /dev/null +++ b/tests/baselines/reference/es6ModuleLet.types @@ -0,0 +1,70 @@ +=== tests/cases/compiler/es6ModuleLet.ts === +export let a = "hello"; +>a : string + +export let x: string = a, y = x; +>x : string +>a : string +>y : string +>x : string + +let b = y; +>b : string +>y : string + +let c: string = b, d = c; +>c : string +>b : string +>d : string +>c : string + +export module m1 { +>m1 : typeof m1 + + export let k = a; +>k : string +>a : string + + export let l: string = b, m = k; +>l : string +>b : string +>m : string +>k : string + + let n = m1.k; +>n : string +>m1.k : string +>m1 : typeof m1 +>k : string + + let o: string = n, p = k; +>o : string +>n : string +>p : string +>k : string +} +module m2 { +>m2 : typeof m2 + + export let k = a; +>k : string +>a : string + + export let l: string = b, m = k; +>l : string +>b : string +>m : string +>k : string + + let n = m1.k; +>n : string +>m1.k : string +>m1 : typeof m1 +>k : string + + let o: string = n, p = k; +>o : string +>n : string +>p : string +>k : string +} diff --git a/tests/baselines/reference/es6ModuleModuleDeclaration.js b/tests/baselines/reference/es6ModuleModuleDeclaration.js new file mode 100644 index 0000000000000..c240545239f85 --- /dev/null +++ b/tests/baselines/reference/es6ModuleModuleDeclaration.js @@ -0,0 +1,57 @@ +//// [es6ModuleModuleDeclaration.ts] +export module m1 { + export var a = 10; + var b = 10; + export module innerExportedModule { + export var k = 10; + var l = 10; + } + export module innerNonExportedModule { + export var x = 10; + var y = 10; + } +} +module m2 { + export var a = 10; + var b = 10; + export module innerExportedModule { + export var k = 10; + var l = 10; + } + export module innerNonExportedModule { + export var x = 10; + var y = 10; + } +} + +//// [es6ModuleModuleDeclaration.js] +export var m1; +(function (m1) { + m1.a = 10; + var b = 10; + var innerExportedModule; + (function (innerExportedModule) { + innerExportedModule.k = 10; + var l = 10; + })(innerExportedModule = m1.innerExportedModule || (m1.innerExportedModule = {})); + var innerNonExportedModule; + (function (innerNonExportedModule) { + innerNonExportedModule.x = 10; + var y = 10; + })(innerNonExportedModule = m1.innerNonExportedModule || (m1.innerNonExportedModule = {})); +})(m1 || (m1 = {})); +var m2; +(function (m2) { + m2.a = 10; + var b = 10; + var innerExportedModule; + (function (innerExportedModule) { + innerExportedModule.k = 10; + var l = 10; + })(innerExportedModule = m2.innerExportedModule || (m2.innerExportedModule = {})); + var innerNonExportedModule; + (function (innerNonExportedModule) { + innerNonExportedModule.x = 10; + var y = 10; + })(innerNonExportedModule = m2.innerNonExportedModule || (m2.innerNonExportedModule = {})); +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleModuleDeclaration.types b/tests/baselines/reference/es6ModuleModuleDeclaration.types new file mode 100644 index 0000000000000..c174fe6f8c7c6 --- /dev/null +++ b/tests/baselines/reference/es6ModuleModuleDeclaration.types @@ -0,0 +1,57 @@ +=== tests/cases/compiler/es6ModuleModuleDeclaration.ts === +export module m1 { +>m1 : typeof m1 + + export var a = 10; +>a : number + + var b = 10; +>b : number + + export module innerExportedModule { +>innerExportedModule : typeof innerExportedModule + + export var k = 10; +>k : number + + var l = 10; +>l : number + } + export module innerNonExportedModule { +>innerNonExportedModule : typeof innerNonExportedModule + + export var x = 10; +>x : number + + var y = 10; +>y : number + } +} +module m2 { +>m2 : typeof m2 + + export var a = 10; +>a : number + + var b = 10; +>b : number + + export module innerExportedModule { +>innerExportedModule : typeof innerExportedModule + + export var k = 10; +>k : number + + var l = 10; +>l : number + } + export module innerNonExportedModule { +>innerNonExportedModule : typeof innerNonExportedModule + + export var x = 10; +>x : number + + var y = 10; +>y : number + } +} diff --git a/tests/baselines/reference/es6ModuleVariableStatement.js b/tests/baselines/reference/es6ModuleVariableStatement.js new file mode 100644 index 0000000000000..50c9c3fb4a84b --- /dev/null +++ b/tests/baselines/reference/es6ModuleVariableStatement.js @@ -0,0 +1,37 @@ +//// [es6ModuleVariableStatement.ts] +export var a = "hello"; +export var x: string = a, y = x; +var b = y; +var c: string = b, d = c; +export module m1 { + export var k = a; + export var l: string = b, m = k; + var n = m1.k; + var o: string = n, p = k; +} +module m2 { + export var k = a; + export var l: string = b, m = k; + var n = m1.k; + var o: string = n, p = k; +} + +//// [es6ModuleVariableStatement.js] +export var a = "hello"; +export var x = a, y = x; +var b = y; +var c = b, d = c; +export var m1; +(function (m1) { + m1.k = a; + m1.l = b, m1.m = m1.k; + var n = m1.k; + var o = n, p = m1.k; +})(m1 || (m1 = {})); +var m2; +(function (m2) { + m2.k = a; + m2.l = b, m2.m = m2.k; + var n = m1.k; + var o = n, p = m2.k; +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleVariableStatement.types b/tests/baselines/reference/es6ModuleVariableStatement.types new file mode 100644 index 0000000000000..a10d8f6cacbc4 --- /dev/null +++ b/tests/baselines/reference/es6ModuleVariableStatement.types @@ -0,0 +1,70 @@ +=== tests/cases/compiler/es6ModuleVariableStatement.ts === +export var a = "hello"; +>a : string + +export var x: string = a, y = x; +>x : string +>a : string +>y : string +>x : string + +var b = y; +>b : string +>y : string + +var c: string = b, d = c; +>c : string +>b : string +>d : string +>c : string + +export module m1 { +>m1 : typeof m1 + + export var k = a; +>k : string +>a : string + + export var l: string = b, m = k; +>l : string +>b : string +>m : string +>k : string + + var n = m1.k; +>n : string +>m1.k : string +>m1 : typeof m1 +>k : string + + var o: string = n, p = k; +>o : string +>n : string +>p : string +>k : string +} +module m2 { +>m2 : typeof m2 + + export var k = a; +>k : string +>a : string + + export var l: string = b, m = k; +>l : string +>b : string +>m : string +>k : string + + var n = m1.k; +>n : string +>m1.k : string +>m1 : typeof m1 +>k : string + + var o: string = n, p = k; +>o : string +>n : string +>p : string +>k : string +} diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.errors.txt b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.errors.txt new file mode 100644 index 0000000000000..bbe0d8b78b65f --- /dev/null +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.errors.txt @@ -0,0 +1,16 @@ +error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. + + +!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +==== tests/cases/compiler/es6ModuleWithModuleGenTargetAmd.ts (0 errors) ==== + export class A + { + constructor () + { + } + + public B() + { + return 42; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js new file mode 100644 index 0000000000000..8757bd1c88f52 --- /dev/null +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js @@ -0,0 +1,21 @@ +//// [es6ModuleWithModuleGenTargetAmd.ts] +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} + +//// [es6ModuleWithModuleGenTargetAmd.js] +export class A { + constructor() { + } + B() { + return 42; + } +} diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.errors.txt b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.errors.txt new file mode 100644 index 0000000000000..87f53cb781041 --- /dev/null +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.errors.txt @@ -0,0 +1,16 @@ +error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. + + +!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +==== tests/cases/compiler/es6ModuleWithModuleGenTargetCommonjs.ts (0 errors) ==== + export class A + { + constructor () + { + } + + public B() + { + return 42; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.js b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.js new file mode 100644 index 0000000000000..2df98e20826aa --- /dev/null +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.js @@ -0,0 +1,21 @@ +//// [es6ModuleWithModuleGenTargetCommonjs.ts] +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} + +//// [es6ModuleWithModuleGenTargetCommonjs.js] +export class A { + constructor() { + } + B() { + return 42; + } +} diff --git a/tests/baselines/reference/exportAssignmentEnum.js b/tests/baselines/reference/exportAssignmentEnum.js index 7b9981d97337c..a484e43738fda 100644 --- a/tests/baselines/reference/exportAssignmentEnum.js +++ b/tests/baselines/reference/exportAssignmentEnum.js @@ -26,6 +26,6 @@ var E; module.exports = E; //// [exportAssignmentEnum_B.js] var EnumE = require("exportAssignmentEnum_A"); -var a = 0 /* A */; -var b = 1 /* B */; -var c = 2 /* C */; +var a = EnumE.A; +var b = EnumE.B; +var c = EnumE.C; diff --git a/tests/baselines/reference/exportAssignmentTopLevelEnumdule.js b/tests/baselines/reference/exportAssignmentTopLevelEnumdule.js index fe6b80292d5e5..791fc4fbd7f96 100644 --- a/tests/baselines/reference/exportAssignmentTopLevelEnumdule.js +++ b/tests/baselines/reference/exportAssignmentTopLevelEnumdule.js @@ -34,7 +34,7 @@ define(["require", "exports"], function (require, exports) { //// [foo_1.js] define(["require", "exports", "./foo_0"], function (require, exports, foo) { var color; - if (color === 1 /* green */) { + if (color === foo.green) { color = foo.answer; } }); diff --git a/tests/baselines/reference/exportDefaultForNonInstantiatedModule.js b/tests/baselines/reference/exportDefaultForNonInstantiatedModule.js new file mode 100644 index 0000000000000..f2b98e6eb4459 --- /dev/null +++ b/tests/baselines/reference/exportDefaultForNonInstantiatedModule.js @@ -0,0 +1,10 @@ +//// [exportDefaultForNonInstantiatedModule.ts] + +module m { + export interface foo { + } +} +// Should not be emitted +export default m; + +//// [exportDefaultForNonInstantiatedModule.js] diff --git a/tests/baselines/reference/exportDefaultForNonInstantiatedModule.types b/tests/baselines/reference/exportDefaultForNonInstantiatedModule.types new file mode 100644 index 0000000000000..940bb44658e8a --- /dev/null +++ b/tests/baselines/reference/exportDefaultForNonInstantiatedModule.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/exportDefaultForNonInstantiatedModule.ts === + +module m { +>m : unknown + + export interface foo { +>foo : foo + } +} +// Should not be emitted +export default m; +>m : unknown + diff --git a/tests/baselines/reference/exportDefaultTypeAnnoation.errors.txt b/tests/baselines/reference/exportDefaultTypeAnnoation.errors.txt new file mode 100644 index 0000000000000..71ff4261ffef8 --- /dev/null +++ b/tests/baselines/reference/exportDefaultTypeAnnoation.errors.txt @@ -0,0 +1,8 @@ +tests/cases/compiler/exportDefaultTypeAnnoation.ts(2,18): error TS1201: A type annotation on an export statement is only allowed in an ambient external module declaration. + + +==== tests/cases/compiler/exportDefaultTypeAnnoation.ts (1 errors) ==== + + export default : number; + ~~~~~~ +!!! error TS1201: A type annotation on an export statement is only allowed in an ambient external module declaration. \ No newline at end of file diff --git a/tests/baselines/reference/exportDefaultTypeAnnoation.js b/tests/baselines/reference/exportDefaultTypeAnnoation.js new file mode 100644 index 0000000000000..71a829ac2848c --- /dev/null +++ b/tests/baselines/reference/exportDefaultTypeAnnoation.js @@ -0,0 +1,6 @@ +//// [exportDefaultTypeAnnoation.ts] + +export default : number; + +//// [exportDefaultTypeAnnoation.js] +exports.default = ; diff --git a/tests/baselines/reference/exportDefaultTypeAnnoation2.js b/tests/baselines/reference/exportDefaultTypeAnnoation2.js new file mode 100644 index 0000000000000..2c918954702b6 --- /dev/null +++ b/tests/baselines/reference/exportDefaultTypeAnnoation2.js @@ -0,0 +1,7 @@ +//// [exportDefaultTypeAnnoation2.ts] + +declare module "mod" { + export default : number; +} + +//// [exportDefaultTypeAnnoation2.js] diff --git a/tests/baselines/reference/exportDefaultTypeAnnoation2.types b/tests/baselines/reference/exportDefaultTypeAnnoation2.types new file mode 100644 index 0000000000000..53ca78586ccd5 --- /dev/null +++ b/tests/baselines/reference/exportDefaultTypeAnnoation2.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/exportDefaultTypeAnnoation2.ts === + +No type information for this code.declare module "mod" { +No type information for this code. export default : number; +No type information for this code.} +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/exportDefaultTypeAnnoation3.errors.txt b/tests/baselines/reference/exportDefaultTypeAnnoation3.errors.txt new file mode 100644 index 0000000000000..326713e059e72 --- /dev/null +++ b/tests/baselines/reference/exportDefaultTypeAnnoation3.errors.txt @@ -0,0 +1,21 @@ +tests/cases/compiler/reference1.ts(2,5): error TS2322: Type 'number' is not assignable to type 'string'. +tests/cases/compiler/reference2.ts(2,5): error TS2322: Type 'number' is not assignable to type 'string'. + + +==== tests/cases/compiler/mod.d.ts (0 errors) ==== + + declare module "mod" { + export default : number; + } + +==== tests/cases/compiler/reference1.ts (1 errors) ==== + import d from "mod"; + var s: string = d; // Error + ~ +!!! error TS2322: Type 'number' is not assignable to type 'string'. + +==== tests/cases/compiler/reference2.ts (1 errors) ==== + import { default as d } from "mod"; + var s: string = d; // Error + ~ +!!! error TS2322: Type 'number' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/exportDefaultTypeAnnoation3.js b/tests/baselines/reference/exportDefaultTypeAnnoation3.js new file mode 100644 index 0000000000000..1f95e669de5d9 --- /dev/null +++ b/tests/baselines/reference/exportDefaultTypeAnnoation3.js @@ -0,0 +1,22 @@ +//// [tests/cases/compiler/exportDefaultTypeAnnoation3.ts] //// + +//// [mod.d.ts] + +declare module "mod" { + export default : number; +} + +//// [reference1.ts] +import d from "mod"; +var s: string = d; // Error + +//// [reference2.ts] +import { default as d } from "mod"; +var s: string = d; // Error + +//// [reference1.js] +var mod_1 = require("mod"); +var s = mod_1.default; // Error +//// [reference2.js] +var mod_1 = require("mod"); +var s = mod_1.default; // Error diff --git a/tests/baselines/reference/exportStar-amd.js b/tests/baselines/reference/exportStar-amd.js index 36d0904a1860d..fb04aa208b22b 100644 --- a/tests/baselines/reference/exportStar-amd.js +++ b/tests/baselines/reference/exportStar-amd.js @@ -51,19 +51,19 @@ define(["require", "exports"], function (require, exports) { exports.z = z; }); //// [t4.js] -define(["require", "exports", "./t1", "./t2", "./t3"], function (require, exports, _t1, _t2, _t3) { +define(["require", "exports", "./t1", "./t2", "./t3"], function (require, exports, t1_1, t2_1, t3_1) { function __export(m) { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; } - __export(_t1); - __export(_t2); - __export(_t3); + __export(t1_1); + __export(t2_1); + __export(t3_1); }); //// [main.js] -define(["require", "exports", "./t4"], function (require, exports, _t4) { - _t4.default; - _t4.x; - _t4.y; - _t4.z; - _t4.foo; +define(["require", "exports", "./t4"], function (require, exports, t4_1) { + t4_1.default; + t4_1.x; + t4_1.y; + t4_1.z; + t4_1.foo; }); diff --git a/tests/baselines/reference/exportStar.js b/tests/baselines/reference/exportStar.js index 070dd90b1dbd2..9fca12af8b153 100644 --- a/tests/baselines/reference/exportStar.js +++ b/tests/baselines/reference/exportStar.js @@ -52,9 +52,9 @@ __export(require("./t1")); __export(require("./t2")); __export(require("./t3")); //// [main.js] -var _t4 = require("./t4"); -_t4.default; -_t4.x; -_t4.y; -_t4.z; -_t4.foo; +var t4_1 = require("./t4"); +t4_1.default; +t4_1.x; +t4_1.y; +t4_1.z; +t4_1.foo; diff --git a/tests/baselines/reference/exportsAndImports1-amd.js b/tests/baselines/reference/exportsAndImports1-amd.js index ac0d56769bb42..99c6fe8d43fe4 100644 --- a/tests/baselines/reference/exportsAndImports1-amd.js +++ b/tests/baselines/reference/exportsAndImports1-amd.js @@ -63,20 +63,20 @@ define(["require", "exports"], function (require, exports) { exports.a = a; }); //// [t2.js] -define(["require", "exports", "./t1"], function (require, exports, _t1) { - exports.v = _t1.v; - exports.f = _t1.f; - exports.C = _t1.C; - exports.E = _t1.E; - exports.M = _t1.M; - exports.a = _t1.a; +define(["require", "exports", "./t1"], function (require, exports, t1_1) { + exports.v = t1_1.v; + exports.f = t1_1.f; + exports.C = t1_1.C; + exports.E = t1_1.E; + exports.M = t1_1.M; + exports.a = t1_1.a; }); //// [t3.js] -define(["require", "exports", "./t1"], function (require, exports, _t1) { - exports.v = _t1.v; - exports.f = _t1.f; - exports.C = _t1.C; - exports.E = _t1.E; - exports.M = _t1.M; - exports.a = _t1.a; +define(["require", "exports", "./t1"], function (require, exports, t1_1) { + exports.v = t1_1.v; + exports.f = t1_1.f; + exports.C = t1_1.C; + exports.E = t1_1.E; + exports.M = t1_1.M; + exports.a = t1_1.a; }); diff --git a/tests/baselines/reference/exportsAndImports1.js b/tests/baselines/reference/exportsAndImports1.js index 2e396c1c72b1a..f381e6b724212 100644 --- a/tests/baselines/reference/exportsAndImports1.js +++ b/tests/baselines/reference/exportsAndImports1.js @@ -61,18 +61,18 @@ exports.M = M; var a = M.x; exports.a = a; //// [t2.js] -var _t1 = require("./t1"); -exports.v = _t1.v; -exports.f = _t1.f; -exports.C = _t1.C; -exports.E = _t1.E; -exports.M = _t1.M; -exports.a = _t1.a; +var t1_1 = require("./t1"); +exports.v = t1_1.v; +exports.f = t1_1.f; +exports.C = t1_1.C; +exports.E = t1_1.E; +exports.M = t1_1.M; +exports.a = t1_1.a; //// [t3.js] -var _t1 = require("./t1"); -exports.v = _t1.v; -exports.f = _t1.f; -exports.C = _t1.C; -exports.E = _t1.E; -exports.M = _t1.M; -exports.a = _t1.a; +var t1_1 = require("./t1"); +exports.v = t1_1.v; +exports.f = t1_1.f; +exports.C = t1_1.C; +exports.E = t1_1.E; +exports.M = t1_1.M; +exports.a = t1_1.a; diff --git a/tests/baselines/reference/exportsAndImports2-amd.js b/tests/baselines/reference/exportsAndImports2-amd.js index a958c5dd77192..10f524de68441 100644 --- a/tests/baselines/reference/exportsAndImports2-amd.js +++ b/tests/baselines/reference/exportsAndImports2-amd.js @@ -19,12 +19,12 @@ define(["require", "exports"], function (require, exports) { exports.y = "y"; }); //// [t2.js] -define(["require", "exports", "./t1"], function (require, exports, _t1) { - exports.y = _t1.x; - exports.x = _t1.y; +define(["require", "exports", "./t1"], function (require, exports, t1_1) { + exports.y = t1_1.x; + exports.x = t1_1.y; }); //// [t3.js] -define(["require", "exports", "./t1"], function (require, exports, _t1) { - exports.y = _t1.x; - exports.x = _t1.y; +define(["require", "exports", "./t1"], function (require, exports, t1_1) { + exports.y = t1_1.x; + exports.x = t1_1.y; }); diff --git a/tests/baselines/reference/exportsAndImports2.js b/tests/baselines/reference/exportsAndImports2.js index 3773dc624c87b..96a3b838ed1ec 100644 --- a/tests/baselines/reference/exportsAndImports2.js +++ b/tests/baselines/reference/exportsAndImports2.js @@ -17,10 +17,10 @@ export { x as y, y as x }; exports.x = "x"; exports.y = "y"; //// [t2.js] -var _t1 = require("./t1"); -exports.y = _t1.x; -exports.x = _t1.y; +var t1_1 = require("./t1"); +exports.y = t1_1.x; +exports.x = t1_1.y; //// [t3.js] -var _t1 = require("./t1"); -exports.y = _t1.x; -exports.x = _t1.y; +var t1_1 = require("./t1"); +exports.y = t1_1.x; +exports.x = t1_1.y; diff --git a/tests/baselines/reference/exportsAndImports3-amd.js b/tests/baselines/reference/exportsAndImports3-amd.js index 443358eafd021..613598cc0ee77 100644 --- a/tests/baselines/reference/exportsAndImports3-amd.js +++ b/tests/baselines/reference/exportsAndImports3-amd.js @@ -65,20 +65,20 @@ define(["require", "exports"], function (require, exports) { exports.a1 = exports.a; }); //// [t2.js] -define(["require", "exports", "./t1"], function (require, exports, _t1) { - exports.v = _t1.v1; - exports.f = _t1.f1; - exports.C = _t1.C1; - exports.E = _t1.E1; - exports.M = _t1.M1; - exports.a = _t1.a1; +define(["require", "exports", "./t1"], function (require, exports, t1_1) { + exports.v = t1_1.v1; + exports.f = t1_1.f1; + exports.C = t1_1.C1; + exports.E = t1_1.E1; + exports.M = t1_1.M1; + exports.a = t1_1.a1; }); //// [t3.js] -define(["require", "exports", "./t1"], function (require, exports, _t1) { - exports.v = _t1.v1; - exports.f = _t1.f1; - exports.C = _t1.C1; - exports.E = _t1.E1; - exports.M = _t1.M1; - exports.a = _t1.a1; +define(["require", "exports", "./t1"], function (require, exports, t1_1) { + exports.v = t1_1.v1; + exports.f = t1_1.f1; + exports.C = t1_1.C1; + exports.E = t1_1.E1; + exports.M = t1_1.M1; + exports.a = t1_1.a1; }); diff --git a/tests/baselines/reference/exportsAndImports3.js b/tests/baselines/reference/exportsAndImports3.js index d4ebe982f895d..f06a6f684d0e4 100644 --- a/tests/baselines/reference/exportsAndImports3.js +++ b/tests/baselines/reference/exportsAndImports3.js @@ -63,18 +63,18 @@ exports.M1 = exports.M; exports.a = M.x; exports.a1 = exports.a; //// [t2.js] -var _t1 = require("./t1"); -exports.v = _t1.v1; -exports.f = _t1.f1; -exports.C = _t1.C1; -exports.E = _t1.E1; -exports.M = _t1.M1; -exports.a = _t1.a1; +var t1_1 = require("./t1"); +exports.v = t1_1.v1; +exports.f = t1_1.f1; +exports.C = t1_1.C1; +exports.E = t1_1.E1; +exports.M = t1_1.M1; +exports.a = t1_1.a1; //// [t3.js] -var _t1 = require("./t1"); -exports.v = _t1.v1; -exports.f = _t1.f1; -exports.C = _t1.C1; -exports.E = _t1.E1; -exports.M = _t1.M1; -exports.a = _t1.a1; +var t1_1 = require("./t1"); +exports.v = t1_1.v1; +exports.f = t1_1.f1; +exports.C = t1_1.C1; +exports.E = t1_1.E1; +exports.M = t1_1.M1; +exports.a = t1_1.a1; diff --git a/tests/baselines/reference/exportsAndImports4-amd.js b/tests/baselines/reference/exportsAndImports4-amd.js index 08342c566007b..db28ed5b35009 100644 --- a/tests/baselines/reference/exportsAndImports4-amd.js +++ b/tests/baselines/reference/exportsAndImports4-amd.js @@ -44,22 +44,22 @@ define(["require", "exports"], function (require, exports) { exports.default = "hello"; }); //// [t3.js] -define(["require", "exports", "./t1", "./t1", "./t1", "./t1", "./t1", "./t1"], function (require, exports, a, _t1, c, _t1_2, _t1_3, _t1_4) { +define(["require", "exports", "./t1", "./t1", "./t1", "./t1", "./t1", "./t1"], function (require, exports, a, t1_1, c, t1_2, t1_3, t1_4) { exports.a = a; a.default; - exports.b = _t1.default; - _t1.default; + exports.b = t1_1.default; + t1_1.default; exports.c = c; c.default; - exports.d = _t1_2.default; - _t1_2.default; - var e2 = _t1_3; - exports.e1 = _t1_3.default; + exports.d = t1_2.default; + t1_2.default; + var e2 = t1_3; + exports.e1 = t1_3.default; exports.e2 = e2; - _t1_3.default; + t1_3.default; e2.default; - exports.f1 = _t1_4.default; - exports.f2 = _t1_4.default; - _t1_4.default; - _t1_4.default; + exports.f1 = t1_4.default; + exports.f2 = t1_4.default; + t1_4.default; + t1_4.default; }); diff --git a/tests/baselines/reference/exportsAndImports4.js b/tests/baselines/reference/exportsAndImports4.js index 05f0285472964..ea5f34b882be8 100644 --- a/tests/baselines/reference/exportsAndImports4.js +++ b/tests/baselines/reference/exportsAndImports4.js @@ -45,22 +45,22 @@ exports.default = "hello"; var a = require("./t1"); exports.a = a; a.default; -var _t1 = require("./t1"); -exports.b = _t1.default; -_t1.default; +var t1_1 = require("./t1"); +exports.b = t1_1.default; +t1_1.default; var c = require("./t1"); exports.c = c; c.default; -var _t1_2 = require("./t1"); -exports.d = _t1_2.default; -_t1_2.default; -var _t1_3 = require("./t1"), e2 = _t1_3; -exports.e1 = _t1_3.default; +var t1_2 = require("./t1"); +exports.d = t1_2.default; +t1_2.default; +var t1_3 = require("./t1"), e2 = t1_3; +exports.e1 = t1_3.default; exports.e2 = e2; -_t1_3.default; +t1_3.default; e2.default; -var _t1_4 = require("./t1"); -exports.f1 = _t1_4.default; -exports.f2 = _t1_4.default; -_t1_4.default; -_t1_4.default; +var t1_4 = require("./t1"); +exports.f1 = t1_4.default; +exports.f2 = t1_4.default; +t1_4.default; +t1_4.default; diff --git a/tests/baselines/reference/externalModuleImmutableBindings.errors.txt b/tests/baselines/reference/externalModuleImmutableBindings.errors.txt new file mode 100644 index 0000000000000..09cc7b3329578 --- /dev/null +++ b/tests/baselines/reference/externalModuleImmutableBindings.errors.txt @@ -0,0 +1,164 @@ +tests/cases/compiler/f2.ts(5,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/f2.ts(6,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/f2.ts(7,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/f2.ts(7,7): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. +tests/cases/compiler/f2.ts(8,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/f2.ts(10,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/compiler/f2.ts(11,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/compiler/f2.ts(12,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/compiler/f2.ts(13,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/compiler/f2.ts(15,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/f2.ts(16,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/f2.ts(17,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/f2.ts(17,8): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. +tests/cases/compiler/f2.ts(18,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/f2.ts(20,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/compiler/f2.ts(21,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/compiler/f2.ts(22,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/compiler/f2.ts(23,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/compiler/f2.ts(25,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. +tests/cases/compiler/f2.ts(26,6): error TS2487: Invalid left-hand side in 'for...of' statement. +tests/cases/compiler/f2.ts(27,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. +tests/cases/compiler/f2.ts(28,6): error TS2487: Invalid left-hand side in 'for...of' statement. +tests/cases/compiler/f2.ts(29,6): error TS2406: Invalid left-hand side in 'for...in' statement. +tests/cases/compiler/f2.ts(29,12): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. +tests/cases/compiler/f2.ts(30,6): error TS2487: Invalid left-hand side in 'for...of' statement. +tests/cases/compiler/f2.ts(30,12): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. +tests/cases/compiler/f2.ts(31,6): error TS2406: Invalid left-hand side in 'for...in' statement. +tests/cases/compiler/f2.ts(32,6): error TS2487: Invalid left-hand side in 'for...of' statement. +tests/cases/compiler/f2.ts(34,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. +tests/cases/compiler/f2.ts(35,6): error TS2487: Invalid left-hand side in 'for...of' statement. +tests/cases/compiler/f2.ts(36,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. +tests/cases/compiler/f2.ts(37,6): error TS2487: Invalid left-hand side in 'for...of' statement. +tests/cases/compiler/f2.ts(38,6): error TS2406: Invalid left-hand side in 'for...in' statement. +tests/cases/compiler/f2.ts(38,13): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. +tests/cases/compiler/f2.ts(39,6): error TS2487: Invalid left-hand side in 'for...of' statement. +tests/cases/compiler/f2.ts(39,13): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. +tests/cases/compiler/f2.ts(40,6): error TS2406: Invalid left-hand side in 'for...in' statement. +tests/cases/compiler/f2.ts(41,6): error TS2487: Invalid left-hand side in 'for...of' statement. + + +==== tests/cases/compiler/f1.ts (0 errors) ==== + export var x = 1; + +==== tests/cases/compiler/f2.ts (38 errors) ==== + import * as stuff from 'f1'; + + var n = 'baz'; + + stuff.x = 0; + ~~~~~~~ +!!! error TS2364: Invalid left-hand side of assignment expression. + stuff['x'] = 1; + ~~~~~~~~~~ +!!! error TS2364: Invalid left-hand side of assignment expression. + stuff.blah = 2; + ~~~~~~~~~~ +!!! error TS2364: Invalid left-hand side of assignment expression. + ~~~~ +!!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. + stuff[n] = 3; + ~~~~~~~~ +!!! error TS2364: Invalid left-hand side of assignment expression. + + stuff.x++; + ~~~~~~~ +!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. + stuff['x']++; + ~~~~~~~~~~ +!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. + stuff['blah']++; + ~~~~~~~~~~~~~ +!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. + stuff[n]++; + ~~~~~~~~ +!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. + + (stuff.x) = 0; + ~~~~~~~~~ +!!! error TS2364: Invalid left-hand side of assignment expression. + (stuff['x']) = 1; + ~~~~~~~~~~~~ +!!! error TS2364: Invalid left-hand side of assignment expression. + (stuff.blah) = 2; + ~~~~~~~~~~~~ +!!! error TS2364: Invalid left-hand side of assignment expression. + ~~~~ +!!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. + (stuff[n]) = 3; + ~~~~~~~~~~ +!!! error TS2364: Invalid left-hand side of assignment expression. + + (stuff.x)++; + ~~~~~~~~~ +!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. + (stuff['x'])++; + ~~~~~~~~~~~~ +!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. + (stuff['blah'])++; + ~~~~~~~~~~~~~~~ +!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. + (stuff[n])++; + ~~~~~~~~~~ +!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. + + for (stuff.x in []) {} + ~~~~~~~ +!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. + for (stuff.x of []) {} + ~~~~~~~ +!!! error TS2487: Invalid left-hand side in 'for...of' statement. + for (stuff['x'] in []) {} + ~~~~~~~~~~ +!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. + for (stuff['x'] of []) {} + ~~~~~~~~~~ +!!! error TS2487: Invalid left-hand side in 'for...of' statement. + for (stuff.blah in []) {} + ~~~~~~~~~~ +!!! error TS2406: Invalid left-hand side in 'for...in' statement. + ~~~~ +!!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. + for (stuff.blah of []) {} + ~~~~~~~~~~ +!!! error TS2487: Invalid left-hand side in 'for...of' statement. + ~~~~ +!!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. + for (stuff[n] in []) {} + ~~~~~~~~ +!!! error TS2406: Invalid left-hand side in 'for...in' statement. + for (stuff[n] of []) {} + ~~~~~~~~ +!!! error TS2487: Invalid left-hand side in 'for...of' statement. + + for ((stuff.x) in []) {} + ~~~~~~~~~ +!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. + for ((stuff.x) of []) {} + ~~~~~~~~~ +!!! error TS2487: Invalid left-hand side in 'for...of' statement. + for ((stuff['x']) in []) {} + ~~~~~~~~~~~~ +!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. + for ((stuff['x']) of []) {} + ~~~~~~~~~~~~ +!!! error TS2487: Invalid left-hand side in 'for...of' statement. + for ((stuff.blah) in []) {} + ~~~~~~~~~~~~ +!!! error TS2406: Invalid left-hand side in 'for...in' statement. + ~~~~ +!!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. + for ((stuff.blah) of []) {} + ~~~~~~~~~~~~ +!!! error TS2487: Invalid left-hand side in 'for...of' statement. + ~~~~ +!!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. + for ((stuff[n]) in []) {} + ~~~~~~~~~~ +!!! error TS2406: Invalid left-hand side in 'for...in' statement. + for ((stuff[n]) of []) {} + ~~~~~~~~~~ +!!! error TS2487: Invalid left-hand side in 'for...of' statement. + + + \ No newline at end of file diff --git a/tests/baselines/reference/externalModuleImmutableBindings.js b/tests/baselines/reference/externalModuleImmutableBindings.js new file mode 100644 index 0000000000000..546b593fa77b7 --- /dev/null +++ b/tests/baselines/reference/externalModuleImmutableBindings.js @@ -0,0 +1,112 @@ +//// [tests/cases/compiler/externalModuleImmutableBindings.ts] //// + +//// [f1.ts] +export var x = 1; + +//// [f2.ts] +import * as stuff from 'f1'; + +var n = 'baz'; + +stuff.x = 0; +stuff['x'] = 1; +stuff.blah = 2; +stuff[n] = 3; + +stuff.x++; +stuff['x']++; +stuff['blah']++; +stuff[n]++; + +(stuff.x) = 0; +(stuff['x']) = 1; +(stuff.blah) = 2; +(stuff[n]) = 3; + +(stuff.x)++; +(stuff['x'])++; +(stuff['blah'])++; +(stuff[n])++; + +for (stuff.x in []) {} +for (stuff.x of []) {} +for (stuff['x'] in []) {} +for (stuff['x'] of []) {} +for (stuff.blah in []) {} +for (stuff.blah of []) {} +for (stuff[n] in []) {} +for (stuff[n] of []) {} + +for ((stuff.x) in []) {} +for ((stuff.x) of []) {} +for ((stuff['x']) in []) {} +for ((stuff['x']) of []) {} +for ((stuff.blah) in []) {} +for ((stuff.blah) of []) {} +for ((stuff[n]) in []) {} +for ((stuff[n]) of []) {} + + + + +//// [f1.js] +exports.x = 1; +//// [f2.js] +var stuff = require('f1'); +var n = 'baz'; +stuff.x = 0; +stuff['x'] = 1; +stuff.blah = 2; +stuff[n] = 3; +stuff.x++; +stuff['x']++; +stuff['blah']++; +stuff[n]++; +(stuff.x) = 0; +(stuff['x']) = 1; +(stuff.blah) = 2; +(stuff[n]) = 3; +(stuff.x)++; +(stuff['x'])++; +(stuff['blah'])++; +(stuff[n])++; +for (stuff.x in []) { +} +for (var _i = 0, _a = []; _i < _a.length; _i++) { + stuff.x = _a[_i]; +} +for (stuff['x'] in []) { +} +for (var _b = 0, _c = []; _b < _c.length; _b++) { + stuff['x'] = _c[_b]; +} +for (stuff.blah in []) { +} +for (var _d = 0, _e = []; _d < _e.length; _d++) { + stuff.blah = _e[_d]; +} +for (stuff[n] in []) { +} +for (var _f = 0, _g = []; _f < _g.length; _f++) { + stuff[n] = _g[_f]; +} +for ((stuff.x) in []) { +} +for (var _h = 0, _j = []; _h < _j.length; _h++) { + (stuff.x) = _j[_h]; +} +for ((stuff['x']) in []) { +} +for (var _k = 0, _l = []; _k < _l.length; _k++) { + (stuff['x']) = _l[_k]; +} +for ((stuff.blah) in []) { +} +for (var _m = 0, _o = []; _m < _o.length; _m++) { + (stuff.blah) = _o[_m]; +} +for ((stuff[n]) in []) { +} +for (var _p = 0, _q = []; _p < _q.length; _p++) { + (stuff[n]) = _q[_p]; +} diff --git a/tests/baselines/reference/fileWithNextLine1.js b/tests/baselines/reference/fileWithNextLine1.js new file mode 100644 index 0000000000000..a89c5b3e2077d --- /dev/null +++ b/tests/baselines/reference/fileWithNextLine1.js @@ -0,0 +1,9 @@ +//// [fileWithNextLine1.ts] +// Note: there is a nextline (0x85) in the string +// 0. It should be counted as a space and should not cause an error. +var v = '…'; + +//// [fileWithNextLine1.js] +// Note: there is a nextline (0x85) in the string +// 0. It should be counted as a space and should not cause an error. +var v = '…'; diff --git a/tests/baselines/reference/fileWithNextLine1.types b/tests/baselines/reference/fileWithNextLine1.types new file mode 100644 index 0000000000000..721b3d6fb101e --- /dev/null +++ b/tests/baselines/reference/fileWithNextLine1.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/fileWithNextLine1.ts === +// Note: there is a nextline (0x85) in the string +// 0. It should be counted as a space and should not cause an error. +var v = '…'; +>v : string + diff --git a/tests/baselines/reference/fileWithNextLine2.js b/tests/baselines/reference/fileWithNextLine2.js new file mode 100644 index 0000000000000..439b9bd42f902 --- /dev/null +++ b/tests/baselines/reference/fileWithNextLine2.js @@ -0,0 +1,9 @@ +//// [fileWithNextLine2.ts] +// Note: there is a nextline (0x85) char between the = and the 0. +// it should be treated like a space +var v =…0; + +//// [fileWithNextLine2.js] +// Note: there is a nextline (0x85) char between the = and the 0. +// it should be treated like a space +var v = 0; diff --git a/tests/baselines/reference/fileWithNextLine2.types b/tests/baselines/reference/fileWithNextLine2.types new file mode 100644 index 0000000000000..8a6de1a4b2f99 --- /dev/null +++ b/tests/baselines/reference/fileWithNextLine2.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/fileWithNextLine2.ts === +// Note: there is a nextline (0x85) char between the = and the 0. +// it should be treated like a space +var v =…0; +>v : number + diff --git a/tests/baselines/reference/fileWithNextLine3.errors.txt b/tests/baselines/reference/fileWithNextLine3.errors.txt new file mode 100644 index 0000000000000..647ec722549ab --- /dev/null +++ b/tests/baselines/reference/fileWithNextLine3.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/fileWithNextLine3.ts(3,1): error TS1108: A 'return' statement can only be used within a function body. + + +==== tests/cases/compiler/fileWithNextLine3.ts (1 errors) ==== + // Note: there is a nextline (0x85) between the return and the + // 0. It should be counted as a space and should not trigger ASI + return…0; + ~~~~~~ +!!! error TS1108: A 'return' statement can only be used within a function body. \ No newline at end of file diff --git a/tests/baselines/reference/fileWithNextLine3.js b/tests/baselines/reference/fileWithNextLine3.js new file mode 100644 index 0000000000000..c1d4204bcaeea --- /dev/null +++ b/tests/baselines/reference/fileWithNextLine3.js @@ -0,0 +1,9 @@ +//// [fileWithNextLine3.ts] +// Note: there is a nextline (0x85) between the return and the +// 0. It should be counted as a space and should not trigger ASI +return…0; + +//// [fileWithNextLine3.js] +// Note: there is a nextline (0x85) between the return and the +// 0. It should be counted as a space and should not trigger ASI +return 0; diff --git a/tests/baselines/reference/for-inStatements.js b/tests/baselines/reference/for-inStatements.js index 08ef1dbcccd15..3787887923cd7 100644 --- a/tests/baselines/reference/for-inStatements.js +++ b/tests/baselines/reference/for-inStatements.js @@ -200,5 +200,5 @@ var Color; })(Color || (Color = {})); for (var x in Color) { } -for (var x in 1 /* Blue */) { +for (var x in Color.Blue) { } diff --git a/tests/baselines/reference/for-of14.js b/tests/baselines/reference/for-of14.js index 65ac7119fb610..958e621c8aa5b 100644 --- a/tests/baselines/reference/for-of14.js +++ b/tests/baselines/reference/for-of14.js @@ -12,11 +12,8 @@ class StringIterator { var v; for (v of new StringIterator) { } // Should fail because the iterator is not iterable -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype.next = function () { +class StringIterator { + next() { return ""; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of15.js b/tests/baselines/reference/for-of15.js index 74e34c2b2ae0c..2b4846ec8bef5 100644 --- a/tests/baselines/reference/for-of15.js +++ b/tests/baselines/reference/for-of15.js @@ -15,14 +15,11 @@ class StringIterator { var v; for (v of new StringIterator) { } // Should fail -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype.next = function () { +class StringIterator { + next() { return ""; - }; - StringIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of16.js b/tests/baselines/reference/for-of16.js index 526dc277be7c1..1cdf72c26ac03 100644 --- a/tests/baselines/reference/for-of16.js +++ b/tests/baselines/reference/for-of16.js @@ -12,11 +12,8 @@ class StringIterator { var v; for (v of new StringIterator) { } // Should fail -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype[Symbol.iterator] = function () { +class StringIterator { + [Symbol.iterator]() { return this; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of17.js b/tests/baselines/reference/for-of17.js index 268ead7ee18da..3fb4fac91d603 100644 --- a/tests/baselines/reference/for-of17.js +++ b/tests/baselines/reference/for-of17.js @@ -18,17 +18,14 @@ class NumberIterator { var v; for (v of new NumberIterator) { } // Should succeed -var NumberIterator = (function () { - function NumberIterator() { - } - NumberIterator.prototype.next = function () { +class NumberIterator { + next() { return { value: 0, done: false }; - }; - NumberIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return NumberIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of18.js b/tests/baselines/reference/for-of18.js index 3be876409dc4f..ae3a9e130f003 100644 --- a/tests/baselines/reference/for-of18.js +++ b/tests/baselines/reference/for-of18.js @@ -18,17 +18,14 @@ class StringIterator { var v; for (v of new StringIterator) { } // Should succeed -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype.next = function () { +class StringIterator { + next() { return { value: "", done: false }; - }; - StringIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of19.js b/tests/baselines/reference/for-of19.js index eefb9339f18bd..d0f95caa1e27d 100644 --- a/tests/baselines/reference/for-of19.js +++ b/tests/baselines/reference/for-of19.js @@ -20,22 +20,16 @@ class FooIterator { for (var v of new FooIterator) { v; } -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var FooIterator = (function () { - function FooIterator() { - } - FooIterator.prototype.next = function () { +class Foo { +} +class FooIterator { + next() { return { value: new Foo, done: false }; - }; - FooIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return FooIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of20.js b/tests/baselines/reference/for-of20.js index 39b1081954be7..c098abd2f73a0 100644 --- a/tests/baselines/reference/for-of20.js +++ b/tests/baselines/reference/for-of20.js @@ -20,22 +20,16 @@ class FooIterator { for (let v of new FooIterator) { v; } -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var FooIterator = (function () { - function FooIterator() { - } - FooIterator.prototype.next = function () { +class Foo { +} +class FooIterator { + next() { return { value: new Foo, done: false }; - }; - FooIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return FooIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of21.js b/tests/baselines/reference/for-of21.js index 5deaad3c2d8f6..27da28e3b4f40 100644 --- a/tests/baselines/reference/for-of21.js +++ b/tests/baselines/reference/for-of21.js @@ -20,22 +20,16 @@ class FooIterator { for (const v of new FooIterator) { v; } -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var FooIterator = (function () { - function FooIterator() { - } - FooIterator.prototype.next = function () { +class Foo { +} +class FooIterator { + next() { return { value: new Foo, done: false }; - }; - FooIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return FooIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of22.js b/tests/baselines/reference/for-of22.js index d38accb6cd818..886e8dba7c33d 100644 --- a/tests/baselines/reference/for-of22.js +++ b/tests/baselines/reference/for-of22.js @@ -21,22 +21,16 @@ class FooIterator { v; for (var v of new FooIterator) { } -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var FooIterator = (function () { - function FooIterator() { - } - FooIterator.prototype.next = function () { +class Foo { +} +class FooIterator { + next() { return { value: new Foo, done: false }; - }; - FooIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return FooIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of23.js b/tests/baselines/reference/for-of23.js index 87bb1fd428d29..f5649128c115c 100644 --- a/tests/baselines/reference/for-of23.js +++ b/tests/baselines/reference/for-of23.js @@ -20,22 +20,16 @@ class FooIterator { for (const v of new FooIterator) { const v = 0; // new scope } -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var FooIterator = (function () { - function FooIterator() { - } - FooIterator.prototype.next = function () { +class Foo { +} +class FooIterator { + next() { return { value: new Foo, done: false }; - }; - FooIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return FooIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of25.js b/tests/baselines/reference/for-of25.js index 86c175f861e8e..2c85a4dc2fd34 100644 --- a/tests/baselines/reference/for-of25.js +++ b/tests/baselines/reference/for-of25.js @@ -12,11 +12,8 @@ class StringIterator { var x; for (var v of new StringIterator) { } -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype[Symbol.iterator] = function () { +class StringIterator { + [Symbol.iterator]() { return x; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of26.js b/tests/baselines/reference/for-of26.js index edb6b4c38b264..e048caf1006d5 100644 --- a/tests/baselines/reference/for-of26.js +++ b/tests/baselines/reference/for-of26.js @@ -15,14 +15,11 @@ class StringIterator { var x; for (var v of new StringIterator) { } -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype.next = function () { +class StringIterator { + next() { return x; - }; - StringIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of27.js b/tests/baselines/reference/for-of27.js index 379b95c5b09d7..8b44ca03ef455 100644 --- a/tests/baselines/reference/for-of27.js +++ b/tests/baselines/reference/for-of27.js @@ -8,8 +8,5 @@ class StringIterator { //// [for-of27.js] for (var v of new StringIterator) { } -var StringIterator = (function () { - function StringIterator() { - } - return StringIterator; -})(); +class StringIterator { +} diff --git a/tests/baselines/reference/for-of28.js b/tests/baselines/reference/for-of28.js index 79b1590e12fb1..69c8ccab72798 100644 --- a/tests/baselines/reference/for-of28.js +++ b/tests/baselines/reference/for-of28.js @@ -11,11 +11,8 @@ class StringIterator { //// [for-of28.js] for (var v of new StringIterator) { } -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype[Symbol.iterator] = function () { +class StringIterator { + [Symbol.iterator]() { return this; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of30.js b/tests/baselines/reference/for-of30.js index 759c7823e63e1..0ed6caaf81e61 100644 --- a/tests/baselines/reference/for-of30.js +++ b/tests/baselines/reference/for-of30.js @@ -19,18 +19,17 @@ class StringIterator { //// [for-of30.js] for (var v of new StringIterator) { } -var StringIterator = (function () { - function StringIterator() { +class StringIterator { + constructor() { this.return = 0; } - StringIterator.prototype.next = function () { + next() { return { done: false, value: "" }; - }; - StringIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of31.js b/tests/baselines/reference/for-of31.js index 6773c8a3452ca..d38c1fa017d26 100644 --- a/tests/baselines/reference/for-of31.js +++ b/tests/baselines/reference/for-of31.js @@ -17,17 +17,14 @@ class StringIterator { //// [for-of31.js] for (var v of new StringIterator) { } -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype.next = function () { +class StringIterator { + next() { return { // no done property value: "" }; - }; - StringIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of33.js b/tests/baselines/reference/for-of33.js index f3a75eec13701..66097f777c8c2 100644 --- a/tests/baselines/reference/for-of33.js +++ b/tests/baselines/reference/for-of33.js @@ -10,11 +10,8 @@ class StringIterator { //// [for-of33.js] for (var v of new StringIterator) { } -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype[Symbol.iterator] = function () { +class StringIterator { + [Symbol.iterator]() { return v; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of34.js b/tests/baselines/reference/for-of34.js index 521b4f3c2a4aa..568a9f73535f9 100644 --- a/tests/baselines/reference/for-of34.js +++ b/tests/baselines/reference/for-of34.js @@ -14,14 +14,11 @@ class StringIterator { //// [for-of34.js] for (var v of new StringIterator) { } -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype.next = function () { +class StringIterator { + next() { return v; - }; - StringIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of35.js b/tests/baselines/reference/for-of35.js index cb6dc0e532fc5..a157d5e2e8eb1 100644 --- a/tests/baselines/reference/for-of35.js +++ b/tests/baselines/reference/for-of35.js @@ -17,17 +17,14 @@ class StringIterator { //// [for-of35.js] for (var v of new StringIterator) { } -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype.next = function () { +class StringIterator { + next() { return { done: true, value: v }; - }; - StringIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of47.js b/tests/baselines/reference/for-of47.js index f5e03dce571c2..f1e9295c3676f 100644 --- a/tests/baselines/reference/for-of47.js +++ b/tests/baselines/reference/for-of47.js @@ -21,7 +21,7 @@ var E; })(E || (E = {})); for ({ x, - y: y = 0 /* x */ + y: y = E.x } of array) { x; y; diff --git a/tests/baselines/reference/for-of48.js b/tests/baselines/reference/for-of48.js index 3b96f460e97ec..3030f07e605ae 100644 --- a/tests/baselines/reference/for-of48.js +++ b/tests/baselines/reference/for-of48.js @@ -21,7 +21,7 @@ var E; })(E || (E = {})); for ({ x, - y: = 0 /* x */ + y: = E.x } of array) { x; y; diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments2.js b/tests/baselines/reference/genericCallWithGenericSignatureArguments2.js index 4c0d57b9acfce..758852a918bc4 100644 --- a/tests/baselines/reference/genericCallWithGenericSignatureArguments2.js +++ b/tests/baselines/reference/genericCallWithGenericSignatureArguments2.js @@ -125,10 +125,10 @@ var onlyT; var r; return r; } - var r7 = foo3(0 /* A */, function (x) { - return 0 /* A */; + var r7 = foo3(E.A, function (x) { + return E.A; }, function (x) { - return 0 /* A */; + return F.A; }); // error })(onlyT || (onlyT = {})); var TU; @@ -179,9 +179,9 @@ var TU; var r; return r; } - var r7 = foo3(0 /* A */, function (x) { - return 0 /* A */; + var r7 = foo3(E.A, function (x) { + return E.A; }, function (x) { - return 0 /* A */; + return F.A; }); })(TU || (TU = {})); diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments3.js b/tests/baselines/reference/genericCallWithGenericSignatureArguments3.js index 8f691d936ec3b..b7cc833b9d903 100644 --- a/tests/baselines/reference/genericCallWithGenericSignatureArguments3.js +++ b/tests/baselines/reference/genericCallWithGenericSignatureArguments3.js @@ -78,10 +78,10 @@ var F; (function (F) { F[F["A"] = 0] = "A"; })(F || (F = {})); -var r6 = foo(0 /* A */, function (x) { - return 0 /* A */; +var r6 = foo(E.A, function (x) { + return E.A; }, function (x) { - return 0 /* A */; + return F.A; }); // number => number function foo2(x, a, b) { var r; diff --git a/tests/baselines/reference/giant.js b/tests/baselines/reference/giant.js index 9de46f76b1bb8..cc532ff43d955 100644 --- a/tests/baselines/reference/giant.js +++ b/tests/baselines/reference/giant.js @@ -754,7 +754,7 @@ define(["require", "exports"], function (require, exports) { return C; })(); var M; - (function (_M) { + (function (M_1) { var V; function F() { } @@ -844,10 +844,10 @@ define(["require", "exports"], function (require, exports) { ; ; })(M || (M = {})); - _M.eV; + M_1.eV; function eF() { } - _M.eF = eF; + M_1.eF = eF; ; var eC = (function () { function eC() { @@ -902,7 +902,7 @@ define(["require", "exports"], function (require, exports) { }); return eC; })(); - _M.eC = eC; + M_1.eC = eC; var eM; (function (eM) { var V; @@ -934,7 +934,7 @@ define(["require", "exports"], function (require, exports) { ; ; ; - })(eM = _M.eM || (_M.eM = {})); + })(eM = M_1.eM || (M_1.eM = {})); ; })(M || (M = {})); exports.eV; @@ -997,7 +997,7 @@ define(["require", "exports"], function (require, exports) { })(); exports.eC = eC; var eM; - (function (_eM) { + (function (eM_1) { var V; function F() { } @@ -1087,10 +1087,10 @@ define(["require", "exports"], function (require, exports) { ; ; })(M || (M = {})); - _eM.eV; + eM_1.eV; function eF() { } - _eM.eF = eF; + eM_1.eF = eF; ; var eC = (function () { function eC() { @@ -1145,7 +1145,7 @@ define(["require", "exports"], function (require, exports) { }); return eC; })(); - _eM.eC = eC; + eM_1.eC = eC; var eM; (function (eM) { var V; @@ -1177,7 +1177,7 @@ define(["require", "exports"], function (require, exports) { ; ; ; - })(eM = _eM.eM || (_eM.eM = {})); + })(eM = eM_1.eM || (eM_1.eM = {})); ; })(eM = exports.eM || (exports.eM = {})); ; diff --git a/tests/baselines/reference/importAndVariableDeclarationConflict1.js b/tests/baselines/reference/importAndVariableDeclarationConflict1.js index 78484b2c295a1..b812deec0ef45 100644 --- a/tests/baselines/reference/importAndVariableDeclarationConflict1.js +++ b/tests/baselines/reference/importAndVariableDeclarationConflict1.js @@ -9,8 +9,8 @@ var x = ''; //// [importAndVariableDeclarationConflict1.js] var m; -(function (_m) { - _m.m = ''; +(function (m_1) { + m_1.m = ''; })(m || (m = {})); var x = m.m; var x = ''; diff --git a/tests/baselines/reference/importAndVariableDeclarationConflict2.js b/tests/baselines/reference/importAndVariableDeclarationConflict2.js index bea146fe9bf0e..6d188b373b74a 100644 --- a/tests/baselines/reference/importAndVariableDeclarationConflict2.js +++ b/tests/baselines/reference/importAndVariableDeclarationConflict2.js @@ -13,8 +13,8 @@ class C { //// [importAndVariableDeclarationConflict2.js] var m; -(function (_m) { - _m.m = ''; +(function (m_1) { + m_1.m = ''; })(m || (m = {})); var x = m.m; var C = (function () { diff --git a/tests/baselines/reference/importAndVariableDeclarationConflict3.js b/tests/baselines/reference/importAndVariableDeclarationConflict3.js index 426d44bab2173..887aec16c59b0 100644 --- a/tests/baselines/reference/importAndVariableDeclarationConflict3.js +++ b/tests/baselines/reference/importAndVariableDeclarationConflict3.js @@ -9,8 +9,8 @@ import x = m.m; //// [importAndVariableDeclarationConflict3.js] var m; -(function (_m) { - _m.m = ''; +(function (m_1) { + m_1.m = ''; })(m || (m = {})); var x = m.m; var x = m.m; diff --git a/tests/baselines/reference/importAndVariableDeclarationConflict4.js b/tests/baselines/reference/importAndVariableDeclarationConflict4.js index 2adb78594a23a..4949df6366a42 100644 --- a/tests/baselines/reference/importAndVariableDeclarationConflict4.js +++ b/tests/baselines/reference/importAndVariableDeclarationConflict4.js @@ -9,8 +9,8 @@ import x = m.m; //// [importAndVariableDeclarationConflict4.js] var m; -(function (_m) { - _m.m = ''; +(function (m_1) { + m_1.m = ''; })(m || (m = {})); var x = ''; var x = m.m; diff --git a/tests/baselines/reference/importedModuleAddToGlobal.js b/tests/baselines/reference/importedModuleAddToGlobal.js index 6685bec69e374..a848ccb504bde 100644 --- a/tests/baselines/reference/importedModuleAddToGlobal.js +++ b/tests/baselines/reference/importedModuleAddToGlobal.js @@ -18,13 +18,13 @@ module C { //// [importedModuleAddToGlobal.js] var B; -(function (_B) { +(function (B_1) { var B = (function () { function B() { } return B; })(); - _B.B = B; + B_1.B = B; })(B || (B = {})); var C; (function (C) { diff --git a/tests/baselines/reference/inOperatorWithInvalidOperands.js b/tests/baselines/reference/inOperatorWithInvalidOperands.js index 29293f880ed94..005681b62857b 100644 --- a/tests/baselines/reference/inOperatorWithInvalidOperands.js +++ b/tests/baselines/reference/inOperatorWithInvalidOperands.js @@ -61,7 +61,7 @@ var ra3 = a3 in x; var ra4 = a4 in x; var ra5 = null in x; var ra6 = undefined in x; -var ra7 = 0 /* a */ in x; +var ra7 = E.a in x; var ra8 = false in x; var ra9 = {} in x; // invalid right operands diff --git a/tests/baselines/reference/incrementAndDecrement.js b/tests/baselines/reference/incrementAndDecrement.js index 96794e3c956d2..09c0b3ae490bf 100644 --- a/tests/baselines/reference/incrementAndDecrement.js +++ b/tests/baselines/reference/incrementAndDecrement.js @@ -70,7 +70,7 @@ var E; })(E || (E = {})); ; var x = 4; -var e = 1 /* B */; +var e = E.B; var a; var w = window; // Assign to expression++ diff --git a/tests/baselines/reference/incrementOperatorWithEnumType.js b/tests/baselines/reference/incrementOperatorWithEnumType.js index 590815ffec55a..e3e843a45da57 100644 --- a/tests/baselines/reference/incrementOperatorWithEnumType.js +++ b/tests/baselines/reference/incrementOperatorWithEnumType.js @@ -22,8 +22,8 @@ var ENUM1; })(ENUM1 || (ENUM1 = {})); ; // expression -var ResultIsNumber1 = ++1 /* "B" */; -var ResultIsNumber2 = 1 /* B */++; +var ResultIsNumber1 = ++ENUM1["B"]; +var ResultIsNumber2 = ENUM1.B++; // miss assignment operator -++1 /* "B" */; -1 /* B */++; +++ENUM1["B"]; +ENUM1.B++; diff --git a/tests/baselines/reference/initializePropertiesWithRenamedLet.js b/tests/baselines/reference/initializePropertiesWithRenamedLet.js new file mode 100644 index 0000000000000..1d34d7c13fc86 --- /dev/null +++ b/tests/baselines/reference/initializePropertiesWithRenamedLet.js @@ -0,0 +1,46 @@ +//// [initializePropertiesWithRenamedLet.ts] + +var x0; +if (true) { + let x0; + var obj1 = { x0: x0 }; + var obj2 = { x0 }; +} + +var x, y, z; +if (true) { + let { x: x } = { x: 0 }; + let { y } = { y: 0 }; + let z; + ({ z: z } = { z: 0 }); + ({ z } = { z: 0 }); +} + +//// [initializePropertiesWithRenamedLet.js] +var x0; +if (true) { + var x0_1; + var obj1 = { + x0: x0_1 + }; + var obj2 = { + x0: x0_1 + }; +} +var x, y, z; +if (true) { + var x_1 = ({ + x: 0 + }).x; + var y_1 = ({ + y: 0 + }).y; + var z_1; + (_a = { + z: 0 + }, z_1 = _a.z, _a); + (_b = { + z: 0 + }, z_1 = _b.z, _b); +} +var _a, _b; diff --git a/tests/baselines/reference/initializePropertiesWithRenamedLet.types b/tests/baselines/reference/initializePropertiesWithRenamedLet.types new file mode 100644 index 0000000000000..77f16756fdb23 --- /dev/null +++ b/tests/baselines/reference/initializePropertiesWithRenamedLet.types @@ -0,0 +1,58 @@ +=== tests/cases/compiler/initializePropertiesWithRenamedLet.ts === + +var x0; +>x0 : any + +if (true) { + let x0; +>x0 : any + + var obj1 = { x0: x0 }; +>obj1 : { x0: any; } +>{ x0: x0 } : { x0: any; } +>x0 : any +>x0 : any + + var obj2 = { x0 }; +>obj2 : { x0: any; } +>{ x0 } : { x0: any; } +>x0 : any +} + +var x, y, z; +>x : any +>y : any +>z : any + +if (true) { + let { x: x } = { x: 0 }; +>x : unknown +>x : number +>{ x: 0 } : { x: number; } +>x : number + + let { y } = { y: 0 }; +>y : number +>{ y: 0 } : { y: number; } +>y : number + + let z; +>z : any + + ({ z: z } = { z: 0 }); +>({ z: z } = { z: 0 }) : { z: number; } +>{ z: z } = { z: 0 } : { z: number; } +>{ z: z } : { z: any; } +>z : any +>z : any +>{ z: 0 } : { z: number; } +>z : number + + ({ z } = { z: 0 }); +>({ z } = { z: 0 }) : { z: number; } +>{ z } = { z: 0 } : { z: number; } +>{ z } : { z: any; } +>z : any +>{ z: 0 } : { z: number; } +>z : number +} diff --git a/tests/baselines/reference/instantiatedModule.js b/tests/baselines/reference/instantiatedModule.js index 7993628f89897..2b1871aea9d75 100644 --- a/tests/baselines/reference/instantiatedModule.js +++ b/tests/baselines/reference/instantiatedModule.js @@ -115,7 +115,7 @@ var m3 = M3; var a3; var a3 = m3.Color; var a3 = M3.Color; -var blue = 0 /* Blue */; +var blue = a3.Blue; var p3; -var p3 = 1 /* Red */; -var p3 = 0 /* Blue */; +var p3 = M3.Color.Red; +var p3 = m3.Color.Blue; diff --git a/tests/baselines/reference/interfaceAssignmentCompat.js b/tests/baselines/reference/interfaceAssignmentCompat.js index dbad8eabd78d5..7ddd22ee863eb 100644 --- a/tests/baselines/reference/interfaceAssignmentCompat.js +++ b/tests/baselines/reference/interfaceAssignmentCompat.js @@ -73,13 +73,13 @@ var M; var x = []; var result = ""; x[0] = { - color: 2 /* Brown */ + color: Color.Brown }; x[1] = { - color: 1 /* Blue */ + color: Color.Blue }; x[2] = { - color: 0 /* Green */ + color: Color.Green }; x = x.sort(CompareYeux); // parameter mismatch // type of z inferred from specialized array type diff --git a/tests/baselines/reference/interfaceWithPropertyOfEveryType.js b/tests/baselines/reference/interfaceWithPropertyOfEveryType.js index 4f8d8919563fb..e10b83297bccd 100644 --- a/tests/baselines/reference/interfaceWithPropertyOfEveryType.js +++ b/tests/baselines/reference/interfaceWithPropertyOfEveryType.js @@ -79,5 +79,5 @@ var a = { l: f1, m: M, n: {}, - o: 0 /* A */ + o: E.A }; diff --git a/tests/baselines/reference/internalAliasEnum.js b/tests/baselines/reference/internalAliasEnum.js index b5c68ea5c1663..6400cf26ddcff 100644 --- a/tests/baselines/reference/internalAliasEnum.js +++ b/tests/baselines/reference/internalAliasEnum.js @@ -26,7 +26,7 @@ var a; var c; (function (c) { var b = a.weekend; - c.bVal = 2 /* Sunday */; + c.bVal = b.Sunday; })(c || (c = {})); diff --git a/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithExport.js b/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithExport.js index e21dd35532271..f2223b197e00f 100644 --- a/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithExport.js +++ b/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithExport.js @@ -26,7 +26,7 @@ var a; var c; (function (c) { c.b = a.weekend; - c.bVal = 2 /* Sunday */; + c.bVal = c.b.Sunday; })(c = exports.c || (exports.c = {})); diff --git a/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExport.js b/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExport.js index 3d60e055edeed..afd6597869be6 100644 --- a/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExport.js +++ b/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExport.js @@ -26,7 +26,7 @@ var a; var c; (function (c) { var b = a.weekend; - c.bVal = 2 /* Sunday */; + c.bVal = b.Sunday; })(c = exports.c || (exports.c = {})); diff --git a/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExportAccessError.js b/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExportAccessError.js index f050d6f9a553c..acd3f4c61b185 100644 --- a/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExportAccessError.js +++ b/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExportAccessError.js @@ -27,6 +27,6 @@ var a; var c; (function (c) { var b = a.weekend; - c.bVal = 2 /* Sunday */; + c.bVal = b.Sunday; })(c = exports.c || (exports.c = {})); var happyFriday = c.b.Friday; diff --git a/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithExport.js b/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithExport.js index e4dc73b2403f2..96e17c6f6e305 100644 --- a/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithExport.js +++ b/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithExport.js @@ -23,7 +23,7 @@ define(["require", "exports"], function (require, exports) { var weekend = a.weekend; })(a = exports.a || (exports.a = {})); exports.b = a.weekend; - exports.bVal = 2 /* Sunday */; + exports.bVal = exports.b.Sunday; }); diff --git a/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithoutExport.js b/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithoutExport.js index e81093147e881..b224c22f45e1a 100644 --- a/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithoutExport.js +++ b/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithoutExport.js @@ -23,7 +23,7 @@ define(["require", "exports"], function (require, exports) { var weekend = a.weekend; })(a = exports.a || (exports.a = {})); var b = a.weekend; - exports.bVal = 2 /* Sunday */; + exports.bVal = b.Sunday; }); diff --git a/tests/baselines/reference/invalidEnumAssignments.js b/tests/baselines/reference/invalidEnumAssignments.js index b9bb9e12cedd6..dfdd0600ed0ce 100644 --- a/tests/baselines/reference/invalidEnumAssignments.js +++ b/tests/baselines/reference/invalidEnumAssignments.js @@ -35,8 +35,8 @@ var E2; })(E2 || (E2 = {})); var e; var e2; -e = 0 /* A */; -e2 = 0 /* A */; +e = E2.A; +e2 = E.A; e = null; e = {}; e = ''; diff --git a/tests/baselines/reference/invalidUndefinedAssignments.js b/tests/baselines/reference/invalidUndefinedAssignments.js index 0b37316e0855d..7617e5eae8e2c 100644 --- a/tests/baselines/reference/invalidUndefinedAssignments.js +++ b/tests/baselines/reference/invalidUndefinedAssignments.js @@ -28,7 +28,7 @@ var E; E[E["A"] = 0] = "A"; })(E || (E = {})); E = x; -0 /* A */ = x; +E.A = x; var C = (function () { function C() { } diff --git a/tests/baselines/reference/invalidUndefinedValues.js b/tests/baselines/reference/invalidUndefinedValues.js index b4751cf25d817..9361f43bbae68 100644 --- a/tests/baselines/reference/invalidUndefinedValues.js +++ b/tests/baselines/reference/invalidUndefinedValues.js @@ -67,4 +67,4 @@ var E; E[E["A"] = 0] = "A"; })(E || (E = {})); x = E; -x = 0 /* A */; +x = E.A; diff --git a/tests/baselines/reference/invalidVoidAssignments.js b/tests/baselines/reference/invalidVoidAssignments.js index c8c395b0e4fdb..b821b0ca79649 100644 --- a/tests/baselines/reference/invalidVoidAssignments.js +++ b/tests/baselines/reference/invalidVoidAssignments.js @@ -58,7 +58,7 @@ var E; E[E["A"] = 0] = "A"; })(E || (E = {})); x = E; -x = 0 /* A */; +x = E.A; x = { f: function () { } diff --git a/tests/baselines/reference/invalidVoidValues.js b/tests/baselines/reference/invalidVoidValues.js index 6740eb3fc1bce..13f2d681f2622 100644 --- a/tests/baselines/reference/invalidVoidValues.js +++ b/tests/baselines/reference/invalidVoidValues.js @@ -36,7 +36,7 @@ var E; E[E["A"] = 0] = "A"; })(E || (E = {})); x = E; -x = 0 /* A */; +x = E.A; var C = (function () { function C() { } diff --git a/tests/baselines/reference/isDeclarationVisibleNodeKinds.js b/tests/baselines/reference/isDeclarationVisibleNodeKinds.js index d357922f5bce6..8604ec493a2ab 100644 --- a/tests/baselines/reference/isDeclarationVisibleNodeKinds.js +++ b/tests/baselines/reference/isDeclarationVisibleNodeKinds.js @@ -72,67 +72,67 @@ module schema { //// [isDeclarationVisibleNodeKinds.js] // Function types var schema; -(function (_schema) { +(function (schema_1) { function createValidator1(schema) { return undefined; } - _schema.createValidator1 = createValidator1; + schema_1.createValidator1 = createValidator1; })(schema || (schema = {})); // Constructor types var schema; -(function (_schema_1) { +(function (schema_2) { function createValidator2(schema) { return undefined; } - _schema_1.createValidator2 = createValidator2; + schema_2.createValidator2 = createValidator2; })(schema || (schema = {})); // union types var schema; -(function (_schema_2) { +(function (schema_3) { function createValidator3(schema) { return undefined; } - _schema_2.createValidator3 = createValidator3; + schema_3.createValidator3 = createValidator3; })(schema || (schema = {})); // Array types var schema; -(function (_schema_3) { +(function (schema_4) { function createValidator4(schema) { return undefined; } - _schema_3.createValidator4 = createValidator4; + schema_4.createValidator4 = createValidator4; })(schema || (schema = {})); // TypeLiterals var schema; -(function (_schema_4) { +(function (schema_5) { function createValidator5(schema) { return undefined; } - _schema_4.createValidator5 = createValidator5; + schema_5.createValidator5 = createValidator5; })(schema || (schema = {})); // Tuple types var schema; -(function (_schema_5) { +(function (schema_6) { function createValidator6(schema) { return undefined; } - _schema_5.createValidator6 = createValidator6; + schema_6.createValidator6 = createValidator6; })(schema || (schema = {})); // Paren Types var schema; -(function (_schema_6) { +(function (schema_7) { function createValidator7(schema) { return undefined; } - _schema_6.createValidator7 = createValidator7; + schema_7.createValidator7 = createValidator7; })(schema || (schema = {})); // Type reference var schema; -(function (_schema_7) { +(function (schema_8) { function createValidator8(schema) { return undefined; } - _schema_7.createValidator8 = createValidator8; + schema_8.createValidator8 = createValidator8; })(schema || (schema = {})); var schema; (function (schema) { diff --git a/tests/baselines/reference/letConstInCaseClauses.js b/tests/baselines/reference/letConstInCaseClauses.js index 94840a11a2c74..33650dcaf4caf 100644 --- a/tests/baselines/reference/letConstInCaseClauses.js +++ b/tests/baselines/reference/letConstInCaseClauses.js @@ -34,28 +34,28 @@ var y = 20; var x = 10; var y = 20; { - var _x = 1; - var _y = 2; - console.log(_x); - switch (_x) { + var x_1 = 1; + var y_1 = 2; + console.log(x_1); + switch (x_1) { case 10: - var _x_1 = 20; + var x_2 = 20; } - switch (_y) { + switch (y_1) { case 10: - var _y_1 = 20; + var y_2 = 20; } } { - var _x_2 = 1; - var _y_2 = 2; - console.log(_x_2); - switch (_x_2) { + var x_3 = 1; + var y_3 = 2; + console.log(x_3); + switch (x_3) { case 10: - var _x_3 = 20; + var x_4 = 20; } - switch (_y_2) { + switch (y_3) { case 10: - var _y_3 = 20; + var y_4 = 20; } } diff --git a/tests/baselines/reference/letConstMatchingParameterNames.js b/tests/baselines/reference/letConstMatchingParameterNames.js index a11405b9f83c7..392f0e7ae943e 100644 --- a/tests/baselines/reference/letConstMatchingParameterNames.js +++ b/tests/baselines/reference/letConstMatchingParameterNames.js @@ -19,8 +19,8 @@ function a() { var parent = true; var parent2 = true; function a() { - var _parent = 1; - var _parent2 = 2; + var parent = 1; + var parent2 = 2; function b(parent, parent2) { use(parent); use(parent2); diff --git a/tests/baselines/reference/letDeclarations-es5.js b/tests/baselines/reference/letDeclarations-es5.js index 5246e91edfb76..1d4eb4afcbfef 100644 --- a/tests/baselines/reference/letDeclarations-es5.js +++ b/tests/baselines/reference/letDeclarations-es5.js @@ -20,7 +20,7 @@ var l3, l4, l5, l6; var l7 = false; var l8 = 23; var l9 = 0, l10 = "", l11 = null; -for (var _l11 in {}) { +for (var l11_1 in {}) { } for (var l12 = 0; l12 < 9; l12++) { } diff --git a/tests/baselines/reference/letDeclarations-scopes.js b/tests/baselines/reference/letDeclarations-scopes.js index fc7218079940d..d0489820d0b90 100644 --- a/tests/baselines/reference/letDeclarations-scopes.js +++ b/tests/baselines/reference/letDeclarations-scopes.js @@ -259,30 +259,25 @@ var m; lable: let l2 = 0; })(m || (m = {})); // methods -var C = (function () { - function C() { +class C { + constructor() { let l = 0; n = l; } - C.prototype.method = function () { + method() { let l = 0; n = l; - }; - Object.defineProperty(C.prototype, "v", { - get: function () { - let l = 0; - n = l; - return n; - }, - set: function (value) { - let l = 0; - n = l; - }, - enumerable: true, - configurable: true - }); - return C; -})(); + } + get v() { + let l = 0; + n = l; + return n; + } + set v(value) { + let l = 0; + n = l; + } +} // object literals var o = { f() { diff --git a/tests/baselines/reference/letDeclarations-validContexts.js b/tests/baselines/reference/letDeclarations-validContexts.js index f6d404135f695..b11a19223836d 100644 --- a/tests/baselines/reference/letDeclarations-validContexts.js +++ b/tests/baselines/reference/letDeclarations-validContexts.js @@ -221,26 +221,21 @@ var m; } })(m || (m = {})); // methods -var C = (function () { - function C() { +class C { + constructor() { let l24 = 0; } - C.prototype.method = function () { + method() { let l25 = 0; - }; - Object.defineProperty(C.prototype, "v", { - get: function () { - let l26 = 0; - return l26; - }, - set: function (value) { - let l27 = value; - }, - enumerable: true, - configurable: true - }); - return C; -})(); + } + get v() { + let l26 = 0; + return l26; + } + set v(value) { + let l27 = value; + } +} // object literals var o = { f() { diff --git a/tests/baselines/reference/letKeepNamesOfTopLevelItems.js b/tests/baselines/reference/letKeepNamesOfTopLevelItems.js new file mode 100644 index 0000000000000..96fd31ae536dd --- /dev/null +++ b/tests/baselines/reference/letKeepNamesOfTopLevelItems.js @@ -0,0 +1,19 @@ +//// [letKeepNamesOfTopLevelItems.ts] +let x; +function foo() { + let x; +} + +module A { + let x; +} + +//// [letKeepNamesOfTopLevelItems.js] +var x; +function foo() { + var x; +} +var A; +(function (A) { + var x; +})(A || (A = {})); diff --git a/tests/baselines/reference/letKeepNamesOfTopLevelItems.types b/tests/baselines/reference/letKeepNamesOfTopLevelItems.types new file mode 100644 index 0000000000000..952be1512a984 --- /dev/null +++ b/tests/baselines/reference/letKeepNamesOfTopLevelItems.types @@ -0,0 +1,17 @@ +=== tests/cases/compiler/letKeepNamesOfTopLevelItems.ts === +let x; +>x : any + +function foo() { +>foo : () => void + + let x; +>x : any +} + +module A { +>A : typeof A + + let x; +>x : any +} diff --git a/tests/baselines/reference/letShadowedByNameInNestedScope.errors.txt b/tests/baselines/reference/letShadowedByNameInNestedScope.errors.txt new file mode 100644 index 0000000000000..b47e194f93eb1 --- /dev/null +++ b/tests/baselines/reference/letShadowedByNameInNestedScope.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/letShadowedByNameInNestedScope.ts(6,9): error TS2304: Cannot find name 'console'. + + +==== tests/cases/compiler/letShadowedByNameInNestedScope.ts (1 errors) ==== + var x; + function foo() { + let x = 0; + (function () { + var _x = 1; + console.log(x); + ~~~~~~~ +!!! error TS2304: Cannot find name 'console'. + })(); + } \ No newline at end of file diff --git a/tests/baselines/reference/letShadowedByNameInNestedScope.js b/tests/baselines/reference/letShadowedByNameInNestedScope.js new file mode 100644 index 0000000000000..648fe0b8e94df --- /dev/null +++ b/tests/baselines/reference/letShadowedByNameInNestedScope.js @@ -0,0 +1,19 @@ +//// [letShadowedByNameInNestedScope.ts] +var x; +function foo() { + let x = 0; + (function () { + var _x = 1; + console.log(x); + })(); +} + +//// [letShadowedByNameInNestedScope.js] +var x; +function foo() { + var x = 0; + (function () { + var _x = 1; + console.log(x); + })(); +} diff --git a/tests/baselines/reference/localImportNameVsGlobalName.js b/tests/baselines/reference/localImportNameVsGlobalName.js index f27e7d648d10c..8ba7ec567a0d9 100644 --- a/tests/baselines/reference/localImportNameVsGlobalName.js +++ b/tests/baselines/reference/localImportNameVsGlobalName.js @@ -30,7 +30,7 @@ var App; function foo(key) { } App.foo = foo; - foo(0 /* UP */); - foo(1 /* DOWN */); - foo(2 /* LEFT */); + foo(Key.UP); + foo(Key.DOWN); + foo(Key.LEFT); })(App || (App = {})); diff --git a/tests/baselines/reference/logicalNotOperatorWithEnumType.js b/tests/baselines/reference/logicalNotOperatorWithEnumType.js index 89ee1a148335a..382cf577713bc 100644 --- a/tests/baselines/reference/logicalNotOperatorWithEnumType.js +++ b/tests/baselines/reference/logicalNotOperatorWithEnumType.js @@ -37,13 +37,13 @@ var ENUM1; // enum type var var ResultIsBoolean1 = !ENUM; // enum type expressions -var ResultIsBoolean2 = !1 /* "B" */; -var ResultIsBoolean3 = !(1 /* B */ + 2 /* "C" */); +var ResultIsBoolean2 = !ENUM["B"]; +var ResultIsBoolean3 = !(ENUM.B + ENUM["C"]); // multiple ! operators var ResultIsBoolean4 = !!ENUM; -var ResultIsBoolean5 = !!!(1 /* "B" */ + 2 /* C */); +var ResultIsBoolean5 = !!!(ENUM["B"] + ENUM.C); // miss assignment operators !ENUM; !ENUM1; -!1 /* B */; +!ENUM.B; !ENUM, ENUM1; diff --git a/tests/baselines/reference/mergedDeclarations2.js b/tests/baselines/reference/mergedDeclarations2.js index 1e9254bb0bb75..962346541cc6c 100644 --- a/tests/baselines/reference/mergedDeclarations2.js +++ b/tests/baselines/reference/mergedDeclarations2.js @@ -17,7 +17,7 @@ var Foo; })(Foo || (Foo = {})); var Foo; (function (Foo) { - Foo[Foo["a"] = Foo.b] = "a"; + Foo[Foo["a"] = 0] = "a"; })(Foo || (Foo = {})); var Foo; (function (Foo) { diff --git a/tests/baselines/reference/mergedEnumDeclarationCodeGen.js b/tests/baselines/reference/mergedEnumDeclarationCodeGen.js index 574ef6fa2d040..57b6e8051f8e8 100644 --- a/tests/baselines/reference/mergedEnumDeclarationCodeGen.js +++ b/tests/baselines/reference/mergedEnumDeclarationCodeGen.js @@ -11,9 +11,9 @@ enum E { var E; (function (E) { E[E["a"] = 0] = "a"; - E[E["b"] = E.a] = "b"; + E[E["b"] = 0] = "b"; })(E || (E = {})); var E; (function (E) { - E[E["c"] = E.a] = "c"; + E[E["c"] = 0] = "c"; })(E || (E = {})); diff --git a/tests/baselines/reference/mergedModuleDeclarationCodeGen.js b/tests/baselines/reference/mergedModuleDeclarationCodeGen.js index 88b949dd92023..d5cda7c91099d 100644 --- a/tests/baselines/reference/mergedModuleDeclarationCodeGen.js +++ b/tests/baselines/reference/mergedModuleDeclarationCodeGen.js @@ -19,10 +19,10 @@ export module X { var X; (function (X) { var Y; - (function (_Y) { + (function (Y_1) { var A = (function () { function A(Y) { - new _Y.B(); + new Y_1.B(); } return A; })(); diff --git a/tests/baselines/reference/mergedModuleDeclarationCodeGen2.js b/tests/baselines/reference/mergedModuleDeclarationCodeGen2.js index 457bd12b8f082..06a590194f5f5 100644 --- a/tests/baselines/reference/mergedModuleDeclarationCodeGen2.js +++ b/tests/baselines/reference/mergedModuleDeclarationCodeGen2.js @@ -22,11 +22,11 @@ var my; })(data = my.data || (my.data = {})); })(my || (my = {})); var my; -(function (_my) { +(function (my_1) { var data; - (function (_data) { + (function (data_1) { function data(my) { - _data.foo.buz(); + data_1.foo.buz(); } - })(data = _my.data || (_my.data = {})); + })(data = my_1.data || (my_1.data = {})); })(my || (my = {})); diff --git a/tests/baselines/reference/mergedModuleDeclarationCodeGen3.js b/tests/baselines/reference/mergedModuleDeclarationCodeGen3.js index 0618346dd75ea..43c55ed8291af 100644 --- a/tests/baselines/reference/mergedModuleDeclarationCodeGen3.js +++ b/tests/baselines/reference/mergedModuleDeclarationCodeGen3.js @@ -19,14 +19,14 @@ var my; })(data = my.data || (my.data = {})); })(my || (my = {})); var my; -(function (_my) { +(function (my_1) { var data; - (function (_data) { + (function (data_1) { var foo; - (function (_foo) { + (function (foo_1) { function data(my, foo) { - _data.buz(); + data_1.buz(); } - })(foo = _data.foo || (_data.foo = {})); - })(data = _my.data || (_my.data = {})); + })(foo = data_1.foo || (data_1.foo = {})); + })(data = my_1.data || (my_1.data = {})); })(my || (my = {})); diff --git a/tests/baselines/reference/mergedModuleDeclarationCodeGen4.js b/tests/baselines/reference/mergedModuleDeclarationCodeGen4.js index 2463c9cae906a..af7f5bacef73b 100644 --- a/tests/baselines/reference/mergedModuleDeclarationCodeGen4.js +++ b/tests/baselines/reference/mergedModuleDeclarationCodeGen4.js @@ -20,7 +20,7 @@ module superContain { var superContain; (function (superContain) { var contain; - (function (_contain) { + (function (contain_1) { var my; (function (my) { var buz; @@ -32,19 +32,19 @@ var superContain; data.foo = foo; })(data = buz.data || (buz.data = {})); })(buz = my.buz || (my.buz = {})); - })(my = _contain.my || (_contain.my = {})); + })(my = contain_1.my || (contain_1.my = {})); var my; - (function (_my) { + (function (my_1) { var buz; - (function (_buz) { + (function (buz_1) { var data; - (function (_data) { + (function (data_1) { function bar(contain, my, buz, data) { - _data.foo(); + data_1.foo(); } - _data.bar = bar; - })(data = _buz.data || (_buz.data = {})); - })(buz = _my.buz || (_my.buz = {})); - })(my = _contain.my || (_contain.my = {})); + data_1.bar = bar; + })(data = buz_1.data || (buz_1.data = {})); + })(buz = my_1.buz || (my_1.buz = {})); + })(my = contain_1.my || (contain_1.my = {})); })(contain = superContain.contain || (superContain.contain = {})); })(superContain || (superContain = {})); diff --git a/tests/baselines/reference/mergedModuleDeclarationCodeGen5.js b/tests/baselines/reference/mergedModuleDeclarationCodeGen5.js index 2c8e0bb79e4fb..4bbad2e567868 100644 --- a/tests/baselines/reference/mergedModuleDeclarationCodeGen5.js +++ b/tests/baselines/reference/mergedModuleDeclarationCodeGen5.js @@ -20,7 +20,7 @@ module M.buz.plop { //// [mergedModuleDeclarationCodeGen5.js] var M; -(function (_M) { +(function (M_1) { var buz; (function (buz) { var plop; @@ -32,14 +32,14 @@ var M; } plop.M = M; })(plop = buz.plop || (buz.plop = {})); - })(buz = _M.buz || (_M.buz = {})); + })(buz = M_1.buz || (M_1.buz = {})); })(M || (M = {})); var M; (function (M) { var buz; - (function (_buz) { + (function (buz_1) { var plop; - (function (_plop) { + (function (plop_1) { function gunk() { } function buz() { @@ -49,17 +49,17 @@ var M; } return fudge; })(); - _plop.fudge = fudge; + plop_1.fudge = fudge; (function (plop) { - })(_plop.plop || (_plop.plop = {})); - var plop = _plop.plop; + })(plop_1.plop || (plop_1.plop = {})); + var plop = plop_1.plop; // Emit these references as follows var v1 = gunk; // gunk var v2 = buz; // buz - _plop.v3 = _plop.doom; // _plop.doom - _plop.v4 = _plop.M; // _plop.M - _plop.v5 = fudge; // fudge - _plop.v6 = plop; // plop - })(plop = _buz.plop || (_buz.plop = {})); + plop_1.v3 = plop_1.doom; // _plop.doom + plop_1.v4 = plop_1.M; // _plop.M + plop_1.v5 = fudge; // fudge + plop_1.v6 = plop; // plop + })(plop = buz_1.plop || (buz_1.plop = {})); })(buz = M.buz || (M.buz = {})); })(M || (M = {})); diff --git a/tests/baselines/reference/moduleCodeGenTest5.js b/tests/baselines/reference/moduleCodeGenTest5.js index 6f5f0a4e91295..6f56f44c6849e 100644 --- a/tests/baselines/reference/moduleCodeGenTest5.js +++ b/tests/baselines/reference/moduleCodeGenTest5.js @@ -50,9 +50,9 @@ var C2 = (function () { E1[E1["A"] = 0] = "A"; })(exports.E1 || (exports.E1 = {})); var E1 = exports.E1; -var u = 0 /* A */; +var u = E1.A; var E2; (function (E2) { E2[E2["B"] = 0] = "B"; })(E2 || (E2 = {})); -var v = 0 /* B */; +var v = E2.B; diff --git a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt.js b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt.js index 983dc004acf31..f9a90fd515155 100644 --- a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt.js +++ b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt.js @@ -25,11 +25,11 @@ var Z; var A; (function (A) { var M; - (function (_M) { + (function (M_1) { var M = Z.M; function bar() { } - _M.bar = bar; + M_1.bar = bar; M.bar(); // Should call Z.M.bar })(M = A.M || (A.M = {})); })(A || (A = {})); diff --git a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt3.js b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt3.js index c11b36f643a30..efdcebe84e96d 100644 --- a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt3.js +++ b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt3.js @@ -30,11 +30,11 @@ var Z; var A; (function (A) { var M; - (function (_M) { + (function (M_1) { var M = Z.M; function bar() { } - _M.bar = bar; + M_1.bar = bar; M.bar(); // Should call Z.M.bar })(M = A.M || (A.M = {})); })(A || (A = {})); diff --git a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt4.js b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt4.js index c61f3d4dd9d73..e9cd456f3f3f8 100644 --- a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt4.js +++ b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt4.js @@ -26,11 +26,11 @@ var Z; var A; (function (A) { var M; - (function (_M) { + (function (M_1) { var M = Z.M; function bar() { } - _M.bar = bar; + M_1.bar = bar; M.bar(); // Should call Z.M.bar })(M = A.M || (A.M = {})); })(A || (A = {})); diff --git a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt5.js b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt5.js index 0bc314ccc0706..72aa36022634d 100644 --- a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt5.js +++ b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt5.js @@ -30,10 +30,10 @@ var Z; var A; (function (A) { var M; - (function (_M) { + (function (M_1) { function bar() { } - _M.bar = bar; + M_1.bar = bar; M.bar(); // Should call Z.M.bar })(M = A.M || (A.M = {})); })(A || (A = {})); diff --git a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt6.js b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt6.js index 4ba0a33c29a0c..fbad13359b8eb 100644 --- a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt6.js +++ b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt6.js @@ -24,9 +24,9 @@ var Z; var A; (function (A) { var M; - (function (_M) { + (function (M_1) { function bar() { } - _M.bar = bar; + M_1.bar = bar; })(M = A.M || (A.M = {})); })(A || (A = {})); diff --git a/tests/baselines/reference/moduleVisibilityTest1.js b/tests/baselines/reference/moduleVisibilityTest1.js index d8bdedfafe257..8f129f545de21 100644 --- a/tests/baselines/reference/moduleVisibilityTest1.js +++ b/tests/baselines/reference/moduleVisibilityTest1.js @@ -137,11 +137,11 @@ var M; var M; (function (M) { M.c = M.x; - M.meb = 1 /* B */; + M.meb = M.E.B; })(M || (M = {})); var cprime = null; var c = new M.C(); var z = M.x; -var alpha = 0 /* A */; +var alpha = M.E.A; var omega = M.exported_var; c.someMethodThatCallsAnOuterMethod(); diff --git a/tests/baselines/reference/moduleWithStatementsOfEveryKind.js b/tests/baselines/reference/moduleWithStatementsOfEveryKind.js index 5161f72d5f023..cab0d35aa5a20 100644 --- a/tests/baselines/reference/moduleWithStatementsOfEveryKind.js +++ b/tests/baselines/reference/moduleWithStatementsOfEveryKind.js @@ -66,7 +66,7 @@ var __extends = this.__extends || function (d, b) { d.prototype = new __(); }; var A; -(function (_A) { +(function (A_1) { var A = (function () { function A() { } diff --git a/tests/baselines/reference/multipleExports.errors.txt b/tests/baselines/reference/multipleExports.errors.txt new file mode 100644 index 0000000000000..254717843cfb4 --- /dev/null +++ b/tests/baselines/reference/multipleExports.errors.txt @@ -0,0 +1,21 @@ +tests/cases/compiler/multipleExports.ts(10,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/multipleExports.ts(10,13): error TS2484: Export declaration conflicts with exported declaration of 'x' + + +==== tests/cases/compiler/multipleExports.ts (2 errors) ==== + + export module M { + export var v = 0; + export let x; + } + + const x = 0; + export module M { + v; + export {x}; + ~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + ~ +!!! error TS2484: Export declaration conflicts with exported declaration of 'x' + } + \ No newline at end of file diff --git a/tests/baselines/reference/multipleExports.js b/tests/baselines/reference/multipleExports.js new file mode 100644 index 0000000000000..b8c08952b67a8 --- /dev/null +++ b/tests/baselines/reference/multipleExports.js @@ -0,0 +1,25 @@ +//// [multipleExports.ts] + +export module M { + export var v = 0; + export let x; +} + +const x = 0; +export module M { + v; + export {x}; +} + + +//// [multipleExports.js] +var M; +(function (M) { + M.v = 0; + M.x; +})(M = exports.M || (exports.M = {})); +var x = 0; +var M; +(function (M) { + M.v; +})(M = exports.M || (exports.M = {})); diff --git a/tests/baselines/reference/nameCollision.js b/tests/baselines/reference/nameCollision.js index fe7bb3a891975..0e559b7091cc8 100644 --- a/tests/baselines/reference/nameCollision.js +++ b/tests/baselines/reference/nameCollision.js @@ -48,7 +48,7 @@ module D { //// [nameCollision.js] var A; -(function (_A_1) { +(function (A_1) { // these 2 statements force an underscore before the 'A' // in the generated function call. var A = 12; @@ -59,7 +59,7 @@ var B; var A = 12; })(B || (B = {})); var B; -(function (_B) { +(function (B_1) { // re-opened module with colliding name // this should add an underscore. var B = (function () { @@ -69,29 +69,29 @@ var B; })(); })(B || (B = {})); var X; -(function (_X) { +(function (X_1) { var X = 13; var Y; - (function (_Y) { + (function (Y_1) { var Y = 13; var Z; - (function (_Z) { + (function (Z_1) { var X = 12; var Y = 12; var Z = 12; - })(Z = _Y.Z || (_Y.Z = {})); - })(Y = _X.Y || (_X.Y = {})); + })(Z = Y_1.Z || (Y_1.Z = {})); + })(Y = X_1.Y || (X_1.Y = {})); })(X || (X = {})); var Y; -(function (_Y_1) { +(function (Y_2) { var Y; - (function (_Y_2) { + (function (Y_3) { (function (Y) { Y[Y["Red"] = 0] = "Red"; Y[Y["Blue"] = 1] = "Blue"; - })(_Y_2.Y || (_Y_2.Y = {})); - var Y = _Y_2.Y; - })(Y = _Y_1.Y || (_Y_1.Y = {})); + })(Y_3.Y || (Y_3.Y = {})); + var Y = Y_3.Y; + })(Y = Y_2.Y || (Y_2.Y = {})); })(Y || (Y = {})); // no collision, since interface doesn't // generate code. diff --git a/tests/baselines/reference/negateOperatorWithEnumType.js b/tests/baselines/reference/negateOperatorWithEnumType.js index 77458f442df9a..e33e78110772b 100644 --- a/tests/baselines/reference/negateOperatorWithEnumType.js +++ b/tests/baselines/reference/negateOperatorWithEnumType.js @@ -33,10 +33,10 @@ var ENUM1; // enum type var var ResultIsNumber1 = -ENUM; // expressions -var ResultIsNumber2 = -1 /* "B" */; -var ResultIsNumber3 = -(1 /* B */ + 2 /* "" */); +var ResultIsNumber2 = -ENUM1["B"]; +var ResultIsNumber3 = -(ENUM1.B + ENUM1[""]); // miss assignment operators -ENUM; -ENUM1; --1 /* "B" */; +-ENUM1["B"]; -ENUM, ENUM1; diff --git a/tests/baselines/reference/noDefaultLib.errors.txt b/tests/baselines/reference/noDefaultLib.errors.txt index b8f42ba7c331b..c73f3e0b9487e 100644 --- a/tests/baselines/reference/noDefaultLib.errors.txt +++ b/tests/baselines/reference/noDefaultLib.errors.txt @@ -1,9 +1,19 @@ +error TS2318: Cannot find global type 'TypedPropertyDescriptor'. +error TS2318: Cannot find global type 'PropertyDecorator'. +error TS2318: Cannot find global type 'ParameterDecorator'. +error TS2318: Cannot find global type 'MethodDecorator'. error TS2318: Cannot find global type 'IArguments'. +error TS2318: Cannot find global type 'ClassDecorator'. error TS2318: Cannot find global type 'Boolean'. tests/cases/compiler/noDefaultLib.ts(4,11): error TS2317: Global type 'Array' must have 1 type parameter(s). +!!! error TS2318: Cannot find global type 'TypedPropertyDescriptor'. +!!! error TS2318: Cannot find global type 'PropertyDecorator'. +!!! error TS2318: Cannot find global type 'ParameterDecorator'. +!!! error TS2318: Cannot find global type 'MethodDecorator'. !!! error TS2318: Cannot find global type 'IArguments'. +!!! error TS2318: Cannot find global type 'ClassDecorator'. !!! error TS2318: Cannot find global type 'Boolean'. ==== tests/cases/compiler/noDefaultLib.ts (1 errors) ==== /// diff --git a/tests/baselines/reference/noImplicitAnyIndexing.js b/tests/baselines/reference/noImplicitAnyIndexing.js index 91dbcae730c93..8451a1426a609 100644 --- a/tests/baselines/reference/noImplicitAnyIndexing.js +++ b/tests/baselines/reference/noImplicitAnyIndexing.js @@ -57,11 +57,11 @@ var MyEmusEnum; // Should be okay; should be a string. var strRepresentation1 = MyEmusEnum[0]; // Should be okay; should be a string. -var strRepresentation2 = MyEmusEnum[0 /* emu */]; +var strRepresentation2 = MyEmusEnum[MyEmusEnum.emu]; // Should be implicit 'any' ; property access fails, no string indexer. var strRepresentation3 = MyEmusEnum["monehh"]; // Should be okay; should be a MyEmusEnum -var strRepresentation4 = 0 /* "emu" */; +var strRepresentation4 = MyEmusEnum["emu"]; // Should report an implicit 'any'. var x = {}["hi"]; // Should report an implicit 'any'. @@ -77,6 +77,6 @@ var m = { "2": 2, "Okay that's enough for today.": NaN }; -var mResult1 = m[0 /* emu */]; -var mResult2 = m[MyEmusEnum[0 /* emu */]]; +var mResult1 = m[MyEmusEnum.emu]; +var mResult2 = m[MyEmusEnum[MyEmusEnum.emu]]; var mResult3 = m[hi]; diff --git a/tests/baselines/reference/noImplicitAnyIndexingSuppressed.js b/tests/baselines/reference/noImplicitAnyIndexingSuppressed.js index 5185a9b8db846..6d91d8eb83888 100644 --- a/tests/baselines/reference/noImplicitAnyIndexingSuppressed.js +++ b/tests/baselines/reference/noImplicitAnyIndexingSuppressed.js @@ -56,11 +56,11 @@ var MyEmusEnum; // Should be okay; should be a string. var strRepresentation1 = MyEmusEnum[0]; // Should be okay; should be a string. -var strRepresentation2 = MyEmusEnum[0 /* emu */]; +var strRepresentation2 = MyEmusEnum[MyEmusEnum.emu]; // Should be okay, as we suppress implicit 'any' property access checks var strRepresentation3 = MyEmusEnum["monehh"]; // Should be okay; should be a MyEmusEnum -var strRepresentation4 = 0 /* "emu" */; +var strRepresentation4 = MyEmusEnum["emu"]; // Should be okay, as we suppress implicit 'any' property access checks var x = {}["hi"]; // Should be okay, as we suppress implicit 'any' property access checks @@ -76,6 +76,6 @@ var m = { "2": 2, "Okay that's enough for today.": NaN }; -var mResult1 = m[0 /* emu */]; -var mResult2 = m[MyEmusEnum[0 /* emu */]]; +var mResult1 = m[MyEmusEnum.emu]; +var mResult2 = m[MyEmusEnum[MyEmusEnum.emu]]; var mResult3 = m[hi]; diff --git a/tests/baselines/reference/nullIsSubtypeOfEverythingButUndefined.js b/tests/baselines/reference/nullIsSubtypeOfEverythingButUndefined.js index f69fe668f34d5..b47a591444c04 100644 --- a/tests/baselines/reference/nullIsSubtypeOfEverythingButUndefined.js +++ b/tests/baselines/reference/nullIsSubtypeOfEverythingButUndefined.js @@ -149,8 +149,8 @@ var E; })(E || (E = {})); var r13 = true ? E : null; var r13 = true ? null : E; -var r14 = true ? 0 /* A */ : null; -var r14 = true ? null : 0 /* A */; +var r14 = true ? E.A : null; +var r14 = true ? null : E.A; function f() { } var f; diff --git a/tests/baselines/reference/objectTypesIdentity2.js b/tests/baselines/reference/objectTypesIdentity2.js index bdd20d8ac5e08..f721fb04b52d2 100644 --- a/tests/baselines/reference/objectTypesIdentity2.js +++ b/tests/baselines/reference/objectTypesIdentity2.js @@ -88,7 +88,7 @@ var E; E[E["A"] = 0] = "A"; })(E || (E = {})); var b = { - foo: 0 /* A */ + foo: E.A }; function foo5(x) { } diff --git a/tests/baselines/reference/operatorAddNullUndefined.js b/tests/baselines/reference/operatorAddNullUndefined.js index f6b4fd240b257..4d52dbb234c68 100644 --- a/tests/baselines/reference/operatorAddNullUndefined.js +++ b/tests/baselines/reference/operatorAddNullUndefined.js @@ -34,7 +34,7 @@ var x9 = "test" + null; var x10 = "test" + undefined; var x11 = null + "test"; var x12 = undefined + "test"; -var x13 = null + 0 /* x */; -var x14 = undefined + 0 /* x */; -var x15 = 0 /* x */ + null; -var x16 = 0 /* x */ + undefined; +var x13 = null + E.x; +var x14 = undefined + E.x; +var x15 = E.x + null; +var x16 = E.x + undefined; diff --git a/tests/baselines/reference/overloadResolutionOverNonCTLambdas.js b/tests/baselines/reference/overloadResolutionOverNonCTLambdas.js index d0ced9921469c..86e84ced58f0f 100644 --- a/tests/baselines/reference/overloadResolutionOverNonCTLambdas.js +++ b/tests/baselines/reference/overloadResolutionOverNonCTLambdas.js @@ -39,8 +39,8 @@ var Bugs; } var result = message.replace(/\{(\d+)\}/g, function (match) { var rest = []; - for (var _a = 1; _a < arguments.length; _a++) { - rest[_a - 1] = arguments[_a]; + for (var _i = 1; _i < arguments.length; _i++) { + rest[_i - 1] = arguments[_i]; } var index = rest[0]; return typeof args[index] !== 'undefined' ? args[index] : match; diff --git a/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt b/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt new file mode 100644 index 0000000000000..d109b0480854b --- /dev/null +++ b/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt @@ -0,0 +1,25 @@ +tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(4,16): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(5,17): error TS1100: Invalid use of 'eval' in strict mode. +tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(6,9): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(6,9): error TS2322: Type 'string' is not assignable to type 'IArguments'. + Property 'callee' is missing in type 'String'. + + +==== tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts (4 errors) ==== + class C { + interface = 10; + public implements() { } + public foo(arguments: any) { } + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. + private bar(eval:any) { + ~~~~ +!!! error TS1100: Invalid use of 'eval' in strict mode. + arguments = "hello"; + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. + ~~~~~~~~~ +!!! error TS2322: Type 'string' is not assignable to type 'IArguments'. +!!! error TS2322: Property 'callee' is missing in type 'String'. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.js b/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.js new file mode 100644 index 0000000000000..2a8d75dde60aa --- /dev/null +++ b/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.js @@ -0,0 +1,23 @@ +//// [parseClassDeclarationInStrictModeByDefaultInES6.ts] +class C { + interface = 10; + public implements() { } + public foo(arguments: any) { } + private bar(eval:any) { + arguments = "hello"; + } +} + +//// [parseClassDeclarationInStrictModeByDefaultInES6.js] +class C { + constructor() { + this.interface = 10; + } + implements() { + } + foo(arguments) { + } + bar(eval) { + arguments = "hello"; + } +} diff --git a/tests/baselines/reference/parser509698.errors.txt b/tests/baselines/reference/parser509698.errors.txt index 85485dd65012a..3dd70275e5c7a 100644 --- a/tests/baselines/reference/parser509698.errors.txt +++ b/tests/baselines/reference/parser509698.errors.txt @@ -1,21 +1,31 @@ +error TS2318: Cannot find global type 'Number'. +error TS2318: Cannot find global type 'TypedPropertyDescriptor'. +error TS2318: Cannot find global type 'Object'. +error TS2318: Cannot find global type 'Array'. +error TS2318: Cannot find global type 'ClassDecorator'. error TS2318: Cannot find global type 'String'. error TS2318: Cannot find global type 'RegExp'. -error TS2318: Cannot find global type 'Object'. -error TS2318: Cannot find global type 'Number'. -error TS2318: Cannot find global type 'IArguments'. +error TS2318: Cannot find global type 'PropertyDecorator'. +error TS2318: Cannot find global type 'ParameterDecorator'. error TS2318: Cannot find global type 'Function'. error TS2318: Cannot find global type 'Boolean'. -error TS2318: Cannot find global type 'Array'. +error TS2318: Cannot find global type 'MethodDecorator'. +error TS2318: Cannot find global type 'IArguments'. +!!! error TS2318: Cannot find global type 'Number'. +!!! error TS2318: Cannot find global type 'TypedPropertyDescriptor'. +!!! error TS2318: Cannot find global type 'Object'. +!!! error TS2318: Cannot find global type 'Array'. +!!! error TS2318: Cannot find global type 'ClassDecorator'. !!! error TS2318: Cannot find global type 'String'. !!! error TS2318: Cannot find global type 'RegExp'. -!!! error TS2318: Cannot find global type 'Object'. -!!! error TS2318: Cannot find global type 'Number'. -!!! error TS2318: Cannot find global type 'IArguments'. +!!! error TS2318: Cannot find global type 'PropertyDecorator'. +!!! error TS2318: Cannot find global type 'ParameterDecorator'. !!! error TS2318: Cannot find global type 'Function'. !!! error TS2318: Cannot find global type 'Boolean'. -!!! error TS2318: Cannot find global type 'Array'. +!!! error TS2318: Cannot find global type 'MethodDecorator'. +!!! error TS2318: Cannot find global type 'IArguments'. ==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser509698.ts (0 errors) ==== ///