Socket
Socket
Sign inDemoInstall

ember-template-recast

Package Overview
Dependencies
Maintainers
7
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 6.0.0 to 6.1.0

lib/custom-nodes.d.ts

6

lib/index.d.ts

@@ -1,3 +0,4 @@

import { traverse, builders, Walker } from '@glimmer/syntax';
import { traverse, Walker } from '@glimmer/syntax';
import type { ASTv1 as AST, NodeVisitor } from '@glimmer/syntax';
import { builders } from './custom-nodes';
export declare function parse(template: string): AST.Template;

@@ -52,4 +53,5 @@ export declare function print(ast: AST.Node): string;

export type { AST, NodeVisitor } from '@glimmer/syntax';
export { builders, traverse } from '@glimmer/syntax';
export { traverse } from '@glimmer/syntax';
export { builders } from './custom-nodes';
export { sourceForLoc } from './utils';
//# sourceMappingURL=index.d.ts.map

@@ -6,5 +6,6 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.sourceForLoc = exports.traverse = exports.builders = exports.transform = exports.print = exports.parse = void 0;
exports.sourceForLoc = exports.builders = exports.traverse = exports.transform = exports.print = exports.parse = void 0;
const syntax_1 = require("@glimmer/syntax");
const parse_result_1 = __importDefault(require("./parse-result"));
const custom_nodes_1 = require("./custom-nodes");
const PARSE_RESULT_FOR = new WeakMap();

@@ -61,3 +62,3 @@ const NODE_INFO = new WeakMap();

parse,
builders: syntax_1.builders,
builders: custom_nodes_1.builders,
print,

@@ -81,6 +82,7 @@ traverse: syntax_1.traverse,

var syntax_2 = require("@glimmer/syntax");
Object.defineProperty(exports, "builders", { enumerable: true, get: function () { return syntax_2.builders; } });
Object.defineProperty(exports, "traverse", { enumerable: true, get: function () { return syntax_2.traverse; } });
var custom_nodes_2 = require("./custom-nodes");
Object.defineProperty(exports, "builders", { enumerable: true, get: function () { return custom_nodes_2.builders; } });
var utils_1 = require("./utils");
Object.defineProperty(exports, "sourceForLoc", { enumerable: true, get: function () { return utils_1.sourceForLoc; } });
//# sourceMappingURL=index.js.map

@@ -28,3 +28,4 @@ import { ASTv1 as AST } from '@glimmer/syntax';

print(_ast?: AST.Node): string;
printUserSuppliedNode(_ast: AST.Node): string;
}
//# sourceMappingURL=parse-result.d.ts.map

@@ -5,5 +5,7 @@ "use strict";

const utils_1 = require("./utils");
const custom_nodes_1 = require("./custom-nodes");
const leadingWhitespace = /(^\s+)/;
const attrNodeParts = /(^[^=]+)(\s+)?(=)?(\s+)?(['"])?(\S+)?/;
const hashPairParts = /(^[^=]+)(\s+)?=(\s+)?(\S+)/;
const invalidUnquotedAttrValue = /[^-.a-zA-Z0-9]/;
const voidTagNames = new Set([

@@ -36,3 +38,4 @@ 'area',

(0, syntax_1.traverse)(ast, {
AttrNode(node) {
AttrNode(attr) {
const node = attr;
const source = (0, utils_1.sourceForLoc)(sourceLines, node.loc);

@@ -53,4 +56,13 @@ const attrNodePartsResults = source.match(attrNodeParts);

node.isValueless = isValueless;
node.quoteType = quote ? quote : null;
node.quoteType = quote || null;
},
StringLiteral(lit) {
const quotes = /^['"]/;
const node = lit;
const source = (0, utils_1.sourceForLoc)(sourceLines, node.loc);
if (!source.match(quotes)) {
throw new Error('Invalid string literal found');
}
node.quoteType = source[0];
},
TextNode(node, path) {

@@ -297,10 +309,3 @@ if (path.parentNode === null) {

if (nodeInfo === undefined) {
return (0, syntax_1.print)(_ast, {
entityEncoding: 'raw',
override: (ast) => {
if (this.nodeInfo.has(ast)) {
return this.print(ast);
}
},
});
return this.printUserSuppliedNode(_ast);
}

@@ -741,23 +746,74 @@ // this ensures that we are operating on the actual node and not a

let valueSource = this.sourceForLoc(attrNode.value.loc);
// does not include ConcatStatement because `_print` automatically
// adds a `"` around them, meaning we do not need to add our own quotes
const wasQuotableValue = attrNode.value.type === 'TextNode';
// Source of ConcatStatements includes their quotes,
// but source of an AttrNode's TextNode value does not.
// Normalize on not including them, then always printing them ourselves:
if (attrNode.value.type === 'ConcatStatement') {
valueSource = valueSource.slice(1, -1);
}
const node = ast;
if (dirtyFields.has('name')) {
if (!wasQuotableValue) {
nameSource = node.name;
dirtyFields.delete('name');
}
if (dirtyFields.has('quoteType')) {
// Ensure the quote type they've specified is valid for the value
if (node.value.type === 'MustacheStatement' && node.quoteType) {
throw new Error('Mustache statements should not be quoted as attribute values');
}
else if (node.value.type === 'ConcatStatement' && !node.quoteType) {
throw new Error('ConcatStatements must be quoted as attribute values');
}
else if (node.value.type == 'TextNode' &&
!node.quoteType &&
node.value.chars.match(invalidUnquotedAttrValue)) {
throw new Error(`\`${node.value.chars}\` is invalid as an unquoted attribute value. Alphanumeric, hyphens, and periods only`);
}
quote = node.quoteType || ''; // null => empty string
}
else if (dirtyFields.has('value')) {
// They updated the value without choosing a quote type. We'll use the previous quote
// type or default to double quote if necessary
if (node.value.type === 'MustacheStatement') {
quote = '';
}
nameSource = ast.name;
dirtyFields.delete('name');
else if (node.value.type === 'TextNode' &&
node.quoteType === null &&
!node.value.chars.match(invalidUnquotedAttrValue)) {
// If old value was unquoted, and new value is also ok as unquoted, preserve that.
quote = '';
}
else {
quote = quote || '"';
}
}
dirtyFields.delete('quoteType');
if (dirtyFields.has('isValueless')) {
if (node.isValueless) {
equals = '';
quote = '';
valueSource = '';
dirtyFields.delete('isValueless');
dirtyFields.delete('value');
}
else {
equals = '=';
if (node.value.type !== 'MustacheStatement' && !quote) {
quote = '"';
}
dirtyFields.delete('isValueless');
}
}
if (dirtyFields.has('value')) {
const newValueNeedsQuotes = ast.value.type === 'TextNode';
if (!wasQuotableValue && newValueNeedsQuotes) {
quote = '"';
equals = '=';
// If they created a ConcatStatement node, we need to print it ourselves here.
// Otherwise, since it has no nodeInfo, it will print using the glimmer printer
// which hardcodes double quotes.
if (node.value.type === 'ConcatStatement') {
valueSource = node.value.parts.map((part) => this.print(part)).join('');
}
else if (wasQuotableValue && !newValueNeedsQuotes) {
quote = '';
else {
valueSource = this.print(node.value);
}
valueSource = this.print(ast.value);
dirtyFields.delete('value');
}
dirtyFields.delete('value');
output.push(nameSource, postNameWhitespace, equals, postEqualsWhitespace, quote, valueSource, quote);

@@ -803,11 +859,4 @@ }

{
const { source } = nodeInfo;
const openQuote = source[0];
const closeQuote = source[source.length - 1];
let valueSource = source.slice(1, -1);
if (dirtyFields.has('value')) {
valueSource = ast.value;
dirtyFields.delete('value');
}
output.push(openQuote, valueSource, closeQuote);
const node = ast;
output.push(node.quoteType, node.value, node.quoteType);
}

@@ -836,4 +885,72 @@ break;

}
// User-created nodes will have no nodeInfo, but we support
// formatting properties that the glimmer printer does not.
// If the user-created node specifies no custom formatting,
// just use the glimmer printer.
// These overrides could go away if glimmer had a concrete
// syntax tree type and printer.
printUserSuppliedNode(_ast) {
switch (_ast.type) {
case 'StringLiteral':
{
let quote = _ast.quoteType || '"';
return quote + _ast.value + quote;
}
break;
case 'AttrNode':
{
const node = _ast;
if (node.isValueless) {
if (node.value.type !== 'TextNode' || node.value.chars !== '') {
throw new Error('The value property of a valueless attr must be an empty TextNode');
}
return node.name;
}
if (node.isValueless === undefined &&
node.value.type === 'TextNode' &&
node.value.chars === '') {
return node.name;
}
switch (node.value.type) {
case 'MustacheStatement':
return node.name + '=' + this.print(node.value);
break;
case 'ConcatStatement':
{
const value = node.value.parts.map((part) => this.print(part)).join('');
const quote = node.quoteType || '"';
return node.name + '=' + quote + value + quote;
}
break;
case 'TextNode':
{
if (node.quoteType === null && node.value.chars.match(invalidUnquotedAttrValue)) {
throw new Error(`You specified a quoteless attribute \`${node.value.chars}\`, which is invalid without quotes`);
}
let quote;
if (node.quoteType === null) {
quote = '';
}
else {
quote = node.quoteType || '"';
}
return node.name + '=' + quote + node.value.chars + quote;
}
break;
}
}
break;
default:
return (0, syntax_1.print)(_ast, {
entityEncoding: 'raw',
override: (ast) => {
if (this.nodeInfo.has(ast) || (0, custom_nodes_1.useCustomPrinter)(ast)) {
return this.print(ast);
}
},
});
}
}
}
exports.default = ParseResult;
//# sourceMappingURL=parse-result.js.map
{
"name": "ember-template-recast",
"version": "6.0.0",
"version": "6.1.0",
"description": "Non-destructive template transformer.",

@@ -35,4 +35,4 @@ "keywords": [

"dependencies": {
"@glimmer/reference": "^0.83.0",
"@glimmer/syntax": "^0.83.0",
"@glimmer/reference": "^0.83.1",
"@glimmer/syntax": "^0.83.1",
"@glimmer/validator": "^0.83.0",

@@ -49,9 +49,7 @@ "async-promise-queue": "^1.0.5",

"devDependencies": {
"@types/common-tags": "^1.8.1",
"@types/jest": "^27.0.2",
"@types/workerpool": "^6.1.0",
"@typescript-eslint/eslint-plugin": "^5.3.0",
"@typescript-eslint/parser": "^5.3.0",
"@typescript-eslint/eslint-plugin": "^5.3.1",
"@typescript-eslint/parser": "^5.3.1",
"broccoli-test-helper": "^2.0.0",
"common-tags": "^1.8.0",
"eslint": "^8.2.0",

@@ -64,4 +62,5 @@ "eslint-config-prettier": "^8.3.0",

"npm-run-all": "^4.1.5",
"outdent": "^0.8.0",
"prettier": "^2.4.1",
"release-it": "^14.11.6",
"release-it": "^14.11.7",
"release-it-lerna-changelog": "^4.0.1",

@@ -68,0 +67,0 @@ "ts-jest": "^26.5.6",

@@ -128,3 +128,5 @@ # ember-template-recast

The list of known builders on the `env.syntax.builders` are [found
here](https://github.com/glimmerjs/glimmer-vm/blob/v0.62.4/packages/%40glimmer/syntax/lib/builders.ts#L547-L578).
here](https://github.com/glimmerjs/glimmer-vm/blob/v0.82.0/packages/%40glimmer/syntax/lib/v1/public-builders.ts#L530),
although there are a few small extensions related to formatting
[in `custom-nodes.ts`](src/custom-nodes.ts)

@@ -131,0 +133,0 @@ Example:

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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