Skip to content

Commit

Permalink
Merge pull request #284 from sass/merge-main
Browse files Browse the repository at this point in the history
Merge main into feature.color-4
  • Loading branch information
nex3 committed Apr 12, 2024
2 parents fef63f3 + a843bd5 commit 625e11d
Show file tree
Hide file tree
Showing 23 changed files with 345 additions and 40 deletions.
79 changes: 79 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,82 @@
## 1.74.1

* No user-visible changes.

## 1.74.0

### JS API

* Add a new top-level `deprecations` object, which contains various
`Deprecation` objects that define the different types of deprecation used by
the Sass compiler and can be passed to the options below.

* Add a new `fatalDeprecations` compiler option that causes the compiler to
error if any deprecation warnings of the provided types are encountered. You
can also pass in a `Version` object to treat all deprecations that were active
in that Dart Sass version as fatal.

* Add a new `futureDeprecations` compiler option that allows you to opt-in to
certain deprecations early (currently just `import`).

* Add a new `silenceDeprecations` compiler option to ignore any deprecation
warnings of the provided types.

### Command-Line Interface

* Add a new `--silence-deprecation` flag, which causes the compiler to ignore
any deprecation warnings of the provided types.

* Previously, if a future deprecation was passed to `--fatal-deprecation` but
not `--future-deprecation`, it would be treated as fatal despite not being
enabled. Both flags are now required to treat a future deprecation as fatal
with a warning emitted if `--fatal-deprecation` is passed without
`--future-deprecation`, matching the JS API's behavior.

### Dart API

* The `compile` methods now take in a `silenceDeprecations` parameter, which
causes the compiler to ignore any deprecation warnings of the provided types.

* Add `Deprecation.obsoleteIn` to match the JS API. This is currently null for
all deprecations, but will be used once some deprecations become obsolete in
Dart Sass 2.0.0.

* **Potentially breaking bug fix:** Fix a bug where `compileStringToResultAsync`
ignored `fatalDeprecations` and `futureDeprecations`.

* The behavior around making future deprecations fatal mentioned in the CLI
section above has also been changed in the Dart API.

## 1.73.0

* Add support for nesting in plain CSS files. This is not processed by Sass at
all; it's emitted exactly as-is in the CSS.

* In certain circumstances, the current working directory was unintentionally
being made available as a load path. This is now deprecated. Anyone relying on
this should explicitly pass in `.` as a load path or `FilesystemImporter('.')`
as the current importer.

* Add linux-riscv64 and windows-arm64 releases.

### Command-Line Interface

* Fix a bug where absolute `file:` URLs weren't loaded for files compiled via
the command line unless an unrelated load path was also passed.

* Fix a bug where `--update` would always update files that were specified via
absolute path unless an unrelated load path was also passed.

### Dart API

* Add `FilesystemImporter.noLoadPath`, which is a `FilesystemImporter` that can
load absolute `file:` URLs and resolve URLs relative to the base file but
doesn't load relative URLs from a load path.

* `FilesystemImporter.cwd` is now deprecated. Either use
`FilesystemImporter.noLoadPath` if you weren't intending to rely on the load
path, or `FilesystemImporter('.')` if you were.

## 1.72.0

* Support adjacent `/`s without whitespace in between when parsing plain CSS
Expand Down
10 changes: 10 additions & 0 deletions lib/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export const AsyncCompiler = sass.AsyncCompiler;
export const Compiler = sass.Compiler;
export const initAsyncCompiler = sass.initAsyncCompiler;
export const initCompiler = sass.initCompiler;
export const deprecations = sass.deprecations;
export const Version = sass.Version;
export const Logger = sass.Logger;
export const CalculationInterpolation = sass.CalculationInterpolation;
export const CalculationOperation = sass.CalculationOperation;
Expand Down Expand Up @@ -86,6 +88,14 @@ export default {
defaultExportDeprecation();
return sass.Compiler;
},
get deprecations() {
defaultExportDeprecation();
return sass.deprecations;
},
get Version() {
defaultExportDeprecation();
return sass.Version;
},
get Logger() {
defaultExportDeprecation();
return sass.Logger;
Expand Down
7 changes: 7 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ export {
} from './src/compile';
export {initAsyncCompiler, AsyncCompiler} from './src/compiler/async';
export {initCompiler, Compiler} from './src/compiler/sync';
export {
deprecations,
Deprecation,
DeprecationOrId,
DeprecationStatus,
Version,
} from './src/deprecations';
export {render, renderSync} from './src/legacy';

export const info = `sass-embedded\t${pkg.version}`;
Expand Down
30 changes: 26 additions & 4 deletions lib/src/compiler/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import * as p from 'path';
import * as supportsColor from 'supports-color';
import {deprecations, getDeprecationIds, Deprecation} from '../deprecations';
import {deprotofySourceSpan} from '../deprotofy-span';
import {Dispatcher, DispatcherHandlers} from '../dispatcher';
import {Exception} from '../exception';
Expand Down Expand Up @@ -75,6 +76,9 @@ function newCompileRequest(
verbose: !!options?.verbose,
charset: !!(options?.charset ?? true),
silent: options?.logger === Logger.silent,
fatalDeprecation: getDeprecationIds(options?.fatalDeprecations ?? []),
silenceDeprecation: getDeprecationIds(options?.silenceDeprecations ?? []),
futureDeprecation: getDeprecationIds(options?.futureDeprecations ?? []),
});

switch (options?.style ?? 'expanded') {
Expand Down Expand Up @@ -137,6 +141,13 @@ export function newCompileStringRequest(
return request;
}

/** Type guard to check that `id` is a valid deprecation ID. */
function validDeprecationId(
id: string | number | symbol | undefined
): id is keyof typeof deprecations {
return !!id && id in deprecations;
}

/** Handles a log event according to `options`. */
export function handleLogEvent(
options: OptionsWithLegacy<'sync' | 'async'> | undefined,
Expand All @@ -148,6 +159,9 @@ export function handleLogEvent(
if (options?.legacy) message = removeLegacyImporter(message);
let formatted = event.formatted;
if (options?.legacy) formatted = removeLegacyImporter(formatted);
const deprecationType = validDeprecationId(event.deprecationType)
? deprecations[event.deprecationType]
: null;

if (event.type === proto.LogEventType.DEBUG) {
if (options?.logger?.debug) {
Expand All @@ -159,10 +173,18 @@ export function handleLogEvent(
}
} else {
if (options?.logger?.warn) {
const params: {deprecation: boolean; span?: SourceSpan; stack?: string} =
{
deprecation: event.type === proto.LogEventType.DEPRECATION_WARNING,
};
const params: (
| {
deprecation: true;
deprecationType: Deprecation;
}
| {deprecation: false}
) & {
span?: SourceSpan;
stack?: string;
} = deprecationType
? {deprecation: true, deprecationType: deprecationType}
: {deprecation: false};
if (span) params.span = span;

const stack = event.stackTrace;
Expand Down
187 changes: 187 additions & 0 deletions lib/src/deprecations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
// Copyright 2024 Google LLC. 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 * as api from './vendor/sass';

export {Deprecation, DeprecationOrId, DeprecationStatus} from './vendor/sass';

export class Version implements api.Version {
constructor(
readonly major: number,
readonly minor: number,
readonly patch: number
) {}
static parse(version: string): Version {
const match = version.match(/^(\d+)\.(\d+)\.(\d+)$/);
if (match === null) {
throw new Error(`Invalid version ${version}`);
}
return new Version(
parseInt(match[1]),
parseInt(match[2]),
parseInt(match[3])
);
}
}

/**
* Returns whether the given deprecation was active in the given version.
*/
function isActiveIn(deprecation: api.Deprecation, version: Version) {
const deprecatedIn = deprecation.deprecatedIn;
if (deprecation.status !== 'active' || !deprecatedIn) return false;
if (version.major > deprecatedIn.major) return true;
if (version.major < deprecatedIn.major) return false;
if (version.minor > deprecatedIn.minor) return true;
if (version.minor < deprecatedIn.minor) return false;
return version.patch >= deprecatedIn.patch;
}

/**
* Converts a mixed array of deprecations, IDs, and versions to an array of IDs
* that's ready to include in a CompileRequest.
*/
export function getDeprecationIds(
arr: (api.DeprecationOrId | Version)[]
): string[] {
return arr.flatMap(item => {
if (item instanceof Version) {
return Object.values(deprecations)
.filter(deprecation => isActiveIn(deprecation, item))
.map(deprecation => deprecation.id);
} else if (typeof item === 'string') {
return item;
}
return item.id;
});
}

export const deprecations: typeof api.deprecations = {
'call-string': {
id: 'call-string',
status: 'active',
deprecatedIn: new Version(0, 0, 0),
obsoleteIn: null,
description: 'Passing a string directly to meta.call().',
},
elseif: {
id: 'elseif',
status: 'active',
deprecatedIn: new Version(1, 3, 2),
obsoleteIn: null,
description: '@elseif.',
},
'moz-document': {
id: 'moz-document',
status: 'active',
deprecatedIn: new Version(1, 7, 2),
obsoleteIn: null,
description: '@-moz-document.',
},
'relative-canonical': {
id: 'relative-canonical',
status: 'active',
deprecatedIn: new Version(1, 14, 2),
obsoleteIn: null,
},
'new-global': {
id: 'new-global',
status: 'active',
deprecatedIn: new Version(1, 17, 2),
obsoleteIn: null,
description: 'Declaring new variables with !global.',
},
'color-module-compat': {
id: 'color-module-compat',
status: 'active',
deprecatedIn: new Version(1, 23, 0),
obsoleteIn: null,
description:
'Using color module functions in place of plain CSS functions.',
},
'slash-div': {
id: 'slash-div',
status: 'active',
deprecatedIn: new Version(1, 33, 0),
obsoleteIn: null,
description: '/ operator for division.',
},
'bogus-combinators': {
id: 'bogus-combinators',
status: 'active',
deprecatedIn: new Version(1, 54, 0),
obsoleteIn: null,
description: 'Leading, trailing, and repeated combinators.',
},
'strict-unary': {
id: 'strict-unary',
status: 'active',
deprecatedIn: new Version(1, 55, 0),
obsoleteIn: null,
description: 'Ambiguous + and - operators.',
},
'function-units': {
id: 'function-units',
status: 'active',
deprecatedIn: new Version(1, 56, 0),
obsoleteIn: null,
description: 'Passing invalid units to built-in functions.',
},
'duplicate-var-flags': {
id: 'duplicate-var-flags',
status: 'active',
deprecatedIn: new Version(1, 62, 0),
obsoleteIn: null,
description: 'Using !default or !global multiple times for one variable.',
},
'null-alpha': {
id: 'null-alpha',
status: 'active',
deprecatedIn: new Version(1, 62, 3),
obsoleteIn: null,
description: 'Passing null as alpha in the JS API.',
},
'abs-percent': {
id: 'abs-percent',
status: 'active',
deprecatedIn: new Version(1, 65, 0),
obsoleteIn: null,
description: 'Passing percentages to the Sass abs() function.',
},
'fs-importer-cwd': {
id: 'fs-importer-cwd',
status: 'active',
deprecatedIn: new Version(1, 73, 0),
obsoleteIn: null,
description:
'Using the current working directory as an implicit load path.',
},
'color-4-api': {
id: 'color-4-api',
status: 'active',
deprecatedIn: new Version(1, 76, 0),
obsoleteIn: null,
description: 'Methods of interacting with legacy SassColors.',
},
'color-functions': {
id: 'color-functions',
status: 'active',
deprecatedIn: new Version(1, 76, 0),
obsoleteIn: null,
description: 'Using global Sass color functions.',
},
import: {
id: 'import',
status: 'future',
deprecatedIn: null,
obsoleteIn: null,
description: '@import rules.',
},
'user-authored': {
id: 'user-authored',
status: 'user',
deprecatedIn: null,
obsoleteIn: null,
},
};
2 changes: 1 addition & 1 deletion npm/android-arm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sass-embedded-android-arm",
"version": "1.72.0",
"version": "1.74.1",
"description": "The android-arm binary for sass-embedded",
"repository": "sass/embedded-host-node",
"author": "Google Inc.",
Expand Down
2 changes: 1 addition & 1 deletion npm/android-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sass-embedded-android-arm64",
"version": "1.72.0",
"version": "1.74.1",
"description": "The android-arm64 binary for sass-embedded",
"repository": "sass/embedded-host-node",
"author": "Google Inc.",
Expand Down
2 changes: 1 addition & 1 deletion npm/android-ia32/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sass-embedded-android-ia32",
"version": "1.72.0",
"version": "1.74.1",
"description": "The android-ia32 binary for sass-embedded",
"repository": "sass/embedded-host-node",
"author": "Google Inc.",
Expand Down

0 comments on commit 625e11d

Please sign in to comment.