-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathtypescript.ts
More file actions
48 lines (35 loc) · 1.17 KB
/
typescript.ts
File metadata and controls
48 lines (35 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import {Configuration, loadConfiguration} from '../../backend/config-loader'
import {IPCClient} from '../../backend/worker/client'
import {processSourceMaps} from '../../exports'
import TypescriptAsset from 'parcel-bundler/src/assets/TypeScriptAsset'
class TSAsset extends TypescriptAsset {
private readonly config: Promise<Configuration>
constructor(name: string, options: any) {
super(name, options)
this.config = loadConfiguration(name, options.rootDir)
}
public async parse(): Promise<any> {
const config = await this.config
const reportErrors = !config.typescript.options.noEmitOnError
const result = await IPCClient.compile({
file: this.name,
rootDir: this.options.rootDir,
reportErrors
})
if(!reportErrors) {
const {diagnostics} = result
if(diagnostics) {
console.error(diagnostics)
// tslint:disable:no-string-throw
throw 'TypeScript errors were found while compiling'
}
}
this.contents = processSourceMaps(this, result.sources).js
// Parse result as ast format through babylon
return super.parse(this.contents)
}
public generateErrorMessage(err: any) {
return err.stack || err.message || err
}
}
export = TSAsset