Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX beta] Deprecate importing htmlSafe and isHTMLSafe from @ember/string #19339

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 30 additions & 2 deletions packages/ember/index.js
Expand Up @@ -651,8 +651,36 @@ if (ENV.EXTEND_PROTOTYPES.String) {
return htmlSafe(this);
};
}
Ember.String.htmlSafe = htmlSafe;
Ember.String.isHTMLSafe = isHTMLSafe;
const deprecateImportFromString = function (
name,
message = `Importing ${name} from '@ember/string' is deprecated. Please import ${name} from '@ember/template' instead.`
) {
deprecate(message, false, {
id: 'ember-string.htmlsafe-ishtmlsafe',
for: 'ember-source',
since: {
enabled: '3.25',
},
until: '4.0.0',
url: 'https://deprecations.emberjs.com/v3.x/#toc_ember-string-htmlsafe-ishtmlsafe',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that ember-learn/deprecation-app#758 is merged, can you double check the deployed URL to make sure this is right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Things seem to jump around after page load so you don't end up exactly in the right spot, but the anchor but the link does match what's in the TOC. This jumping issue seems to affect all the anchors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the jumping around is the code blocks rendering. I'll make an issue!

});
};
Object.defineProperty(Ember.String, 'htmlSafe', {
enumerable: true,
configurable: true,
get() {
deprecateImportFromString('htmlSafe');
return htmlSafe;
},
});
Object.defineProperty(Ember.String, 'isHTMLSafe', {
enumerable: true,
configurable: true,
get() {
deprecateImportFromString('isHTMLSafe');
return isHTMLSafe;
},
});

/**
Global hash of shared templates. This will automatically be populated
Expand Down
25 changes: 22 additions & 3 deletions packages/ember/tests/reexports_test.js
Expand Up @@ -68,8 +68,28 @@ moduleFor(
});
}

['@test Ember.String.isHTMLSafe exports correctly'](assert) {
confirmExport(Ember, assert, 'String.isHTMLSafe', '@ember/-internals/glimmer', 'isHTMLSafe');
['@test Ember.String.htmlSafe exports correctly (but deprecated)'](assert) {
let glimmer = require('@ember/-internals/glimmer');
expectDeprecation(() => {
assert.equal(
Ember.String.htmlSafe,
glimmer.htmlSafe,
'Ember.String.htmlSafe is exported correctly'
);
}, /Importing htmlSafe from '@ember\/string' is deprecated/);
assert.notEqual(glimmer.htmlSafe, undefined, 'Ember.String.htmlSafe is not `undefined`');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These asserts are based on

export default function confirmExport(Ember, assert, path, moduleId, exportName) {
try {
let desc = getDescriptor(Ember, path);
assert.ok(desc, `the ${path} property exists on the Ember global`);
if (typeof exportName === 'string') {
let mod = require(moduleId);
assert.equal(desc.value, mod[exportName], `Ember.${path} is exported correctly`);
assert.notEqual(mod[exportName], undefined, `Ember.${path} is not \`undefined\``);
} else if ('value' in desc) {
assert.equal(desc.value, exportName.value, `Ember.${path} is exported correctly`);
} else {
let mod = require(moduleId);
assert.equal(desc.get, mod[exportName.get], `Ember.${path} getter is exported correctly`);
assert.notEqual(desc.get, undefined, `Ember.${path} getter is not undefined`);
if (exportName.set) {
assert.equal(desc.set, mod[exportName.set], `Ember.${path} setter is exported correctly`);
assert.notEqual(desc.set, undefined, `Ember.${path} setter is not undefined`);
}
}
} catch (error) {
assert.pushResult({
result: false,
message: `An error occurred while testing ${path} is exported from ${moduleId}.`,
source: error,
});
}

but had to be a little different because it's now a getter in the "reexport" (not strictly a reexport now, I guess) and a value in the original mod.

}

['@test Ember.String.isHTMLSafe exports correctly (but deprecated)'](assert) {
let glimmer = require('@ember/-internals/glimmer');
expectDeprecation(() => {
assert.equal(
Ember.String.isHTMLSafe,
glimmer.isHTMLSafe,
'Ember.String.isHTMLSafe is exported correctly'
);
}, /Importing isHTMLSafe from '@ember\/string' is deprecated/);
assert.notEqual(glimmer.isHTMLSafe, undefined, 'Ember.String.isHTMLSafe is not `undefined`');
}

['@test Ember.EXTEND_PROTOTYPES is present (but deprecated)'](assert) {
Expand Down Expand Up @@ -270,7 +290,6 @@ let allExports = [
['Handlebars.template', '@ember/-internals/glimmer', 'template'],
['HTMLBars.template', '@ember/-internals/glimmer', 'template'],
['Handlebars.Utils.escapeExpression', '@ember/-internals/glimmer', 'escapeExpression'],
['String.htmlSafe', '@ember/-internals/glimmer', 'htmlSafe'],
['_setComponentManager', '@ember/-internals/glimmer', 'setComponentManager'],
['_componentManagerCapabilities', '@glimmer/manager', 'componentCapabilities'],
['_setComponentTemplate', '@glimmer/manager', 'setComponentTemplate'],
Expand Down