fix(tsc-wrapped): resolve short-hand literal values to locals (#16873)
Fixes: #16872
This commit is contained in:
parent
98849de127
commit
11c10b2ab8
|
@ -233,6 +233,15 @@ export class Evaluator {
|
||||||
return !t.options.verboseInvalidExpression && isMetadataError(value);
|
return !t.options.verboseInvalidExpression && isMetadataError(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const resolveName = (name: string): MetadataValue => {
|
||||||
|
const reference = this.symbols.resolve(name);
|
||||||
|
if (reference === undefined) {
|
||||||
|
// Encode as a global reference. StaticReflector will check the reference.
|
||||||
|
return recordEntry({__symbolic: 'reference', name}, node);
|
||||||
|
}
|
||||||
|
return reference;
|
||||||
|
};
|
||||||
|
|
||||||
switch (node.kind) {
|
switch (node.kind) {
|
||||||
case ts.SyntaxKind.ObjectLiteralExpression:
|
case ts.SyntaxKind.ObjectLiteralExpression:
|
||||||
let obj: {[name: string]: any} = {};
|
let obj: {[name: string]: any} = {};
|
||||||
|
@ -253,7 +262,7 @@ export class Evaluator {
|
||||||
}
|
}
|
||||||
const propertyValue = isPropertyAssignment(assignment) ?
|
const propertyValue = isPropertyAssignment(assignment) ?
|
||||||
this.evaluateNode(assignment.initializer) :
|
this.evaluateNode(assignment.initializer) :
|
||||||
{__symbolic: 'reference', name: propertyName};
|
resolveName(propertyName);
|
||||||
if (isFoldableError(propertyValue)) {
|
if (isFoldableError(propertyValue)) {
|
||||||
error = propertyValue;
|
error = propertyValue;
|
||||||
return true; // Stop the forEachChild.
|
return true; // Stop the forEachChild.
|
||||||
|
@ -384,12 +393,7 @@ export class Evaluator {
|
||||||
case ts.SyntaxKind.Identifier:
|
case ts.SyntaxKind.Identifier:
|
||||||
const identifier = <ts.Identifier>node;
|
const identifier = <ts.Identifier>node;
|
||||||
const name = identifier.text;
|
const name = identifier.text;
|
||||||
const reference = this.symbols.resolve(name);
|
return resolveName(name);
|
||||||
if (reference === undefined) {
|
|
||||||
// Encode as a global reference. StaticReflector will check the reference.
|
|
||||||
return recordEntry({__symbolic: 'reference', name}, node);
|
|
||||||
}
|
|
||||||
return reference;
|
|
||||||
case ts.SyntaxKind.TypeReference:
|
case ts.SyntaxKind.TypeReference:
|
||||||
const typeReferenceNode = <ts.TypeReferenceNode>node;
|
const typeReferenceNode = <ts.TypeReferenceNode>node;
|
||||||
const typeNameNode = typeReferenceNode.typeName;
|
const typeNameNode = typeReferenceNode.typeName;
|
||||||
|
|
|
@ -721,6 +721,21 @@ describe('Collector', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('regerssion', () => {
|
||||||
|
it('should be able to collect a short-hand property value', () => {
|
||||||
|
const source = ts.createSourceFile(
|
||||||
|
'', `
|
||||||
|
const children = { f1: 1 };
|
||||||
|
export const r = [
|
||||||
|
{path: ':locale', children}
|
||||||
|
];
|
||||||
|
`,
|
||||||
|
ts.ScriptTarget.Latest, true);
|
||||||
|
const metadata = collector.getMetadata(source);
|
||||||
|
expect(metadata.metadata).toEqual({r: [{path: ':locale', children: {f1: 1}}]});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
function override(fileName: string, content: string) {
|
function override(fileName: string, content: string) {
|
||||||
host.overrideFile(fileName, content);
|
host.overrideFile(fileName, content);
|
||||||
host.addFile(fileName);
|
host.addFile(fileName);
|
||||||
|
|
Loading…
Reference in New Issue