From 0f7ae264e4e682b56c02ac184c96fb87e0d25359 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Sun, 3 Feb 2019 20:39:00 -0500 Subject: [PATCH] insert semicolon where necessary when initing props - fixes #2037 --- src/compile/Component.ts | 11 ++++++++--- .../samples/prop-without-semicolon-b/_config.js | 7 +++++++ .../samples/prop-without-semicolon-b/main.html | 6 ++++++ 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 test/runtime/samples/prop-without-semicolon-b/_config.js create mode 100644 test/runtime/samples/prop-without-semicolon-b/main.html diff --git a/src/compile/Component.ts b/src/compile/Component.ts index c9304ee54a..74c0b2b54c 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -744,10 +744,14 @@ export default class Component { }); } + const suffix = code.original[declarator.end] === ';' + ? ` = $$props` + : ` = $$props;` + if (declarator.id.end === declarator.end) { - code.appendLeft(declarator.end, ' = $$props'); + code.appendLeft(declarator.end, suffix); } else { - code.overwrite(declarator.id.end, declarator.end, ' = $$props'); + code.overwrite(declarator.id.end, declarator.end, suffix); } } @@ -823,7 +827,8 @@ export default class Component { }); if (combining) { - code.appendLeft(c, ' } = $$props'); + const suffix = code.original[c] === ';' ? ` } = $$props` : ` } = $$props;`; + code.appendLeft(c, suffix); } }); } diff --git a/test/runtime/samples/prop-without-semicolon-b/_config.js b/test/runtime/samples/prop-without-semicolon-b/_config.js new file mode 100644 index 0000000000..7104dc2b2d --- /dev/null +++ b/test/runtime/samples/prop-without-semicolon-b/_config.js @@ -0,0 +1,7 @@ +export default { + props: { + name: 'world' + }, + + html: `

Hello world!

` +}; \ No newline at end of file diff --git a/test/runtime/samples/prop-without-semicolon-b/main.html b/test/runtime/samples/prop-without-semicolon-b/main.html new file mode 100644 index 0000000000..671fb95186 --- /dev/null +++ b/test/runtime/samples/prop-without-semicolon-b/main.html @@ -0,0 +1,6 @@ +

Hello {name}!

+ + \ No newline at end of file