@fugood/bricks-ctor 2.25.0-beta.53 → 2.25.0-beta.55
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/compile/index.ts +22 -11
- package/package.json +2 -2
- package/utils/data.ts +1 -1
package/compile/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ import upperFirst from 'lodash/upperFirst'
|
|
|
4
4
|
import snakeCase from 'lodash/snakeCase'
|
|
5
5
|
import omit from 'lodash/omit'
|
|
6
6
|
import { parse as parseAST } from 'acorn'
|
|
7
|
-
import type { ExportNamedDeclaration, FunctionDeclaration } from 'acorn'
|
|
7
|
+
import type { BlockStatement, ExportNamedDeclaration, FunctionDeclaration } from 'acorn'
|
|
8
8
|
import escodegen from 'escodegen'
|
|
9
9
|
import { makeSeededId } from '../utils/id'
|
|
10
10
|
import { generateCalulationMap } from './util'
|
|
@@ -126,17 +126,28 @@ const compileProperty = (property, errorReference: string, result = {}) => {
|
|
|
126
126
|
const compileScriptCalculationCode = (code = '') => {
|
|
127
127
|
try {
|
|
128
128
|
const program = parseAST(code, { sourceType: 'module', ecmaVersion: 2020 })
|
|
129
|
-
//
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
129
|
+
// The stored config holds the bare function body, which codegen re-wraps as
|
|
130
|
+
// `export function main() { <code> }`. Unwrap it back to that body here.
|
|
131
|
+
let block = ((program.body[0] as ExportNamedDeclaration).declaration as FunctionDeclaration)
|
|
132
|
+
?.body as BlockStatement | undefined
|
|
133
|
+
if (!block) return code || ''
|
|
134
|
+
// Earlier versions emitted the whole BlockStatement (braces included), so every
|
|
135
|
+
// compile -> codegen round-trip nested the body in one more `{ }`. Emit the inner
|
|
136
|
+
// statements instead, collapsing any wrapper blocks previous round-trips added so
|
|
137
|
+
// existing over-wrapped sandboxes heal on the next compile.
|
|
138
|
+
while (block.body.length === 1 && block.body[0].type === 'BlockStatement') {
|
|
139
|
+
block = block.body[0] as BlockStatement
|
|
140
|
+
}
|
|
141
|
+
return escodegen.generate(
|
|
142
|
+
{ type: 'Program', body: block.body },
|
|
143
|
+
{
|
|
144
|
+
format: {
|
|
145
|
+
indent: { style: ' ' },
|
|
146
|
+
semicolons: false,
|
|
147
|
+
},
|
|
148
|
+
comment: true,
|
|
137
149
|
},
|
|
138
|
-
|
|
139
|
-
})
|
|
150
|
+
)
|
|
140
151
|
} catch {
|
|
141
152
|
return code || ''
|
|
142
153
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fugood/bricks-ctor",
|
|
3
|
-
"version": "2.25.0-beta.
|
|
3
|
+
"version": "2.25.0-beta.55",
|
|
4
4
|
"main": "index.ts",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"typecheck": "tsc --noEmit",
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"oxfmt": "^0.36.0"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "08f3ae4a88db84f682384ecfa94e9d4583371bda"
|
|
33
33
|
}
|
package/utils/data.ts
CHANGED