@nxtedition/lib 14.0.0-alpha.1 → 14.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/util/template/index.js +28 -25
package/package.json
CHANGED
package/util/template/index.js
CHANGED
|
@@ -125,6 +125,7 @@ module.exports = (options) => {
|
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
return {
|
|
128
|
+
input: str,
|
|
128
129
|
pre: str.slice(0, templateStart),
|
|
129
130
|
type,
|
|
130
131
|
body: str.slice(bodyStart, bodyEnd),
|
|
@@ -132,39 +133,41 @@ module.exports = (options) => {
|
|
|
132
133
|
}
|
|
133
134
|
}
|
|
134
135
|
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const match = inner(str)
|
|
136
|
+
const _compileStringTemplate = weakCache(
|
|
137
|
+
function _compileStringTemplate(match) {
|
|
138
|
+
const { pre, type, body, post } = match
|
|
141
139
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
140
|
+
const compileExpression = compilers[type]
|
|
141
|
+
if (!compileExpression) {
|
|
142
|
+
throw new Error('unknown expression type')
|
|
143
|
+
}
|
|
145
144
|
|
|
146
|
-
|
|
145
|
+
const expr = compileExpression(body)
|
|
147
146
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
147
|
+
if (!pre && !post) {
|
|
148
|
+
return expr
|
|
149
|
+
}
|
|
152
150
|
|
|
153
|
-
|
|
151
|
+
return (...args) =>
|
|
152
|
+
expr(...args).pipe(
|
|
153
|
+
rx.switchMap((body) =>
|
|
154
|
+
compileStringTemplate(`${pre}${stringify(body, type !== 'js')}${post}`)(...args)
|
|
155
|
+
)
|
|
156
|
+
)
|
|
157
|
+
},
|
|
158
|
+
(match) => match.input
|
|
159
|
+
)
|
|
154
160
|
|
|
155
|
-
|
|
156
|
-
|
|
161
|
+
function compileStringTemplateLazy(str) {
|
|
162
|
+
if (!fp.isString(str)) {
|
|
163
|
+
throw new Error('invalid argument')
|
|
157
164
|
}
|
|
158
165
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
compileStringTemplate(`${pre}${stringify(body, type !== 'js')}${post}`)(...args)
|
|
163
|
-
)
|
|
164
|
-
)
|
|
165
|
-
})
|
|
166
|
+
const match = inner(str)
|
|
167
|
+
return match ? _compileStringTemplate(str, match) : null
|
|
168
|
+
}
|
|
166
169
|
|
|
167
|
-
|
|
170
|
+
function compileStringTemplate(str) {
|
|
168
171
|
return compileStringTemplateLazy(str) ?? (() => rxjs.of(str))
|
|
169
172
|
}
|
|
170
173
|
|