Fix KCL source ranges to know which source file they point to (#4418)

* Add ts_rs feature to work with indexmap

* Add feature for schemars to work with indexmap

* Add module ID to intern module paths

* Update code to use new source range with three fields

* Update generated files

* Update docs

* Fix wasm

* Fix TS code to use new SourceRange

* Fix TS tests to use new SourceRange and moduleId

* Fix formatting

* Fix to filter errors and source ranges to only show the top-level module

* Fix to reuse module IDs

* Fix to disallow empty path for import

* Revert unneeded Self change

* Rename field to be clearer

* Fix parser tests

* Update snapshots

* Change to not serialize module_id of 0

* Update snapshots after adding default module_id

* Move module_id functions to separate module

* Fix tests for console errors

* Proposal: module ID = 0 gets skipped when serializing tokens too (#4422)

Just like in AST nodes.

Also I think "is_top_level" communicates intention better than is_default

---------

Co-authored-by: Adam Chalmers <adam.chalmers@zoo.dev>
This commit is contained in:
Jonathan Tran
2024-11-07 11:23:41 -05:00
committed by GitHub
parent 30dfc167d3
commit 97705234c6
80 changed files with 1789 additions and 1246 deletions

View File

@ -242,6 +242,7 @@ export function mutateObjExpProp(
value: updateWith,
start: 0,
end: 0,
moduleId: 0,
})
}
}
@ -577,6 +578,7 @@ export function createLiteral(value: string | number): Node<Literal> {
type: 'Literal',
start: 0,
end: 0,
moduleId: 0,
value,
raw: `${value}`,
}
@ -587,6 +589,7 @@ export function createTagDeclarator(value: string): Node<TagDeclarator> {
type: 'TagDeclarator',
start: 0,
end: 0,
moduleId: 0,
value,
}
@ -597,6 +600,7 @@ export function createIdentifier(name: string): Node<Identifier> {
type: 'Identifier',
start: 0,
end: 0,
moduleId: 0,
name,
}
@ -607,6 +611,7 @@ export function createPipeSubstitution(): Node<PipeSubstitution> {
type: 'PipeSubstitution',
start: 0,
end: 0,
moduleId: 0,
}
}
@ -618,10 +623,12 @@ export function createCallExpressionStdLib(
type: 'CallExpression',
start: 0,
end: 0,
moduleId: 0,
callee: {
type: 'Identifier',
start: 0,
end: 0,
moduleId: 0,
name,
},
@ -638,10 +645,12 @@ export function createCallExpression(
type: 'CallExpression',
start: 0,
end: 0,
moduleId: 0,
callee: {
type: 'Identifier',
start: 0,
end: 0,
moduleId: 0,
name,
},
@ -657,6 +666,7 @@ export function createArrayExpression(
type: 'ArrayExpression',
start: 0,
end: 0,
moduleId: 0,
nonCodeMeta: nonCodeMetaEmpty(),
elements,
@ -670,6 +680,7 @@ export function createPipeExpression(
type: 'PipeExpression',
start: 0,
end: 0,
moduleId: 0,
body,
nonCodeMeta: nonCodeMetaEmpty(),
@ -686,12 +697,14 @@ export function createVariableDeclaration(
type: 'VariableDeclaration',
start: 0,
end: 0,
moduleId: 0,
declarations: [
{
type: 'VariableDeclarator',
start: 0,
end: 0,
moduleId: 0,
id: createIdentifier(varName),
init,
@ -709,12 +722,14 @@ export function createObjectExpression(properties: {
type: 'ObjectExpression',
start: 0,
end: 0,
moduleId: 0,
nonCodeMeta: nonCodeMetaEmpty(),
properties: Object.entries(properties).map(([key, value]) => ({
type: 'ObjectProperty',
start: 0,
end: 0,
moduleId: 0,
key: createIdentifier(key),
value,
@ -730,6 +745,7 @@ export function createUnaryExpression(
type: 'UnaryExpression',
start: 0,
end: 0,
moduleId: 0,
operator,
argument,
@ -745,6 +761,7 @@ export function createBinaryExpression([left, operator, right]: [
type: 'BinaryExpression',
start: 0,
end: 0,
moduleId: 0,
operator,
left,