-
Notifications
You must be signed in to change notification settings - Fork 348
/
compile.dart
208 lines (190 loc) · 6.36 KB
/
compile.dart
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
// Copyright 2018 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.
// DO NOT EDIT. This file was generated from async_compile.dart.
// See tool/grind/synchronize.dart for details.
//
// Checksum: 7e80ff5e991b0815e71b91b23a869222f12cf90b
//
// ignore_for_file: unused_import
export 'async_compile.dart';
import 'dart:convert';
import 'package:cli_pkg/js.dart';
import 'package:path/path.dart' as p;
import 'ast/sass.dart';
import 'import_cache.dart';
import 'callable.dart';
import 'compile_result.dart';
import 'deprecation.dart';
import 'importer.dart';
import 'importer/legacy_node.dart';
import 'importer/no_op.dart';
import 'io.dart';
import 'logger.dart';
import 'logger/deprecation_processing.dart';
import 'syntax.dart';
import 'utils.dart';
import 'visitor/evaluate.dart';
import 'visitor/serialize.dart';
/// Like [compile] in `lib/sass.dart`, but provides more options to support
/// the node-sass compatible API and the executable.
///
/// If both `importCache` and `nodeImporter` are provided, the importers in
/// `importCache` will be evaluated before `nodeImporter`.
CompileResult compile(String path,
{Syntax? syntax,
Logger? logger,
ImportCache? importCache,
NodeImporter? nodeImporter,
Iterable<Callable>? functions,
OutputStyle? style,
bool useSpaces = true,
int? indentWidth,
LineFeed? lineFeed,
bool quietDeps = false,
bool verbose = false,
bool sourceMap = false,
bool charset = true,
Iterable<Deprecation>? silenceDeprecations,
Iterable<Deprecation>? fatalDeprecations,
Iterable<Deprecation>? futureDeprecations}) {
DeprecationProcessingLogger deprecationLogger = logger =
DeprecationProcessingLogger(logger ?? Logger.stderr(),
silenceDeprecations: {...?silenceDeprecations},
fatalDeprecations: {...?fatalDeprecations},
futureDeprecations: {...?futureDeprecations},
limitRepetition: !verbose);
// If the syntax is different than the importer would default to, we have to
// parse the file manually and we can't store it in the cache.
Stylesheet? stylesheet;
if (nodeImporter == null &&
(syntax == null || syntax == Syntax.forPath(path))) {
importCache ??= ImportCache.none(logger: logger);
stylesheet = importCache.importCanonical(
FilesystemImporter.cwd, p.toUri(canonicalize(path)),
originalUrl: p.toUri(path))!;
} else {
stylesheet = Stylesheet.parse(
readFile(path), syntax ?? Syntax.forPath(path),
url: p.toUri(path), logger: logger);
}
var result = _compileStylesheet(
stylesheet,
logger,
importCache,
nodeImporter,
FilesystemImporter.cwd,
functions,
style,
useSpaces,
indentWidth,
lineFeed,
quietDeps,
sourceMap,
charset);
deprecationLogger.summarize(js: nodeImporter != null);
return result;
}
/// Like [compileString] in `lib/sass.dart`, but provides more options to
/// support the node-sass compatible API.
///
/// At most one of `importCache` and `nodeImporter` may be provided at once.
CompileResult compileString(String source,
{Syntax? syntax,
Logger? logger,
ImportCache? importCache,
NodeImporter? nodeImporter,
Iterable<Importer>? importers,
Iterable<String>? loadPaths,
Importer? importer,
Iterable<Callable>? functions,
OutputStyle? style,
bool useSpaces = true,
int? indentWidth,
LineFeed? lineFeed,
Object? url,
bool quietDeps = false,
bool verbose = false,
bool sourceMap = false,
bool charset = true,
Iterable<Deprecation>? silenceDeprecations,
Iterable<Deprecation>? fatalDeprecations,
Iterable<Deprecation>? futureDeprecations}) {
DeprecationProcessingLogger deprecationLogger = logger =
DeprecationProcessingLogger(logger ?? Logger.stderr(),
silenceDeprecations: {...?silenceDeprecations},
fatalDeprecations: {...?fatalDeprecations},
futureDeprecations: {...?futureDeprecations},
limitRepetition: !verbose);
// Allow NoOpImporter because various first-party callers use that to opt out
// of the also-deprecated FilesystemImporter.cwd behavior.
if (importer != null && importer is! NoOpImporter && url == null) {
logger.warnForDeprecation(
Deprecation.importerWithoutUrl,
"Passing an importer to compileString* without a canonical URL is "
"deprecated and will be an error in future versions of Sass. Use the "
"importers argument for non-relative loads.");
}
var stylesheet =
Stylesheet.parse(source, syntax ?? Syntax.scss, url: url, logger: logger);
var result = _compileStylesheet(
stylesheet,
logger,
importCache,
nodeImporter,
importer ?? (isBrowser ? NoOpImporter() : FilesystemImporter.cwd),
functions,
style,
useSpaces,
indentWidth,
lineFeed,
quietDeps,
sourceMap,
charset);
deprecationLogger.summarize(js: nodeImporter != null);
return result;
}
/// Compiles [stylesheet] and returns its result.
///
/// Arguments are handled as for [compileString].
CompileResult _compileStylesheet(
Stylesheet stylesheet,
Logger? logger,
ImportCache? importCache,
NodeImporter? nodeImporter,
Importer importer,
Iterable<Callable>? functions,
OutputStyle? style,
bool useSpaces,
int? indentWidth,
LineFeed? lineFeed,
bool quietDeps,
bool sourceMap,
bool charset) {
var evaluateResult = evaluate(stylesheet,
importCache: importCache,
nodeImporter: nodeImporter,
importer: importer,
functions: functions,
logger: logger,
quietDeps: quietDeps,
sourceMap: sourceMap);
var serializeResult = serialize(evaluateResult.stylesheet,
style: style,
useSpaces: useSpaces,
indentWidth: indentWidth,
lineFeed: lineFeed,
sourceMap: sourceMap,
charset: charset);
var resultSourceMap = serializeResult.sourceMap;
if (resultSourceMap != null && importCache != null) {
mapInPlace(
resultSourceMap.urls,
(url) => url == ''
? Uri.dataFromString(stylesheet.span.file.getText(0),
encoding: utf8)
.toString()
: importCache.sourceMapUrl(Uri.parse(url)).toString());
}
return CompileResult(evaluateResult, serializeResult);
}