@jesscss/plugin-scss 2.0.0-alpha.8 → 2.0.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -25,10 +25,9 @@ preview, not a promise.
25
25
 
26
26
  ## Status
27
27
 
28
- **Alpha / experimental.** Part of [Jess](https://github.com/jesscss/jess), the
29
- ground-up rewrite of Less.js (Jess *is* Less.js v5). The programmatic
30
- plugin/compiler API is **not yet stabilized** — the `jess` / `lessc` CLIs are the
31
- public surface for the alpha, and they target Less.
28
+ **Alpha / experimental.** Part of [Jess](https://github.com/jesscss/jess). The
29
+ programmatic plugin/compiler API is **not yet stabilized** the `jess` CLI is
30
+ the documented public surface for the alpha, and it targets Less today.
32
31
 
33
32
  - Project overview & positioning: <https://github.com/jesscss/jess#readme>
34
33
  - Docs: <https://jesscss.github.io/> (currently pre-alpha content)
package/lib/index.cjs CHANGED
@@ -2,38 +2,13 @@ Object.defineProperties(exports, {
2
2
  __esModule: { value: true },
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
- //#region \0rolldown/runtime.js
6
- var __create = Object.create;
7
- var __defProp = Object.defineProperty;
8
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
- var __getOwnPropNames = Object.getOwnPropertyNames;
10
- var __getProtoOf = Object.getPrototypeOf;
11
- var __hasOwnProp = Object.prototype.hasOwnProperty;
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
14
- key = keys[i];
15
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
- get: ((k) => from[k]).bind(null, key),
17
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
- });
19
- }
20
- return to;
21
- };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
- value: mod,
24
- enumerable: true
25
- }) : target, mod));
26
- //#endregion
27
5
  let _jesscss_core = require("@jesscss/core");
28
- let _jesscss_scss_parser_jess = require("@jesscss/scss-parser/jess");
29
- let node_path = require("node:path");
30
- node_path = __toESM(node_path);
6
+ let _jesscss_scss_parser = require("@jesscss/scss-parser");
31
7
  let _jesscss_style_resolver = require("@jesscss/style-resolver");
32
8
  //#region src/index.ts
33
9
  var ScssPlugin = class extends _jesscss_core.AbstractPlugin {
34
10
  name = "scss";
35
11
  supportedExtensions = [".scss"];
36
- parser;
37
12
  unitMode;
38
13
  equalityMode;
39
14
  constructor(opts = {}) {
@@ -41,77 +16,28 @@ var ScssPlugin = class extends _jesscss_core.AbstractPlugin {
41
16
  this.opts = opts;
42
17
  this.unitMode = opts.unitMode ?? "preserve";
43
18
  this.equalityMode = opts.equalityMode ?? "sass";
44
- this.parser = new _jesscss_scss_parser_jess.Parser();
45
19
  }
46
20
  expandImport(importPath) {
47
21
  return (0, _jesscss_style_resolver.expandScssImportCandidates)(importPath);
48
22
  }
49
- safeParse(filePath, source, parseOptions) {
50
- const allowExtendSelectors = this.opts.allowExtendSelectors ?? parseOptions?.compilerOptions?.allowExtendSelectors ?? ["simple"];
51
- const context = new _jesscss_core.TreeContext({
52
- file: {
53
- name: node_path.default.basename(filePath),
54
- path: node_path.default.dirname(filePath),
55
- fullPath: filePath,
56
- source
57
- },
58
- plugin: this,
59
- allowExtendSelectors,
60
- unitMode: this.unitMode,
61
- equalityMode: this.equalityMode,
62
- collapseNesting: this.opts.collapseNesting ?? false
63
- });
64
- const errors = [];
65
- const warnings = [];
66
- let tree;
23
+ safeParse(filePath, source) {
67
24
  try {
68
- const parseResult = this.parser.parse(source, "Stylesheet", { context });
69
- tree = parseResult.tree;
70
- if (parseResult.errors.length) for (const error of parseResult.errors) {
71
- const line = error.token?.startLine ?? 1;
72
- const diagnostic = (0, _jesscss_core.toDiagnostic)((0, _jesscss_core.getErrorFromParser)([error], void 0, filePath, source, { file: context.file }));
73
- if (!diagnostic.lines) diagnostic.lines = (0, _jesscss_core.extractRelevantLines)(source, line);
74
- if ("errors" in diagnostic) errors.push(diagnostic);
75
- else warnings.push(diagnostic);
76
- }
77
- const lexErrors = parseResult.lexerResult?.errors ?? [];
78
- if (lexErrors.length) for (const lexError of lexErrors) {
79
- const line = typeof lexError.line === "number" ? lexError.line : 1;
80
- const diagnostic = (0, _jesscss_core.toDiagnostic)((0, _jesscss_core.getErrorFromParser)([], [lexError], filePath, source, { file: context.file }));
81
- if (!diagnostic.lines) diagnostic.lines = (0, _jesscss_core.extractRelevantLines)(source, line);
82
- if ("errors" in diagnostic) errors.push(diagnostic);
83
- else warnings.push(diagnostic);
84
- }
25
+ return {
26
+ document: (0, _jesscss_scss_parser.parse)(source),
27
+ errors: [],
28
+ warnings: []
29
+ };
85
30
  } catch (error) {
86
- if (error instanceof _jesscss_core.JessError) {
87
- const diagnostic = (0, _jesscss_core.toDiagnostic)(error);
88
- if ("errors" in diagnostic) errors.push(diagnostic);
89
- else warnings.push(diagnostic);
90
- } else {
91
- const message = error instanceof Error ? error.message : "Unknown parsing error";
92
- errors.push({
93
- code: "internal/unknown",
94
- phase: "parse",
95
- message,
96
- reason: message,
97
- fix: "Check the file syntax and ensure it is valid.",
98
- file: context.file,
99
- filePath,
100
- line: 1,
101
- column: 1,
102
- lines: (0, _jesscss_core.extractRelevantLines)(source, 1)
103
- });
104
- }
105
31
  return {
106
- errors,
107
- warnings
32
+ errors: [(0, _jesscss_core.parserDiagnostic)({
33
+ dialect: "SCSS",
34
+ error,
35
+ filePath,
36
+ source
37
+ })],
38
+ warnings: []
108
39
  };
109
40
  }
110
- return {
111
- tree,
112
- errors,
113
- warnings
114
- };
115
41
  }
116
42
  };
117
43
  const scssPlugin = ((opts) => new ScssPlugin(opts));
package/lib/index.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ import { AbstractPlugin, type ISafeParseResult, type EqualityMode, type UnitMode } from '@jesscss/core';
2
+ export type ScssPluginOptions = {
3
+ allowExtendSelectors?: ExtendSelectorKind[];
4
+ /**
5
+ * Compatibility input retained on this frontend's option object. The shared
6
+ * evaluator reads the resolved Context compile/input option; configuring a
7
+ * Compiler should use `compile.unitMode` or matched input options.
8
+ */
9
+ unitMode?: UnitMode;
10
+ /**
11
+ * Compatibility input retained on this frontend's option object. It does not
12
+ * select a separate SCSS evaluator; configure the shared evaluator through
13
+ * Context compile/input options.
14
+ */
15
+ equalityMode?: EqualityMode;
16
+ /**
17
+ * Whether to collapse nested selectors (flatten nesting during print).
18
+ * This is a Jess output option, not a Sass option.
19
+ */
20
+ collapseNesting?: boolean;
21
+ };
22
+ type ExtendSelectorKind = 'simple' | 'basic' | 'pseudo' | 'complex' | 'compound';
23
+ export declare class ScssPlugin extends AbstractPlugin {
24
+ opts: ScssPluginOptions;
25
+ name: string;
26
+ supportedExtensions: string[];
27
+ unitMode: UnitMode;
28
+ equalityMode: EqualityMode;
29
+ constructor(opts?: ScssPluginOptions);
30
+ expandImport(importPath: string): string[];
31
+ safeParse(filePath: string, source: string): ISafeParseResult;
32
+ }
33
+ declare const scssPlugin: (opts?: ScssPluginOptions) => ScssPlugin;
34
+ export default scssPlugin;
package/lib/index.js CHANGED
@@ -1,12 +1,10 @@
1
- import { AbstractPlugin, JessError, TreeContext, extractRelevantLines, getErrorFromParser, toDiagnostic } from "@jesscss/core";
2
- import { Parser } from "@jesscss/scss-parser/jess";
3
- import path from "node:path";
1
+ import { AbstractPlugin, parserDiagnostic } from "@jesscss/core";
2
+ import { parse } from "@jesscss/scss-parser";
4
3
  import { expandScssImportCandidates } from "@jesscss/style-resolver";
5
4
  //#region src/index.ts
6
5
  var ScssPlugin = class extends AbstractPlugin {
7
6
  name = "scss";
8
7
  supportedExtensions = [".scss"];
9
- parser;
10
8
  unitMode;
11
9
  equalityMode;
12
10
  constructor(opts = {}) {
@@ -14,77 +12,28 @@ var ScssPlugin = class extends AbstractPlugin {
14
12
  this.opts = opts;
15
13
  this.unitMode = opts.unitMode ?? "preserve";
16
14
  this.equalityMode = opts.equalityMode ?? "sass";
17
- this.parser = new Parser();
18
15
  }
19
16
  expandImport(importPath) {
20
17
  return expandScssImportCandidates(importPath);
21
18
  }
22
- safeParse(filePath, source, parseOptions) {
23
- const allowExtendSelectors = this.opts.allowExtendSelectors ?? parseOptions?.compilerOptions?.allowExtendSelectors ?? ["simple"];
24
- const context = new TreeContext({
25
- file: {
26
- name: path.basename(filePath),
27
- path: path.dirname(filePath),
28
- fullPath: filePath,
29
- source
30
- },
31
- plugin: this,
32
- allowExtendSelectors,
33
- unitMode: this.unitMode,
34
- equalityMode: this.equalityMode,
35
- collapseNesting: this.opts.collapseNesting ?? false
36
- });
37
- const errors = [];
38
- const warnings = [];
39
- let tree;
19
+ safeParse(filePath, source) {
40
20
  try {
41
- const parseResult = this.parser.parse(source, "Stylesheet", { context });
42
- tree = parseResult.tree;
43
- if (parseResult.errors.length) for (const error of parseResult.errors) {
44
- const line = error.token?.startLine ?? 1;
45
- const diagnostic = toDiagnostic(getErrorFromParser([error], void 0, filePath, source, { file: context.file }));
46
- if (!diagnostic.lines) diagnostic.lines = extractRelevantLines(source, line);
47
- if ("errors" in diagnostic) errors.push(diagnostic);
48
- else warnings.push(diagnostic);
49
- }
50
- const lexErrors = parseResult.lexerResult?.errors ?? [];
51
- if (lexErrors.length) for (const lexError of lexErrors) {
52
- const line = typeof lexError.line === "number" ? lexError.line : 1;
53
- const diagnostic = toDiagnostic(getErrorFromParser([], [lexError], filePath, source, { file: context.file }));
54
- if (!diagnostic.lines) diagnostic.lines = extractRelevantLines(source, line);
55
- if ("errors" in diagnostic) errors.push(diagnostic);
56
- else warnings.push(diagnostic);
57
- }
21
+ return {
22
+ document: parse(source),
23
+ errors: [],
24
+ warnings: []
25
+ };
58
26
  } catch (error) {
59
- if (error instanceof JessError) {
60
- const diagnostic = toDiagnostic(error);
61
- if ("errors" in diagnostic) errors.push(diagnostic);
62
- else warnings.push(diagnostic);
63
- } else {
64
- const message = error instanceof Error ? error.message : "Unknown parsing error";
65
- errors.push({
66
- code: "internal/unknown",
67
- phase: "parse",
68
- message,
69
- reason: message,
70
- fix: "Check the file syntax and ensure it is valid.",
71
- file: context.file,
72
- filePath,
73
- line: 1,
74
- column: 1,
75
- lines: extractRelevantLines(source, 1)
76
- });
77
- }
78
27
  return {
79
- errors,
80
- warnings
28
+ errors: [parserDiagnostic({
29
+ dialect: "SCSS",
30
+ error,
31
+ filePath,
32
+ source
33
+ })],
34
+ warnings: []
81
35
  };
82
36
  }
83
- return {
84
- tree,
85
- errors,
86
- warnings
87
- };
88
37
  }
89
38
  };
90
39
  const scssPlugin = ((opts) => new ScssPlugin(opts));
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "description": "An SCSS stylesheet engine for Jess",
7
- "version": "2.0.0-alpha.8",
7
+ "version": "2.0.0-alpha.9",
8
8
  "main": "lib/index.cjs",
9
9
  "types": "lib/index.d.ts",
10
10
  "exports": {
@@ -19,9 +19,9 @@
19
19
  "lib"
20
20
  ],
21
21
  "dependencies": {
22
- "@jesscss/core": "2.0.0-alpha.8",
23
- "@jesscss/scss-parser": "2.0.0-alpha.8",
24
- "@jesscss/style-resolver": "2.0.0-alpha.8"
22
+ "@jesscss/core": "2.0.0-alpha.9",
23
+ "@jesscss/scss-parser": "2.0.0-alpha.9",
24
+ "@jesscss/style-resolver": "2.0.0-alpha.9"
25
25
  },
26
26
  "devDependencies": {},
27
27
  "author": "Matthew Dean <matthew-dean@users.noreply.github.com>",
@@ -35,7 +35,7 @@
35
35
  "scripts": {
36
36
  "ci": "pnpm build && pnpm test",
37
37
  "build": "pnpm compile",
38
- "compile": "tsdown --tsconfig tsconfig.build.json --no-dts && tsc -p tsconfig.build.json --emitDeclarationOnly --noCheck",
38
+ "compile": "tsdown --tsconfig tsconfig.build.json --no-dts && tsc -p tsconfig.build.json --emitDeclarationOnly",
39
39
  "test": "vitest --run --passWithNoTests",
40
40
  "lint:fix": "eslint --fix '**/*.{js,ts}'",
41
41
  "lint": "eslint '**/*.{js,ts}'"