diff --git a/package-lock.json b/package-lock.json index ce46cbb8b8..9d6d48ac1a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "svelte", - "version": "3.0.0-alpha13", + "version": "3.0.0-alpha16", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -217,19 +217,16 @@ "dev": true }, "acorn": { - "version": "5.7.3", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.3.tgz", - "integrity": "sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw==", + "version": "6.0.5", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.0.5.tgz", + "integrity": "sha512-i33Zgp3XWtmZBMNvCr4azvOFeWVw1Rk6p3hfi3LUDvIFraOMywb1kAtrbi+med14m4Xfpqm3zRZMT+c0FNE7kg==", "dev": true }, "acorn-dynamic-import": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/acorn-dynamic-import/-/acorn-dynamic-import-3.0.0.tgz", - "integrity": "sha512-zVWV8Z8lislJoOKKqdNMOB+s6+XV5WERty8MnKBeFgwA+19XJjJHs2RP5dzM57FftIs+jQnRToLiWazKr6sSWg==", - "dev": true, - "requires": { - "acorn": "^5.0.0" - } + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/acorn-dynamic-import/-/acorn-dynamic-import-4.0.0.tgz", + "integrity": "sha512-d3OEjQV4ROpoflsnUA8HozoIR504TFxNivYEUi6uwz0IYhBkTDXGuWlNdMtybRt3nqVx/L6XqMt0FxkXuWKZhw==", + "dev": true }, "acorn-globals": { "version": "4.3.0", @@ -2934,6 +2931,14 @@ "whatwg-url": "^6.4.1", "ws": "^5.2.0", "xml-name-validator": "^3.0.0" + }, + "dependencies": { + "acorn": { + "version": "5.7.3", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.3.tgz", + "integrity": "sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw==", + "dev": true + } } }, "jsesc": { diff --git a/package.json b/package.json index d4766ee63b..4de67b4346 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svelte", - "version": "3.0.0-alpha15", + "version": "3.0.0-alpha16", "description": "The magical disappearing UI framework", "module": "index.mjs", "main": "index.js", @@ -55,8 +55,8 @@ "devDependencies": { "@types/mocha": "^5.2.0", "@types/node": "^10.5.5", - "acorn": "^5.4.1", - "acorn-dynamic-import": "^3.0.0", + "acorn": "^6.0.5", + "acorn-dynamic-import": "^4.0.0", "agadoo": "^1.0.1", "codecov": "^3.0.0", "css-tree": "1.0.0-alpha22", diff --git a/src/compile/Component.ts b/src/compile/Component.ts index 541814a1ff..c9c985339f 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -170,6 +170,7 @@ export default class Component { const props = [...this.template_references]; this.declarations.push(...props); addToSet(this.writable_declarations, this.template_references); + addToSet(this.userVars, this.template_references); this.props = props.map(name => ({ name, diff --git a/src/compile/render-dom/wrappers/Window.ts b/src/compile/render-dom/wrappers/Window.ts index beacaaf254..7bf41cdc0b 100644 --- a/src/compile/render-dom/wrappers/Window.ts +++ b/src/compile/render-dom/wrappers/Window.ts @@ -114,7 +114,7 @@ export default class WindowWrapper extends Wrapper { }); block.event_listeners.push(deindent` - @addListener(window, "${event}", ctx.${handler_name}); + @addListener(window, "${event}", ctx.${handler_name}) `); } @@ -179,4 +179,4 @@ export default class WindowWrapper extends Wrapper { `); } } -} \ No newline at end of file +} diff --git a/src/parse/acorn.ts b/src/parse/acorn.ts new file mode 100644 index 0000000000..2f0cd2ec20 --- /dev/null +++ b/src/parse/acorn.ts @@ -0,0 +1,15 @@ +import * as acorn from 'acorn'; +import dynamicImport from 'acorn-dynamic-import'; + +const Parser = acorn.Parser.extend(dynamicImport); + +export const parse = (source: string, options: any) => Parser.parse(source, { + sourceType: 'module', + ecmaVersion: 9, + preserveParens: true +}); + +export const parseExpressionAt = (source: string, index: number, options: any) => Parser.parseExpressionAt(source, index, { + ecmaVersion: 9, + preserveParens: true +}); \ No newline at end of file diff --git a/src/parse/read/expression.ts b/src/parse/read/expression.ts index 0c7ee2ac31..3bfad75e6a 100644 --- a/src/parse/read/expression.ts +++ b/src/parse/read/expression.ts @@ -1,4 +1,4 @@ -import { parseExpressionAt } from 'acorn'; +import { parseExpressionAt } from '../acorn'; import { Parser } from '../index'; const literals = new Map([['true', true], ['false', false], ['null', null]]); @@ -31,13 +31,7 @@ export default function readExpression(parser: Parser) { parser.index = start; try { - const node = parseExpressionAt(parser.template, parser.index, { - ecmaVersion: 9, - preserveParens: true, - plugins: { - dynamicImport: true - } - }); + const node = parseExpressionAt(parser.template, parser.index); parser.index = node.end; return node; diff --git a/src/parse/read/script.ts b/src/parse/read/script.ts index b6d6cd53a8..11337db513 100644 --- a/src/parse/read/script.ts +++ b/src/parse/read/script.ts @@ -1,13 +1,10 @@ -import * as acorn from 'acorn'; -import injectDynamicImport from 'acorn-dynamic-import/src/inject'; +import * as acorn from '../acorn'; import repeat from '../../utils/repeat'; import { Parser } from '../index'; import { Node } from '../../interfaces'; const scriptClosingTag = ''; -injectDynamicImport(acorn); - export default function readScript(parser: Parser, start: number, attributes: Node[]) { const scriptStart = parser.index; const scriptEnd = parser.template.indexOf(scriptClosingTag, scriptStart); @@ -24,13 +21,7 @@ export default function readScript(parser: Parser, start: number, attributes: No let ast; try { - ast = acorn.parse(source, { - ecmaVersion: 9, - sourceType: 'module', - plugins: { - dynamicImport: true - } - }); + ast = acorn.parse(source); } catch (err) { parser.acornError(err); } diff --git a/src/parse/state/tag.ts b/src/parse/state/tag.ts index 5465f6f3e1..1ed7b3d1e8 100644 --- a/src/parse/state/tag.ts +++ b/src/parse/state/tag.ts @@ -395,7 +395,7 @@ function readAttribute(parser: Parser, uniqueNames: Set) { parser.allowWhitespace(); const colon_index = name.indexOf(':'); - const type = colon_index !== 1 && get_directive_type(name.slice(0, colon_index)); + const type = colon_index !== -1 && get_directive_type(name.slice(0, colon_index)); let value: any[] | true = true; if (parser.eat('=')) { diff --git a/test/js/samples/deconflict-builtins/expected.js b/test/js/samples/deconflict-builtins/expected.js index 3f73d83574..fe2a247d3d 100644 --- a/test/js/samples/deconflict-builtins/expected.js +++ b/test/js/samples/deconflict-builtins/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { SvelteComponent as SvelteComponent_1, append, createComment, createElement, createText, destroyEach, detachNode, flush, init, insert, run, safe_not_equal, setData } from "svelte/internal"; +import { SvelteComponent as SvelteComponent_1, append, createComment, createElement as createElement_1, createText, destroyEach, detachNode, flush, init, insert, run, safe_not_equal, setData } from "svelte/internal"; function get_each_context(ctx, list, i) { const child_ctx = Object.create(ctx); @@ -13,7 +13,7 @@ function create_each_block($$, ctx) { return { c() { - span = createElement("span"); + span = createElement_1("span"); text = createText(text_value); }, diff --git a/test/js/samples/select-dynamic-value/expected.js b/test/js/samples/select-dynamic-value/expected.js index 6788f18fd0..cce868ee40 100644 --- a/test/js/samples/select-dynamic-value/expected.js +++ b/test/js/samples/select-dynamic-value/expected.js @@ -2,7 +2,7 @@ import { SvelteComponent as SvelteComponent_1, append, createElement, detachNode, flush, init, insert, run, safe_not_equal } from "svelte/internal"; function create_fragment($$, ctx) { - var select, option0, option1, select_value_value, current; + var select, option0, option1, select_value_value, current_1; return { c() { @@ -32,7 +32,7 @@ function create_fragment($$, ctx) { } } - current = true; + current_1 = true; }, p(changed, ctx) { @@ -49,7 +49,7 @@ function create_fragment($$, ctx) { }, i(target, anchor) { - if (current) return; + if (current_1) return; this.m(target, anchor); }, diff --git a/test/runtime/samples/event-handler-deconflicted/_config.js b/test/runtime/samples/event-handler-deconflicted/_config.js new file mode 100644 index 0000000000..69151997a0 --- /dev/null +++ b/test/runtime/samples/event-handler-deconflicted/_config.js @@ -0,0 +1,11 @@ +export default { + preserveIdentifiers: true, + + props: { + click_handler: 'x' + }, + + html: ` + + ` +}; diff --git a/test/runtime/samples/event-handler-deconflicted/main.html b/test/runtime/samples/event-handler-deconflicted/main.html new file mode 100644 index 0000000000..38c923794e --- /dev/null +++ b/test/runtime/samples/event-handler-deconflicted/main.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/runtime/samples/prop-not-action/Nested.html b/test/runtime/samples/prop-not-action/Nested.html new file mode 100644 index 0000000000..b1029d2ad5 --- /dev/null +++ b/test/runtime/samples/prop-not-action/Nested.html @@ -0,0 +1 @@ +

Hello {user.name}!

\ No newline at end of file diff --git a/test/runtime/samples/prop-not-action/_config.js b/test/runtime/samples/prop-not-action/_config.js new file mode 100644 index 0000000000..17ab47b584 --- /dev/null +++ b/test/runtime/samples/prop-not-action/_config.js @@ -0,0 +1,9 @@ +export default { + props: { + currentUser: { name: 'world' } + }, + + html: ` +

Hello world!

+ ` +}; \ No newline at end of file diff --git a/test/runtime/samples/prop-not-action/main.html b/test/runtime/samples/prop-not-action/main.html new file mode 100644 index 0000000000..c0ddd01e79 --- /dev/null +++ b/test/runtime/samples/prop-not-action/main.html @@ -0,0 +1,6 @@ + + + \ No newline at end of file diff --git a/test/runtime/samples/window-binding-multiple-handlers/_config.js b/test/runtime/samples/window-binding-multiple-handlers/_config.js new file mode 100644 index 0000000000..2f7c6be562 --- /dev/null +++ b/test/runtime/samples/window-binding-multiple-handlers/_config.js @@ -0,0 +1,3 @@ +export default { + html: '' +}; diff --git a/test/runtime/samples/window-binding-multiple-handlers/main.html b/test/runtime/samples/window-binding-multiple-handlers/main.html new file mode 100644 index 0000000000..8b28d53a9f --- /dev/null +++ b/test/runtime/samples/window-binding-multiple-handlers/main.html @@ -0,0 +1,2 @@ + +