Skip to content

Commit aef5671

Browse files
authored
update acorn and parse expression as module script (#5423)
1 parent 5f93853 commit aef5671

File tree

11 files changed

+88
-6
lines changed

11 files changed

+88
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Svelte changelog
22

3+
## Unreleased
4+
5+
* Support `_` as numeric separator ([#5407](https://github.com/sveltejs/svelte/issues/5407))
6+
* Support `import.meta` in template expressions ([#5422](https://github.com/sveltejs/svelte/issues/5422))
7+
38
## 3.25.1
49

510
* Fix specificity of certain styles involving a child selector ([#4795](https://github.com/sveltejs/svelte/issues/4795))

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"@types/node": "^8.10.53",
6969
"@typescript-eslint/eslint-plugin": "^3.0.2",
7070
"@typescript-eslint/parser": "^3.0.2",
71-
"acorn": "^7.3.1",
71+
"acorn": "^7.4.0",
7272
"agadoo": "^1.1.0",
7373
"c8": "^5.0.1",
7474
"code-red": "^0.1.3",

src/compiler/compile/nodes/shared/Expression.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ export default class Expression {
6464
enter(node: any, parent: any, key: string) {
6565
// don't manipulate shorthand props twice
6666
if (key === 'value' && parent.shorthand) return;
67+
// don't manipulate `import.meta`, `new.target`
68+
if (node.type === 'MetaProperty') return this.skip();
6769

6870
if (map.has(node)) {
6971
scope = map.get(node);

src/compiler/parse/acorn.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import * as code_red from 'code-red';
33

44
export const parse = (source: string): Node => code_red.parse(source, {
55
sourceType: 'module',
6-
ecmaVersion: 11,
6+
ecmaVersion: 12,
77
locations: true
88
});
99

1010
export const parse_expression_at = (source: string, index: number): Node => code_red.parseExpressionAt(source, index, {
11-
ecmaVersion: 11,
11+
sourceType: 'module',
12+
ecmaVersion: 12,
1213
locations: true
1314
});
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* generated by Svelte vX.Y.Z */
2+
import {
3+
SvelteComponent,
4+
detach,
5+
init,
6+
insert,
7+
noop,
8+
safe_not_equal,
9+
space,
10+
text
11+
} from "svelte/internal";
12+
13+
function create_fragment(ctx) {
14+
let t0;
15+
let t1;
16+
let t2_value = import.meta.url + "";
17+
let t2;
18+
19+
return {
20+
c() {
21+
t0 = text(/*url*/ ctx[0]);
22+
t1 = space();
23+
t2 = text(t2_value);
24+
},
25+
m(target, anchor) {
26+
insert(target, t0, anchor);
27+
insert(target, t1, anchor);
28+
insert(target, t2, anchor);
29+
},
30+
p: noop,
31+
i: noop,
32+
o: noop,
33+
d(detaching) {
34+
if (detaching) detach(t0);
35+
if (detaching) detach(t1);
36+
if (detaching) detach(t2);
37+
}
38+
};
39+
}
40+
41+
function instance($$self) {
42+
const url = import.meta.url;
43+
return [url];
44+
}
45+
46+
class Component extends SvelteComponent {
47+
constructor(options) {
48+
super();
49+
init(this, options, instance, create_fragment, safe_not_equal, {});
50+
}
51+
}
52+
53+
export default Component;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script>
2+
const url = import.meta.url;
3+
</script>
4+
5+
{url}
6+
{import.meta.url}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
html: `2048 2048`
3+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
const num = 2_048;
3+
</script>
4+
5+
{num} {2_048}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script>
2+
const url = import.meta.url;
3+
</script>
4+
5+
{url}
6+
{import.meta.url}

0 commit comments

Comments
 (0)