Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose charset option in Node API [closes #567] #1446

Merged
merged 4 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
## 1.38.3
## 1.39.0

* No user-visible changes.
### JS API

* Add a `charset` option that controls whether or not Sass emits a
`@charset`/BOM for non-ASCII stylesheets.

## 1.38.2

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ Both `render()` and `renderSync()` support the following options:
* [`sourceMap`](https://github.com/sass/node-sass#sourcemap)
* Only the `"expanded"` and `"compressed"` values of
[`outputStyle`](https://github.com/sass/node-sass#outputstyle) are supported.
* `charset` (`true`, the default, will prefix non-ASCII CSS with `U+FEFF` or
[`@charset "UTF-8";`](https://developer.mozilla.org/en-US/docs/Web/CSS/@charset))

No support is intended for the following options:

Expand Down
4 changes: 4 additions & 0 deletions lib/src/node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Future<RenderResult> _renderAsync(RenderOptions options) async {
url: file == null ? 'stdin' : p.toUri(file).toString(),
quietDeps: options.quietDeps ?? false,
verbose: options.verbose ?? false,
charset: options.charset ?? true,
sourceMap: _enableSourceMaps(options));
} else if (file != null) {
result = await compileAsync(file,
Expand All @@ -121,6 +122,7 @@ Future<RenderResult> _renderAsync(RenderOptions options) async {
lineFeed: _parseLineFeed(options.linefeed),
quietDeps: options.quietDeps ?? false,
verbose: options.verbose ?? false,
charset: options.charset ?? true,
sourceMap: _enableSourceMaps(options));
} else {
throw ArgumentError("Either options.data or options.file must be set.");
Expand Down Expand Up @@ -154,6 +156,7 @@ RenderResult _renderSync(RenderOptions options) {
url: file == null ? 'stdin' : p.toUri(file).toString(),
quietDeps: options.quietDeps ?? false,
verbose: options.verbose ?? false,
charset: options.charset ?? true,
sourceMap: _enableSourceMaps(options));
} else if (file != null) {
result = compile(file,
Expand All @@ -166,6 +169,7 @@ RenderResult _renderSync(RenderOptions options) {
lineFeed: _parseLineFeed(options.linefeed),
quietDeps: options.quietDeps ?? false,
verbose: options.verbose ?? false,
charset: options.charset ?? true,
sourceMap: _enableSourceMaps(options));
} else {
throw ArgumentError("Either options.data or options.file must be set.");
Expand Down
4 changes: 3 additions & 1 deletion lib/src/node/render_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class RenderOptions {
external String? get sourceMapRoot;
external bool? get quietDeps;
external bool? get verbose;
external bool? get charset;

external factory RenderOptions(
{String? file,
Expand All @@ -48,5 +49,6 @@ class RenderOptions {
bool? sourceMapEmbed,
String? sourceMapRoot,
bool? quietDeps,
bool? verbose});
bool? verbose,
bool? charset});
}
4 changes: 2 additions & 2 deletions pkg/sass_api/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ name: sass_api
# Note: Every time we add a new Sass AST node, we need to bump the *major*
# version because it's a breaking change for anyone who's implementing the
# visitor interface(s).
version: 1.0.0-dev
version: 1.0.0-beta.6
description: Additional APIs for Dart Sass.
homepage: https://github.com/sass/dart-sass

environment:
sdk: '>=2.12.0 <3.0.0'

dependencies:
sass: 1.38.2
sass: 1.39.0

dependency_overrides:
sass: {path: ../..}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: sass
version: 1.38.3-dev
version: 1.39.0
description: A Sass implementation in Dart.
homepage: https://github.com/sass/dart-sass

Expand Down
16 changes: 16 additions & 0 deletions test/node_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,22 @@ a {
}'''));
});

group("unicode", () {
test("adds @charset by default", () async {
var unicodePath = p.join(sandbox, 'test.scss');
await writeTextFile(unicodePath, 'p { content: "é"; } ');
expect(renderSync(RenderOptions(file: unicodePath)),
equalsIgnoringWhitespace('@charset "UTF-8"; p { content: "é"; } '));
});

test("allows charset=false to hide @charset", () async {
var unicodePath = p.join(sandbox, 'test.scss');
await writeTextFile(unicodePath, 'p { content: "é"; } ');
expect(renderSync(RenderOptions(file: unicodePath, charset: false)),
equalsIgnoringWhitespace('p { content: "é"; } '));
});
});

group("linefeed allows", () {
test("cr", () {
expect(renderSync(RenderOptions(file: sassPath, linefeed: 'cr')),
Expand Down