@d-zero/csstree-scss-syntax 5.0.0-alpha.11

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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (C) 2024 by D-ZERO Co., Ltd.
2
+
3
+ Copyright (C) 2017 by Roman Dvornov
4
+ https://github.com/csstree/csstree-scss-syntax
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # @d-zero/csstree-scss-syntax
2
+
3
+ SCSS processor based on [csstree](https://github.com/csstree/csstree). It allows to work with SCSS AST, but it does not compile SCSS to CSS.
4
+
5
+ ## License
6
+
7
+ MIT
8
+
9
+ ## Forked from [csstree/csstree-scss-syntax](https://github.com/csstree/csstree-scss-syntax)
@@ -0,0 +1,5 @@
1
+ import type { CSSTreeModule } from './types.js';
2
+ export * as CSSTree from 'css-tree';
3
+ export type * from './types.js';
4
+ declare const _default: CSSTreeModule;
5
+ export default _default;
package/dist/index.js ADDED
@@ -0,0 +1,43 @@
1
+ import * as CSSTree from 'css-tree';
2
+
3
+ import SassVariable from './node/sass-variable.js';
4
+ const DELIM = 9;
5
+ const DOLLAR_SIGN = 36; // U+0024 DOLLAR SIGN ($)
6
+ const forked = CSSTree.fork(
7
+ // @ts-ignore
8
+ function (syntax, assign) {
9
+ // @ts-ignore
10
+ const scope = syntax.scope;
11
+ const getNode = scope.Value.getNode;
12
+ return assign(syntax, {
13
+ scope: assign(scope, {
14
+ Value: assign(scope.Value, {
15
+ // @ts-ignore
16
+ getNode: function (context) {
17
+ // @ts-ignore
18
+ switch (this.tokenType) {
19
+ case DELIM: {
20
+ // @ts-ignore
21
+ // eslint-disable-next-line unicorn/prefer-code-point
22
+ const code = this.charCodeAt(this.tokenStart);
23
+ if (code === DOLLAR_SIGN) {
24
+ // @ts-ignore
25
+ return this.SassVariable();
26
+ }
27
+ }
28
+ }
29
+ return getNode.call(this, context);
30
+ },
31
+ }),
32
+ }),
33
+ // @ts-ignore
34
+ node: assign(syntax.node, {
35
+ SassVariable,
36
+ }),
37
+ });
38
+ });
39
+ export * as CSSTree from 'css-tree';
40
+ export default {
41
+ ...CSSTree,
42
+ ...forked,
43
+ };
@@ -0,0 +1,9 @@
1
+ declare const _default: {
2
+ name: string;
3
+ structure: {
4
+ name: StringConstructor;
5
+ };
6
+ parse: () => any;
7
+ generate: (node: any) => string;
8
+ };
9
+ export default _default;
@@ -0,0 +1,26 @@
1
+ const IDENTIFIER = 1;
2
+ const DELIM = 9;
3
+ export default {
4
+ name: 'SassVariable',
5
+ structure: {
6
+ name: String,
7
+ },
8
+ // @ts-ignore
9
+ parse: function SassVariable() {
10
+ // @ts-ignore
11
+ const start = this.tokenStart;
12
+ // @ts-ignore
13
+ this.eat(DELIM);
14
+ return {
15
+ type: 'SassVariable',
16
+ // @ts-ignore
17
+ loc: this.getLocation(start, this.tokenEnd),
18
+ // @ts-ignore
19
+ name: this.consume(IDENTIFIER),
20
+ };
21
+ },
22
+ // @ts-ignore
23
+ generate: function (node) {
24
+ return '$' + node.name;
25
+ },
26
+ };
@@ -0,0 +1,61 @@
1
+ import type * as CSSTree from 'css-tree';
2
+ import type { LexerMatchResult } from 'css-tree';
3
+ /**
4
+ * @see https://github.com/csstree/csstree/blob/master/lib/index.js
5
+ */
6
+ export type CSSTreeModule = typeof CSSTree & {
7
+ lexer: LexerEx;
8
+ createLexer: unknown;
9
+ tokenize: unknown;
10
+ parse: typeof CSSTree.parse;
11
+ generate: typeof CSSTree.generate;
12
+ walk: typeof CSSTree.walk;
13
+ find: typeof CSSTree.find;
14
+ findLast: typeof CSSTree.findLast;
15
+ findAll: typeof CSSTree.findAll;
16
+ fromPlainObject: typeof CSSTree.fromPlainObject;
17
+ toPlainObject: typeof CSSTree.toPlainObject;
18
+ fork(...args: Parameters<typeof CSSTree.fork>): CSSTreeModule;
19
+ fork(fn: (syntax: CSSTreeModule, assign: typeof Object.assign) => CSSTreeModule): CSSTreeModule;
20
+ };
21
+ interface LexerEx extends CSSTree.Lexer {
22
+ matchProperty(...args: Parameters<CSSTree.Lexer['matchProperty']>): LexerMatchResultMatched | LexerMatchResultMismatch;
23
+ }
24
+ interface LexerMatchResultMatched extends LexerMatchResult {
25
+ matched: PropertyToken;
26
+ }
27
+ interface LexerMatchResultMismatch extends LexerMatchResult {
28
+ matched: null;
29
+ iterations: number;
30
+ error: SyntaxError & {
31
+ rawMessage: string;
32
+ syntax: string;
33
+ css: string;
34
+ mismatchOffset: number;
35
+ mismatchLength: number;
36
+ offset: number;
37
+ line: number;
38
+ column: number;
39
+ loc: Record<string, unknown>;
40
+ };
41
+ }
42
+ type Syntax<S extends 'Property' | 'Type' | 'Keyword'> = {
43
+ type: S;
44
+ name: string;
45
+ };
46
+ export type PropertyToken = {
47
+ syntax: Syntax<'Property'>;
48
+ match: (PropertyToken | TypeToken | KeywordToken)[];
49
+ };
50
+ export type TypeToken = {
51
+ syntax: Syntax<'Type'> & {
52
+ opts: null | Record<string, string>;
53
+ };
54
+ match: (TypeToken | KeywordToken)[];
55
+ };
56
+ export type KeywordToken = {
57
+ syntax: Syntax<'Keyword'>;
58
+ token: string;
59
+ node: null;
60
+ };
61
+ export {};
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@d-zero/csstree-scss-syntax",
3
+ "version": "5.0.0-alpha.11",
4
+ "description": "SCSS syntax processor based on csstree",
5
+ "repository": "https://github.com/d-zero-dev/linters.git",
6
+ "author": "D-ZERO Co., Ltd.",
7
+ "license": "MIT",
8
+ "private": false,
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "type": "module",
13
+ "exports": {
14
+ ".": {
15
+ "import": "./dist/index.js",
16
+ "types": "./dist/index.d.ts"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "scripts": {
23
+ "build": "tsc"
24
+ },
25
+ "dependencies": {
26
+ "css-tree": "2.3.1"
27
+ },
28
+ "gitHead": "1c2ab0432103986eebd319cbea166e951d8ff524"
29
+ }