Skip to content

Commit

Permalink
use set the dart version from the Platform library instead of the ana…
Browse files Browse the repository at this point in the history
…nlyzer library because that analyzer library may use beta versions
  • Loading branch information
Goodwine committed Dec 20, 2024
1 parent e681eb6 commit adb872a
Show file tree
Hide file tree
Showing 7 changed files with 1,463 additions and 2,270 deletions.
264 changes: 121 additions & 143 deletions lib/src/compile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,69 +37,60 @@ import 'visitor/serialize.dart';
///
/// 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,
}) {
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,
)..validate();
logger = DeprecationProcessingLogger(logger ?? Logger.stderr(),
silenceDeprecations: {...?silenceDeprecations},
fatalDeprecations: {...?fatalDeprecations},
futureDeprecations: {...?futureDeprecations},
limitRepetition: !verbose)
..validate();

// 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();
stylesheet =
importCache.importCanonical(
FilesystemImporter.cwd,
p.toUri(canonicalize(path)),
originalUrl: p.toUri(path),
)!;
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),
);
readFile(path), syntax ?? Syntax.forPath(path),
url: p.toUri(path));
}

var result = _compileStylesheet(
stylesheet,
logger,
importCache,
nodeImporter,
FilesystemImporter.cwd,
functions,
style,
useSpaces,
indentWidth,
lineFeed,
quietDeps,
sourceMap,
charset,
);
stylesheet,
logger,
importCache,
nodeImporter,
FilesystemImporter.cwd,
functions,
style,
useSpaces,
indentWidth,
lineFeed,
quietDeps,
sourceMap,
charset);

deprecationLogger.summarize(js: nodeImporter != null);
return result;
Expand All @@ -109,55 +100,51 @@ CompileResult compile(
/// 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,
}) {
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,
)..validate();
logger = DeprecationProcessingLogger(logger ?? Logger.stderr(),
silenceDeprecations: {...?silenceDeprecations},
fatalDeprecations: {...?fatalDeprecations},
futureDeprecations: {...?futureDeprecations},
limitRepetition: !verbose)
..validate();

var stylesheet = Stylesheet.parse(source, syntax ?? Syntax.scss, url: url);

var result = _compileStylesheet(
stylesheet,
logger,
importCache,
nodeImporter,
importer ?? (isBrowser ? NoOpImporter() : FilesystemImporter.cwd),
functions,
style,
useSpaces,
indentWidth,
lineFeed,
quietDeps,
sourceMap,
charset,
);
stylesheet,
logger,
importCache,
nodeImporter,
importer ?? (isBrowser ? NoOpImporter() : FilesystemImporter.cwd),
functions,
style,
useSpaces,
indentWidth,
lineFeed,
quietDeps,
sourceMap,
charset);

deprecationLogger.summarize(js: nodeImporter != null);
return result;
Expand All @@ -167,62 +154,53 @@ CompileResult compileString(
///
/// 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,
) {
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) {
if (nodeImporter != null) {
logger?.warnForDeprecation(
Deprecation.legacyJsApi,
'The legacy JS API is deprecated and will be removed in '
'Dart Sass 2.0.0.\n\n'
'More info: https://sass-lang.com/d/legacy-js-api',
);
Deprecation.legacyJsApi,
'The legacy JS API is deprecated and will be removed in '
'Dart Sass 2.0.0.\n\n'
'More info: https://sass-lang.com/d/legacy-js-api');
}
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,
logger: logger,
sourceMap: sourceMap,
charset: 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,
logger: logger,
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(),
);
resultSourceMap.urls,
(url) => url == ''
? Uri.dataFromString(stylesheet.span.file.getText(0),
encoding: utf8)
.toString()
: importCache.sourceMapUrl(Uri.parse(url)).toString());
}

return CompileResult(evaluateResult, serializeResult);
Expand Down
Loading

0 comments on commit adb872a

Please sign in to comment.