Skip to content

Commit

Permalink
1588 accidental unpacking during evaluating the if statement (#1601)
Browse files Browse the repository at this point in the history
* Fix issue of accidental unpacking, manually adding undefined in the block statement to make it value producing

* Prettier changes during saving, might be an issue.

* Fix the problem of accidental unpacking when an if statement in a block statement

* fixing build (movement of scm-slang)

* fixing build (movement of scm-slang)

* Update publish-npm.yml

* Update publish-npm.yml

* Update createContext.ts

* remove old src/scm-slang folder

* making linter happy

---------

Co-authored-by: henz <[email protected]>
Co-authored-by: s-kybound <[email protected]>
  • Loading branch information
3 people authored Mar 23, 2024
1 parent 2536d84 commit 90fbfc7
Showing 1 changed file with 36 additions and 12 deletions.
48 changes: 36 additions & 12 deletions src/stepper/stepper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1777,12 +1777,24 @@ function reduceMain(
paths[0].push('body[0]')
const [reduced, cont, path, str] = reduce(firstStatement, context, paths)
if (reduced.type === 'BlockStatement') {
const body = reduced.body as es.Statement[]
if (body.length > 1) {
path[1] = [...path[0].slice(0, path[0].length - 1)]
}
const wholeBlock = body.concat(...(otherStatements as es.Statement[]))
return [ast.program(wholeBlock), cont, path, str]
/**
* Manually adding undefined within the block statement to make it value-producing.
* We do not unpack the block statement to prevent possible confusion
*/
const und = ast.expressionStatement(ast.identifier('undefined'))
const statementBodyAfterAddingUndefined = ast.blockStatement([
und as es.Statement,
...reduced.body
])
return [
ast.program([
statementBodyAfterAddingUndefined,
...(otherStatements as es.Statement[])
]),
cont,
path,
str
]
} else {
return [
ast.program([reduced as es.Statement, ...(otherStatements as es.Statement[])]),
Expand Down Expand Up @@ -1988,12 +2000,24 @@ function reduceMain(
paths[0].push('body[0]')
const [reduced, cont, path, str] = reduce(firstStatement, context, paths)
if (reduced.type === 'BlockStatement') {
const body = reduced.body as es.Statement[]
if (body.length > 1) {
path[1] = [...path[0].slice(0, path[0].length - 1)]
}
const wholeBlock = body.concat(...(otherStatements as es.Statement[]))
return [ast.blockStatement(wholeBlock), cont, path, str]
/**
* Manually adding undefined within the block statement to make it value-producing.
* We do not unpack the block statement to prevent possible confusion
*/
const und = ast.expressionStatement(ast.identifier('undefined'))
const statementBodyAfterAddingUndefined = ast.blockStatement([
und as es.Statement,
...reduced.body
])
return [
ast.program([
statementBodyAfterAddingUndefined,
...(otherStatements as es.Statement[])
]),
cont,
path,
str
]
} else {
return [
ast.blockStatement([reduced as es.Statement, ...(otherStatements as es.Statement[])]),
Expand Down

0 comments on commit 90fbfc7

Please sign in to comment.