Skip to content

Commit

Permalink
Merge pull request #316 from marko-js/async-script-tag
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey authored Dec 11, 2024
2 parents 3bf2264 + 11f8953 commit 3a1c37b
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 215 deletions.
8 changes: 8 additions & 0 deletions .changeset/nice-terms-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@marko/language-server": patch
"@marko/language-tools": patch
"@marko/type-check": patch
"marko-vscode": patch
---

Allow await inside script tags.
350 changes: 170 additions & 180 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/language-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
"dependencies": {
"@luxass/strip-json-comments": "^1.3.2",
"@marko/language-tools": "^2.5.2",
"@marko/babel-utils": "^6.6.1",
"@marko/compiler": "^5.38.3",
"@marko/babel-utils": "^6.6.2",
"@marko/compiler": "^5.38.4",
"@marko/translator-default": "^6.1.2",
"htmljs-parser": "^5.5.3",
"marko": "^5.36.3",
"prettier": "^3.4.2",
"prettier-plugin-marko": "^3.1.7",
"prettier-plugin-marko": "^3.1.9",
"relative-import-path": "^1.0.0",
"typescript": "^5.7.2",
"vscode-css-languageservice": "^6.3.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,57 @@
## Hovers
### Ln 9, Col 17
### Ln 10, Col 17
```marko
7 | <const/y="hi"/>
8 | <script>
> 9 | console.log(x);
8 | <const/promise=Promise.resolve("world")/>
9 | <script>
> 10 | console.log(x);
| ^ const x: number
10 | // ^?
11 | console.log(y);
12 | // ^?
11 | // ^?
12 | console.log(y);
13 | // ^?
```

### Ln 11, Col 17
### Ln 12, Col 17
```marko
9 | console.log(x);
10 | // ^?
> 11 | console.log(y);
10 | console.log(x);
11 | // ^?
> 12 | console.log(y);
| ^ const y: string
12 | // ^?
13 | console.log(input.name);
14 | // ^?
13 | // ^?
14 | console.log(input.name);
15 | // ^?
```

### Ln 13, Col 23
### Ln 14, Col 23
```marko
11 | console.log(y);
12 | // ^?
> 13 | console.log(input.name);
12 | console.log(y);
13 | // ^?
> 14 | console.log(input.name);
| ^ (property) Input<T>.name: T extends string
14 | // ^?
15 | x = 2;
16 | y = "bye";
15 | // ^?
16 |
17 | const resolved = await promise;
```

### Ln 18, Col 17
```marko
16 |
17 | const resolved = await promise;
> 18 | console.log(resolved);
| ^ const resolved: string
19 | // ^?
20 | x = 2;
21 | y = "bye";
```

## Diagnostics
### Ln 16, Col 5
### Ln 21, Col 5
```marko
14 | // ^?
15 | x = 2;
> 16 | y = "bye";
19 | // ^?
20 | x = 2;
> 21 | y = "bye";
| ^ Cannot assign to 'y' because it is a read-only property.
17 | </script>
18 | </div>
19 |
22 | </script>
23 | </div>
24 |
```

Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ export interface Input<T extends string> {
<div>
<let/x=1/>
<const/y="hi"/>
<const/promise=Promise.resolve("world")/>
<script>
console.log(x);
// ^?
console.log(y);
// ^?
console.log(input.name);
// ^?
const resolved = await promise;
console.log(resolved);
// ^?
x = 2;
y = "bye";
</script>
Expand Down
2 changes: 1 addition & 1 deletion packages/language-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"devDependencies": {
"@babel/code-frame": "^7.26.2",
"@marko/compiler": "^5.38.3",
"@marko/compiler": "^5.38.4",
"@marko/translator-default": "^6.1.2",
"@types/babel__code-frame": "^7.0.6",
"@typescript/vfs": "^1.6.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/language-tools/src/extractors/script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ constructor(_?: Return) {}
let body: ProcessedBody | undefined;

if (isScript) {
this.#extractor.write("value(){");
this.#extractor.write("async value(){");
this.#copyWithMutationsReplaced({
start: tag.body[0].start,
end: tag.body[tag.body.length - 1].end,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ export function crawlProgramScope(parsed: Parsed, scriptParser: ScriptParser) {
checkForMutations(
parentScope,
scriptParser.expressionAt(
child.body[0].start - "()=>{\n".length,
`()=>{\n${read({
child.body[0].start - "async ()=>{\n".length,
`async ()=>{\n${read({
start: child.body[0].start,
end: child.body[child.body.length - 1].end,
})}\n}`,
Expand Down

0 comments on commit 3a1c37b

Please sign in to comment.