fix(compiler): emit quoted object literal keys if the source is quoted

feat(tsc-wrapped): recored when to quote a object literal key

Collecting quoted literals is off by default as it introduces
a breaking change in the .metadata.json file. A follow-up commit
will address this.

Fixes #13249
Closes #13356
This commit is contained in:
Chuck Jazdzewski
2016-12-12 10:49:17 -08:00
committed by Victor Berchet
parent 5918133784
commit ecfad467a1
10 changed files with 136 additions and 21 deletions

View File

@ -13,11 +13,22 @@ import {ClassMetadata, ConstructorMetadata, FunctionMetadata, MemberMetadata, Me
import {Symbols} from './symbols';
/**
* A set of collector options to use when collecting metadata.
*/
export class CollectorOptions {
/**
* Collect a hidden field "$quoted$" in objects literals that record when the key was quoted in
* the source.
*/
quotedNames?: boolean;
}
/**
* Collect decorator metadata from a TypeScript module.
*/
export class MetadataCollector {
constructor() {}
constructor(private options: CollectorOptions = {}) {}
/**
* Returns a JSON.stringify friendly form describing the decorators of the exported classes from
@ -26,7 +37,7 @@ export class MetadataCollector {
public getMetadata(sourceFile: ts.SourceFile, strict: boolean = false): ModuleMetadata {
const locals = new Symbols(sourceFile);
const nodeMap = new Map<MetadataValue|ClassMetadata|FunctionMetadata, ts.Node>();
const evaluator = new Evaluator(locals, nodeMap);
const evaluator = new Evaluator(locals, nodeMap, this.options);
let metadata: {[name: string]: MetadataValue | ClassMetadata | FunctionMetadata}|undefined;
let exports: ModuleExportMetadata[];