Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix pug-lexer parsed escaped interpolations incorrectly #3299

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/pug-lexer/index.js
Expand Up @@ -579,7 +579,11 @@ Lexer.prototype = {
}
if (indexOfStringInterp !== Infinity) {
if (matchOfStringInterp[1]) {
prefix = prefix + value.substring(0, indexOfStringInterp) + '#{';
prefix =
prefix +
value.substring(0, indexOfStringInterp) +
matchOfStringInterp[2] +
'{';
return this.addText(
type,
value.substring(indexOfStringInterp + 3),
Expand Down
74 changes: 30 additions & 44 deletions packages/pug-lexer/test/__snapshots__/index.test.js.snap
Expand Up @@ -26702,31 +26702,17 @@ Array [

exports[`interpolation.escape.pug 1`] = `
Array [
Object {
"loc": Object {
"end": Object {
"column": 1,
"line": 2,
},
"filename": "<basedir>/packages/pug-lexer/test/cases/interpolation.escape.pug",
"start": Object {
"column": 1,
"line": 2,
},
},
"type": "newline",
},
Object {
"buffer": false,
"loc": Object {
"end": Object {
"column": 15,
"line": 2,
"line": 1,
},
"filename": "<basedir>/packages/pug-lexer/test/cases/interpolation.escape.pug",
"start": Object {
"column": 1,
"line": 2,
"line": 1,
},
},
"mustEscape": false,
Expand All @@ -26737,12 +26723,12 @@ Array [
"loc": Object {
"end": Object {
"column": 1,
"line": 3,
"line": 2,
},
"filename": "<basedir>/packages/pug-lexer/test/cases/interpolation.escape.pug",
"start": Object {
"column": 1,
"line": 3,
"line": 2,
},
},
"type": "newline",
Expand All @@ -26751,12 +26737,12 @@ Array [
"loc": Object {
"end": Object {
"column": 4,
"line": 3,
"line": 2,
},
"filename": "<basedir>/packages/pug-lexer/test/cases/interpolation.escape.pug",
"start": Object {
"column": 1,
"line": 3,
"line": 2,
},
},
"type": "tag",
Expand All @@ -26766,12 +26752,12 @@ Array [
"loc": Object {
"end": Object {
"column": 3,
"line": 4,
"line": 3,
},
"filename": "<basedir>/packages/pug-lexer/test/cases/interpolation.escape.pug",
"start": Object {
"column": 1,
"line": 4,
"line": 3,
},
},
"type": "indent",
Expand All @@ -26781,12 +26767,12 @@ Array [
"loc": Object {
"end": Object {
"column": 9,
"line": 4,
"line": 3,
},
"filename": "<basedir>/packages/pug-lexer/test/cases/interpolation.escape.pug",
"start": Object {
"column": 5,
"line": 4,
"line": 3,
},
},
"type": "text",
Expand All @@ -26796,12 +26782,12 @@ Array [
"loc": Object {
"end": Object {
"column": 3,
"line": 5,
"line": 4,
},
"filename": "<basedir>/packages/pug-lexer/test/cases/interpolation.escape.pug",
"start": Object {
"column": 1,
"line": 5,
"line": 4,
},
},
"type": "newline",
Expand All @@ -26810,12 +26796,12 @@ Array [
"loc": Object {
"end": Object {
"column": 13,
"line": 5,
"line": 4,
},
"filename": "<basedir>/packages/pug-lexer/test/cases/interpolation.escape.pug",
"start": Object {
"column": 5,
"line": 5,
"line": 4,
},
},
"type": "text",
Expand All @@ -26825,41 +26811,41 @@ Array [
"loc": Object {
"end": Object {
"column": 3,
"line": 6,
"line": 5,
},
"filename": "<basedir>/packages/pug-lexer/test/cases/interpolation.escape.pug",
"start": Object {
"column": 1,
"line": 6,
"line": 5,
},
},
"type": "newline",
},
Object {
"loc": Object {
"end": Object {
"column": 9,
"line": 6,
"column": 13,
"line": 5,
},
"filename": "<basedir>/packages/pug-lexer/test/cases/interpolation.escape.pug",
"start": Object {
"column": 5,
"line": 6,
"line": 5,
},
},
"type": "text",
"val": "here",
"val": "!{here}",
},
Object {
"loc": Object {
"end": Object {
"column": 3,
"line": 7,
"line": 6,
},
"filename": "<basedir>/packages/pug-lexer/test/cases/interpolation.escape.pug",
"start": Object {
"column": 1,
"line": 7,
"line": 6,
},
},
"type": "newline",
Expand All @@ -26868,12 +26854,12 @@ Array [
"loc": Object {
"end": Object {
"column": 11,
"line": 7,
"line": 6,
},
"filename": "<basedir>/packages/pug-lexer/test/cases/interpolation.escape.pug",
"start": Object {
"column": 5,
"line": 7,
"line": 6,
},
},
"type": "text",
Expand All @@ -26884,12 +26870,12 @@ Array [
"loc": Object {
"end": Object {
"column": 31,
"line": 7,
"line": 6,
},
"filename": "<basedir>/packages/pug-lexer/test/cases/interpolation.escape.pug",
"start": Object {
"column": 11,
"line": 7,
"line": 6,
},
},
"mustEscape": true,
Expand All @@ -26899,12 +26885,12 @@ Array [
Object {
"loc": Object {
"end": Object {
"column": 31,
"column": 1,
"line": 7,
},
"filename": "<basedir>/packages/pug-lexer/test/cases/interpolation.escape.pug",
"start": Object {
"column": 31,
"column": 1,
"line": 7,
},
},
Expand All @@ -26913,12 +26899,12 @@ Array [
Object {
"loc": Object {
"end": Object {
"column": 31,
"column": 1,
"line": 7,
},
"filename": "<basedir>/packages/pug-lexer/test/cases/interpolation.escape.pug",
"start": Object {
"column": 31,
"column": 1,
"line": 7,
},
},
Expand Down
5 changes: 2 additions & 3 deletions packages/pug-lexer/test/cases/interpolation.escape.pug
@@ -1,7 +1,6 @@

- var id = 42;
foo
| some
| \#{text}
| here
| My ID #{"is {" + id + "}"}
| \!{here}
| My ID #{"is {" + id + "}"}