@@ -4959,6 +4959,7 @@ namespace ts {
49594959 createNamedExports(flatMap(exports, e => e.exportClause!.elements)),
49604960 /*moduleSpecifier*/ undefined
49614961 )];
4962+ // TODO combine multiple `export {a} from "..."` into a single statement
49624963 }
49634964 // Pass 3: Move all `export {}`'s to `export` modifiers where possible
49644965 const exportDecl = find(statements, d => isExportDeclaration(d) && !d.moduleSpecifier && !!d.exportClause) as ExportDeclaration | undefined;
@@ -5091,7 +5092,7 @@ namespace ts {
50915092 // Each overload becomes a seperate function declaration, in order
50925093 const decl = signatureToSignatureDeclarationHelper(sig, SyntaxKind.FunctionDeclaration, context) as FunctionDeclaration;
50935094 decl.name = createIdentifier(localName);
5094- addResult(decl, modifierFlags);
5095+ addResult(setTextRange( decl, sig.declaration) , modifierFlags);
50955096 }
50965097 const props = getPropertiesOfType(type);
50975098 if (length(props)) {
@@ -5142,14 +5143,14 @@ namespace ts {
51425143 c.typeParameters = undefined;
51435144 }
51445145 const indexSignatures = serializeIndexSignatures(classType, baseTypes[0]);
5145- addResult(createClassDeclaration(
5146+ addResult(setTextRange( createClassDeclaration(
51465147 /*decorators*/ undefined,
51475148 /*modifiers*/ undefined,
51485149 localName,
51495150 typeParamDecls,
51505151 heritageClauses,
51515152 [...indexSignatures, ...staticMembers, ...constructors, ...members]
5152- ), modifierFlags);
5153+ ), filter(symbol.declarations, d => isClassDeclaration(d) || isClassExpression(d))[0]), modifierFlags);
51535154 }
51545155
51555156 // Synthesize declarations for a symbol - might be an Interface, a Class, a Namespace, a Type, a Variable (const, let, or var), an Alias
@@ -5200,9 +5201,13 @@ namespace ts {
52005201 // `var` is `FunctionScopedVariable`, `const` and `let` are `BlockScopedVariable`, and `module.exports.thing =` is `Property`
52015202 const flags = !(symbol.flags & SymbolFlags.BlockScopedVariable) ? undefined : isConstVariable(symbol) ? NodeFlags.Const : NodeFlags.Let;
52025203 const name = (needsPostExportDefault || !(symbol.flags & SymbolFlags.Property)) ? localName : getUnusedName(localName, symbol);
5203- const statement = createVariableStatement(/*modifiers*/ undefined, createVariableDeclarationList([
5204+ let textRange: Node | undefined = filter(symbol.declarations, d => isVariableDeclaration(d))[0];
5205+ if (textRange && isVariableDeclarationList(textRange.parent) && textRange.parent.declarations.length === 1) {
5206+ textRange = textRange.parent.parent;
5207+ }
5208+ const statement = setTextRange(createVariableStatement(/*modifiers*/ undefined, createVariableDeclarationList([
52045209 createVariableDeclaration(name, serializeTypeForDeclaration(getTypeOfSymbol(symbol), symbol))
5205- ], flags));
5210+ ], flags)), textRange) ;
52065211 addResult(statement, name !== localName ? modifierFlags & ~ModifierFlags.Export : modifierFlags);
52075212 if (name !== localName && !isPrivate) {
52085213 // We rename the variable declaration we generate for Property symbols since they may have a name which conflicts with a local declaration. Eg,
@@ -5338,7 +5343,8 @@ namespace ts {
53385343 break;
53395344 case SyntaxKind.ExportSpecifier:
53405345 // does not use localName because the symbol name in this case refers to the name in the exports table, which we must exactly preserve
5341- serializeExportSpecifier(unescapeLeadingUnderscores(symbol.escapedName), targetName);
5346+ const specifier = (node.parent.parent as ExportDeclaration).moduleSpecifier;
5347+ serializeExportSpecifier(unescapeLeadingUnderscores(symbol.escapedName), targetName, specifier && isStringLiteralLike(specifier) ? createLiteral(specifier.text) : undefined);
53425348 break;
53435349 case SyntaxKind.ExportAssignment:
53445350 serializeMaybeAliasAssignment(symbol);
@@ -5362,8 +5368,13 @@ namespace ts {
53625368 }
53635369 }
53645370
5365- function serializeExportSpecifier(localName: string, targetName: string) {
5366- addResult(createExportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, createNamedExports([createExportSpecifier(localName !== targetName ? targetName : undefined, localName)])), ModifierFlags.None);
5371+ function serializeExportSpecifier(localName: string, targetName: string, specifier?: Expression) {
5372+ addResult(createExportDeclaration(
5373+ /*decorators*/ undefined,
5374+ /*modifiers*/ undefined,
5375+ createNamedExports([createExportSpecifier(localName !== targetName ? targetName : undefined, localName)]),
5376+ specifier
5377+ ), ModifierFlags.None);
53675378 }
53685379
53695380 function serializeMaybeAliasAssignment(symbol: Symbol) {
@@ -5485,14 +5496,14 @@ namespace ts {
54855496 const rawName = unescapeLeadingUnderscores(p.escapedName);
54865497 const name = getPropertyNameNodeForSymbolFromNameType(p, context) || createIdentifier(rawName);
54875498 if (p.flags & (SymbolFlags.Property | SymbolFlags.Accessor | SymbolFlags.Variable)) {
5488- return createProperty(
5499+ return setTextRange( createProperty(
54895500 /*decorators*/ undefined,
54905501 createModifiersFromModifierFlags((isReadonlySymbol(p) ? ModifierFlags.Readonly : 0) | staticFlag),
54915502 name,
54925503 p.flags & SymbolFlags.Optional ? createToken(SyntaxKind.QuestionToken) : undefined,
54935504 serializeTypeForDeclaration(getTypeOfSymbol(p), p),
54945505 /*initializer*/ undefined // interface members can't have initializers, however class members _can_
5495- );
5506+ ), filter(p.declarations, d => isPropertyDeclaration(d) || isAccessor(d) || isVariableDeclaration(d) || isPropertySignature(d) || isBinaryExpression(d) || isPropertyAccessExpression(d))[0]) ;
54965507 }
54975508 if (p.flags & (SymbolFlags.Method | SymbolFlags.Function)) {
54985509 const type = getTypeOfSymbol(p);
@@ -5508,7 +5519,7 @@ namespace ts {
55085519 if (p.flags & SymbolFlags.Optional) {
55095520 decl.questionToken = createToken(SyntaxKind.QuestionToken);
55105521 }
5511- results.push(decl);
5522+ results.push(setTextRange( decl, sig.declaration) );
55125523 }
55135524 return results as unknown as T[];
55145525 }
@@ -5695,7 +5706,7 @@ namespace ts {
56955706 for (const sig of signatures) {
56965707 // Each overload becomes a seperate constructor declaration, in order
56975708 const decl = signatureToSignatureDeclarationHelper(sig, outputKind, context);
5698- results.push(decl);
5709+ results.push(setTextRange( decl, sig.declaration) );
56995710 }
57005711 return results;
57015712 }
0 commit comments