Skip to content

Commit bff48c4

Browse files
rwjblueRobert Jackson
authored andcommitted
Adds isProduction flag for the template compiler.
Adds an `isProduction` flag option to the template compiler that can be used to change the behavior of the compiler for production builds. We generally do this already for the JS side of Ember, but not for templates, and this closes that gap. Notes: Exposes an `env.isProduction` (or for legacy style AST plugins `this.options.isProduction`) boolean that can be used from within the plugin itself to toggle debug vs prod only behaviors. (cherry picked from f09dcfc)
1 parent 28866d3 commit bff48c4

24 files changed

+152
-105
lines changed

packages/ember-template-compiler/lib/plugins/assert-against-named-blocks.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { StaticTemplateMeta } from '@ember/-internals/views';
21
import { assert } from '@ember/debug';
3-
import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
2+
import { AST, ASTPlugin } from '@glimmer/syntax';
43
import calculateLocationDisplay from '../system/calculate-location-display';
4+
import { EmberASTPluginEnvironment } from '../types';
55

66
/**
77
@module ember
@@ -13,8 +13,8 @@ import calculateLocationDisplay from '../system/calculate-location-display';
1313
@private
1414
@class AssertAgainstNamedBlocks
1515
*/
16-
export default function assertAgainstNamedBlocks(env: ASTPluginEnvironment): ASTPlugin {
17-
let { moduleName } = env.meta as StaticTemplateMeta;
16+
export default function assertAgainstNamedBlocks(env: EmberASTPluginEnvironment): ASTPlugin {
17+
let { moduleName } = env.meta;
1818

1919
return {
2020
name: 'assert-against-named-blocks',

packages/ember-template-compiler/lib/plugins/assert-if-helper-without-arguments.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { StaticTemplateMeta } from '@ember/-internals/views';
21
import { assert } from '@ember/debug';
3-
import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
2+
import { AST, ASTPlugin } from '@glimmer/syntax';
43
import calculateLocationDisplay from '../system/calculate-location-display';
4+
import { EmberASTPluginEnvironment } from '../types';
55
import { isPath } from './utils';
66

7-
export default function assertIfHelperWithoutArguments(env: ASTPluginEnvironment): ASTPlugin {
8-
let { moduleName } = env.meta as StaticTemplateMeta;
7+
export default function assertIfHelperWithoutArguments(env: EmberASTPluginEnvironment): ASTPlugin {
8+
let { moduleName } = env.meta;
99

1010
return {
1111
name: 'assert-if-helper-without-arguments',

packages/ember-template-compiler/lib/plugins/assert-input-helper-without-block.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { StaticTemplateMeta } from '@ember/-internals/views';
21
import { assert } from '@ember/debug';
3-
import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
2+
import { AST, ASTPlugin } from '@glimmer/syntax';
43
import calculateLocationDisplay from '../system/calculate-location-display';
4+
import { EmberASTPluginEnvironment } from '../types';
55
import { isPath } from './utils';
66

7-
export default function errorOnInputWithContent(env: ASTPluginEnvironment): ASTPlugin {
8-
let { moduleName } = env.meta as StaticTemplateMeta;
7+
export default function errorOnInputWithContent(env: EmberASTPluginEnvironment): ASTPlugin {
8+
let { moduleName } = env.meta;
99

1010
return {
1111
name: 'assert-input-helper-without-block',

packages/ember-template-compiler/lib/plugins/assert-local-variable-shadowing-helper-invocation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { StaticTemplateMeta } from '@ember/-internals/views';
21
import { assert } from '@ember/debug';
3-
import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
2+
import { AST, ASTPlugin } from '@glimmer/syntax';
43
import calculateLocationDisplay from '../system/calculate-location-display';
4+
import { EmberASTPluginEnvironment } from '../types';
55
import { isPath, trackLocals } from './utils';
66

77
export default function assertLocalVariableShadowingHelperInvocation(
8-
env: ASTPluginEnvironment
8+
env: EmberASTPluginEnvironment
99
): ASTPlugin {
10-
let { moduleName } = env.meta as StaticTemplateMeta;
10+
let { moduleName } = env.meta;
1111
let { hasLocal, node } = trackLocals();
1212

1313
return {

packages/ember-template-compiler/lib/plugins/assert-reserved-named-arguments.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { StaticTemplateMeta } from '@ember/-internals/views';
21
import { assert } from '@ember/debug';
3-
import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
2+
import { AST, ASTPlugin } from '@glimmer/syntax';
43
import calculateLocationDisplay from '../system/calculate-location-display';
4+
import { EmberASTPluginEnvironment } from '../types';
55

6-
export default function assertReservedNamedArguments(env: ASTPluginEnvironment): ASTPlugin {
7-
let { moduleName } = env.meta as StaticTemplateMeta;
6+
export default function assertReservedNamedArguments(env: EmberASTPluginEnvironment): ASTPlugin {
7+
let { moduleName } = env.meta;
88

99
return {
1010
name: 'assert-reserved-named-arguments',

packages/ember-template-compiler/lib/plugins/assert-splattribute-expression.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { StaticTemplateMeta } from '@ember/-internals/views';
21
import { assert } from '@ember/debug';
3-
import { ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
2+
import { ASTPlugin } from '@glimmer/syntax';
43
import calculateLocationDisplay from '../system/calculate-location-display';
4+
import { EmberASTPluginEnvironment } from '../types';
55

6-
export default function assertSplattributeExpressions(env: ASTPluginEnvironment): ASTPlugin {
7-
let { moduleName } = env.meta as StaticTemplateMeta;
6+
export default function assertSplattributeExpressions(env: EmberASTPluginEnvironment): ASTPlugin {
7+
let { moduleName } = env.meta;
88

99
return {
1010
name: 'assert-splattribute-expressions',

packages/ember-template-compiler/lib/plugins/deprecate-send-action.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { StaticTemplateMeta } from '@ember/-internals/views';
21
import { deprecate } from '@ember/debug';
32
import { SEND_ACTION } from '@ember/deprecated-features';
4-
import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
3+
import { AST, ASTPlugin } from '@glimmer/syntax';
54
import calculateLocationDisplay from '../system/calculate-location-display';
5+
import { EmberASTPluginEnvironment } from '../types';
66
import { isPath } from './utils';
77

88
const EVENTS = [
@@ -16,9 +16,9 @@ const EVENTS = [
1616
'key-down',
1717
];
1818

19-
export default function deprecateSendAction(env: ASTPluginEnvironment): ASTPlugin | undefined {
19+
export default function deprecateSendAction(env: EmberASTPluginEnvironment): ASTPlugin {
2020
if (SEND_ACTION) {
21-
let { moduleName } = env.meta as StaticTemplateMeta;
21+
let { moduleName } = env.meta;
2222

2323
let deprecationMessage = (node: AST.Node, eventName: string, actionName: string) => {
2424
let sourceInformation = calculateLocationDisplay(moduleName, node.loc);
@@ -83,5 +83,9 @@ export default function deprecateSendAction(env: ASTPluginEnvironment): ASTPlugi
8383
},
8484
};
8585
}
86-
return;
86+
87+
return {
88+
name: 'deprecate-send-action',
89+
visitor: {},
90+
};
8791
}

packages/ember-template-compiler/lib/plugins/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@ import TransformWrapMountAndOutlet from './transform-wrap-mount-and-outlet';
1919

2020
import { EMBER_NAMED_BLOCKS } from '@ember/canary-features';
2121
import { SEND_ACTION } from '@ember/deprecated-features';
22-
import { ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
23-
24-
export type APluginFunc = (env: ASTPluginEnvironment) => ASTPlugin | undefined;
2522

2623
// order of plugins is important
27-
const transforms: Array<APluginFunc> = [
24+
const transforms = [
2825
TransformComponentInvocation,
2926
TransformOldClassBindingSyntax,
3027
TransformQuotedBindingsIntoJustBindings,

packages/ember-template-compiler/lib/plugins/transform-action-syntax.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
2-
import { Builders } from '../types';
1+
import { AST, ASTPlugin } from '@glimmer/syntax';
2+
import { Builders, EmberASTPluginEnvironment } from '../types';
33
import { isPath } from './utils';
44

55
/**
@@ -27,7 +27,7 @@ import { isPath } from './utils';
2727
@class TransformActionSyntax
2828
*/
2929

30-
export default function transformActionSyntax({ syntax }: ASTPluginEnvironment): ASTPlugin {
30+
export default function transformActionSyntax({ syntax }: EmberASTPluginEnvironment): ASTPlugin {
3131
let { builders: b } = syntax;
3232

3333
return {

packages/ember-template-compiler/lib/plugins/transform-attrs-into-args.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
1+
import { AST, ASTPlugin } from '@glimmer/syntax';
2+
import { EmberASTPluginEnvironment } from '../types';
23

34
/**
45
@module ember
@@ -24,7 +25,7 @@ import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
2425
@class TransformAttrsToProps
2526
*/
2627

27-
export default function transformAttrsIntoArgs(env: ASTPluginEnvironment): ASTPlugin {
28+
export default function transformAttrsIntoArgs(env: EmberASTPluginEnvironment): ASTPlugin {
2829
let { builders: b } = env.syntax;
2930

3031
let stack: string[][] = [[]];

0 commit comments

Comments
 (0)