ember-template-recast
Advanced tools
Comparing version 6.1.0 to 6.1.1
@@ -10,24 +10,17 @@ "use strict"; | ||
const custom_nodes_1 = require("./custom-nodes"); | ||
const PARSE_RESULT_FOR = new WeakMap(); | ||
const NODE_INFO = new WeakMap(); | ||
function parse(template) { | ||
const result = new parse_result_1.default(template, NODE_INFO); | ||
PARSE_RESULT_FOR.set(result.ast, result); | ||
return result.ast; | ||
return new parse_result_1.default(template, NODE_INFO).ast; | ||
} | ||
exports.parse = parse; | ||
function print(ast) { | ||
const parseResult = PARSE_RESULT_FOR.get(ast); | ||
// TODO: write a test for this case | ||
if (parseResult === undefined) { | ||
return (0, syntax_1.print)(ast, { | ||
entityEncoding: 'raw', | ||
override: (ast) => { | ||
if (NODE_INFO.has(ast)) { | ||
return print(ast); | ||
} | ||
}, | ||
}); | ||
} | ||
return parseResult.print(); | ||
return (0, syntax_1.print)(ast, { | ||
entityEncoding: 'raw', | ||
override: (ast) => { | ||
let info = NODE_INFO.get(ast); | ||
if (info) { | ||
return info.parse_result.print(ast); | ||
} | ||
}, | ||
}); | ||
} | ||
@@ -34,0 +27,0 @@ exports.print = print; |
@@ -6,2 +6,3 @@ import { ASTv1 as AST } from '@glimmer/syntax'; | ||
source: string; | ||
parse_result: ParseResult; | ||
hadHash?: boolean; | ||
@@ -8,0 +9,0 @@ hadParams?: boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const syntax_1 = require("@glimmer/syntax"); | ||
const custom_nodes_1 = require("./custom-nodes"); | ||
const utils_1 = require("./utils"); | ||
const custom_nodes_1 = require("./custom-nodes"); | ||
const leadingWhitespace = /(^\s+)/; | ||
@@ -117,2 +117,3 @@ const attrNodeParts = /(^[^=]+)(\s+)?(=)?(\s+)?(['"])?(\S+)?/; | ||
source: this.sourceForLoc(node.loc), | ||
parse_result: this, | ||
}; | ||
@@ -406,5 +407,4 @@ this.nodeInfo.set(node, nodeInfo); | ||
if (element.blockParams.length > 0) { | ||
const blockParamStartIndex = nodeInfo.source.indexOf('as |'); | ||
const blockParamsEndIndex = nodeInfo.source.indexOf('|', blockParamStartIndex + 4); | ||
blockParamsSource = nodeInfo.source.substring(blockParamStartIndex, blockParamsEndIndex + 1); | ||
blockParamsSource = (0, utils_1.getBlockParams)(nodeInfo.source); | ||
const [, blockParamsEndIndex] = (0, utils_1.rangeOfBlockParam)(nodeInfo.source); | ||
const closeOpenIndex = nodeInfo.source.indexOf(selfClosing ? '/>' : '>'); | ||
@@ -572,5 +572,4 @@ postBlockParamsWhitespace = nodeInfo.source.substring(blockParamsEndIndex + 1, closeOpenIndex); | ||
}); | ||
const indexOfAsPipe = blockParamsSourceScratch.indexOf('as |'); | ||
const indexOfEndPipe = blockParamsSourceScratch.indexOf('|', indexOfAsPipe + 4); | ||
blockParamsSource = blockParamsSourceScratch.substring(indexOfAsPipe, indexOfEndPipe + 1); | ||
blockParamsSource = (0, utils_1.getBlockParams)(blockParamsSourceScratch); | ||
const [, indexOfEndPipe] = (0, utils_1.rangeOfBlockParam)(blockParamsSourceScratch); | ||
const postBlockParamsWhitespaceMatch = blockParamsSourceScratch | ||
@@ -595,4 +594,3 @@ .substring(indexOfEndPipe + 1) | ||
if (hadProgramBlockParams) { | ||
const indexOfAsPipe = openEndSourceScratch.indexOf('as |'); | ||
const indexOfEndPipe = openEndSourceScratch.indexOf('|', indexOfAsPipe + 4); | ||
const [, indexOfEndPipe] = (0, utils_1.rangeOfBlockParam)(openEndSourceScratch); | ||
startingOffset = indexOfEndPipe + 1; | ||
@@ -599,0 +597,0 @@ } |
@@ -8,2 +8,4 @@ import type { ASTv1 as AST } from '@glimmer/syntax'; | ||
export declare function getLines(source: string): string[]; | ||
export declare function rangeOfBlockParam(source: string): [number, number]; | ||
export declare function getBlockParams(source: string): string; | ||
//# sourceMappingURL=utils.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getLines = exports.compactJoin = exports.compact = exports.sortByLoc = exports.isSyntheticWithNoLocation = exports.sourceForLoc = void 0; | ||
exports.getBlockParams = exports.rangeOfBlockParam = exports.getLines = exports.compactJoin = exports.compact = exports.sortByLoc = exports.isSyntheticWithNoLocation = exports.sourceForLoc = void 0; | ||
const reLines = /(.*?(?:\r\n?|\n|$))/gm; | ||
@@ -88,2 +88,41 @@ function sourceForLoc(source, loc) { | ||
exports.getLines = getLines; | ||
/* | ||
* This function takes a string (the source of an ElementNode or a | ||
* BlockStatement) and returns the range of the last possible block param's | ||
* range. | ||
* | ||
* If the block param is not found, the function will return [-1, -1]; | ||
* | ||
* For example: | ||
* ``` | ||
* rangeOfBlockParam('<Component data-foo="as |foo|" as |bar|></Component>') // => [31, 38] | ||
* rangeOfBlockParam('{{#BlockStatement data-foo="as |foo|" as |bar|}}{{/BlockStatement}}') // => [38, 45] | ||
* ``` | ||
*/ | ||
function rangeOfBlockParam(source) { | ||
let matches = Array.from(source.matchAll(/as\s+\|[^|]+\|/g)); | ||
let match = matches[matches.length - 1]; | ||
if (!match) { | ||
return [-1, -1]; | ||
} | ||
return [match.index, match.index + match[0].length - 1]; | ||
} | ||
exports.rangeOfBlockParam = rangeOfBlockParam; | ||
/* | ||
* This function takes a string (the source of an ElementNode or a | ||
* BlockStatement) and returns its block param. | ||
* | ||
* If the block param is not found, the function will return ""; | ||
* | ||
* For example: | ||
* ``` | ||
* getBlockParams("<Component as |bar|></Component>") // => "as |bar|" | ||
* getBlockParams("{{#BlockStatement as |bar|}}{{/BlockStatement}}") // => "as |bar|" | ||
* ``` | ||
*/ | ||
function getBlockParams(source) { | ||
const [indexOfAsPipe, indexOfEndPipe] = rangeOfBlockParam(source); | ||
return source.substring(indexOfAsPipe, indexOfEndPipe + 1); | ||
} | ||
exports.getBlockParams = getBlockParams; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "ember-template-recast", | ||
"version": "6.1.0", | ||
"version": "6.1.1", | ||
"description": "Non-destructive template transformer.", | ||
@@ -29,2 +29,3 @@ "keywords": [ | ||
"lint:tsc": "tsc --noEmit", | ||
"perf:benchmark": "node scripts/benchmark.mjs", | ||
"prepare": "tsc", | ||
@@ -49,8 +50,9 @@ "release": "release-it", | ||
"devDependencies": { | ||
"@types/jest": "^27.0.2", | ||
"@types/jest": "^27.0.3", | ||
"@types/workerpool": "^6.1.0", | ||
"@typescript-eslint/eslint-plugin": "^5.3.1", | ||
"@typescript-eslint/parser": "^5.3.1", | ||
"@typescript-eslint/eslint-plugin": "^5.5.0", | ||
"@typescript-eslint/parser": "^5.6.0", | ||
"benchmark": "^2.1.4", | ||
"broccoli-test-helper": "^2.0.0", | ||
"eslint": "^8.2.0", | ||
"eslint": "^8.4.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
@@ -63,7 +65,7 @@ "eslint-plugin-node": "^11.1.0", | ||
"outdent": "^0.8.0", | ||
"prettier": "^2.4.1", | ||
"release-it": "^14.11.7", | ||
"prettier": "^2.5.1", | ||
"release-it": "^14.11.8", | ||
"release-it-lerna-changelog": "^4.0.1", | ||
"ts-jest": "^26.5.6", | ||
"typescript": "~4.4.4" | ||
"typescript": "~4.5.2" | ||
}, | ||
@@ -70,0 +72,0 @@ "engines": { |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
160058
32
1644
19