11language go
22
33pattern before_each_file_prep_imports() {
4- $_ where {
5- // Array of global imports. Each import is a tuple of (source, as)
6- $GLOBAL_NEW_IMPORTS = [],
7- }
4+ $_ where {
5+ // Array of global imports. Each import is a tuple of (source, as)
6+ $GLOBAL_NEW_IMPORTS = []
7+ }
88}
99
1010// Handle inserting imports if we accumulated any
1111pattern after_each_file_handle_imports() {
12- $_ where {
13- if ($GLOBAL_NEW_IMPORTS <: not []) {
14- $program <: or {
15- contains import_declaration(imports=$list) as $outer where {
16- $list <: or {
17- import_spec_list(imports=$imports) where {
18- $GLOBAL_NEW_IMPORTS <: some bubble($imports) $import where {
19- $imports += `"$import"`,
20- }
21- },
22- import_spec() where {
23- $GLOBAL_NEW_IMPORTS <: some bubble($outer) $import where {
24- $outer += `\nimport "$import"`,
25- }
26- }
27- },
28- },
29- contains package_clause() as $anchor where {
30- $GLOBAL_NEW_IMPORTS <: some bubble($anchor) $import where {
31- $anchor += `\nimport "$import"`,
32- }
33- }
34- }
35- }
36- }
12+ $_ where {
13+ if ($GLOBAL_NEW_IMPORTS <: not []) {
14+ $program <: or {
15+ contains import_declaration(imports=$list) as $outer where {
16+ $list <: or {
17+ import_spec_list(imports=$imports) where {
18+ $GLOBAL_NEW_IMPORTS <: some bubble($imports) $import where {
19+ $imports += `"$import"`
20+ }
21+ },
22+ import_spec() where {
23+ $GLOBAL_NEW_IMPORTS <: some bubble($outer) $import where {
24+ $outer += `\nimport "$import"`
25+ }
26+ }
27+ }
28+ },
29+ contains package_clause() as $anchor where {
30+ $GLOBAL_NEW_IMPORTS <: some bubble($anchor) $import where {
31+ $anchor += `\nimport "$import"`
32+ }
33+ }
34+ }
35+ }
36+ }
3737}
3838
3939function require_import($source, $as) {
40- // Default condition
41- $split_source = split($source, "/"),
42- if ($as <: undefined) {
43- $name_to_use = $split_source[-1],
44- } else {
45- $name_to_use = $as,
46- },
47- or {
48- $program <: contains bubble($source, $name_to_use) import_spec($name, path=$path) where {
49- $path <: contains $source,
50- if ($name <: not .) {
51- $name_to_use=$name,
52- }
53- },
54- // $GLOBAL_NEW_IMPORTS <: some bubble($source) `$import` where $import <: $source,
55- $GLOBAL_NEW_IMPORTS += $source
56- },
57- return $name_to_use
40+ // Default condition
41+ $split_source = split($source, "/"),
42+ if ($as <: undefined) { $name_to_use = $split_source[-1] } else {
43+ $name_to_use = $as
44+ },
45+ or {
46+ $program <: contains bubble($source, $name_to_use) import_spec($name, path=$path) where {
47+ $path <: contains $source,
48+ if ($name <: not .) { $name_to_use = $name }
49+ },
50+ // $GLOBAL_NEW_IMPORTS <: some bubble($source) `$import` where $import <: $source,
51+ $GLOBAL_NEW_IMPORTS += $source
52+ },
53+ return $name_to_use
5854}
5955
6056pattern import_of($source) {
61- import_declaration(imports=import_spec_list(imports=$mod)) where {
62- $mod <: not contains $source,
63- $mod += $source
64- }
57+ import_declaration(imports=import_spec_list(imports=$mod)) where {
58+ $mod <: not contains $source,
59+ $mod += $source
60+ }
6561}
6662
67-
6863pattern ensure_import($source) {
69- import_declaration(imports=import_spec_list(imports=$mod)) where {
70- $mod <: not contains $source,
71- $mod += $source
72- }
73- }
64+ import_declaration(imports=import_spec_list(imports=$mod)) where {
65+ $mod <: not contains $source,
66+ $mod += $source
67+ }
68+ }
0 commit comments