Skip to content

Commit

Permalink
Merge pull request #19081 from emberjs/bugfix/production-template-com…
Browse files Browse the repository at this point in the history
…piler
  • Loading branch information
rwjblue authored Aug 10, 2020
2 parents 4b1ffe2 + 0cbf985 commit f09dcfc
Show file tree
Hide file tree
Showing 24 changed files with 152 additions and 105 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { StaticTemplateMeta } from '@ember/-internals/views';
import { assert } from '@ember/debug';
import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
import { AST, ASTPlugin } from '@glimmer/syntax';
import calculateLocationDisplay from '../system/calculate-location-display';
import { EmberASTPluginEnvironment } from '../types';

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

return {
name: 'assert-against-named-blocks',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { StaticTemplateMeta } from '@ember/-internals/views';
import { assert } from '@ember/debug';
import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
import { AST, ASTPlugin } from '@glimmer/syntax';
import calculateLocationDisplay from '../system/calculate-location-display';
import { EmberASTPluginEnvironment } from '../types';
import { isPath } from './utils';

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

return {
name: 'assert-if-helper-without-arguments',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { StaticTemplateMeta } from '@ember/-internals/views';
import { assert } from '@ember/debug';
import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
import { AST, ASTPlugin } from '@glimmer/syntax';
import calculateLocationDisplay from '../system/calculate-location-display';
import { EmberASTPluginEnvironment } from '../types';
import { isPath } from './utils';

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

return {
name: 'assert-input-helper-without-block',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { StaticTemplateMeta } from '@ember/-internals/views';
import { assert } from '@ember/debug';
import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
import { AST, ASTPlugin } from '@glimmer/syntax';
import calculateLocationDisplay from '../system/calculate-location-display';
import { EmberASTPluginEnvironment } from '../types';
import { isPath, trackLocals } from './utils';

export default function assertLocalVariableShadowingHelperInvocation(
env: ASTPluginEnvironment
env: EmberASTPluginEnvironment
): ASTPlugin {
let { moduleName } = env.meta as StaticTemplateMeta;
let { moduleName } = env.meta;
let { hasLocal, node } = trackLocals();

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { StaticTemplateMeta } from '@ember/-internals/views';
import { assert } from '@ember/debug';
import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
import { AST, ASTPlugin } from '@glimmer/syntax';
import calculateLocationDisplay from '../system/calculate-location-display';
import { EmberASTPluginEnvironment } from '../types';

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

return {
name: 'assert-reserved-named-arguments',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { StaticTemplateMeta } from '@ember/-internals/views';
import { assert } from '@ember/debug';
import { ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
import { ASTPlugin } from '@glimmer/syntax';
import calculateLocationDisplay from '../system/calculate-location-display';
import { EmberASTPluginEnvironment } from '../types';

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

return {
name: 'assert-splattribute-expressions',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { StaticTemplateMeta } from '@ember/-internals/views';
import { deprecate } from '@ember/debug';
import { SEND_ACTION } from '@ember/deprecated-features';
import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
import { AST, ASTPlugin } from '@glimmer/syntax';
import calculateLocationDisplay from '../system/calculate-location-display';
import { EmberASTPluginEnvironment } from '../types';
import { isPath } from './utils';

const EVENTS = [
Expand All @@ -16,9 +16,9 @@ const EVENTS = [
'key-down',
];

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

let deprecationMessage = (node: AST.Node, eventName: string, actionName: string) => {
let sourceInformation = calculateLocationDisplay(moduleName, node.loc);
Expand Down Expand Up @@ -83,5 +83,9 @@ export default function deprecateSendAction(env: ASTPluginEnvironment): ASTPlugi
},
};
}
return;

return {
name: 'deprecate-send-action',
visitor: {},
};
}
5 changes: 1 addition & 4 deletions packages/ember-template-compiler/lib/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ import TransformWrapMountAndOutlet from './transform-wrap-mount-and-outlet';

import { EMBER_NAMED_BLOCKS } from '@ember/canary-features';
import { SEND_ACTION } from '@ember/deprecated-features';
import { ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';

export type APluginFunc = (env: ASTPluginEnvironment) => ASTPlugin | undefined;

// order of plugins is important
const transforms: Array<APluginFunc> = [
const transforms = [
TransformComponentInvocation,
TransformOldClassBindingSyntax,
TransformQuotedBindingsIntoJustBindings,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
import { Builders } from '../types';
import { AST, ASTPlugin } from '@glimmer/syntax';
import { Builders, EmberASTPluginEnvironment } from '../types';
import { isPath } from './utils';

/**
Expand Down Expand Up @@ -27,7 +27,7 @@ import { isPath } from './utils';
@class TransformActionSyntax
*/

export default function transformActionSyntax({ syntax }: ASTPluginEnvironment): ASTPlugin {
export default function transformActionSyntax({ syntax }: EmberASTPluginEnvironment): ASTPlugin {
let { builders: b } = syntax;

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
import { AST, ASTPlugin } from '@glimmer/syntax';
import { EmberASTPluginEnvironment } from '../types';

/**
@module ember
Expand All @@ -24,7 +25,7 @@ import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
@class TransformAttrsToProps
*/

export default function transformAttrsIntoArgs(env: ASTPluginEnvironment): ASTPlugin {
export default function transformAttrsIntoArgs(env: EmberASTPluginEnvironment): ASTPlugin {
let { builders: b } = env.syntax;

let stack: string[][] = [[]];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { StaticTemplateMeta } from '@ember/-internals/views';
import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
import { AST, ASTPlugin } from '@glimmer/syntax';
import calculateLocationDisplay from '../system/calculate-location-display';
import { Builders } from '../types';
import { Builders, EmberASTPluginEnvironment } from '../types';
import { isPath, trackLocals } from './utils';

/**
Expand Down Expand Up @@ -122,10 +121,7 @@ import { isPath, trackLocals } from './utils';
@private
@class TransFormComponentInvocation
*/
export default function transformComponentInvocation(env: ASTPluginEnvironment): ASTPlugin {
let { moduleName } = env.meta as StaticTemplateMeta;
let { builders: b } = env.syntax;

export default function transformComponentInvocation(env: EmberASTPluginEnvironment): ASTPlugin {
let { hasLocal, node } = trackLocals();

let isAttrs = false;
Expand Down Expand Up @@ -154,13 +150,13 @@ export default function transformComponentInvocation(env: ASTPluginEnvironment):

BlockStatement(node: AST.BlockStatement) {
if (isBlockInvocation(node, hasLocal)) {
wrapInComponent(moduleName, node, b);
wrapInComponent(env, node);
}
},

MustacheStatement(node: AST.MustacheStatement): AST.Node | void {
if (!isAttrs && isInlineInvocation(node, hasLocal)) {
wrapInComponent(moduleName, node, b);
wrapInComponent(env, node);
}
},
},
Expand Down Expand Up @@ -221,11 +217,16 @@ function wrapInAssertion(moduleName: string, node: AST.PathExpression, b: Builde
}

function wrapInComponent(
moduleName: string,
node: AST.MustacheStatement | AST.BlockStatement,
b: Builders
env: EmberASTPluginEnvironment,
node: AST.MustacheStatement | AST.BlockStatement
) {
let component = wrapInAssertion(moduleName, node.path as AST.PathExpression, b);
let { moduleName } = env.meta;
let { builders: b } = env.syntax;

let component = env.isProduction
? node.path
: wrapInAssertion(moduleName, node.path as AST.PathExpression, b);

node.path = b.path('component');
node.params.unshift(component);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
import { AST, ASTPlugin } from '@glimmer/syntax';
import { EmberASTPluginEnvironment } from '../types';
import { isPath } from './utils';

/**
Expand All @@ -21,7 +22,7 @@ import { isPath } from './utils';
@private
@class TransformHasBlockSyntax
*/
export default function transformEachInIntoEach(env: ASTPluginEnvironment): ASTPlugin {
export default function transformEachInIntoEach(env: EmberASTPluginEnvironment): ASTPlugin {
let { builders: b } = env.syntax;

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
import { AST, ASTPlugin } from '@glimmer/syntax';
import { EmberASTPluginEnvironment } from '../types';
import { isPath } from './utils';

/**
Expand All @@ -21,7 +22,7 @@ import { isPath } from './utils';
@private
@class TransformHasBlockSyntax
*/
export default function transformEachTrackArray(env: ASTPluginEnvironment): ASTPlugin {
export default function transformEachTrackArray(env: EmberASTPluginEnvironment): ASTPlugin {
let { builders: b } = env.syntax;

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
import { AST, ASTPlugin } from '@glimmer/syntax';
import { EmberASTPluginEnvironment } from '../types';
import { isPath } from './utils';

/**
@module ember
*/
Expand All @@ -26,7 +28,7 @@ const TRANSFORMATIONS = {
hasBlockParams: 'has-block-params',
};

export default function transformHasBlockSyntax(env: ASTPluginEnvironment): ASTPlugin {
export default function transformHasBlockSyntax(env: EmberASTPluginEnvironment): ASTPlugin {
let { builders: b } = env.syntax;

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { StaticTemplateMeta } from '@ember/-internals/views';
import { EMBER_GLIMMER_IN_ELEMENT } from '@ember/canary-features';
import { assert, deprecate } from '@ember/debug';
import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
import { AST, ASTPlugin } from '@glimmer/syntax';
import calculateLocationDisplay from '../system/calculate-location-display';
import { EmberASTPluginEnvironment } from '../types';
import { isPath } from './utils';

/**
Expand Down Expand Up @@ -42,8 +42,8 @@ import { isPath } from './utils';
@private
@class TransformInElement
*/
export default function transformInElement(env: ASTPluginEnvironment): ASTPlugin {
let { moduleName } = env.meta as StaticTemplateMeta;
export default function transformInElement(env: EmberASTPluginEnvironment): ASTPlugin {
let { moduleName } = env.meta;
let { builders: b } = env.syntax;

return {
Expand All @@ -57,7 +57,7 @@ export default function transformInElement(env: ASTPluginEnvironment): ASTPlugin
if (EMBER_GLIMMER_IN_ELEMENT) {
let originalValue = node.params[0];

if (originalValue) {
if (originalValue && !env.isProduction) {
let subExpr = b.sexpr('-in-el-null', [originalValue]);

node.params.shift();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { StaticTemplateMeta } from '@ember/-internals/views';
import { assert } from '@ember/debug';
import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
import { AST, ASTPlugin } from '@glimmer/syntax';
import calculateLocationDisplay from '../system/calculate-location-display';
import { Builders } from '../types';
import { Builders, EmberASTPluginEnvironment } from '../types';
import { isPath, isSubExpression } from './utils';

function isInlineLinkTo(node: AST.MustacheStatement): boolean {
Expand All @@ -18,7 +17,7 @@ function isQueryParams(node: AST.Expression): node is AST.SubExpression {
}

function transformInlineLinkToIntoBlockForm(
env: ASTPluginEnvironment,
env: EmberASTPluginEnvironment,
node: AST.MustacheStatement
): AST.BlockStatement {
let { builders: b } = env.syntax;
Expand All @@ -39,11 +38,11 @@ function transformInlineLinkToIntoBlockForm(
}

function transformPositionalLinkToIntoNamedArguments(
env: ASTPluginEnvironment,
env: EmberASTPluginEnvironment,
node: AST.BlockStatement
): AST.BlockStatement {
let { builders: b } = env.syntax;
let { moduleName } = env.meta as StaticTemplateMeta;
let { moduleName } = env.meta;
let {
params,
hash: { pairs },
Expand Down Expand Up @@ -181,7 +180,7 @@ function buildStatement(b: Builders, content: AST.Node, escaped: boolean, loc: A
}
}

export default function transformLinkTo(env: ASTPluginEnvironment): ASTPlugin {
export default function transformLinkTo(env: EmberASTPluginEnvironment): ASTPlugin {
return {
name: 'transform-link-to',

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
import { Builders } from '../types';
import { AST, ASTPlugin } from '@glimmer/syntax';
import { Builders, EmberASTPluginEnvironment } from '../types';

export default function transformOldClassBindingSyntax(env: ASTPluginEnvironment): ASTPlugin {
export default function transformOldClassBindingSyntax(env: EmberASTPluginEnvironment): ASTPlugin {
let b = env.syntax.builders;

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AST, ASTPlugin, ASTPluginEnvironment } from '@glimmer/syntax';
import { AST, ASTPlugin } from '@glimmer/syntax';
import { EmberASTPluginEnvironment } from '../types';
import { isPath, trackLocals } from './utils';

/**
Expand Down Expand Up @@ -33,7 +34,7 @@ import { isPath, trackLocals } from './utils';
@private
@class TransformHasBlockSyntax
*/
export default function transformWrapMountAndOutlet(env: ASTPluginEnvironment): ASTPlugin {
export default function transformWrapMountAndOutlet(env: EmberASTPluginEnvironment): ASTPlugin {
let { builders: b } = env.syntax;

let { hasLocal, node } = trackLocals();
Expand Down
Loading

0 comments on commit f09dcfc

Please sign in to comment.