Skip to content

Commit

Permalink
Merge pull request #19196 from NoneOfMaster/clean-glimmer-in-element-…
Browse files Browse the repository at this point in the history
…feature-flag-18060
  • Loading branch information
rwjblue authored Oct 14, 2020
2 parents ae672e5 + 952a4fb commit da458df
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
import { moduleFor, RenderingTestCase, strip, equalTokens, runTask } from 'internal-test-helpers';
import { Component } from '@ember/-internals/glimmer';
import { set } from '@ember/-internals/metal';
import { EMBER_GLIMMER_IN_ELEMENT } from '@ember/canary-features';

const deprecationMessage = /The use of the private `{{-in-element}}` is deprecated, please refactor to the public `{{in-element}}`/;

moduleFor(
'{{-in-element}}',
class extends RenderingTestCase {
['@feature(!EMBER_GLIMMER_IN_ELEMENT) using {{#in-element whatever}} asserts']() {
// the in-element keyword is not yet public API this test should be removed
// once https://github.com/emberjs/rfcs/pull/287 lands and is enabled

let el = document.createElement('div');
expectAssertion(() => {
this.render(strip`{{#in-element el}}{{/in-element}}`, { el });
}, /The {{in-element}} helper cannot be used. \('-top-level' @ L1:C0\)/);
}

['@test allows rendering into an external element']() {
if (EMBER_GLIMMER_IN_ELEMENT) {
expectDeprecation(deprecationMessage);
}
expectDeprecation(deprecationMessage);

let someElement = document.createElement('div');

Expand Down Expand Up @@ -54,9 +41,7 @@ moduleFor(
}

['@test it appends to the external element by default']() {
if (EMBER_GLIMMER_IN_ELEMENT) {
expectDeprecation(deprecationMessage);
}
expectDeprecation(deprecationMessage);

let someElement = document.createElement('div');
someElement.appendChild(document.createTextNode('foo '));
Expand Down Expand Up @@ -90,9 +75,7 @@ moduleFor(
}

['@test allows appending to the external element with insertBefore=null']() {
if (EMBER_GLIMMER_IN_ELEMENT) {
expectDeprecation(deprecationMessage);
}
expectDeprecation(deprecationMessage);

let someElement = document.createElement('div');
someElement.appendChild(document.createTextNode('foo '));
Expand Down Expand Up @@ -126,9 +109,7 @@ moduleFor(
}

['@test allows clearing the external element with insertBefore=undefined']() {
if (EMBER_GLIMMER_IN_ELEMENT) {
expectDeprecation(deprecationMessage);
}
expectDeprecation(deprecationMessage);

let someElement = document.createElement('div');
someElement.appendChild(document.createTextNode('foo '));
Expand Down Expand Up @@ -162,9 +143,7 @@ moduleFor(
}

['@test does not allow insertBefore=non-null-value']() {
if (EMBER_GLIMMER_IN_ELEMENT) {
expectDeprecation(deprecationMessage);
}
expectDeprecation(deprecationMessage);

let someElement = document.createElement('div');

Expand All @@ -184,9 +163,7 @@ moduleFor(
}

['@test components are cleaned up properly'](assert) {
if (EMBER_GLIMMER_IN_ELEMENT) {
expectDeprecation(deprecationMessage);
}
expectDeprecation(deprecationMessage);

let hooks = [];

Expand Down Expand Up @@ -256,9 +233,7 @@ moduleFor(
}

['@test appending to the root element should not cause double clearing']() {
if (EMBER_GLIMMER_IN_ELEMENT) {
expectDeprecation(deprecationMessage);
}
expectDeprecation(deprecationMessage);

this.render(
strip`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { set } from '@ember/-internals/metal';
moduleFor(
'{{in-element}}',
class extends RenderingTestCase {
['@feature(EMBER_GLIMMER_IN_ELEMENT) allows rendering into an external element']() {
['@test allows rendering into an external element']() {
let someElement = document.createElement('div');

this.render(
Expand Down Expand Up @@ -37,7 +37,7 @@ moduleFor(
equalTokens(someElement, 'Whoop!');
}

["@feature(EMBER_GLIMMER_IN_ELEMENT) it replaces the external element's content by default"]() {
["@test it replaces the external element's content by default"]() {
let someElement = document.createElement('div');
someElement.appendChild(document.createTextNode('foo '));

Expand Down Expand Up @@ -69,7 +69,7 @@ moduleFor(
equalTokens(someElement, 'bar');
}

['@feature(EMBER_GLIMMER_IN_ELEMENT) allows appending to the external element with insertBefore=null']() {
['@test allows appending to the external element with insertBefore=null']() {
let someElement = document.createElement('div');
someElement.appendChild(document.createTextNode('foo '));

Expand Down Expand Up @@ -101,7 +101,7 @@ moduleFor(
equalTokens(someElement, 'foo bar');
}

['@feature(EMBER_GLIMMER_IN_ELEMENT) does not allow insertBefore=non-null-value']() {
['@test does not allow insertBefore=non-null-value']() {
let someElement = document.createElement('div');

expectAssertion(() => {
Expand All @@ -119,7 +119,7 @@ moduleFor(
}, /Can only pass null to insertBefore in in-element, received:/);
}

['@feature(EMBER_GLIMMER_IN_ELEMENT) does not allow null as a destination element']() {
['@test does not allow null as a destination element']() {
let someElement = null;

expectAssertion(() => {
Expand All @@ -137,7 +137,7 @@ moduleFor(
}, /You cannot pass a null or undefined destination element to in-element/);
}

['@feature(EMBER_GLIMMER_IN_ELEMENT) does not undefined as a destination element']() {
['@test does not undefined as a destination element']() {
let someElement = undefined;

expectAssertion(() => {
Expand All @@ -155,7 +155,7 @@ moduleFor(
}, /You cannot pass a null or undefined destination element to in-element/);
}

['@feature(EMBER_GLIMMER_IN_ELEMENT) components are cleaned up properly'](assert) {
['@test components are cleaned up properly'](assert) {
let hooks = [];

let someElement = document.createElement('div');
Expand Down Expand Up @@ -223,7 +223,7 @@ moduleFor(
assert.deepEqual(hooks, ['didInsertElement', 'willDestroyElement']);
}

['@feature(EMBER_GLIMMER_IN_ELEMENT) appending to the root element should not cause double clearing']() {
['@test appending to the root element should not cause double clearing']() {
this.render(
strip`
Before
Expand Down
2 changes: 0 additions & 2 deletions packages/@ember/canary-features/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const DEFAULT_FEATURES = {
EMBER_NAMED_BLOCKS: null,
EMBER_GLIMMER_SET_COMPONENT_TEMPLATE: true,
EMBER_ROUTING_MODEL_ARG: true,
EMBER_GLIMMER_IN_ELEMENT: true,
EMBER_CACHE_API: true,
EMBER_DESTROYABLES: true,
EMBER_GLIMMER_HELPER_MANAGER: true,
Expand Down Expand Up @@ -79,7 +78,6 @@ export const EMBER_GLIMMER_SET_COMPONENT_TEMPLATE = featureValue(
FEATURES.EMBER_GLIMMER_SET_COMPONENT_TEMPLATE
);
export const EMBER_ROUTING_MODEL_ARG = featureValue(FEATURES.EMBER_ROUTING_MODEL_ARG);
export const EMBER_GLIMMER_IN_ELEMENT = featureValue(FEATURES.EMBER_GLIMMER_IN_ELEMENT);
export const EMBER_CACHE_API = featureValue(FEATURES.EMBER_CACHE_API);
export const EMBER_DESTROYABLES = featureValue(FEATURES.EMBER_DESTROYABLES);
export const EMBER_GLIMMER_HELPER_MANAGER = featureValue(FEATURES.EMBER_GLIMMER_HELPER_MANAGER);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { EMBER_GLIMMER_IN_ELEMENT } from '@ember/canary-features';
import { assert, deprecate } from '@ember/debug';
import { AST, ASTPlugin } from '@glimmer/syntax';
import calculateLocationDisplay from '../system/calculate-location-display';
Expand Down Expand Up @@ -54,45 +53,39 @@ export default function transformInElement(env: EmberASTPluginEnvironment): ASTP
if (!isPath(node.path)) return;

if (node.path.original === 'in-element') {
if (EMBER_GLIMMER_IN_ELEMENT) {
let originalValue = node.params[0];
let originalValue = node.params[0];

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

node.params.shift();
node.params.unshift(subExpr);
}

node.hash.pairs.forEach((pair) => {
if (pair.key === 'insertBefore') {
assert(
`Can only pass null to insertBefore in in-element, received: ${JSON.stringify(
pair.value
)}`,
pair.value.type === 'NullLiteral' || pair.value.type === 'UndefinedLiteral'
);
}
});
} else {
assert(assertMessage(moduleName, node));
node.params.shift();
node.params.unshift(subExpr);
}

node.hash.pairs.forEach((pair) => {
if (pair.key === 'insertBefore') {
assert(
`Can only pass null to insertBefore in in-element, received: ${JSON.stringify(
pair.value
)}`,
pair.value.type === 'NullLiteral' || pair.value.type === 'UndefinedLiteral'
);
}
});
} else if (node.path.original === '-in-element') {
if (EMBER_GLIMMER_IN_ELEMENT) {
let sourceInformation = calculateLocationDisplay(moduleName, node.loc);
deprecate(
`The use of the private \`{{-in-element}}\` is deprecated, please refactor to the public \`{{in-element}}\`. ${sourceInformation}`,
false,
{
id: 'glimmer.private-in-element',
until: '3.25.0',
for: 'ember-source',
since: {
enabled: '3.20.0',
},
}
);
}
let sourceInformation = calculateLocationDisplay(moduleName, node.loc);
deprecate(
`The use of the private \`{{-in-element}}\` is deprecated, please refactor to the public \`{{in-element}}\`. ${sourceInformation}`,
false,
{
id: 'glimmer.private-in-element',
until: '3.25.0',
for: 'ember-source',
since: {
enabled: '3.20.0',
},
}
);

node.path.original = 'in-element';
node.path.parts = ['in-element'];
Expand Down Expand Up @@ -125,9 +118,3 @@ export default function transformInElement(env: EmberASTPluginEnvironment): ASTP
},
};
}

function assertMessage(moduleName: string, node: AST.BlockStatement) {
let sourceInformation = calculateLocationDisplay(moduleName, node.loc);

return `The {{in-element}} helper cannot be used. ${sourceInformation}`;
}

0 comments on commit da458df

Please sign in to comment.