From ed9d9d5096a79a2e6d9023d11f0824a18b598578 Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Fri, 19 Jun 2015 18:02:35 -0400 Subject: [PATCH] build(broccoli): make node_trees produce strict-mode scripts Closes #2575 Closes #2648 --- modules/angular2/src/util/decorators.ts | 36 +++++++++---------- .../test/core/compiler/integration_spec.ts | 27 +++++++------- tools/broccoli/trees/node_tree.ts | 7 ++++ 3 files changed, 38 insertions(+), 32 deletions(-) diff --git a/modules/angular2/src/util/decorators.ts b/modules/angular2/src/util/decorators.ts index bccc3ebe43..d2f01aca1f 100644 --- a/modules/angular2/src/util/decorators.ts +++ b/modules/angular2/src/util/decorators.ts @@ -127,27 +127,27 @@ export function makeParamDecorator(annotationCls): any { if (this instanceof annotationCls) { return annotationInstance; } else { - function ParamDecorator(cls, unusedKey, index) { - var parameters: Array> = Reflect.getMetadata('parameters', cls); - parameters = parameters || []; - - // there might be gaps if some in between parameters do not have annotations. - // we pad with nulls. - while (parameters.length <= index) { - parameters.push(null); - } - - parameters[index] = parameters[index] || []; - var annotationsForParam: Array = parameters[index]; - annotationsForParam.push(annotationInstance); - - Reflect.defineMetadata('parameters', parameters, cls); - return cls; - } - (ParamDecorator).annotation = annotationInstance; return ParamDecorator; } + + function ParamDecorator(cls, unusedKey, index) { + var parameters: Array> = Reflect.getMetadata('parameters', cls); + parameters = parameters || []; + + // there might be gaps if some in between parameters do not have annotations. + // we pad with nulls. + while (parameters.length <= index) { + parameters.push(null); + } + + parameters[index] = parameters[index] || []; + var annotationsForParam: Array = parameters[index]; + annotationsForParam.push(annotationInstance); + + Reflect.defineMetadata('parameters', parameters, cls); + return cls; + } } ParamDecoratorFactory.prototype = Object.create(annotationCls.prototype); return ParamDecoratorFactory; diff --git a/modules/angular2/test/core/compiler/integration_spec.ts b/modules/angular2/test/core/compiler/integration_spec.ts index 9da5d0e568..f898bdfd1e 100644 --- a/modules/angular2/test/core/compiler/integration_spec.ts +++ b/modules/angular2/test/core/compiler/integration_spec.ts @@ -1209,22 +1209,21 @@ export function main() { // - https://github.com/angular/angular/issues/776 // - https://github.com/angular/angular/commit/81f3f32 xdescribe('Missing directive checks', () => { + function expectCompileError(tb, inlineTpl, errMessage, done) { + tb.overrideView(MyComp, new viewAnn.View({template: inlineTpl})); + PromiseWrapper.then( + tb.createView(MyComp), + (value) => { + throw new BaseException( + "Test failure: should not have come here as an exception was expected"); + }, + (err) => { + expect(err.message).toEqual(errMessage); + done(); + }); + } if (assertionsEnabled()) { - function expectCompileError(tb, inlineTpl, errMessage, done) { - tb.overrideView(MyComp, new viewAnn.View({template: inlineTpl})); - PromiseWrapper.then( - tb.createView(MyComp), - (value) => { - throw new BaseException( - "Test failure: should not have come here as an exception was expected"); - }, - (err) => { - expect(err.message).toEqual(errMessage); - done(); - }); - } - it('should raise an error if no directive is registered for a template with template bindings', inject([TestBed, AsyncTestCompleter], (tb: TestBed, async) => { expectCompileError(tb, '
', diff --git a/tools/broccoli/trees/node_tree.ts b/tools/broccoli/trees/node_tree.ts index 5bee8a8367..6bfc564dfd 100644 --- a/tools/broccoli/trees/node_tree.ts +++ b/tools/broccoli/trees/node_tree.ts @@ -127,5 +127,12 @@ module.exports = function makeNodeTree(destinationPath) { ] }); + // Prepend 'use strict' directive to all JS files. + // See https://github.com/Microsoft/TypeScript/issues/3576 + nodeTree = replace(nodeTree, { + files: ['**/*.js'], + patterns: [{match: /^/, replacement: function() { return `'use strict';` }}] + }); + return destCopy(nodeTree, destinationPath); };