Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tsc-wrapped): resolve short-hand literal values to locals #16873

Merged
merged 1 commit into from May 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 11 additions & 7 deletions tools/@angular/tsc-wrapped/src/evaluator.ts
Expand Up @@ -233,6 +233,15 @@ export class Evaluator {
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) {
case ts.SyntaxKind.ObjectLiteralExpression:
let obj: {[name: string]: any} = {};
Expand All @@ -253,7 +262,7 @@ export class Evaluator {
}
const propertyValue = isPropertyAssignment(assignment) ?
this.evaluateNode(assignment.initializer) :
{__symbolic: 'reference', name: propertyName};
resolveName(propertyName);
if (isFoldableError(propertyValue)) {
error = propertyValue;
return true; // Stop the forEachChild.
Expand Down Expand Up @@ -384,12 +393,7 @@ export class Evaluator {
case ts.SyntaxKind.Identifier:
const identifier = <ts.Identifier>node;
const name = identifier.text;
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;
return resolveName(name);
case ts.SyntaxKind.TypeReference:
const typeReferenceNode = <ts.TypeReferenceNode>node;
const typeNameNode = typeReferenceNode.typeName;
Expand Down
15 changes: 15 additions & 0 deletions tools/@angular/tsc-wrapped/test/collector.spec.ts
Expand Up @@ -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) {
host.overrideFile(fileName, content);
host.addFile(fileName);
Expand Down