@jesscss/less-parser 1.0.8-alpha.6 → 2.0.0-alpha.10

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/lib/index.cjs ADDED
@@ -0,0 +1,72 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_grammar = require("./grammar2.cjs");
3
+ let parseman = require("parseman");
4
+ let _jesscss_core = require("@jesscss/core");
5
+ let _jesscss_core_ast = require("@jesscss/core/ast");
6
+ //#region src/index.ts
7
+ function isStylesheet(value) {
8
+ return typeof value === "object" && value !== null && "type" in value && value.type === "Stylesheet" && "children" in value && Array.isArray(value.children);
9
+ }
10
+ /** Parse Less directly into the canonical AST v2 document. */
11
+ function parse(input) {
12
+ const entry = require_grammar.lessAstGrammar.Stylesheet;
13
+ const trivia = require_grammar.lessAstGrammar.whitespace;
14
+ if (entry === void 0 || trivia === void 0) throw new TypeError("Less AST grammar is missing its public document entry.");
15
+ const result = (0, parseman.run)(entry, input, {
16
+ trivia,
17
+ state: { source: input }
18
+ });
19
+ if (!result.ok) throw new require_grammar.LessParseError(result.span.start, result.expected);
20
+ if (result.unconsumedFrom !== null) {
21
+ if (result.unconsumedFrom > result.span.start) throw new require_grammar.LessParseError(result.unconsumedFrom, [], {
22
+ message: "Unexpected Less input after a complete stylesheet.",
23
+ reason: "The parser consumed a complete Less stylesheet before this token, so the remaining text is not part of any rule, declaration, or at-rule.",
24
+ fix: "Remove the extra input or wrap it in valid Less syntax."
25
+ });
26
+ throw new require_grammar.LessParseError(result.unconsumedFrom, [], {
27
+ message: "Unexpected Less syntax.",
28
+ reason: "The parser could not match this token as the start of a Less rule, declaration, or at-rule.",
29
+ fix: "Remove the token or rewrite it as valid Less syntax."
30
+ });
31
+ }
32
+ if (!isStylesheet(result.value)) throw new require_grammar.LessParseError(result.span.end, [], {
33
+ message: "Less parser did not produce a stylesheet.",
34
+ reason: "The Less parser matched the input but returned a value that is not a stylesheet document.",
35
+ fix: "Report this as a parser bug with the source that triggered it."
36
+ });
37
+ return (0, _jesscss_core_ast.withTriviaMap)((0, _jesscss_core_ast.withSourceSpan)(result.value, result.span), (0, _jesscss_core_ast.createTriviaMapFromParseman)(input, result.triviaMap));
38
+ }
39
+ /**
40
+ * Parse Less for the product plugin path. Parser packages own recognition facts;
41
+ * this boundary attaches file/source context once and returns the normalized
42
+ * diagnostic shape that `@jesscss/jess` forwards and renders.
43
+ */
44
+ function safeParse(filePath, input) {
45
+ try {
46
+ return {
47
+ document: parse(input),
48
+ errors: [],
49
+ warnings: []
50
+ };
51
+ } catch (error) {
52
+ return {
53
+ errors: [(0, _jesscss_core.parserDiagnostic)({
54
+ dialect: "Less",
55
+ error,
56
+ filePath,
57
+ source: input
58
+ })],
59
+ warnings: []
60
+ };
61
+ }
62
+ }
63
+ //#endregion
64
+ exports.LessBareVariableInterpolationError = require_grammar.LessBareVariableInterpolationError;
65
+ exports.LessDynamicCharsetError = require_grammar.LessDynamicCharsetError;
66
+ exports.LessInlineJavaScriptError = require_grammar.LessInlineJavaScriptError;
67
+ exports.LessParseError = require_grammar.LessParseError;
68
+ exports.LessUnparenthesizedMixinGuardError = require_grammar.LessUnparenthesizedMixinGuardError;
69
+ exports.LessUnsupportedMixinNameError = require_grammar.LessUnsupportedMixinNameError;
70
+ exports.LessUnsupportedVariableNameError = require_grammar.LessUnsupportedVariableNameError;
71
+ exports.parse = parse;
72
+ exports.safeParse = safeParse;
package/lib/index.d.ts CHANGED
@@ -1,11 +1,12 @@
1
- import { Lexer } from 'chevrotain';
2
- import { IParseResult } from '@jesscss/css-parser';
3
- import { LessParser } from './lessParser';
4
- export * from './lessParser';
5
- export * from './lessTokens';
6
- export declare class Parser {
7
- lexer: Lexer;
8
- parser: LessParser;
9
- constructor();
10
- parse(text: string): IParseResult<LessParser>;
11
- }
1
+ import { type ISafeParseResult } from '@jesscss/core';
2
+ import { type Stylesheet } from '@jesscss/core/ast';
3
+ export { LessBareVariableInterpolationError, LessDynamicCharsetError, LessInlineJavaScriptError, LessParseError, LessUnparenthesizedMixinGuardError, LessUnsupportedMixinNameError, LessUnsupportedVariableNameError } from './parse-error.js';
4
+ /** Parse Less directly into the canonical AST v2 document. */
5
+ export declare function parse(input: string): Stylesheet;
6
+ /**
7
+ * Parse Less for the product plugin path. Parser packages own recognition facts;
8
+ * this boundary attaches file/source context once and returns the normalized
9
+ * diagnostic shape that `@jesscss/jess` forwards and renders.
10
+ */
11
+ export declare function safeParse(filePath: string, input: string): ISafeParseResult;
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACxE,OAAO,EAIL,KAAK,UAAU,EAChB,MAAM,mBAAmB,CAAC;AAI3B,OAAO,EACL,kCAAkC,EAClC,uBAAuB,EACvB,yBAAyB,EACzB,cAAc,EACd,kCAAkC,EAClC,6BAA6B,EAC7B,gCAAgC,EACjC,MAAM,kBAAkB,CAAC;AAa1B,8DAA8D;AAC9D,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAwC/C;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,gBAAgB,CAW3E"}
package/lib/index.js CHANGED
@@ -1,38 +1,63 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.Parser = void 0;
14
- const chevrotain_1 = require("chevrotain");
15
- const lessTokens_1 = require("./lessTokens");
16
- const css_parser_1 = require("@jesscss/css-parser");
17
- const lessParser_1 = require("./lessParser");
18
- __exportStar(require("./lessParser"), exports);
19
- __exportStar(require("./lessTokens"), exports);
20
- class Parser {
21
- constructor() {
22
- const { tokens, T } = css_parser_1.createTokens(lessTokens_1.Fragments, lessTokens_1.Tokens);
23
- this.lexer = new chevrotain_1.Lexer(tokens, {
24
- ensureOptimizations: true,
25
- skipValidations: process.env['JESS_TESTING_MODE'] !== 'true'
26
- });
27
- this.parser = new lessParser_1.LessParser(tokens, T);
28
- }
29
- parse(text) {
30
- const parser = this.parser;
31
- const lexerResult = this.lexer.tokenize(text);
32
- const lexedTokens = lexerResult.tokens;
33
- parser.input = lexedTokens;
34
- const cst = parser.root();
35
- return { cst, lexerResult, parser };
36
- }
1
+ import { a as LessDynamicCharsetError, c as LessUnparenthesizedMixinGuardError, i as LessBareVariableInterpolationError, l as LessUnsupportedMixinNameError, o as LessInlineJavaScriptError, s as LessParseError, t as lessAstGrammar, u as LessUnsupportedVariableNameError } from "./grammar2.js";
2
+ import { run } from "parseman";
3
+ import { parserDiagnostic } from "@jesscss/core";
4
+ import { createTriviaMapFromParseman, withSourceSpan, withTriviaMap } from "@jesscss/core/ast";
5
+ //#region src/index.ts
6
+ function isStylesheet(value) {
7
+ return typeof value === "object" && value !== null && "type" in value && value.type === "Stylesheet" && "children" in value && Array.isArray(value.children);
37
8
  }
38
- exports.Parser = Parser;
9
+ /** Parse Less directly into the canonical AST v2 document. */
10
+ function parse(input) {
11
+ const entry = lessAstGrammar.Stylesheet;
12
+ const trivia = lessAstGrammar.whitespace;
13
+ if (entry === void 0 || trivia === void 0) throw new TypeError("Less AST grammar is missing its public document entry.");
14
+ const result = run(entry, input, {
15
+ trivia,
16
+ state: { source: input }
17
+ });
18
+ if (!result.ok) throw new LessParseError(result.span.start, result.expected);
19
+ if (result.unconsumedFrom !== null) {
20
+ if (result.unconsumedFrom > result.span.start) throw new LessParseError(result.unconsumedFrom, [], {
21
+ message: "Unexpected Less input after a complete stylesheet.",
22
+ reason: "The parser consumed a complete Less stylesheet before this token, so the remaining text is not part of any rule, declaration, or at-rule.",
23
+ fix: "Remove the extra input or wrap it in valid Less syntax."
24
+ });
25
+ throw new LessParseError(result.unconsumedFrom, [], {
26
+ message: "Unexpected Less syntax.",
27
+ reason: "The parser could not match this token as the start of a Less rule, declaration, or at-rule.",
28
+ fix: "Remove the token or rewrite it as valid Less syntax."
29
+ });
30
+ }
31
+ if (!isStylesheet(result.value)) throw new LessParseError(result.span.end, [], {
32
+ message: "Less parser did not produce a stylesheet.",
33
+ reason: "The Less parser matched the input but returned a value that is not a stylesheet document.",
34
+ fix: "Report this as a parser bug with the source that triggered it."
35
+ });
36
+ return withTriviaMap(withSourceSpan(result.value, result.span), createTriviaMapFromParseman(input, result.triviaMap));
37
+ }
38
+ /**
39
+ * Parse Less for the product plugin path. Parser packages own recognition facts;
40
+ * this boundary attaches file/source context once and returns the normalized
41
+ * diagnostic shape that `@jesscss/jess` forwards and renders.
42
+ */
43
+ function safeParse(filePath, input) {
44
+ try {
45
+ return {
46
+ document: parse(input),
47
+ errors: [],
48
+ warnings: []
49
+ };
50
+ } catch (error) {
51
+ return {
52
+ errors: [parserDiagnostic({
53
+ dialect: "Less",
54
+ error,
55
+ filePath,
56
+ source: input
57
+ })],
58
+ warnings: []
59
+ };
60
+ }
61
+ }
62
+ //#endregion
63
+ export { LessBareVariableInterpolationError, LessDynamicCharsetError, LessInlineJavaScriptError, LessParseError, LessUnparenthesizedMixinGuardError, LessUnsupportedMixinNameError, LessUnsupportedVariableNameError, parse, safeParse };
@@ -0,0 +1,68 @@
1
+ /** Structured failure from the public direct Less parser. */
2
+ export declare class LessParseError extends SyntaxError {
3
+ readonly code: 'parse/syntax-error';
4
+ readonly offset: number;
5
+ readonly expected: readonly string[];
6
+ readonly reason?: string;
7
+ readonly fix?: string;
8
+ constructor(offset: number, expected: readonly string[], options?: {
9
+ message?: string;
10
+ reason?: string;
11
+ fix?: string;
12
+ });
13
+ }
14
+ /** Interpolation is rejected inside the CSS @charset token. */
15
+ export declare class LessDynamicCharsetError extends SyntaxError {
16
+ readonly code: 'parse/dynamic-charset';
17
+ readonly offset: number;
18
+ readonly endOffset: number;
19
+ readonly reason = "Interpolation is not valid inside the CSS @charset token.";
20
+ readonly fix = "Use a static declaration such as @charset \"UTF-8\";";
21
+ constructor(offset: number, endOffset: number);
22
+ }
23
+ /** Executable inline backtick JavaScript is recognized so diagnostics can be precise. */
24
+ export declare class LessInlineJavaScriptError extends SyntaxError {
25
+ readonly code: 'parse/unsupported-inline-javascript';
26
+ readonly offset: number;
27
+ readonly endOffset: number;
28
+ readonly reason = "Backtick JavaScript expressions are not evaluated.";
29
+ readonly fix = "Move the expression into an explicit @from/@-from script import or a plugin function.";
30
+ constructor(offset: number, endOffset: number);
31
+ }
32
+ /** Syntax/prelude slots require explicit @{name} interpolation. */
33
+ export declare class LessBareVariableInterpolationError extends SyntaxError {
34
+ readonly code: 'parse/unsupported-bare-variable-interpolation';
35
+ readonly offset: number;
36
+ readonly endOffset: number;
37
+ readonly reason: string;
38
+ readonly fix: string;
39
+ constructor(offset: number, endOffset: number, name: string);
40
+ }
41
+ /** Legacy Less variable names are recognized so diagnostics can be precise. */
42
+ export declare class LessUnsupportedVariableNameError extends SyntaxError {
43
+ readonly code: 'parse/unsupported-variable-name';
44
+ readonly offset: number;
45
+ readonly endOffset: number;
46
+ readonly reason = "Less variable names must not be numeric-leading or dash-only.";
47
+ readonly fix: string;
48
+ constructor(offset: number, endOffset: number, name: string);
49
+ }
50
+ /** Legacy dash-only mixin names are recognized so diagnostics can be precise. */
51
+ export declare class LessUnsupportedMixinNameError extends SyntaxError {
52
+ readonly code: 'parse/unsupported-mixin-name';
53
+ readonly offset: number;
54
+ readonly endOffset: number;
55
+ readonly reason = "Dash-only Less mixin names are not supported.";
56
+ readonly fix = "Rename the mixin to a descriptive selector-like name, for example .mixin().";
57
+ constructor(offset: number, endOffset: number);
58
+ }
59
+ /** Ungrouped Less mixin guards are recognized so diagnostics can point at the guard. */
60
+ export declare class LessUnparenthesizedMixinGuardError extends SyntaxError {
61
+ readonly code: 'parse/unparenthesized-mixin-guard';
62
+ readonly offset: number;
63
+ readonly endOffset: number;
64
+ readonly reason = "Top-level Less mixin guards require each condition after when to be wrapped in parentheses.";
65
+ readonly fix = "Wrap the guard condition, for example: when (default()).";
66
+ constructor(offset: number, endOffset: number);
67
+ }
68
+ //# sourceMappingURL=parse-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-error.d.ts","sourceRoot":"","sources":["../src/parse-error.ts"],"names":[],"mappings":"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"}
package/package.json CHANGED
@@ -1,31 +1,74 @@
1
1
  {
2
2
  "name": "@jesscss/less-parser",
3
+ "type": "module",
3
4
  "publishConfig": {
4
5
  "access": "public"
5
6
  },
6
- "description": "",
7
- "version": "1.0.8-alpha.6",
8
- "main": "lib/index",
9
- "types": "lib/index",
7
+ "version": "2.0.0-alpha.10",
8
+ "engines": {
9
+ "node": "^20.19.0 || >=22.12.0"
10
+ },
11
+ "description": "Jess LESS parser",
12
+ "main": "lib/index.cjs",
13
+ "types": "lib/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./lib/index.d.ts",
17
+ "import": "./lib/index.js",
18
+ "require": "./lib/index.cjs"
19
+ },
20
+ "./cst": {
21
+ "types": "./lib/cst.d.ts",
22
+ "import": "./lib/cst.js",
23
+ "require": "./lib/cst.cjs"
24
+ },
25
+ "./grammar": {
26
+ "types": "./lib/grammar.d.ts",
27
+ "import": "./lib/grammar.js",
28
+ "require": "./lib/grammar.cjs"
29
+ },
30
+ "./package.json": "./package.json"
31
+ },
10
32
  "files": [
11
33
  "lib"
12
34
  ],
13
- "scripts": {
14
- "ci": "yarn build && yarn test",
15
- "prepublishOnly": "npm run build",
16
- "build": "yarn clean && yarn compile",
17
- "clean": "shx rm -rf ./lib tsconfig.tsbuildinfo",
18
- "compile": "tsc -b tsconfig.json",
19
- "test": "ts-mocha test/**/*.ts"
20
- },
21
- "author": "Matthew Dean",
22
- "license": "MIT",
23
35
  "dependencies": {
24
- "@jesscss/css-parser": "^1.0.8-alpha.6",
25
- "chevrotain": "^7.1.0"
36
+ "known-css-properties": "~0.37.0",
37
+ "@jesscss/css-parser": "2.0.0-alpha.10"
38
+ },
39
+ "peerDependencies": {
40
+ "parseman": "^0.41.0",
41
+ "@jesscss/core": "2.0.0-alpha.10"
42
+ },
43
+ "peerDependenciesMeta": {
44
+ "@jesscss/core": {
45
+ "optional": true
46
+ }
26
47
  },
27
48
  "devDependencies": {
28
- "@less/test-data": "^4.1.0"
49
+ "@types/node": "^18.19.31",
50
+ "less": "^4.6.3",
51
+ "parseman": "^0.41.0",
52
+ "tsx": "~4.21.0",
53
+ "@jesscss/parser-shared": "0.0.0",
54
+ "@jesscss/core": "2.0.0-alpha.10",
55
+ "@jesscss/shared": "2.0.0-alpha.1"
56
+ },
57
+ "author": "Matthew Dean <matthew-dean@users.noreply.github.com>",
58
+ "license": "MIT",
59
+ "bugs": {
60
+ "url": "https://github.com/jesscss/jess/issues"
29
61
  },
30
- "gitHead": "48267a282482c9d9f9a9dd0cbf29defc79b5b3f3"
31
- }
62
+ "homepage": "https://github.com/jesscss/jess#readme",
63
+ "module": "lib/index.js",
64
+ "scripts": {
65
+ "ci": "pnpm build && pnpm test",
66
+ "build": "pnpm --filter @jesscss/parser-shared build && pnpm compile",
67
+ "compile": "tsdown --tsconfig tsconfig.build.json --no-dts && tsc -p tsconfig.build.json --emitDeclarationOnly --noCheck",
68
+ "dev": "tsdown --tsconfig tsconfig.build.json --watch",
69
+ "test": "cross-env TEST=true vitest --watch=false",
70
+ "test:coverage": "cross-env TEST=true vitest --coverage",
71
+ "lint:fix": "eslint --fix '**/*.{js,ts}'",
72
+ "lint": "eslint '**/*.{js,ts}'"
73
+ }
74
+ }
@@ -1,36 +0,0 @@
1
- import { TokenType, IParserConfig } from 'chevrotain';
2
- import { TokenMap, CssParser, Rule } from '@jesscss/css-parser';
3
- export declare class LessParser extends CssParser {
4
- T: TokenMap;
5
- inCompareBlock: boolean;
6
- isMixinDefinition: boolean;
7
- isSemiColonSeparated: boolean;
8
- isVariableCall: boolean;
9
- hasExtend: boolean;
10
- identOrInterpolated: Rule;
11
- /** values */
12
- addition: Rule;
13
- multiplication: Rule;
14
- compare: Rule;
15
- variable: Rule;
16
- valueBlock: Rule;
17
- /** functions */
18
- function: Rule;
19
- functionArgs: Rule;
20
- functionArg: Rule;
21
- /** mixins */
22
- testMixin: Rule;
23
- mixin: Rule;
24
- mixinName: Rule;
25
- mixinStart: Rule;
26
- mixinArgs: Rule;
27
- mixinArg: Rule;
28
- anonMixin: Rule;
29
- /** guards */
30
- guard: Rule;
31
- guardExpression: Rule;
32
- guardOr: Rule;
33
- guardAnd: Rule;
34
- constructor(tokens: TokenType[], T: TokenMap, config?: IParserConfig);
35
- reset(): void;
36
- }
package/lib/lessParser.js DELETED
@@ -1,49 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.LessParser = void 0;
7
- const css_parser_1 = require("@jesscss/css-parser");
8
- const root_1 = __importDefault(require("./productions/root"));
9
- const atRules_1 = __importDefault(require("./productions/atRules"));
10
- const blocks_1 = __importDefault(require("./productions/blocks"));
11
- const declarations_1 = __importDefault(require("./productions/declarations"));
12
- const mixin_1 = __importDefault(require("./productions/mixin"));
13
- const selectors_1 = __importDefault(require("./productions/selectors"));
14
- const interpolation_1 = __importDefault(require("./productions/interpolation"));
15
- const values_1 = __importDefault(require("./productions/values"));
16
- class LessParser extends css_parser_1.CssParser {
17
- constructor(tokens, T, config = {
18
- maxLookahead: 1
19
- }) {
20
- super(tokens, T, config);
21
- this.inCompareBlock = false;
22
- this.isMixinDefinition = false;
23
- this.isSemiColonSeparated = false;
24
- this.isVariableCall = false;
25
- this.hasExtend = false;
26
- const $ = this;
27
- $.T = T;
28
- root_1.default.call($, $);
29
- atRules_1.default.call($, $);
30
- blocks_1.default.call($, $);
31
- declarations_1.default.call($, $);
32
- interpolation_1.default.call($, $);
33
- mixin_1.default.call($, $);
34
- selectors_1.default.call($, $);
35
- values_1.default.call($, $);
36
- if ($.constructor === LessParser) {
37
- $.performSelfAnalysis();
38
- }
39
- }
40
- // https://sap.github.io/chevrotain/documentation/6_1_0/classes/baseparser.html#reset
41
- reset() {
42
- super.reset();
43
- this.inCompareBlock = false;
44
- this.isMixinDefinition = false;
45
- this.isSemiColonSeparated = false;
46
- this.isVariableCall = false;
47
- }
48
- }
49
- exports.LessParser = LessParser;
@@ -1,3 +0,0 @@
1
- import { rawTokenConfig } from '@jesscss/css-parser';
2
- export declare const Fragments: [string, string][];
3
- export declare let Tokens: rawTokenConfig[];
package/lib/lessTokens.js DELETED
@@ -1,155 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Tokens = exports.Fragments = void 0;
4
- const css_parser_1 = require("@jesscss/css-parser");
5
- exports.Fragments = [...css_parser_1.Fragments];
6
- exports.Tokens = [...css_parser_1.Tokens];
7
- exports.Fragments.unshift(['lineComment', '\\/\\/[^\\n\\r]*']);
8
- exports.Fragments.push(['interpolated', '[@$]\\{({{ident}})\\}']);
9
- exports.Fragments.forEach(fragment => {
10
- if (fragment[0].indexOf('wsorcomment') !== -1) {
11
- fragment[1] = '(?:({{ws}})|({{comment}})|({{lineComment}}))';
12
- }
13
- });
14
- /** Keyed by what to insert after */
15
- const merges = {
16
- Assign: [
17
- { name: 'Ampersand', pattern: /&/, categories: ['Selector'] },
18
- { name: 'Ellipsis', pattern: /\.\.\./ }
19
- ],
20
- PlainIdent: [
21
- { name: 'Interpolated', pattern: css_parser_1.LexerType.NA },
22
- {
23
- name: 'InterpolatedIdent',
24
- pattern: ['{{interpolated}}', css_parser_1.groupCapture],
25
- categories: ['Interpolated', 'Selector'],
26
- start_chars_hint: ['@', '$']
27
- },
28
- /**
29
- * Unfortunately, there's grammatical ambiguity between
30
- * interpolated props and a naked interpolated selector name,
31
- * making this awkward token necessary.
32
- */
33
- {
34
- name: 'InterpolatedSelector',
35
- pattern: ['[.#:]{{interpolated}}', css_parser_1.groupCapture],
36
- categories: ['Interpolated', 'Selector'],
37
- start_chars_hint: ['.', '#', ':']
38
- },
39
- { name: 'PlusAssign', pattern: '\\+{{whitespace}}*:', categories: ['BlockMarker', 'Assign'] },
40
- {
41
- name: 'UnderscoreAssign',
42
- pattern: '\\+{{whitespace}}*_{{whitespace}}*:',
43
- categories: ['BlockMarker', 'Assign']
44
- },
45
- { name: 'AnonMixinStart', pattern: /[.#]\(/, categories: ['BlockMarker'] },
46
- { name: 'GtEqAlias', pattern: /=>/, categories: ['CompareOperator'] },
47
- { name: 'LtEqAlias', pattern: /=</, categories: ['CompareOperator'] },
48
- {
49
- name: 'Extend',
50
- pattern: /:extend\(/,
51
- categories: ['BlockMarker']
52
- },
53
- {
54
- name: 'When',
55
- pattern: /when/,
56
- longer_alt: 'PlainIdent',
57
- categories: ['BlockMarker']
58
- },
59
- {
60
- name: 'VarOrProp',
61
- pattern: css_parser_1.LexerType.NA
62
- },
63
- {
64
- name: 'NestedReference',
65
- pattern: ['([@$]+{{ident}}?){2,}', css_parser_1.groupCapture],
66
- start_chars_hint: ['@', '$'],
67
- categories: ['VarOrProp']
68
- },
69
- {
70
- name: 'PropertyReference',
71
- pattern: '\\$-?{{ident}}',
72
- categories: ['VarOrProp']
73
- }
74
- ],
75
- // AtMedia: [
76
- // {
77
- // name: 'AtPlugin',
78
- // pattern: /@plugin/,
79
- // longer_alt: 'AtKeyword',
80
- // categories: ['BlockMarker', 'AtName']
81
- // }
82
- // ],
83
- PlainFunction: [
84
- /** Can be used in unit function */
85
- {
86
- name: 'Percent',
87
- pattern: /%/
88
- },
89
- {
90
- name: 'FormatFunction',
91
- pattern: /%\(/,
92
- categories: ['BlockMarker', 'Function']
93
- },
94
- {
95
- name: 'IfFunction',
96
- pattern: /if\(/,
97
- categories: ['BlockMarker', 'Function']
98
- },
99
- {
100
- name: 'BooleanFunction',
101
- pattern: /boolean\(/,
102
- categories: ['BlockMarker', 'Function']
103
- }
104
- ],
105
- Uri: [
106
- {
107
- name: 'JavaScript',
108
- pattern: /`[^`]*`/,
109
- group: css_parser_1.LexerType.SKIPPED,
110
- line_breaks: true
111
- }
112
- ]
113
- };
114
- let tokenLength = exports.Tokens.length;
115
- for (let i = 0; i < tokenLength; i++) {
116
- let token = exports.Tokens[i];
117
- let { name, categories } = token;
118
- const copyToken = () => {
119
- token = Object.assign({}, token);
120
- categories = categories ? categories.slice(0) : [];
121
- };
122
- let alterations = true;
123
- switch (name) {
124
- // Removed in Less v5
125
- // case 'Divide':
126
- // copyToken()
127
- // token.pattern = /\.?\//
128
- // break
129
- case 'StringLiteral':
130
- copyToken();
131
- token.pattern = '~?{{string1}}|~?{{string2}}';
132
- break;
133
- case 'CustomProperty':
134
- copyToken();
135
- token.pattern = '--(?:{{nmstart}}{{nmchar}}*)?';
136
- break;
137
- case 'AtKeyword':
138
- copyToken();
139
- token.categories = categories.concat(['VarOrProp']);
140
- break;
141
- default:
142
- alterations = false;
143
- }
144
- if (alterations) {
145
- exports.Tokens[i] = token;
146
- }
147
- const merge = merges[name];
148
- if (merge) {
149
- /** Insert after current token */
150
- exports.Tokens = exports.Tokens.slice(0, i + 1).concat(merge, exports.Tokens.slice(i + 1));
151
- const mergeLength = merge.length;
152
- tokenLength += mergeLength;
153
- i += mergeLength;
154
- }
155
- }
@@ -1,2 +0,0 @@
1
- import type { LessParser } from '../lessParser';
2
- export default function (this: LessParser, $: LessParser): void;