File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change
1
+ const isSimple = / ^ ( \w | \. ) + $ /
2
+
1
3
export function compileRawExpression ( src ) {
4
+ return isSimple . test ( src ) ? compileSimpleExpression ( src ) : compileComplexExpression ( src )
5
+ }
6
+
7
+ function compileSimpleExpression ( src ) {
8
+ return new Function ( 'context' , 'tempVars' , // eslint-disable-line
9
+ `if (tempVars) {
10
+ try { return tempVars.${ src } } catch (err) {
11
+ if (!(err instanceof TypeError)) throw err
12
+ }
13
+ }
14
+ try { return context.${ src } } catch (err) {
15
+ if (!(err instanceof TypeError)) throw err
16
+ }` )
17
+ }
18
+
19
+ function compileComplexExpression ( src ) {
2
20
return new Function ( 'context' , 'tempVars' , // eslint-disable-line
3
21
`const sandbox = $nxCompileToSandbox(context, tempVars)
4
22
try { with (sandbox) { return ${ src } } } catch (err) {
You can’t perform that action at this time.
0 commit comments