@angular/tsc-wrapped
Advanced tools
Comparing version 0.4.2 to 0.5.0
{ | ||
"name": "@angular/tsc-wrapped", | ||
"version": "0.4.2", | ||
"version": "0.5.0", | ||
"description": "Wraps the tsc CLI, allowing extensions.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/angular/angular/tree/master/tools/tsc-wrapped", |
@@ -11,6 +11,21 @@ /** | ||
/** | ||
* A set of collector options to use when collecting metadata. | ||
*/ | ||
export declare class CollectorOptions { | ||
/** | ||
* Version of the metadata to collect. | ||
*/ | ||
version?: number; | ||
/** | ||
* 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 declare class MetadataCollector { | ||
constructor(); | ||
private options; | ||
constructor(options?: CollectorOptions); | ||
/** | ||
@@ -17,0 +32,0 @@ * Returns a JSON.stringify friendly form describing the decorators of the exported classes from |
@@ -14,6 +14,17 @@ /** | ||
/** | ||
* A set of collector options to use when collecting metadata. | ||
*/ | ||
var CollectorOptions = (function () { | ||
function CollectorOptions() { | ||
} | ||
return CollectorOptions; | ||
}()); | ||
exports.CollectorOptions = CollectorOptions; | ||
/** | ||
* Collect decorator metadata from a TypeScript module. | ||
*/ | ||
var MetadataCollector = (function () { | ||
function MetadataCollector() { | ||
function MetadataCollector(options) { | ||
if (options === void 0) { options = {}; } | ||
this.options = options; | ||
} | ||
@@ -28,3 +39,3 @@ /** | ||
var nodeMap = new Map(); | ||
var evaluator = new evaluator_1.Evaluator(locals, nodeMap); | ||
var evaluator = new evaluator_1.Evaluator(locals, nodeMap, this.options); | ||
var metadata; | ||
@@ -229,3 +240,16 @@ var exports; | ||
var exportDeclaration = node; | ||
var moduleSpecifier = exportDeclaration.moduleSpecifier; | ||
var moduleSpecifier = exportDeclaration.moduleSpecifier, exportClause = exportDeclaration.exportClause; | ||
if (!moduleSpecifier) { | ||
// no module specifier -> export {propName as name}; | ||
if (exportClause) { | ||
exportClause.elements.forEach(function (spec) { | ||
var name = spec.name.text; | ||
var propNode = spec.propertyName || spec.name; | ||
var value = evaluator.evaluateNode(propNode); | ||
if (!metadata) | ||
metadata = {}; | ||
metadata[name] = recordEntry(value, node); | ||
}); | ||
} | ||
} | ||
if (moduleSpecifier && moduleSpecifier.kind == ts.SyntaxKind.StringLiteral) { | ||
@@ -236,6 +260,5 @@ // Ignore exports that don't have string literals as exports. | ||
var moduleExport = { from: from }; | ||
if (exportDeclaration.exportClause) { | ||
moduleExport.export = exportDeclaration.exportClause.elements.map(function (element) { return element.propertyName ? | ||
{ name: element.propertyName.text, as: element.name.text } : | ||
element.name.text; }); | ||
if (exportClause) { | ||
moduleExport.export = exportClause.elements.map(function (spec) { return spec.propertyName ? { name: spec.propertyName.text, as: spec.name.text } : | ||
spec.name.text; }); | ||
} | ||
@@ -317,3 +340,2 @@ if (!exports) | ||
} | ||
; | ||
} | ||
@@ -361,3 +383,3 @@ if (writtenMembers) { | ||
// Destructuring (or binding) declarations are not supported, | ||
// var {<identifier>[, <identifer>]+} = <expression>; | ||
// var {<identifier>[, <identifier>]+} = <expression>; | ||
// or | ||
@@ -405,3 +427,6 @@ // var [<identifier>[, <identifier}+] = <expression>; | ||
} | ||
var result = { __symbolic: 'module', version: schema_1.VERSION, metadata: metadata }; | ||
var result = { | ||
__symbolic: 'module', | ||
version: this.options.version || schema_1.VERSION, metadata: metadata | ||
}; | ||
if (exports) | ||
@@ -408,0 +433,0 @@ result.exports = exports; |
@@ -45,2 +45,3 @@ import * as ts from 'typescript'; | ||
private metadataCollector; | ||
private metadataCollector1; | ||
constructor(delegate: ts.CompilerHost, ngOptions: NgOptions); | ||
@@ -47,0 +48,0 @@ private writeMetadata(emitFilePath, sourceFile); |
@@ -115,3 +115,3 @@ /** | ||
exports.TsickleCompilerHost = TsickleCompilerHost; | ||
var IGNORED_FILES = /\.ngfactory\.js$|\.css\.js$|\.css\.shim\.js$/; | ||
var IGNORED_FILES = /\.ngfactory\.js$|\.ngstyle\.js$/; | ||
var MetadataWriterHost = (function (_super) { | ||
@@ -123,3 +123,4 @@ __extends(MetadataWriterHost, _super); | ||
this.ngOptions = ngOptions; | ||
this.metadataCollector = new collector_1.MetadataCollector(); | ||
this.metadataCollector = new collector_1.MetadataCollector({ quotedNames: true }); | ||
this.metadataCollector1 = new collector_1.MetadataCollector({ version: 1 }); | ||
this.writeFile = function (fileName, data, writeByteOrderMark, onError, sourceFiles) { | ||
@@ -153,14 +154,5 @@ if (/\.d\.ts$/.test(fileName)) { | ||
var metadata = this.metadataCollector.getMetadata(sourceFile, !!this.ngOptions.strictMetadataEmit); | ||
var metadatas = [metadata]; | ||
if (metadata && metadata.metadata) { | ||
if (metadata.version === 2) { | ||
// Also emit a version 1 so that older clients can consume new metadata files as well. | ||
// We can write the same data as version 2 is a strict super set. | ||
metadatas.push({ | ||
__symbolic: metadata.__symbolic, | ||
exports: metadata.exports, | ||
metadata: metadata.metadata, | ||
version: 1 | ||
}); | ||
} | ||
var metadata1 = this.metadataCollector1.getMetadata(sourceFile, false); | ||
var metadatas = [metadata, metadata1].filter(function (e) { return !!e; }); | ||
if (metadatas.length) { | ||
var metadataText = JSON.stringify(metadatas); | ||
@@ -167,0 +159,0 @@ fs_1.writeFileSync(path_1, metadataText, { encoding: 'utf-8' }); |
@@ -9,2 +9,3 @@ /** | ||
import * as ts from 'typescript'; | ||
import { CollectorOptions } from './collector'; | ||
import { MetadataEntry, MetadataError, MetadataValue } from './schema'; | ||
@@ -33,3 +34,4 @@ import { Symbols } from './symbols'; | ||
private nodeMap; | ||
constructor(symbols: Symbols, nodeMap: Map<MetadataEntry, ts.Node>); | ||
private options; | ||
constructor(symbols: Symbols, nodeMap: Map<MetadataEntry, ts.Node>, options?: CollectorOptions); | ||
nameOf(node: ts.Node): string | MetadataError; | ||
@@ -36,0 +38,0 @@ /** |
@@ -76,5 +76,7 @@ /** | ||
var Evaluator = (function () { | ||
function Evaluator(symbols, nodeMap) { | ||
function Evaluator(symbols, nodeMap, options) { | ||
if (options === void 0) { options = {}; } | ||
this.symbols = symbols; | ||
this.nodeMap = nodeMap; | ||
this.options = options; | ||
} | ||
@@ -202,2 +204,3 @@ Evaluator.prototype.nameOf = function (node) { | ||
var obj_1 = {}; | ||
var quoted_1 = []; | ||
ts.forEachChild(node, function (child) { | ||
@@ -208,2 +211,6 @@ switch (child.kind) { | ||
var assignment = child; | ||
if (assignment.name.kind == ts.SyntaxKind.StringLiteral) { | ||
var name_2 = assignment.name.text; | ||
quoted_1.push(name_2); | ||
} | ||
var propertyName = _this.nameOf(assignment.name); | ||
@@ -228,2 +235,5 @@ if (schema_1.isMetadataError(propertyName)) { | ||
return error; | ||
if (this.options.quotedNames && quoted_1.length) { | ||
obj_1['$quoted$'] = quoted_1; | ||
} | ||
return obj_1; | ||
@@ -343,7 +353,7 @@ case ts.SyntaxKind.ArrayLiteralExpression: | ||
var identifier = node; | ||
var name_2 = identifier.text; | ||
var reference = this.symbols.resolve(name_2); | ||
var name_3 = identifier.text; | ||
var reference = this.symbols.resolve(name_3); | ||
if (reference === undefined) { | ||
// Encode as a global reference. StaticReflector will check the reference. | ||
return recordEntry({ __symbolic: 'reference', name: name_2 }, node); | ||
return recordEntry({ __symbolic: 'reference', name: name_3 }, node); | ||
} | ||
@@ -350,0 +360,0 @@ return reference; |
@@ -15,3 +15,3 @@ /** | ||
// can accurately represent the metadata, generate both version 1 and version 2 in an array. | ||
exports.VERSION = 2; | ||
exports.VERSION = 3; | ||
function isModuleMetadata(value) { | ||
@@ -18,0 +18,0 @@ return value && value.__symbolic === 'module'; |
@@ -37,2 +37,3 @@ /** | ||
're-exports.ts', | ||
're-exports-2.ts', | ||
'static-field-reference.ts', | ||
@@ -49,3 +50,3 @@ 'static-method.ts', | ||
program = service.getProgram(); | ||
collector = new collector_1.MetadataCollector(); | ||
collector = new collector_1.MetadataCollector({ quotedNames: true }); | ||
}); | ||
@@ -63,3 +64,3 @@ it('should not have errors in test data', function () { typescript_mocks_1.expectValidSources(service, program); }); | ||
__symbolic: 'module', | ||
version: 2, | ||
version: 3, | ||
metadata: { | ||
@@ -94,3 +95,3 @@ HeroDetailComponent: { | ||
__symbolic: 'module', | ||
version: 2, | ||
version: 3, | ||
metadata: { | ||
@@ -138,10 +139,15 @@ AppComponent: { | ||
__symbolic: 'module', | ||
version: 2, | ||
version: 3, | ||
metadata: { | ||
HEROES: [ | ||
{ 'id': 11, 'name': 'Mr. Nice' }, { 'id': 12, 'name': 'Narco' }, | ||
{ 'id': 13, 'name': 'Bombasto' }, { 'id': 14, 'name': 'Celeritas' }, | ||
{ 'id': 15, 'name': 'Magneta' }, { 'id': 16, 'name': 'RubberMan' }, | ||
{ 'id': 17, 'name': 'Dynama' }, { 'id': 18, 'name': 'Dr IQ' }, { 'id': 19, 'name': 'Magma' }, | ||
{ 'id': 20, 'name': 'Tornado' } | ||
{ 'id': 11, 'name': 'Mr. Nice', '$quoted$': ['id', 'name'] }, | ||
{ 'id': 12, 'name': 'Narco', '$quoted$': ['id', 'name'] }, | ||
{ 'id': 13, 'name': 'Bombasto', '$quoted$': ['id', 'name'] }, | ||
{ 'id': 14, 'name': 'Celeritas', '$quoted$': ['id', 'name'] }, | ||
{ 'id': 15, 'name': 'Magneta', '$quoted$': ['id', 'name'] }, | ||
{ 'id': 16, 'name': 'RubberMan', '$quoted$': ['id', 'name'] }, | ||
{ 'id': 17, 'name': 'Dynama', '$quoted$': ['id', 'name'] }, | ||
{ 'id': 18, 'name': 'Dr IQ', '$quoted$': ['id', 'name'] }, | ||
{ 'id': 19, 'name': 'Magma', '$quoted$': ['id', 'name'] }, | ||
{ 'id': 20, 'name': 'Tornado', '$quoted$': ['id', 'name'] } | ||
] | ||
@@ -206,3 +212,3 @@ } | ||
__symbolic: 'module', | ||
version: 2, | ||
version: 3, | ||
metadata: { | ||
@@ -246,3 +252,3 @@ a: { __symbolic: 'error', message: 'Destructuring not supported', line: 1, character: 16 }, | ||
__symbolic: 'module', | ||
version: 2, | ||
version: 3, | ||
metadata: { | ||
@@ -260,3 +266,3 @@ SimpleClass: { __symbolic: 'class' }, | ||
__symbolic: 'module', | ||
version: 2, | ||
version: 3, | ||
metadata: { | ||
@@ -480,2 +486,18 @@ one: { | ||
}); | ||
it('should be able to collect exports with no module specifier', function () { | ||
var source = program.getSourceFile('/re-exports-2.ts'); | ||
var metadata = collector.getMetadata(source); | ||
expect(metadata.metadata).toEqual({ | ||
OtherModule: { __symbolic: 'reference', module: './static-field-reference', name: 'Foo' }, | ||
MyOtherModule: { __symbolic: 'reference', module: './static-field', name: 'MyModule' }, | ||
// TODO(vicb): support exported symbols - https://github.com/angular/angular/issues/13473 | ||
MyClass: { | ||
__symbolic: 'error', | ||
message: 'Reference to non-exported class', | ||
line: 3, | ||
character: 4, | ||
context: { className: 'MyClass' } | ||
}, | ||
}); | ||
}); | ||
it('should collect an error symbol if collecting a reference to a non-exported symbol', function () { | ||
@@ -636,2 +658,3 @@ var source = program.getSourceFile('/local-symbol-ref.ts'); | ||
're-exports.ts': "\n export {MyModule} from './static-field';\n export {Foo as OtherModule} from './static-field-reference';\n export * from 'angular2/core';\n ", | ||
're-exports-2.ts': "\n import {MyModule} from './static-field';\n import {Foo as OtherModule} from './static-field-reference';\n class MyClass {}\n export {OtherModule, MyModule as MyOtherModule, MyClass};\n ", | ||
'local-symbol-ref.ts': "\n import {Component, Validators} from 'angular2/core';\n\n var REQUIRED;\n\n export const REQUIRED_VALIDATOR: any = {\n provide: 'SomeToken',\n useValue: REQUIRED,\n multi: true\n };\n\n @Component({\n providers: [REQUIRED_VALIDATOR]\n })\n export class SomeComponent {}\n ", | ||
@@ -638,0 +661,0 @@ 'private-enum.ts': "\n export enum PublicEnum { a, b, c }\n enum PrivateEnum { e, f, g }\n ", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 3 instances in 1 package
476959
0
100
3788