1
1
import { walk as zimmerframe_walk } from 'zimmerframe' ;
2
- import { CompileError } from './errors.js' ;
3
2
import { convert } from './legacy.js' ;
4
3
import { parse as parse_acorn } from './phases/1-parse/acorn.js' ;
5
4
import { parse as _parse } from './phases/1-parse/index.js' ;
@@ -22,38 +21,30 @@ export function compile(source, options) {
22
21
const validated = validate_component_options ( options , '' ) ;
23
22
state . reset ( source , validated ) ;
24
23
25
- try {
26
- let parsed = _parse ( source ) ;
24
+ let parsed = _parse ( source ) ;
27
25
28
- const { customElement : customElementOptions , ...parsed_options } = parsed . options || { } ;
26
+ const { customElement : customElementOptions , ...parsed_options } = parsed . options || { } ;
29
27
30
- /** @type {import('#compiler').ValidatedCompileOptions } */
31
- const combined_options = {
32
- ...validated ,
33
- ...parsed_options ,
34
- customElementOptions
35
- } ;
28
+ /** @type {import('#compiler').ValidatedCompileOptions } */
29
+ const combined_options = {
30
+ ...validated ,
31
+ ...parsed_options ,
32
+ customElementOptions
33
+ } ;
36
34
37
- if ( parsed . metadata . ts ) {
38
- parsed = {
39
- ...parsed ,
40
- fragment : parsed . fragment && remove_typescript_nodes ( parsed . fragment ) ,
41
- instance : parsed . instance && remove_typescript_nodes ( parsed . instance ) ,
42
- module : parsed . module && remove_typescript_nodes ( parsed . module )
43
- } ;
44
- }
45
-
46
- const analysis = analyze_component ( parsed , source , combined_options ) ;
47
- const result = transform_component ( analysis , source , combined_options ) ;
48
- result . ast = to_public_ast ( source , parsed , options . modernAst ) ;
49
- return result ;
50
- } catch ( e ) {
51
- if ( e instanceof CompileError ) {
52
- handle_compile_error ( e ) ;
53
- }
54
-
55
- throw e ;
35
+ if ( parsed . metadata . ts ) {
36
+ parsed = {
37
+ ...parsed ,
38
+ fragment : parsed . fragment && remove_typescript_nodes ( parsed . fragment ) ,
39
+ instance : parsed . instance && remove_typescript_nodes ( parsed . instance ) ,
40
+ module : parsed . module && remove_typescript_nodes ( parsed . module )
41
+ } ;
56
42
}
43
+
44
+ const analysis = analyze_component ( parsed , source , combined_options ) ;
45
+ const result = transform_component ( analysis , source , combined_options ) ;
46
+ result . ast = to_public_ast ( source , parsed , options . modernAst ) ;
47
+ return result ;
57
48
}
58
49
59
50
/**
@@ -68,34 +59,8 @@ export function compileModule(source, options) {
68
59
const validated = validate_module_options ( options , '' ) ;
69
60
state . reset ( source , validated ) ;
70
61
71
- try {
72
- const analysis = analyze_module ( parse_acorn ( source , false ) , validated ) ;
73
- const result = transform_module ( analysis , source , validated ) ;
74
- return result ;
75
- } catch ( e ) {
76
- if ( e instanceof CompileError ) {
77
- handle_compile_error ( e ) ;
78
- }
79
-
80
- throw e ;
81
- }
82
- }
83
-
84
- /**
85
- * @param {import('#compiler').CompileError } error
86
- */
87
- function handle_compile_error ( error ) {
88
- error . filename = state . filename ;
89
-
90
- if ( error . position ) {
91
- const start = state . locator ( error . position [ 0 ] ) ;
92
- const end = state . locator ( error . position [ 1 ] ) ;
93
-
94
- error . start = start ;
95
- error . end = end ;
96
- }
97
-
98
- throw error ;
62
+ const analysis = analyze_module ( parse_acorn ( source , false ) , validated ) ;
63
+ return transform_module ( analysis , source , validated ) ;
99
64
}
100
65
101
66
/**
@@ -138,18 +103,7 @@ function handle_compile_error(error) {
138
103
export function parse ( source , { filename, rootDir, modern } = { } ) {
139
104
state . reset ( source , { filename, rootDir } ) ; // TODO it's weird to require filename/rootDir here. reconsider the API
140
105
141
- /** @type {import('#compiler').Root } */
142
- let ast ;
143
- try {
144
- ast = _parse ( source ) ;
145
- } catch ( e ) {
146
- if ( e instanceof CompileError ) {
147
- handle_compile_error ( e ) ;
148
- }
149
-
150
- throw e ;
151
- }
152
-
106
+ const ast = _parse ( source ) ;
153
107
return to_public_ast ( source , ast , modern ) ;
154
108
}
155
109
0 commit comments