✨ feat(vscode): shell 被当成一串步骤执行时(Dockerfile 的 RUN)只用 && 连着的一串拆成一条一步;tree-sitter-bash 把 a && b > f 读成整串带重定向,重定向改算在最后那条命令上
This commit is contained in:
1 parent
3353cf870c
commit
149cb51cc0
2 files changed
+90
-2
No files matched your search
@@ -138,6 +138,33 @@ describe('shell 属性表信息(facts)', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('shell 被别的语言嵌着当步骤执行(Dockerfile 的 RUN)', () => {
|
||||
const steps = async (source: string): Promise<{ blocks: Outline[], chained: boolean, headers: string[] } | undefined> => {
|
||||
const parsed = await runtime.parse(adapter, 'shellscript', source)
|
||||
try {
|
||||
const found = adapter.steps?.(parsed.rootNode, source, 'shellscript')
|
||||
return found && { blocks: outline(found.blocks), chained: found.chained, headers: found.blocks.map(block => source.slice(block.header.startIndex, block.header.endIndex)) }
|
||||
}
|
||||
finally {
|
||||
parsed.delete()
|
||||
}
|
||||
}
|
||||
|
||||
it('只用 && 连着的一串拆成一条一步(一步失败就停);整串带着的重定向只算在最后一条上,它的头部延到重定向结尾', async () => {
|
||||
expect(await steps('apt-get update && echo hi > /f && rm -rf /x')).toEqual({
|
||||
blocks: [{ at: 1, kind: 'command' }, { at: 1, kind: 'command' }, { at: 1, kind: 'command' }],
|
||||
chained: true,
|
||||
headers: ['apt-get update', 'echo hi > /f', 'rm -rf /x'],
|
||||
})
|
||||
})
|
||||
|
||||
it('条件串、有 || 的串、几句分开写的照 toBlocks 一句一步,不算一步失败就停', async () => {
|
||||
expect(await steps('[ -f x ] && rm x')).toMatchObject({ blocks: [{ at: 1, kind: 'if' }], chained: false })
|
||||
expect(await steps('a && b || c')).toMatchObject({ blocks: [{ at: 1, kind: 'command' }], chained: false })
|
||||
expect(await steps('a\nb')).toMatchObject({ blocks: [{ at: 1, kind: 'command' }, { at: 2, kind: 'command' }], chained: false })
|
||||
})
|
||||
})
|
||||
|
||||
describe('shell 命令、名字', () => {
|
||||
const commands = (source: string): Promise<unknown[]> => nodeFacts(adapter, 'shellscript', source, node => adapter.command?.(node))
|
||||
|
||||
|
||||
Reference in new issue
Block a user