-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathcompile.ts
More file actions
104 lines (97 loc) · 2.83 KB
/
compile.ts
File metadata and controls
104 lines (97 loc) · 2.83 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright 2020 Google Inc. Use of this source code is governed by an
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
import {initAsyncCompiler} from './compiler/async';
import {OptionsWithLegacy, StringOptionsWithLegacy} from './compiler/utils';
import {initCompiler} from './compiler/sync';
import {CompileResult, SourceMapIncludeSources} from './vendor/sass';
import {
DeprecationOptions,
deprecations,
warnForHostSideDeprecation,
} from './deprecations';
export {NodePackageImporter} from './importer-registry';
export function compile(
path: string,
options?: OptionsWithLegacy<'sync'>,
): CompileResult {
_warnForSourceMapIncludeSourcesBoolean(
options?.sourceMapIncludeSources,
options?.legacy,
options,
);
const compiler = initCompiler();
try {
return compiler.compile(path, options);
} finally {
compiler.dispose();
}
}
export function compileString(
source: string,
options?: StringOptionsWithLegacy<'sync'>,
): CompileResult {
_warnForSourceMapIncludeSourcesBoolean(
options?.sourceMapIncludeSources,
options?.legacy,
options,
);
const compiler = initCompiler();
try {
return compiler.compileString(source, options);
} finally {
compiler.dispose();
}
}
export async function compileAsync(
path: string,
options?: OptionsWithLegacy<'async'>,
): Promise<CompileResult> {
_warnForSourceMapIncludeSourcesBoolean(
options?.sourceMapIncludeSources,
options?.legacy,
options,
);
const compiler = await initAsyncCompiler();
try {
return await compiler.compileAsync(path, options);
} finally {
await compiler.dispose();
}
}
export async function compileStringAsync(
source: string,
options?: StringOptionsWithLegacy<'async'>,
): Promise<CompileResult> {
_warnForSourceMapIncludeSourcesBoolean(
options?.sourceMapIncludeSources,
options?.legacy,
options,
);
const compiler = await initAsyncCompiler();
try {
return await compiler.compileStringAsync(source, options);
} finally {
await compiler.dispose();
}
}
function _warnForSourceMapIncludeSourcesBoolean(
sourceMapIncludeSources?: SourceMapIncludeSources | boolean,
legacy?: boolean,
options?: DeprecationOptions,
): void {
if (
legacy !== true &&
(sourceMapIncludeSources === true || sourceMapIncludeSources === false)
) {
const suggestion = sourceMapIncludeSources ? 'always' : 'never';
warnForHostSideDeprecation(
'Passing a boolean value for Options.sourceMapIncludeSources is' +
'deprecated and will be removed in Dart Sass 2.0.0.\n' +
`Please use '${suggestion}' instead of ${sourceMapIncludeSources}.\n\n` +
'More info: https://sass-lang.com/d/source-map-include-sources-boolean',
deprecations['source-map-include-sources-boolean'],
options,
);
}
}