refactor(compiler_cli): move it into modules/@angular and integrate properly into the build
This also does no more depend on a version on npm for the compiler_cli. Also runs the tests for tools/metadata
This commit is contained in:
@@ -6,7 +6,7 @@ cd `dirname $0`
|
||||
|
||||
|
||||
TSCONFIG=./modules/tsconfig.json
|
||||
echo "====== (all)COMPILING: \$(npm bin)/ng2tc -p ${TSCONFIG} ====="
|
||||
echo "====== (all)COMPILING: \$(npm bin)/tsc -p ${TSCONFIG} ====="
|
||||
rm -rf ./dist/all/
|
||||
mkdir ./dist/all/
|
||||
|
||||
@@ -27,8 +27,14 @@ ln -s ../../../../node_modules/angular/angular.js .
|
||||
cd -
|
||||
|
||||
# compile ts code
|
||||
$(npm bin)/ng2tc -p ${TSCONFIG}
|
||||
|
||||
# TODO: Right now we have a cycle in that the compiler_cli depends on Angular
|
||||
# but we need it to compile Angular.
|
||||
# The solution right now is to do 2 compilation runs.
|
||||
# Fix this by separating the metadata extraction into a separate binary that does
|
||||
# not depend on Angular.
|
||||
$(npm bin)/tsc -p ${TSCONFIG}
|
||||
NG_TC="node dist/all/@angular/compiler_cli/src/main"
|
||||
$NG_TC -p modules/tsconfig.json
|
||||
|
||||
rm -rf ./dist/packages-dist
|
||||
|
||||
@@ -42,20 +48,20 @@ for PACKAGE in \
|
||||
http \
|
||||
router \
|
||||
router-deprecated \
|
||||
upgrade
|
||||
upgrade \
|
||||
compiler_cli
|
||||
do
|
||||
SRCDIR=./modules/@angular/${PACKAGE}
|
||||
DESTDIR=./dist/packages-dist/${PACKAGE}
|
||||
UMDES6PATH=${DESTDIR}/esm/${PACKAGE}.umd.js
|
||||
UMDES5PATH=${DESTDIR}/${PACKAGE}.umd.js
|
||||
|
||||
|
||||
if [[ ${PACKAGE} == "router-deprecated" ]]; then
|
||||
echo "====== COMPILING: \$(npm bin)/tsc -p ${SRCDIR}/tsconfig-es5.json ====="
|
||||
$(npm bin)/tsc -p ${SRCDIR}/tsconfig-es5.json
|
||||
else
|
||||
echo "====== COMPILING: \$(npm bin)/ng2tc -p ${SRCDIR}/tsconfig-es5.json ====="
|
||||
$(npm bin)/ng2tc -p ${SRCDIR}/tsconfig-es5.json
|
||||
echo "====== COMPILING: ${NG_TC} -p ${SRCDIR}/tsconfig-es5.json ====="
|
||||
$NG_TC -p ${SRCDIR}/tsconfig-es5.json
|
||||
fi
|
||||
|
||||
cp ${SRCDIR}/package.json ${DESTDIR}/
|
||||
@@ -71,42 +77,43 @@ do
|
||||
find ${DESTDIR} -type f -name '*.d.ts' -print0 | xargs -0 sed -i '' -E 's/^( +)abstract ([[:alnum:]]+\:)/\1\2/g'
|
||||
fi
|
||||
|
||||
if [[ ${PACKAGE} != compiler_cli ]]; then
|
||||
|
||||
if [[ ${PACKAGE} == "router-deprecated" ]]; then
|
||||
echo "====== (esm)COMPILING: \$(npm bin)/tsc -p ${SRCDIR}/tsconfig-es2015.json ====="
|
||||
$(npm bin)/tsc -p ${SRCDIR}/tsconfig-es2015.json
|
||||
else
|
||||
echo "====== (esm)COMPILING: $NG_TC -p ${SRCDIR}/tsconfig-es2015.json ====="
|
||||
$NG_TC -p ${SRCDIR}/tsconfig-es2015.json
|
||||
fi
|
||||
|
||||
echo "====== BUNDLING: ${SRCDIR} ====="
|
||||
(
|
||||
cd ${SRCDIR}
|
||||
echo "..." # here just to have grep match something and not exit with 1
|
||||
../../../node_modules/.bin/rollup -c rollup.config.js
|
||||
) 2>&1 | grep -v "as external dependency"
|
||||
|
||||
# workaround for https://github.com/rollup/rollup/issues/626
|
||||
if [[ ${TRAVIS} ]]; then
|
||||
sed -i "s/ class exports\./ class /g" ${DESTDIR}/esm/${PACKAGE}.umd.js
|
||||
else
|
||||
sed -i '' "s/ class exports\./ class /g" ${DESTDIR}/esm/${PACKAGE}.umd.js
|
||||
fi
|
||||
|
||||
$(npm bin)/tsc \
|
||||
--out ${UMDES5PATH} \
|
||||
--target es5 \
|
||||
--allowJs \
|
||||
${UMDES6PATH} \
|
||||
modules/\@angular/manual_typings/globals.d.ts \
|
||||
modules/\@angular/typings/es6-collections/es6-collections.d.ts \
|
||||
modules/\@angular/typings/es6-promise/es6-promise.d.ts
|
||||
rm ${UMDES6PATH}
|
||||
|
||||
cat ./modules/@angular/license-banner.txt > ${UMDES5PATH}.tmp
|
||||
cat ${UMDES5PATH} >> ${UMDES5PATH}.tmp
|
||||
mv ${UMDES5PATH}.tmp ${UMDES5PATH}
|
||||
|
||||
if [[ ${PACKAGE} == "router-deprecated" ]]; then
|
||||
echo "====== (esm)COMPILING: \$(npm bin)/tsc -p ${SRCDIR}/tsconfig-es2015.json ====="
|
||||
$(npm bin)/tsc -p ${SRCDIR}/tsconfig-es2015.json
|
||||
else
|
||||
echo "====== (esm)COMPILING: \$(npm bin)/ng2tc -p ${SRCDIR}/tsconfig-es2015.json ====="
|
||||
$(npm bin)/ng2tc -p ${SRCDIR}/tsconfig-es2015.json
|
||||
fi
|
||||
|
||||
|
||||
echo "====== BUNDLING: ${SRCDIR} ====="
|
||||
(
|
||||
cd ${SRCDIR}
|
||||
echo "..." # here just to have grep match something and not exit with 1
|
||||
../../../node_modules/.bin/rollup -c rollup.config.js
|
||||
) 2>&1 | grep -v "as external dependency"
|
||||
|
||||
# workaround for https://github.com/rollup/rollup/issues/626
|
||||
if [[ ${TRAVIS} ]]; then
|
||||
sed -i "s/ class exports\./ class /g" ${DESTDIR}/esm/${PACKAGE}.umd.js
|
||||
else
|
||||
sed -i '' "s/ class exports\./ class /g" ${DESTDIR}/esm/${PACKAGE}.umd.js
|
||||
fi
|
||||
|
||||
$(npm bin)/tsc \
|
||||
--out ${UMDES5PATH} \
|
||||
--target es5 \
|
||||
--allowJs \
|
||||
${UMDES6PATH} \
|
||||
modules/\@angular/manual_typings/globals.d.ts \
|
||||
modules/\@angular/typings/es6-collections/es6-collections.d.ts \
|
||||
modules/\@angular/typings/es6-promise/es6-promise.d.ts
|
||||
rm ${UMDES6PATH}
|
||||
|
||||
cat ./modules/@angular/license-banner.txt > ${UMDES5PATH}.tmp
|
||||
cat ${UMDES5PATH} >> ${UMDES5PATH}.tmp
|
||||
mv ${UMDES5PATH}.tmp ${UMDES5PATH}
|
||||
|
||||
done
|
||||
|
||||
@@ -39,6 +39,7 @@ module.exports = function(config) {
|
||||
exclude: [
|
||||
'dist/all/@angular/**/e2e_test/**',
|
||||
'dist/all/@angular/examples/**',
|
||||
'dist/all/@angular/compiler_cli/**',
|
||||
'dist/all/angular1_router.js',
|
||||
'dist/all/@angular/platform-browser/testing/e2e_util.js'
|
||||
],
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
import * as selector from './src/selector';
|
||||
import * as pathUtil from './src/output/path_util';
|
||||
import * as path_util from './src/output/path_util';
|
||||
import * as metadata_resolver from './src/metadata_resolver';
|
||||
import * as html_parser from './src/html_parser';
|
||||
import * as directive_normalizer from './src/directive_normalizer';
|
||||
import * as lexer from './src/expression_parser/lexer';
|
||||
import * as parser from './src/expression_parser/parser';
|
||||
import * as template_parser from './src/template_parser';
|
||||
import * as dom_element_schema_registry from './src/schema/dom_element_schema_registry';
|
||||
import * as style_compiler from './src/style_compiler';
|
||||
import * as view_compiler from './src/view_compiler/view_compiler';
|
||||
import * as ts_emitter from './src/output/ts_emitter';
|
||||
|
||||
export namespace __compiler_private__ {
|
||||
export type SelectorMatcher = selector.SelectorMatcher;
|
||||
@@ -8,9 +18,39 @@ export namespace __compiler_private__ {
|
||||
export type CssSelector = selector.CssSelector;
|
||||
export var CssSelector = selector.CssSelector;
|
||||
|
||||
export type AssetUrl = pathUtil.AssetUrl;
|
||||
export var AssetUrl = pathUtil.AssetUrl;
|
||||
export type AssetUrl = path_util.AssetUrl;
|
||||
export var AssetUrl = path_util.AssetUrl;
|
||||
|
||||
export type ImportGenerator = pathUtil.ImportGenerator;
|
||||
export var ImportGenerator = pathUtil.ImportGenerator;
|
||||
export type ImportGenerator = path_util.ImportGenerator;
|
||||
export var ImportGenerator = path_util.ImportGenerator;
|
||||
|
||||
export type CompileMetadataResolver = metadata_resolver.CompileMetadataResolver;
|
||||
export var CompileMetadataResolver = metadata_resolver.CompileMetadataResolver;
|
||||
|
||||
export type HtmlParser = html_parser.HtmlParser;
|
||||
export var HtmlParser = html_parser.HtmlParser;
|
||||
|
||||
export type DirectiveNormalizer = directive_normalizer.DirectiveNormalizer;
|
||||
export var DirectiveNormalizer = directive_normalizer.DirectiveNormalizer;
|
||||
|
||||
export type Lexer = lexer.Lexer;
|
||||
export var Lexer = lexer.Lexer;
|
||||
|
||||
export type Parser = parser.Parser;
|
||||
export var Parser = parser.Parser;
|
||||
|
||||
export type TemplateParser = template_parser.TemplateParser;
|
||||
export var TemplateParser = template_parser.TemplateParser;
|
||||
|
||||
export type DomElementSchemaRegistry = dom_element_schema_registry.DomElementSchemaRegistry;
|
||||
export var DomElementSchemaRegistry = dom_element_schema_registry.DomElementSchemaRegistry;
|
||||
|
||||
export type StyleCompiler = style_compiler.StyleCompiler;
|
||||
export var StyleCompiler = style_compiler.StyleCompiler;
|
||||
|
||||
export type ViewCompiler = view_compiler.ViewCompiler;
|
||||
export var ViewCompiler = view_compiler.ViewCompiler;
|
||||
|
||||
export type TypeScriptEmitter = ts_emitter.TypeScriptEmitter;
|
||||
export var TypeScriptEmitter = ts_emitter.TypeScriptEmitter;
|
||||
}
|
||||
|
||||
@@ -80,18 +80,17 @@ At a high level, this program
|
||||
## For developers
|
||||
Run the compiler from source:
|
||||
```
|
||||
# Build angular2
|
||||
./build.sh
|
||||
# Build the compiler
|
||||
./node_modules/.bin/tsc -p tools/compiler_cli/src
|
||||
# Build angular2 and the compiler
|
||||
./node_modules/.bin/tsc -p modules
|
||||
# Run it on the test project
|
||||
node ./dist/tools/compiler_cli/main.js -p tools/compiler_cli/test
|
||||
$ export NODE_PATH=$NODE_PATH:dist/all:dist/tools
|
||||
$ node dist/packages-dist/compiler_cli/src/main -p modules/@angular/compiler_cli/integrationtest
|
||||
```
|
||||
|
||||
Release:
|
||||
```
|
||||
$ gulp test.compiler_cli
|
||||
$ cp tools/compiler_cli/README.md tools/compiler_cli/package.json dist/tools/compiler_cli
|
||||
$ node dist/tools/cjs-jasmine -- @angular/compiler_cli/integrationtest/**/*_spec.js
|
||||
$ cp modules/@angular/compiler_cli/README.md modules/@angular/compiler_cli/package.json dist/all/@angular/compiler_cli
|
||||
# npm login as angular
|
||||
$ npm publish dist/tools/compiler_cli/ --access=public
|
||||
$ npm publish dist/all/@angular/compiler_cli --access=public
|
||||
```
|
||||
@@ -0,0 +1,3 @@
|
||||
export {CodeGenerator} from './src/codegen';
|
||||
export {NodeReflectorHost} from './src/reflector_host';
|
||||
export {TsickleHost, MetadataWriterHost} from './src/compiler_host';
|
||||
Vendored
+2
-4
@@ -1,10 +1,8 @@
|
||||
/// <reference path="../../typings/jasmine/jasmine.d.ts" />
|
||||
/// <reference path="../../typings/node/node.d.ts" />
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
describe("template codegen output", () => {
|
||||
const outDir = path.join('dist', 'tools', 'compiler_cli', 'test', 'built');
|
||||
const outDir = path.join('dist', 'all', '@angular', 'compiler_cli', 'integrationtest', 'src');
|
||||
|
||||
it("should lower Decorators without reflect-metadata", () => {
|
||||
const jsOutput = path.join(outDir, 'basic.js');
|
||||
@@ -17,7 +15,7 @@ describe("template codegen output", () => {
|
||||
expect(fs.existsSync(metadataOutput)).toBeTruthy();
|
||||
const output = fs.readFileSync(metadataOutput, {encoding: 'utf-8'});
|
||||
expect(output).toContain('"decorators":');
|
||||
expect(output).toContain('"name":"Component","module":"angular2/core"');
|
||||
expect(output).toContain('"name":"Component","module":"@angular/core"');
|
||||
});
|
||||
|
||||
it("should write .d.ts files", () => {
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"angularCompilerOptions": {
|
||||
// For TypeScript 1.8, we have to lay out generated files
|
||||
// in the same source directory with your code.
|
||||
"genDir": ".",
|
||||
"legacyPackageLayout": false
|
||||
},
|
||||
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"experimentalDecorators": true,
|
||||
"noImplicitAny": false,
|
||||
"moduleResolution": "node",
|
||||
"outDir": "../../../../dist/all/@angular/compiler_cli/integrationtest",
|
||||
"rootDir": "",
|
||||
"declaration": true,
|
||||
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@angular/*": ["../../../../dist/all/@angular/*"]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
/// <reference path="../../typings/es6-collections/es6-collections.d.ts" />
|
||||
/// <reference path="../../typings/es6-promise/es6-promise.d.ts" />
|
||||
/// <reference path="../../typings/node/node.d.ts" />
|
||||
/// <reference path="../../typings/jasmine/jasmine.d.ts" />
|
||||
@@ -5,7 +5,7 @@
|
||||
"main": "index.js",
|
||||
"typings": "index.d.ts",
|
||||
"bin": {
|
||||
"ngc": "./main.js"
|
||||
"ngc": "./src/main.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"ts-metadata-collector": "^0.1.0",
|
||||
@@ -8,16 +8,11 @@ import * as path from 'path';
|
||||
import * as compiler from '@angular/compiler';
|
||||
import {ViewEncapsulation} from '@angular/core';
|
||||
import {StaticReflector} from './static_reflector';
|
||||
import {CompileMetadataResolver} from '@angular/compiler/src/metadata_resolver';
|
||||
import {HtmlParser} from '@angular/compiler/src/html_parser';
|
||||
import {DirectiveNormalizer} from '@angular/compiler/src/directive_normalizer';
|
||||
import {Lexer} from '@angular/compiler/src/expression_parser/lexer';
|
||||
import {Parser} from '@angular/compiler/src/expression_parser/parser';
|
||||
import {TemplateParser} from '@angular/compiler/src/template_parser';
|
||||
import {DomElementSchemaRegistry} from '@angular/compiler/src/schema/dom_element_schema_registry';
|
||||
import {StyleCompiler} from '@angular/compiler/src/style_compiler';
|
||||
import {ViewCompiler} from '@angular/compiler/src/view_compiler/view_compiler';
|
||||
import {TypeScriptEmitter} from '@angular/compiler/src/output/ts_emitter';
|
||||
import {CompileMetadataResolver, HtmlParser, DirectiveNormalizer, Lexer, Parser,
|
||||
TemplateParser, DomElementSchemaRegistry, StyleCompiler,
|
||||
ViewCompiler, TypeScriptEmitter
|
||||
} from './compiler_private';
|
||||
|
||||
import {Parse5DomAdapter} from '@angular/platform-server';
|
||||
|
||||
import {MetadataCollector} from 'ts-metadata-collector';
|
||||
@@ -0,0 +1,37 @@
|
||||
import {__compiler_private__ as _c} from '@angular/compiler';
|
||||
|
||||
export var AssetUrl: typeof _c.AssetUrl = _c.AssetUrl;
|
||||
export type AssetUrl = _c.AssetUrl;
|
||||
|
||||
export var ImportGenerator: typeof _c.ImportGenerator = _c.ImportGenerator;
|
||||
export type ImportGenerator = _c.ImportGenerator;
|
||||
|
||||
export type CompileMetadataResolver = _c.CompileMetadataResolver;
|
||||
export var CompileMetadataResolver: typeof _c.CompileMetadataResolver = _c.CompileMetadataResolver;
|
||||
|
||||
export type HtmlParser = _c.HtmlParser;
|
||||
export var HtmlParser: typeof _c.HtmlParser = _c.HtmlParser;
|
||||
|
||||
export type DirectiveNormalizer = _c.DirectiveNormalizer;
|
||||
export var DirectiveNormalizer: typeof _c.DirectiveNormalizer = _c.DirectiveNormalizer;
|
||||
|
||||
export type Lexer = _c.Lexer;
|
||||
export var Lexer: typeof _c.Lexer = _c.Lexer;
|
||||
|
||||
export type Parser = _c.Parser;
|
||||
export var Parser: typeof _c.Parser = _c.Parser;
|
||||
|
||||
export type TemplateParser = _c.TemplateParser;
|
||||
export var TemplateParser: typeof _c.TemplateParser = _c.TemplateParser;
|
||||
|
||||
export type DomElementSchemaRegistry = _c.DomElementSchemaRegistry;
|
||||
export var DomElementSchemaRegistry: typeof _c.DomElementSchemaRegistry = _c.DomElementSchemaRegistry;
|
||||
|
||||
export type StyleCompiler = _c.StyleCompiler;
|
||||
export var StyleCompiler: typeof _c.StyleCompiler = _c.StyleCompiler;
|
||||
|
||||
export type ViewCompiler = _c.ViewCompiler;
|
||||
export var ViewCompiler: typeof _c.ViewCompiler = _c.ViewCompiler;
|
||||
|
||||
export type TypeScriptEmitter = _c.TypeScriptEmitter;
|
||||
export var TypeScriptEmitter: typeof _c.TypeScriptEmitter = _c.TypeScriptEmitter;
|
||||
@@ -0,0 +1,4 @@
|
||||
import {__core_private__ as r, __core_private_types__ as t} from '@angular/core';
|
||||
|
||||
export type ReflectorReader = t.ReflectorReader;
|
||||
export var ReflectorReader: typeof t.ReflectorReader = r.ReflectorReader;
|
||||
@@ -1,7 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
// TODO(alexeagle): use --lib=node when available; remove this reference
|
||||
// https://github.com/Microsoft/TypeScript/pull/7757#issuecomment-205644657
|
||||
/// <reference path="../../typings/node/node.d.ts"/>
|
||||
|
||||
// Must be imported first, because angular2 decorators throws on load.
|
||||
import 'reflect-metadata';
|
||||
+41
-45
@@ -1,12 +1,3 @@
|
||||
import {StringMapWrapper, ListWrapper} from '@angular/core/src/facade/collection';
|
||||
import {
|
||||
isArray,
|
||||
isPresent,
|
||||
isBlank,
|
||||
isPrimitive,
|
||||
isStringMap,
|
||||
FunctionWrapper
|
||||
} from '@angular/core/src/facade/lang';
|
||||
import {
|
||||
AttributeMetadata,
|
||||
DirectiveMetadata,
|
||||
@@ -23,8 +14,7 @@ import {
|
||||
ViewQueryMetadata,
|
||||
QueryMetadata,
|
||||
} from '@angular/core';
|
||||
import {ReflectorReader} from '@angular/core/src/reflection/reflector_reader';
|
||||
import {reflector} from '@angular/core';
|
||||
import {ReflectorReader} from './core_private';
|
||||
import {Provider} from '@angular/core';
|
||||
import {
|
||||
HostMetadata,
|
||||
@@ -89,26 +79,26 @@ export class StaticReflector implements ReflectorReader {
|
||||
|
||||
public annotations(type: StaticSymbol): any[] {
|
||||
let annotations = this.annotationCache.get(type);
|
||||
if (!isPresent(annotations)) {
|
||||
if (!annotations) {
|
||||
let classMetadata = this.getTypeMetadata(type);
|
||||
if (isPresent(classMetadata['decorators'])) {
|
||||
if (classMetadata['decorators']) {
|
||||
annotations = this.simplify(type, classMetadata['decorators']);
|
||||
} else {
|
||||
annotations = [];
|
||||
}
|
||||
this.annotationCache.set(type, annotations.filter(ann => isPresent(ann)));
|
||||
this.annotationCache.set(type, annotations.filter(ann => !!ann));
|
||||
}
|
||||
return annotations;
|
||||
}
|
||||
|
||||
public propMetadata(type: StaticSymbol): {[key: string]: any} {
|
||||
let propMetadata = this.propertyCache.get(type);
|
||||
if (!isPresent(propMetadata)) {
|
||||
if (!propMetadata) {
|
||||
let classMetadata = this.getTypeMetadata(type);
|
||||
let members = isPresent(classMetadata) ? classMetadata['members'] : {};
|
||||
let members = classMetadata ? classMetadata['members'] : {};
|
||||
propMetadata = mapStringMap(members, (propData, propName) => {
|
||||
let prop = (<any[]>propData).find(a => a['__symbolic'] == 'property');
|
||||
if (isPresent(prop) && isPresent(prop['decorators'])) {
|
||||
if (prop && prop['decorators']) {
|
||||
return this.simplify(type, prop['decorators']);
|
||||
} else {
|
||||
return [];
|
||||
@@ -125,29 +115,29 @@ export class StaticReflector implements ReflectorReader {
|
||||
}
|
||||
try {
|
||||
let parameters = this.parameterCache.get(type);
|
||||
if (!isPresent(parameters)) {
|
||||
if (!parameters) {
|
||||
let classMetadata = this.getTypeMetadata(type);
|
||||
let members = isPresent(classMetadata) ? classMetadata['members'] : null;
|
||||
let ctorData = isPresent(members) ? members['__ctor__'] : null;
|
||||
if (isPresent(ctorData)) {
|
||||
let members = classMetadata ? classMetadata['members'] : null;
|
||||
let ctorData = members ? members['__ctor__'] : null;
|
||||
if (ctorData) {
|
||||
let ctor = (<any[]>ctorData).find(a => a['__symbolic'] == 'constructor');
|
||||
let parameterTypes = <any[]>this.simplify(type, ctor['parameters']);
|
||||
let parameterDecorators = <any[]>this.simplify(type, ctor['parameterDecorators']);
|
||||
|
||||
parameters = [];
|
||||
ListWrapper.forEachWithIndex(parameterTypes, (paramType, index) => {
|
||||
parameterTypes.forEach( (paramType, index) => {
|
||||
let nestedResult: any[] = [];
|
||||
if (isPresent(paramType)) {
|
||||
if (paramType) {
|
||||
nestedResult.push(paramType);
|
||||
}
|
||||
let decorators = isPresent(parameterDecorators) ? parameterDecorators[index] : null;
|
||||
if (isPresent(decorators)) {
|
||||
ListWrapper.addAll(nestedResult, decorators);
|
||||
let decorators = parameterDecorators ? parameterDecorators[index] : null;
|
||||
if (decorators) {
|
||||
nestedResult.push(...decorators);
|
||||
}
|
||||
parameters.push(nestedResult);
|
||||
});
|
||||
}
|
||||
if (!isPresent(parameters)) {
|
||||
if (!parameters) {
|
||||
parameters = [];
|
||||
}
|
||||
this.parameterCache.set(type, parameters);
|
||||
@@ -162,16 +152,18 @@ export class StaticReflector implements ReflectorReader {
|
||||
private registerDecoratorOrConstructor(type: StaticSymbol, ctor: any): void {
|
||||
this.conversionMap.set(type, (context: StaticSymbol, args: any[]) => {
|
||||
let argValues: any[] = [];
|
||||
ListWrapper.forEachWithIndex(args, (arg, index) => {
|
||||
args.forEach( (arg, index) => {
|
||||
let argValue: any;
|
||||
if (isStringMap(arg) && isBlank(arg['__symbolic'])) {
|
||||
if (typeof arg === 'object' && !arg['__symbolic']) {
|
||||
argValue = mapStringMap(arg, (value, key) => this.simplify(context, value));
|
||||
} else {
|
||||
argValue = this.simplify(context, arg);
|
||||
}
|
||||
argValues.push(argValue);
|
||||
});
|
||||
return FunctionWrapper.apply(reflector.factory(ctor), argValues);
|
||||
var metadata = Object.create(ctor.prototype);
|
||||
ctor.apply(metadata, argValues);
|
||||
return metadata;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -239,15 +231,15 @@ export class StaticReflector implements ReflectorReader {
|
||||
if (isPrimitive(expression)) {
|
||||
return expression;
|
||||
}
|
||||
if (isArray(expression)) {
|
||||
if (expression instanceof Array) {
|
||||
let result: any[] = [];
|
||||
for (let item of(<any>expression)) {
|
||||
result.push(simplify(item));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
if (isPresent(expression)) {
|
||||
if (isPresent(expression['__symbolic'])) {
|
||||
if (expression) {
|
||||
if (expression['__symbolic']) {
|
||||
let staticSymbol: StaticSymbol;
|
||||
switch (expression['__symbolic']) {
|
||||
case "binop":
|
||||
@@ -312,15 +304,15 @@ export class StaticReflector implements ReflectorReader {
|
||||
case "index":
|
||||
let indexTarget = simplify(expression['expression']);
|
||||
let index = simplify(expression['index']);
|
||||
if (isPresent(indexTarget) && isPrimitive(index)) return indexTarget[index];
|
||||
if (indexTarget && isPrimitive(index)) return indexTarget[index];
|
||||
return null;
|
||||
case "select":
|
||||
let selectTarget = simplify(expression['expression']);
|
||||
let member = simplify(expression['member']);
|
||||
if (isPresent(selectTarget) && isPrimitive(member)) return selectTarget[member];
|
||||
if (selectTarget && isPrimitive(member)) return selectTarget[member];
|
||||
return null;
|
||||
case "reference":
|
||||
if (isPresent(expression['module'])) {
|
||||
if (expression['module']) {
|
||||
staticSymbol = _this.host.findDeclaration(expression['module'], expression['name'],
|
||||
context.filePath);
|
||||
} else {
|
||||
@@ -329,8 +321,8 @@ export class StaticReflector implements ReflectorReader {
|
||||
let result = staticSymbol;
|
||||
let moduleMetadata = _this.getModuleMetadata(staticSymbol.filePath);
|
||||
let declarationValue =
|
||||
isPresent(moduleMetadata) ? moduleMetadata['metadata'][staticSymbol.name] : null;
|
||||
if (isPresent(declarationValue)) {
|
||||
moduleMetadata ? moduleMetadata['metadata'][staticSymbol.name] : null;
|
||||
if (declarationValue) {
|
||||
result = _this.simplify(staticSymbol, declarationValue);
|
||||
}
|
||||
return result;
|
||||
@@ -342,9 +334,9 @@ export class StaticReflector implements ReflectorReader {
|
||||
staticSymbol =
|
||||
_this.host.findDeclaration(target['module'], target['name'], context.filePath);
|
||||
let converter = _this.conversionMap.get(staticSymbol);
|
||||
if (isPresent(converter)) {
|
||||
if (converter) {
|
||||
let args = expression['arguments'];
|
||||
if (isBlank(args)) {
|
||||
if (!args) {
|
||||
args = [];
|
||||
}
|
||||
return converter(context, args);
|
||||
@@ -367,9 +359,9 @@ export class StaticReflector implements ReflectorReader {
|
||||
*/
|
||||
public getModuleMetadata(module: string): {[key: string]: any} {
|
||||
let moduleMetadata = this.metadataCache.get(module);
|
||||
if (!isPresent(moduleMetadata)) {
|
||||
if (!moduleMetadata) {
|
||||
moduleMetadata = this.host.getMetadataFor(module);
|
||||
if (!isPresent(moduleMetadata)) {
|
||||
if (!moduleMetadata) {
|
||||
moduleMetadata = {__symbolic: "module", module: module, metadata: {}};
|
||||
}
|
||||
this.metadataCache.set(module, moduleMetadata);
|
||||
@@ -380,7 +372,7 @@ export class StaticReflector implements ReflectorReader {
|
||||
private getTypeMetadata(type: StaticSymbol): {[key: string]: any} {
|
||||
let moduleMetadata = this.getModuleMetadata(type.filePath);
|
||||
let result = moduleMetadata['metadata'][type.name];
|
||||
if (!isPresent(result)) {
|
||||
if (!result) {
|
||||
result = {__symbolic: "class"};
|
||||
}
|
||||
return result;
|
||||
@@ -389,8 +381,12 @@ export class StaticReflector implements ReflectorReader {
|
||||
|
||||
function mapStringMap(input: {[key: string]: any},
|
||||
transform: (value: any, key: string) => any): {[key: string]: any} {
|
||||
if (isBlank(input)) return {};
|
||||
if (!input) return {};
|
||||
var result: {[key: string]: any} = {};
|
||||
StringMapWrapper.keys(input).forEach((key) => { result[key] = transform(input[key], key); });
|
||||
Object.keys(input).forEach((key) => { result[key] = transform(input[key], key); });
|
||||
return result;
|
||||
}
|
||||
|
||||
function isPrimitive(o: any):boolean {
|
||||
return o === null || (typeof o !== "function" && typeof o !== "object");
|
||||
}
|
||||
+1
-3
@@ -1,5 +1,3 @@
|
||||
/// <reference path="../../typings/jasmine/jasmine.d.ts" />
|
||||
|
||||
import {
|
||||
describe,
|
||||
it,
|
||||
@@ -11,7 +9,7 @@ import {
|
||||
import {isBlank} from '@angular/facade/src/lang';
|
||||
import {ListWrapper} from '@angular/facade/src/collection';
|
||||
|
||||
import {StaticReflector, StaticReflectorHost, StaticSymbol} from './static_reflector';
|
||||
import {StaticReflector, StaticReflectorHost, StaticSymbol} from '@angular/compiler_cli/src/static_reflector';
|
||||
|
||||
describe('StaticReflector', () => {
|
||||
let noContext = new StaticSymbol('', '');
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"angularCompilerOptions": {
|
||||
"skipTemplateCodegen": true
|
||||
},
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"lib": ["es6", "dom"],
|
||||
"noImplicitAny": true,
|
||||
"sourceMap": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@angular/core": ["../../../dist/packages-dist/core"],
|
||||
"@angular/common": ["../../../dist/packages-dist/common"],
|
||||
"@angular/compiler": ["../../../dist/packages-dist/compiler"],
|
||||
"@angular/platform-server": ["../../../dist/packages-dist/platform-server"],
|
||||
"@angular/platform-browser": ["../../../dist/packages-dist/platform-browser"],
|
||||
"ts-metadata-collector": ["dist/tools/metadata"]
|
||||
},
|
||||
"experimentalDecorators": true,
|
||||
"rootDir": ".",
|
||||
"sourceRoot": ".",
|
||||
"outDir": "../../../dist/packages-dist/compiler_cli",
|
||||
"declaration": true
|
||||
},
|
||||
"exclude": ["integrationtest"],
|
||||
"files": [
|
||||
"index.ts",
|
||||
"src/main.ts",
|
||||
"../typings/node/node.d.ts",
|
||||
"../typings/jasmine/jasmine.d.ts",
|
||||
"../../../node_modules/zone.js/dist/zone.js.d.ts"
|
||||
]
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import {__compiler_private__ as _} from '@angular/compiler';
|
||||
import {__compiler_private__ as _c} from '@angular/compiler';
|
||||
|
||||
export type SelectorMatcher = typeof _.SelectorMatcher;
|
||||
export var SelectorMatcher: typeof _.SelectorMatcher = _.SelectorMatcher;
|
||||
export type SelectorMatcher = typeof _c.SelectorMatcher;
|
||||
export var SelectorMatcher: typeof _c.SelectorMatcher = _c.SelectorMatcher;
|
||||
|
||||
export type CssSelector = typeof _.CssSelector;
|
||||
export var CssSelector: typeof _.CssSelector = _.CssSelector;
|
||||
export type CssSelector = typeof _c.CssSelector;
|
||||
export var CssSelector: typeof _c.CssSelector = _c.CssSelector;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
"payload_tests",
|
||||
"rollup-test",
|
||||
"upgrade-ts2dart.d.ts",
|
||||
"zone-ts2dart.d.ts"
|
||||
"zone-ts2dart.d.ts",
|
||||
"@angular/compiler_cli/integrationtest"
|
||||
]
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user