revert(format): Revert "chore(format): update to latest formatter"
This reverts commit 03627aa84d
.
This commit is contained in:
@ -11,7 +11,10 @@ export type ProjectMap = {
|
||||
};
|
||||
|
||||
export type Options = {
|
||||
projects: ProjectMap; noTypeChecks: boolean; generateEs6: boolean; useBundles: boolean;
|
||||
projects: ProjectMap;
|
||||
noTypeChecks: boolean;
|
||||
generateEs6: boolean;
|
||||
useBundles: boolean;
|
||||
};
|
||||
|
||||
export interface AngularBuilderOptions {
|
||||
@ -155,17 +158,16 @@ function writeBuildLog(result: BuildResult, name: string) {
|
||||
function broccoliNodeToBuildNode(broccoliNode) {
|
||||
let tree = broccoliNode.tree.newStyleTree || broccoliNode.tree;
|
||||
|
||||
return new BuildNode(
|
||||
tree.description || tree.constructor.name,
|
||||
tree.inputPath ? [tree.inputPath] : tree.inputPaths, tree.cachePath, tree.outputPath,
|
||||
broccoliNode.selfTime / (1000 * 1000 * 1000), broccoliNode.totalTime / (1000 * 1000 * 1000),
|
||||
broccoliNode.subtrees.map(broccoliNodeToBuildNode));
|
||||
return new BuildNode(tree.description || tree.constructor.name,
|
||||
tree.inputPath ? [tree.inputPath] : tree.inputPaths, tree.cachePath,
|
||||
tree.outputPath, broccoliNode.selfTime / (1000 * 1000 * 1000),
|
||||
broccoliNode.totalTime / (1000 * 1000 * 1000),
|
||||
broccoliNode.subtrees.map(broccoliNodeToBuildNode));
|
||||
}
|
||||
|
||||
|
||||
class BuildNode {
|
||||
constructor(
|
||||
public pluginName: string, public inputPaths: string[], public cachePath: string,
|
||||
public outputPath: string, public selfTime: number, public totalTime: number,
|
||||
public inputNodes: BroccoliNode[]) {}
|
||||
constructor(public pluginName: string, public inputPaths: string[], public cachePath: string,
|
||||
public outputPath: string, public selfTime: number, public totalTime: number,
|
||||
public inputNodes: BroccoliNode[]) {}
|
||||
}
|
||||
|
@ -9,15 +9,15 @@ import {wrapDiffingPlugin, DiffingBroccoliPlugin, DiffResult} from './diffing-br
|
||||
* This guarantees that platform-independent modules remain platoform-independent.
|
||||
*/
|
||||
class CheckImports implements DiffingBroccoliPlugin {
|
||||
static IMPORT_DECL_REGEXP = new RegExp(`^import[^;]+;`, 'mg');
|
||||
static IMPORT_PATH_REGEXP = new RegExp(`['"]([^'"]+)+['"]`, 'm');
|
||||
static IMPORT_DECL_REGEXP = new RegExp(`^import[^;]+;`, "mg");
|
||||
static IMPORT_PATH_REGEXP = new RegExp(`['"]([^'"]+)+['"]`, "m");
|
||||
|
||||
static ALLOWED_IMPORTS = {
|
||||
'angular2/src/core': ['angular2/src/facade'],
|
||||
'angular2/src/facade': ['rxjs'],
|
||||
'angular2/src/common': ['angular2/core', 'angular2/src/facade'],
|
||||
'angular2/src/http': ['angular2/core', 'angular2/src/facade', 'rxjs'],
|
||||
'angular2/src/upgrade': ['angular2/core', 'angular2/src/facade', 'angular2/platform/browser']
|
||||
"angular2/src/core": ["angular2/src/facade"],
|
||||
"angular2/src/facade": ["rxjs"],
|
||||
"angular2/src/common": ["angular2/core", "angular2/src/facade"],
|
||||
"angular2/src/http": ["angular2/core", "angular2/src/facade", "rxjs"],
|
||||
"angular2/src/upgrade": ["angular2/core", "angular2/src/facade", "angular2/platform/browser"]
|
||||
//"angular2/src/render": [
|
||||
// "angular2/animate",
|
||||
// "angular2/core",
|
||||
@ -54,8 +54,8 @@ class CheckImports implements DiffingBroccoliPlugin {
|
||||
|
||||
private checkFilePath(filePath: string) {
|
||||
const sourceFilePath = path.join(this.inputPath, filePath);
|
||||
if (endsWith(sourceFilePath, '.ts') && fs.existsSync(sourceFilePath)) {
|
||||
const content = fs.readFileSync(sourceFilePath, 'UTF-8');
|
||||
if (endsWith(sourceFilePath, ".ts") && fs.existsSync(sourceFilePath)) {
|
||||
const content = fs.readFileSync(sourceFilePath, "UTF-8");
|
||||
const imports = content.match(CheckImports.IMPORT_DECL_REGEXP);
|
||||
if (imports) {
|
||||
return imports.filter(i => !this.isAllowedImport(filePath, i))
|
||||
@ -72,14 +72,14 @@ class CheckImports implements DiffingBroccoliPlugin {
|
||||
if (!res || res.length < 2) return true; // non-es6 import
|
||||
const importPath = res[1];
|
||||
|
||||
if (startsWith(importPath, './') || startsWith(importPath, '../')) return true;
|
||||
if (startsWith(importPath, "./") || startsWith(importPath, "../")) return true;
|
||||
|
||||
const c = CheckImports.ALLOWED_IMPORTS;
|
||||
for (var prop in c) {
|
||||
if (c.hasOwnProperty(prop) && startsWith(sourceFile, prop)) {
|
||||
const allowedPaths = c[prop];
|
||||
return startsWith(importPath, prop) ||
|
||||
allowedPaths.filter(p => startsWith(importPath, p)).length > 0;
|
||||
allowedPaths.filter(p => startsWith(importPath, p)).length > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,7 +87,7 @@ class CheckImports implements DiffingBroccoliPlugin {
|
||||
}
|
||||
|
||||
private formatError(filePath: string, importPath: string): string {
|
||||
const i = importPath.replace(new RegExp(`\n`, 'g'), '\\n');
|
||||
const i = importPath.replace(new RegExp(`\n`, 'g'), "\\n");
|
||||
return `${filePath}: ${i}`;
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ class DartFormatter implements DiffingBroccoliPlugin {
|
||||
private firstBuild: boolean = true;
|
||||
|
||||
constructor(public inputPath: string, public cachePath: string, options) {
|
||||
if (!options.dartSDK) throw new Error('Missing Dart SDK');
|
||||
if (!options.dartSDK) throw new Error("Missing Dart SDK");
|
||||
this.DARTFMT = options.dartSDK.DARTFMT;
|
||||
this.verbose = options.logs.dartfmt;
|
||||
}
|
||||
@ -34,21 +34,22 @@ class DartFormatter implements DiffingBroccoliPlugin {
|
||||
let argsLength = 2;
|
||||
let argPackages = [];
|
||||
let firstBuild = this.firstBuild;
|
||||
treeDiff.addedPaths.concat(treeDiff.changedPaths).forEach((changedFile) => {
|
||||
let sourcePath = path.join(this.inputPath, changedFile);
|
||||
let destPath = path.join(this.cachePath, changedFile);
|
||||
if (!firstBuild && /\.dart$/.test(changedFile)) {
|
||||
if ((argsLength + destPath.length + 2) >= 0x2000) {
|
||||
// Win32 command line arguments length
|
||||
argPackages.push(args);
|
||||
args = ['-w'];
|
||||
argsLength = 2;
|
||||
}
|
||||
args.push(destPath);
|
||||
argsLength += destPath.length + 2;
|
||||
}
|
||||
fse.copySync(sourcePath, destPath);
|
||||
});
|
||||
treeDiff.addedPaths.concat(treeDiff.changedPaths)
|
||||
.forEach((changedFile) => {
|
||||
let sourcePath = path.join(this.inputPath, changedFile);
|
||||
let destPath = path.join(this.cachePath, changedFile);
|
||||
if (!firstBuild && /\.dart$/.test(changedFile)) {
|
||||
if ((argsLength + destPath.length + 2) >= 0x2000) {
|
||||
// Win32 command line arguments length
|
||||
argPackages.push(args);
|
||||
args = ['-w'];
|
||||
argsLength = 2;
|
||||
}
|
||||
args.push(destPath);
|
||||
argsLength += destPath.length + 2;
|
||||
}
|
||||
fse.copySync(sourcePath, destPath);
|
||||
});
|
||||
treeDiff.removedPaths.forEach((removedFile) => {
|
||||
let destPath = path.join(this.cachePath, removedFile);
|
||||
fse.removeSync(destPath);
|
||||
|
@ -15,13 +15,14 @@ class DestCopy implements DiffingBroccoliPlugin {
|
||||
|
||||
|
||||
rebuild(treeDiff: DiffResult) {
|
||||
treeDiff.addedPaths.concat(treeDiff.changedPaths).forEach((changedFilePath) => {
|
||||
var destFilePath = path.join(this.outputRoot, changedFilePath);
|
||||
treeDiff.addedPaths.concat(treeDiff.changedPaths)
|
||||
.forEach((changedFilePath) => {
|
||||
var destFilePath = path.join(this.outputRoot, changedFilePath);
|
||||
|
||||
var destDirPath = path.dirname(destFilePath);
|
||||
fse.mkdirsSync(destDirPath);
|
||||
fse.copySync(path.join(this.inputPath, changedFilePath), destFilePath);
|
||||
});
|
||||
var destDirPath = path.dirname(destFilePath);
|
||||
fse.mkdirsSync(destDirPath);
|
||||
fse.copySync(path.join(this.inputPath, changedFilePath), destFilePath);
|
||||
});
|
||||
|
||||
treeDiff.removedPaths.forEach((removedFilePath) => {
|
||||
var destFilePath = path.join(this.outputRoot, removedFilePath);
|
||||
|
@ -12,9 +12,9 @@ describe('Flatten', () => {
|
||||
|
||||
function flatten(inputPaths) { return new DiffingFlatten(inputPaths, 'output', null); }
|
||||
|
||||
function read(path) { return fs.readFileSync(path, {encoding: 'utf-8'}); }
|
||||
function read(path) { return fs.readFileSync(path, {encoding: "utf-8"}); }
|
||||
function rm(path) { return fs.unlinkSync(path); }
|
||||
function write(path, content) { fs.writeFileSync(path, content, {encoding: 'utf-8'}); }
|
||||
function write(path, content) { fs.writeFileSync(path, content, {encoding: "utf-8"}); }
|
||||
|
||||
|
||||
it('should flatten files and be incremental', () => {
|
||||
@ -70,8 +70,7 @@ describe('Flatten', () => {
|
||||
let differ = new TreeDiffer('testLabel', 'input');
|
||||
let flattenedTree = flatten('input');
|
||||
expect(() => flattenedTree.rebuild(differ.diffTree()))
|
||||
.toThrowError(
|
||||
'Duplicate file \'file-1.txt\' found in path \'dir1' + path.sep + 'subdir-1' +
|
||||
path.sep + 'file-1.txt\'');
|
||||
.toThrowError("Duplicate file 'file-1.txt' found in path 'dir1" + path.sep + "subdir-1" +
|
||||
path.sep + "file-1.txt'");
|
||||
});
|
||||
});
|
||||
|
@ -36,9 +36,8 @@ export class DiffingFlatten implements DiffingBroccoliPlugin {
|
||||
if (!fs.existsSync(destFilePath)) {
|
||||
symlinkOrCopy(sourceFilePath, destFilePath);
|
||||
} else {
|
||||
throw new Error(
|
||||
`Duplicate file '${path.basename(changedFilePath)}' ` +
|
||||
`found in path '${changedFilePath}'`);
|
||||
throw new Error(`Duplicate file '${path.basename(changedFilePath)}' ` +
|
||||
`found in path '${changedFilePath}'`);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -23,9 +23,8 @@ const kDefaultOptions: LodashRendererOptions = {
|
||||
* the associated changes.
|
||||
*/
|
||||
export class LodashRenderer implements DiffingBroccoliPlugin {
|
||||
constructor(
|
||||
private inputPath, private cachePath,
|
||||
private options: LodashRendererOptions = kDefaultOptions) {}
|
||||
constructor(private inputPath, private cachePath,
|
||||
private options: LodashRendererOptions = kDefaultOptions) {}
|
||||
|
||||
rebuild(treeDiff: DiffResult) {
|
||||
let {encoding = 'utf-8', context = {}} = this.options;
|
||||
|
@ -19,7 +19,7 @@ describe('MergeTrees', () => {
|
||||
return treeDiffers;
|
||||
}
|
||||
|
||||
function read(path) { return fs.readFileSync(path, 'utf-8'); }
|
||||
function read(path) { return fs.readFileSync(path, "utf-8"); }
|
||||
|
||||
it('should copy the file from the right-most inputTree with overwrite=true', () => {
|
||||
let testDir: any = {
|
||||
|
@ -24,8 +24,8 @@ export class MergeTrees implements DiffingBroccoliPlugin {
|
||||
public options: MergeTreesOptions;
|
||||
private firstBuild: boolean = true;
|
||||
|
||||
constructor(
|
||||
public inputPaths: string[], public cachePath: string, options: MergeTreesOptions = {}) {
|
||||
constructor(public inputPaths: string[], public cachePath: string,
|
||||
options: MergeTreesOptions = {}) {
|
||||
this.options = options || {};
|
||||
}
|
||||
|
||||
|
@ -17,36 +17,37 @@ class DiffingReplace implements DiffingBroccoliPlugin {
|
||||
var patterns = this.options.patterns;
|
||||
var files = this.options.files;
|
||||
|
||||
treeDiff.addedPaths.concat(treeDiff.changedPaths).forEach((changedFilePath) => {
|
||||
var sourceFilePath = path.join(this.inputPath, changedFilePath);
|
||||
var destFilePath = path.join(this.cachePath, changedFilePath);
|
||||
var destDirPath = path.dirname(destFilePath);
|
||||
treeDiff.addedPaths.concat(treeDiff.changedPaths)
|
||||
.forEach((changedFilePath) => {
|
||||
var sourceFilePath = path.join(this.inputPath, changedFilePath);
|
||||
var destFilePath = path.join(this.cachePath, changedFilePath);
|
||||
var destDirPath = path.dirname(destFilePath);
|
||||
|
||||
if (!fs.existsSync(destDirPath)) {
|
||||
fse.mkdirpSync(destDirPath);
|
||||
}
|
||||
|
||||
var fileMatches = files.some((filePath) => minimatch(changedFilePath, filePath));
|
||||
if (fileMatches) {
|
||||
var content = fs.readFileSync(sourceFilePath, FILE_ENCODING);
|
||||
patterns.forEach((pattern) => {
|
||||
var replacement = pattern.replacement;
|
||||
if (typeof replacement === 'function') {
|
||||
replacement = function(content) {
|
||||
return pattern.replacement(content, changedFilePath);
|
||||
};
|
||||
if (!fs.existsSync(destDirPath)) {
|
||||
fse.mkdirpSync(destDirPath);
|
||||
}
|
||||
|
||||
var fileMatches = files.some((filePath) => minimatch(changedFilePath, filePath));
|
||||
if (fileMatches) {
|
||||
var content = fs.readFileSync(sourceFilePath, FILE_ENCODING);
|
||||
patterns.forEach((pattern) => {
|
||||
var replacement = pattern.replacement;
|
||||
if (typeof replacement === 'function') {
|
||||
replacement = function(content) {
|
||||
return pattern.replacement(content, changedFilePath);
|
||||
};
|
||||
}
|
||||
content = content.replace(pattern.match, replacement);
|
||||
});
|
||||
fs.writeFileSync(destFilePath, content, FILE_ENCODING);
|
||||
} else if (!fs.existsSync(destFilePath)) {
|
||||
try {
|
||||
fs.symlinkSync(sourceFilePath, destFilePath);
|
||||
} catch (e) {
|
||||
fs.writeFileSync(destFilePath, fs.readFileSync(sourceFilePath));
|
||||
}
|
||||
}
|
||||
content = content.replace(pattern.match, replacement);
|
||||
});
|
||||
fs.writeFileSync(destFilePath, content, FILE_ENCODING);
|
||||
} else if (!fs.existsSync(destFilePath)) {
|
||||
try {
|
||||
fs.symlinkSync(sourceFilePath, destFilePath);
|
||||
} catch (e) {
|
||||
fs.writeFileSync(destFilePath, fs.readFileSync(sourceFilePath));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
treeDiff.removedPaths.forEach((removedFilePath) => {
|
||||
var destFilePath = path.join(this.cachePath, removedFilePath);
|
||||
|
@ -11,9 +11,8 @@ class TSToDartTranspiler implements DiffingBroccoliPlugin {
|
||||
|
||||
private transpiler: any /*ts2dart.Transpiler*/;
|
||||
|
||||
constructor(
|
||||
public inputPath: string, public cachePath: string,
|
||||
public options: any /*ts2dart.TranspilerOptions*/) {
|
||||
constructor(public inputPath: string, public cachePath: string,
|
||||
public options: any /*ts2dart.TranspilerOptions*/) {
|
||||
options.basePath = inputPath;
|
||||
// Workaround for https://github.com/dart-lang/dart_style/issues/493
|
||||
var ts2dart = require('ts2dart');
|
||||
@ -27,16 +26,17 @@ class TSToDartTranspiler implements DiffingBroccoliPlugin {
|
||||
path.resolve(this.inputPath, 'angular2/typings/es6-collections/es6-collections.d.ts')
|
||||
];
|
||||
let getDartFilePath = (path: string) => path.replace(/((\.js)|(\.ts))$/i, '.dart');
|
||||
treeDiff.addedPaths.concat(treeDiff.changedPaths).forEach((changedPath) => {
|
||||
let inputFilePath = path.resolve(this.inputPath, changedPath);
|
||||
treeDiff.addedPaths.concat(treeDiff.changedPaths)
|
||||
.forEach((changedPath) => {
|
||||
let inputFilePath = path.resolve(this.inputPath, changedPath);
|
||||
|
||||
// Ignore files which don't need to be transpiled to Dart
|
||||
let dartInputFilePath = getDartFilePath(inputFilePath);
|
||||
if (fs.existsSync(dartInputFilePath)) return;
|
||||
// Ignore files which don't need to be transpiled to Dart
|
||||
let dartInputFilePath = getDartFilePath(inputFilePath);
|
||||
if (fs.existsSync(dartInputFilePath)) return;
|
||||
|
||||
// Prepare to rebuild
|
||||
toEmit.push(path.resolve(this.inputPath, changedPath));
|
||||
});
|
||||
// Prepare to rebuild
|
||||
toEmit.push(path.resolve(this.inputPath, changedPath));
|
||||
});
|
||||
|
||||
treeDiff.removedPaths.forEach((removedPath) => {
|
||||
let absolutePath = path.resolve(this.inputPath, removedPath);
|
||||
|
@ -85,8 +85,8 @@ class DiffingTSCompiler implements DiffingBroccoliPlugin {
|
||||
this.tsOpts.rootDir = inputPath;
|
||||
this.tsOpts.outDir = this.cachePath;
|
||||
|
||||
this.tsServiceHost = new CustomLanguageServiceHost(
|
||||
this.tsOpts, this.rootFilePaths, this.fileRegistry, this.inputPath);
|
||||
this.tsServiceHost = new CustomLanguageServiceHost(this.tsOpts, this.rootFilePaths,
|
||||
this.fileRegistry, this.inputPath);
|
||||
this.tsService = ts.createLanguageService(this.tsServiceHost, ts.createDocumentRegistry());
|
||||
this.metadataCollector = new MetadataCollector();
|
||||
}
|
||||
@ -97,16 +97,17 @@ class DiffingTSCompiler implements DiffingBroccoliPlugin {
|
||||
let pathsWithErrors = [];
|
||||
let errorMessages = [];
|
||||
|
||||
treeDiff.addedPaths.concat(treeDiff.changedPaths).forEach((tsFilePath) => {
|
||||
if (!this.fileRegistry[tsFilePath]) {
|
||||
this.fileRegistry[tsFilePath] = {version: 0};
|
||||
this.rootFilePaths.push(tsFilePath);
|
||||
} else {
|
||||
this.fileRegistry[tsFilePath].version++;
|
||||
}
|
||||
treeDiff.addedPaths.concat(treeDiff.changedPaths)
|
||||
.forEach((tsFilePath) => {
|
||||
if (!this.fileRegistry[tsFilePath]) {
|
||||
this.fileRegistry[tsFilePath] = {version: 0};
|
||||
this.rootFilePaths.push(tsFilePath);
|
||||
} else {
|
||||
this.fileRegistry[tsFilePath].version++;
|
||||
}
|
||||
|
||||
pathsToEmit.push(path.join(this.inputPath, tsFilePath));
|
||||
});
|
||||
pathsToEmit.push(path.join(this.inputPath, tsFilePath));
|
||||
});
|
||||
|
||||
treeDiff.removedPaths.forEach((tsFilePath) => {
|
||||
console.log('removing outputs for', tsFilePath);
|
||||
@ -180,7 +181,7 @@ class DiffingTSCompiler implements DiffingBroccoliPlugin {
|
||||
let errors = [];
|
||||
|
||||
allDiagnostics.forEach(diagnostic => {
|
||||
let message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
|
||||
let message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
||||
if (diagnostic.file) {
|
||||
let {line, character} = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
||||
errors.push(` ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
|
||||
@ -256,8 +257,8 @@ class DiffingTSCompiler implements DiffingBroccoliPlugin {
|
||||
* Emit a .metadata.json file to correspond to the .d.ts file if the module contains classes that
|
||||
* use decorators or exported constants.
|
||||
*/
|
||||
private emitMetadata(
|
||||
dtsFileName: string, sourceFile: ts.SourceFile, typeChecker: ts.TypeChecker) {
|
||||
private emitMetadata(dtsFileName: string, sourceFile: ts.SourceFile,
|
||||
typeChecker: ts.TypeChecker) {
|
||||
if (sourceFile) {
|
||||
const metadata = this.metadataCollector.getMetadata(sourceFile, typeChecker);
|
||||
if (metadata && metadata.metadata) {
|
||||
@ -280,16 +281,16 @@ class DiffingTSCompiler implements DiffingBroccoliPlugin {
|
||||
*/
|
||||
private fixSourceMapSources(content: string): string {
|
||||
try {
|
||||
const marker = '//# sourceMappingURL=data:application/json;base64,';
|
||||
const marker = "//# sourceMappingURL=data:application/json;base64,";
|
||||
const index = content.indexOf(marker);
|
||||
if (index == -1) return content;
|
||||
|
||||
const base = content.substring(0, index + marker.length);
|
||||
const sourceMapBit =
|
||||
new Buffer(content.substring(index + marker.length), 'base64').toString('utf8');
|
||||
new Buffer(content.substring(index + marker.length), 'base64').toString("utf8");
|
||||
const sourceMaps = JSON.parse(sourceMapBit);
|
||||
const source = sourceMaps.sources[0];
|
||||
sourceMaps.sources = [source.substring(source.lastIndexOf('../') + 3)];
|
||||
sourceMaps.sources = [source.substring(source.lastIndexOf("../") + 3)];
|
||||
return `${base}${new Buffer(JSON.stringify(sourceMaps)).toString('base64')}`;
|
||||
} catch (e) {
|
||||
return content;
|
||||
@ -318,9 +319,8 @@ class CustomLanguageServiceHost implements ts.LanguageServiceHost {
|
||||
private defaultLibFilePath: string;
|
||||
|
||||
|
||||
constructor(
|
||||
private compilerOptions: ts.CompilerOptions, private fileNames: string[],
|
||||
private fileRegistry: FileRegistry, private treeInputPath: string) {
|
||||
constructor(private compilerOptions: ts.CompilerOptions, private fileNames: string[],
|
||||
private fileRegistry: FileRegistry, private treeInputPath: string) {
|
||||
this.currentDirectory = process.cwd();
|
||||
this.defaultLibFilePath = ts.getDefaultLibFilePath(compilerOptions).replace(/\\/g, '/');
|
||||
}
|
||||
|
2
tools/broccoli/broccoli-writer.d.ts
vendored
2
tools/broccoli/broccoli-writer.d.ts
vendored
@ -1,6 +1,6 @@
|
||||
/// <reference path="../typings/es6-promise/es6-promise.d.ts" />
|
||||
|
||||
declare module 'broccoli-writer' {
|
||||
declare module "broccoli-writer" {
|
||||
class Writer {
|
||||
write(readTree: (tree) => Promise<string>, destDir: string): Promise<any>;
|
||||
}
|
||||
|
4
tools/broccoli/broccoli.d.ts
vendored
4
tools/broccoli/broccoli.d.ts
vendored
@ -66,13 +66,13 @@ interface BroccoliTree {
|
||||
*/
|
||||
description?: string;
|
||||
|
||||
rebuild(): (Promise<any>|void);
|
||||
rebuild(): (Promise<any>| void);
|
||||
cleanup(): void;
|
||||
}
|
||||
|
||||
|
||||
interface OldBroccoliTree {
|
||||
read?(readTree: (tree: BroccoliTree) => Promise<string>): (Promise<string>|string);
|
||||
read?(readTree: (tree: BroccoliTree) => Promise<string>): (Promise<string>| string);
|
||||
}
|
||||
|
||||
|
||||
|
@ -28,8 +28,8 @@ export function wrapDiffingPlugin(pluginClass): DiffingPluginWrapperFactory {
|
||||
|
||||
|
||||
export interface DiffingBroccoliPlugin {
|
||||
rebuild(diff: (DiffResult|DiffResult[])): (Promise<DiffResult|void>|DiffResult|void);
|
||||
cleanup?(): void;
|
||||
rebuild(diff: (DiffResult | DiffResult[])): (Promise<DiffResult | void>| DiffResult | void);
|
||||
cleanup ? () : void;
|
||||
}
|
||||
|
||||
|
||||
@ -64,7 +64,7 @@ class DiffingPluginWrapper implements BroccoliTree {
|
||||
this.description = this.pluginClass.name;
|
||||
}
|
||||
|
||||
private getDiffResult(): (DiffResult|DiffResult[]) {
|
||||
private getDiffResult(): (DiffResult | DiffResult[]) {
|
||||
let returnOrCalculateDiffResult = (tree, index) => {
|
||||
// returnOrCalculateDiffResult will do one of two things:
|
||||
//
|
||||
@ -85,16 +85,16 @@ class DiffingPluginWrapper implements BroccoliTree {
|
||||
} else if (this.inputTree) {
|
||||
return returnOrCalculateDiffResult(this.inputTree, false);
|
||||
} else {
|
||||
throw new Error('Missing TreeDiffer');
|
||||
throw new Error("Missing TreeDiffer");
|
||||
}
|
||||
}
|
||||
|
||||
private maybeStoreDiffResult(value: (DiffResult|void)) {
|
||||
private maybeStoreDiffResult(value: (DiffResult | void)) {
|
||||
if (!(value instanceof DiffResult)) value = null;
|
||||
this.diffResult = <DiffResult>(value);
|
||||
}
|
||||
|
||||
rebuild(): (Promise<any>|void) {
|
||||
rebuild(): (Promise<any>| void) {
|
||||
try {
|
||||
let firstRun = !this.initialized;
|
||||
this.init();
|
||||
@ -104,7 +104,7 @@ class DiffingPluginWrapper implements BroccoliTree {
|
||||
let result = this.wrappedPlugin.rebuild(diffResult);
|
||||
|
||||
if (result) {
|
||||
let resultPromise = <Promise<DiffResult|void>>(result);
|
||||
let resultPromise = <Promise<DiffResult | void>>(result);
|
||||
if (resultPromise.then) {
|
||||
// rebuild() -> Promise<>
|
||||
return resultPromise.then((result: (DiffResult | void)) => {
|
||||
@ -144,15 +144,15 @@ class DiffingPluginWrapper implements BroccoliTree {
|
||||
let description = this.description;
|
||||
this.initialized = true;
|
||||
if (this.inputPaths) {
|
||||
this.treeDiffers = this.inputPaths.map(
|
||||
(inputPath) =>
|
||||
new TreeDiffer(description, inputPath, includeExtensions, excludeExtensions));
|
||||
this.treeDiffers =
|
||||
this.inputPaths.map((inputPath) => new TreeDiffer(
|
||||
description, inputPath, includeExtensions, excludeExtensions));
|
||||
} else if (this.inputPath) {
|
||||
this.treeDiffer =
|
||||
new TreeDiffer(description, this.inputPath, includeExtensions, excludeExtensions);
|
||||
}
|
||||
this.wrappedPlugin = new this.pluginClass(
|
||||
this.inputPaths || this.inputPath, this.cachePath, this.wrappedPluginArguments[1]);
|
||||
this.wrappedPlugin = new this.pluginClass(this.inputPaths || this.inputPath, this.cachePath,
|
||||
this.wrappedPluginArguments[1]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -182,9 +182,8 @@ class DiffingPluginWrapper implements BroccoliTree {
|
||||
// Since it's not safe to use instanceof operator in node, we are checking the constructor.name.
|
||||
//
|
||||
// New-style/rebuild trees should always be stable.
|
||||
let isNewStyleTree =
|
||||
!!(tree['newStyleTree'] || typeof tree.rebuild === 'function' ||
|
||||
tree['isReadAPICompatTree'] || tree.constructor['name'] === 'Funnel');
|
||||
let isNewStyleTree = !!(tree['newStyleTree'] || typeof tree.rebuild === 'function' ||
|
||||
tree['isReadAPICompatTree'] || tree.constructor['name'] === 'Funnel');
|
||||
|
||||
return isNewStyleTree ? tree : stabilizeTree(tree);
|
||||
}
|
||||
|
@ -3,9 +3,9 @@ var path = require('path');
|
||||
|
||||
module.exports = read;
|
||||
function read(file) {
|
||||
var content = fs.readFileSync(
|
||||
path.join('tools/broccoli/html-replace', file + '.html'), {encoding: 'utf-8'});
|
||||
var content = fs.readFileSync(path.join('tools/broccoli/html-replace', file + '.html'),
|
||||
{encoding: 'utf-8'});
|
||||
// TODO(broccoli): we don't really need this, it's here to make the output match the
|
||||
// tools/build/html
|
||||
return content.substring(0, content.lastIndexOf('\n'));
|
||||
return content.substring(0, content.lastIndexOf("\n"));
|
||||
}
|
||||
|
@ -7,5 +7,5 @@ function readJs(file) {
|
||||
fs.readFileSync(path.join('tools/broccoli/js-replace', file + '.js'), {encoding: 'utf-8'});
|
||||
// TODO(broccoli): we don't really need this, it's here to make the output match the
|
||||
// tools/build/html
|
||||
return content.substring(0, content.lastIndexOf('\n'));
|
||||
return content.substring(0, content.lastIndexOf("\n"));
|
||||
}
|
||||
|
@ -26,23 +26,24 @@ export class MultiCopy extends Writer {
|
||||
constructor(private inputTree, private options: MultiCopyOptions) { super(); }
|
||||
|
||||
write(readTree: (tree) => Promise<string>, destDir: string): Promise<any> {
|
||||
return readTree(this.inputTree).then((inputPath: string) => {
|
||||
var fileName = path.basename(this.options.srcPath);
|
||||
var data = fs.readFileSync(path.join(inputPath, this.options.srcPath), 'utf-8');
|
||||
return readTree(this.inputTree)
|
||||
.then((inputPath: string) => {
|
||||
var fileName = path.basename(this.options.srcPath);
|
||||
var data = fs.readFileSync(path.join(inputPath, this.options.srcPath), 'utf-8');
|
||||
|
||||
this.options.targetPatterns.forEach(pattern => {
|
||||
var paths: string[] = glob.sync(pattern);
|
||||
paths = paths.filter(p => fs.statSync(p).isDirectory());
|
||||
if (this.options.exclude) {
|
||||
paths = paths.filter(p => !this.options.exclude.some((excl) => minimatch(p, excl)));
|
||||
}
|
||||
paths.forEach(p => {
|
||||
var folder = path.join(destDir, p);
|
||||
fsx.mkdirsSync(folder);
|
||||
var outputPath = path.join(folder, fileName);
|
||||
fs.writeFileSync(outputPath, data);
|
||||
this.options.targetPatterns.forEach(pattern => {
|
||||
var paths: string[] = glob.sync(pattern);
|
||||
paths = paths.filter(p => fs.statSync(p).isDirectory());
|
||||
if (this.options.exclude) {
|
||||
paths = paths.filter(p => !this.options.exclude.some((excl) => minimatch(p, excl)));
|
||||
}
|
||||
paths.forEach(p => {
|
||||
var folder = path.join(destDir, p);
|
||||
fsx.mkdirsSync(folder);
|
||||
var outputPath = path.join(folder, fileName);
|
||||
fs.writeFileSync(outputPath, data);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -31,9 +31,8 @@ describe('TreeDiffer', () => {
|
||||
|
||||
let diffResult = differ.diffTree();
|
||||
|
||||
expect(diffResult.addedPaths).toEqual([
|
||||
'file-1.txt', 'file-2.txt', 'subdir-1' + path.sep + 'file-1.1.txt'
|
||||
]);
|
||||
expect(diffResult.addedPaths)
|
||||
.toEqual(['file-1.txt', 'file-2.txt', 'subdir-1' + path.sep + 'file-1.1.txt']);
|
||||
|
||||
expect(diffResult.changedPaths).toEqual([]);
|
||||
expect(diffResult.removedPaths).toEqual([]);
|
||||
@ -85,9 +84,8 @@ describe('TreeDiffer', () => {
|
||||
|
||||
let diffResult = differ.diffTree();
|
||||
|
||||
expect(diffResult.addedPaths).toEqual([
|
||||
'file-1.txt', 'file-2.txt', 'subdir-1' + path.sep + 'file-1.1.txt'
|
||||
]);
|
||||
expect(diffResult.addedPaths)
|
||||
.toEqual(['file-1.txt', 'file-2.txt', 'subdir-1' + path.sep + 'file-1.1.txt']);
|
||||
|
||||
// change two files
|
||||
testDir['dir1']['file-1.txt'] = mockfs.file({content: 'new content', mtime: new Date(1000)});
|
||||
@ -97,9 +95,8 @@ describe('TreeDiffer', () => {
|
||||
|
||||
diffResult = differ.diffTree();
|
||||
|
||||
expect(diffResult.changedPaths).toEqual([
|
||||
'file-1.txt', 'subdir-1' + path.sep + 'file-1.1.txt'
|
||||
]);
|
||||
expect(diffResult.changedPaths)
|
||||
.toEqual(['file-1.txt', 'subdir-1' + path.sep + 'file-1.1.txt']);
|
||||
|
||||
expect(diffResult.removedPaths).toEqual([]);
|
||||
|
||||
@ -134,9 +131,8 @@ describe('TreeDiffer', () => {
|
||||
|
||||
let diffResult = differ.diffTree();
|
||||
|
||||
expect(diffResult.addedPaths).toEqual([
|
||||
'file-1.txt', 'file-2.txt', 'subdir-1' + path.sep + 'file-1.1.txt'
|
||||
]);
|
||||
expect(diffResult.addedPaths)
|
||||
.toEqual(['file-1.txt', 'file-2.txt', 'subdir-1' + path.sep + 'file-1.1.txt']);
|
||||
|
||||
// change two files
|
||||
testDir['orig_path']['file-1.txt'] =
|
||||
@ -148,9 +144,8 @@ describe('TreeDiffer', () => {
|
||||
diffResult = differ.diffTree();
|
||||
|
||||
expect(diffResult.addedPaths).toEqual([]);
|
||||
expect(diffResult.changedPaths).toEqual([
|
||||
'file-1.txt', 'subdir-1' + path.sep + 'file-1.1.txt'
|
||||
]);
|
||||
expect(diffResult.changedPaths)
|
||||
.toEqual(['file-1.txt', 'subdir-1' + path.sep + 'file-1.1.txt']);
|
||||
expect(diffResult.removedPaths).toEqual([]);
|
||||
|
||||
// change one file
|
||||
@ -189,14 +184,14 @@ describe('TreeDiffer', () => {
|
||||
});
|
||||
|
||||
|
||||
it('should throw an error if an extension isn\'t prefixed with doc', () => {
|
||||
it("should throw an error if an extension isn't prefixed with doc", () => {
|
||||
// includeExtensions
|
||||
expect(() => new TreeDiffer('testLabel', 'dir1', ['js']))
|
||||
.toThrowError('Extension must begin with \'.\'. Was: \'js\'');
|
||||
.toThrowError("Extension must begin with '.'. Was: 'js'");
|
||||
|
||||
// excludeExtentions
|
||||
expect(() => new TreeDiffer('testLabel', 'dir1', [], ['js']))
|
||||
.toThrowError('Extension must begin with \'.\'. Was: \'js\'');
|
||||
.toThrowError("Extension must begin with '.'. Was: 'js'");
|
||||
});
|
||||
|
||||
|
||||
|
@ -8,7 +8,7 @@ function tryStatSync(path) {
|
||||
try {
|
||||
return fs.statSync(path);
|
||||
} catch (e) {
|
||||
if (e.code === 'ENOENT') return null;
|
||||
if (e.code === "ENOENT") return null;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@ -21,18 +21,17 @@ export class TreeDiffer {
|
||||
private include: RegExp = null;
|
||||
private exclude: RegExp = null;
|
||||
|
||||
constructor(
|
||||
private label: string, private rootPath: string, includeExtensions?: string[],
|
||||
excludeExtensions?: string[]) {
|
||||
constructor(private label: string, private rootPath: string, includeExtensions?: string[],
|
||||
excludeExtensions?: string[]) {
|
||||
this.rootDirName = path.basename(rootPath);
|
||||
|
||||
let buildRegexp = (arr) => new RegExp(`(${arr.reduce(combine, "")})$`, 'i');
|
||||
let buildRegexp = (arr) => new RegExp(`(${arr.reduce(combine, "")})$`, "i");
|
||||
|
||||
this.include = (includeExtensions || []).length ? buildRegexp(includeExtensions) : null;
|
||||
this.exclude = (excludeExtensions || []).length ? buildRegexp(excludeExtensions) : null;
|
||||
|
||||
function combine(prev, curr) {
|
||||
if (curr.charAt(0) !== '.') {
|
||||
if (curr.charAt(0) !== ".") {
|
||||
throw new Error(`Extension must begin with '.'. Was: '${curr}'`);
|
||||
}
|
||||
let kSpecialRegexpChars = /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g;
|
||||
@ -147,17 +146,17 @@ class DirtyCheckingDiffResult extends DiffResult {
|
||||
|
||||
toString() {
|
||||
return `${pad(this.label, 30)}, ${pad(this.endTime - this.startTime, 5)}ms, ` +
|
||||
`${pad(this.addedPaths.length + this.changedPaths.length + this.removedPaths.length, 5)} changes ` +
|
||||
`(files: ${pad(this.filesChecked, 5)}, dirs: ${pad(this.directoriesChecked, 4)})`;
|
||||
`${pad(this.addedPaths.length + this.changedPaths.length + this.removedPaths.length, 5)} changes ` +
|
||||
`(files: ${pad(this.filesChecked, 5)}, dirs: ${pad(this.directoriesChecked, 4)})`;
|
||||
}
|
||||
|
||||
log(verbose) {
|
||||
let prefixedPaths = this.addedPaths.map(p => `+ ${p}`)
|
||||
.concat(this.changedPaths.map(p => `* ${p}`))
|
||||
.concat(this.removedPaths.map(p => `- ${p}`));
|
||||
console.log(
|
||||
`Tree diff: ${this}` +
|
||||
((verbose && prefixedPaths.length) ? ` [\n ${prefixedPaths.join('\n ')}\n]` : ''));
|
||||
console.log(`Tree diff: ${this}` + ((verbose && prefixedPaths.length) ?
|
||||
` [\n ${prefixedPaths.join('\n ')}\n]` :
|
||||
''));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,27 +16,51 @@ import checkImports from '../broccoli-check-imports';
|
||||
|
||||
const kServedPaths = [
|
||||
// Relative (to /modules) paths to benchmark directories
|
||||
'benchmarks/src', 'benchmarks/src/change_detection', 'benchmarks/src/compiler',
|
||||
'benchmarks/src/costs', 'benchmarks/src/di', 'benchmarks/src/element_injector',
|
||||
'benchmarks/src/largetable', 'benchmarks/src/naive_infinite_scroll', 'benchmarks/src/tree',
|
||||
'benchmarks/src',
|
||||
'benchmarks/src/change_detection',
|
||||
'benchmarks/src/compiler',
|
||||
'benchmarks/src/costs',
|
||||
'benchmarks/src/di',
|
||||
'benchmarks/src/element_injector',
|
||||
'benchmarks/src/largetable',
|
||||
'benchmarks/src/naive_infinite_scroll',
|
||||
'benchmarks/src/tree',
|
||||
'benchmarks/src/static_tree',
|
||||
|
||||
// Relative (to /modules) paths to external benchmark directories
|
||||
'benchmarks_external/src', 'benchmarks_external/src/compiler',
|
||||
'benchmarks_external/src/largetable', 'benchmarks_external/src/naive_infinite_scroll',
|
||||
'benchmarks_external/src/tree', 'benchmarks_external/src/tree/react',
|
||||
'benchmarks_external/src',
|
||||
'benchmarks_external/src/compiler',
|
||||
'benchmarks_external/src/largetable',
|
||||
'benchmarks_external/src/naive_infinite_scroll',
|
||||
'benchmarks_external/src/tree',
|
||||
'benchmarks_external/src/tree/react',
|
||||
'benchmarks_external/src/static_tree',
|
||||
|
||||
// Relative (to /modules) paths to example directories
|
||||
'playground/src/animate', 'playground/src/benchpress', 'playground/src/model_driven_forms',
|
||||
'playground/src/template_driven_forms', 'playground/src/person_management',
|
||||
'playground/src/order_management', 'playground/src/gestures', 'playground/src/hash_routing',
|
||||
'playground/src/hello_world', 'playground/src/http', 'playground/src/jsonp',
|
||||
'playground/src/key_events', 'playground/src/relative_assets', 'playground/src/routing',
|
||||
'playground/src/sourcemap', 'playground/src/svg', 'playground/src/todo', 'playground/src/upgrade',
|
||||
'playground/src/zippy_component', 'playground/src/async',
|
||||
'playground/src/web_workers/kitchen_sink', 'playground/src/web_workers/todo',
|
||||
'playground/src/web_workers/images', 'playground/src/web_workers/message_broker',
|
||||
'playground/src/animate',
|
||||
'playground/src/benchpress',
|
||||
'playground/src/model_driven_forms',
|
||||
'playground/src/template_driven_forms',
|
||||
'playground/src/person_management',
|
||||
'playground/src/order_management',
|
||||
'playground/src/gestures',
|
||||
'playground/src/hash_routing',
|
||||
'playground/src/hello_world',
|
||||
'playground/src/http',
|
||||
'playground/src/jsonp',
|
||||
'playground/src/key_events',
|
||||
'playground/src/relative_assets',
|
||||
'playground/src/routing',
|
||||
'playground/src/sourcemap',
|
||||
'playground/src/svg',
|
||||
'playground/src/todo',
|
||||
'playground/src/upgrade',
|
||||
'playground/src/zippy_component',
|
||||
'playground/src/async',
|
||||
'playground/src/web_workers/kitchen_sink',
|
||||
'playground/src/web_workers/todo',
|
||||
'playground/src/web_workers/images',
|
||||
'playground/src/web_workers/message_broker',
|
||||
'playground/src/web_workers/router'
|
||||
];
|
||||
|
||||
@ -60,9 +84,9 @@ module.exports = function makeBrowserTree(options, destinationPath) {
|
||||
}
|
||||
|
||||
if (modules.benchmarks) {
|
||||
var benchmarksTree = new Funnel(
|
||||
'modules/benchmarks',
|
||||
{include: ['**/**'], exclude: ['e2e_test/**'], destDir: '/benchmarks/'});
|
||||
var benchmarksTree =
|
||||
new Funnel('modules/benchmarks',
|
||||
{include: ['**/**'], exclude: ['e2e_test/**'], destDir: '/benchmarks/'});
|
||||
}
|
||||
|
||||
if (modules.benchmarks_external) {
|
||||
@ -72,21 +96,21 @@ module.exports = function makeBrowserTree(options, destinationPath) {
|
||||
}
|
||||
|
||||
if (modules.payload_tests) {
|
||||
var payloadTestsTree = new Funnel(
|
||||
'modules/payload_tests',
|
||||
{include: ['**/ts/**'], exclude: ['e2e_test/**'], destDir: '/payload_tests/'});
|
||||
var payloadTestsTree =
|
||||
new Funnel('modules/payload_tests',
|
||||
{include: ['**/ts/**'], exclude: ['e2e_test/**'], destDir: '/payload_tests/'});
|
||||
}
|
||||
|
||||
if (modules.playground) {
|
||||
var playgroundTree = new Funnel(
|
||||
'modules/playground',
|
||||
{include: ['**/**'], exclude: ['e2e_test/**'], destDir: '/playground/'});
|
||||
var playgroundTree =
|
||||
new Funnel('modules/playground',
|
||||
{include: ['**/**'], exclude: ['e2e_test/**'], destDir: '/playground/'});
|
||||
}
|
||||
|
||||
if (modules.benchpress) {
|
||||
var benchpressTree = new Funnel(
|
||||
'modules/benchpress',
|
||||
{include: ['**/**'], exclude: ['e2e_test/**'], destDir: '/benchpress/'});
|
||||
var benchpressTree =
|
||||
new Funnel('modules/benchpress',
|
||||
{include: ['**/**'], exclude: ['e2e_test/**'], destDir: '/benchpress/'});
|
||||
}
|
||||
|
||||
let externalTypings =
|
||||
@ -133,13 +157,15 @@ module.exports = function makeBrowserTree(options, destinationPath) {
|
||||
modulesTree = checkImports(modulesTree);
|
||||
|
||||
modulesTree = replace(modulesTree, {
|
||||
files: ['playground*/**/*.js'],
|
||||
files: ["playground*/**/*.js"],
|
||||
patterns: [{match: /\$SCRIPTS\$/, replacement: jsReplace('SCRIPTS')}]
|
||||
});
|
||||
|
||||
let ambientTypings = [
|
||||
'angular2/typings/hammerjs/hammerjs.d.ts', 'angular2/typings/node/node.d.ts',
|
||||
'node_modules/zone.js/dist/zone.js.d.ts', 'angular2/manual_typings/globals.d.ts',
|
||||
'angular2/typings/hammerjs/hammerjs.d.ts',
|
||||
'angular2/typings/node/node.d.ts',
|
||||
'node_modules/zone.js/dist/zone.js.d.ts',
|
||||
'angular2/manual_typings/globals.d.ts',
|
||||
'angular2/typings/es6-collections/es6-collections.d.ts',
|
||||
'angular2/typings/es6-promise/es6-promise.d.ts'
|
||||
];
|
||||
@ -161,9 +187,11 @@ module.exports = function makeBrowserTree(options, destinationPath) {
|
||||
|
||||
var vendorScriptsTree = flatten(new Funnel('.', {
|
||||
files: [
|
||||
'node_modules/es6-shim/es6-shim.js', 'node_modules/zone.js/dist/zone.js',
|
||||
'node_modules/es6-shim/es6-shim.js',
|
||||
'node_modules/zone.js/dist/zone.js',
|
||||
'node_modules/zone.js/dist/long-stack-trace-zone.js',
|
||||
'node_modules/systemjs/dist/system.src.js', 'node_modules/base64-js/lib/b64.js',
|
||||
'node_modules/systemjs/dist/system.src.js',
|
||||
'node_modules/base64-js/lib/b64.js',
|
||||
'node_modules/reflect-metadata/Reflect.js'
|
||||
]
|
||||
}));
|
||||
@ -202,8 +230,10 @@ module.exports = function makeBrowserTree(options, destinationPath) {
|
||||
htmlTree = replace(htmlTree, {
|
||||
files: ['playground*/**/*.html'],
|
||||
patterns: [
|
||||
{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS')}, scriptPathPatternReplacement,
|
||||
scriptFilePatternReplacement, useBundlesPatternReplacement
|
||||
{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS')},
|
||||
scriptPathPatternReplacement,
|
||||
scriptFilePatternReplacement,
|
||||
useBundlesPatternReplacement
|
||||
]
|
||||
});
|
||||
}
|
||||
@ -213,7 +243,9 @@ module.exports = function makeBrowserTree(options, destinationPath) {
|
||||
files: ['benchmarks/**'],
|
||||
patterns: [
|
||||
{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS_benchmarks')},
|
||||
scriptPathPatternReplacement, scriptFilePatternReplacement, useBundlesPatternReplacement
|
||||
scriptPathPatternReplacement,
|
||||
scriptFilePatternReplacement,
|
||||
useBundlesPatternReplacement
|
||||
]
|
||||
});
|
||||
}
|
||||
@ -223,7 +255,9 @@ module.exports = function makeBrowserTree(options, destinationPath) {
|
||||
files: ['benchmarks_external/**'],
|
||||
patterns: [
|
||||
{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS_benchmarks_external')},
|
||||
scriptPathPatternReplacement, scriptFilePatternReplacement, useBundlesPatternReplacement
|
||||
scriptPathPatternReplacement,
|
||||
scriptFilePatternReplacement,
|
||||
useBundlesPatternReplacement
|
||||
]
|
||||
});
|
||||
}
|
||||
@ -233,7 +267,7 @@ module.exports = function makeBrowserTree(options, destinationPath) {
|
||||
// for web-worker e2e tests.
|
||||
htmlTree = replace(htmlTree, {
|
||||
files: ['playground*/**/web_workers/**/*.html'],
|
||||
patterns: [{match: '/bundle/angular2.dev.js', replacement: '/bundle/web_worker/ui.dev.js'}]
|
||||
patterns: [{match: "/bundle/angular2.dev.js", replacement: "/bundle/web_worker/ui.dev.js"}]
|
||||
});
|
||||
}
|
||||
|
||||
@ -244,8 +278,10 @@ module.exports = function makeBrowserTree(options, destinationPath) {
|
||||
if (modules.benchmarks_external) {
|
||||
var polymerFiles = new Funnel('.', {
|
||||
files: [
|
||||
'bower_components/polymer/polymer.html', 'bower_components/polymer/polymer-micro.html',
|
||||
'bower_components/polymer/polymer-mini.html', 'tools/build/snippets/url_params_to_form.js'
|
||||
'bower_components/polymer/polymer.html',
|
||||
'bower_components/polymer/polymer-micro.html',
|
||||
'bower_components/polymer/polymer-mini.html',
|
||||
'tools/build/snippets/url_params_to_form.js'
|
||||
]
|
||||
});
|
||||
var polymer = stew.mv(flatten(polymerFiles), 'benchmarks_external/src/tree/polymer');
|
||||
|
@ -14,10 +14,19 @@ import replace from '../broccoli-replace';
|
||||
import {AngularBuilderOptions} from '../angular_builder';
|
||||
|
||||
var global_excludes = [
|
||||
'angular2/examples/**/ts/**/*', 'angular2/http*', 'angular2/http/**/*', 'angular2/src/http/**/*',
|
||||
'angular2/src/upgrade/**/*', 'angular2/test/http/**/*', 'angular2/test/upgrade/**/*',
|
||||
'angular2/upgrade*', 'payload_tests/**/ts/**/*', 'playground/src/http/**/*',
|
||||
'playground/src/jsonp/**/*', 'playground/test/http/**/*', 'playground/test/jsonp/**/*'
|
||||
'angular2/examples/**/ts/**/*',
|
||||
'angular2/http*',
|
||||
'angular2/http/**/*',
|
||||
'angular2/src/http/**/*',
|
||||
'angular2/src/upgrade/**/*',
|
||||
'angular2/test/http/**/*',
|
||||
'angular2/test/upgrade/**/*',
|
||||
'angular2/upgrade*',
|
||||
'payload_tests/**/ts/**/*',
|
||||
'playground/src/http/**/*',
|
||||
'playground/src/jsonp/**/*',
|
||||
'playground/test/http/**/*',
|
||||
'playground/test/jsonp/**/*'
|
||||
];
|
||||
|
||||
|
||||
@ -41,7 +50,7 @@ function replaceScriptTagInHtml(placeholder: string, relativePath: string): stri
|
||||
}
|
||||
var scriptName = relativePath.replace(/\\/g, '/').replace(/.*\/([^/]+)\.html$/, '$1.dart');
|
||||
scriptTags += '<script src="' + scriptName + '" type="application/dart"></script>\n' +
|
||||
'<script src="packages/browser/dart.js" type="text/javascript"></script>';
|
||||
'<script src="packages/browser/dart.js" type="text/javascript"></script>';
|
||||
return scriptTags;
|
||||
}
|
||||
|
||||
@ -70,11 +79,13 @@ function fixDartFolderLayout(sourceTree) {
|
||||
return stew.rename(sourceTree, function(relativePath) {
|
||||
// If a file matches the `pattern`, insert the given `insertion` as the second path part.
|
||||
var replacements = [
|
||||
{pattern: /^benchmarks\/test\//, insertion: ''}, {pattern: /^benchmarks\//, insertion: 'web'},
|
||||
{pattern: /^benchmarks\/test\//, insertion: ''},
|
||||
{pattern: /^benchmarks\//, insertion: 'web'},
|
||||
{pattern: /^benchmarks_external\/test\//, insertion: ''},
|
||||
{pattern: /^benchmarks_external\//, insertion: 'web'},
|
||||
{pattern: /^playground\/test\//, insertion: ''},
|
||||
{pattern: /^playground\//, insertion: 'web/'}, {pattern: /^[^\/]*\/test\//, insertion: ''},
|
||||
{pattern: /^playground\//, insertion: 'web/'},
|
||||
{pattern: /^[^\/]*\/test\//, insertion: ''},
|
||||
{pattern: /^./, insertion: 'lib'}, // catch all.
|
||||
];
|
||||
|
||||
@ -136,7 +147,9 @@ function getDocsTree() {
|
||||
srcPath: 'LICENSE',
|
||||
targetPatterns: ['modules/*'],
|
||||
exclude: [
|
||||
'*/angular1_router', '*/angular2/src/http', '*/payload_tests',
|
||||
'*/angular1_router',
|
||||
'*/angular2/src/http',
|
||||
'*/payload_tests',
|
||||
'*/upgrade'
|
||||
] // Not in dart.
|
||||
});
|
||||
@ -144,12 +157,11 @@ function getDocsTree() {
|
||||
|
||||
// Documentation.
|
||||
// Rename *.dart.md -> *.dart.
|
||||
var mdTree = stew.rename(
|
||||
modulesFunnel(['**/*.dart.md']), relativePath => relativePath.replace(/\.dart\.md$/, '.md'));
|
||||
var mdTree = stew.rename(modulesFunnel(['**/*.dart.md']),
|
||||
relativePath => relativePath.replace(/\.dart\.md$/, '.md'));
|
||||
// Copy all assets, ignore .js. and .dart. (handled above).
|
||||
var docs = modulesFunnel(
|
||||
['**/*.md', '**/*.png', '**/*.html', '**/*.css', '**/*.scss'],
|
||||
['**/*.js.md', '**/*.dart.md', 'angular1_router/**/*']);
|
||||
var docs = modulesFunnel(['**/*.md', '**/*.png', '**/*.html', '**/*.css', '**/*.scss'],
|
||||
['**/*.js.md', '**/*.dart.md', 'angular1_router/**/*']);
|
||||
|
||||
var assets = modulesFunnel(['playground/**/*.json']);
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
import destCopy from '../broccoli-dest-copy';
|
||||
import compileWithTypescript, {INTERNAL_TYPINGS_PATH} from '../broccoli-typescript';
|
||||
import compileWithTypescript, { INTERNAL_TYPINGS_PATH }
|
||||
from '../broccoli-typescript';
|
||||
var Funnel = require('broccoli-funnel');
|
||||
import mergeTrees from '../broccoli-merge-trees';
|
||||
var path = require('path');
|
||||
@ -19,17 +20,26 @@ module.exports = function makeNodeTree(projects, destinationPath) {
|
||||
let srcTree = new Funnel('modules', {
|
||||
include: ['angular2/**'],
|
||||
exclude: [
|
||||
'**/e2e_test/**', 'angular2/test/**', 'angular2/examples/**',
|
||||
'**/e2e_test/**',
|
||||
'angular2/test/**',
|
||||
'angular2/examples/**',
|
||||
|
||||
'angular2/src/testing/**', 'angular2/testing.ts', 'angular2/testing_internal.ts',
|
||||
'angular2/src/upgrade/**', 'angular2/upgrade.ts', 'angular2/platform/testing/**',
|
||||
'angular2/manual_typings/**', 'angular2/typings/**'
|
||||
'angular2/src/testing/**',
|
||||
'angular2/testing.ts',
|
||||
'angular2/testing_internal.ts',
|
||||
'angular2/src/upgrade/**',
|
||||
'angular2/upgrade.ts',
|
||||
'angular2/platform/testing/**',
|
||||
'angular2/manual_typings/**',
|
||||
'angular2/typings/**'
|
||||
]
|
||||
});
|
||||
|
||||
let externalTypings = [
|
||||
'angular2/typings/hammerjs/hammerjs.d.ts', 'angular2/typings/node/node.d.ts',
|
||||
'angular2/manual_typings/globals.d.ts', 'angular2/typings/es6-collections/es6-collections.d.ts',
|
||||
'angular2/typings/hammerjs/hammerjs.d.ts',
|
||||
'angular2/typings/node/node.d.ts',
|
||||
'angular2/manual_typings/globals.d.ts',
|
||||
'angular2/typings/es6-collections/es6-collections.d.ts',
|
||||
'angular2/typings/es6-promise/es6-promise.d.ts'
|
||||
];
|
||||
|
||||
@ -62,21 +72,29 @@ module.exports = function makeNodeTree(projects, destinationPath) {
|
||||
],
|
||||
exclude: [
|
||||
// the following code and tests are not compatible with CJS/node environment
|
||||
'angular2/test/animate/**', 'angular2/test/core/zone/**',
|
||||
'angular2/test/testing/fake_async_spec.ts', 'angular2/test/testing/testing_public_spec.ts',
|
||||
'angular2/test/platform/xhr_impl_spec.ts', 'angular2/test/platform/browser/**/*.ts',
|
||||
'angular2/test/common/forms/**', 'angular2/manual_typings/**', 'angular2/typings/**',
|
||||
'angular2/test/animate/**',
|
||||
'angular2/test/core/zone/**',
|
||||
'angular2/test/testing/fake_async_spec.ts',
|
||||
'angular2/test/testing/testing_public_spec.ts',
|
||||
'angular2/test/platform/xhr_impl_spec.ts',
|
||||
'angular2/test/platform/browser/**/*.ts',
|
||||
'angular2/test/common/forms/**',
|
||||
'angular2/manual_typings/**',
|
||||
'angular2/typings/**',
|
||||
|
||||
// we call browser's bootstrap
|
||||
'angular2/test/router/route_config/route_config_spec.ts',
|
||||
'angular2/test/router/integration/bootstrap_spec.ts',
|
||||
|
||||
// we check the public api by importing angular2/angular2
|
||||
'angular2/test/symbol_inspector/**/*.ts', 'angular2/test/public_api_spec.ts',
|
||||
'angular2/test/symbol_inspector/**/*.ts',
|
||||
'angular2/test/public_api_spec.ts',
|
||||
|
||||
'angular2/test/web_workers/worker/renderer_integration_spec.ts',
|
||||
|
||||
'angular2/test/upgrade/**/*.ts', 'angular1_router/**', 'payload_tests/**'
|
||||
'angular2/test/upgrade/**/*.ts',
|
||||
'angular1_router/**',
|
||||
'payload_tests/**'
|
||||
]
|
||||
});
|
||||
|
||||
@ -119,19 +137,20 @@ module.exports = function makeNodeTree(projects, destinationPath) {
|
||||
|
||||
// Copy es6 typings so quickstart doesn't require typings install
|
||||
let typingsTree = mergeTrees([
|
||||
new Funnel('modules', {
|
||||
include: [
|
||||
'angular2/typings/es6-collections/es6-collections.d.ts',
|
||||
'angular2/typings/es6-promise/es6-promise.d.ts',
|
||||
]
|
||||
}),
|
||||
writeFile(
|
||||
'angular2/typings/browser.d.ts', '// Typings needed for compilation with --target=es5\n' +
|
||||
'///<reference path="./es6-collections/es6-collections.d.ts"/>\n' +
|
||||
'///<reference path="./es6-promise/es6-promise.d.ts"/>\n' +
|
||||
'// Workaround for https://github.com/ReactiveX/RxJS/issues/1270\n' +
|
||||
'// to be removed when angular2 upgrades to rxjs beta.2\n' +
|
||||
'declare type PromiseConstructor = typeof Promise;\n')
|
||||
new Funnel('modules',
|
||||
{
|
||||
include: [
|
||||
'angular2/typings/es6-collections/es6-collections.d.ts',
|
||||
'angular2/typings/es6-promise/es6-promise.d.ts',
|
||||
]
|
||||
}),
|
||||
writeFile('angular2/typings/browser.d.ts',
|
||||
'// Typings needed for compilation with --target=es5\n' +
|
||||
'///<reference path="./es6-collections/es6-collections.d.ts"/>\n' +
|
||||
'///<reference path="./es6-promise/es6-promise.d.ts"/>\n' +
|
||||
'// Workaround for https://github.com/ReactiveX/RxJS/issues/1270\n' +
|
||||
'// to be removed when angular2 upgrades to rxjs beta.2\n' +
|
||||
'declare type PromiseConstructor = typeof Promise;\n')
|
||||
]);
|
||||
|
||||
var nodeTree =
|
||||
@ -146,9 +165,9 @@ module.exports = function makeNodeTree(projects, destinationPath) {
|
||||
replacement:
|
||||
() =>
|
||||
`var parse5Adapter = require('angular2/src/platform/server/parse5_adapter');\r\n` +
|
||||
`parse5Adapter.Parse5DomAdapter.makeCurrent();`
|
||||
`parse5Adapter.Parse5DomAdapter.makeCurrent();`
|
||||
},
|
||||
{match: /$/, replacement: (_, relativePath) => '\r\n main(); \r\n'}
|
||||
{match: /$/, replacement: (_, relativePath) => "\r\n main(); \r\n"}
|
||||
]
|
||||
});
|
||||
|
||||
@ -163,20 +182,20 @@ module.exports = function makeNodeTree(projects, destinationPath) {
|
||||
function compileTree(tree, genInternalTypings, rootFilePaths: string[] = []) {
|
||||
return compileWithTypescript(tree, {
|
||||
// build pipeline options
|
||||
'rootFilePaths': rootFilePaths,
|
||||
'internalTypings': genInternalTypings,
|
||||
"rootFilePaths": rootFilePaths,
|
||||
"internalTypings": genInternalTypings,
|
||||
// tsc options
|
||||
'emitDecoratorMetadata': true,
|
||||
'experimentalDecorators': true,
|
||||
'declaration': true,
|
||||
'stripInternal': true,
|
||||
'module': 'commonjs',
|
||||
'moduleResolution': 'classic',
|
||||
'noEmitOnError': true,
|
||||
'rootDir': '.',
|
||||
'inlineSourceMap': true,
|
||||
'inlineSources': true,
|
||||
'target': 'es5'
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"declaration": true,
|
||||
"stripInternal": true,
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "classic",
|
||||
"noEmitOnError": true,
|
||||
"rootDir": ".",
|
||||
"inlineSourceMap": true,
|
||||
"inlineSources": true,
|
||||
"target": "es5"
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,17 @@
|
||||
import * as ts from 'typescript';
|
||||
import {Evaluator} from './evaluator';
|
||||
import {Symbols} from './symbols';
|
||||
import {ClassMetadata, ConstructorMetadata, ModuleMetadata, MemberMetadata, MetadataMap, MetadataSymbolicExpression, MetadataSymbolicReferenceExpression, MetadataValue, MethodMetadata} from './schema';
|
||||
import {
|
||||
ClassMetadata,
|
||||
ConstructorMetadata,
|
||||
ModuleMetadata,
|
||||
MemberMetadata,
|
||||
MetadataMap,
|
||||
MetadataSymbolicExpression,
|
||||
MetadataSymbolicReferenceExpression,
|
||||
MetadataValue,
|
||||
MethodMetadata
|
||||
} from './schema';
|
||||
|
||||
import * as path from 'path';
|
||||
|
||||
@ -65,7 +75,7 @@ export class MetadataCollector {
|
||||
const declaration = symbol.declarations[0];
|
||||
const sourceFile = declaration.getSourceFile();
|
||||
return {
|
||||
__symbolic: 'reference',
|
||||
__symbolic: "reference",
|
||||
module: moduleNameOf(sourceFile.fileName),
|
||||
name: symbol.name
|
||||
};
|
||||
@ -75,9 +85,8 @@ export class MetadataCollector {
|
||||
}
|
||||
|
||||
function classMetadataOf(classDeclaration: ts.ClassDeclaration): ClassMetadata {
|
||||
let result: ClassMetadata = {
|
||||
__symbolic: 'class'
|
||||
}
|
||||
let result: ClassMetadata =
|
||||
{ __symbolic: "class" }
|
||||
|
||||
function getDecorators(decorators: ts.Decorator[]):
|
||||
MetadataSymbolicExpression[] {
|
||||
@ -106,7 +115,7 @@ export class MetadataCollector {
|
||||
isConstructor = true;
|
||||
// fallthrough
|
||||
case ts.SyntaxKind.MethodDeclaration:
|
||||
const method = <ts.MethodDeclaration|ts.ConstructorDeclaration>member;
|
||||
const method = <ts.MethodDeclaration | ts.ConstructorDeclaration>member;
|
||||
const methodDecorators = getDecorators(method.decorators);
|
||||
const parameters = method.parameters;
|
||||
const parameterDecoratorData: MetadataSymbolicExpression[][] = [];
|
||||
@ -124,8 +133,8 @@ export class MetadataCollector {
|
||||
}
|
||||
}
|
||||
if (methodDecorators || hasDecoratorData || hasParameterData) {
|
||||
const data: MethodMetadata = {__symbolic: isConstructor ? 'constructor' : 'method'};
|
||||
const name = isConstructor ? '__ctor__' : evaluator.nameOf(member.name);
|
||||
const data: MethodMetadata = {__symbolic: isConstructor ? "constructor" : "method"};
|
||||
const name = isConstructor ? "__ctor__" : evaluator.nameOf(member.name);
|
||||
if (methodDecorators) {
|
||||
data.decorators = methodDecorators;
|
||||
}
|
||||
@ -144,9 +153,8 @@ export class MetadataCollector {
|
||||
const property = <ts.PropertyDeclaration>member;
|
||||
const propertyDecorators = getDecorators(property.decorators);
|
||||
if (propertyDecorators) {
|
||||
recordMember(
|
||||
evaluator.nameOf(property.name),
|
||||
{__symbolic: 'property', decorators: propertyDecorators});
|
||||
recordMember(evaluator.nameOf(property.name),
|
||||
{__symbolic: 'property', decorators: propertyDecorators});
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -188,6 +196,6 @@ export class MetadataCollector {
|
||||
}
|
||||
}
|
||||
}
|
||||
return metadata && {__symbolic: 'module', module: moduleNameOf(sourceFile.fileName), metadata};
|
||||
return metadata && {__symbolic: "module", module: moduleNameOf(sourceFile.fileName), metadata};
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,12 @@
|
||||
import * as ts from 'typescript';
|
||||
import {Symbols} from './symbols';
|
||||
|
||||
import {MetadataValue, MetadataObject, MetadataSymbolicCallExpression, MetadataSymbolicReferenceExpression} from './schema';
|
||||
import {
|
||||
MetadataValue,
|
||||
MetadataObject,
|
||||
MetadataSymbolicCallExpression,
|
||||
MetadataSymbolicReferenceExpression
|
||||
} from './schema';
|
||||
|
||||
// TOOD: Remove when tools directory is upgraded to support es6 target
|
||||
interface Map<K, V> {
|
||||
@ -58,9 +63,8 @@ function isDefined(obj: any): boolean {
|
||||
* possible.
|
||||
*/
|
||||
export class Evaluator {
|
||||
constructor(
|
||||
private typeChecker: ts.TypeChecker, private symbols: Symbols,
|
||||
private moduleNameOf: (fileName: string) => string) {}
|
||||
constructor(private typeChecker: ts.TypeChecker, private symbols: Symbols,
|
||||
private moduleNameOf: (fileName: string) => string) {}
|
||||
|
||||
// TODO: Determine if the first declaration is deterministic.
|
||||
private symbolFileName(symbol: ts.Symbol): string {
|
||||
@ -83,7 +87,7 @@ export class Evaluator {
|
||||
if (symbol) {
|
||||
const name = symbol.name;
|
||||
const module = this.moduleNameOf(this.symbolFileName(symbol));
|
||||
return {__symbolic: 'reference', name, module};
|
||||
return {__symbolic: "reference", name, module};
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,7 +138,7 @@ export class Evaluator {
|
||||
case ts.SyntaxKind.CallExpression:
|
||||
const callExpression = <ts.CallExpression>node;
|
||||
// We can fold a <array>.concat(<v>).
|
||||
if (isMethodCallOf(callExpression, 'concat') && callExpression.arguments.length === 1) {
|
||||
if (isMethodCallOf(callExpression, "concat") && callExpression.arguments.length === 1) {
|
||||
const arrayNode = (<ts.PropertyAccessExpression>callExpression.expression).expression;
|
||||
if (this.isFoldableWorker(arrayNode, folding) &&
|
||||
this.isFoldableWorker(callExpression.arguments[0], folding)) {
|
||||
@ -146,7 +150,7 @@ export class Evaluator {
|
||||
}
|
||||
}
|
||||
// We can fold a call to CONST_EXPR
|
||||
if (isCallOf(callExpression, 'CONST_EXPR') && callExpression.arguments.length === 1)
|
||||
if (isCallOf(callExpression, "CONST_EXPR") && callExpression.arguments.length === 1)
|
||||
return this.isFoldableWorker(callExpression.arguments[0], folding);
|
||||
return false;
|
||||
case ts.SyntaxKind.NoSubstitutionTemplateLiteral:
|
||||
@ -170,7 +174,7 @@ export class Evaluator {
|
||||
case ts.SyntaxKind.AmpersandAmpersandToken:
|
||||
case ts.SyntaxKind.BarBarToken:
|
||||
return this.isFoldableWorker(binaryExpression.left, folding) &&
|
||||
this.isFoldableWorker(binaryExpression.right, folding);
|
||||
this.isFoldableWorker(binaryExpression.right, folding);
|
||||
}
|
||||
case ts.SyntaxKind.PropertyAccessExpression:
|
||||
const propertyAccessExpression = <ts.PropertyAccessExpression>node;
|
||||
@ -178,7 +182,7 @@ export class Evaluator {
|
||||
case ts.SyntaxKind.ElementAccessExpression:
|
||||
const elementAccessExpression = <ts.ElementAccessExpression>node;
|
||||
return this.isFoldableWorker(elementAccessExpression.expression, folding) &&
|
||||
this.isFoldableWorker(elementAccessExpression.argumentExpression, folding);
|
||||
this.isFoldableWorker(elementAccessExpression.argumentExpression, folding);
|
||||
case ts.SyntaxKind.Identifier:
|
||||
let symbol = this.typeChecker.getSymbolAtLocation(node);
|
||||
if (symbol.flags & ts.SymbolFlags.Alias) {
|
||||
@ -241,20 +245,20 @@ export class Evaluator {
|
||||
const callExpression = <ts.CallExpression>node;
|
||||
const args = callExpression.arguments.map(arg => this.evaluateNode(arg));
|
||||
if (this.isFoldable(callExpression)) {
|
||||
if (isMethodCallOf(callExpression, 'concat')) {
|
||||
if (isMethodCallOf(callExpression, "concat")) {
|
||||
const arrayValue = <MetadataValue[]>this.evaluateNode(
|
||||
(<ts.PropertyAccessExpression>callExpression.expression).expression);
|
||||
return arrayValue.concat(args[0]);
|
||||
}
|
||||
}
|
||||
// Always fold a CONST_EXPR even if the argument is not foldable.
|
||||
if (isCallOf(callExpression, 'CONST_EXPR') && callExpression.arguments.length === 1) {
|
||||
if (isCallOf(callExpression, "CONST_EXPR") && callExpression.arguments.length === 1) {
|
||||
return args[0];
|
||||
}
|
||||
const expression = this.evaluateNode(callExpression.expression);
|
||||
if (isDefined(expression) && args.every(isDefined)) {
|
||||
const result: MetadataSymbolicCallExpression = {
|
||||
__symbolic: 'call',
|
||||
__symbolic: "call",
|
||||
expression: this.evaluateNode(callExpression.expression)
|
||||
};
|
||||
if (args && args.length) {
|
||||
@ -269,7 +273,7 @@ export class Evaluator {
|
||||
const member = this.nameOf(propertyAccessExpression.name);
|
||||
if (this.isFoldable(propertyAccessExpression.expression)) return expression[member];
|
||||
if (isDefined(expression)) {
|
||||
return {__symbolic: 'select', expression, member};
|
||||
return {__symbolic: "select", expression, member};
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -279,9 +283,9 @@ export class Evaluator {
|
||||
const index = this.evaluateNode(elementAccessExpression.argumentExpression);
|
||||
if (this.isFoldable(elementAccessExpression.expression) &&
|
||||
this.isFoldable(elementAccessExpression.argumentExpression))
|
||||
return expression[<string|number>index];
|
||||
return expression[<string | number>index];
|
||||
if (isDefined(expression) && isDefined(index)) {
|
||||
return {__symbolic: 'index', expression, index};
|
||||
return {__symbolic: "index", expression, index};
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -348,7 +352,7 @@ export class Evaluator {
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
return {__symbolic: 'pre', operator: operatorText, operand: operand};
|
||||
return {__symbolic: "pre", operator: operatorText, operand: operand };
|
||||
case ts.SyntaxKind.BinaryExpression:
|
||||
const binaryExpression = <ts.BinaryExpression>node;
|
||||
const left = this.evaluateNode(binaryExpression.left);
|
||||
@ -400,7 +404,7 @@ export class Evaluator {
|
||||
return <any>left % <any>right;
|
||||
}
|
||||
return {
|
||||
__symbolic: 'binop',
|
||||
__symbolic: "binop",
|
||||
operator: binaryExpression.operatorToken.getText(),
|
||||
left: left,
|
||||
right: right
|
||||
|
@ -6,7 +6,7 @@ export interface ModuleMetadata {
|
||||
metadata: {[name: string]: (ClassMetadata | MetadataValue)};
|
||||
}
|
||||
export function isModuleMetadata(value: any): value is ModuleMetadata {
|
||||
return value && value.__symbolic === 'module';
|
||||
return value && value.__symbolic === "module";
|
||||
}
|
||||
|
||||
export interface ClassMetadata {
|
||||
@ -15,7 +15,7 @@ export interface ClassMetadata {
|
||||
members?: MetadataMap;
|
||||
}
|
||||
export function isClassMetadata(value: any): value is ClassMetadata {
|
||||
return value && value.__symbolic === 'class';
|
||||
return value && value.__symbolic === "class";
|
||||
}
|
||||
|
||||
export interface MetadataMap { [name: string]: MemberMetadata[]; }
|
||||
@ -27,9 +27,9 @@ export interface MemberMetadata {
|
||||
export function isMemberMetadata(value: any): value is MemberMetadata {
|
||||
if (value) {
|
||||
switch (value.__symbolic) {
|
||||
case 'constructor':
|
||||
case 'method':
|
||||
case 'property':
|
||||
case "constructor":
|
||||
case "method":
|
||||
case "property":
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -41,7 +41,7 @@ export interface MethodMetadata extends MemberMetadata {
|
||||
parameterDecorators?: MetadataSymbolicExpression[][];
|
||||
}
|
||||
export function isMethodMetadata(value: any): value is MemberMetadata {
|
||||
return value && (value.__symbolic === 'constructor' || value.__symbolic === 'method');
|
||||
return value && (value.__symbolic === "constructor" || value.__symbolic === "method");
|
||||
}
|
||||
|
||||
export interface ConstructorMetadata extends MethodMetadata {
|
||||
@ -49,7 +49,7 @@ export interface ConstructorMetadata extends MethodMetadata {
|
||||
parameters?: MetadataSymbolicExpression[];
|
||||
}
|
||||
export function isConstructorMetadata(value: any): value is ConstructorMetadata {
|
||||
return value && value.__symbolic === 'constructor';
|
||||
return value && value.__symbolic === "constructor";
|
||||
}
|
||||
|
||||
export type MetadataValue =
|
||||
@ -65,12 +65,12 @@ export interface MetadataSymbolicExpression {
|
||||
export function isMetadataSymbolicExpression(value: any): value is MetadataSymbolicExpression {
|
||||
if (value) {
|
||||
switch (value.__symbolic) {
|
||||
case 'binary':
|
||||
case 'call':
|
||||
case 'index':
|
||||
case 'pre':
|
||||
case 'reference':
|
||||
case 'select':
|
||||
case "binary":
|
||||
case "call":
|
||||
case "index":
|
||||
case "pre":
|
||||
case "reference":
|
||||
case "select":
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -85,9 +85,9 @@ export interface MetadataSymbolicBinaryExpression extends MetadataSymbolicExpres
|
||||
left: MetadataValue;
|
||||
right: MetadataValue;
|
||||
}
|
||||
export function isMetadataSymbolicBinaryExpression(value: any):
|
||||
value is MetadataSymbolicBinaryExpression {
|
||||
return value && value.__symbolic === 'binary';
|
||||
export function isMetadataSymbolicBinaryExpression(
|
||||
value: any): value is MetadataSymbolicBinaryExpression {
|
||||
return value && value.__symbolic === "binary";
|
||||
}
|
||||
|
||||
export interface MetadataSymbolicIndexExpression extends MetadataSymbolicExpression {
|
||||
@ -95,9 +95,9 @@ export interface MetadataSymbolicIndexExpression extends MetadataSymbolicExpress
|
||||
expression: MetadataValue;
|
||||
index: MetadataValue;
|
||||
}
|
||||
export function isMetadataSymbolicIndexExpression(value: any):
|
||||
value is MetadataSymbolicIndexExpression {
|
||||
return value && value.__symbolic === 'index';
|
||||
export function isMetadataSymbolicIndexExpression(
|
||||
value: any): value is MetadataSymbolicIndexExpression {
|
||||
return value && value.__symbolic === "index";
|
||||
}
|
||||
|
||||
export interface MetadataSymbolicCallExpression extends MetadataSymbolicExpression {
|
||||
@ -105,9 +105,9 @@ export interface MetadataSymbolicCallExpression extends MetadataSymbolicExpressi
|
||||
expression: MetadataValue;
|
||||
arguments?: MetadataValue[];
|
||||
}
|
||||
export function isMetadataSymbolicCallExpression(value: any):
|
||||
value is MetadataSymbolicCallExpression {
|
||||
return value && value.__symbolic === 'call';
|
||||
export function isMetadataSymbolicCallExpression(
|
||||
value: any): value is MetadataSymbolicCallExpression {
|
||||
return value && value.__symbolic === "call";
|
||||
}
|
||||
|
||||
export interface MetadataSymbolicPrefixExpression extends MetadataSymbolicExpression {
|
||||
@ -115,9 +115,9 @@ export interface MetadataSymbolicPrefixExpression extends MetadataSymbolicExpres
|
||||
operator: string; // "+" | "-" | "~" | "!";
|
||||
operand: MetadataValue;
|
||||
}
|
||||
export function isMetadataSymbolicPrefixExpression(value: any):
|
||||
value is MetadataSymbolicPrefixExpression {
|
||||
return value && value.__symbolic === 'pre';
|
||||
export function isMetadataSymbolicPrefixExpression(
|
||||
value: any): value is MetadataSymbolicPrefixExpression {
|
||||
return value && value.__symbolic === "pre";
|
||||
}
|
||||
|
||||
export interface MetadataSymbolicReferenceExpression extends MetadataSymbolicExpression {
|
||||
@ -125,9 +125,9 @@ export interface MetadataSymbolicReferenceExpression extends MetadataSymbolicExp
|
||||
name: string;
|
||||
module: string;
|
||||
}
|
||||
export function isMetadataSymbolicReferenceExpression(value: any):
|
||||
value is MetadataSymbolicReferenceExpression {
|
||||
return value && value.__symbolic === 'reference';
|
||||
export function isMetadataSymbolicReferenceExpression(
|
||||
value: any): value is MetadataSymbolicReferenceExpression {
|
||||
return value && value.__symbolic === "reference";
|
||||
}
|
||||
|
||||
export interface MetadataSymbolicSelectExpression extends MetadataSymbolicExpression {
|
||||
@ -135,7 +135,7 @@ export interface MetadataSymbolicSelectExpression extends MetadataSymbolicExpres
|
||||
expression: MetadataValue;
|
||||
name: string;
|
||||
}
|
||||
export function isMetadataSymbolicSelectExpression(value: any):
|
||||
value is MetadataSymbolicSelectExpression {
|
||||
return value && value.__symbolic === 'select';
|
||||
export function isMetadataSymbolicSelectExpression(
|
||||
value: any): value is MetadataSymbolicSelectExpression {
|
||||
return value && value.__symbolic === "select";
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ describe('Collector', () => {
|
||||
expect(metadata).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should be able to collect a simple component\'s metadata', () => {
|
||||
it("should be able to collect a simple component's metadata", () => {
|
||||
const sourceFile = program.getSourceFile('app/hero-detail.component.ts');
|
||||
const metadata = collector.getMetadata(sourceFile, typeChecker);
|
||||
expect(metadata).toEqual({
|
||||
@ -38,12 +38,14 @@ describe('Collector', () => {
|
||||
metadata: {
|
||||
HeroDetailComponent: {
|
||||
__symbolic: 'class',
|
||||
decorators: [{
|
||||
__symbolic: 'call',
|
||||
expression: {__symbolic: 'reference', name: 'Component', module: 'angular2/core'},
|
||||
arguments: [{
|
||||
selector: 'my-hero-detail',
|
||||
template: `
|
||||
decorators: [
|
||||
{
|
||||
__symbolic: 'call',
|
||||
expression: {__symbolic: 'reference', name: 'Component', module: 'angular2/core'},
|
||||
arguments: [
|
||||
{
|
||||
selector: 'my-hero-detail',
|
||||
template: `
|
||||
<div *ngIf="hero">
|
||||
<h2>{{hero.name}} details!</h2>
|
||||
<div><label>id: </label>{{hero.id}}</div>
|
||||
@ -53,24 +55,30 @@ describe('Collector', () => {
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
}]
|
||||
}],
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
members: {
|
||||
hero: [{
|
||||
__symbolic: 'property',
|
||||
decorators: [{
|
||||
__symbolic: 'call',
|
||||
expression:
|
||||
{__symbolic: 'reference', name: 'Input', module: 'angular2/core'}
|
||||
}]
|
||||
}]
|
||||
hero: [
|
||||
{
|
||||
__symbolic: 'property',
|
||||
decorators: [
|
||||
{
|
||||
__symbolic: 'call',
|
||||
expression:
|
||||
{__symbolic: 'reference', name: 'Input', module: 'angular2/core'}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to get a more complicated component\'s metadata', () => {
|
||||
it("should be able to get a more complicated component's metadata", () => {
|
||||
const sourceFile = program.getSourceFile('/app/app.component.ts');
|
||||
const metadata = collector.getMetadata(sourceFile, typeChecker);
|
||||
expect(metadata).toEqual({
|
||||
@ -79,12 +87,14 @@ describe('Collector', () => {
|
||||
metadata: {
|
||||
AppComponent: {
|
||||
__symbolic: 'class',
|
||||
decorators: [{
|
||||
__symbolic: 'call',
|
||||
expression: {__symbolic: 'reference', name: 'Component', module: 'angular2/core'},
|
||||
arguments: [{
|
||||
selector: 'my-app',
|
||||
template: `
|
||||
decorators: [
|
||||
{
|
||||
__symbolic: 'call',
|
||||
expression: {__symbolic: 'reference', name: 'Component', module: 'angular2/core'},
|
||||
arguments: [
|
||||
{
|
||||
selector: 'my-app',
|
||||
template: `
|
||||
<h2>My Heroes</h2>
|
||||
<ul class="heroes">
|
||||
<li *ngFor="#hero of heroes"
|
||||
@ -95,27 +105,37 @@ describe('Collector', () => {
|
||||
</ul>
|
||||
<my-hero-detail [hero]="selectedHero"></my-hero-detail>
|
||||
`,
|
||||
directives: [
|
||||
{
|
||||
__symbolic: 'reference',
|
||||
name: 'HeroDetailComponent',
|
||||
module: './hero-detail.component'
|
||||
},
|
||||
{__symbolic: 'reference', name: 'NgFor', module: 'angular2/common'}
|
||||
],
|
||||
providers: [{__symbolic: 'reference', name: 'HeroService', module: './hero.service'}],
|
||||
pipes: [
|
||||
{__symbolic: 'reference', name: 'LowerCasePipe', module: 'angular2/common'},
|
||||
{__symbolic: 'reference', name: 'UpperCasePipe', module: 'angular2/common'}
|
||||
directives: [
|
||||
{
|
||||
__symbolic: 'reference',
|
||||
name: 'HeroDetailComponent',
|
||||
module: './hero-detail.component'
|
||||
},
|
||||
{__symbolic: 'reference', name: 'NgFor', module: 'angular2/common'}
|
||||
],
|
||||
providers:
|
||||
[{__symbolic: 'reference', name: 'HeroService', module: './hero.service'}],
|
||||
pipes: [
|
||||
{__symbolic: 'reference', name: 'LowerCasePipe', module: 'angular2/common'},
|
||||
{
|
||||
__symbolic: 'reference',
|
||||
name: 'UpperCasePipe',
|
||||
module: 'angular2/common'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}]
|
||||
}],
|
||||
}
|
||||
],
|
||||
members: {
|
||||
__ctor__: [{
|
||||
__symbolic: 'constructor',
|
||||
parameters:
|
||||
[{__symbolic: 'reference', module: './hero.service', name: 'HeroService'}]
|
||||
}]
|
||||
__ctor__: [
|
||||
{
|
||||
__symbolic: 'constructor',
|
||||
parameters: [
|
||||
{__symbolic: 'reference', module: './hero.service', name: 'HeroService'}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -130,11 +150,16 @@ describe('Collector', () => {
|
||||
module: './mock-heroes',
|
||||
metadata: {
|
||||
HEROES: [
|
||||
{'id': 11, 'name': 'Mr. Nice'}, {'id': 12, 'name': 'Narco'},
|
||||
{'id': 13, 'name': 'Bombasto'}, {'id': 14, 'name': 'Celeritas'},
|
||||
{'id': 15, 'name': 'Magneta'}, {'id': 16, 'name': 'RubberMan'},
|
||||
{'id': 17, 'name': 'Dynama'}, {'id': 18, 'name': 'Dr IQ'}, {'id': 19, 'name': 'Magma'},
|
||||
{'id': 20, 'name': 'Tornado'}
|
||||
{"id": 11, "name": "Mr. Nice"},
|
||||
{"id": 12, "name": "Narco"},
|
||||
{"id": 13, "name": "Bombasto"},
|
||||
{"id": 14, "name": "Celeritas"},
|
||||
{"id": 15, "name": "Magneta"},
|
||||
{"id": 16, "name": "RubberMan"},
|
||||
{"id": 17, "name": "Dynama"},
|
||||
{"id": 18, "name": "Dr IQ"},
|
||||
{"id": 19, "name": "Magma"},
|
||||
{"id": 20, "name": "Tornado"}
|
||||
]
|
||||
}
|
||||
});
|
||||
@ -164,14 +189,18 @@ describe('Collector', () => {
|
||||
|
||||
it('should record annotations on set and get declartions', () => {
|
||||
const propertyData = {
|
||||
name: [{
|
||||
__symbolic: 'property',
|
||||
decorators: [{
|
||||
__symbolic: 'call',
|
||||
expression: {__symbolic: 'reference', module: 'angular2/core', name: 'Input'},
|
||||
arguments: ['firstName']
|
||||
}]
|
||||
}]
|
||||
name: [
|
||||
{
|
||||
__symbolic: 'property',
|
||||
decorators: [
|
||||
{
|
||||
__symbolic: 'call',
|
||||
expression: {__symbolic: 'reference', module: 'angular2/core', name: 'Input'},
|
||||
arguments: ['firstName']
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
const caseGetProp = <ClassMetadata>casesMetadata.metadata['GetProp'];
|
||||
expect(caseGetProp.members).toEqual(propertyData);
|
||||
@ -194,8 +223,7 @@ const FILES: Directory = {
|
||||
|
||||
@Component({
|
||||
selector: 'my-app',
|
||||
template:` +
|
||||
'`' + `
|
||||
template:` + "`" + `
|
||||
<h2>My Heroes</h2>
|
||||
<ul class="heroes">
|
||||
<li *ngFor="#hero of heroes"
|
||||
@ -206,7 +234,7 @@ const FILES: Directory = {
|
||||
</ul>
|
||||
<my-hero-detail [hero]="selectedHero"></my-hero-detail>
|
||||
` +
|
||||
'`' + `,
|
||||
"`" + `,
|
||||
directives: [HeroDetailComponent, NgFor],
|
||||
providers: [HeroService],
|
||||
pipes: [LowerCasePipe, UpperCasePipe]
|
||||
@ -239,8 +267,7 @@ const FILES: Directory = {
|
||||
|
||||
@Component({
|
||||
selector: 'my-hero-detail',
|
||||
template: ` +
|
||||
'`' + `
|
||||
template: ` + "`" + `
|
||||
<div *ngIf="hero">
|
||||
<h2>{{hero.name}} details!</h2>
|
||||
<div><label>id: </label>{{hero.id}}</div>
|
||||
@ -249,8 +276,7 @@ const FILES: Directory = {
|
||||
<input [(ngModel)]="hero.name" placeholder="name"/>
|
||||
</div>
|
||||
</div>
|
||||
` +
|
||||
'`' + `,
|
||||
` + "`" + `,
|
||||
})
|
||||
export class HeroDetailComponent {
|
||||
@Input() public hero: Hero;
|
||||
|
@ -73,13 +73,13 @@ describe('Evaluator', () => {
|
||||
expect(evaluator.evaluateNode(findVar(expressions, 'bBAnd').initializer)).toEqual(0x11 & 0x03);
|
||||
expect(evaluator.evaluateNode(findVar(expressions, 'bXor').initializer)).toEqual(0x11 ^ 0x21);
|
||||
expect(evaluator.evaluateNode(findVar(expressions, 'bEqual').initializer))
|
||||
.toEqual(1 == <any>'1');
|
||||
.toEqual(1 == <any>"1");
|
||||
expect(evaluator.evaluateNode(findVar(expressions, 'bNotEqual').initializer))
|
||||
.toEqual(1 != <any>'1');
|
||||
.toEqual(1 != <any>"1");
|
||||
expect(evaluator.evaluateNode(findVar(expressions, 'bIdentical').initializer))
|
||||
.toEqual(1 === <any>'1');
|
||||
.toEqual(1 === <any>"1");
|
||||
expect(evaluator.evaluateNode(findVar(expressions, 'bNotIdentical').initializer))
|
||||
.toEqual(1 !== <any>'1');
|
||||
.toEqual(1 !== <any>"1");
|
||||
expect(evaluator.evaluateNode(findVar(expressions, 'bLessThan').initializer)).toEqual(1 < 2);
|
||||
expect(evaluator.evaluateNode(findVar(expressions, 'bGreaterThan').initializer)).toEqual(1 > 2);
|
||||
expect(evaluator.evaluateNode(findVar(expressions, 'bLessThanEqual').initializer))
|
||||
@ -97,9 +97,9 @@ describe('Evaluator', () => {
|
||||
it('should report recursive references as symbolic', () => {
|
||||
var expressions = program.getSourceFile('expressions.ts');
|
||||
expect(evaluator.evaluateNode(findVar(expressions, 'recursiveA').initializer))
|
||||
.toEqual({__symbolic: 'reference', name: 'recursiveB', module: 'expressions.ts'});
|
||||
.toEqual({__symbolic: "reference", name: "recursiveB", module: "expressions.ts"});
|
||||
expect(evaluator.evaluateNode(findVar(expressions, 'recursiveB').initializer))
|
||||
.toEqual({__symbolic: 'reference', name: 'recursiveA', module: 'expressions.ts'});
|
||||
.toEqual({__symbolic: "reference", name: "recursiveA", module: "expressions.ts"});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -2,7 +2,7 @@ import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
export interface Directory { [name: string]: (Directory|string); }
|
||||
export interface Directory { [name: string]: (Directory | string); }
|
||||
|
||||
export class Host implements ts.LanguageServiceHost {
|
||||
constructor(private directory: Directory, private scripts: string[]) {}
|
||||
@ -17,7 +17,7 @@ export class Host implements ts.LanguageServiceHost {
|
||||
|
||||
getScriptFileNames(): string[] { return this.scripts; }
|
||||
|
||||
getScriptVersion(fileName: string): string { return '1'; }
|
||||
getScriptVersion(fileName: string): string { return "1"; }
|
||||
|
||||
getScriptSnapshot(fileName: string): ts.IScriptSnapshot {
|
||||
let content = this.getFileContent(fileName);
|
||||
@ -33,7 +33,7 @@ export class Host implements ts.LanguageServiceHost {
|
||||
if (names[names.length - 1] === 'lib.d.ts') {
|
||||
return fs.readFileSync(ts.getDefaultLibFilePath(this.getCompilationSettings()), 'utf8');
|
||||
}
|
||||
let current: Directory|string = this.directory;
|
||||
let current: Directory | string = this.directory;
|
||||
if (names.length && names[0] === '') names.shift();
|
||||
for (const name of names) {
|
||||
if (!current || typeof current === 'string') return undefined;
|
||||
@ -44,9 +44,8 @@ export class Host implements ts.LanguageServiceHost {
|
||||
}
|
||||
|
||||
export class MockNode implements ts.Node {
|
||||
constructor(
|
||||
public kind: ts.SyntaxKind = ts.SyntaxKind.Identifier, public flags: ts.NodeFlags = 0,
|
||||
public pos: number = 0, public end: number = 0) {}
|
||||
constructor(public kind: ts.SyntaxKind = ts.SyntaxKind.Identifier, public flags: ts.NodeFlags = 0,
|
||||
public pos: number = 0, public end: number = 0) {}
|
||||
getSourceFile(): ts.SourceFile { return null; }
|
||||
getChildCount(sourceFile?: ts.SourceFile): number { return 0 }
|
||||
getChildAt(index: number, sourceFile?: ts.SourceFile): ts.Node { return null; }
|
||||
@ -72,9 +71,8 @@ export class MockIdentifier extends MockNode implements ts.Identifier {
|
||||
public _unaryExpressionBrand: any;
|
||||
public _expressionBrand: any;
|
||||
|
||||
constructor(
|
||||
public name: string, kind: ts.SyntaxKind = ts.SyntaxKind.Identifier, flags: ts.NodeFlags = 0,
|
||||
pos: number = 0, end: number = 0) {
|
||||
constructor(public name: string, kind: ts.SyntaxKind = ts.SyntaxKind.Identifier,
|
||||
flags: ts.NodeFlags = 0, pos: number = 0, end: number = 0) {
|
||||
super(kind, flags, pos, end);
|
||||
this.text = name;
|
||||
}
|
||||
@ -83,33 +81,31 @@ export class MockIdentifier extends MockNode implements ts.Identifier {
|
||||
export class MockVariableDeclaration extends MockNode implements ts.VariableDeclaration {
|
||||
public _declarationBrand: any;
|
||||
|
||||
constructor(
|
||||
public name: ts.Identifier, kind: ts.SyntaxKind = ts.SyntaxKind.VariableDeclaration,
|
||||
flags: ts.NodeFlags = 0, pos: number = 0, end: number = 0) {
|
||||
constructor(public name: ts.Identifier, kind: ts.SyntaxKind = ts.SyntaxKind.VariableDeclaration,
|
||||
flags: ts.NodeFlags = 0, pos: number = 0, end: number = 0) {
|
||||
super(kind, flags, pos, end);
|
||||
}
|
||||
|
||||
static of (name: string): MockVariableDeclaration {
|
||||
static of(name: string): MockVariableDeclaration {
|
||||
return new MockVariableDeclaration(new MockIdentifier(name));
|
||||
}
|
||||
}
|
||||
|
||||
export class MockSymbol implements ts.Symbol {
|
||||
constructor(
|
||||
public name: string, private node: ts.Declaration = MockVariableDeclaration.of(name),
|
||||
public flags: ts.SymbolFlags = 0) {}
|
||||
constructor(public name: string, private node: ts.Declaration = MockVariableDeclaration.of(name),
|
||||
public flags: ts.SymbolFlags = 0) {}
|
||||
|
||||
getFlags(): ts.SymbolFlags { return this.flags; }
|
||||
getName(): string { return this.name; }
|
||||
getDeclarations(): ts.Declaration[] { return [this.node]; }
|
||||
getDocumentationComment(): ts.SymbolDisplayPart[] { return []; }
|
||||
|
||||
static of (name: string): MockSymbol { return new MockSymbol(name); }
|
||||
static of(name: string): MockSymbol { return new MockSymbol(name); }
|
||||
}
|
||||
|
||||
export function expectNoDiagnostics(diagnostics: ts.Diagnostic[]) {
|
||||
for (const diagnostic of diagnostics) {
|
||||
let message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
|
||||
let message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
||||
let {line, character} = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
||||
console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
|
||||
}
|
||||
@ -135,13 +131,13 @@ export function allChildren<T>(node: ts.Node, cb: (node: ts.Node) => T) {
|
||||
}
|
||||
|
||||
export function findClass(sourceFile: ts.SourceFile, name: string): ts.ClassDeclaration {
|
||||
return ts.forEachChild(
|
||||
sourceFile, node => isClass(node) && isNamed(node.name, name) ? node : undefined);
|
||||
return ts.forEachChild(sourceFile,
|
||||
node => isClass(node) && isNamed(node.name, name) ? node : undefined);
|
||||
}
|
||||
|
||||
export function findVar(sourceFile: ts.SourceFile, name: string): ts.VariableDeclaration {
|
||||
return allChildren(
|
||||
sourceFile, node => isVar(node) && isNamed(node.name, name) ? node : undefined);
|
||||
return allChildren(sourceFile,
|
||||
node => isVar(node) && isNamed(node.name, name) ? node : undefined);
|
||||
}
|
||||
|
||||
export function isClass(node: ts.Node): node is ts.ClassDeclaration {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -24,7 +24,7 @@ class TypedefWalker extends RuleWalker {
|
||||
private hasInternalAnnotation(range: ts.CommentRange): boolean {
|
||||
let text = this.getSourceFile().text;
|
||||
let comment = text.substring(range.pos, range.end);
|
||||
return comment.indexOf('@internal') >= 0;
|
||||
return comment.indexOf("@internal") >= 0;
|
||||
}
|
||||
|
||||
private assertInternalAnnotationPresent(node: ts.Declaration) {
|
||||
|
@ -4,7 +4,7 @@ import {RuleWalker} from 'tslint/lib/language/walker';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
export class Rule extends AbstractRule {
|
||||
public static FAILURE_STRING = 'missing type declaration';
|
||||
public static FAILURE_STRING = "missing type declaration";
|
||||
|
||||
public apply(sourceFile: ts.SourceFile): RuleFailure[] {
|
||||
const typedefWalker = new TypedefWalker(sourceFile, this.getOptions());
|
||||
@ -28,12 +28,12 @@ class TypedefWalker extends RuleWalker {
|
||||
|
||||
private checkTypeAnnotation(location: number, typeAnnotation: ts.TypeNode, name?: ts.Node) {
|
||||
if (typeAnnotation == null) {
|
||||
let ns = '<name missing>';
|
||||
let ns = "<name missing>";
|
||||
if (name != null && name.kind === ts.SyntaxKind.Identifier) {
|
||||
ns = (<ts.Identifier>name).text;
|
||||
}
|
||||
if (ns.charAt(0) === '_') return;
|
||||
let failure = this.createFailure(location, 1, 'expected parameter ' + ns + ' to have a type');
|
||||
let failure = this.createFailure(location, 1, "expected parameter " + ns + " to have a type");
|
||||
this.addFailure(failure);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import {RuleWalker} from 'tslint/lib/language/walker';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
export class Rule extends AbstractRule {
|
||||
public static FAILURE_STRING = 'missing type declaration';
|
||||
public static FAILURE_STRING = "missing type declaration";
|
||||
|
||||
public apply(sourceFile: ts.SourceFile): RuleFailure[] {
|
||||
const typedefWalker = new TypedefWalker(sourceFile, this.getOptions());
|
||||
@ -50,12 +50,12 @@ class TypedefWalker extends RuleWalker {
|
||||
|
||||
private checkTypeAnnotation(typeAnnotation: ts.TypeNode, name: ts.Node, start: number) {
|
||||
if (typeAnnotation == null) {
|
||||
let ns = '<name missing>';
|
||||
let ns = "<name missing>";
|
||||
if (name != null && name.kind === ts.SyntaxKind.Identifier) {
|
||||
ns = (<ts.Identifier>name).text;
|
||||
}
|
||||
if (ns.charAt(0) === '_') return;
|
||||
let failure = this.createFailure(start, 1, 'expected ' + ns + ' to have a return type');
|
||||
let failure = this.createFailure(start, 1, "expected " + ns + " to have a return type");
|
||||
this.addFailure(failure);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user