Skip to content

Commit

Permalink
Check for missing AST in parcel transformer (#1645)
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeLane authored Mar 12, 2024
1 parent cf43d66 commit 6a606ee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/brown-apes-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@compiled/parcel-transformer': patch
---

Check for missing AST in @compiled/parcel-transformer
18 changes: 11 additions & 7 deletions packages/parcel-transformer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,21 @@ export default new Transformer<ParcelTransformerOpts>({
plugins: config.transformerBabelPlugins ?? undefined,
});

return {
type: 'babel',
version: '7.0.0',
program,
};
if (program) {
return {
type: 'babel',
version: '7.0.0',
program,
};
}

return undefined;
},

async transform({ asset, config, options }) {
const ast = await asset.getAST();

if (!ast) {
if (!(ast?.type === 'babel' && ast.program)) {
// We will only receive ASTs for assets we're interested in.
// Since this is undefined (or in node modules) we aren't interested in it.
return [asset];
Expand Down Expand Up @@ -185,7 +189,7 @@ export default new Transformer<ParcelTransformerOpts>({
asset.setAST({
type: 'babel',
version: '7.0.0',
program: result?.ast,
program: result.ast,
});
}

Expand Down

0 comments on commit 6a606ee

Please sign in to comment.