Socket
Socket
Sign inDemoInstall

ember-template-recast

Package Overview
Dependencies
Maintainers
5
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.3.0 to 3.3.1

8

CHANGELOG.md

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

## v3.3.1 (2019-12-16)
#### :bug: Bug Fix
* [#181](https://github.com/ember-template-lint/ember-template-recast/pull/181) Fix issue with mutation of `ElementNode`'s attributes when the first attribute value is `=""` ([@Turbo87](https://github.com/Turbo87))
#### Committers: 1
- Tobias Bieniek ([@Turbo87](https://github.com/Turbo87))
## v3.3.0 (2019-12-09)

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

2

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

@@ -5,0 +5,0 @@ "keywords": [

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

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

*/
function fixASTIssues(ast) {
function fixASTIssues(sourceLines, ast) {
traverse(ast, {
AttrNode(node) {
let source = sourceForLoc(sourceLines, node.loc);
let isValueless = !source.includes('=');
// TODO: manually working around https://github.com/glimmerjs/glimmer-vm/pull/953
if (node.value.type === 'TextNode' && node.value.chars === '') {
if (isValueless && node.value.type === 'TextNode' && node.value.chars === '') {
// \n is not valid within an attribute name (it would indicate two attributes)

@@ -73,5 +76,6 @@ // always assume the attribute ends on the starting line

ast = fixASTIssues(ast);
let source = getLines(template);
this.source = getLines(template);
ast = fixASTIssues(source, ast);
this.source = source;
this._originalAst = ast;

@@ -162,35 +166,3 @@

sourceForLoc(loc) {
if (!loc) {
return;
}
let firstLine = loc.start.line - 1;
let lastLine = loc.end.line - 1;
let currentLine = firstLine - 1;
let firstColumn = loc.start.column;
let lastColumn = loc.end.column;
let string = [];
let line;
while (currentLine < lastLine) {
currentLine++;
// for templates that are completely empty the outer Template loc is line
// 0, column 0 for both start and end defaulting to empty string prevents
// more complicated logic below
line = this.source[currentLine] || '';
if (currentLine === firstLine) {
if (firstLine === lastLine) {
string.push(line.slice(firstColumn, lastColumn));
} else {
string.push(line.slice(firstColumn));
}
} else if (currentLine === lastLine) {
string.push(line.slice(0, lastColumn));
} else {
string.push(line);
}
}
return string.join('');
return sourceForLoc(this.source, loc);
}

@@ -197,0 +169,0 @@

@@ -0,1 +1,37 @@

function sourceForLoc(sourceLines, loc) {
if (!loc) {
return;
}
let firstLine = loc.start.line - 1;
let lastLine = loc.end.line - 1;
let currentLine = firstLine - 1;
let firstColumn = loc.start.column;
let lastColumn = loc.end.column;
let string = [];
let line;
while (currentLine < lastLine) {
currentLine++;
// for templates that are completely empty the outer Template loc is line
// 0, column 0 for both start and end defaulting to empty string prevents
// more complicated logic below
line = sourceLines[currentLine] || '';
if (currentLine === firstLine) {
if (firstLine === lastLine) {
string.push(line.slice(firstColumn, lastColumn));
} else {
string.push(line.slice(firstColumn));
}
} else if (currentLine === lastLine) {
string.push(line.slice(0, lastColumn));
} else {
string.push(line);
}
}
return string.join('');
}
function isSynthetic(node) {

@@ -53,2 +89,3 @@ if (node && node.loc) {

compactJoin,
sourceForLoc,
};
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc