5
5
BashoLogFn ,
6
6
ExpressionStackEntry ,
7
7
BashoEvaluationResult ,
8
- EvaluationEnv
8
+ EvaluationEnv ,
9
9
} from "./types" ;
10
10
import { PipelineValue , PipelineItem } from "./pipeline" ;
11
11
import jsExpression from "./operators/jsExpression" ;
@@ -17,7 +17,7 @@ import execShellCommand from "./operators/execShellCommand";
17
17
import onError from "./operators/onError" ;
18
18
import filter from "./operators/filter" ;
19
19
import recurse from "./operators/recurse" ;
20
- import doImport from "./operators/doImport" ;
20
+ import { defaultImport , namedImport } from "./operators/doImport" ;
21
21
import log from "./operators/log" ;
22
22
import flatMap from "./operators/flatMap" ;
23
23
import namedExpression from "./operators/namedExpression" ;
@@ -67,7 +67,7 @@ function createProxy(): EvaluationStack {
67
67
const outer = evalScope . slice ( - 1 ) [ 0 ] ;
68
68
outer [ prop ] = value ;
69
69
return true ;
70
- }
70
+ } ,
71
71
} ;
72
72
73
73
const proxy = new Proxy ( evalScope , handler ) ;
@@ -76,7 +76,7 @@ function createProxy(): EvaluationStack {
76
76
create : ( ) => evalScope . push ( { } ) ,
77
77
unwind : ( ) => evalScope . pop ( ) ,
78
78
value : evalScope ,
79
- proxy
79
+ proxy,
80
80
} ;
81
81
}
82
82
@@ -108,7 +108,7 @@ export async function createStackAndEvaluate(
108
108
args ,
109
109
[ ] ,
110
110
evalScope ,
111
- Seq . of ( pipedValues . map ( x => new PipelineValue ( x ) ) ) ,
111
+ Seq . of ( pipedValues . map ( ( x ) => new PipelineValue ( x ) ) ) ,
112
112
mustPrint ,
113
113
onLog ,
114
114
onWrite ,
@@ -145,70 +145,73 @@ export async function evaluateInternal(
145
145
) : Promise < BashoEvaluationResult > {
146
146
const cases : Array < [ ( arg : string ) => boolean , OperatorFn ] > = [
147
147
/* Enumerate sequence into an array */
148
- [ x => x === "-a" , toArray ] ,
148
+ [ ( x ) => x === "-a" , toArray ] ,
149
149
150
150
/* Combine multiple named streams */
151
- [ x => x === "-c" , combineStreams ] ,
151
+ [ ( x ) => x === "-c" , combineStreams ] ,
152
152
153
153
/* Define an expression */
154
- [ x => x === "-d" , defineExpression ] ,
154
+ [ ( x ) => x === "-d" , defineExpression ] ,
155
155
156
156
/* Execute shell command */
157
- [ x => x === "-e" , execShellCommand ] ,
157
+ [ ( x ) => x === "-e" , execShellCommand ] ,
158
158
159
159
/* Error handling */
160
- [ x => x === "--error" , onError ] ,
160
+ [ ( x ) => x === "--error" , onError ] ,
161
161
162
162
/* Filter */
163
- [ x => x === "-f" , filter ] ,
163
+ [ ( x ) => x === "-f" , filter ] ,
164
164
165
165
/* Recurse/Goto */
166
- [ x => x === "-g" , recurse ] ,
166
+ [ ( x ) => x === "-g" , recurse ] ,
167
+
168
+ /* Import default export from a module */
169
+ [ ( x ) => x === "--import" || x === "-i" , defaultImport ( ) ] ,
167
170
168
- /* Named Export */
169
- [ x => x === "--import" || x === "-i" , doImport ] ,
171
+ /* Import named export from a module */
172
+ [ ( x ) => x === "--named- import" , namedImport ( ) ] ,
170
173
171
174
/* JS expressions */
172
- [ x => x === "-j" , jsExpression ( 1 ) ] ,
175
+ [ ( x ) => x === "-j" , jsExpression ( 1 ) ] ,
173
176
174
177
/* Treats input as JSON */
175
- [ x => x === "--json" , asJson ] ,
178
+ [ ( x ) => x === "--json" , asJson ] ,
176
179
177
180
/* Logging */
178
- [ x => x === "-l" , log ] ,
181
+ [ ( x ) => x === "-l" , log ] ,
179
182
180
183
/* Flatmap */
181
- [ x => x === "-m" , flatMap ] ,
184
+ [ ( x ) => x === "-m" , flatMap ] ,
182
185
183
186
/* Named Expressions */
184
- [ x => x === "-n" , namedExpression ] ,
187
+ [ ( x ) => x === "-n" , namedExpression ] ,
185
188
186
189
/* Error handling. Handled by shell, ignore */
187
- [ x => x === "--ignoreerror" || x === "--printerror" , errorHandler ] ,
190
+ [ ( x ) => x === "--ignoreerror" || x === "--printerror" , errorHandler ] ,
188
191
189
192
/* Print */
190
- [ x => x === "-p" , print ] ,
193
+ [ ( x ) => x === "-p" , print ] ,
191
194
192
195
/* Reduce */
193
- [ x => x === "-r" , reduce ] ,
196
+ [ ( x ) => x === "-r" , reduce ] ,
194
197
195
198
/* Seek a named result */
196
- [ x => x === "-s" , seek ] ,
199
+ [ ( x ) => x === "-s" , seek ] ,
197
200
198
201
/* Convert input to a single string */
199
- [ x => x === "--str" , asString ] ,
202
+ [ ( x ) => x === "--str" , asString ] ,
200
203
201
204
/* Define a subroutine */
202
- [ x => x === "--sub" , subroutine ] ,
205
+ [ ( x ) => x === "--sub" , subroutine ] ,
203
206
204
207
/* Terminate the pipeline */
205
- [ x => x === "-t" , terminate ] ,
208
+ [ ( x ) => x === "-t" , terminate ] ,
206
209
207
210
/* Writing */
208
- [ x => x === "-w" , write ] ,
211
+ [ ( x ) => x === "-w" , write ] ,
209
212
210
213
/* Everything else as a JS expression */
211
- [ x => isFirstParam , jsExpression ( 0 ) ]
214
+ [ ( x ) => isFirstParam , jsExpression ( 0 ) ] ,
212
215
] ;
213
216
214
217
return args . length
0 commit comments