@angular/tsc-wrapped
Advanced tools
Comparing version 0.5.0 to 0.5.1
{ | ||
"name": "@angular/tsc-wrapped", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "Wraps the tsc CLI, allowing extensions.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/angular/angular/tree/master/tools/tsc-wrapped", |
@@ -13,2 +13,14 @@ /** | ||
var symbols_1 = require('./symbols'); | ||
// In TypeScript 2.1 these flags moved | ||
// These helpers work for both 2.0 and 2.1. | ||
var isExport = ts.ModifierFlags ? | ||
(function (node) { | ||
return !!(ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Export); | ||
}) : | ||
(function (node) { return !!((node.flags & ts.NodeFlags.Export)); }); | ||
var isStatic = ts.ModifierFlags ? | ||
(function (node) { | ||
return !!(ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Static); | ||
}) : | ||
(function (node) { return !!((node.flags & ts.NodeFlags.Static)); }); | ||
/** | ||
@@ -130,3 +142,3 @@ * A set of collector options to use when collecting metadata. | ||
var method = member; | ||
if (method.flags & ts.NodeFlags.Static) { | ||
if (isStatic(method)) { | ||
var maybeFunc = maybeGetSimpleFunction(method); | ||
@@ -178,3 +190,3 @@ if (maybeFunc) { | ||
var property = member; | ||
if (property.flags & ts.NodeFlags.Static) { | ||
if (isStatic(property)) { | ||
var name_2 = evaluator.nameOf(property.name); | ||
@@ -209,2 +221,28 @@ if (!schema_1.isMetadataError(name_2)) { | ||
} | ||
// Collect all exported symbols from an exports clause. | ||
var exportMap = new Map(); | ||
ts.forEachChild(sourceFile, function (node) { | ||
switch (node.kind) { | ||
case ts.SyntaxKind.ExportDeclaration: | ||
var exportDeclaration = node; | ||
var moduleSpecifier = exportDeclaration.moduleSpecifier, exportClause = exportDeclaration.exportClause; | ||
if (!moduleSpecifier) { | ||
exportClause.elements.forEach(function (spec) { | ||
var exportedAs = spec.name.text; | ||
var name = (spec.propertyName || spec.name).text; | ||
exportMap.set(name, exportedAs); | ||
}); | ||
} | ||
} | ||
}); | ||
var isExportedIdentifier = function (identifier) { return exportMap.has(identifier.text); }; | ||
var isExported = function (node) { | ||
return isExport(node) || isExportedIdentifier(node.name); | ||
}; | ||
var exportedIdentifierName = function (identifier) { | ||
return exportMap.get(identifier.text) || identifier.text; | ||
}; | ||
var exportedName = function (node) { | ||
return exportedIdentifierName(node.name); | ||
}; | ||
// Predeclare classes and functions | ||
@@ -217,4 +255,4 @@ ts.forEachChild(sourceFile, function (node) { | ||
var className = classDeclaration.name.text; | ||
if (node.flags & ts.NodeFlags.Export) { | ||
locals.define(className, { __symbolic: 'reference', name: className }); | ||
if (isExported(classDeclaration)) { | ||
locals.define(className, { __symbolic: 'reference', name: exportedName(classDeclaration) }); | ||
} | ||
@@ -227,5 +265,5 @@ else { | ||
case ts.SyntaxKind.FunctionDeclaration: | ||
if (!(node.flags & ts.NodeFlags.Export)) { | ||
var functionDeclaration = node; | ||
if (!isExported(functionDeclaration)) { | ||
// Report references to this function as an error. | ||
var functionDeclaration = node; | ||
var nameNode = functionDeclaration.name; | ||
@@ -250,7 +288,11 @@ if (nameNode && nameNode.text) { | ||
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 the symbol was not already exported, export a reference since it is a | ||
// reference to an import | ||
if (!metadata || !metadata[name]) { | ||
var propNode = spec.propertyName || spec.name; | ||
var value = evaluator.evaluateNode(propNode); | ||
if (!metadata) | ||
metadata = {}; | ||
metadata[name] = recordEntry(value, node); | ||
} | ||
}); | ||
@@ -277,6 +319,6 @@ } | ||
var className = classDeclaration.name.text; | ||
if (node.flags & ts.NodeFlags.Export) { | ||
if (isExported(classDeclaration)) { | ||
if (!metadata) | ||
metadata = {}; | ||
metadata[className] = classMetadataOf(classDeclaration); | ||
metadata[exportedName(classDeclaration)] = classMetadataOf(classDeclaration); | ||
} | ||
@@ -290,21 +332,16 @@ } | ||
var functionDeclaration = node; | ||
if (node.flags & ts.NodeFlags.Export) { | ||
if (isExported(functionDeclaration)) { | ||
if (!metadata) | ||
metadata = {}; | ||
var name_4 = exportedName(functionDeclaration); | ||
var maybeFunc = maybeGetSimpleFunction(functionDeclaration); | ||
if (maybeFunc) { | ||
metadata[maybeFunc.name] = recordEntry(maybeFunc.func, node); | ||
} | ||
else if (functionDeclaration.name.kind == ts.SyntaxKind.Identifier) { | ||
var nameNode = functionDeclaration.name; | ||
var functionName = nameNode.text; | ||
metadata[functionName] = { __symbolic: 'function' }; | ||
} | ||
metadata[name_4] = | ||
maybeFunc ? recordEntry(maybeFunc.func, node) : { __symbolic: 'function' }; | ||
} | ||
break; | ||
case ts.SyntaxKind.EnumDeclaration: | ||
if (node.flags & ts.NodeFlags.Export) { | ||
var enumDeclaration = node; | ||
var enumDeclaration = node; | ||
if (isExported(enumDeclaration)) { | ||
var enumValueHolder = {}; | ||
var enumName = enumDeclaration.name.text; | ||
var enumName = exportedName(enumDeclaration); | ||
var nextDefaultValue = 0; | ||
@@ -321,7 +358,7 @@ var writtenMembers = 0; | ||
} | ||
var name_4 = undefined; | ||
var name_5 = undefined; | ||
if (member.name.kind == ts.SyntaxKind.Identifier) { | ||
var identifier = member.name; | ||
name_4 = identifier.text; | ||
enumValueHolder[name_4] = enumValue; | ||
name_5 = identifier.text; | ||
enumValueHolder[name_5] = enumValue; | ||
writtenMembers++; | ||
@@ -332,3 +369,3 @@ } | ||
} | ||
else if (name_4) { | ||
else if (name_5) { | ||
nextDefaultValue = { | ||
@@ -339,3 +376,3 @@ __symbolic: 'binary', | ||
__symbolic: 'select', | ||
expression: recordEntry({ __symbolic: 'reference', name: enumName }, node), name: name_4 | ||
expression: recordEntry({ __symbolic: 'reference', name: enumName }, node), name: name_5 | ||
} | ||
@@ -369,7 +406,7 @@ }; | ||
var exported = false; | ||
if (variableStatement.flags & ts.NodeFlags.Export || | ||
variableDeclaration.flags & ts.NodeFlags.Export) { | ||
if (isExport(variableStatement) || isExport(variableDeclaration) || | ||
isExportedIdentifier(nameNode)) { | ||
if (!metadata) | ||
metadata = {}; | ||
metadata[nameNode.text] = recordEntry(varValue, node); | ||
metadata[exportedIdentifierName(nameNode)] = recordEntry(varValue, node); | ||
exported = true; | ||
@@ -398,9 +435,9 @@ } | ||
case ts.SyntaxKind.Identifier: | ||
var name_5 = nameNode; | ||
var varValue = errorSym('Destructuring not supported', nameNode); | ||
locals.define(name_5.text, varValue); | ||
if (node.flags & ts.NodeFlags.Export) { | ||
var name_6 = nameNode; | ||
var varValue = errorSym('Destructuring not supported', name_6); | ||
locals.define(name_6.text, varValue); | ||
if (isExport(node)) { | ||
if (!metadata) | ||
metadata = {}; | ||
metadata[name_5.text] = varValue; | ||
metadata[name_6.text] = varValue; | ||
} | ||
@@ -596,3 +633,6 @@ break; | ||
var element = _a[_i]; | ||
addNamesOf(element.name); | ||
var name_7 = element.name; | ||
if (name_7) { | ||
addNamesOf(name_7); | ||
} | ||
} | ||
@@ -599,0 +639,0 @@ } |
@@ -151,4 +151,12 @@ /** | ||
var path_1 = emitFilePath.replace(/*DTS*/ /\.js$/, '.metadata.json'); | ||
var metadata = this.metadataCollector.getMetadata(sourceFile, !!this.ngOptions.strictMetadataEmit); | ||
var metadata1 = this.metadataCollector1.getMetadata(sourceFile, false); | ||
// Beginning with 2.1, TypeScript transforms the source tree before emitting it. | ||
// We need the original, unmodified, tree which might be several levels back | ||
// depending on the number of transforms performed. All SourceFile's prior to 2.1 | ||
// will appear to be the original source since they didn't include an original field. | ||
var collectableFile = sourceFile; | ||
while (collectableFile.original) { | ||
collectableFile = collectableFile.original; | ||
} | ||
var metadata = this.metadataCollector.getMetadata(collectableFile, !!this.ngOptions.strictMetadataEmit); | ||
var metadata1 = this.metadataCollector1.getMetadata(collectableFile, false); | ||
var metadatas = [metadata, metadata1].filter(function (e) { return !!e; }); | ||
@@ -155,0 +163,0 @@ if (metadatas.length) { |
@@ -11,2 +11,4 @@ /** | ||
var schema_1 = require('./schema'); | ||
// In TypeScript 2.1 the spread element kind was renamed. | ||
var spreadElementSyntaxKind = ts.SyntaxKind.SpreadElement || ts.SyntaxKind.SpreadElementExpression; | ||
function isMethodCallOf(callExpression, memberName) { | ||
@@ -261,5 +263,4 @@ var expression = callExpression.expression; | ||
return arr_1; | ||
case ts.SyntaxKind.SpreadElementExpression: | ||
var spread = node; | ||
var spreadExpression = this.evaluateNode(spread.expression); | ||
case spreadElementSyntaxKind: | ||
var spreadExpression = this.evaluateNode(node.expression); | ||
return recordEntry({ __symbolic: 'spread', expression: spreadExpression }, node); | ||
@@ -266,0 +267,0 @@ case ts.SyntaxKind.CallExpression: |
@@ -41,2 +41,2 @@ import * as ts from 'typescript'; | ||
} | ||
export declare var tsc: CompilerInterface; | ||
export declare const tsc: CompilerInterface; |
@@ -38,2 +38,3 @@ /** | ||
're-exports-2.ts', | ||
'export-as.d.ts', | ||
'static-field-reference.ts', | ||
@@ -479,2 +480,7 @@ 'static-method.ts', | ||
}); | ||
it('should be able to collect a export as symbol', function () { | ||
var source = program.getSourceFile('export-as.d.ts'); | ||
var metadata = collector.getMetadata(source); | ||
expect(metadata.metadata).toEqual({ SomeFunction: { __symbolic: 'function' } }); | ||
}); | ||
it('should be able to collect exports with no module specifier', function () { | ||
@@ -484,12 +490,5 @@ var source = program.getSourceFile('/re-exports-2.ts'); | ||
expect(metadata.metadata).toEqual({ | ||
MyClass: Object({ __symbolic: 'class' }), | ||
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' } | ||
}, | ||
MyOtherModule: { __symbolic: 'reference', module: './static-field', name: 'MyModule' } | ||
}); | ||
@@ -653,2 +652,3 @@ }); | ||
'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 ", | ||
'export-as.d.ts': "\n declare function someFunction(): void;\n export { someFunction as SomeFunction };\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 ", | ||
@@ -655,0 +655,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
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
484229
3837