-
Notifications
You must be signed in to change notification settings - Fork 710
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add wireformat view for glimmer transform (#187)
* Update "@glimmer/syntax" to v0.21.2 * handlebars: Add "glimmer-compiler" transform This is essentially the same kind of transform as "glimmer" but with a different kind of output view * Use JSONEditor component for JSON transformer output
- Loading branch information
Showing
7 changed files
with
96 additions
and
10 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
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
11 changes: 11 additions & 0 deletions
11
website/src/parsers/handlebars/transformers/glimmer-compiler/codeExample.txt
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,11 @@ | ||
module.exports = class { | ||
transform(ast) { | ||
this.syntax.traverse(ast, { | ||
ElementNode(node) { | ||
node.tag = node.tag.split('').reverse().join(''); | ||
} | ||
}); | ||
|
||
return ast; | ||
} | ||
}; |
39 changes: 39 additions & 0 deletions
39
website/src/parsers/handlebars/transformers/glimmer-compiler/index.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,39 @@ | ||
import compileModule from '../../../utils/compileModule'; | ||
import pkg from '@glimmer/compiler/package.json'; | ||
|
||
const ID = 'glimmer-compiler'; | ||
|
||
export default { | ||
id: ID, | ||
displayName: ID, | ||
version: pkg.version, | ||
homepage: pkg.homepage || 'https://github.com/tildeio/glimmer', | ||
|
||
defaultParserID: 'glimmer', | ||
|
||
loadTransformer(callback) { | ||
require(['@glimmer/compiler'], callback); | ||
}, | ||
|
||
transform(glimmer, transformCode, code) { | ||
const transformModule = compileModule(transformCode); | ||
|
||
// allow "export default" instead of "module.exports = " | ||
const transform = transformModule.__esModule ? | ||
transformModule.default : | ||
transformModule; | ||
|
||
// compile template to wireformat | ||
let result = glimmer.precompile(code, { | ||
plugins: { | ||
ast: [transform], | ||
}, | ||
}); | ||
|
||
// parse wireformat into JSON | ||
let json = JSON.parse(JSON.parse(result).block); | ||
|
||
// pretty print JSON | ||
return { code: json }; | ||
}, | ||
}; |
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