Skip to content

Commit

Permalink
fix: Fix pug-lexer parsed escaped interpolations incorrectly (#3299)
Browse files Browse the repository at this point in the history
* fix: Fix escaped interpolation returning `#{}` but not `!{}`

* test: Update test case and snapshot of `pug-lexer/../interpolation.escape.pug`

* style: Fix prettier format
  • Loading branch information
shirohana committed Feb 28, 2021
1 parent 60b1b15 commit 29a53c5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 48 deletions.
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 + "}"}

0 comments on commit 29a53c5

Please sign in to comment.