@angular/tsc-wrapped
Advanced tools
Comparing version 0.2.1 to 0.2.2
{ | ||
"name": "@angular/tsc-wrapped", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Wraps the tsc CLI, allowing extensions.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/angular/angular/tree/master/tools/tsc-wrapped", |
@@ -20,2 +20,3 @@ "use strict"; | ||
var metadata; | ||
var exports; | ||
function objFromDecorator(decoratorNode) { | ||
@@ -27,2 +28,27 @@ return evaluator.evaluateNode(decoratorNode.expression); | ||
} | ||
function maybeGetSimpleFunction(functionDeclaration) { | ||
if (functionDeclaration.name.kind == ts.SyntaxKind.Identifier) { | ||
var nameNode = functionDeclaration.name; | ||
var functionName = nameNode.text; | ||
var functionBody = functionDeclaration.body; | ||
if (functionBody && functionBody.statements.length == 1) { | ||
var statement = functionBody.statements[0]; | ||
if (statement.kind === ts.SyntaxKind.ReturnStatement) { | ||
var returnStatement = statement; | ||
if (returnStatement.expression) { | ||
var func = { | ||
__symbolic: 'function', | ||
parameters: namesOf(functionDeclaration.parameters), | ||
value: evaluator.evaluateNode(returnStatement.expression) | ||
}; | ||
if (functionDeclaration.parameters.some(function (p) { return p.initializer != null; })) { | ||
var defaults = []; | ||
func.defaults = functionDeclaration.parameters.map(function (p) { return p.initializer && evaluator.evaluateNode(p.initializer); }); | ||
} | ||
return { func: func, name: functionName }; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
function classMetadataOf(classDeclaration) { | ||
@@ -37,3 +63,4 @@ var result = { __symbolic: 'class' }; | ||
var result = evaluator.evaluateNode(node); | ||
if (schema_1.isMetadataError(result) || schema_1.isMetadataSymbolicReferenceExpression(result)) { | ||
if (schema_1.isMetadataError(result) || schema_1.isMetadataSymbolicReferenceExpression(result) || | ||
schema_1.isMetadataSymbolicSelectExpression(result)) { | ||
return result; | ||
@@ -58,2 +85,9 @@ } | ||
} | ||
// static member | ||
var statics = null; | ||
function recordStaticMember(name, value) { | ||
if (!statics) | ||
statics = {}; | ||
statics[name] = value; | ||
} | ||
for (var _i = 0, _a = classDeclaration.members; _i < _a.length; _i++) { | ||
@@ -67,2 +101,9 @@ var member = _a[_i]; | ||
var method = member; | ||
if (method.flags & ts.NodeFlags.Static) { | ||
var maybeFunc = maybeGetSimpleFunction(method); | ||
if (maybeFunc) { | ||
recordStaticMember(maybeFunc.name, maybeFunc.func); | ||
} | ||
continue; | ||
} | ||
var methodDecorators = getDecorators(method.decorators); | ||
@@ -108,9 +149,21 @@ var parameters = method.parameters; | ||
var property = member; | ||
var propertyDecorators = getDecorators(property.decorators); | ||
if (propertyDecorators) { | ||
if (property.flags & ts.NodeFlags.Static) { | ||
var name_2 = evaluator.nameOf(property.name); | ||
if (!schema_1.isMetadataError(name_2)) { | ||
recordMember(name_2, { __symbolic: 'property', decorators: propertyDecorators }); | ||
if (property.initializer) { | ||
var value = evaluator.evaluateNode(property.initializer); | ||
recordStaticMember(name_2, value); | ||
} | ||
else { | ||
recordStaticMember(name_2, errorSym('Variable not initialized', property.name)); | ||
} | ||
} | ||
} | ||
var propertyDecorators = getDecorators(property.decorators); | ||
if (propertyDecorators) { | ||
var name_3 = evaluator.nameOf(property.name); | ||
if (!schema_1.isMetadataError(name_3)) { | ||
recordMember(name_3, { __symbolic: 'property', decorators: propertyDecorators }); | ||
} | ||
} | ||
break; | ||
@@ -122,3 +175,6 @@ } | ||
} | ||
return result.decorators || members ? result : undefined; | ||
if (statics) { | ||
result.statics = statics; | ||
} | ||
return result.decorators || members || statics ? result : undefined; | ||
} | ||
@@ -142,2 +198,21 @@ // Predeclare classes | ||
switch (node.kind) { | ||
case ts.SyntaxKind.ExportDeclaration: | ||
// Record export declarations | ||
var exportDeclaration = node; | ||
var moduleSpecifier = exportDeclaration.moduleSpecifier; | ||
if (moduleSpecifier && moduleSpecifier.kind == ts.SyntaxKind.StringLiteral) { | ||
// Ignore exports that don't have string literals as exports. | ||
// This is allowed by the syntax but will be flagged as an error by the type checker. | ||
var from = moduleSpecifier.text; | ||
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 (!exports) | ||
exports = []; | ||
exports.push(moduleExport); | ||
} | ||
break; | ||
case ts.SyntaxKind.ClassDeclaration: | ||
@@ -160,18 +235,7 @@ var classDeclaration = node; | ||
var functionDeclaration = node; | ||
var functionName = functionDeclaration.name.text; | ||
var functionBody = functionDeclaration.body; | ||
if (functionBody && functionBody.statements.length == 1) { | ||
var statement = functionBody.statements[0]; | ||
if (statement.kind === ts.SyntaxKind.ReturnStatement) { | ||
var returnStatement = statement; | ||
if (returnStatement.expression) { | ||
if (!metadata) | ||
metadata = {}; | ||
metadata[functionName] = { | ||
__symbolic: 'function', | ||
parameters: namesOf(functionDeclaration.parameters), | ||
value: evaluator.evaluateNode(returnStatement.expression) | ||
}; | ||
} | ||
} | ||
var maybeFunc = maybeGetSimpleFunction(functionDeclaration); | ||
if (maybeFunc) { | ||
if (!metadata) | ||
metadata = {}; | ||
metadata[maybeFunc.name] = maybeFunc.func; | ||
} | ||
@@ -181,2 +245,48 @@ } | ||
break; | ||
case ts.SyntaxKind.EnumDeclaration: | ||
var enumDeclaration = node; | ||
var enumValueHolder = {}; | ||
var enumName = enumDeclaration.name.text; | ||
var nextDefaultValue = 0; | ||
var writtenMembers = 0; | ||
for (var _i = 0, _a = enumDeclaration.members; _i < _a.length; _i++) { | ||
var member = _a[_i]; | ||
var enumValue = void 0; | ||
if (!member.initializer) { | ||
enumValue = nextDefaultValue; | ||
} | ||
else { | ||
enumValue = evaluator.evaluateNode(member.initializer); | ||
} | ||
var name_4 = undefined; | ||
if (member.name.kind == ts.SyntaxKind.Identifier) { | ||
var identifier = member.name; | ||
name_4 = identifier.text; | ||
enumValueHolder[name_4] = enumValue; | ||
writtenMembers++; | ||
} | ||
if (typeof enumValue === 'number') { | ||
nextDefaultValue = enumValue + 1; | ||
} | ||
else if (name_4) { | ||
nextDefaultValue = { | ||
__symbolic: 'binary', | ||
operator: '+', | ||
left: { | ||
__symbolic: 'select', | ||
expression: { __symbolic: 'reference', name: enumName }, name: name_4 | ||
} | ||
}; | ||
} | ||
else { | ||
nextDefaultValue = errorSym('Unsuppported enum member name', member.name); | ||
} | ||
; | ||
} | ||
if (writtenMembers) { | ||
if (!metadata) | ||
metadata = {}; | ||
metadata[enumName] = enumValueHolder; | ||
} | ||
break; | ||
case ts.SyntaxKind.VariableStatement: | ||
@@ -194,2 +304,3 @@ var variableStatement = node; | ||
} | ||
var exported = false; | ||
if (variableStatement.flags & ts.NodeFlags.Export || | ||
@@ -200,2 +311,3 @@ variableDeclaration.flags & ts.NodeFlags.Export) { | ||
metadata[nameNode.text] = varValue; | ||
exported = true; | ||
} | ||
@@ -205,2 +317,5 @@ if (evaluator_1.isPrimitive(varValue)) { | ||
} | ||
else if (!exported) { | ||
locals.define(nameNode.text, errorSym('Reference to a local symbol', nameNode, { name: nameNode.text })); | ||
} | ||
} | ||
@@ -216,9 +331,9 @@ else { | ||
case ts.SyntaxKind.Identifier: | ||
var name_3 = nameNode; | ||
var name_5 = nameNode; | ||
var varValue = errorSym('Destructuring not supported', nameNode); | ||
locals.define(name_3.text, varValue); | ||
locals.define(name_5.text, varValue); | ||
if (node.flags & ts.NodeFlags.Export) { | ||
if (!metadata) | ||
metadata = {}; | ||
metadata[name_3.text] = varValue; | ||
metadata[name_5.text] = varValue; | ||
} | ||
@@ -240,4 +355,4 @@ break; | ||
}; | ||
for (var _i = 0, _a = variableStatement.declarationList.declarations; _i < _a.length; _i++) { | ||
var variableDeclaration = _a[_i]; | ||
for (var _b = 0, _c = variableStatement.declarationList.declarations; _b < _c.length; _b++) { | ||
var variableDeclaration = _c[_b]; | ||
_loop_1(variableDeclaration); | ||
@@ -248,3 +363,10 @@ } | ||
}); | ||
return metadata && { __symbolic: 'module', version: schema_1.VERSION, metadata: metadata }; | ||
if (metadata || exports) { | ||
if (!metadata) | ||
metadata = {}; | ||
var result = { __symbolic: 'module', version: schema_1.VERSION, metadata: metadata }; | ||
if (exports) | ||
result.exports = exports; | ||
return result; | ||
} | ||
}; | ||
@@ -251,0 +373,0 @@ return MetadataCollector; |
@@ -345,3 +345,4 @@ "use strict"; | ||
} | ||
return errorSymbol('Qualified type names not supported', node); | ||
// Record a type reference to a declared type as a select. | ||
return { __symbolic: 'select', expression: left_1, member: qualifiedName.right.text }; | ||
} | ||
@@ -493,2 +494,11 @@ else { | ||
break; | ||
case ts.SyntaxKind.ConditionalExpression: | ||
var conditionalExpression = node; | ||
var condition = this.evaluateNode(conditionalExpression.condition); | ||
var thenExpression = this.evaluateNode(conditionalExpression.whenTrue); | ||
var elseExpression = this.evaluateNode(conditionalExpression.whenFalse); | ||
if (isPrimitive(condition)) { | ||
return condition ? thenExpression : elseExpression; | ||
} | ||
return { __symbolic: 'if', condition: condition, thenExpression: thenExpression, elseExpression: elseExpression }; | ||
case ts.SyntaxKind.FunctionExpression: | ||
@@ -495,0 +505,0 @@ case ts.SyntaxKind.ArrowFunction: |
@@ -5,7 +5,15 @@ export declare const VERSION: number; | ||
version: number; | ||
exports?: ModuleExportMetadata[]; | ||
metadata: { | ||
[name: string]: (ClassMetadata | MetadataValue); | ||
[name: string]: (ClassMetadata | FunctionMetadata | MetadataValue); | ||
}; | ||
} | ||
export declare function isModuleMetadata(value: any): value is ModuleMetadata; | ||
export interface ModuleExportMetadata { | ||
export?: (string | { | ||
name: string; | ||
as: string; | ||
})[]; | ||
from: string; | ||
} | ||
export interface ClassMetadata { | ||
@@ -15,2 +23,5 @@ __symbolic: 'class'; | ||
members?: MetadataMap; | ||
statics?: { | ||
[name: string]: MetadataValue | FunctionMetadata; | ||
}; | ||
} | ||
@@ -39,3 +50,4 @@ export declare function isClassMetadata(value: any): value is ClassMetadata; | ||
parameters: string[]; | ||
result: MetadataValue; | ||
defaults?: MetadataValue[]; | ||
value: MetadataValue; | ||
} | ||
@@ -51,3 +63,3 @@ export declare function isFunctionMetadata(value: any): value is FunctionMetadata; | ||
export interface MetadataSymbolicExpression { | ||
__symbolic: 'binary' | 'call' | 'index' | 'new' | 'pre' | 'reference' | 'select' | 'spread'; | ||
__symbolic: 'binary' | 'call' | 'index' | 'new' | 'pre' | 'reference' | 'select' | 'spread' | 'if'; | ||
} | ||
@@ -80,2 +92,9 @@ export declare function isMetadataSymbolicExpression(value: any): value is MetadataSymbolicExpression; | ||
export declare function isMetadataSymbolicPrefixExpression(value: any): value is MetadataSymbolicPrefixExpression; | ||
export interface MetadataSymbolicIfExpression extends MetadataSymbolicExpression { | ||
__symbolic: 'if'; | ||
condition: MetadataValue; | ||
thenExpression: MetadataValue; | ||
elseExpression: MetadataValue; | ||
} | ||
export declare function isMetadataSymbolicIfExpression(value: any): value is MetadataSymbolicIfExpression; | ||
export interface MetadataGlobalReferenceExpression extends MetadataSymbolicExpression { | ||
@@ -82,0 +101,0 @@ __symbolic: 'reference'; |
@@ -52,2 +52,3 @@ // Metadata Schema | ||
case 'spread': | ||
case 'if': | ||
return true; | ||
@@ -75,2 +76,6 @@ } | ||
exports.isMetadataSymbolicPrefixExpression = isMetadataSymbolicPrefixExpression; | ||
function isMetadataSymbolicIfExpression(value) { | ||
return value && value.__symbolic === 'if'; | ||
} | ||
exports.isMetadataSymbolicIfExpression = isMetadataSymbolicIfExpression; | ||
function isMetadataGlobalReferenceExpression(value) { | ||
@@ -77,0 +82,0 @@ return isMetadataSymbolicReferenceExpression(value) && value.name && !value.module; |
@@ -13,4 +13,19 @@ "use strict"; | ||
host = new typescript_mocks_1.Host(FILES, [ | ||
'/app/app.component.ts', '/app/cases-data.ts', '/app/error-cases.ts', '/promise.ts', | ||
'/unsupported-1.ts', '/unsupported-2.ts', 'import-star.ts', 'exported-functions.ts' | ||
'/app/app.component.ts', | ||
'/app/cases-data.ts', | ||
'/app/error-cases.ts', | ||
'/promise.ts', | ||
'/unsupported-1.ts', | ||
'/unsupported-2.ts', | ||
'import-star.ts', | ||
'exported-functions.ts', | ||
'exported-enum.ts', | ||
'exported-consts.ts', | ||
'local-symbol-ref.ts', | ||
're-exports.ts', | ||
'static-field-reference.ts', | ||
'static-method.ts', | ||
'static-method-call.ts', | ||
'static-method-with-if.ts', | ||
'static-method-with-default.ts', | ||
]); | ||
@@ -279,2 +294,170 @@ service = ts.createLanguageService(host, documentRegistry); | ||
}); | ||
it('should be able to collect the value of an enum', function () { | ||
var enumSource = program.getSourceFile('/exported-enum.ts'); | ||
var metadata = collector.getMetadata(enumSource); | ||
var someEnum = metadata.metadata['SomeEnum']; | ||
expect(someEnum).toEqual({ A: 0, B: 1, C: 100, D: 101 }); | ||
}); | ||
it('should be able to collect enums initialized from consts', function () { | ||
var enumSource = program.getSourceFile('/exported-enum.ts'); | ||
var metadata = collector.getMetadata(enumSource); | ||
var complexEnum = metadata.metadata['ComplexEnum']; | ||
expect(complexEnum).toEqual({ | ||
A: 0, | ||
B: 1, | ||
C: 30, | ||
D: 40, | ||
E: { __symbolic: 'reference', module: './exported-consts', name: 'constValue' } | ||
}); | ||
}); | ||
it('should be able to collect a simple static method', function () { | ||
var staticSource = program.getSourceFile('/static-method.ts'); | ||
var metadata = collector.getMetadata(staticSource); | ||
expect(metadata).toBeDefined(); | ||
var classData = metadata.metadata['MyModule']; | ||
expect(classData).toBeDefined(); | ||
expect(classData.statics).toEqual({ | ||
with: { | ||
__symbolic: 'function', | ||
parameters: ['comp'], | ||
value: [ | ||
{ __symbolic: 'reference', name: 'MyModule' }, | ||
{ provider: 'a', useValue: { __symbolic: 'reference', name: 'comp' } } | ||
] | ||
} | ||
}); | ||
}); | ||
it('should be able to collect a call to a static method', function () { | ||
var staticSource = program.getSourceFile('/static-method-call.ts'); | ||
var metadata = collector.getMetadata(staticSource); | ||
expect(metadata).toBeDefined(); | ||
var classData = metadata.metadata['Foo']; | ||
expect(classData).toBeDefined(); | ||
expect(classData.decorators).toEqual([{ | ||
__symbolic: 'call', | ||
expression: { __symbolic: 'reference', module: 'angular2/core', name: 'Component' }, | ||
arguments: [{ | ||
providers: { | ||
__symbolic: 'call', | ||
expression: { | ||
__symbolic: 'select', | ||
expression: { __symbolic: 'reference', module: './static-method.ts', name: 'MyModule' }, | ||
member: 'with' | ||
}, | ||
arguments: ['a'] | ||
} | ||
}] | ||
}]); | ||
}); | ||
it('should be able to collect a static field', function () { | ||
var staticSource = program.getSourceFile('/static-field.ts'); | ||
var metadata = collector.getMetadata(staticSource); | ||
expect(metadata).toBeDefined(); | ||
var classData = metadata.metadata['MyModule']; | ||
expect(classData).toBeDefined(); | ||
expect(classData.statics).toEqual({ VALUE: 'Some string' }); | ||
}); | ||
it('should be able to collect a reference to a static field', function () { | ||
var staticSource = program.getSourceFile('/static-field-reference.ts'); | ||
var metadata = collector.getMetadata(staticSource); | ||
expect(metadata).toBeDefined(); | ||
var classData = metadata.metadata['Foo']; | ||
expect(classData).toBeDefined(); | ||
expect(classData.decorators).toEqual([{ | ||
__symbolic: 'call', | ||
expression: { __symbolic: 'reference', module: 'angular2/core', name: 'Component' }, | ||
arguments: [{ | ||
providers: [{ | ||
provide: 'a', | ||
useValue: { | ||
__symbolic: 'select', | ||
expression: { __symbolic: 'reference', module: './static-field.ts', name: 'MyModule' }, | ||
member: 'VALUE' | ||
} | ||
}] | ||
}] | ||
}]); | ||
}); | ||
it('should be able to collect a method with a conditional expression', function () { | ||
var source = program.getSourceFile('/static-method-with-if.ts'); | ||
var metadata = collector.getMetadata(source); | ||
expect(metadata).toBeDefined(); | ||
var classData = metadata.metadata['MyModule']; | ||
expect(classData).toBeDefined(); | ||
expect(classData.statics).toEqual({ | ||
with: { | ||
__symbolic: 'function', | ||
parameters: ['cond'], | ||
value: [ | ||
{ __symbolic: 'reference', name: 'MyModule' }, { | ||
provider: 'a', | ||
useValue: { | ||
__symbolic: 'if', | ||
condition: { __symbolic: 'reference', name: 'cond' }, | ||
thenExpression: '1', | ||
elseExpression: '2' | ||
} | ||
} | ||
] | ||
} | ||
}); | ||
}); | ||
it('should be able to collect a method with a default parameter', function () { | ||
var source = program.getSourceFile('/static-method-with-default.ts'); | ||
var metadata = collector.getMetadata(source); | ||
expect(metadata).toBeDefined(); | ||
var classData = metadata.metadata['MyModule']; | ||
expect(classData).toBeDefined(); | ||
expect(classData.statics).toEqual({ | ||
with: { | ||
__symbolic: 'function', | ||
parameters: ['comp', 'foo', 'bar'], | ||
defaults: [undefined, true, false], | ||
value: [ | ||
{ __symbolic: 'reference', name: 'MyModule' }, { | ||
__symbolic: 'if', | ||
condition: { __symbolic: 'reference', name: 'foo' }, | ||
thenExpression: { provider: 'a', useValue: { __symbolic: 'reference', name: 'comp' } }, | ||
elseExpression: { provider: 'b', useValue: { __symbolic: 'reference', name: 'comp' } } | ||
}, | ||
{ | ||
__symbolic: 'if', | ||
condition: { __symbolic: 'reference', name: 'bar' }, | ||
thenExpression: { provider: 'c', useValue: { __symbolic: 'reference', name: 'comp' } }, | ||
elseExpression: { provider: 'd', useValue: { __symbolic: 'reference', name: 'comp' } } | ||
} | ||
] | ||
} | ||
}); | ||
}); | ||
it('should be able to collect re-exported symbols', function () { | ||
var source = program.getSourceFile('/re-exports.ts'); | ||
var metadata = collector.getMetadata(source); | ||
expect(metadata.exports).toEqual([ | ||
{ from: './static-field', export: ['MyModule'] }, | ||
{ from: './static-field-reference.ts', export: [{ name: 'Foo', as: 'OtherModule' }] }, | ||
{ from: 'angular2/core' } | ||
]); | ||
}); | ||
it('should collect an error symbol if collecting a reference to a non-exported symbol', function () { | ||
var source = program.getSourceFile('/local-symbol-ref.ts'); | ||
var metadata = collector.getMetadata(source); | ||
expect(metadata.metadata).toEqual({ | ||
REQUIRED_VALIDATOR: { | ||
__symbolic: 'error', | ||
message: 'Reference to a local symbol', | ||
line: 3, | ||
character: 9, | ||
context: { name: 'REQUIRED' } | ||
}, | ||
SomeComponent: { | ||
__symbolic: 'class', | ||
decorators: [{ | ||
__symbolic: 'call', | ||
expression: { __symbolic: 'reference', module: 'angular2/core', name: 'Component' }, | ||
arguments: [{ providers: [{ __symbolic: 'reference', name: 'REQUIRED_VALIDATOR' }] }] | ||
}] | ||
} | ||
}); | ||
}); | ||
}); | ||
@@ -306,5 +489,15 @@ // TODO: Do not use \` in a template literal as it confuses clang-format | ||
'exported-functions.ts': "\n export function one(a: string, b: string, c: string) {\n return {a: a, b: b, c: c};\n }\n export function two(a: string, b: string, c: string) {\n return {a, b, c};\n }\n export function three({a, b, c}: {a: string, b: string, c: string}) {\n return [a, b, c];\n }\n export function supportsState(): boolean {\n return !!window.history.pushState;\n }\n ", | ||
'exported-enum.ts': "\n import {constValue} from './exported-consts';\n\n export const someValue = 30;\n export enum SomeEnum { A, B, C = 100, D };\n export enum ComplexEnum { A, B, C = someValue, D = someValue + 10, E = constValue };\n ", | ||
'exported-consts.ts': "\n export const constValue = 100;\n ", | ||
'static-method.ts': "\n import {Injectable} from 'angular2/core';\n\n @Injectable()\n export class MyModule {\n static with(comp: any): any[] {\n return [\n MyModule,\n { provider: 'a', useValue: comp }\n ];\n }\n }\n ", | ||
'static-method-with-default.ts': "\n import {Injectable} from 'angular2/core';\n\n @Injectable()\n export class MyModule {\n static with(comp: any, foo: boolean = true, bar: boolean = false): any[] {\n return [\n MyModule,\n foo ? { provider: 'a', useValue: comp } : {provider: 'b', useValue: comp},\n bar ? { provider: 'c', useValue: comp } : {provider: 'd', useValue: comp}\n ];\n }\n }\n ", | ||
'static-method-call.ts': "\n import {Component} from 'angular2/core';\n import {MyModule} from './static-method.ts';\n\n @Component({\n providers: MyModule.with('a')\n })\n export class Foo { }\n ", | ||
'static-field.ts': "\n import {Injectable} from 'angular2/core';\n\n @Injectable()\n export class MyModule {\n static VALUE = 'Some string';\n }\n ", | ||
'static-field-reference.ts': "\n import {Component} from 'angular2/core';\n import {MyModule} from './static-field.ts';\n\n @Component({\n providers: [ { provide: 'a', useValue: MyModule.VALUE } ]\n })\n export class Foo { }\n ", | ||
'static-method-with-if.ts': "\n import {Injectable} from 'angular2/core';\n\n @Injectable()\n export class MyModule {\n static with(cond: boolean): any[] {\n return [\n MyModule,\n { provider: 'a', useValue: cond ? '1' : '2' }\n ];\n }\n }\n ", | ||
're-exports.ts': "\n export {MyModule} from './static-field';\n export {Foo as OtherModule} from './static-field-reference.ts';\n export * from 'angular2/core';\n ", | ||
'local-symbol-ref.ts': "\n import {Component, Validators} from 'angular2/core';\n\n const REQUIRED = Validators.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 ", | ||
'node_modules': { | ||
'angular2': { | ||
'core.d.ts': "\n export interface Type extends Function { }\n export interface TypeDecorator {\n <T extends Type>(type: T): T;\n (target: Object, propertyKey?: string | symbol, parameterIndex?: number): void;\n annotations: any[];\n }\n export interface ComponentDecorator extends TypeDecorator { }\n export interface ComponentFactory {\n (obj: {\n selector?: string;\n inputs?: string[];\n outputs?: string[];\n properties?: string[];\n events?: string[];\n host?: {\n [key: string]: string;\n };\n bindings?: any[];\n providers?: any[];\n exportAs?: string;\n moduleId?: string;\n queries?: {\n [key: string]: any;\n };\n viewBindings?: any[];\n viewProviders?: any[];\n templateUrl?: string;\n template?: string;\n styleUrls?: string[];\n styles?: string[];\n directives?: Array<Type | any[]>;\n pipes?: Array<Type | any[]>;\n }): ComponentDecorator;\n }\n export declare var Component: ComponentFactory;\n export interface InputFactory {\n (bindingPropertyName?: string): any;\n new (bindingPropertyName?: string): any;\n }\n export declare var Input: InputFactory;\n export interface InjectableFactory {\n (): any;\n }\n export declare var Injectable: InjectableFactory;\n export interface OnInit {\n ngOnInit(): any;\n }\n ", | ||
'core.d.ts': "\n export interface Type extends Function { }\n export interface TypeDecorator {\n <T extends Type>(type: T): T;\n (target: Object, propertyKey?: string | symbol, parameterIndex?: number): void;\n annotations: any[];\n }\n export interface ComponentDecorator extends TypeDecorator { }\n export interface ComponentFactory {\n (obj: {\n selector?: string;\n inputs?: string[];\n outputs?: string[];\n properties?: string[];\n events?: string[];\n host?: {\n [key: string]: string;\n };\n bindings?: any[];\n providers?: any[];\n exportAs?: string;\n moduleId?: string;\n queries?: {\n [key: string]: any;\n };\n viewBindings?: any[];\n viewProviders?: any[];\n templateUrl?: string;\n template?: string;\n styleUrls?: string[];\n styles?: string[];\n directives?: Array<Type | any[]>;\n pipes?: Array<Type | any[]>;\n }): ComponentDecorator;\n }\n export declare var Component: ComponentFactory;\n export interface InputFactory {\n (bindingPropertyName?: string): any;\n new (bindingPropertyName?: string): any;\n }\n export declare var Input: InputFactory;\n export interface InjectableFactory {\n (): any;\n }\n export declare var Injectable: InjectableFactory;\n export interface OnInit {\n ngOnInit(): any;\n }\n export class Validators {\n static required(): void;\n }\n ", | ||
'common.d.ts': "\n export declare class NgFor {\n ngForOf: any;\n ngForTemplate: any;\n ngDoCheck(): void;\n }\n export declare class LowerCasePipe {\n transform(value: string, args?: any[]): string;\n }\n export declare class UpperCasePipe {\n transform(value: string, args?: any[]): string;\n }\n " | ||
@@ -311,0 +504,0 @@ } |
@@ -17,3 +17,3 @@ "use strict"; | ||
'expressions.ts', 'consts.ts', 'const_expr.ts', 'forwardRef.ts', 'classes.ts', | ||
'newExpression.ts', 'errors.ts' | ||
'newExpression.ts', 'errors.ts', 'declared.ts' | ||
]); | ||
@@ -140,14 +140,16 @@ service = ts.createLanguageService(host, documentRegistry); | ||
}); | ||
it('should support referene to a declared module type', function () { | ||
var declared = program.getSourceFile('declared.ts'); | ||
var aDecl = typescript_mocks_1.findVar(declared, 'a'); | ||
expect(evaluator.evaluateNode(aDecl.type)).toEqual({ | ||
__symbolic: 'select', | ||
expression: { __symbolic: 'reference', name: 'Foo' }, | ||
member: 'A' | ||
}); | ||
}); | ||
it('should return errors for unsupported expressions', function () { | ||
var errors = program.getSourceFile('errors.ts'); | ||
var aDecl = typescript_mocks_1.findVar(errors, 'a'); | ||
expect(evaluator.evaluateNode(aDecl.type)).toEqual({ | ||
__symbolic: 'error', | ||
message: 'Qualified type names not supported', | ||
line: 5, | ||
character: 10 | ||
}); | ||
var fDecl = typescript_mocks_1.findVar(errors, 'f'); | ||
expect(evaluator.evaluateNode(fDecl.initializer)) | ||
.toEqual({ __symbolic: 'error', message: 'Function call not supported', line: 6, character: 11 }); | ||
.toEqual({ __symbolic: 'error', message: 'Function call not supported', line: 1, character: 11 }); | ||
var eDecl = typescript_mocks_1.findVar(errors, 'e'); | ||
@@ -157,3 +159,3 @@ expect(evaluator.evaluateNode(eDecl.type)).toEqual({ | ||
message: 'Could not resolve type', | ||
line: 7, | ||
line: 2, | ||
character: 10, | ||
@@ -166,3 +168,3 @@ context: { typeName: 'NotFound' } | ||
message: 'Name expected', | ||
line: 8, | ||
line: 3, | ||
character: 13, | ||
@@ -175,3 +177,3 @@ context: { received: '1' } | ||
message: 'Expression form not supported', | ||
line: 9, | ||
line: 4, | ||
character: 11 | ||
@@ -204,4 +206,5 @@ }); | ||
'newExpression.ts': "\n import {Value} from './classes';\n function CONST_EXPR(value: any) { return value; }\n function forwardRef(value: any) { return value; }\n export const someValue = new Value(\"name\", 12);\n export const complex = CONST_EXPR(new Value(\"name\", forwardRef(() => 12)));\n ", | ||
'errors.ts': "\n declare namespace Foo {\n type A = string;\n }\n\n let a: Foo.A = 'some value';\n let f = () => 1;\n let e: NotFound;\n let s = { 1: 1, 2: 2 };\n let t = typeof 12;\n ", | ||
'errors.ts': "\n let f = () => 1;\n let e: NotFound;\n let s = { 1: 1, 2: 2 };\n let t = typeof 12;\n ", | ||
'declared.ts': "\n declare namespace Foo {\n type A = string;\n }\n\n let a: Foo.A = 'some value';\n " | ||
}; | ||
//# sourceMappingURL=evaluator.spec.js.map |
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
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
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
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
361614
2793