Skip to content

Commit 69cbcca

Browse files
committed
Implement error recovery
Closes parcel-bundler#39. Closes parcel-bundler#209.
1 parent 5b63dd4 commit 69cbcca

File tree

12 files changed

+496
-210
lines changed

12 files changed

+496
-210
lines changed

examples/serialize.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ fn parse() {
99

1010
let args: Vec<String> = env::args().collect();
1111
let contents = fs::read_to_string(&args[1]).unwrap();
12-
let stylesheet = StyleSheet::parse(&args[1], &contents, ParserOptions::default()).unwrap();
12+
let stylesheet = StyleSheet::parse(
13+
&contents,
14+
ParserOptions {
15+
filename: args[1].clone(),
16+
..ParserOptions::default()
17+
},
18+
)
19+
.unwrap();
1320
let json = serde_json::to_string(&stylesheet).unwrap();
1421
println!("{}", json);
1522
}

node/index.d.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ export interface TransformOptions {
3434
* to be unused. These will be removed during minification. Note that these are not
3535
* selectors but individual names (without any . or # prefixes).
3636
*/
37-
unusedSymbols?: string[]
37+
unusedSymbols?: string[],
38+
/**
39+
* Whether to ignore invalid rules and declarations rather than erroring.
40+
* When enabled, warnings are returned, and the invalid rule or declaration is
41+
* omitted from the output code.
42+
*/
43+
errorRecovery?: boolean
3844
}
3945

4046
export type BundleOptions = Omit<TransformOptions, 'code'>;
@@ -64,7 +70,16 @@ export interface TransformResult {
6470
/** CSS module references, if `dashedIdents` is enabled. */
6571
references: CSSModuleReferences,
6672
/** `@import` and `url()` dependencies, if enabled. */
67-
dependencies: Dependency[] | void
73+
dependencies: Dependency[] | void,
74+
/** Warnings that occurred during compilation. */
75+
warnings: Warning[]
76+
}
77+
78+
export interface Warning {
79+
message: string,
80+
type: string,
81+
value?: any,
82+
loc: ErrorLocation
6883
}
6984

7085
export interface CSSModulesConfig {
@@ -155,6 +170,10 @@ export interface Location {
155170
column: number
156171
}
157172

173+
export interface ErrorLocation extends Location {
174+
filename: string
175+
}
176+
158177
/**
159178
* Compiles a CSS file, including optionally minifying and lowering syntax to the given
160179
* targets. A source map may also be generated, but this is not enabled by default.

0 commit comments

Comments
 (0)