@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 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
- // export function main() { ... }
130
- const declarationBody = (
131
- (program.body[0] as ExportNamedDeclaration).declaration as FunctionDeclaration
132
- )?.body
133
- return escodegen.generate(declarationBody, {
134
- format: {
135
- indent: { style: ' ' },
136
- semicolons: false,
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
- comment: true,
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.53",
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": "b08f881540787ad817115880ebcee1487a0a81ab"
32
+ "gitHead": "08f3ae4a88db84f682384ecfa94e9d4583371bda"
33
33
  }
package/utils/data.ts CHANGED
@@ -83,7 +83,7 @@ type SystemDataName =
83
83
  type SystemDataInfo = {
84
84
  name: SystemDataName
85
85
  id: string
86
- type: 'string' | 'number' | 'bool' | 'boolean' | 'array' | 'object' | 'any'
86
+ type: Data['type']
87
87
  title?: string
88
88
  description?: string
89
89
  schema?: object