Parse inline imports and ingested files at the expression level

```
numbers =
    import "numbers.json" as numbersJson : Str
    import json.Decode exposing [decode, list, int]

    numbersJson
    |> decode (list int)
    |> Result.withDefault []
```
This commit is contained in:
Agus Zubiaga 2023-12-26 17:43:14 -03:00
parent 2d93f0c3f1
commit 11e0202eb9
No known key found for this signature in database
8 changed files with 219 additions and 5 deletions

View file

@ -0,0 +1,101 @@
Defs(
Defs {
tags: [
Index(2147483648),
Index(2147483649),
],
regions: [
@0-26,
@27-50,
],
space_before: [
Slice(start = 0, length = 0),
Slice(start = 0, length = 1),
],
space_after: [
Slice(start = 0, length = 0),
Slice(start = 1, length = 0),
],
spaces: [
Newline,
],
type_defs: [],
value_defs: [
ModuleImport(
ModuleImport {
before_name: [],
name: @7-11 ImportedModuleName {
package: None,
name: "Json",
},
alias: None,
exposed: Some(
KeywordItem {
keyword: Spaces {
before: [],
item: ImportExposingKeyword,
after: [],
},
item: [
@22-25 ExposedName(
"int",
),
],
},
),
},
),
ModuleImport(
ModuleImport {
before_name: [],
name: @34-44 ImportedModuleName {
package: None,
name: "JsonEncode",
},
alias: Some(
KeywordItem {
keyword: Spaces {
before: [],
item: ImportAsKeyword,
after: [],
},
item: @48-50 ImportAlias(
"JE",
),
},
),
exposed: None,
},
),
],
},
@52-70 SpaceBefore(
Apply(
@52-61 Var {
module_name: "JE",
ident: "encode",
},
[
@63-69 ParensAround(
Apply(
@63-66 Var {
module_name: "",
ident: "int",
},
[
@67-69 Num(
"42",
),
],
Space,
),
),
],
Space,
),
[
Newline,
Newline,
],
),
)

View file

@ -0,0 +1,4 @@
import Json exposing [int]
import JsonEncode as JE
JE.encode (int 42)

View file

@ -0,0 +1,63 @@
Defs(
Defs {
tags: [
Index(2147483648),
],
regions: [
@0-33,
],
space_before: [
Slice(start = 0, length = 0),
],
space_after: [
Slice(start = 0, length = 0),
],
spaces: [],
type_defs: [],
value_defs: [
IngestedFileImport(
IngestedFileImport {
before_path: [],
path: @7-19 PlainLine(
"users.json",
),
name: KeywordItem {
keyword: Spaces {
before: [],
item: ImportAsKeyword,
after: [],
},
item: @23-33 TypedIdent {
ident: @23-27 "data",
spaces_before_colon: [],
ann: @30-33 Apply(
"",
"Str",
[],
),
},
},
},
),
],
},
@35-49 SpaceBefore(
Apply(
@35-44 Var {
module_name: "",
ident: "parseJson",
},
[
@45-49 Var {
module_name: "",
ident: "data",
},
],
Space,
),
[
Newline,
Newline,
],
),
)

View file

@ -0,0 +1,3 @@
import "users.json" as data : Str
parseJson data

View file

@ -330,6 +330,8 @@ mod test_snapshots {
pass/import_with_comments.moduledefs,
pass/import_with_exposed.moduledefs,
pass/ingested_file.moduledefs,
pass/inline_import.expr,
pass/inline_ingested_file.expr,
pass/int_with_underscore.expr,
pass/interface_with_newline.header,
pass/lambda_in_chain.expr,