Skip to content

Commit

Permalink
Merge pull request #1983 from embroider-build/merge-stable
Browse files Browse the repository at this point in the history
Merge stable into Main
  • Loading branch information
mansona authored Jun 12, 2024
2 parents 0277294 + d2422d9 commit b61ecde
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 44 deletions.
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
# Embroider Changelog

## Release (2024-06-12)

@embroider/webpack 4.0.3 (patch)

#### :bug: Bug Fix
* `@embroider/webpack`
* [#1981](https://github.com/embroider-build/embroider/pull/1981) Revert "Webpack: close the compiler" ([@krasnoukhov](https://github.com/krasnoukhov))

#### Committers: 1
- Dmitry Krasnoukhov ([@krasnoukhov](https://github.com/krasnoukhov))

## Release (2024-06-11)

@embroider/compat 3.5.2 (patch)
@embroider/core 3.4.11 (patch)
@embroider/macros 1.16.3 (patch)
@embroider/webpack 4.0.2 (patch)

#### :bug: Bug Fix
* `@embroider/macros`
* [#1967](https://github.com/embroider-build/embroider/pull/1967) Address these issues in new apps (5.9): ([@NullVoxPopuli](https://github.com/NullVoxPopuli))
* `@embroider/webpack`
* [#1978](https://github.com/embroider-build/embroider/pull/1978) Webpack: close the compiler ([@ef4](https://github.com/ef4))
* `@embroider/macros`, `@embroider/test-fixtures`
* [#1977](https://github.com/embroider-build/embroider/pull/1977) Fix modifier removal for "unless (macroCondition ...)" ([@ef4](https://github.com/ef4))
* `@embroider/macros`, `@embroider/test-fixtures`, `@embroider/test-scenarios`
* [#1975](https://github.com/embroider-build/embroider/pull/1975) Stop using "#with" in macro tests ([@ef4](https://github.com/ef4))

#### Committers: 2
- Edward Faulkner ([@ef4](https://github.com/ef4))
- [@NullVoxPopuli](https://github.com/NullVoxPopuli)

## Release (2024-05-29)

@embroider/router 2.1.8 (patch)
Expand Down
2 changes: 1 addition & 1 deletion packages/compat/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@embroider/compat",
"version": "3.5.1",
"version": "3.5.2",
"private": false,
"description": "Backward compatibility layer for the Embroider build system.",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@embroider/core",
"version": "3.4.10",
"version": "3.4.11",
"private": false,
"description": "A build system for EmberJS applications.",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/macros/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@embroider/macros",
"version": "1.16.2",
"version": "1.16.3",
"private": false,
"description": "Standardized build-time macros for ember apps.",
"keywords": [
Expand Down
78 changes: 47 additions & 31 deletions packages/macros/src/glimmer/ast-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,16 @@ export function makeFirstTransform(opts: FirstTransformParams) {
name: '@embroider/macros/first',

visitor: {
Program: {
enter(node: any) {
if (node.blockParams.length > 0) {
scopeStack.push(node.blockParams);
}
},
exit(node: any) {
if (node.blockParams.length > 0) {
scopeStack.pop();
}
},
},
...scopeVisitors(env, scopeStack),
SubExpression(node: any, walker: { parent: { node: any } }) {
if (node.path.type !== 'PathExpression') {
return;
}
if (inScope(scopeStack, node.path.parts[0])) {

if (inScope(scopeStack, headOf(node.path))) {
return;
}

if (node.path.original === 'macroGetOwnConfig') {
return literal(
getConfig(node, opts.configs, opts.packageRoot, moduleName, true, packageCache),
Expand Down Expand Up @@ -120,7 +111,8 @@ export function makeFirstTransform(opts: FirstTransformParams) {
if (node.path.type !== 'PathExpression') {
return;
}
if (inScope(scopeStack, node.path.parts[0])) {

if (inScope(scopeStack, headOf(node.path))) {
return;
}
if (node.path.original === 'macroGetOwnConfig') {
Expand Down Expand Up @@ -166,23 +158,13 @@ export function makeSecondTransform() {
name: '@embroider/macros/second',

visitor: {
Program: {
enter(node: any) {
if (node.blockParams.length > 0) {
scopeStack.push(node.blockParams);
}
},
exit(node: any) {
if (node.blockParams.length > 0) {
scopeStack.pop();
}
},
},
...scopeVisitors(env, scopeStack),
BlockStatement(node: any) {
if (node.path.type !== 'PathExpression') {
return;
}
if (inScope(scopeStack, node.path.parts[0])) {

if (inScope(scopeStack, headOf(node.path))) {
return;
}
if (node.path.original === 'if') {
Expand All @@ -196,7 +178,8 @@ export function makeSecondTransform() {
if (node.path.type !== 'PathExpression') {
return;
}
if (inScope(scopeStack, node.path.parts[0])) {

if (inScope(scopeStack, headOf(node.path))) {
return;
}
if (node.path.original === 'if') {
Expand Down Expand Up @@ -228,13 +211,14 @@ export function makeSecondTransform() {
) {
modifier.path = macroUnlessExpression(modifier.path, env.syntax.builders);
if (modifier.path.type === 'UndefinedLiteral') {
return true;
return false;
}
}
if (modifier.path.type !== 'PathExpression') {
return true;
}
if (inScope(scopeStack, modifier.path.parts[0])) {

if (inScope(scopeStack, headOf(node.path))) {
return true;
}
if (modifier.path.original === 'macroMaybeAttrs') {
Expand All @@ -248,7 +232,8 @@ export function makeSecondTransform() {
if (node.path.type !== 'PathExpression') {
return;
}
if (inScope(scopeStack, node.path.parts[0])) {

if (inScope(scopeStack, headOf(node.path))) {
return;
}
if (node.path.original === 'if') {
Expand Down Expand Up @@ -281,3 +266,34 @@ function inScope(scopeStack: string[][], name: string) {
}
return false;
}

function headOf(path: any) {
if (!path) return;

return 'head' in path ? path.head.name : path.parts[0];
}

function scopeVisitors(env: any, scopeStack: string[][]) {
function enter(node: any) {
if (node.blockParams.length > 0) {
scopeStack.push(node.blockParams);
}
}
function exit(node: any) {
if (node.blockParams.length > 0) {
scopeStack.pop();
}
}

let hasTemplate = 'template' in env.syntax.builders;
if (hasTemplate) {
return {
Template: { enter, exit },
Block: { enter, exit },
};
} else {
return {
Program: { enter, exit },
};
}
}
4 changes: 2 additions & 2 deletions packages/macros/tests/glimmer/get-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ describe(`macroGetConfig`, function () {
});

test('macroGetOwnConfig in subexpression position', function () {
let code = transform(`{{#with (macroGetOwnConfig "mode") as |m|}}{{m}}{{/with}}`);
let code = transform(`{{#let (macroGetOwnConfig "mode") as |m|}}{{m}}{{/let}}`);
expect(code).toMatch(/\{\{#with ["']amazing["'] as |m|\}\}/);
});

test('macroGetConfig in subexpression position', function () {
let code = transform(`{{#with (macroGetConfig "scenario-tester" "color") as |m|}}{{m}}{{/with}}`);
let code = transform(`{{#let (macroGetConfig "scenario-tester" "color") as |m|}}{{m}}{{/let}}`);
expect(code).toMatch(/\{\{#with ["']orange["'] as |m|\}\}/);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/webpack/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@embroider/webpack",
"version": "4.0.1",
"version": "4.0.3",
"private": false,
"description": "Builds EmberJS apps with Webpack",
"repository": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module('Integration | Macro | common', function(hooks) {
setupRenderingTest(hooks);

test('our macros do not shadow local variables', async function(assert) {
await render(hbs`{{#with "hello" as |macroDependencySatisfies|}} {{macroDependencySatisfies}} {{/with}}`);
await render(hbs`{{#let "hello" as |macroDependencySatisfies|}} {{macroDependencySatisfies}} {{/let}}`);
assert.equal(this.element.textContent.trim(), 'hello');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ module('Integration | Macro | getConfig', function(hooks) {
});

test('macroGetOwnConfig in subexpression position', async function(assert) {
await render(hbs`{{#with (macroGetOwnConfig "mode") as |m|}}{{m}}{{/with}}`);
await render(hbs`{{#let (macroGetOwnConfig "mode") as |m|}}{{m}}{{/let}}`);
assert.equal(this.element.textContent.trim(), 'amazing');
});

test('macroGetConfig in subexpression position', async function(assert) {
await render(hbs`{{#with (macroGetConfig "ember-source" "color") as |m|}}{{m}}{{/with}}`);
await render(hbs`{{#let (macroGetConfig "ember-source" "color") as |m|}}{{m}}{{/let}}`);
assert.equal(this.element.textContent.trim(), 'orange');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ module('Integration | Macro | macroCondition + {{unless}}', function (hooks) {
await click('button');
});

test('macroCondition in modifier position when true with no alternate', async function (assert) {
test('macroCondition in modifier position when true with no alternate should do nothing', async function (assert) {
assert.expect(0);
this.doThing = function () {
assert.ok(true, 'it ran');
Expand Down
6 changes: 3 additions & 3 deletions tests/scenarios/compat-resolver-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1160,8 +1160,8 @@ Scenarios.fromProject(() => new Project())
'templates/application.hbs': `
{{outlet}}
{{yield bar}}
{{#with (hash submit=(action doit)) as |thing| }}
{{/with}}
{{#let (hash submit=(action doit)) as |thing| }}
{{/let}}
<LinkTo @route="index"/>
<form {{on "submit" doit}}></form>
`,
Expand All @@ -1170,7 +1170,7 @@ Scenarios.fromProject(() => new Project())
expectTranspiled('templates/application.hbs').equalsCode(`
import { precompileTemplate } from "@ember/template-compilation";
import { on } from "@ember/modifier";
export default precompileTemplate("\\n {{outlet}}\\n {{yield bar}}\\n {{#with (hash submit=(action doit)) as |thing|}}\\n {{/with}}\\n <LinkTo @route=\\"index\\" />\\n <form {{on \\"submit\\" doit}}></form>\\n ", {
export default precompileTemplate("\\n {{outlet}}\\n {{yield bar}}\\n {{#let (hash submit=(action doit)) as |thing|}}\\n {{/let}}\\n <LinkTo @route=\\"index\\" />\\n <form {{on \\"submit\\" doit}}></form>\\n ", {
moduleName: "my-app/templates/application.hbs",
scope: () => ({
on,
Expand Down

0 comments on commit b61ecde

Please sign in to comment.