-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX release] Expose
@glimmer/syntax
from template compiler priv…
…ately for use in Embroider. This enables Embroider to remove some gnarly hacks (or at least only resort to them when operating on older Ember).
- Loading branch information
Showing
3 changed files
with
117 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
packages/ember-template-compiler/tests/basic-usage-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { | ||
_buildCompileOptions, | ||
_preprocess, | ||
_print, | ||
registerPlugin, | ||
unregisterPlugin, | ||
} from '../index'; | ||
import { moduleFor, RenderingTestCase } from 'internal-test-helpers'; | ||
|
||
function reverseElementNodeTag() { | ||
return { | ||
name: 'reverse-element-node-tag', | ||
visitor: { | ||
ElementNode(node) { | ||
node.tag = node.tag.split('').reverse().join(''); | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
function removeDataTest() { | ||
return { | ||
name: 'remove-data-test', | ||
|
||
visitor: { | ||
ElementNode(node) { | ||
for (let i = 0; i < node.attributes.length; i++) { | ||
let attribute = node.attributes[i]; | ||
|
||
if (attribute.name === 'data-test') { | ||
node.attributes.splice(i, 1); | ||
} | ||
} | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
moduleFor( | ||
'ember-template-compiler: Embroider-like compilation', | ||
class extends RenderingTestCase { | ||
afterEach() { | ||
expectDeprecation(() => { | ||
unregisterPlugin('ast', removeDataTest); | ||
}, /unregisterPlugin is deprecated, please pass plugins directly via `compile` and\/or `precompile`/); | ||
return super.afterEach(); | ||
} | ||
|
||
'@test can process a subset of AST plugins and print'(assert) { | ||
let template = '<div data-test="foo" data-blah="derp" class="hahaha"> </div>'; | ||
|
||
// build up options including strictMode default values, customizeComponentName, meta.moduleName, etc | ||
let options = _buildCompileOptions({ | ||
mode: 'codemod', | ||
moduleName: 'components/foo', | ||
plugins: { ast: [removeDataTest] }, | ||
}); | ||
|
||
let transformedTemplateAST = _preprocess(template, options); | ||
|
||
// print back to a handlebars string | ||
let result = _print(transformedTemplateAST, { entityEncoding: 'raw' }); | ||
|
||
assert.equal(result, '<div data-blah="derp" class="hahaha"> </div>'); | ||
} | ||
|
||
'@test registerPlugin based transforms can be avoided'(assert) { | ||
expectDeprecation(() => { | ||
registerPlugin('ast', removeDataTest); | ||
}, /registerPlugin is deprecated, please pass plugins directly via `compile` and\/or `precompile`/); | ||
|
||
let template = '<div data-test="foo" data-blah="derp" class="hahaha"> </div>'; | ||
|
||
// build up options including strictMode default values, customizeComponentName, meta.moduleName, etc | ||
let options = _buildCompileOptions({ | ||
mode: 'codemod', | ||
moduleName: 'components/foo', | ||
plugins: { | ||
ast: [reverseElementNodeTag], | ||
}, | ||
}); | ||
|
||
let transformedTemplateAST = _preprocess(template, options); | ||
|
||
// print back to a handlebars string | ||
let result = _print(transformedTemplateAST, { entityEncoding: 'raw' }); | ||
|
||
// only reverseElementNodeTag has ran, **not** removeDataTest | ||
assert.equal(result, '<vid data-test="foo" data-blah="derp" class="hahaha"> </vid>'); | ||
} | ||
} | ||
); |