@@ -4959,6 +4959,7 @@ namespace ts {
4959
4959
createNamedExports(flatMap(exports, e => e.exportClause!.elements)),
4960
4960
/*moduleSpecifier*/ undefined
4961
4961
)];
4962
+ // TODO combine multiple `export {a} from "..."` into a single statement
4962
4963
}
4963
4964
// Pass 3: Move all `export {}`'s to `export` modifiers where possible
4964
4965
const exportDecl = find(statements, d => isExportDeclaration(d) && !d.moduleSpecifier && !!d.exportClause) as ExportDeclaration | undefined;
@@ -5091,7 +5092,7 @@ namespace ts {
5091
5092
// Each overload becomes a seperate function declaration, in order
5092
5093
const decl = signatureToSignatureDeclarationHelper(sig, SyntaxKind.FunctionDeclaration, context) as FunctionDeclaration;
5093
5094
decl.name = createIdentifier(localName);
5094
- addResult(decl, modifierFlags);
5095
+ addResult(setTextRange( decl, sig.declaration) , modifierFlags);
5095
5096
}
5096
5097
const props = getPropertiesOfType(type);
5097
5098
if (length(props)) {
@@ -5142,14 +5143,14 @@ namespace ts {
5142
5143
c.typeParameters = undefined;
5143
5144
}
5144
5145
const indexSignatures = serializeIndexSignatures(classType, baseTypes[0]);
5145
- addResult(createClassDeclaration(
5146
+ addResult(setTextRange( createClassDeclaration(
5146
5147
/*decorators*/ undefined,
5147
5148
/*modifiers*/ undefined,
5148
5149
localName,
5149
5150
typeParamDecls,
5150
5151
heritageClauses,
5151
5152
[...indexSignatures, ...staticMembers, ...constructors, ...members]
5152
- ), modifierFlags);
5153
+ ), filter(symbol.declarations, d => isClassDeclaration(d) || isClassExpression(d))[0]), modifierFlags);
5153
5154
}
5154
5155
5155
5156
// 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 {
5200
5201
// `var` is `FunctionScopedVariable`, `const` and `let` are `BlockScopedVariable`, and `module.exports.thing =` is `Property`
5201
5202
const flags = !(symbol.flags & SymbolFlags.BlockScopedVariable) ? undefined : isConstVariable(symbol) ? NodeFlags.Const : NodeFlags.Let;
5202
5203
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([
5204
5209
createVariableDeclaration(name, serializeTypeForDeclaration(getTypeOfSymbol(symbol), symbol))
5205
- ], flags));
5210
+ ], flags)), textRange) ;
5206
5211
addResult(statement, name !== localName ? modifierFlags & ~ModifierFlags.Export : modifierFlags);
5207
5212
if (name !== localName && !isPrivate) {
5208
5213
// 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 {
5338
5343
break;
5339
5344
case SyntaxKind.ExportSpecifier:
5340
5345
// 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);
5342
5348
break;
5343
5349
case SyntaxKind.ExportAssignment:
5344
5350
serializeMaybeAliasAssignment(symbol);
@@ -5362,8 +5368,13 @@ namespace ts {
5362
5368
}
5363
5369
}
5364
5370
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);
5367
5378
}
5368
5379
5369
5380
function serializeMaybeAliasAssignment(symbol: Symbol) {
@@ -5485,14 +5496,14 @@ namespace ts {
5485
5496
const rawName = unescapeLeadingUnderscores(p.escapedName);
5486
5497
const name = getPropertyNameNodeForSymbolFromNameType(p, context) || createIdentifier(rawName);
5487
5498
if (p.flags & (SymbolFlags.Property | SymbolFlags.Accessor | SymbolFlags.Variable)) {
5488
- return createProperty(
5499
+ return setTextRange( createProperty(
5489
5500
/*decorators*/ undefined,
5490
5501
createModifiersFromModifierFlags((isReadonlySymbol(p) ? ModifierFlags.Readonly : 0) | staticFlag),
5491
5502
name,
5492
5503
p.flags & SymbolFlags.Optional ? createToken(SyntaxKind.QuestionToken) : undefined,
5493
5504
serializeTypeForDeclaration(getTypeOfSymbol(p), p),
5494
5505
/*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]) ;
5496
5507
}
5497
5508
if (p.flags & (SymbolFlags.Method | SymbolFlags.Function)) {
5498
5509
const type = getTypeOfSymbol(p);
@@ -5508,7 +5519,7 @@ namespace ts {
5508
5519
if (p.flags & SymbolFlags.Optional) {
5509
5520
decl.questionToken = createToken(SyntaxKind.QuestionToken);
5510
5521
}
5511
- results.push(decl);
5522
+ results.push(setTextRange( decl, sig.declaration) );
5512
5523
}
5513
5524
return results as unknown as T[];
5514
5525
}
@@ -5695,7 +5706,7 @@ namespace ts {
5695
5706
for (const sig of signatures) {
5696
5707
// Each overload becomes a seperate constructor declaration, in order
5697
5708
const decl = signatureToSignatureDeclarationHelper(sig, outputKind, context);
5698
- results.push(decl);
5709
+ results.push(setTextRange( decl, sig.declaration) );
5699
5710
}
5700
5711
return results;
5701
5712
}
0 commit comments