ast parse ExportNamedDeclaration type, source filed maybe null
Closed this issue · 5 comments
in my project , i encounter an error "[vite] Internal server error: Cannot read property 'value' of null"
it seems getAvailableExportsFromAst in ast.ts
has bug.
const addExport = (node: ExportNamedDeclaration) => {
for (const specifier of node.specifiers) {
if (specifier.type === 'ExportSpecifier' && specifier.exported.type === 'Identifier') {
console.log('----max---', node) // console logs
exports.push({
start: specifier.exported.start!,
end: specifier.local.end!,
imported: specifier.exported.name,
local: specifier.local.name,
path: node.source.value // notice this line
})
}
}
}
i console the node
, got some logs:
----max--- Node {
type: 'ExportNamedDeclaration',
start: 932,
end: 963,
loc: SourceLocation {
start: Position { line: 51, column: 0 },
end: Position { line: 51, column: 31 },
filename: undefined,
identifierName: undefined
},
exportKind: 'value',
specifiers: [
Node {
type: 'ExportSpecifier',
start: 941,
end: 950,
loc: [SourceLocation],
local: [Node],
exportKind: 'value',
exported: [Node]
},
Node {
type: 'ExportSpecifier',
start: 952,
end: 961,
loc: [SourceLocation],
local: [Node],
exportKind: 'value',
exported: [Node]
}
],
source: null,
declaration: null
}
----max--- Node {
type: 'ExportNamedDeclaration',
start: 932,
end: 963,
loc: SourceLocation {
start: Position { line: 51, column: 0 },
end: Position { line: 51, column: 31 },
filename: undefined,
identifierName: undefined
},
exportKind: 'value',
specifiers: [
Node {
type: 'ExportSpecifier',
start: 941,
end: 950,
loc: [SourceLocation],
local: [Node],
exportKind: 'value',
exported: [Node]
},
Node {
type: 'ExportSpecifier',
start: 952,
end: 961,
loc: [SourceLocation],
local: [Node],
exportKind: 'value',
exported: [Node]
}
],
source: null,
declaration: null
}
----max--- Node {
type: 'ExportNamedDeclaration',
start: 1047,
end: 1073,
loc: SourceLocation {
start: Position { line: 46, column: 0 },
end: Position { line: 48, column: 1 },
filename: undefined,
identifierName: undefined
},
exportKind: 'value',
specifiers: [
Node {
type: 'ExportSpecifier',
start: 1059,
end: 1070,
loc: [SourceLocation],
local: [Node],
exportKind: 'value',
exported: [Node]
}
],
source: null,
declaration: null
}
----max--- Node {
type: 'ExportNamedDeclaration',
start: 932,
end: 963,
loc: SourceLocation {
start: Position { line: 51, column: 0 },
end: Position { line: 51, column: 31 },
filename: undefined,
identifierName: undefined
},
exportKind: 'value',
specifiers: [
Node {
type: 'ExportSpecifier',
start: 941,
end: 950,
loc: [SourceLocation],
local: [Node],
exportKind: 'value',
exported: [Node]
},
Node {
type: 'ExportSpecifier',
start: 952,
end: 961,
loc: [SourceLocation],
local: [Node],
exportKind: 'value',
exported: [Node]
}
],
source: null,
declaration: null
}
----max--- Node {
type: 'ExportNamedDeclaration',
start: 932,
end: 963,
loc: SourceLocation {
start: Position { line: 51, column: 0 },
end: Position { line: 51, column: 31 },
filename: undefined,
identifierName: undefined
},
exportKind: 'value',
specifiers: [
Node {
type: 'ExportSpecifier',
start: 941,
end: 950,
loc: [SourceLocation],
local: [Node],
exportKind: 'value',
exported: [Node]
},
Node {
type: 'ExportSpecifier',
start: 952,
end: 961,
loc: [SourceLocation],
local: [Node],
exportKind: 'value',
exported: [Node]
}
],
source: null,
declaration: null
}
the node.source
maybe null
value , is it should use node.source?.value
to fixed it ?
I think this is the second time this has been reported. Can you provide a reproduction for this, I'm not quite sure what is causing it yet
I think this is the second time this has been reported. Can you provide a reproduction for this, I'm not quite sure what is causing it yet
I was the one who reported last time.
i think it caused by some ts file have not export default
statements.
i made a reproduce demo:
https://stackblitz.com/edit/vitejs-vite-rdmu1d?file=src%2FApp.vue
Thanks, I'll get a fix out soon
Thanks, I'll get a fix out soon
hi, have you solved it ?