feat: docker compose maybe
This commit is contained in:
21
node_modules/eslint-plugin-svelte/lib/shared/comment-directives.d.ts
generated
vendored
Normal file
21
node_modules/eslint-plugin-svelte/lib/shared/comment-directives.d.ts
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
import type { AST } from 'svelte-eslint-parser';
|
||||
import type { Linter } from 'eslint';
|
||||
type Define = {
|
||||
loc: AST.Position;
|
||||
};
|
||||
export declare class CommentDirectives {
|
||||
private readonly reportUnusedDisableDirectives;
|
||||
private readonly ruleId;
|
||||
private readonly lineDisableDirectives;
|
||||
private readonly blockDirectives;
|
||||
constructor(options: {
|
||||
reportUnusedDisableDirectives?: boolean;
|
||||
ruleId: string;
|
||||
});
|
||||
filterMessages(messages: Linter.LintMessage[]): Linter.LintMessage[];
|
||||
disableLine(line: number, rule: string | ((ruleId: string) => boolean), define: Define): void;
|
||||
disableBlock(pos: AST.Position, rule: string | ((ruleId: string) => boolean), define: Define): void;
|
||||
enableBlock(pos: AST.Position, rule: string | ((ruleId: string) => boolean), define: Define): void;
|
||||
private block;
|
||||
}
|
||||
export {};
|
149
node_modules/eslint-plugin-svelte/lib/shared/comment-directives.js
generated
vendored
Normal file
149
node_modules/eslint-plugin-svelte/lib/shared/comment-directives.js
generated
vendored
Normal file
@ -0,0 +1,149 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CommentDirectives = void 0;
|
||||
const COMPUTED = Symbol();
|
||||
const ALL = Symbol();
|
||||
class CommentDirectives {
|
||||
constructor(options) {
|
||||
this.lineDisableDirectives = new Map();
|
||||
this.blockDirectives = new Map();
|
||||
this.ruleId = options.ruleId;
|
||||
this.reportUnusedDisableDirectives = Boolean(options?.reportUnusedDisableDirectives);
|
||||
}
|
||||
filterMessages(messages) {
|
||||
const { lineDisableDirectives, blockDirectives, reportUnusedDisableDirectives } = this;
|
||||
const usedDirectives = new Set();
|
||||
if (reportUnusedDisableDirectives) {
|
||||
const allBlocks = [];
|
||||
for (const bs of blockDirectives.values()) {
|
||||
for (const b of bs) {
|
||||
allBlocks.push(b);
|
||||
}
|
||||
}
|
||||
const blockEnableDirectives = new Set();
|
||||
for (const block of allBlocks.sort((a, b) => comparePos(b.loc, a.loc))) {
|
||||
if (block.kind === 'enable') {
|
||||
if (block.targetRule === ALL) {
|
||||
blockEnableDirectives.clear();
|
||||
}
|
||||
blockEnableDirectives.add(block);
|
||||
}
|
||||
else {
|
||||
if (block.targetRule === ALL) {
|
||||
for (const b of blockEnableDirectives) {
|
||||
usedDirectives.add(b);
|
||||
}
|
||||
blockEnableDirectives.clear();
|
||||
}
|
||||
else {
|
||||
for (const b of [...blockEnableDirectives]) {
|
||||
if (block.targetRule === b.targetRule || b.targetRule === ALL) {
|
||||
usedDirectives.add(b);
|
||||
blockEnableDirectives.delete(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let filteredMessages = messages.filter(isEnable);
|
||||
if (reportUnusedDisableDirectives) {
|
||||
const usedDirectiveKeys = new Set([...usedDirectives].map((d) => locToKey(d.define.loc)));
|
||||
filteredMessages = filteredMessages.filter((m) => {
|
||||
if (m.ruleId !== this.ruleId) {
|
||||
return true;
|
||||
}
|
||||
if (usedDirectiveKeys.has(messageToKey(m))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
return filteredMessages;
|
||||
function isEnable(message) {
|
||||
if (!message.ruleId) {
|
||||
return true;
|
||||
}
|
||||
for (const disableLines of getFromRule(lineDisableDirectives, message.ruleId)) {
|
||||
for (const disableLine of disableLines.get(message.line) ?? []) {
|
||||
if (!disableLine.rule(message.ruleId)) {
|
||||
continue;
|
||||
}
|
||||
usedDirectives.add(disableLine);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const blocks = getFromRule(blockDirectives, message.ruleId)
|
||||
.reduce((p, c) => p.concat(c), [])
|
||||
.sort((a, b) => comparePos(b.loc, a.loc));
|
||||
for (const block of blocks) {
|
||||
if (comparePos(message, block.loc) < 0) {
|
||||
continue;
|
||||
}
|
||||
if (!block.rule(message.ruleId)) {
|
||||
continue;
|
||||
}
|
||||
if (block.kind === 'enable') {
|
||||
return true;
|
||||
}
|
||||
usedDirectives.add(block);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function comparePos(a, b) {
|
||||
return a.line - b.line || a.column - b.column;
|
||||
}
|
||||
}
|
||||
disableLine(line, rule, define) {
|
||||
const key = typeof rule === 'string' ? rule : COMPUTED;
|
||||
let disableLines = this.lineDisableDirectives.get(key);
|
||||
if (!disableLines) {
|
||||
disableLines = new Map();
|
||||
this.lineDisableDirectives.set(key, disableLines);
|
||||
}
|
||||
let disableLine = disableLines.get(line);
|
||||
if (!disableLine) {
|
||||
disableLine = [];
|
||||
disableLines.set(line, disableLine);
|
||||
}
|
||||
const disable = {
|
||||
line,
|
||||
rule: typeof rule === 'string' ? (id) => id === rule : rule,
|
||||
define
|
||||
};
|
||||
disableLine.push(disable);
|
||||
}
|
||||
disableBlock(pos, rule, define) {
|
||||
this.block(pos, rule, define, 'disable');
|
||||
}
|
||||
enableBlock(pos, rule, define) {
|
||||
this.block(pos, rule, define, 'enable');
|
||||
}
|
||||
block(pos, rule, define, kind) {
|
||||
const key = typeof rule === 'string' ? rule : COMPUTED;
|
||||
let blocks = this.blockDirectives.get(key);
|
||||
if (!blocks) {
|
||||
blocks = [];
|
||||
this.blockDirectives.set(key, blocks);
|
||||
}
|
||||
const disable = {
|
||||
loc: pos,
|
||||
rule: typeof rule === 'string' ? (id) => id === rule : rule,
|
||||
kind,
|
||||
targetRule: typeof rule === 'string' ? rule : ALL,
|
||||
define
|
||||
};
|
||||
blocks.push(disable);
|
||||
}
|
||||
}
|
||||
exports.CommentDirectives = CommentDirectives;
|
||||
function getFromRule(map, ruleId) {
|
||||
return [map.get(ruleId), map.get(COMPUTED)].filter((a) => Boolean(a));
|
||||
}
|
||||
function locToKey(location) {
|
||||
return `line:${location.line},column${location.column}`;
|
||||
}
|
||||
function messageToKey(message) {
|
||||
return `line:${message.line},column${message.column - 1}`;
|
||||
}
|
8
node_modules/eslint-plugin-svelte/lib/shared/index.d.ts
generated
vendored
Normal file
8
node_modules/eslint-plugin-svelte/lib/shared/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
import { CommentDirectives } from './comment-directives';
|
||||
export declare class Shared {
|
||||
readonly commentDirectives: CommentDirectives[];
|
||||
newCommentDirectives(options: ConstructorParameters<typeof CommentDirectives>[0]): CommentDirectives;
|
||||
}
|
||||
export declare function beginShared(filename: string): void;
|
||||
export declare function terminateShared(filename: string): Shared | null;
|
||||
export declare function getShared(filename: string): Shared | null;
|
30
node_modules/eslint-plugin-svelte/lib/shared/index.js
generated
vendored
Normal file
30
node_modules/eslint-plugin-svelte/lib/shared/index.js
generated
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getShared = exports.terminateShared = exports.beginShared = exports.Shared = void 0;
|
||||
const comment_directives_1 = require("./comment-directives");
|
||||
class Shared {
|
||||
constructor() {
|
||||
this.commentDirectives = [];
|
||||
}
|
||||
newCommentDirectives(options) {
|
||||
const directives = new comment_directives_1.CommentDirectives(options);
|
||||
this.commentDirectives.push(directives);
|
||||
return directives;
|
||||
}
|
||||
}
|
||||
exports.Shared = Shared;
|
||||
const sharedMap = new Map();
|
||||
function beginShared(filename) {
|
||||
sharedMap.set(filename, new Shared());
|
||||
}
|
||||
exports.beginShared = beginShared;
|
||||
function terminateShared(filename) {
|
||||
const result = sharedMap.get(filename);
|
||||
sharedMap.delete(filename);
|
||||
return result ?? null;
|
||||
}
|
||||
exports.terminateShared = terminateShared;
|
||||
function getShared(filename) {
|
||||
return sharedMap.get(filename) ?? null;
|
||||
}
|
||||
exports.getShared = getShared;
|
4
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/extract-leading-comments.d.ts
generated
vendored
Normal file
4
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/extract-leading-comments.d.ts
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
import type { AST } from 'svelte-eslint-parser';
|
||||
import type { RuleContext } from '../../types';
|
||||
import type { ASTNodeWithParent } from '../../types-for-node';
|
||||
export declare function extractLeadingComments(context: RuleContext, node: ASTNodeWithParent): (AST.Token | AST.Comment)[];
|
31
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/extract-leading-comments.js
generated
vendored
Normal file
31
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/extract-leading-comments.js
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.extractLeadingComments = void 0;
|
||||
const eslint_utils_1 = require("@eslint-community/eslint-utils");
|
||||
const compat_1 = require("../../utils/compat");
|
||||
function extractLeadingComments(context, node) {
|
||||
const sourceCode = (0, compat_1.getSourceCode)(context);
|
||||
const beforeToken = sourceCode.getTokenBefore(node, {
|
||||
includeComments: false,
|
||||
filter(token) {
|
||||
if ((0, eslint_utils_1.isOpeningParenToken)(token)) {
|
||||
return false;
|
||||
}
|
||||
const astToken = token;
|
||||
if (astToken.type === 'HTMLText') {
|
||||
return false;
|
||||
}
|
||||
return astToken.type !== 'HTMLComment';
|
||||
}
|
||||
});
|
||||
if (beforeToken) {
|
||||
return sourceCode
|
||||
.getTokensBetween(beforeToken, node, { includeComments: true })
|
||||
.filter(isComment);
|
||||
}
|
||||
return sourceCode.getTokensBefore(node, { includeComments: true }).filter(isComment);
|
||||
}
|
||||
exports.extractLeadingComments = extractLeadingComments;
|
||||
function isComment(token) {
|
||||
return token.type === 'HTMLComment' || token.type === 'Block' || token.type === 'Line';
|
||||
}
|
13
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/ignore-comment.d.ts
generated
vendored
Normal file
13
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/ignore-comment.d.ts
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
import type { AST } from 'svelte-eslint-parser';
|
||||
import type { RuleContext } from '../../types';
|
||||
export type IgnoreItemWithoutCode = {
|
||||
range: [number, number];
|
||||
code: null;
|
||||
token: AST.Token | AST.Comment;
|
||||
};
|
||||
export type IgnoreItem = {
|
||||
range: [number, number];
|
||||
code: string;
|
||||
token: AST.Token | AST.Comment;
|
||||
};
|
||||
export declare function getSvelteIgnoreItems(context: RuleContext): (IgnoreItem | IgnoreItemWithoutCode)[];
|
76
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/ignore-comment.js
generated
vendored
Normal file
76
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/ignore-comment.js
generated
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getSvelteIgnoreItems = void 0;
|
||||
const compat_1 = require("../../utils/compat");
|
||||
const SVELTE_IGNORE_PATTERN = /^\s*svelte-ignore/m;
|
||||
function getSvelteIgnoreItems(context) {
|
||||
const sourceCode = (0, compat_1.getSourceCode)(context);
|
||||
const ignoreComments = [];
|
||||
for (const comment of sourceCode.getAllComments()) {
|
||||
const ignores = extractSvelteIgnore(comment.value, comment.range[0] + 2, comment);
|
||||
if (ignores) {
|
||||
ignoreComments.push(...ignores);
|
||||
}
|
||||
else if (hasMissingCodeIgnore(comment.value)) {
|
||||
ignoreComments.push({
|
||||
range: comment.range,
|
||||
code: null,
|
||||
token: comment
|
||||
});
|
||||
}
|
||||
}
|
||||
for (const token of sourceCode.ast.tokens) {
|
||||
if (token.type === 'HTMLComment') {
|
||||
const text = token.value.slice(4, -3);
|
||||
const ignores = extractSvelteIgnore(text, token.range[0] + 4, token);
|
||||
if (ignores) {
|
||||
ignoreComments.push(...ignores);
|
||||
}
|
||||
else if (hasMissingCodeIgnore(text)) {
|
||||
ignoreComments.push({
|
||||
range: token.range,
|
||||
code: null,
|
||||
token
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
ignoreComments.sort((a, b) => b.range[0] - a.range[0]);
|
||||
return ignoreComments;
|
||||
}
|
||||
exports.getSvelteIgnoreItems = getSvelteIgnoreItems;
|
||||
function extractSvelteIgnore(text, startIndex, token) {
|
||||
const m1 = SVELTE_IGNORE_PATTERN.exec(text);
|
||||
if (!m1) {
|
||||
return null;
|
||||
}
|
||||
const ignoreStart = m1.index + m1[0].length;
|
||||
const beforeText = text.slice(ignoreStart);
|
||||
if (!/^\s/.test(beforeText) || !beforeText.trim()) {
|
||||
return null;
|
||||
}
|
||||
let start = startIndex + ignoreStart;
|
||||
const results = [];
|
||||
for (const code of beforeText.split(/\s/)) {
|
||||
const end = start + code.length;
|
||||
const trimmed = code.trim();
|
||||
if (trimmed) {
|
||||
results.push({
|
||||
code: trimmed,
|
||||
range: [start, end],
|
||||
token
|
||||
});
|
||||
}
|
||||
start = end + 1;
|
||||
}
|
||||
return results;
|
||||
}
|
||||
function hasMissingCodeIgnore(text) {
|
||||
const m1 = SVELTE_IGNORE_PATTERN.exec(text);
|
||||
if (!m1) {
|
||||
return false;
|
||||
}
|
||||
const ignoreStart = m1.index + m1[0].length;
|
||||
const beforeText = text.slice(ignoreStart);
|
||||
return !beforeText.trim();
|
||||
}
|
24
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/index.d.ts
generated
vendored
Normal file
24
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
import type { AST } from 'svelte-eslint-parser';
|
||||
import type { RuleContext } from '../../types';
|
||||
import type { IgnoreItem } from './ignore-comment';
|
||||
export type SvelteCompileWarnings = {
|
||||
warnings: Warning[];
|
||||
unusedIgnores: IgnoreItem[];
|
||||
kind: 'warn' | 'error';
|
||||
stripStyleElements: AST.SvelteStyleElement[];
|
||||
};
|
||||
export type Loc = {
|
||||
start?: {
|
||||
line: number;
|
||||
column: number;
|
||||
};
|
||||
end?: {
|
||||
line: number;
|
||||
column: number;
|
||||
};
|
||||
};
|
||||
export type Warning = {
|
||||
code?: string;
|
||||
message: string;
|
||||
} & Loc;
|
||||
export declare function getSvelteCompileWarnings(context: RuleContext): SvelteCompileWarnings;
|
506
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/index.js
generated
vendored
Normal file
506
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/index.js
generated
vendored
Normal file
@ -0,0 +1,506 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getSvelteCompileWarnings = void 0;
|
||||
const compiler = __importStar(require("svelte/compiler"));
|
||||
const sourcemap_codec_1 = require("@jridgewell/sourcemap-codec");
|
||||
const lines_and_columns_1 = require("../../utils/lines-and-columns");
|
||||
const typescript_1 = require("./transform/typescript");
|
||||
const babel_1 = require("./transform/babel");
|
||||
const postcss_1 = require("./transform/postcss");
|
||||
const sass_1 = require("./transform/sass");
|
||||
const less_1 = require("./transform/less");
|
||||
const stylus_1 = require("./transform/stylus");
|
||||
const ignore_comment_1 = require("./ignore-comment");
|
||||
const extract_leading_comments_1 = require("./extract-leading-comments");
|
||||
const ast_utils_1 = require("../../utils/ast-utils");
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const semver_1 = __importDefault(require("semver"));
|
||||
const compat_1 = require("../../utils/compat");
|
||||
const STYLE_TRANSFORMS = {
|
||||
postcss: postcss_1.transform,
|
||||
pcss: postcss_1.transform,
|
||||
scss: (node, text, context) => (0, sass_1.transform)(node, text, context, 'scss'),
|
||||
sass: (node, text, context) => (0, sass_1.transform)(node, text, context, 'sass'),
|
||||
less: less_1.transform,
|
||||
stylus: stylus_1.transform,
|
||||
styl: stylus_1.transform
|
||||
};
|
||||
const CSS_WARN_CODES = new Set([
|
||||
'css-unused-selector',
|
||||
'css-invalid-global',
|
||||
'css-invalid-global-selector'
|
||||
]);
|
||||
const cacheAll = new WeakMap();
|
||||
function getSvelteCompileWarnings(context) {
|
||||
const sourceCode = (0, compat_1.getSourceCode)(context);
|
||||
const cache = cacheAll.get(sourceCode.ast);
|
||||
if (cache) {
|
||||
return cache;
|
||||
}
|
||||
const result = getSvelteCompileWarningsWithoutCache(context);
|
||||
cacheAll.set(sourceCode.ast, result);
|
||||
return result;
|
||||
}
|
||||
exports.getSvelteCompileWarnings = getSvelteCompileWarnings;
|
||||
function getSvelteCompileWarningsWithoutCache(context) {
|
||||
const sourceCode = (0, compat_1.getSourceCode)(context);
|
||||
const styleElementsWithNotCSS = [...extractStyleElementsWithLangOtherThanCSS(context)];
|
||||
const stripStyleElements = [];
|
||||
const transformResults = [];
|
||||
for (const style of styleElementsWithNotCSS) {
|
||||
const transform = STYLE_TRANSFORMS[style.lang];
|
||||
if (transform) {
|
||||
const result = transform(style.node, (0, compat_1.getSourceCode)(context).text, context);
|
||||
if (result) {
|
||||
transformResults.push(result);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
stripStyleElements.push(style.node);
|
||||
}
|
||||
const stripStyleTokens = stripStyleElements.flatMap((e) => e.children);
|
||||
const ignoreComments = (0, ignore_comment_1.getSvelteIgnoreItems)(context).filter((item) => item.code != null);
|
||||
const text = buildStrippedText(context, ignoreComments, stripStyleTokens);
|
||||
transformResults.push(...transformScripts(context, text));
|
||||
if (!transformResults.length) {
|
||||
const warnings = getWarningsFromCode(text, context);
|
||||
return {
|
||||
...processIgnore(warnings.warnings, warnings.kind, stripStyleElements, ignoreComments, context),
|
||||
kind: warnings.kind,
|
||||
stripStyleElements
|
||||
};
|
||||
}
|
||||
class RemapContext {
|
||||
constructor() {
|
||||
this.originalStart = 0;
|
||||
this.code = '';
|
||||
this.locs = null;
|
||||
this.mapIndexes = [];
|
||||
}
|
||||
appendOriginal(endIndex) {
|
||||
const codeStart = this.code.length;
|
||||
const start = this.originalStart;
|
||||
this.code += text.slice(start, endIndex);
|
||||
this.originalStart = endIndex;
|
||||
const offset = start - codeStart;
|
||||
this.mapIndexes.push({
|
||||
range: [codeStart, this.code.length],
|
||||
remap(index) {
|
||||
return index + offset;
|
||||
}
|
||||
});
|
||||
}
|
||||
postprocess() {
|
||||
this.appendOriginal(text.length);
|
||||
return this.code;
|
||||
}
|
||||
appendTranspile(output) {
|
||||
const endIndex = output.inputRange[1];
|
||||
const codeStart = this.code.length;
|
||||
const start = this.originalStart;
|
||||
const inputText = text.slice(start, endIndex);
|
||||
const outputText = `${output.output}\n`;
|
||||
this.code += outputText;
|
||||
this.originalStart = endIndex;
|
||||
let outputLocs = null;
|
||||
let inputLocs = null;
|
||||
let decoded = null;
|
||||
this.mapIndexes.push({
|
||||
range: [codeStart, this.code.length],
|
||||
remap: (index) => {
|
||||
outputLocs = outputLocs ?? new lines_and_columns_1.LinesAndColumns(outputText);
|
||||
inputLocs = inputLocs ?? new lines_and_columns_1.LinesAndColumns(inputText);
|
||||
const outputCodePos = outputLocs.getLocFromIndex(index - codeStart);
|
||||
const inputCodePos = remapPosition(outputCodePos);
|
||||
return inputLocs.getIndexFromLoc(inputCodePos) + start;
|
||||
}
|
||||
});
|
||||
function remapPosition(pos) {
|
||||
decoded = decoded ?? (0, sourcemap_codec_1.decode)(output.mappings);
|
||||
const lineMaps = decoded[pos.line - 1];
|
||||
if (!lineMaps?.length) {
|
||||
for (let line = pos.line - 1; line >= 0; line--) {
|
||||
const prevLineMaps = decoded[line];
|
||||
if (prevLineMaps?.length) {
|
||||
const [, , sourceCodeLine, sourceCodeColumn] = prevLineMaps[prevLineMaps.length - 1];
|
||||
return {
|
||||
line: sourceCodeLine + 1,
|
||||
column: sourceCodeColumn
|
||||
};
|
||||
}
|
||||
}
|
||||
return { line: -1, column: -1 };
|
||||
}
|
||||
for (let index = 0; index < lineMaps.length - 1; index++) {
|
||||
const [generateCodeColumn, , sourceCodeLine, sourceCodeColumn] = lineMaps[index];
|
||||
if (generateCodeColumn <= pos.column && pos.column < lineMaps[index + 1][0]) {
|
||||
return {
|
||||
line: sourceCodeLine + 1,
|
||||
column: sourceCodeColumn + (pos.column - generateCodeColumn)
|
||||
};
|
||||
}
|
||||
}
|
||||
const [generateCodeColumn, , sourceCodeLine, sourceCodeColumn] = lineMaps[lineMaps.length - 1];
|
||||
return {
|
||||
line: sourceCodeLine + 1,
|
||||
column: sourceCodeColumn + (pos.column - generateCodeColumn)
|
||||
};
|
||||
}
|
||||
}
|
||||
remapLocs(points) {
|
||||
const mapIndexes = this.mapIndexes;
|
||||
const locs = (this.locs = this.locs ?? new lines_and_columns_1.LinesAndColumns(this.code));
|
||||
let start = undefined;
|
||||
let end = undefined;
|
||||
if (points.start) {
|
||||
const index = locs.getIndexFromLoc(points.start);
|
||||
const remapped = remapIndex(index);
|
||||
if (remapped) {
|
||||
start = sourceCode.getLocFromIndex(remapped);
|
||||
}
|
||||
}
|
||||
if (points.end) {
|
||||
const index = locs.getIndexFromLoc(points.end);
|
||||
const remapped = remapIndex(index - 1);
|
||||
if (remapped) {
|
||||
end = sourceCode.getLocFromIndex(remapped + 1);
|
||||
}
|
||||
}
|
||||
return { start, end };
|
||||
function remapIndex(index) {
|
||||
for (const mapIndex of mapIndexes) {
|
||||
if (mapIndex.range[0] <= index && index < mapIndex.range[1]) {
|
||||
return mapIndex.remap(index);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
const remapContext = new RemapContext();
|
||||
for (const result of transformResults.sort((a, b) => a.inputRange[0] - b.inputRange[0])) {
|
||||
remapContext.appendOriginal(result.inputRange[0]);
|
||||
remapContext.appendTranspile(result);
|
||||
}
|
||||
const code = remapContext.postprocess();
|
||||
const baseWarnings = getWarningsFromCode(code, context);
|
||||
const warnings = [];
|
||||
for (const warn of baseWarnings.warnings) {
|
||||
let loc = null;
|
||||
const getLoc = function getLoc() {
|
||||
if (loc) {
|
||||
return loc;
|
||||
}
|
||||
return (loc = remapContext.remapLocs(warn));
|
||||
};
|
||||
warnings.push({
|
||||
code: warn.code,
|
||||
message: warn.message,
|
||||
get start() {
|
||||
return getLoc().start;
|
||||
},
|
||||
get end() {
|
||||
return getLoc().end;
|
||||
}
|
||||
});
|
||||
}
|
||||
return {
|
||||
...processIgnore(warnings, baseWarnings.kind, stripStyleElements, ignoreComments, context),
|
||||
kind: baseWarnings.kind,
|
||||
stripStyleElements
|
||||
};
|
||||
}
|
||||
function* extractStyleElementsWithLangOtherThanCSS(context) {
|
||||
const sourceCode = (0, compat_1.getSourceCode)(context);
|
||||
const root = sourceCode.ast;
|
||||
for (const node of root.body) {
|
||||
if (node.type === 'SvelteStyleElement') {
|
||||
const lang = (0, ast_utils_1.getLangValue)(node);
|
||||
if (lang != null && lang.toLowerCase() !== 'css') {
|
||||
yield { node, lang: lang.toLowerCase() };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function buildStrippedText(context, ignoreComments, stripStyleTokens) {
|
||||
const sourceCode = (0, compat_1.getSourceCode)(context);
|
||||
const baseText = sourceCode.text;
|
||||
const stripTokens = new Set([...ignoreComments.map((item) => item.token), ...stripStyleTokens]);
|
||||
if (!stripTokens.size) {
|
||||
return baseText;
|
||||
}
|
||||
let code = '';
|
||||
let start = 0;
|
||||
for (const token of [...stripTokens].sort((a, b) => a.range[0] - b.range[0])) {
|
||||
code +=
|
||||
baseText.slice(start, token.range[0]) +
|
||||
baseText.slice(...token.range).replace(/[^\t\n\r ]/g, ' ');
|
||||
start = token.range[1];
|
||||
}
|
||||
code += baseText.slice(start);
|
||||
return code;
|
||||
}
|
||||
function* transformScripts(context, text) {
|
||||
const transform = isUseTypeScript(context)
|
||||
? (0, typescript_1.hasTypeScript)(context)
|
||||
? typescript_1.transform
|
||||
: babel_1.transform
|
||||
: isUseBabel(context)
|
||||
? babel_1.transform
|
||||
: null;
|
||||
const sourceCode = (0, compat_1.getSourceCode)(context);
|
||||
if (transform) {
|
||||
const root = sourceCode.ast;
|
||||
for (const node of root.body) {
|
||||
if (node.type === 'SvelteScriptElement') {
|
||||
const result = transform(node, text, context);
|
||||
if (result) {
|
||||
yield result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function hasTagOption(program) {
|
||||
return program.body.some((body) => {
|
||||
if (body.type !== 'SvelteElement' || body.kind !== 'special') {
|
||||
return false;
|
||||
}
|
||||
if (body.name.name !== 'svelte:options') {
|
||||
return false;
|
||||
}
|
||||
return Boolean((0, ast_utils_1.findAttribute)(body, 'tag'));
|
||||
});
|
||||
}
|
||||
function getWarningsFromCode(code, context) {
|
||||
try {
|
||||
const result = compiler.compile(code, {
|
||||
generate: false,
|
||||
...(semver_1.default.satisfies(compiler.VERSION, '>=4.0.0-0')
|
||||
? { customElement: true }
|
||||
: hasTagOption((0, compat_1.getSourceCode)(context).ast)
|
||||
? { customElement: true }
|
||||
: {})
|
||||
});
|
||||
return { warnings: result.warnings, kind: 'warn' };
|
||||
}
|
||||
catch (e) {
|
||||
return {
|
||||
warnings: [
|
||||
{
|
||||
code: e.code,
|
||||
message: e.message,
|
||||
start: e.start,
|
||||
end: e.end
|
||||
}
|
||||
],
|
||||
kind: 'error'
|
||||
};
|
||||
}
|
||||
}
|
||||
function processIgnore(warnings, kind, stripStyleElements, ignoreComments, context) {
|
||||
if (kind === 'error') {
|
||||
return {
|
||||
warnings,
|
||||
unusedIgnores: ignoreComments
|
||||
};
|
||||
}
|
||||
const sourceCode = (0, compat_1.getSourceCode)(context);
|
||||
const unusedIgnores = new Set(ignoreComments);
|
||||
const remainingWarning = new Set(warnings);
|
||||
for (const warning of warnings) {
|
||||
if (!warning.code) {
|
||||
continue;
|
||||
}
|
||||
let node = getWarningNode(warning);
|
||||
while (node) {
|
||||
for (const comment of (0, extract_leading_comments_1.extractLeadingComments)(context, node).reverse()) {
|
||||
const ignoreItem = ignoreComments.find((item) => item.token === comment && item.code === warning.code);
|
||||
if (ignoreItem) {
|
||||
unusedIgnores.delete(ignoreItem);
|
||||
remainingWarning.delete(warning);
|
||||
break;
|
||||
}
|
||||
}
|
||||
node = getIgnoreParent(node);
|
||||
}
|
||||
}
|
||||
for (const node of stripStyleElements) {
|
||||
for (const comment of (0, extract_leading_comments_1.extractLeadingComments)(context, node).reverse()) {
|
||||
const ignoreItem = ignoreComments.find((item) => item.token === comment && CSS_WARN_CODES.has(item.code));
|
||||
if (ignoreItem) {
|
||||
unusedIgnores.delete(ignoreItem);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
warnings: [...remainingWarning],
|
||||
unusedIgnores: [...unusedIgnores]
|
||||
};
|
||||
function getIgnoreParent(node) {
|
||||
if (node.type !== 'SvelteElement' &&
|
||||
node.type !== 'SvelteIfBlock' &&
|
||||
node.type !== 'SvelteKeyBlock' &&
|
||||
node.type !== 'SvelteEachBlock' &&
|
||||
node.type !== 'SvelteAwaitBlock') {
|
||||
return null;
|
||||
}
|
||||
const parent = node.parent;
|
||||
if (parent.type === 'SvelteElseBlock') {
|
||||
return parent.parent;
|
||||
}
|
||||
if (parent.type === 'SvelteAwaitPendingBlock' ||
|
||||
parent.type === 'SvelteAwaitThenBlock' ||
|
||||
parent.type === 'SvelteAwaitCatchBlock') {
|
||||
return parent.parent;
|
||||
}
|
||||
if (parent.type !== 'SvelteElement' &&
|
||||
parent.type !== 'SvelteIfBlock' &&
|
||||
parent.type !== 'SvelteKeyBlock' &&
|
||||
parent.type !== 'SvelteEachBlock') {
|
||||
return null;
|
||||
}
|
||||
return parent;
|
||||
}
|
||||
function getWarningNode(warning) {
|
||||
const indexes = getWarningIndexes(warning);
|
||||
if (indexes.start != null) {
|
||||
const node = getWarningTargetNodeFromIndex(indexes.start);
|
||||
if (node) {
|
||||
return node;
|
||||
}
|
||||
if (indexes.end != null) {
|
||||
const center = Math.floor(indexes.start + (indexes.end - indexes.start) / 2);
|
||||
return getWarningTargetNodeFromIndex(center);
|
||||
}
|
||||
}
|
||||
if (indexes.end != null) {
|
||||
return getWarningTargetNodeFromIndex(indexes.end);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function getWarningTargetNodeFromIndex(index) {
|
||||
let targetNode = sourceCode.getNodeByRangeIndex(index);
|
||||
while (targetNode) {
|
||||
if (targetNode.type === 'SvelteElement' || targetNode.type === 'SvelteStyleElement') {
|
||||
return targetNode;
|
||||
}
|
||||
if (targetNode.parent) {
|
||||
if (targetNode.parent.type === 'Program' ||
|
||||
targetNode.parent.type === 'SvelteScriptElement') {
|
||||
return targetNode;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
targetNode = targetNode.parent || null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function getWarningIndexes(warning) {
|
||||
const start = warning.start && sourceCode.getIndexFromLoc(warning.start);
|
||||
const end = warning.end && sourceCode.getIndexFromLoc(warning.end);
|
||||
return { start, end };
|
||||
}
|
||||
}
|
||||
function isUseTypeScript(context) {
|
||||
const sourceCode = (0, compat_1.getSourceCode)(context);
|
||||
if (sourceCode.parserServices.esTreeNodeToTSNodeMap)
|
||||
return true;
|
||||
const root = sourceCode.ast;
|
||||
for (const node of root.body) {
|
||||
if (node.type === 'SvelteScriptElement') {
|
||||
const lang = (0, ast_utils_1.getLangValue)(node)?.toLowerCase();
|
||||
if (lang === 'ts' || lang === 'typescript') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function isUseBabel(context) {
|
||||
const parser = context.parserOptions?.parser;
|
||||
if (!parser) {
|
||||
return false;
|
||||
}
|
||||
const sourceCode = (0, compat_1.getSourceCode)(context);
|
||||
const root = sourceCode.ast;
|
||||
let scriptLang = 'js';
|
||||
for (const node of root.body) {
|
||||
if (node.type === 'SvelteScriptElement') {
|
||||
const lang = (0, ast_utils_1.getLangValue)(node)?.toLowerCase();
|
||||
if (lang === 'ts' || lang === 'typescript') {
|
||||
scriptLang = lang;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
const parserName = getParserName(scriptLang, parser);
|
||||
if (!parserName) {
|
||||
return false;
|
||||
}
|
||||
if (parserName === '@babel/eslint-parser') {
|
||||
return true;
|
||||
}
|
||||
if (parserName.includes('@babel/eslint-parser')) {
|
||||
let targetPath = parserName;
|
||||
while (targetPath) {
|
||||
const pkgPath = path_1.default.join(targetPath, 'package.json');
|
||||
if (fs_1.default.existsSync(pkgPath)) {
|
||||
try {
|
||||
return JSON.parse(fs_1.default.readFileSync(pkgPath, 'utf-8'))?.name === '@babel/eslint-parser';
|
||||
}
|
||||
catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const parent = path_1.default.dirname(targetPath);
|
||||
if (targetPath === parent) {
|
||||
break;
|
||||
}
|
||||
targetPath = parent;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
function getParserName(lang, parser) {
|
||||
if (typeof parser === 'string') {
|
||||
return parser;
|
||||
}
|
||||
else if (typeof parser === 'object') {
|
||||
const name = parser[lang];
|
||||
if (typeof name === 'string') {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
5
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/babel.d.ts
generated
vendored
Normal file
5
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/babel.d.ts
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
import type { AST } from 'svelte-eslint-parser';
|
||||
import type { RuleContext } from '../../../types';
|
||||
import type { TransformResult } from './types';
|
||||
export declare function transform(node: AST.SvelteScriptElement, text: string, context: RuleContext): TransformResult | null;
|
||||
export declare function hasBabel(context: RuleContext): boolean;
|
48
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/babel.js
generated
vendored
Normal file
48
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/babel.js
generated
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.hasBabel = exports.transform = void 0;
|
||||
const load_module_1 = require("../../../utils/load-module");
|
||||
const compat_1 = require("../../../utils/compat");
|
||||
function transform(node, text, context) {
|
||||
const babel = loadBabel(context);
|
||||
if (!babel) {
|
||||
return null;
|
||||
}
|
||||
let inputRange;
|
||||
if (node.endTag) {
|
||||
inputRange = [node.startTag.range[1], node.endTag.range[0]];
|
||||
}
|
||||
else {
|
||||
inputRange = [node.startTag.range[1], node.range[1]];
|
||||
}
|
||||
const code = text.slice(...inputRange);
|
||||
try {
|
||||
const output = babel.transformSync(code, {
|
||||
sourceType: 'module',
|
||||
sourceMaps: true,
|
||||
minified: false,
|
||||
ast: false,
|
||||
code: true,
|
||||
cwd: (0, compat_1.getCwd)(context)
|
||||
});
|
||||
if (!output) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
inputRange,
|
||||
output: output.code,
|
||||
mappings: output.map.mappings
|
||||
};
|
||||
}
|
||||
catch (_e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
exports.transform = transform;
|
||||
function hasBabel(context) {
|
||||
return Boolean(loadBabel(context));
|
||||
}
|
||||
exports.hasBabel = hasBabel;
|
||||
function loadBabel(context) {
|
||||
return (0, load_module_1.loadModule)(context, '@babel/core');
|
||||
}
|
4
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/less.d.ts
generated
vendored
Normal file
4
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/less.d.ts
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
import type { AST } from 'svelte-eslint-parser';
|
||||
import type { RuleContext } from '../../../types';
|
||||
import type { TransformResult } from './types';
|
||||
export declare function transform(node: AST.SvelteStyleElement, text: string, context: RuleContext): TransformResult | null;
|
46
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/less.js
generated
vendored
Normal file
46
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/less.js
generated
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.transform = void 0;
|
||||
const load_module_1 = require("../../../utils/load-module");
|
||||
const compat_1 = require("../../../utils/compat");
|
||||
function transform(node, text, context) {
|
||||
const less = loadLess(context);
|
||||
if (!less) {
|
||||
return null;
|
||||
}
|
||||
let inputRange;
|
||||
if (node.endTag) {
|
||||
inputRange = [node.startTag.range[1], node.endTag.range[0]];
|
||||
}
|
||||
else {
|
||||
inputRange = [node.startTag.range[1], node.range[1]];
|
||||
}
|
||||
const code = text.slice(...inputRange);
|
||||
const filename = `${(0, compat_1.getFilename)(context)}.less`;
|
||||
try {
|
||||
let output;
|
||||
less.render(code, {
|
||||
sourceMap: {},
|
||||
syncImport: true,
|
||||
filename,
|
||||
lint: false
|
||||
}, (_error, result) => {
|
||||
output = result;
|
||||
});
|
||||
if (!output) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
inputRange,
|
||||
output: output.css,
|
||||
mappings: JSON.parse(output.map).mappings
|
||||
};
|
||||
}
|
||||
catch (_e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
exports.transform = transform;
|
||||
function loadLess(context) {
|
||||
return (0, load_module_1.loadModule)(context, 'less');
|
||||
}
|
4
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/postcss.d.ts
generated
vendored
Normal file
4
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/postcss.d.ts
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
import type { AST } from 'svelte-eslint-parser';
|
||||
import type { RuleContext } from '../../../types';
|
||||
import type { TransformResult } from './types';
|
||||
export declare function transform(node: AST.SvelteStyleElement, text: string, context: RuleContext): TransformResult | null;
|
46
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/postcss.js
generated
vendored
Normal file
46
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/postcss.js
generated
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.transform = void 0;
|
||||
const postcss_1 = __importDefault(require("postcss"));
|
||||
const postcss_load_config_1 = __importDefault(require("postcss-load-config"));
|
||||
const compat_1 = require("../../../utils/compat");
|
||||
function transform(node, text, context) {
|
||||
const postcssConfig = context.settings?.svelte?.compileOptions?.postcss;
|
||||
if (postcssConfig === false) {
|
||||
return null;
|
||||
}
|
||||
let inputRange;
|
||||
if (node.endTag) {
|
||||
inputRange = [node.startTag.range[1], node.endTag.range[0]];
|
||||
}
|
||||
else {
|
||||
inputRange = [node.startTag.range[1], node.range[1]];
|
||||
}
|
||||
const code = text.slice(...inputRange);
|
||||
const filename = `${(0, compat_1.getFilename)(context)}.css`;
|
||||
try {
|
||||
const configFilePath = postcssConfig?.configFilePath;
|
||||
const config = postcss_load_config_1.default.sync({
|
||||
cwd: (0, compat_1.getCwd)(context),
|
||||
from: filename
|
||||
}, typeof configFilePath === 'string' ? configFilePath : undefined);
|
||||
const result = (0, postcss_1.default)(config.plugins).process(code, {
|
||||
...config.options,
|
||||
map: {
|
||||
inline: false
|
||||
}
|
||||
});
|
||||
return {
|
||||
inputRange,
|
||||
output: result.content,
|
||||
mappings: result.map.toJSON().mappings
|
||||
};
|
||||
}
|
||||
catch (_e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
exports.transform = transform;
|
4
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/sass.d.ts
generated
vendored
Normal file
4
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/sass.d.ts
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
import type { AST } from 'svelte-eslint-parser';
|
||||
import type { RuleContext } from '../../../types';
|
||||
import type { TransformResult } from './types';
|
||||
export declare function transform(node: AST.SvelteStyleElement, text: string, context: RuleContext, type: 'scss' | 'sass'): TransformResult | null;
|
39
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/sass.js
generated
vendored
Normal file
39
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/sass.js
generated
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.transform = void 0;
|
||||
const load_module_1 = require("../../../utils/load-module");
|
||||
function transform(node, text, context, type) {
|
||||
const sass = loadSass(context);
|
||||
if (!sass) {
|
||||
return null;
|
||||
}
|
||||
let inputRange;
|
||||
if (node.endTag) {
|
||||
inputRange = [node.startTag.range[1], node.endTag.range[0]];
|
||||
}
|
||||
else {
|
||||
inputRange = [node.startTag.range[1], node.range[1]];
|
||||
}
|
||||
const code = text.slice(...inputRange);
|
||||
try {
|
||||
const output = sass.compileString(code, {
|
||||
sourceMap: true,
|
||||
syntax: type === 'sass' ? 'indented' : undefined
|
||||
});
|
||||
if (!output) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
inputRange,
|
||||
output: output.css,
|
||||
mappings: output.sourceMap.mappings
|
||||
};
|
||||
}
|
||||
catch (_e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
exports.transform = transform;
|
||||
function loadSass(context) {
|
||||
return (0, load_module_1.loadModule)(context, 'sass');
|
||||
}
|
4
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/stylus.d.ts
generated
vendored
Normal file
4
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/stylus.d.ts
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
import type { AST } from 'svelte-eslint-parser';
|
||||
import type { RuleContext } from '../../../types';
|
||||
import type { TransformResult } from './types';
|
||||
export declare function transform(node: AST.SvelteStyleElement, text: string, context: RuleContext): TransformResult | null;
|
44
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/stylus.js
generated
vendored
Normal file
44
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/stylus.js
generated
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.transform = void 0;
|
||||
const load_module_1 = require("../../../utils/load-module");
|
||||
const compat_1 = require("../../../utils/compat");
|
||||
function transform(node, text, context) {
|
||||
const stylus = loadStylus(context);
|
||||
if (!stylus) {
|
||||
return null;
|
||||
}
|
||||
let inputRange;
|
||||
if (node.endTag) {
|
||||
inputRange = [node.startTag.range[1], node.endTag.range[0]];
|
||||
}
|
||||
else {
|
||||
inputRange = [node.startTag.range[1], node.range[1]];
|
||||
}
|
||||
const code = text.slice(...inputRange);
|
||||
const filename = `${(0, compat_1.getFilename)(context)}.stylus`;
|
||||
try {
|
||||
let output;
|
||||
const style = stylus(code, {
|
||||
filename
|
||||
}).set('sourcemap', {});
|
||||
style.render((_error, code) => {
|
||||
output = code;
|
||||
});
|
||||
if (output == null) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
inputRange,
|
||||
output,
|
||||
mappings: style.sourcemap.mappings
|
||||
};
|
||||
}
|
||||
catch (_e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
exports.transform = transform;
|
||||
function loadStylus(context) {
|
||||
return (0, load_module_1.loadModule)(context, 'stylus');
|
||||
}
|
6
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/types.d.ts
generated
vendored
Normal file
6
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/types.d.ts
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
import type { AST } from 'svelte-eslint-parser';
|
||||
export type TransformResult = {
|
||||
inputRange: AST.Range;
|
||||
output: string;
|
||||
mappings: string;
|
||||
};
|
2
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/types.js
generated
vendored
Normal file
2
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/types.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
5
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/typescript.d.ts
generated
vendored
Normal file
5
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/typescript.d.ts
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
import type { AST } from 'svelte-eslint-parser';
|
||||
import type { RuleContext } from '../../../types';
|
||||
import type { TransformResult } from './types';
|
||||
export declare function transform(node: AST.SvelteScriptElement, text: string, context: RuleContext): TransformResult | null;
|
||||
export declare function hasTypeScript(context: RuleContext): boolean;
|
47
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/typescript.js
generated
vendored
Normal file
47
node_modules/eslint-plugin-svelte/lib/shared/svelte-compile-warns/transform/typescript.js
generated
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.hasTypeScript = exports.transform = void 0;
|
||||
const load_module_1 = require("../../../utils/load-module");
|
||||
const compat_1 = require("../../../utils/compat");
|
||||
function transform(node, text, context) {
|
||||
const ts = loadTs(context);
|
||||
if (!ts) {
|
||||
return null;
|
||||
}
|
||||
let inputRange;
|
||||
if (node.endTag) {
|
||||
inputRange = [node.startTag.range[1], node.endTag.range[0]];
|
||||
}
|
||||
else {
|
||||
inputRange = [node.startTag.range[1], node.range[1]];
|
||||
}
|
||||
const code = text.slice(...inputRange);
|
||||
try {
|
||||
const output = ts.transpileModule(code, {
|
||||
reportDiagnostics: false,
|
||||
compilerOptions: {
|
||||
target: (0, compat_1.getSourceCode)(context).parserServices.program?.getCompilerOptions()?.target ||
|
||||
ts.ScriptTarget.ESNext,
|
||||
module: ts.ModuleKind.ESNext,
|
||||
importsNotUsedAsValues: ts.ImportsNotUsedAsValues.Preserve,
|
||||
sourceMap: true
|
||||
}
|
||||
});
|
||||
return {
|
||||
inputRange,
|
||||
output: output.outputText,
|
||||
mappings: JSON.parse(output.sourceMapText).mappings
|
||||
};
|
||||
}
|
||||
catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
exports.transform = transform;
|
||||
function hasTypeScript(context) {
|
||||
return Boolean(loadTs(context));
|
||||
}
|
||||
exports.hasTypeScript = hasTypeScript;
|
||||
function loadTs(context) {
|
||||
return (0, load_module_1.loadModule)(context, 'typescript');
|
||||
}
|
Reference in New Issue
Block a user