Skip to content

Commit 29e46fd

Browse files
authored
Merge branch 'rescript-lang:master' into master
2 parents 2133229 + 7861628 commit 29e46fd

File tree

120 files changed

+3246
-2063
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+3246
-2063
lines changed

.github/workflows/ci.yml

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -373,33 +373,35 @@ jobs:
373373
if: matrix.benchmarks
374374
run: ./_build/install/default/bin/syntax_benchmarks | tee tests/benchmark-output.json
375375

376-
- name: Restore previous benchmark data
377-
if: matrix.benchmarks
378-
uses: actions/cache/restore@v4
379-
with:
380-
path: ./tests/benchmark-cache
381-
key: syntax-benchmark-v1
382-
383-
- name: Create new benchmark data and comment on alert
384-
# Do not run for PRs created from other repos as those won't be able to write to the pull request
385-
if: ${{ matrix.benchmarks && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.event.repository.full_name) }}
386-
uses: benchmark-action/github-action-benchmark@v1
387-
with:
388-
name: Syntax Benchmarks
389-
tool: customSmallerIsBetter
390-
output-file-path: tests/benchmark-output.json
391-
external-data-json-path: ./tests/benchmark-cache/benchmark-data.json
392-
github-token: ${{ secrets.GITHUB_TOKEN }}
393-
alert-threshold: "105%"
394-
comment-always: false
395-
comment-on-alert: true
396-
397-
- name: Save benchmark data as new baseline
398-
if: matrix.benchmarks && github.ref == 'refs/heads/master'
399-
uses: actions/cache/save@v4
400-
with:
401-
path: ./tests/benchmark-cache
402-
key: syntax-benchmark-v1
376+
# Benchmarking is disabled for now because of inconsistent run times on different runners
377+
#
378+
# - name: Restore previous benchmark data
379+
# if: matrix.benchmarks
380+
# uses: actions/cache/restore@v4
381+
# with:
382+
# path: ./tests/benchmark-cache
383+
# key: syntax-benchmark-v1
384+
385+
# - name: Create new benchmark data and comment on alert
386+
# # Do not run for PRs created from other repos as those won't be able to write to the pull request
387+
# if: ${{ matrix.benchmarks && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.event.repository.full_name) }}
388+
# uses: benchmark-action/github-action-benchmark@v1
389+
# with:
390+
# name: Syntax Benchmarks
391+
# tool: customSmallerIsBetter
392+
# output-file-path: tests/benchmark-output.json
393+
# external-data-json-path: ./tests/benchmark-cache/benchmark-data.json
394+
# github-token: ${{ secrets.GITHUB_TOKEN }}
395+
# alert-threshold: "105%"
396+
# comment-always: false
397+
# comment-on-alert: true
398+
399+
# - name: Save benchmark data as new baseline
400+
# if: matrix.benchmarks && github.ref == 'refs/heads/master'
401+
# uses: actions/cache/save@v4
402+
# with:
403+
# path: ./tests/benchmark-cache
404+
# key: syntax-benchmark-v1
403405

404406
- name: Build playground compiler
405407
if: matrix.build_playground

.github/workflows/prepare_package_upload.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import * as fs from "node:fs";
22
import * as os from "node:os";
33

4-
import packageSpec from "rescript/package.json" with { type: "json" };
4+
const packageSpec = JSON.parse(
5+
fs.readFileSync(new URL("../../package.json", import.meta.url), "utf-8")
6+
);
57

68
const { version } = packageSpec;
79

CHANGELOG.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,34 @@
1010
> - :house: [Internal]
1111
> - :nail_care: [Polish]
1212
13-
# 12.0.0-alpha.11 (Unreleased)
13+
# 12.0.0-alpha.12 (Unreleased)
14+
15+
#### :bug: Bug fix
16+
17+
- Fix node.js ExperimentalWarning. https://github.com/rescript-lang/rescript/pull/7379
18+
19+
#### :house: Internal
20+
21+
- Better representation of JSX in AST. https://github.com/rescript-lang/rescript/pull/7286
22+
23+
# 12.0.0-alpha.11
1424

1525
#### :bug: Bug fix
1626

1727
- Fix `Error.fromException`. https://github.com/rescript-lang/rescript/pull/7364
28+
- Fix signature of `throw`. https://github.com/rescript-lang/rescript/pull/7365
29+
- Fix formatter adds superfluous parens in pipe chain. https://github.com/rescript-lang/rescript/pull/7370
1830

1931
#### :house: Internal
2032

2133
- Remove `Stdlib_Char` module for now. https://github.com/rescript-lang/rescript/pull/7367
2234
- Convert internal JavaScript codebase into ESM, ReScript package itself is now ESM (`"type": "module"`). https://github.com/rescript-lang/rescript/pull/6899
35+
- Add built-in support for the JavaScript `in` operator. https://github.com/rescript-lang/rescript/pull/7342
36+
- AST cleanup: add `Pexp_await` ast node instead of `res.await` attribute. (The attribute is still used for await on modules currently). https://github.com/rescript-lang/rescript/pull/7368
37+
38+
#### :nail_care: Polish
39+
40+
- More deprecations in `Pervasives`; add `Stdlib.Pair` and `Stdlib.Int.Ref`. https://github.com/rescript-lang/rescript/pull/7371
2341

2442
# 12.0.0-alpha.10
2543

@@ -60,7 +78,7 @@
6078

6179
#### :bug: Bug fix
6280

63-
- Fix recursive untagged variant type checking by delaying well-formedness checks until environment construction completes. [#7320](https://github.com/rescript-lang/rescript/pull/7320)
81+
- Fix recursive untagged variant type checking by delaying well-formedness checks until environment construction completes. https://github.com/rescript-lang/rescript/pull/7320
6482
- Fix incorrect expansion of polymorphic return types in uncurried function applications. https://github.com/rescript-lang/rescript/pull/7338
6583

6684
# 12.0.0-alpha.9

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,19 @@ After adding a new file to the repository that should go into the npm package -
123123

124124
```sh
125125
make lib # Build compiler and standard library
126-
./cli/bsc myTestFile.res
126+
./cli/bsc.js myTestFile.res
127127
```
128128

129129
To view the untyped tree of the file run:
130130

131131
```sh
132-
./cli/bsc -dparsetree myTestFile.res
132+
./cli/bsc.js -dparsetree myTestFile.res
133133
```
134134

135135
To view the typed tree of the file run:
136136

137137
```sh
138-
./cli/bsc -dtypedtree myTestFile.res
138+
./cli/bsc.js -dtypedtree myTestFile.res
139139
```
140140

141141
### Project

analysis/src/CompletionFrontEnd.ml

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,12 @@ let rec exprToContextPathInner ~(inJsxContext : bool) (e : Parsetree.expression)
312312
if List.length exprs = List.length exprsAsContextPaths then
313313
Some (CTuple exprsAsContextPaths)
314314
else None
315+
| Pexp_await e -> exprToContextPathInner ~inJsxContext e
315316
| _ -> None
316317

317318
and exprToContextPath ~(inJsxContext : bool) (e : Parsetree.expression) =
318319
match
319-
( Res_parsetree_viewer.has_await_attribute e.pexp_attributes,
320+
( Res_parsetree_viewer.expr_is_await e,
320321
exprToContextPathInner ~inJsxContext e )
321322
with
322323
| true, Some ctxPath -> Some (CPAwait ctxPath)
@@ -1232,8 +1233,6 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
12321233
then ValueOrField
12331234
else Value);
12341235
}))
1235-
| Pexp_construct ({txt = Lident ("::" | "()")}, _) ->
1236-
(* Ignore list expressions, used in JSX, unit, and more *) ()
12371236
| Pexp_construct (lid, eOpt) -> (
12381237
let lidPath = flattenLidCheckDot lid in
12391238
if debug then
@@ -1324,10 +1323,29 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
13241323
inJsx = !inJsxContext;
13251324
}))
13261325
| None -> ())
1327-
| Pexp_apply {funct = {pexp_desc = Pexp_ident compName}; args}
1328-
when Res_parsetree_viewer.is_jsx_expression expr ->
1326+
| Pexp_jsx_element
1327+
( Jsx_unary_element
1328+
{
1329+
jsx_unary_element_tag_name = compName;
1330+
jsx_unary_element_props = props;
1331+
}
1332+
| Jsx_container_element
1333+
{
1334+
jsx_container_element_tag_name_start = compName;
1335+
jsx_container_element_props = props;
1336+
} ) ->
13291337
inJsxContext := true;
1330-
let jsxProps = CompletionJsx.extractJsxProps ~compName ~args in
1338+
let children =
1339+
match expr.pexp_desc with
1340+
| Pexp_jsx_element
1341+
(Jsx_container_element
1342+
{jsx_container_element_children = children}) ->
1343+
children
1344+
| _ -> JSXChildrenItems []
1345+
in
1346+
let jsxProps =
1347+
CompletionJsx.extractJsxProps ~compName ~props ~children
1348+
in
13311349
let compNamePath = flattenLidCheckDot ~jsx:true compName in
13321350
if debug then
13331351
Printf.printf "JSX <%s:%s %s> _children:%s\n"
@@ -1344,10 +1362,21 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
13441362
| None -> "None"
13451363
| Some childrenPosStart -> Pos.toString childrenPosStart);
13461364
let jsxCompletable =
1347-
CompletionJsx.findJsxPropsCompletable ~jsxProps
1348-
~endPos:(Loc.end_ expr.pexp_loc) ~posBeforeCursor
1349-
~posAfterCompName:(Loc.end_ compName.loc)
1350-
~firstCharBeforeCursorNoWhite ~charAtCursor
1365+
match expr.pexp_desc with
1366+
| Pexp_jsx_element
1367+
(Jsx_container_element
1368+
{
1369+
jsx_container_element_closing_tag = None;
1370+
jsx_container_element_children =
1371+
JSXChildrenSpreading _ | JSXChildrenItems (_ :: _);
1372+
}) ->
1373+
(* This is a weird edge case where there is no closing tag but there are children *)
1374+
None
1375+
| _ ->
1376+
CompletionJsx.findJsxPropsCompletable ~jsxProps
1377+
~endPos:(Loc.end_ expr.pexp_loc) ~posBeforeCursor
1378+
~posAfterCompName:(Loc.end_ compName.loc)
1379+
~firstCharBeforeCursorNoWhite ~charAtCursor
13511380
in
13521381
if jsxCompletable <> None then setResultOpt jsxCompletable
13531382
else if compName.loc |> Loc.hasPos ~pos:posBeforeCursor then

analysis/src/CompletionJsx.ml

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -455,40 +455,39 @@ let findJsxPropsCompletable ~jsxProps ~endPos ~posBeforeCursor
455455
in
456456
loop jsxProps.props
457457

458-
let extractJsxProps ~(compName : Longident.t Location.loc) ~args =
459-
let thisCaseShouldNotHappen =
460-
{
461-
compName = Location.mknoloc (Longident.Lident "");
462-
props = [];
463-
childrenStart = None;
464-
}
458+
let extractJsxProps ~(compName : Longident.t Location.loc) ~props ~children =
459+
let open Parsetree in
460+
let childrenStart =
461+
match children with
462+
| JSXChildrenItems [] -> None
463+
| JSXChildrenSpreading child | JSXChildrenItems (child :: _) ->
464+
if child.pexp_loc.loc_ghost then None else Some (Loc.start child.pexp_loc)
465465
in
466-
let rec processProps ~acc args =
467-
match args with
468-
| (Asttypes.Labelled {txt = "children"}, {Parsetree.pexp_loc}) :: _ ->
469-
{
470-
compName;
471-
props = List.rev acc;
472-
childrenStart =
473-
(if pexp_loc.loc_ghost then None else Some (Loc.start pexp_loc));
474-
}
475-
| ( (Labelled {txt = s; loc} | Optional {txt = s; loc}),
476-
(eProp : Parsetree.expression) )
477-
:: rest -> (
478-
let namedArgLoc = if loc = Location.none then None else Some loc in
479-
match namedArgLoc with
480-
| Some loc ->
481-
processProps
482-
~acc:
483-
({
484-
name = s;
485-
posStart = Loc.start loc;
486-
posEnd = Loc.end_ loc;
487-
exp = eProp;
488-
}
489-
:: acc)
490-
rest
491-
| None -> processProps ~acc rest)
492-
| _ -> thisCaseShouldNotHappen
466+
let props =
467+
props
468+
|> List.map (function
469+
| JSXPropPunning (_, name) ->
470+
{
471+
name = name.txt;
472+
posStart = Loc.start name.loc;
473+
posEnd = Loc.end_ name.loc;
474+
exp =
475+
Ast_helper.Exp.ident ~loc:name.loc
476+
{txt = Longident.Lident name.txt; loc = name.loc};
477+
}
478+
| JSXPropValue (name, _, value) ->
479+
{
480+
name = name.txt;
481+
posStart = Loc.start name.loc;
482+
posEnd = Loc.end_ name.loc;
483+
exp = value;
484+
}
485+
| JSXPropSpreading (loc, expr) ->
486+
{
487+
name = "_spreadProps";
488+
posStart = Loc.start loc;
489+
posEnd = Loc.end_ loc;
490+
exp = expr;
491+
})
493492
in
494-
args |> processProps ~acc:[]
493+
{compName; props; childrenStart}

0 commit comments

Comments
 (0)