@angular/tsc-wrapped
Advanced tools
Comparing version 4.3.0-rc.0 to 4.3.0
{ | ||
"name": "@angular/tsc-wrapped", | ||
"version": "4.3.0-rc.0", | ||
"version": "4.3.0", | ||
"description": "Wraps the tsc CLI, allowing extensions.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/angular/angular/blob/master/tools/@angular/tsc-wrapped", |
@@ -420,2 +420,5 @@ "use strict"; | ||
locals.define(nameNode.text, varValue); | ||
if (exported) { | ||
locals.defineReference(nameNode.text, { __symbolic: 'reference', name: nameNode.text }); | ||
} | ||
} | ||
@@ -422,0 +425,0 @@ else if (!exported) { |
@@ -58,3 +58,3 @@ /** | ||
*/ | ||
evaluateNode(node: ts.Node): MetadataValue; | ||
evaluateNode(node: ts.Node, preferReference?: boolean): MetadataValue; | ||
} |
@@ -202,3 +202,3 @@ "use strict"; | ||
*/ | ||
Evaluator.prototype.evaluateNode = function (node) { | ||
Evaluator.prototype.evaluateNode = function (node, preferReference) { | ||
var _this = this; | ||
@@ -214,4 +214,4 @@ var t = this; | ||
} | ||
var resolveName = function (name) { | ||
var reference = _this.symbols.resolve(name); | ||
var resolveName = function (name, preferReference) { | ||
var reference = _this.symbols.resolve(name, preferReference); | ||
if (reference === undefined) { | ||
@@ -242,4 +242,4 @@ // Encode as a global reference. StaticReflector will check the reference. | ||
var propertyValue = isPropertyAssignment(assignment) ? | ||
_this.evaluateNode(assignment.initializer) : | ||
resolveName(propertyName); | ||
_this.evaluateNode(assignment.initializer, /* preferReference */ true) : | ||
resolveName(propertyName, /* preferReference */ true); | ||
if (isFoldableError(propertyValue)) { | ||
@@ -263,3 +263,3 @@ error = propertyValue; | ||
ts.forEachChild(node, function (child) { | ||
var value = _this.evaluateNode(child); | ||
var value = _this.evaluateNode(child, /* preferReference */ true); | ||
// Check for error | ||
@@ -364,2 +364,5 @@ if (isFoldableError(value)) { | ||
} | ||
if (!elementAccessExpression.argumentExpression) { | ||
return recordEntry(errorSymbol('Expression form not supported', node), node); | ||
} | ||
var index = this.evaluateNode(elementAccessExpression.argumentExpression); | ||
@@ -377,3 +380,3 @@ if (isFoldableError(expression_2)) { | ||
var name_3 = identifier.text; | ||
return resolveName(name_3); | ||
return resolveName(name_3, preferReference); | ||
case ts.SyntaxKind.TypeReference: | ||
@@ -615,2 +618,7 @@ var typeReferenceNode = node; | ||
} | ||
case ts.SyntaxKind.AsExpression: | ||
var asExpression = node; | ||
return this.evaluateNode(asExpression.expression); | ||
case ts.SyntaxKind.ClassExpression: | ||
return { __symbolic: 'class' }; | ||
} | ||
@@ -617,0 +625,0 @@ return recordEntry(errorSymbol('Expression form not supported', node), node); |
@@ -9,9 +9,11 @@ /** | ||
import * as ts from 'typescript'; | ||
import { MetadataValue } from './schema'; | ||
import { MetadataSymbolicReferenceExpression, MetadataValue } from './schema'; | ||
export declare class Symbols { | ||
private sourceFile; | ||
private _symbols; | ||
private references; | ||
constructor(sourceFile: ts.SourceFile); | ||
resolve(name: string): MetadataValue | undefined; | ||
resolve(name: string, preferReference?: boolean): MetadataValue | undefined; | ||
define(name: string, value: MetadataValue): void; | ||
defineReference(name: string, value: MetadataSymbolicReferenceExpression): void; | ||
has(name: string): boolean; | ||
@@ -18,0 +20,0 @@ private readonly symbols; |
@@ -14,5 +14,11 @@ "use strict"; | ||
this.sourceFile = sourceFile; | ||
this.references = new Map(); | ||
} | ||
Symbols.prototype.resolve = function (name) { return this.symbols.get(name); }; | ||
Symbols.prototype.resolve = function (name, preferReference) { | ||
return (preferReference && this.references.get(name)) || this.symbols.get(name); | ||
}; | ||
Symbols.prototype.define = function (name, value) { this.symbols.set(name, value); }; | ||
Symbols.prototype.defineReference = function (name, value) { | ||
this.references.set(name, value); | ||
}; | ||
Symbols.prototype.has = function (name) { return this.symbols.has(name); }; | ||
@@ -19,0 +25,0 @@ Object.defineProperty(Symbols.prototype, "symbols", { |
@@ -9,2 +9,3 @@ "use strict"; | ||
*/ | ||
var _this = this; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -580,4 +581,3 @@ var ts = require("typescript"); | ||
function e(expr, prefix) { | ||
var source = createSource((prefix || '') + " export let value = " + expr + ";"); | ||
var metadata = collector.getMetadata(source); | ||
var metadata = collectSource((prefix || '') + " export let value = " + expr + ";"); | ||
return expect(metadata.metadata['value']); | ||
@@ -640,4 +640,3 @@ } | ||
it('should ignore |null or |undefined in type expressions', function () { | ||
var source = ts.createSourceFile('somefile.ts', "\n import {Foo} from './foo';\n export class SomeClass {\n constructor (a: Foo, b: Foo | null, c: Foo | undefined, d: Foo | undefined | null, e: Foo | undefined | null | Foo) {}\n }\n ", ts.ScriptTarget.Latest, true); | ||
var metadata = collector.getMetadata(source); | ||
var metadata = collectSource("\n import {Foo} from './foo';\n export class SomeClass {\n constructor (a: Foo, b: Foo | null, c: Foo | undefined, d: Foo | undefined | null, e: Foo | undefined | null | Foo) {}\n }\n "); | ||
expect(metadata.metadata['SomeClass'].members).toEqual({ | ||
@@ -656,2 +655,7 @@ __ctor__: [{ | ||
}); | ||
it('should treat exported class expressions as a class', function () { | ||
var source = ts.createSourceFile('', "\n export const InjectionToken: {new<T>(desc: string): InjectionToken<T>;} = class extends OpaqueToken {\n constructor(desc: string) {\n super(desc);\n }\n\n toString(): string { return `InjectionToken " + _this._desc + "`; }\n } as any;", ts.ScriptTarget.Latest, true); | ||
var metadata = collector.getMetadata(source); | ||
expect(metadata.metadata).toEqual({ InjectionToken: { __symbolic: 'class' } }); | ||
}); | ||
describe('in strict mode', function () { | ||
@@ -740,4 +744,3 @@ it('should throw if an error symbol is collecting a reference to a non-exported symbol', function () { | ||
it('should be able to collect a short-hand property value', function () { | ||
var source = createSource("\n const children = { f1: 1 };\n export const r = [\n {path: ':locale', children}\n ];\n "); | ||
var metadata = collector.getMetadata(source); | ||
var metadata = collectSource("\n const children = { f1: 1 };\n export const r = [\n {path: ':locale', children}\n ];\n "); | ||
expect(metadata.metadata).toEqual({ r: [{ path: ':locale', children: { f1: 1 } }] }); | ||
@@ -747,12 +750,45 @@ }); | ||
it('should skip a default function', function () { | ||
var source = createSource("\n export default function () {\n\n const mainRoutes = [\n {name: 'a', abstract: true, component: 'main'},\n\n {name: 'a.welcome', url: '/welcome', component: 'welcome'}\n ];\n\n return mainRoutes;\n\n }"); | ||
var metadata = collector.getMetadata(source); | ||
var metadata = collectSource("\n export default function () {\n\n const mainRoutes = [\n {name: 'a', abstract: true, component: 'main'},\n\n {name: 'a.welcome', url: '/welcome', component: 'welcome'}\n ];\n\n return mainRoutes;\n\n }"); | ||
expect(metadata).toBeUndefined(); | ||
}); | ||
it('should skip a named default export', function () { | ||
var source = createSource("\n function mainRoutes() {\n\n const mainRoutes = [\n {name: 'a', abstract: true, component: 'main'},\n\n {name: 'a.welcome', url: '/welcome', component: 'welcome'}\n ];\n\n return mainRoutes;\n\n }\n\n exports = foo;\n "); | ||
var metadata = collector.getMetadata(source); | ||
var metadata = collectSource("\n function mainRoutes() {\n\n const mainRoutes = [\n {name: 'a', abstract: true, component: 'main'},\n\n {name: 'a.welcome', url: '/welcome', component: 'welcome'}\n ];\n\n return mainRoutes;\n\n }\n\n exports = foo;\n "); | ||
expect(metadata).toBeUndefined(); | ||
}); | ||
it('should be able to collect an invalid access expression', function () { | ||
var source = createSource("\n import {Component} from '@angular/core';\n\n const value = [];\n @Component({\n provider: [{provide: 'some token', useValue: value[]}]\n })\n export class MyComponent {}\n "); | ||
var metadata = collector.getMetadata(source); | ||
expect(metadata.metadata.MyComponent).toEqual({ | ||
__symbolic: 'class', | ||
decorators: [{ | ||
__symbolic: 'error', | ||
message: 'Expression form not supported', | ||
line: 5, | ||
character: 55 | ||
}] | ||
}); | ||
}); | ||
}); | ||
describe('references', function () { | ||
beforeEach(function () { collector = new collector_1.MetadataCollector({ quotedNames: true }); }); | ||
it('should record a reference to an exported field of a useValue', function () { | ||
var metadata = collectSource("\n export var someValue = 1;\n export const v = {\n useValue: someValue\n };\n "); | ||
expect(metadata.metadata['someValue']).toEqual(1); | ||
expect(metadata.metadata['v']).toEqual({ | ||
useValue: { __symbolic: 'reference', name: 'someValue' } | ||
}); | ||
}); | ||
it('should leave external references in place in an object literal', function () { | ||
var metadata = collectSource("\n export const myLambda = () => [1, 2, 3];\n const indirect = [{a: 1, b: 3: c: myLambda}];\n export const v = {\n v: {i: indirect}\n }\n "); | ||
expect(metadata.metadata['v']).toEqual({ | ||
v: { i: [{ a: 1, b: 3, c: { __symbolic: 'reference', name: 'myLambda' } }] } | ||
}); | ||
}); | ||
it('should leave an external reference in place in an array literal', function () { | ||
var metadata = collectSource("\n export const myLambda = () => [1, 2, 3];\n const indirect = [1, 3, myLambda}];\n export const v = {\n v: {i: indirect}\n }\n "); | ||
expect(metadata.metadata['v']).toEqual({ | ||
v: { i: [1, 3, { __symbolic: 'reference', name: 'myLambda' }] } | ||
}); | ||
}); | ||
}); | ||
function override(fileName, content) { | ||
@@ -763,2 +799,6 @@ host.overrideFile(fileName, content); | ||
} | ||
function collectSource(content) { | ||
var sourceFile = createSource(content); | ||
return collector.getMetadata(sourceFile); | ||
} | ||
}); | ||
@@ -765,0 +805,0 @@ // TODO: Do not use \` in a template literal as it confuses clang-format |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
667548
5270
1