refactor(): use const and let instead of var

This commit is contained in:
Joao Dias
2016-11-12 14:08:58 +01:00
committed by Victor Berchet
parent 73593d4bf3
commit 77ee27c59e
435 changed files with 4637 additions and 4663 deletions

View File

@ -74,7 +74,7 @@ export class MetadataCollector {
}
function classMetadataOf(classDeclaration: ts.ClassDeclaration): ClassMetadata {
let result: ClassMetadata = {__symbolic: 'class'};
const result: ClassMetadata = {__symbolic: 'class'};
function getDecorators(decorators: ts.Decorator[]): MetadataSymbolicExpression[] {
if (decorators && decorators.length)
@ -102,7 +102,7 @@ export class MetadataCollector {
let members: MetadataMap = null;
function recordMember(name: string, metadata: MemberMetadata) {
if (!members) members = {};
let data = members.hasOwnProperty(name) ? members[name] : [];
const data = members.hasOwnProperty(name) ? members[name] : [];
data.push(metadata);
members[name] = data;
}
@ -279,7 +279,7 @@ export class MetadataCollector {
case ts.SyntaxKind.EnumDeclaration:
if (node.flags & ts.NodeFlags.Export) {
const enumDeclaration = <ts.EnumDeclaration>node;
let enumValueHolder: {[name: string]: MetadataValue} = {};
const enumValueHolder: {[name: string]: MetadataValue} = {};
const enumName = enumDeclaration.name.text;
let nextDefaultValue: MetadataValue = 0;
let writtenMembers = 0;
@ -321,9 +321,9 @@ export class MetadataCollector {
break;
case ts.SyntaxKind.VariableStatement:
const variableStatement = <ts.VariableStatement>node;
for (let variableDeclaration of variableStatement.declarationList.declarations) {
for (const variableDeclaration of variableStatement.declarationList.declarations) {
if (variableDeclaration.name.kind == ts.SyntaxKind.Identifier) {
let nameNode = <ts.Identifier>variableDeclaration.name;
const nameNode = <ts.Identifier>variableDeclaration.name;
let varValue: MetadataValue;
if (variableDeclaration.initializer) {
varValue = evaluator.evaluateNode(variableDeclaration.initializer);
@ -530,7 +530,7 @@ function validateMetadata(
const node = nodeMap.get(entry);
if (shouldReportNode(node)) {
if (node) {
let {line, character} = sourceFile.getLineAndCharacterOfPosition(node.getStart());
const {line, character} = sourceFile.getLineAndCharacterOfPosition(node.getStart());
throw new Error(
`${sourceFile.fileName}:${line + 1}:${character + 1}: Error encountered in metadata generated for exported symbol '${name}': \n ${e.message}`);
}
@ -543,7 +543,7 @@ function validateMetadata(
// Collect parameter names from a function.
function namesOf(parameters: ts.NodeArray<ts.ParameterDeclaration>): string[] {
let result: string[] = [];
const result: string[] = [];
function addNamesOf(name: ts.Identifier | ts.BindingPattern) {
if (name.kind == ts.SyntaxKind.Identifier) {
@ -551,13 +551,13 @@ function namesOf(parameters: ts.NodeArray<ts.ParameterDeclaration>): string[] {
result.push(identifier.text);
} else {
const bindingPattern = <ts.BindingPattern>name;
for (let element of bindingPattern.elements) {
for (const element of bindingPattern.elements) {
addNamesOf(element.name);
}
}
}
for (let parameter of parameters) {
for (const parameter of parameters) {
addNamesOf(parameter.name);
}

View File

@ -78,7 +78,7 @@ export function errorSymbol(
if (node) {
sourceFile = sourceFile || getSourceFileOfNode(node);
if (sourceFile) {
let {line, character} =
const {line, character} =
ts.getLineAndCharacterOfPosition(sourceFile, node.getStart(sourceFile));
result = {__symbolic: 'error', message, line, character};
};
@ -260,7 +260,7 @@ export class Evaluator {
// Handle spread expressions
if (isMetadataSymbolicSpreadExpression(value)) {
if (Array.isArray(value.expression)) {
for (let spreadValue of value.expression) {
for (const spreadValue of value.expression) {
arr.push(spreadValue);
}
return;
@ -389,7 +389,7 @@ export class Evaluator {
return {__symbolic: 'select', expression: left, member: qualifiedName.right.text};
} else {
const identifier = <ts.Identifier>typeNameNode;
let symbol = this.symbols.resolve(identifier.text);
const symbol = this.symbols.resolve(identifier.text);
if (isMetadataError(symbol) || isMetadataSymbolicReferenceExpression(symbol)) {
return recordEntry(symbol, node);
}

View File

@ -32,7 +32,7 @@ export class Symbols {
}
private buildImports(): void {
let symbols = this._symbols;
const symbols = this._symbols;
// Collect the imported symbols into this.symbols
const stripQuotes = (s: string) => s.replace(/^['"]|['"]$/g, '');
const visit = (node: ts.Node) => {
@ -84,7 +84,7 @@ export class Symbols {
switch (bindings.kind) {
case ts.SyntaxKind.NamedImports:
// An `import { [<identifier> [, <identifier>] } from <module-specifier>` clause
for (let binding of (<ts.NamedImports>bindings).elements) {
for (const binding of (<ts.NamedImports>bindings).elements) {
symbols.set(binding.name.text, {
__symbolic: 'reference',
module: from,

View File

@ -80,7 +80,7 @@ export class Tsc implements CompilerInterface {
// The issue is that old typescript only has `readDirectory` while
// the newer TypeScript has additional `useCaseSensitiveFileNames` and
// `fileExists`. Inlining will trigger an error of extra parameters.
let host = {
const host = {
useCaseSensitiveFileNames: true,
fileExists: existsSync,
readDirectory: this.readDirectory
@ -103,10 +103,10 @@ export class Tsc implements CompilerInterface {
debug('Checking global diagnostics...');
check(program.getGlobalDiagnostics());
let diagnostics: ts.Diagnostic[] = [];
const diagnostics: ts.Diagnostic[] = [];
debug('Type checking...');
for (let sf of program.getSourceFiles()) {
for (const sf of program.getSourceFiles()) {
diagnostics.push(...ts.getPreEmitDiagnostics(program, sf));
}
check(diagnostics);
@ -117,7 +117,7 @@ export class Tsc implements CompilerInterface {
const program = ts.createProgram(this.parsed.fileNames, this.parsed.options, compilerHost);
debug('Emitting outputs...');
const emitResult = program.emit();
let diagnostics: ts.Diagnostic[] = [];
const diagnostics: ts.Diagnostic[] = [];
diagnostics.push(...emitResult.diagnostics);
check(compilerHost.diagnostics);

View File

@ -14,7 +14,7 @@ import {ClassMetadata, ConstructorMetadata, ModuleMetadata} from '../src/schema'
import {Directory, Host, expectValidSources} from './typescript.mocks';
describe('Collector', () => {
let documentRegistry = ts.createDocumentRegistry();
const documentRegistry = ts.createDocumentRegistry();
let host: Host;
let service: ts.LanguageService;
let program: ts.Program;
@ -234,8 +234,8 @@ describe('Collector', () => {
});
it('should report errors for destructured imports', () => {
let unsupported1 = program.getSourceFile('/unsupported-1.ts');
let metadata = collector.getMetadata(unsupported1);
const unsupported1 = program.getSourceFile('/unsupported-1.ts');
const metadata = collector.getMetadata(unsupported1);
expect(metadata).toEqual({
__symbolic: 'module',
version: 1,
@ -250,11 +250,11 @@ describe('Collector', () => {
});
it('should report an error for references to unexpected types', () => {
let unsupported1 = program.getSourceFile('/unsupported-2.ts');
let metadata = collector.getMetadata(unsupported1);
let barClass = <ClassMetadata>metadata.metadata['Bar'];
let ctor = <ConstructorMetadata>barClass.members['__ctor__'][0];
let parameter = ctor.parameters[0];
const unsupported1 = program.getSourceFile('/unsupported-2.ts');
const metadata = collector.getMetadata(unsupported1);
const barClass = <ClassMetadata>metadata.metadata['Bar'];
const ctor = <ConstructorMetadata>barClass.members['__ctor__'][0];
const parameter = ctor.parameters[0];
expect(parameter).toEqual({
__symbolic: 'error',
message: 'Reference to non-exported class',
@ -265,19 +265,19 @@ describe('Collector', () => {
});
it('should be able to handle import star type references', () => {
let importStar = program.getSourceFile('/import-star.ts');
let metadata = collector.getMetadata(importStar);
let someClass = <ClassMetadata>metadata.metadata['SomeClass'];
let ctor = <ConstructorMetadata>someClass.members['__ctor__'][0];
let parameters = ctor.parameters;
const importStar = program.getSourceFile('/import-star.ts');
const metadata = collector.getMetadata(importStar);
const someClass = <ClassMetadata>metadata.metadata['SomeClass'];
const ctor = <ConstructorMetadata>someClass.members['__ctor__'][0];
const parameters = ctor.parameters;
expect(parameters).toEqual([
{__symbolic: 'reference', module: 'angular2/common', name: 'NgFor'}
]);
});
it('should be able to record functions', () => {
let exportedFunctions = program.getSourceFile('/exported-functions.ts');
let metadata = collector.getMetadata(exportedFunctions);
const exportedFunctions = program.getSourceFile('/exported-functions.ts');
const metadata = collector.getMetadata(exportedFunctions);
expect(metadata).toEqual({
__symbolic: 'module',
version: 1,
@ -334,36 +334,36 @@ describe('Collector', () => {
});
it('should be able to handle import star type references', () => {
let importStar = program.getSourceFile('/import-star.ts');
let metadata = collector.getMetadata(importStar);
let someClass = <ClassMetadata>metadata.metadata['SomeClass'];
let ctor = <ConstructorMetadata>someClass.members['__ctor__'][0];
let parameters = ctor.parameters;
const importStar = program.getSourceFile('/import-star.ts');
const metadata = collector.getMetadata(importStar);
const someClass = <ClassMetadata>metadata.metadata['SomeClass'];
const ctor = <ConstructorMetadata>someClass.members['__ctor__'][0];
const parameters = ctor.parameters;
expect(parameters).toEqual([
{__symbolic: 'reference', module: 'angular2/common', name: 'NgFor'}
]);
});
it('should be able to collect the value of an enum', () => {
let enumSource = program.getSourceFile('/exported-enum.ts');
let metadata = collector.getMetadata(enumSource);
let someEnum: any = metadata.metadata['SomeEnum'];
const enumSource = program.getSourceFile('/exported-enum.ts');
const metadata = collector.getMetadata(enumSource);
const someEnum: any = metadata.metadata['SomeEnum'];
expect(someEnum).toEqual({A: 0, B: 1, C: 100, D: 101});
});
it('should ignore a non-export enum', () => {
let enumSource = program.getSourceFile('/private-enum.ts');
let metadata = collector.getMetadata(enumSource);
let publicEnum: any = metadata.metadata['PublicEnum'];
let privateEnum: any = metadata.metadata['PrivateEnum'];
const enumSource = program.getSourceFile('/private-enum.ts');
const metadata = collector.getMetadata(enumSource);
const publicEnum: any = metadata.metadata['PublicEnum'];
const privateEnum: any = metadata.metadata['PrivateEnum'];
expect(publicEnum).toEqual({a: 0, b: 1, c: 2});
expect(privateEnum).toBeUndefined();
});
it('should be able to collect enums initialized from consts', () => {
let enumSource = program.getSourceFile('/exported-enum.ts');
let metadata = collector.getMetadata(enumSource);
let complexEnum: any = metadata.metadata['ComplexEnum'];
const enumSource = program.getSourceFile('/exported-enum.ts');
const metadata = collector.getMetadata(enumSource);
const complexEnum: any = metadata.metadata['ComplexEnum'];
expect(complexEnum).toEqual({
A: 0,
B: 1,
@ -374,10 +374,10 @@ describe('Collector', () => {
});
it('should be able to collect a simple static method', () => {
let staticSource = program.getSourceFile('/static-method.ts');
let metadata = collector.getMetadata(staticSource);
const staticSource = program.getSourceFile('/static-method.ts');
const metadata = collector.getMetadata(staticSource);
expect(metadata).toBeDefined();
let classData = <ClassMetadata>metadata.metadata['MyModule'];
const classData = <ClassMetadata>metadata.metadata['MyModule'];
expect(classData).toBeDefined();
expect(classData.statics).toEqual({
with: {
@ -392,10 +392,10 @@ describe('Collector', () => {
});
it('should be able to collect a call to a static method', () => {
let staticSource = program.getSourceFile('/static-method-call.ts');
let metadata = collector.getMetadata(staticSource);
const staticSource = program.getSourceFile('/static-method-call.ts');
const metadata = collector.getMetadata(staticSource);
expect(metadata).toBeDefined();
let classData = <ClassMetadata>metadata.metadata['Foo'];
const classData = <ClassMetadata>metadata.metadata['Foo'];
expect(classData).toBeDefined();
expect(classData.decorators).toEqual([{
__symbolic: 'call',
@ -415,19 +415,19 @@ describe('Collector', () => {
});
it('should be able to collect a static field', () => {
let staticSource = program.getSourceFile('/static-field.ts');
let metadata = collector.getMetadata(staticSource);
const staticSource = program.getSourceFile('/static-field.ts');
const metadata = collector.getMetadata(staticSource);
expect(metadata).toBeDefined();
let classData = <ClassMetadata>metadata.metadata['MyModule'];
const classData = <ClassMetadata>metadata.metadata['MyModule'];
expect(classData).toBeDefined();
expect(classData.statics).toEqual({VALUE: 'Some string'});
});
it('should be able to collect a reference to a static field', () => {
let staticSource = program.getSourceFile('/static-field-reference.ts');
let metadata = collector.getMetadata(staticSource);
const staticSource = program.getSourceFile('/static-field-reference.ts');
const metadata = collector.getMetadata(staticSource);
expect(metadata).toBeDefined();
let classData = <ClassMetadata>metadata.metadata['Foo'];
const classData = <ClassMetadata>metadata.metadata['Foo'];
expect(classData).toBeDefined();
expect(classData.decorators).toEqual([{
__symbolic: 'call',
@ -446,10 +446,10 @@ describe('Collector', () => {
});
it('should be able to collect a method with a conditional expression', () => {
let source = program.getSourceFile('/static-method-with-if.ts');
let metadata = collector.getMetadata(source);
const source = program.getSourceFile('/static-method-with-if.ts');
const metadata = collector.getMetadata(source);
expect(metadata).toBeDefined();
let classData = <ClassMetadata>metadata.metadata['MyModule'];
const classData = <ClassMetadata>metadata.metadata['MyModule'];
expect(classData).toBeDefined();
expect(classData.statics).toEqual({
with: {
@ -471,10 +471,10 @@ describe('Collector', () => {
});
it('should be able to collect a method with a default parameter', () => {
let source = program.getSourceFile('/static-method-with-default.ts');
let metadata = collector.getMetadata(source);
const source = program.getSourceFile('/static-method-with-default.ts');
const metadata = collector.getMetadata(source);
expect(metadata).toBeDefined();
let classData = <ClassMetadata>metadata.metadata['MyModule'];
const classData = <ClassMetadata>metadata.metadata['MyModule'];
expect(classData).toBeDefined();
expect(classData.statics).toEqual({
with: {
@ -500,8 +500,8 @@ describe('Collector', () => {
});
it('should be able to collect re-exported symbols', () => {
let source = program.getSourceFile('/re-exports.ts');
let metadata = collector.getMetadata(source);
const source = program.getSourceFile('/re-exports.ts');
const metadata = collector.getMetadata(source);
expect(metadata.exports).toEqual([
{from: './static-field', export: ['MyModule']},
{from: './static-field-reference', export: [{name: 'Foo', as: 'OtherModule'}]},
@ -510,8 +510,8 @@ describe('Collector', () => {
});
it('should collect an error symbol if collecting a reference to a non-exported symbol', () => {
let source = program.getSourceFile('/local-symbol-ref.ts');
let metadata = collector.getMetadata(source);
const source = program.getSourceFile('/local-symbol-ref.ts');
const metadata = collector.getMetadata(source);
expect(metadata.metadata).toEqual({
REQUIRED_VALIDATOR: {
__symbolic: 'error',
@ -532,8 +532,8 @@ describe('Collector', () => {
});
it('should collect an error symbol if collecting a reference to a non-exported function', () => {
let source = program.getSourceFile('/local-function-ref.ts');
let metadata = collector.getMetadata(source);
const source = program.getSourceFile('/local-function-ref.ts');
const metadata = collector.getMetadata(source);
expect(metadata.metadata).toEqual({
REQUIRED_VALIDATOR: {
__symbolic: 'error',
@ -554,8 +554,8 @@ describe('Collector', () => {
});
it('should collect an error for a simple function that references a local variable', () => {
let source = program.getSourceFile('/local-symbol-ref-func.ts');
let metadata = collector.getMetadata(source);
const source = program.getSourceFile('/local-symbol-ref-func.ts');
const metadata = collector.getMetadata(source);
expect(metadata.metadata).toEqual({
foo: {
__symbolic: 'function',
@ -573,18 +573,18 @@ describe('Collector', () => {
describe('in strict mode', () => {
it('should throw if an error symbol is collecting a reference to a non-exported symbol', () => {
let source = program.getSourceFile('/local-symbol-ref.ts');
const source = program.getSourceFile('/local-symbol-ref.ts');
expect(() => collector.getMetadata(source, true)).toThrowError(/Reference to a local symbol/);
});
it('should throw if an error if collecting a reference to a non-exported function', () => {
let source = program.getSourceFile('/local-function-ref.ts');
const source = program.getSourceFile('/local-function-ref.ts');
expect(() => collector.getMetadata(source, true))
.toThrowError(/Reference to a non-exported function/);
});
it('should throw for references to unexpected types', () => {
let unsupported1 = program.getSourceFile('/unsupported-2.ts');
const unsupported1 = program.getSourceFile('/unsupported-2.ts');
expect(() => collector.getMetadata(unsupported1, true))
.toThrowError(/Reference to non-exported class/);
});
@ -594,14 +594,14 @@ describe('Collector', () => {
it('should not throw with a class with no name', () => {
const fileName = '/invalid-class.ts';
override(fileName, 'export class');
let invalidClass = program.getSourceFile(fileName);
const invalidClass = program.getSourceFile(fileName);
expect(() => collector.getMetadata(invalidClass)).not.toThrow();
});
it('should not throw with a function with no name', () => {
const fileName = '/invalid-function.ts';
override(fileName, 'export function');
let invalidFunction = program.getSourceFile(fileName);
const invalidFunction = program.getSourceFile(fileName);
expect(() => collector.getMetadata(invalidFunction)).not.toThrow();
});
});

View File

@ -15,7 +15,7 @@ import {Symbols} from '../src/symbols';
import {Directory, Host, expectNoDiagnostics, findVar} from './typescript.mocks';
describe('Evaluator', () => {
let documentRegistry = ts.createDocumentRegistry();
const documentRegistry = ts.createDocumentRegistry();
let host: ts.LanguageServiceHost;
let service: ts.LanguageService;
let program: ts.Program;

View File

@ -60,13 +60,13 @@ describe('Symbols', () => {
});
it('should be able to create symbols for a source file', () => {
let symbols = new Symbols(expressions);
const symbols = new Symbols(expressions);
expect(symbols).toBeDefined();
});
it('should be able to find symbols in expression', () => {
let symbols = new Symbols(expressions);
const symbols = new Symbols(expressions);
expect(symbols.has('someName')).toBeTruthy();
expect(symbols.resolve('someName'))
.toEqual({__symbolic: 'reference', module: './consts', name: 'someName'});
@ -76,24 +76,24 @@ describe('Symbols', () => {
});
it('should be able to detect a * import', () => {
let symbols = new Symbols(imports);
const symbols = new Symbols(imports);
expect(symbols.resolve('b')).toEqual({__symbolic: 'reference', module: 'b'});
});
it('should be able to detect importing a default export', () => {
let symbols = new Symbols(imports);
const symbols = new Symbols(imports);
expect(symbols.resolve('d')).toEqual({__symbolic: 'reference', module: 'd', default: true});
});
it('should be able to import a renamed symbol', () => {
let symbols = new Symbols(imports);
const symbols = new Symbols(imports);
expect(symbols.resolve('g')).toEqual({__symbolic: 'reference', name: 'f', module: 'f'});
});
it('should be able to resolve any symbol in core global scope', () => {
let core = program.getSourceFiles().find(source => source.fileName.endsWith('lib.d.ts'));
const core = program.getSourceFiles().find(source => source.fileName.endsWith('lib.d.ts'));
expect(core).toBeDefined();
let visit = (node: ts.Node): boolean => {
const visit = (node: ts.Node): boolean => {
switch (node.kind) {
case ts.SyntaxKind.VariableStatement:
case ts.SyntaxKind.VariableDeclarationList:

View File

@ -23,7 +23,7 @@ export class Host implements ts.LanguageServiceHost {
getScriptVersion(fileName: string): string { return this.version.toString(); }
getScriptSnapshot(fileName: string): ts.IScriptSnapshot {
let content = this.getFileContent(fileName);
const content = this.getFileContent(fileName);
if (content) return ts.ScriptSnapshot.fromString(content);
}
@ -125,8 +125,8 @@ export class MockSymbol implements ts.Symbol {
export function expectNoDiagnostics(diagnostics: ts.Diagnostic[]) {
for (const diagnostic of diagnostics) {
let message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
let {line, character} = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
const {line, character} = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
}
expect(diagnostics.length).toBe(0);

View File

@ -6,13 +6,14 @@
* found in the LICENSE file at https://angular.io/license
*/
/* tslint:disable:no-var-keyword */
'use strict';
var glob = require('glob');
require('zone.js/dist/zone-node.js');
var JasmineRunner = require('jasmine');
var path = require('path');
// require('core-js');
require('zone.js/dist/long-stack-trace-zone.js');
require('zone.js/dist/proxy.js');
require('zone.js/dist/sync-test.js');

View File

@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
/* tslint:disable:no-var-keyword */
'use strict';
var glob = require('glob');
@ -13,7 +15,6 @@ require('zone.js/dist/zone-node.js');
var JasmineRunner = require('jasmine');
var path = require('path');
require('source-map-support').install();
// require('core-js');
require('zone.js/dist/long-stack-trace-zone.js');
require('zone.js/dist/proxy.js');
require('zone.js/dist/sync-test.js');
@ -80,7 +81,9 @@ jrunner.specDir = '';
require('./test-cjs-main.js');
distAllRequire('@angular/platform-server/src/parse5_adapter.js').Parse5DomAdapter.makeCurrent();
specFiles.forEach((file: string) => {
var r = distAllRequire(file);
if (r.main) r.main();
const r = distAllRequire(file);
if (r.main) {
r.main();
}
});
jrunner.execute();

View File

@ -6,8 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
var testingPlatformServer = require('../../all/@angular/platform-server/testing/server.js');
var testing = require('../../all/@angular/core/testing');
const testingPlatformServer = require('../../all/@angular/platform-server/testing/server.js');
const coreTesting = require('../../all/@angular/core/testing');
testing.TestBed.initTestEnvironment(
coreTesting.TestBed.initTestEnvironment(
testingPlatformServer.ServerTestingModule, testingPlatformServer.platformServerTesting());

View File

@ -19,11 +19,11 @@ const OFFLINE_COMPILE =
function processOutputEmitterCodeGen(): Promise<number> {
return new Promise((resolve, reject) => {
var outDir = 'dist/all/@angular/compiler/test/';
var promises: Promise<any>[] = [];
const outDir = 'dist/all/@angular/compiler/test/';
const promises: Promise<any>[] = [];
console.log('Processing codegen...');
OFFLINE_COMPILE.forEach((file: string) => {
var codegen = require('../../all/@angular/compiler/test/' + file + '.js');
const codegen = require('../../all/@angular/compiler/test/' + file + '.js');
if (codegen.emit) {
console.log(` ${file} has changed, regenerating...`);
promises.push(Promise.resolve(codegen.emit()).then((code) => {
@ -34,10 +34,10 @@ function processOutputEmitterCodeGen(): Promise<number> {
if (promises.length) {
Promise.all(promises)
.then(() => {
var args =
const args =
['--project', 'tools/cjs-jasmine/tsconfig-output_emitter_codegen.json'];
console.log(' compiling changes: tsc ' + args.join(' '));
var tsc = spawn(TSC, args, {stdio: 'pipe'});
const tsc = spawn(TSC, args, {stdio: 'pipe'});
tsc.stdout.on('data', (data: any) => process.stdout.write(data));
tsc.stderr.on('data', (data: any) => process.stderr.write(data));
tsc.on(
@ -54,8 +54,8 @@ function processOutputEmitterCodeGen(): Promise<number> {
function md(dir: string, folders: string[]) {
if (folders.length) {
var next = folders.shift();
var path = dir + '/' + next;
const next = folders.shift();
const path = dir + '/' + next;
if (!existsSync(path)) {
mkdirSync(path);
}
@ -63,9 +63,9 @@ function md(dir: string, folders: string[]) {
}
}
var tscWatch: TscWatch = null;
var platform = process.argv.length >= 3 ? process.argv[2] : null;
var runMode: string = process.argv.length >= 4 ? process.argv[3] : null;
let tscWatch: TscWatch = null;
const platform = process.argv.length >= 3 ? process.argv[2] : null;
const runMode: string = process.argv.length >= 4 ? process.argv[3] : null;
const BaseConfig = {
start: 'File change detected. Starting incremental compilation...',
error: 'error',

View File

@ -47,9 +47,9 @@ export class TscWatch {
}
watch() {
var args = [TSC, '--emitDecoratorMetadata', '--project', this.tsconfig];
const args = [TSC, '--emitDecoratorMetadata', '--project', this.tsconfig];
if (!this.runOnce) args.push('--watch');
var tsc =
const tsc =
this.runCmd(args, {}, (d) => this.consumeLine(d, false), (d) => this.consumeLine(d, true));
if (this.runOnce) {
tsc.then(() => this.triggerCmds(), code => process.exit(code));
@ -64,14 +64,14 @@ export class TscWatch {
if (typeof argsOrCmd == 'function') {
return (argsOrCmd as Command)(stdErr, stdOut);
} else if (argsOrCmd instanceof Array) {
var args = argsOrCmd as Array<string>;
const args = argsOrCmd as Array<string>;
return <any>new Promise((resolve, reject) => {
var [cmd, ...options] = args;
const [cmd, ...options] = args;
console.log('=====>', cmd, options.join(' '));
var childProcess = spawn(cmd, options, {stdio: 'pipe'});
const childProcess = spawn(cmd, options, {stdio: 'pipe'});
childProcess.stdout.on('data', stdOut);
childProcess.stderr.on('data', stdErr);
var onExit = () => childProcess.kill();
const onExit = () => childProcess.kill();
childProcess.on('close', (code: number) => {
process.removeListener('exit', onExit);
console.log('EXIT:', code, '<=====', args.join(' '));
@ -96,7 +96,7 @@ export class TscWatch {
}
consumeLine(buffer: Buffer, isStdError: boolean) {
var line = '' + buffer;
const line = '' + buffer;
if (contains(line, this.start)) {
console.log('==============================================================================');
stdOut(buffer, isStdError);
@ -125,7 +125,7 @@ export class TscWatch {
}
triggerCmds() {
var cmdPromise: Promise<number> = Promise.resolve(0);
let cmdPromise: Promise<number> = Promise.resolve(0);
this.onChangeCmds.forEach(
(cmd: string[] | Command) => cmdPromise =
cmdPromise.then(() => this.runCmd(<string[]>cmd)));

View File

@ -1,40 +0,0 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {RuleWalker} from 'tslint/lib/language/walker';
import {RuleFailure} from 'tslint/lib/lint';
import {AbstractRule} from 'tslint/lib/rules';
import * as ts from 'typescript';
export class Rule extends AbstractRule {
public static FAILURE_STRING = 'missing copyright header';
public apply(sourceFile: ts.SourceFile): RuleFailure[] {
const walker = new EnforceCopyrightHeaderWalker(sourceFile, this.getOptions());
return this.applyWithWalker(walker);
}
}
class EnforceCopyrightHeaderWalker extends RuleWalker {
private regex: RegExp = /\/\*[\s\S]*?Copyright Google Inc\.[\s\S]*?\*\//;
public visitSourceFile(node: ts.SourceFile) {
// check for a shebang
let text = node.getFullText();
let offset = 0;
if (text.indexOf('#!') === 0) {
offset = text.indexOf('\n') + 1;
text = text.substring(offset);
}
// look for the copyright header
let match = text.match(this.regex);
if (!match || match.index !== 0) {
this.addFailure(this.createFailure(offset, offset + 1, Rule.FAILURE_STRING));
}
}
}

View File

@ -30,8 +30,8 @@ class TypedefWalker extends RuleWalker {
}
private hasInternalAnnotation(range: ts.CommentRange): boolean {
let text = this.getSourceFile().text;
let comment = text.substring(range.pos, range.end);
const text = this.getSourceFile().text;
const comment = text.substring(range.pos, range.end);
return comment.indexOf('@internal') >= 0;
}