summaryrefslogtreecommitdiff
path: root/src/compiler/codegen/index.ts
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@matthewphillips.info> 2021-04-23 15:20:05 -0400
committerGravatar GitHub <noreply@github.com> 2021-04-23 15:20:05 -0400
commit3ffeb0f7b7b16f8a0939a1ae80be90cccbd98579 (patch)
tree61908df2c2f5176f88b15b167773774c6b5105e9 /src/compiler/codegen/index.ts
parent9b9bdbf4a13a77acda47468fd4a1adfd3523f047 (diff)
downloadastro-3ffeb0f7b7b16f8a0939a1ae80be90cccbd98579.tar.gz
astro-3ffeb0f7b7b16f8a0939a1ae80be90cccbd98579.tar.zst
astro-3ffeb0f7b7b16f8a0939a1ae80be90cccbd98579.zip
Restore parse errors (#130)
Diffstat (limited to 'src/compiler/codegen/index.ts')
-rw-r--r--src/compiler/codegen/index.ts19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/compiler/codegen/index.ts b/src/compiler/codegen/index.ts
index a10268883..bca24d81d 100644
--- a/src/compiler/codegen/index.ts
+++ b/src/compiler/codegen/index.ts
@@ -9,11 +9,12 @@ import path from 'path';
import { walk } from 'estree-walker';
import _babelGenerator from '@babel/generator';
import babelParser from '@babel/parser';
+import { codeFrameColumns } from "@babel/code-frame";
import * as babelTraverse from '@babel/traverse';
import { ImportDeclaration, ExportNamedDeclaration, VariableDeclarator, Identifier } from '@babel/types';
import { warn } from '../../logger.js';
import { fetchContent } from './content.js';
-import { isFetchContent, isImportMetaDeclaration } from './utils.js';
+import { isFetchContent } from './utils.js';
import { yellow } from 'kleur/colors';
const traverse: typeof babelTraverse.default = (babelTraverse.default as any).default;
@@ -315,10 +316,22 @@ function compileModule(module: Script, state: CodegenState, compileOptions: Comp
const componentPlugins = new Set<ValidExtensionPlugins>();
if (module) {
- const program = babelParser.parse(module.content, {
+ const parseOptions: babelParser.ParserOptions = {
sourceType: 'module',
plugins: ['jsx', 'typescript', 'topLevelAwait'],
- }).program;
+ };
+ let parseResult;
+ try {
+ parseResult = babelParser.parse(module.content, parseOptions)
+ } catch(err) {
+ const location = { start: err.loc };
+ const frame = codeFrameColumns(module.content, location);
+ err.frame = frame;
+ err.filename = state.filename;
+ err.start = err.loc;
+ throw err;
+ }
+ const program = parseResult.program;
const { body } = program;
let i = body.length;