Socket
Socket
Sign inDemoInstall

ember-template-recast

Package Overview
Dependencies
Maintainers
3
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember-template-recast - npm Package Compare versions

Comparing version 3.1.0 to 3.1.1

8

CHANGELOG.md

@@ -0,1 +1,9 @@

## v3.1.1 (2019-07-11)
#### :house: Internal
* [#75](https://github.com/ember-template-lint/ember-template-recast/pull/75) Remove duplicated @glimmer/syntax printer implementation. ([@rwjblue](https://github.com/rwjblue))
#### Committers: 1
- Robert Jackson ([@rwjblue](https://github.com/rwjblue))
## v3.1.0 (2019-07-11)

@@ -2,0 +10,0 @@

4

package.json
{
"name": "ember-template-recast",
"version": "3.1.0",
"version": "3.1.1",
"description": "Non-destructive template transformer.",

@@ -20,3 +20,3 @@ "license": "MIT",

"dependencies": {
"@glimmer/syntax": "^0.41.3",
"@glimmer/syntax": "^0.41.4",
"async-promise-queue": "^1.0.5",

@@ -23,0 +23,0 @@ "colors": "^1.3.3",

const { preprocess, print: _print } = require('@glimmer/syntax');
const { sortByLoc, compactJoin } = require('./utils');
const { sortByLoc } = require('./utils');

@@ -10,21 +10,2 @@ const reLines = /(.*?(?:\r\n?|\n|$))/gm;

const voidElements = new Set([
'area',
'base',
'br',
'col',
'command',
'embed',
'hr',
'img',
'input',
'keygen',
'link',
'meta',
'param',
'source',
'track',
'wbr',
]);
module.exports = class ParseResult {

@@ -303,288 +284,21 @@ constructor(template) {

print(ast = this._originalAst) {
if (!ast) {
print(_ast = this._originalAst) {
if (!_ast) {
return '';
}
// TODO: this isn't quite right, it forces the whole subtree
// to be reprinted which isn't correct
if (this.nodeInfo.has(ast)) {
return this._printKnownNode(ast);
} else {
return this._printNewNode(ast);
}
}
let nodeInfo = this.nodeInfo.get(_ast);
/*
TODO: this is _nearly_ copied from @glimmer/syntax directly (with some small changes)
if (nodeInfo === undefined) {
return _print(_ast, {
entityEncoding: 'raw',
We should tweak the printer in @glimmer/syntax to allow a custom print function to be used instead of directly
recursing. This would allow us to use our own custom "reprint" code but still do the "right thing" for new nodes.
*/
_printNewNode(ast) {
if (!ast) {
return '';
}
const parseResult = this;
function buildEach(asts) {
return asts.map(node => parseResult.print(node));
}
function pathParams(ast) {
let path;
switch (ast.type) {
case 'MustacheStatement':
case 'SubExpression':
case 'ElementModifierStatement':
case 'BlockStatement':
path = parseResult.print(ast.path);
break;
case 'PartialStatement':
path = parseResult.print(ast.name);
break;
default:
throw new Error('unreachable');
}
return compactJoin([path, buildEach(ast.params).join(' '), parseResult.print(ast.hash)], ' ');
}
function blockParams(block) {
const params = block.program.blockParams;
if (params.length) {
return ` as |${params.join(' ')}|`;
}
return null;
}
function openBlock(block) {
return compactJoin([
'{{',
block.openStrip.open ? '~' : null,
'#',
pathParams(block),
blockParams(block),
block.openStrip.close ? '~' : null,
'}}',
]);
}
function closeBlock(block) {
return compactJoin([
'{{',
block.closeStrip.open ? '~' : null,
'/',
parseResult.print(block.path),
block.closeStrip.close ? '~' : null,
'}}',
]);
}
const output = [];
switch (ast.type) {
case 'Program':
case 'Block':
case 'Template':
{
const chainBlock = ast.chained && ast.body[0];
if (chainBlock) {
chainBlock.chained = true;
override: ast => {
if (this.nodeInfo.has(ast)) {
return this.print(ast);
}
const body = buildEach(ast.body).join('');
output.push(body);
}
break;
case 'ElementNode':
output.push('<', ast.tag);
if (ast.attributes.length) {
output.push(' ', buildEach(ast.attributes).join(' '));
}
if (ast.modifiers.length) {
output.push(' ', buildEach(ast.modifiers).join(' '));
}
if (ast.comments.length) {
output.push(' ', buildEach(ast.comments).join(' '));
}
if (ast.blockParams.length) {
output.push(' ', 'as', ' ', `|${ast.blockParams.join(' ')}|`);
}
if (voidElements.has(ast.tag)) {
if (ast.selfClosing) {
output.push(' /');
}
output.push('>');
} else if (ast.selfClosing) {
output.push(' />');
} else {
output.push('>');
output.push.apply(output, buildEach(ast.children));
output.push('</', ast.tag, '>');
}
break;
case 'AttrNode':
if (ast.value.type === 'TextNode') {
if (ast.value.chars !== '') {
output.push(ast.name, '=');
output.push('"', ast.value.chars, '"');
} else {
output.push(ast.name);
}
} else {
output.push(ast.name, '=');
// ast.value is mustache or concat
output.push(parseResult.print(ast.value));
}
break;
case 'ConcatStatement':
output.push('"');
ast.parts.forEach(node => {
if (node.type === 'TextNode') {
output.push(node.chars);
} else {
output.push(parseResult.print(node));
}
});
output.push('"');
break;
case 'TextNode':
output.push(ast.chars);
break;
case 'MustacheStatement':
{
output.push(
compactJoin([
ast.escaped ? '{{' : '{{{',
ast.strip.open ? '~' : null,
pathParams(ast),
ast.strip.close ? '~' : null,
ast.escaped ? '}}' : '}}}',
])
);
}
break;
case 'MustacheCommentStatement':
{
output.push(compactJoin(['{{!--', ast.value, '--}}']));
}
break;
case 'ElementModifierStatement':
{
output.push(compactJoin(['{{', pathParams(ast), '}}']));
}
break;
case 'PathExpression':
output.push(ast.original);
break;
case 'SubExpression':
{
output.push('(', pathParams(ast), ')');
}
break;
case 'BooleanLiteral':
output.push(ast.value ? 'true' : 'false');
break;
case 'BlockStatement':
{
const lines = [];
if (ast.chained) {
lines.push(
compactJoin([
'{{',
ast.inverseStrip.open ? '~' : null,
'else ',
pathParams(ast),
ast.inverseStrip.close ? '~' : null,
'}}',
])
);
} else {
lines.push(openBlock(ast));
}
lines.push(parseResult.print(ast.program));
if (ast.inverse) {
if (!ast.inverse.chained) {
lines.push(
compactJoin([
'{{',
ast.inverseStrip.open ? '~' : null,
'else',
ast.inverseStrip.close ? '~' : null,
'}}',
])
);
}
lines.push(parseResult.print(ast.inverse));
}
if (!ast.chained) {
lines.push(closeBlock(ast));
}
output.push(lines.join(''));
}
break;
case 'PartialStatement':
{
output.push(compactJoin(['{{>', pathParams(ast), '}}']));
}
break;
case 'CommentStatement':
{
output.push(compactJoin(['<!--', ast.value, '-->']));
}
break;
case 'StringLiteral':
{
output.push(`"${ast.value}"`);
}
break;
case 'NumberLiteral':
{
output.push(String(ast.value));
}
break;
case 'UndefinedLiteral':
{
output.push('undefined');
}
break;
case 'NullLiteral':
{
output.push('null');
}
break;
case 'Hash':
{
output.push(
ast.pairs
.map(pair => {
return parseResult.print(pair);
})
.join(' ')
);
}
break;
case 'HashPair':
{
output.push(`${ast.key}=${parseResult.print(ast.value)}`);
}
break;
},
});
}
return output.join('');
}
_printKnownNode(_ast) {
let nodeInfo = this.nodeInfo.get(_ast);
// this ensures that we are operating on the actual node and not a

@@ -591,0 +305,0 @@ // proxy (we can get Proxies here when transforms splice body/children)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc