ember-template-imports
Advanced tools
Comparing version 3.1.1 to 3.1.2
@@ -65,2 +65,87 @@ import { | ||
it('<template></template> preceded by a slash character', function () { | ||
const input = ` | ||
const divide = () => 4 / 2; | ||
<template>Hello!</template> | ||
`; | ||
const templates = parseTemplates(input, 'foo.gjs', { | ||
templateTag: 'template', | ||
}); | ||
expect(templates).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"end": Object { | ||
"0": "</template>", | ||
"1": undefined, | ||
"groups": undefined, | ||
"index": 57, | ||
"input": " | ||
const divide = () => 4 / 2; | ||
<template>Hello!</template> | ||
", | ||
}, | ||
"start": Object { | ||
"0": "<template>", | ||
"1": undefined, | ||
"groups": undefined, | ||
"index": 41, | ||
"input": " | ||
const divide = () => 4 / 2; | ||
<template>Hello!</template> | ||
", | ||
}, | ||
"type": "template-tag", | ||
}, | ||
] | ||
`); | ||
}); | ||
// This test demonstrates a problem with the current implementation. The characters "<template>" | ||
// inside of a regex is treated as an opening template tag instead of being ignored. Previous | ||
// versions of this addon attempted to address this by parsing "/"-delimited regexes, however | ||
// the addon's regular-expression based tokenizing was unable to properly distinguish a regex | ||
// from division, and so the test above this one ("<template></template> preceded by a slash | ||
// character") did not pass and caused quite confusing failures that occurred far more | ||
// frequently than the issue demonstrated below will occur. | ||
it.skip('<template></template> with <template> inside of a regexp', function () { | ||
const input = ` | ||
const myregex = /<template>/; | ||
<template>Hello!</template> | ||
`; | ||
const templates = parseTemplates(input, 'foo.gjs', { | ||
templateTag: 'template', | ||
}); | ||
expect(templates).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"end": Object { | ||
"0": "</template>", | ||
"1": undefined, | ||
"groups": undefined, | ||
"index": 9, | ||
"input": " | ||
const myregex = /<template>/; | ||
<template>Hello!</template> | ||
", | ||
}, | ||
"start": Object { | ||
"0": "<template>", | ||
"1": undefined, | ||
"groups": undefined, | ||
"index": 43, | ||
"input": " | ||
const myregex = /<template>/; | ||
<template>Hello!</template> | ||
", | ||
}, | ||
"type": "template-tag", | ||
}, | ||
] | ||
`); | ||
}); | ||
it('hbs`Hello!` when only matching <template>', function () { | ||
@@ -67,0 +152,0 @@ const input = 'hbs`Hello!`'; |
@@ -6,3 +6,3 @@ import { preprocessEmbeddedTemplates } from '../src/preprocess-embedded-templates'; | ||
describe('preprocessEmbeddedTemplates', function () { | ||
it('<template><template>', function () { | ||
it('<template></template>', function () { | ||
const input = `<template>Hello!</template>`; | ||
@@ -43,2 +43,39 @@ const templates = preprocessEmbeddedTemplates(input, { | ||
it('<template></template> with backticks in content', function () { | ||
const input = '<template>Hello `world`!</template>'; | ||
const templates = preprocessEmbeddedTemplates(input, { | ||
getTemplateLocals, | ||
relativePath: 'foo.gjs', | ||
templateTag: util.TEMPLATE_TAG_NAME, | ||
templateTagReplacement: util.TEMPLATE_TAG_PLACEHOLDER, | ||
includeSourceMaps: false, | ||
includeTemplateTokens: false, | ||
}); | ||
const expected = { | ||
output: | ||
'[__GLIMMER_TEMPLATE(`Hello \\`world\\`!`, { strictMode: true })]', | ||
replacements: [ | ||
{ | ||
type: 'start', | ||
index: 0, | ||
oldLength: 10, | ||
newLength: 21, | ||
originalCol: 1, | ||
originalLine: 1, | ||
}, | ||
{ | ||
type: 'end', | ||
index: 24, | ||
oldLength: 11, | ||
newLength: 25, | ||
originalCol: 25, | ||
originalLine: 1, | ||
}, | ||
], | ||
}; | ||
expect(templates).toEqual(expected); | ||
}); | ||
it('hbs`Hello`', function () { | ||
@@ -65,2 +102,23 @@ const input = `hbs\`Hello!\``; | ||
it('hbs`Hello \\`world\\``', function () { | ||
const input = `hbs\`Hello \\\`world\\\`!\``; // template tag with escaped backticks in content | ||
const templates = preprocessEmbeddedTemplates(input, { | ||
getTemplateLocals, | ||
relativePath: 'foo.gjs', | ||
templateTag: util.TEMPLATE_TAG_NAME, | ||
templateTagReplacement: util.TEMPLATE_TAG_PLACEHOLDER, | ||
importIdentifier: util.TEMPLATE_LITERAL_IDENTIFIER, | ||
importPath: util.TEMPLATE_LITERAL_MODULE_SPECIFIER, | ||
includeSourceMaps: false, | ||
includeTemplateTokens: false, | ||
}); | ||
const expected = { | ||
output: input, | ||
replacements: [], | ||
}; | ||
expect(templates).toEqual(expected); | ||
}); | ||
it('hbs`Hello` with import statement', function () { | ||
@@ -67,0 +125,0 @@ const input = |
@@ -0,1 +1,19 @@ | ||
Deprecated as of 10.7.0. highlight(lang, code, ...args) has been deprecated. | ||
Deprecated as of 10.7.0. Please use highlight(code, options) instead. | ||
https://github.com/highlightjs/highlight.js/issues/2277 | ||
## v3.1.2 (2022-10-07) | ||
#### :bug: Bug Fix | ||
* [#51](https://github.com/ember-template-imports/ember-template-imports/pull/51) Stop trying to tokenize regexes to avoid confusing bug caused by division appearing in a file before a <template> tag ([@lukemelia](https://github.com/lukemelia)) | ||
* [#54](https://github.com/ember-template-imports/ember-template-imports/pull/54) Fix build failures due to backticks within in template tags ([@lukemelia](https://github.com/lukemelia)) | ||
#### :memo: Documentation | ||
* [#55](https://github.com/ember-template-imports/ember-template-imports/pull/55) Fix parse function comments ([@backspace](https://github.com/backspace)) | ||
#### Committers: 3 | ||
- Buck Doyle ([@backspace](https://github.com/backspace)) | ||
- Luke Melia ([@lukemelia](https://github.com/lukemelia)) | ||
- [@NullVoxPopuli](https://github.com/NullVoxPopuli) | ||
## v3.1.1 (2022-08-28) | ||
@@ -2,0 +20,0 @@ |
@@ -11,3 +11,3 @@ "use strict"; | ||
const escapeChar = '\\'; | ||
const stringOrRegexDelimiter = /['"/]/; | ||
const stringDelimiter = /['"]/; | ||
const singleLineCommentStart = /\/\//; | ||
@@ -66,3 +66,3 @@ const newLine = /\n/; | ||
multiLineCommentEnd.source, | ||
stringOrRegexDelimiter.source, | ||
stringDelimiter.source, | ||
templateLiteralStart.source, | ||
@@ -101,11 +101,11 @@ templateLiteralEnd.source, | ||
} | ||
else if (token[0].match(stringOrRegexDelimiter)) { | ||
parseStringOrRegex(results, template, token, tokens); | ||
else if (token[0].match(stringDelimiter)) { | ||
parseString(results, template, token, tokens); | ||
} | ||
} | ||
/** | ||
* Parse a string or a regex. All tokens within a string or regex are ignored | ||
* Parse a string. All tokens within a string are ignored | ||
* since there are no dynamic segments within these. | ||
*/ | ||
function parseStringOrRegex(_results, template, startToken, tokens) { | ||
function parseString(_results, template, startToken, tokens) { | ||
while (tokens.length > 0) { | ||
@@ -120,4 +120,4 @@ const currentToken = (0, debug_1.expect)(tokens.shift(), 'expected token'); | ||
/** | ||
* Parse a string or a regex. All tokens within a string or regex are ignored | ||
* since there are no dynamic segments within these. | ||
* Parse a single-line comment. All tokens within a single-line comment are ignored | ||
* since there are no dynamic segments within them. | ||
*/ | ||
@@ -133,4 +133,4 @@ function parseSingleLineComment(_results, _template, _startToken, tokens) { | ||
/** | ||
* Parse a string or a regex. All tokens within a string or regex are ignored | ||
* since there are no dynamic segments within these. | ||
* Parse a multi-line comment. All tokens within a multi-line comment are ignored | ||
* since there are no dynamic segments within them. | ||
*/ | ||
@@ -137,0 +137,0 @@ function parseMultiLineComment(_results, _template, _startToken, tokens) { |
@@ -54,2 +54,3 @@ "use strict"; | ||
s.overwrite(closeStart, closeEnd, newEnd); | ||
ensureBackticksEscaped(s, openEnd + 1, closeStart - 1); | ||
return [ | ||
@@ -134,1 +135,6 @@ replacementFrom(template, openStart, openEnd - openStart, newStart.length, 'start'), | ||
exports.preprocessEmbeddedTemplates = preprocessEmbeddedTemplates; | ||
function ensureBackticksEscaped(s, start, end) { | ||
let content = s.slice(start, end); | ||
content = content.replace(/(?<!\\)`/g, '\\`'); | ||
s.overwrite(start, end, content, false); | ||
} |
{ | ||
"name": "ember-template-imports", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"description": "The default blueprint for ember-cli addons.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
104677
1792
1