From ef40dea221daf3e00dcc4f798b6b145f56879330 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Fri, 18 Sep 2020 17:58:58 +0800 Subject: [PATCH 1/4] update acorn and parse expression as module script --- package-lock.json | 6 +-- package.json | 2 +- src/compiler/parse/acorn.ts | 5 +- test/js/samples/import-meta/expected.js | 53 +++++++++++++++++++ test/js/samples/import-meta/input.svelte | 6 +++ .../samples/numeric-seperator/_config.js | 3 ++ .../samples/numeric-seperator/main.svelte | 5 ++ 7 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 test/js/samples/import-meta/expected.js create mode 100644 test/js/samples/import-meta/input.svelte create mode 100644 test/runtime/samples/numeric-seperator/_config.js create mode 100644 test/runtime/samples/numeric-seperator/main.svelte diff --git a/package-lock.json b/package-lock.json index d1ec8d275f2c..2e2a95b362bc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -315,9 +315,9 @@ "dev": true }, "acorn": { - "version": "7.3.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.3.1.tgz", - "integrity": "sha512-tLc0wSnatxAQHVHUapaHdz72pi9KUyHjq5KyHjGg9Y8Ifdc79pTh2XvI6I1/chZbnM7QtNKzh66ooDogPZSleA==", + "version": "7.4.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.0.tgz", + "integrity": "sha512-+G7P8jJmCHr+S+cLfQxygbWhXy+8YTVGzAkpEbcLo2mLoL7tij/VG41QSHACSf5QgYRhMZYHuNc6drJaO0Da+w==", "dev": true }, "acorn-globals": { diff --git a/package.json b/package.json index 20325b4fbfdd..7ebb41fdfb7a 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "@types/node": "^8.10.53", "@typescript-eslint/eslint-plugin": "^3.0.2", "@typescript-eslint/parser": "^3.0.2", - "acorn": "^7.3.1", + "acorn": "^7.4.0", "agadoo": "^1.1.0", "c8": "^5.0.1", "code-red": "^0.1.3", diff --git a/src/compiler/parse/acorn.ts b/src/compiler/parse/acorn.ts index d14721cdabf1..58031c1a1ce1 100644 --- a/src/compiler/parse/acorn.ts +++ b/src/compiler/parse/acorn.ts @@ -3,11 +3,12 @@ import * as code_red from 'code-red'; export const parse = (source: string): Node => code_red.parse(source, { sourceType: 'module', - ecmaVersion: 11, + ecmaVersion: 12, locations: true }); export const parse_expression_at = (source: string, index: number): Node => code_red.parseExpressionAt(source, index, { - ecmaVersion: 11, + sourceType: 'module', + ecmaVersion: 12, locations: true }); \ No newline at end of file diff --git a/test/js/samples/import-meta/expected.js b/test/js/samples/import-meta/expected.js new file mode 100644 index 000000000000..ba77398321cf --- /dev/null +++ b/test/js/samples/import-meta/expected.js @@ -0,0 +1,53 @@ +/* generated by Svelte vX.Y.Z */ +import { + SvelteComponent, + detach, + init, + insert, + noop, + safe_not_equal, + space, + text +} from "svelte/internal"; + +function create_fragment(ctx) { + let t0; + let t1; + let t2_value = import.meta.url + ""; + let t2; + + return { + c() { + t0 = text(/*url*/ ctx[0]); + t1 = space(); + t2 = text(t2_value); + }, + m(target, anchor) { + insert(target, t0, anchor); + insert(target, t1, anchor); + insert(target, t2, anchor); + }, + p: noop, + i: noop, + o: noop, + d(detaching) { + if (detaching) detach(t0); + if (detaching) detach(t1); + if (detaching) detach(t2); + } + }; +} + +function instance($$self) { + const url = import.meta.url; + return [url]; +} + +class Component extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance, create_fragment, safe_not_equal, {}); + } +} + +export default Component; \ No newline at end of file diff --git a/test/js/samples/import-meta/input.svelte b/test/js/samples/import-meta/input.svelte new file mode 100644 index 000000000000..a49e70a66d06 --- /dev/null +++ b/test/js/samples/import-meta/input.svelte @@ -0,0 +1,6 @@ + + +{ url } +{ import.meta.url } diff --git a/test/runtime/samples/numeric-seperator/_config.js b/test/runtime/samples/numeric-seperator/_config.js new file mode 100644 index 000000000000..bc6d7c04f390 --- /dev/null +++ b/test/runtime/samples/numeric-seperator/_config.js @@ -0,0 +1,3 @@ +export default { + html: `2048 2048` +}; diff --git a/test/runtime/samples/numeric-seperator/main.svelte b/test/runtime/samples/numeric-seperator/main.svelte new file mode 100644 index 000000000000..e491b8a10796 --- /dev/null +++ b/test/runtime/samples/numeric-seperator/main.svelte @@ -0,0 +1,5 @@ + + +{num} {2_048} \ No newline at end of file From a8e0a322873583a138a84b3dd24dd049f9d1b422 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Fri, 18 Sep 2020 23:11:47 +0800 Subject: [PATCH 2/4] no missing-declaration warning for import.meta --- src/compiler/compile/nodes/shared/Expression.ts | 2 ++ test/validator/samples/import-meta/errors.json | 1 + test/validator/samples/import-meta/input.svelte | 6 ++++++ 3 files changed, 9 insertions(+) create mode 100644 test/validator/samples/import-meta/errors.json create mode 100644 test/validator/samples/import-meta/input.svelte diff --git a/src/compiler/compile/nodes/shared/Expression.ts b/src/compiler/compile/nodes/shared/Expression.ts index bbbc1b2f2d15..834287bb63f4 100644 --- a/src/compiler/compile/nodes/shared/Expression.ts +++ b/src/compiler/compile/nodes/shared/Expression.ts @@ -64,6 +64,8 @@ export default class Expression { enter(node: any, parent: any, key: string) { // don't manipulate shorthand props twice if (key === 'value' && parent.shorthand) return; + // don't manipulate `import.meta`, `new.target` + if (node.type === 'MetaProperty') return this.skip(); if (map.has(node)) { scope = map.get(node); diff --git a/test/validator/samples/import-meta/errors.json b/test/validator/samples/import-meta/errors.json new file mode 100644 index 000000000000..0637a088a01e --- /dev/null +++ b/test/validator/samples/import-meta/errors.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/validator/samples/import-meta/input.svelte b/test/validator/samples/import-meta/input.svelte new file mode 100644 index 000000000000..a49e70a66d06 --- /dev/null +++ b/test/validator/samples/import-meta/input.svelte @@ -0,0 +1,6 @@ + + +{ url } +{ import.meta.url } From 2081cdb894587016806d3c59d906e51a02c9e802 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Fri, 18 Sep 2020 12:04:00 -0400 Subject: [PATCH 3/4] update changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9569b4ff7b80..8d953183bfd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Svelte changelog +## Unreleased + +* Support `_` as numeric separator ([#5407](https://github.com/sveltejs/svelte/issues/5407)) +* Support `import.meta` in template expressions ([#5422](https://github.com/sveltejs/svelte/issues/5422)) + ## 3.25.1 * Fix specificity of certain styles involving a child selector ([#4795](https://github.com/sveltejs/svelte/issues/4795)) From bb91ee98daf9efbdf7c18c24ab5dc77c1d4f1abb Mon Sep 17 00:00:00 2001 From: Conduitry Date: Fri, 18 Sep 2020 12:05:01 -0400 Subject: [PATCH 4/4] format --- test/js/samples/import-meta/input.svelte | 4 ++-- test/validator/samples/import-meta/input.svelte | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/js/samples/import-meta/input.svelte b/test/js/samples/import-meta/input.svelte index a49e70a66d06..a5ce32dd7774 100644 --- a/test/js/samples/import-meta/input.svelte +++ b/test/js/samples/import-meta/input.svelte @@ -2,5 +2,5 @@ const url = import.meta.url; -{ url } -{ import.meta.url } +{url} +{import.meta.url} diff --git a/test/validator/samples/import-meta/input.svelte b/test/validator/samples/import-meta/input.svelte index a49e70a66d06..a5ce32dd7774 100644 --- a/test/validator/samples/import-meta/input.svelte +++ b/test/validator/samples/import-meta/input.svelte @@ -2,5 +2,5 @@ const url = import.meta.url; -{ url } -{ import.meta.url } +{url} +{import.meta.url}