mirror of
https://github.com/enso-org/enso.git
synced 2024-12-25 06:44:32 +03:00
Fix for code enabling/disabling output context on single node (#8776)
This commit is contained in:
parent
184128949e
commit
080690b3ad
@ -179,24 +179,23 @@ const isOutputContextOverridden = computed({
|
||||
set(shouldOverride) {
|
||||
const module = projectStore.module
|
||||
if (!module) return
|
||||
const replacements = shouldOverride
|
||||
? [Ast.TextLiteral.new(projectStore.executionMode)]
|
||||
: undefined
|
||||
const edit = props.node.rootSpan.module.edit()
|
||||
const newAst = prefixes.modify(
|
||||
edit,
|
||||
props.node.rootSpan,
|
||||
projectStore.isOutputContextEnabled
|
||||
const replacementText = shouldOverride
|
||||
? [Ast.TextLiteral.new(projectStore.executionMode, edit)]
|
||||
: undefined
|
||||
const replacements = projectStore.isOutputContextEnabled
|
||||
? {
|
||||
enableOutputContext: undefined,
|
||||
disableOutputContext: replacements,
|
||||
disableOutputContext: replacementText,
|
||||
}
|
||||
: {
|
||||
enableOutputContext: replacements,
|
||||
enableOutputContext: replacementText,
|
||||
disableOutputContext: undefined,
|
||||
},
|
||||
)
|
||||
graph.setNodeContent(props.node.rootSpan.exprId, newAst.code())
|
||||
}
|
||||
const expression = props.node.rootSpan
|
||||
const newAst = prefixes.modify(edit, expression, replacements)
|
||||
const code = newAst.code()
|
||||
graph.setNodeContent(props.node.rootSpan.exprId, code)
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -106,4 +106,11 @@ test.each([
|
||||
const intron = Ast.parse(source, edit)
|
||||
const instantiated = pattern.instantiate(edit, [intron.exprId])
|
||||
expect(instantiated.code(edit)).toBe(result)
|
||||
|
||||
// Check that `instantiate` has not affected the base module.
|
||||
const intron2 = Ast.parse(source, edit)
|
||||
const originalParent = intron2.parent
|
||||
const edit2 = edit.edit()
|
||||
pattern.instantiate(edit2, [intron2.exprId])
|
||||
expect(edit.get(intron2.exprId)!.parent).toBe(originalParent)
|
||||
})
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { assert } from '@/util/assert'
|
||||
import { Ast } from '@/util/ast'
|
||||
import { MutableModule } from '@/util/ast/abstract'
|
||||
|
||||
@ -44,7 +45,14 @@ export class Pattern {
|
||||
for (const matched of placeholders(ast, this.placeholder)) {
|
||||
const replacement = subtrees.shift()
|
||||
if (replacement === undefined) break
|
||||
edit.get(replacement)!.parent = matched.parent
|
||||
const replacementAst = edit.splice(edit.get(replacement))
|
||||
if (replacementAst === null) {
|
||||
console.error(
|
||||
'Subtree ID provided to `instantiate` is not accessible in the `edit` module.',
|
||||
)
|
||||
continue
|
||||
}
|
||||
replacementAst.parent = matched.parent
|
||||
matched.ref.node = replacement
|
||||
}
|
||||
return ast
|
||||
|
Loading…
Reference in New Issue
Block a user