mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 19:55:08 -06:00
PR Feedback, also removes cloneEntityName.
This commit is contained in:
parent
446494060d
commit
9899cda6d3
@ -16216,7 +16216,10 @@ namespace ts {
|
||||
const exportClause = (<ExportDeclaration>node).exportClause;
|
||||
return exportClause && forEach(exportClause.elements, isValueAliasDeclaration);
|
||||
case SyntaxKind.ExportAssignment:
|
||||
return (<ExportAssignment>node).expression && (<ExportAssignment>node).expression.kind === SyntaxKind.Identifier ? isAliasResolvedToValue(getSymbolOfNode(node) || unknownSymbol) : true;
|
||||
return (<ExportAssignment>node).expression
|
||||
&& (<ExportAssignment>node).expression.kind === SyntaxKind.Identifier
|
||||
? isAliasResolvedToValue(getSymbolOfNode(node) || unknownSymbol)
|
||||
: true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2240,41 +2240,49 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
emit(node.right);
|
||||
}
|
||||
|
||||
function emitQualifiedNameAsExpression(node: QualifiedName, useFallback: boolean) {
|
||||
function emitQualifiedNameAsExpression(node: QualifiedName, useFallback: boolean, location?: Node) {
|
||||
if (node.left.kind === SyntaxKind.Identifier) {
|
||||
emitEntityNameAsExpression(node.left, useFallback);
|
||||
emitEntityNameAsExpression(node.left, useFallback, location);
|
||||
}
|
||||
else if (useFallback) {
|
||||
const temp = createAndRecordTempVariable(TempFlags.Auto);
|
||||
write("(");
|
||||
emitNodeWithoutSourceMap(temp);
|
||||
write(" = ");
|
||||
emitEntityNameAsExpression(node.left, /*useFallback*/ true);
|
||||
emitEntityNameAsExpression(node.left, /*useFallback*/ true, location);
|
||||
write(") && ");
|
||||
emitNodeWithoutSourceMap(temp);
|
||||
}
|
||||
else {
|
||||
emitEntityNameAsExpression(node.left, /*useFallback*/ false);
|
||||
emitEntityNameAsExpression(node.left, /*useFallback*/ false, location);
|
||||
}
|
||||
|
||||
write(".");
|
||||
emit(node.right);
|
||||
}
|
||||
|
||||
function emitEntityNameAsExpression(node: EntityName | Expression, useFallback: boolean) {
|
||||
function emitEntityNameAsExpression(node: EntityName | Expression, useFallback: boolean, location?: Node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
let name = <Identifier>node;
|
||||
if (location) {
|
||||
// to resolve the expression to the correct container, create a shallow
|
||||
// clone of `node` with a new parent.
|
||||
name = clone(name);
|
||||
name.parent = location;
|
||||
}
|
||||
|
||||
if (useFallback) {
|
||||
write("typeof ");
|
||||
emitExpressionIdentifier(<Identifier>node);
|
||||
emitExpressionIdentifier(name);
|
||||
write(" !== 'undefined' && ");
|
||||
}
|
||||
|
||||
emitExpressionIdentifier(<Identifier>node);
|
||||
emitExpressionIdentifier(name);
|
||||
break;
|
||||
|
||||
case SyntaxKind.QualifiedName:
|
||||
emitQualifiedNameAsExpression(<QualifiedName>node, useFallback);
|
||||
emitQualifiedNameAsExpression(<QualifiedName>node, useFallback, location);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -5943,22 +5951,21 @@ const _super = (function (geti, seti) {
|
||||
}
|
||||
|
||||
// Clone the type name and parent it to a location outside of the current declaration.
|
||||
const typeName = cloneEntityName(node.typeName, location);
|
||||
const result = resolver.getTypeReferenceSerializationKind(typeName);
|
||||
const result = resolver.getTypeReferenceSerializationKind(node.typeName, location);
|
||||
switch (result) {
|
||||
case TypeReferenceSerializationKind.Unknown:
|
||||
let temp = createAndRecordTempVariable(TempFlags.Auto);
|
||||
write("(typeof (");
|
||||
emitNodeWithoutSourceMap(temp);
|
||||
write(" = ");
|
||||
emitEntityNameAsExpression(typeName, /*useFallback*/ true);
|
||||
emitEntityNameAsExpression(node.typeName, /*useFallback*/ true, location);
|
||||
write(") === 'function' && ");
|
||||
emitNodeWithoutSourceMap(temp);
|
||||
write(") || Object");
|
||||
break;
|
||||
|
||||
case TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue:
|
||||
emitEntityNameAsExpression(typeName, /*useFallback*/ false);
|
||||
emitEntityNameAsExpression(node.typeName, /*useFallback*/ false, location);
|
||||
break;
|
||||
|
||||
case TypeReferenceSerializationKind.VoidType:
|
||||
|
||||
@ -2644,7 +2644,7 @@ namespace ts {
|
||||
return getNamespaceMemberName(name);
|
||||
}
|
||||
else {
|
||||
// We set the "PrefixExportedLocal" flag to indicate to any module transformer
|
||||
// We set the "ExportName" flag to indicate to any module transformer
|
||||
// downstream that any `exports.` prefix should be added.
|
||||
setNodeEmitFlags(name, getNodeEmitFlags(name) | NodeEmitFlags.ExportName);
|
||||
return name;
|
||||
|
||||
@ -1711,28 +1711,6 @@ namespace ts {
|
||||
|| kind === SyntaxKind.SourceFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a deep clone of an EntityName, with new parent pointers.
|
||||
* NOTE: The new entity name will *not* have "original" pointers.
|
||||
*
|
||||
* @param node The EntityName to clone.
|
||||
* @param parent The parent for the cloned node.
|
||||
*/
|
||||
export function cloneEntityName(node: EntityName, parent?: Node): EntityName {
|
||||
const clone = getMutableClone(node);
|
||||
clone.original = undefined;
|
||||
clone.parent = parent;
|
||||
if (isQualifiedName(clone)) {
|
||||
const { left, right } = clone;
|
||||
clone.left = cloneEntityName(left, clone);
|
||||
clone.right = getMutableClone(right);
|
||||
clone.right.original = undefined;
|
||||
clone.right.parent = clone;
|
||||
}
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
export function nodeIsSynthesized(node: TextRange): boolean {
|
||||
return positionIsSynthesized(node.pos)
|
||||
|| positionIsSynthesized(node.end);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user