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 4.1.4 to 4.1.5

13

CHANGELOG.md

@@ -0,1 +1,14 @@

## v4.1.5 (2020-07-15)
#### :bug: Bug Fix
* [#303](https://github.com/ember-template-lint/ember-template-recast/pull/303) Preserve formatting when switching a template's body ([@dcyriller](https://github.com/dcyriller))
* [#302](https://github.com/ember-template-lint/ember-template-recast/pull/302) Improve whitespace preservation around dirty attributes / comments / modifiers ([@dcyriller](https://github.com/dcyriller))
#### :memo: Documentation
* [#307](https://github.com/ember-template-lint/ember-template-recast/pull/307) Add an intro note to README ([@dcyriller](https://github.com/dcyriller))
#### Committers: 2
- Cyrille ([@dcyriller](https://github.com/dcyriller))
- [@dependabot-preview[bot]](https://github.com/apps/dependabot-preview)
## v4.1.4 (2020-04-27)

@@ -2,0 +15,0 @@

22

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

@@ -31,11 +31,11 @@ "keywords": [

"dependencies": {
"@glimmer/syntax": "^0.51.1",
"@glimmer/syntax": "^0.54.1",
"async-promise-queue": "^1.0.5",
"colors": "^1.4.0",
"commander": "^5.1.0",
"globby": "^11.0.0",
"globby": "^11.0.1",
"ora": "^4.0.4",
"slash": "^3.0.0",
"tmp": "^0.1.0",
"workerpool": "^5.0.4"
"tmp": "^0.2.1",
"workerpool": "^6.0.0"
},

@@ -45,12 +45,12 @@ "devDependencies": {

"common-tags": "^1.8.0",
"eslint": "^6.8.0",
"eslint": "^7.4.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.1.3",
"execa": "^4.0.0",
"jest": "^25.4.0",
"eslint-plugin-prettier": "^3.1.4",
"execa": "^4.0.3",
"jest": "^26.1.0",
"lerna-changelog": "^1.0.1",
"prettier": "^2.0.5",
"release-it": "^13.5.5",
"release-it-lerna-changelog": "^2.2.0"
"release-it": "^13.6.5",
"release-it-lerna-changelog": "^2.3.0"
},

@@ -57,0 +57,0 @@ "engines": {

# ember-template-recast
With ember-template-recast, transform a template's AST and reprint it. Its
formatting will be preserved.
For instance, it is possible to change a component's property while preserving
its formatting:
```js
const recast = require('ember-template-recast');
const template = `
<Sidebar
foo="bar"
item={{hmmm}}
/>
`;
// parse
let ast = recast.parse(template);
// transform
ast.body[1].attributes[1].value.path = builders.path('this.hmmm');
// print
let ouput = recast.print(ast);
output === `
<Sidebar
foo="bar"
item={{this.hmmm}}
/>
`; // is true!
```
## APIs

@@ -4,0 +37,0 @@

@@ -5,5 +5,6 @@ const { traverse, builders, Walker } = require('@glimmer/syntax');

const PARSE_RESULT_FOR = new WeakMap();
const NODES_INFO = new Map();
function parse(template) {
let result = new ParseResult(template);
let result = new ParseResult(template, NODES_INFO);

@@ -10,0 +11,0 @@ PARSE_RESULT_FOR.set(result.ast, result);

@@ -89,3 +89,3 @@ const { preprocess, print: _print, traverse } = require('@glimmer/syntax');

module.exports = class ParseResult {
constructor(template) {
constructor(template, nodesInfo) {
let ast = preprocess(template, {

@@ -101,3 +101,3 @@ mode: 'codemod',

this.nodeInfo = new Map();
this.nodeInfo = nodesInfo;
this.ancestor = new Map();

@@ -411,19 +411,22 @@ this.dirtyFields = new Map();

let joinOpenPartsWith = ' ';
if (originalOpenParts.length > 1) {
joinOpenPartsWith = this.sourceForLoc({
start: originalOpenParts[0].loc.end,
end: originalOpenParts[1].loc.start,
let openPartsSource = originalOpenParts.reduce((acc, part, index, parts) => {
let partSource = this.sourceForLoc(part.loc);
if (index === parts.length - 1) {
return acc + partSource;
}
let joinPartWith = this.sourceForLoc({
start: parts[index].loc.end,
end: parts[index + 1].loc.start,
});
}
if (joinOpenPartsWith.trim() !== '') {
// if the autodetection above resulted in some non whitespace
// values, reset to `' '`
joinOpenPartsWith = ' ';
}
if (joinPartWith.trim() !== '') {
// if the autodetection above resulted in some non whitespace
// values, reset to `' '`
joinPartWith = ' ';
}
let openPartsSource = originalOpenParts
.map((part) => this.sourceForLoc(part.loc))
.join(joinOpenPartsWith);
return acc + partSource + joinPartWith;
}, '');

@@ -523,4 +526,23 @@ let postPartsWhitespace = '';

openPartsSource = openParts.map((part) => this.print(part)).join(joinOpenPartsWith);
openPartsSource = openParts.reduce((acc, part, index, parts) => {
let partSource = this.print(part);
if (index === parts.length - 1) {
return acc + partSource;
}
let joinPartWith = this.sourceForLoc({
start: parts[index].loc.end,
end: parts[index + 1].loc.start,
});
if (joinPartWith === '' || joinPartWith.trim() !== '') {
// if the autodetection above resulted in some non whitespace
// values, reset to `' '`
joinPartWith = ' ';
}
return acc + partSource + joinPartWith;
}, '');
if (originalOpenParts.length === 0) {

@@ -527,0 +549,0 @@ postTagWhitespace = ' ';

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