Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions tools/@angular/tsc-wrapped/src/collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ export class MetadataCollector {
}
}


interface NodeFlagsUtils {
getNodeFlags(flag: ts.NodeFlags): (target: ts.Node) => boolean;
}

const nodeFlagsUtils = {
get isStatic(this: NodeFlagsUtils) { return this.getNodeFlags(ts.NodeFlags.Static); },

get isExport(this: NodeFlagsUtils) { return this.getNodeFlags(ts.NodeFlags.Export); },

getNodeFlags(flag: ts.NodeFlags) {
return function(target: ts.Node) { return !!(target.flags & flag); };
},
};


function classMetadataOf(classDeclaration: ts.ClassDeclaration): ClassMetadata {
const result: ClassMetadata = {__symbolic: 'class'};

Expand Down Expand Up @@ -121,7 +137,7 @@ export class MetadataCollector {
case ts.SyntaxKind.MethodDeclaration:
isConstructor = member.kind === ts.SyntaxKind.Constructor;
const method = <ts.MethodDeclaration|ts.ConstructorDeclaration>member;
if (method.flags & ts.NodeFlags.Static) {
if (nodeFlagsUtils.isStatic(method)) {
const maybeFunc = maybeGetSimpleFunction(<ts.MethodDeclaration>method);
if (maybeFunc) {
recordStaticMember(maybeFunc.name, maybeFunc.func);
Expand Down Expand Up @@ -168,7 +184,7 @@ export class MetadataCollector {
case ts.SyntaxKind.GetAccessor:
case ts.SyntaxKind.SetAccessor:
const property = <ts.PropertyDeclaration>member;
if (property.flags & ts.NodeFlags.Static) {
if (nodeFlagsUtils.isStatic(property)) {
const name = evaluator.nameOf(property.name);
if (!isMetadataError(name)) {
if (property.initializer) {
Expand Down Expand Up @@ -207,7 +223,7 @@ export class MetadataCollector {
const classDeclaration = <ts.ClassDeclaration>node;
if (classDeclaration.name) {
const className = classDeclaration.name.text;
if (node.flags & ts.NodeFlags.Export) {
if (nodeFlagsUtils.isExport(node)) {
locals.define(className, {__symbolic: 'reference', name: className});
} else {
locals.define(
Expand All @@ -216,7 +232,7 @@ export class MetadataCollector {
}
break;
case ts.SyntaxKind.FunctionDeclaration:
if (!(node.flags & ts.NodeFlags.Export)) {
if (!nodeFlagsUtils.isExport(node)) {
// Report references to this function as an error.
const functionDeclaration = <ts.FunctionDeclaration>node;
const nameNode = functionDeclaration.name;
Expand Down Expand Up @@ -255,7 +271,7 @@ export class MetadataCollector {
const classDeclaration = <ts.ClassDeclaration>node;
if (classDeclaration.name) {
const className = classDeclaration.name.text;
if (node.flags & ts.NodeFlags.Export) {
if (nodeFlagsUtils.isExport(node)) {
if (!metadata) metadata = {};
if (classDeclaration.decorators) {
metadata[className] = classMetadataOf(classDeclaration);
Expand All @@ -270,7 +286,7 @@ export class MetadataCollector {
// Record functions that return a single value. Record the parameter
// names substitution will be performed by the StaticReflector.
const functionDeclaration = <ts.FunctionDeclaration>node;
if (node.flags & ts.NodeFlags.Export) {
if (nodeFlagsUtils.isExport(node)) {
if (!metadata) metadata = {};
const maybeFunc = maybeGetSimpleFunction(functionDeclaration);
if (maybeFunc) {
Expand All @@ -283,7 +299,7 @@ export class MetadataCollector {
}
break;
case ts.SyntaxKind.EnumDeclaration:
if (node.flags & ts.NodeFlags.Export) {
if (nodeFlagsUtils.isExport(node)) {
const enumDeclaration = <ts.EnumDeclaration>node;
const enumValueHolder: {[name: string]: MetadataValue} = {};
const enumName = enumDeclaration.name.text;
Expand Down Expand Up @@ -337,8 +353,8 @@ export class MetadataCollector {
varValue = recordEntry(errorSym('Variable not initialized', nameNode), nameNode);
}
let exported = false;
if (variableStatement.flags & ts.NodeFlags.Export ||
variableDeclaration.flags & ts.NodeFlags.Export) {
if (nodeFlagsUtils.isExport(variableStatement) ||
nodeFlagsUtils.isExport(variableDeclaration)) {
if (!metadata) metadata = {};
metadata[nameNode.text] = recordEntry(varValue, node);
exported = true;
Expand Down Expand Up @@ -368,7 +384,7 @@ export class MetadataCollector {
const name = <ts.Identifier>nameNode;
const varValue = errorSym('Destructuring not supported', nameNode);
locals.define(name.text, varValue);
if (node.flags & ts.NodeFlags.Export) {
if (nodeFlagsUtils.isExport(node)) {
if (!metadata) metadata = {};
metadata[name.text] = varValue;
}
Expand Down