feat(compiler): ensure interpolation expressions are wrapped with toString()
This commit is contained in:
@@ -3835,6 +3835,7 @@ Object {
|
||||
"children": Array [
|
||||
Object {
|
||||
"content": "a < b",
|
||||
"isInterpolation": true,
|
||||
"isStatic": false,
|
||||
"loc": Object {
|
||||
"end": Object {
|
||||
@@ -6873,6 +6874,7 @@ Object {
|
||||
"children": Array [
|
||||
Object {
|
||||
"content": "'</div>'",
|
||||
"isInterpolation": true,
|
||||
"isStatic": false,
|
||||
"loc": Object {
|
||||
"end": Object {
|
||||
@@ -7223,6 +7225,7 @@ Object {
|
||||
"children": Array [
|
||||
Object {
|
||||
"content": "",
|
||||
"isInterpolation": true,
|
||||
"isStatic": true,
|
||||
"loc": Object {
|
||||
"end": Object {
|
||||
@@ -7360,6 +7363,7 @@ Object {
|
||||
Object {
|
||||
"arg": Object {
|
||||
"content": "class",
|
||||
"isInterpolation": false,
|
||||
"isStatic": true,
|
||||
"loc": Object {
|
||||
"end": Object {
|
||||
@@ -7378,6 +7382,7 @@ Object {
|
||||
},
|
||||
"exp": Object {
|
||||
"content": "{ some: condition }",
|
||||
"isInterpolation": false,
|
||||
"isStatic": false,
|
||||
"loc": Object {
|
||||
"end": Object {
|
||||
@@ -7438,6 +7443,7 @@ Object {
|
||||
Object {
|
||||
"arg": Object {
|
||||
"content": "style",
|
||||
"isInterpolation": false,
|
||||
"isStatic": true,
|
||||
"loc": Object {
|
||||
"end": Object {
|
||||
@@ -7456,6 +7462,7 @@ Object {
|
||||
},
|
||||
"exp": Object {
|
||||
"content": "{ color: 'red' }",
|
||||
"isInterpolation": false,
|
||||
"isStatic": false,
|
||||
"loc": Object {
|
||||
"end": Object {
|
||||
@@ -7542,6 +7549,7 @@ Object {
|
||||
Object {
|
||||
"arg": Object {
|
||||
"content": "style",
|
||||
"isInterpolation": false,
|
||||
"isStatic": true,
|
||||
"loc": Object {
|
||||
"end": Object {
|
||||
@@ -7560,6 +7568,7 @@ Object {
|
||||
},
|
||||
"exp": Object {
|
||||
"content": "{ color: 'red' }",
|
||||
"isInterpolation": false,
|
||||
"isStatic": false,
|
||||
"loc": Object {
|
||||
"end": Object {
|
||||
@@ -7639,6 +7648,7 @@ Object {
|
||||
Object {
|
||||
"arg": Object {
|
||||
"content": "class",
|
||||
"isInterpolation": false,
|
||||
"isStatic": true,
|
||||
"loc": Object {
|
||||
"end": Object {
|
||||
@@ -7657,6 +7667,7 @@ Object {
|
||||
},
|
||||
"exp": Object {
|
||||
"content": "{ some: condition }",
|
||||
"isInterpolation": false,
|
||||
"isStatic": false,
|
||||
"loc": Object {
|
||||
"end": Object {
|
||||
|
||||
@@ -13,7 +13,7 @@ describe('compiler: codegen', () => {
|
||||
with (this) {
|
||||
return [
|
||||
"hello ",
|
||||
world
|
||||
toString(world)
|
||||
]
|
||||
}
|
||||
}`
|
||||
@@ -25,7 +25,7 @@ describe('compiler: codegen', () => {
|
||||
const consumer = await new SourceMapConsumer(map as RawSourceMap)
|
||||
const pos = consumer.originalPositionFor({
|
||||
line: 5,
|
||||
column: 6
|
||||
column: 15
|
||||
})
|
||||
expect(pos).toMatchObject({
|
||||
line: 1,
|
||||
|
||||
@@ -296,6 +296,7 @@ describe('compiler: parse', () => {
|
||||
type: NodeTypes.EXPRESSION,
|
||||
content: 'message',
|
||||
isStatic: false,
|
||||
isInterpolation: true,
|
||||
loc: {
|
||||
start: { offset: 0, line: 1, column: 1 },
|
||||
end: { offset: 11, line: 1, column: 12 },
|
||||
@@ -312,6 +313,7 @@ describe('compiler: parse', () => {
|
||||
type: NodeTypes.EXPRESSION,
|
||||
content: 'a<b',
|
||||
isStatic: false,
|
||||
isInterpolation: true,
|
||||
loc: {
|
||||
start: { offset: 0, line: 1, column: 1 },
|
||||
end: { offset: 9, line: 1, column: 10 },
|
||||
@@ -329,6 +331,7 @@ describe('compiler: parse', () => {
|
||||
type: NodeTypes.EXPRESSION,
|
||||
content: 'a<b',
|
||||
isStatic: false,
|
||||
isInterpolation: true,
|
||||
loc: {
|
||||
start: { offset: 0, line: 1, column: 1 },
|
||||
end: { offset: 9, line: 1, column: 10 },
|
||||
@@ -339,6 +342,7 @@ describe('compiler: parse', () => {
|
||||
type: NodeTypes.EXPRESSION,
|
||||
content: 'c>d',
|
||||
isStatic: false,
|
||||
isInterpolation: true,
|
||||
loc: {
|
||||
start: { offset: 9, line: 1, column: 10 },
|
||||
end: { offset: 18, line: 1, column: 19 },
|
||||
@@ -356,6 +360,7 @@ describe('compiler: parse', () => {
|
||||
type: NodeTypes.EXPRESSION,
|
||||
content: '"</div>"',
|
||||
isStatic: false,
|
||||
isInterpolation: true,
|
||||
loc: {
|
||||
start: { offset: 5, line: 1, column: 6 },
|
||||
end: { offset: 19, line: 1, column: 20 },
|
||||
@@ -887,6 +892,7 @@ describe('compiler: parse', () => {
|
||||
type: NodeTypes.EXPRESSION,
|
||||
content: 'a',
|
||||
isStatic: false,
|
||||
isInterpolation: false,
|
||||
loc: {
|
||||
start: { offset: 10, line: 1, column: 11 },
|
||||
end: { offset: 13, line: 1, column: 14 },
|
||||
@@ -909,9 +915,10 @@ describe('compiler: parse', () => {
|
||||
type: NodeTypes.DIRECTIVE,
|
||||
name: 'on',
|
||||
arg: {
|
||||
type: 4,
|
||||
type: NodeTypes.EXPRESSION,
|
||||
content: 'click',
|
||||
isStatic: true,
|
||||
isInterpolation: false,
|
||||
loc: {
|
||||
source: 'click',
|
||||
start: {
|
||||
@@ -980,9 +987,10 @@ describe('compiler: parse', () => {
|
||||
type: NodeTypes.DIRECTIVE,
|
||||
name: 'on',
|
||||
arg: {
|
||||
type: 4,
|
||||
type: NodeTypes.EXPRESSION,
|
||||
content: 'click',
|
||||
isStatic: true,
|
||||
isInterpolation: false,
|
||||
loc: {
|
||||
source: 'click',
|
||||
start: {
|
||||
@@ -1015,9 +1023,10 @@ describe('compiler: parse', () => {
|
||||
type: NodeTypes.DIRECTIVE,
|
||||
name: 'bind',
|
||||
arg: {
|
||||
type: 4,
|
||||
type: NodeTypes.EXPRESSION,
|
||||
content: 'a',
|
||||
isStatic: true,
|
||||
isInterpolation: false,
|
||||
loc: {
|
||||
source: 'a',
|
||||
start: {
|
||||
@@ -1037,6 +1046,7 @@ describe('compiler: parse', () => {
|
||||
type: NodeTypes.EXPRESSION,
|
||||
content: 'b',
|
||||
isStatic: false,
|
||||
isInterpolation: false,
|
||||
loc: {
|
||||
start: { offset: 8, line: 1, column: 9 },
|
||||
end: { offset: 9, line: 1, column: 10 },
|
||||
@@ -1059,9 +1069,10 @@ describe('compiler: parse', () => {
|
||||
type: NodeTypes.DIRECTIVE,
|
||||
name: 'bind',
|
||||
arg: {
|
||||
type: 4,
|
||||
type: NodeTypes.EXPRESSION,
|
||||
content: 'a',
|
||||
isStatic: true,
|
||||
isInterpolation: false,
|
||||
loc: {
|
||||
source: 'a',
|
||||
start: {
|
||||
@@ -1081,6 +1092,7 @@ describe('compiler: parse', () => {
|
||||
type: NodeTypes.EXPRESSION,
|
||||
content: 'b',
|
||||
isStatic: false,
|
||||
isInterpolation: false,
|
||||
loc: {
|
||||
start: { offset: 13, line: 1, column: 14 },
|
||||
end: { offset: 14, line: 1, column: 15 },
|
||||
@@ -1103,9 +1115,10 @@ describe('compiler: parse', () => {
|
||||
type: NodeTypes.DIRECTIVE,
|
||||
name: 'on',
|
||||
arg: {
|
||||
type: 4,
|
||||
type: NodeTypes.EXPRESSION,
|
||||
content: 'a',
|
||||
isStatic: true,
|
||||
isInterpolation: false,
|
||||
loc: {
|
||||
source: 'a',
|
||||
start: {
|
||||
@@ -1125,6 +1138,7 @@ describe('compiler: parse', () => {
|
||||
type: NodeTypes.EXPRESSION,
|
||||
content: 'b',
|
||||
isStatic: false,
|
||||
isInterpolation: false,
|
||||
loc: {
|
||||
start: { offset: 8, line: 1, column: 9 },
|
||||
end: { offset: 9, line: 1, column: 10 },
|
||||
@@ -1147,9 +1161,10 @@ describe('compiler: parse', () => {
|
||||
type: NodeTypes.DIRECTIVE,
|
||||
name: 'on',
|
||||
arg: {
|
||||
type: 4,
|
||||
type: NodeTypes.EXPRESSION,
|
||||
content: 'a',
|
||||
isStatic: true,
|
||||
isInterpolation: false,
|
||||
loc: {
|
||||
source: 'a',
|
||||
start: {
|
||||
@@ -1169,6 +1184,7 @@ describe('compiler: parse', () => {
|
||||
type: NodeTypes.EXPRESSION,
|
||||
content: 'b',
|
||||
isStatic: false,
|
||||
isInterpolation: false,
|
||||
loc: {
|
||||
start: { offset: 14, line: 1, column: 15 },
|
||||
end: { offset: 15, line: 1, column: 16 },
|
||||
|
||||
@@ -2,16 +2,9 @@ import { SourceMapConsumer } from 'source-map'
|
||||
import { compile } from '../../src'
|
||||
|
||||
test(`should work`, async () => {
|
||||
const { code, map } = compile(
|
||||
`<div v-for="i in foo">
|
||||
{{ ({ a }, b) => a + b + i + c }} {{ i + 'fe' }} {{ i }}
|
||||
</div>
|
||||
<p>{{ i }}</p>
|
||||
`,
|
||||
{
|
||||
prefixIdentifiers: true
|
||||
}
|
||||
)
|
||||
const { code, map } = compile(`<div>{{ foo }} bar</div>`, {
|
||||
prefixIdentifiers: true
|
||||
})
|
||||
console.log(code)
|
||||
const consumer = await new SourceMapConsumer(map!)
|
||||
const pos = consumer.originalPositionFor({
|
||||
|
||||
Reference in New Issue
Block a user