New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

vscode-css-languageservice

Package Overview
Dependencies
Maintainers
5
Versions
187
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vscode-css-languageservice - npm Package Compare versions

Comparing version 6.1.0 to 6.1.1

21

lib/esm/parser/cssNodes.js

@@ -99,2 +99,3 @@ /*---------------------------------------------------------------------------------------------

NodeType[NodeType["LayerName"] = 85] = "LayerName";
NodeType[NodeType["PropertyAtRule"] = 86] = "PropertyAtRule";
})(NodeType || (NodeType = {}));

@@ -112,2 +113,3 @@ export var ReferenceType;

ReferenceType[ReferenceType["ForwardVisibility"] = 8] = "ForwardVisibility";
ReferenceType[ReferenceType["Property"] = 9] = "Property";
})(ReferenceType || (ReferenceType = {}));

@@ -898,2 +900,21 @@ export function getNodeAtOffset(node, offset) {

}
export class PropertyAtRule extends BodyDeclaration {
constructor(offset, length) {
super(offset, length);
}
get type() {
return NodeType.PropertyAtRule;
}
setName(node) {
if (node) {
node.attachTo(this);
this.name = node;
return true;
}
return false;
}
getName() {
return this.name;
}
}
export class Document extends BodyDeclaration {

@@ -900,0 +921,0 @@ constructor(offset, length) {

@@ -275,2 +275,3 @@ /*---------------------------------------------------------------------------------------------

|| this._parseLayer()
|| this._parsePropertyAtRule()
|| this._parseViewPort()

@@ -721,2 +722,16 @@ || this._parseNamespace()

}
_parsePropertyAtRule() {
// @property <custom-property-name> {
// <declaration-list>
// }
if (!this.peekKeyword('@property')) {
return null;
}
const node = this.create(nodes.PropertyAtRule);
this.consumeToken(); // @layer
if (!this.peekRegExp(TokenType.Ident, /^--/) || !node.setName(this._parseIdent([nodes.ReferenceType.Property]))) {
return this.finish(node, ParseError.IdentifierExpected);
}
return this._parseBody(node, this._parseDeclaration.bind(this));
}
_parseLayer() {

@@ -723,0 +738,0 @@ // @layer layer-name {rules}

1

lib/esm/parser/lessParser.js

@@ -276,2 +276,3 @@ /*---------------------------------------------------------------------------------------------

|| this._parseLayer() // @layer
|| this._parsePropertyAtRule() // @property
|| this._parseDetachedRuleSetMixin() // less detached ruleset mixin

@@ -278,0 +279,0 @@ || this._parseVariableDeclaration() // Variable declarations

@@ -218,2 +218,3 @@ /*---------------------------------------------------------------------------------------------

|| this._parseLayer() // @layer
|| this._parsePropertyAtRule() // @property
|| super._parseRuleSetDeclarationAtStatement();

@@ -220,0 +221,0 @@ }

43

lib/esm/services/cssNavigation.js

@@ -118,3 +118,3 @@ /*---------------------------------------------------------------------------------------------

else {
const resolvedTarget = await this.resolveRelativeReference(target, document.uri, documentContext, data.isRawLink);
const resolvedTarget = await this.resolveReference(target, document.uri, documentContext, data.isRawLink);
if (resolvedTarget !== undefined) {

@@ -308,8 +308,10 @@ link.target = resolvedTarget;

const moduleName = getModuleNameFromPath(ref);
const rootFolderUri = documentContext.resolveReference('/', documentUri);
const documentFolderUri = dirname(documentUri);
const modulePath = await this.resolvePathToModule(moduleName, documentFolderUri, rootFolderUri);
if (modulePath) {
const pathWithinModule = ref.substring(moduleName.length + 1);
return joinPath(modulePath, pathWithinModule);
if (moduleName && moduleName !== '.' && moduleName !== '..') {
const rootFolderUri = documentContext.resolveReference('/', documentUri);
const documentFolderUri = dirname(documentUri);
const modulePath = await this.resolvePathToModule(moduleName, documentFolderUri, rootFolderUri);
if (modulePath) {
const pathWithinModule = ref.substring(moduleName.length + 1);
return joinPath(modulePath, pathWithinModule);
}
}

@@ -319,4 +321,6 @@ }

}
async resolveRelativeReference(ref, documentUri, documentContext, isRawLink) {
const relativeReference = documentContext.resolveReference(ref, documentUri);
async mapReference(target, isRawLink) {
return target;
}
async resolveReference(target, documentUri, documentContext, isRawLink = false) {
// Following [css-loader](https://github.com/webpack-contrib/css-loader#url)

@@ -326,19 +330,22 @@ // and [sass-loader's](https://github.com/webpack-contrib/sass-loader#imports)

// *unless* it starts with "~/" as this refers to the user's home directory.
if (ref[0] === '~' && ref[1] !== '/' && this.fileSystemProvider) {
ref = ref.substring(1);
return await this.resolveModuleReference(ref, documentUri, documentContext) || relativeReference;
if (target[0] === '~' && target[1] !== '/' && this.fileSystemProvider) {
target = target.substring(1);
return this.mapReference(await this.resolveModuleReference(target, documentUri, documentContext), isRawLink);
}
const ref = await this.mapReference(documentContext.resolveReference(target, documentUri), isRawLink);
// Following [less-loader](https://github.com/webpack-contrib/less-loader#imports)
// and [sass-loader's](https://github.com/webpack-contrib/sass-loader#resolving-import-at-rules)
// new resolving import at-rules (~ is deprecated). The loader will first try to resolve @import as a relative path. If it cannot be resolved,
// new resolving import at-rules (~ is deprecated). The loader will first try to resolve @import as a relative path. If it cannot be resolved,
// then the loader will try to resolve @import inside node_modules.
if (this.resolveModuleReferences) {
if (relativeReference && await this.fileExists(relativeReference)) {
return relativeReference;
if (ref && await this.fileExists(ref)) {
return ref;
}
else {
return await this.resolveModuleReference(ref, documentUri, documentContext) || relativeReference;
const moduleReference = await this.mapReference(await this.resolveModuleReference(target, documentUri, documentContext), isRawLink);
if (moduleReference) {
return moduleReference;
}
}
return relativeReference;
// fall back. it might not exists
return ref;
}

@@ -345,0 +352,0 @@ async resolvePathToModule(_moduleName, documentFolderUri, rootFolderUri) {

@@ -8,3 +8,3 @@ /*---------------------------------------------------------------------------------------------

import * as nodes from '../parser/cssNodes';
import { URI } from 'vscode-uri';
import { URI, Utils } from 'vscode-uri';
import { startsWith } from '../utils/strings';

@@ -20,65 +20,43 @@ export class SCSSNavigation extends CSSNavigation {

}
async resolveRelativeReference(ref, documentUri, documentContext, isRawLink) {
if (startsWith(ref, 'sass:')) {
return undefined; // sass library
}
const target = await super.resolveRelativeReference(ref, documentUri, documentContext, isRawLink);
async mapReference(target, isRawLink) {
if (this.fileSystemProvider && target && isRawLink) {
const parsedUri = URI.parse(target);
try {
const pathVariations = toPathVariations(parsedUri);
if (pathVariations) {
for (let j = 0; j < pathVariations.length; j++) {
if (await this.fileExists(pathVariations[j])) {
return pathVariations[j];
}
}
const pathVariations = toPathVariations(target);
for (const variation of pathVariations) {
if (await this.fileExists(variation)) {
return variation;
}
}
catch (e) {
// ignore
}
}
return target;
function toPathVariations(uri) {
// No valid path
if (uri.path === '') {
return undefined;
}
// No variation for links that ends with suffix
if (uri.path.endsWith('.scss') || uri.path.endsWith('.css')) {
return undefined;
}
// If a link is like a/, try resolving a/index.scss and a/_index.scss
if (uri.path.endsWith('/')) {
return [
uri.with({ path: uri.path + 'index.scss' }).toString(true),
uri.with({ path: uri.path + '_index.scss' }).toString(true)
];
}
// Use `uri.path` since it's normalized to use `/` in all platforms
const pathFragments = uri.path.split('/');
const basename = pathFragments[pathFragments.length - 1];
const pathWithoutBasename = uri.path.slice(0, -basename.length);
// No variation for links such as _a
if (basename.startsWith('_')) {
if (uri.path.endsWith('.scss')) {
return undefined;
}
else {
return [uri.with({ path: uri.path + '.scss' }).toString(true)];
}
}
const normalizedBasename = basename + '.scss';
const documentUriWithBasename = (newBasename) => {
return uri.with({ path: pathWithoutBasename + newBasename }).toString(true);
};
const normalizedPath = documentUriWithBasename(normalizedBasename);
const underScorePath = documentUriWithBasename('_' + normalizedBasename);
const indexPath = documentUriWithBasename(normalizedBasename.slice(0, -5) + '/index.scss');
const indexUnderscoreUri = documentUriWithBasename(normalizedBasename.slice(0, -5) + '/_index.scss');
const cssPath = documentUriWithBasename(normalizedBasename.slice(0, -5) + '.css');
return [normalizedPath, underScorePath, indexPath, indexUnderscoreUri, cssPath];
}
async resolveReference(target, documentUri, documentContext, isRawLink = false) {
if (startsWith(target, 'sass:')) {
return undefined; // sass library
}
return super.resolveReference(target, documentUri, documentContext, isRawLink);
}
}
function toPathVariations(target) {
// No variation for links that ends with suffix
if (target.endsWith('.scss') || target.endsWith('.css')) {
return [target];
}
// If a link is like a/, try resolving a/index.scss and a/_index.scss
if (target.endsWith('/')) {
return [target + 'index.scss', target + '_index.scss'];
}
const targetUri = URI.parse(target);
const basename = Utils.basename(targetUri);
const dirname = Utils.dirname(targetUri);
if (basename.startsWith('_')) {
// No variation for links such as _a
return [Utils.joinPath(dirname, basename + '.scss').toString(true)];
}
return [
Utils.joinPath(dirname, basename + '.scss').toString(true),
Utils.joinPath(dirname, '_' + basename + '.scss').toString(true),
target + '/index.scss',
target + '/_index.scss',
Utils.joinPath(dirname, basename + '.css').toString(true)
];
}

@@ -16,3 +16,3 @@ (function (factory) {

Object.defineProperty(exports, "__esModule", { value: true });
exports.ParseErrorCollector = exports.Marker = exports.Level = exports.Module = exports.GuardCondition = exports.LessGuard = exports.ListEntry = exports.UnknownAtRule = exports.MixinDeclaration = exports.MixinReference = exports.MixinContentDeclaration = exports.MixinContentReference = exports.ExtendsReference = exports.Variable = exports.Interpolation = exports.VariableDeclaration = exports.NumericValue = exports.RatioValue = exports.HexColorValue = exports.Operator = exports.AttributeSelector = exports.Term = exports.BinaryExpression = exports.Expression = exports.PageBoxMarginBox = exports.Page = exports.SupportsCondition = exports.MediaFeature = exports.MediaCondition = exports.MediaQuery = exports.Medialist = exports.Document = exports.Layer = exports.Supports = exports.Media = exports.Namespace = exports.ForwardVisibility = exports.Forward = exports.ModuleConfiguration = exports.Use = exports.Import = exports.KeyframeSelector = exports.Keyframe = exports.NestedProperties = exports.FontFace = exports.ViewPort = exports.FunctionDeclaration = exports.ElseStatement = exports.WhileStatement = exports.EachStatement = exports.ForStatement = exports.IfStatement = exports.FunctionArgument = exports.FunctionParameter = exports.Function = exports.Invocation = exports.Property = exports.CustomPropertyDeclaration = exports.Declaration = exports.CustomPropertySet = exports.AbstractDeclaration = exports.AtApplyRule = exports.SimpleSelector = exports.Selector = exports.RuleSet = exports.BodyDeclaration = exports.Declarations = exports.Stylesheet = exports.Identifier = exports.UnicodeRange = exports.Nodelist = exports.Node = exports.getParentDeclaration = exports.getNodePath = exports.getNodeAtOffset = exports.ReferenceType = exports.NodeType = void 0;
exports.ParseErrorCollector = exports.Marker = exports.Level = exports.Module = exports.GuardCondition = exports.LessGuard = exports.ListEntry = exports.UnknownAtRule = exports.MixinDeclaration = exports.MixinReference = exports.MixinContentDeclaration = exports.MixinContentReference = exports.ExtendsReference = exports.Variable = exports.Interpolation = exports.VariableDeclaration = exports.NumericValue = exports.RatioValue = exports.HexColorValue = exports.Operator = exports.AttributeSelector = exports.Term = exports.BinaryExpression = exports.Expression = exports.PageBoxMarginBox = exports.Page = exports.SupportsCondition = exports.MediaFeature = exports.MediaCondition = exports.MediaQuery = exports.Medialist = exports.Document = exports.PropertyAtRule = exports.Layer = exports.Supports = exports.Media = exports.Namespace = exports.ForwardVisibility = exports.Forward = exports.ModuleConfiguration = exports.Use = exports.Import = exports.KeyframeSelector = exports.Keyframe = exports.NestedProperties = exports.FontFace = exports.ViewPort = exports.FunctionDeclaration = exports.ElseStatement = exports.WhileStatement = exports.EachStatement = exports.ForStatement = exports.IfStatement = exports.FunctionArgument = exports.FunctionParameter = exports.Function = exports.Invocation = exports.Property = exports.CustomPropertyDeclaration = exports.Declaration = exports.CustomPropertySet = exports.AbstractDeclaration = exports.AtApplyRule = exports.SimpleSelector = exports.Selector = exports.RuleSet = exports.BodyDeclaration = exports.Declarations = exports.Stylesheet = exports.Identifier = exports.UnicodeRange = exports.Nodelist = exports.Node = exports.getParentDeclaration = exports.getNodePath = exports.getNodeAtOffset = exports.ReferenceType = exports.NodeType = void 0;
const strings_1 = require("../utils/strings");

@@ -111,2 +111,3 @@ /// <summary>

NodeType[NodeType["LayerName"] = 85] = "LayerName";
NodeType[NodeType["PropertyAtRule"] = 86] = "PropertyAtRule";
})(NodeType = exports.NodeType || (exports.NodeType = {}));

@@ -124,2 +125,3 @@ var ReferenceType;

ReferenceType[ReferenceType["ForwardVisibility"] = 8] = "ForwardVisibility";
ReferenceType[ReferenceType["Property"] = 9] = "Property";
})(ReferenceType = exports.ReferenceType || (exports.ReferenceType = {}));

@@ -953,2 +955,22 @@ function getNodeAtOffset(node, offset) {

exports.Layer = Layer;
class PropertyAtRule extends BodyDeclaration {
constructor(offset, length) {
super(offset, length);
}
get type() {
return NodeType.PropertyAtRule;
}
setName(node) {
if (node) {
node.attachTo(this);
this.name = node;
return true;
}
return false;
}
getName() {
return this.name;
}
}
exports.PropertyAtRule = PropertyAtRule;
class Document extends BodyDeclaration {

@@ -955,0 +977,0 @@ constructor(offset, length) {

@@ -287,2 +287,3 @@ (function (factory) {

|| this._parseLayer() // @layer
|| this._parsePropertyAtRule() // @property
|| this._parseDetachedRuleSetMixin() // less detached ruleset mixin

@@ -289,0 +290,0 @@ || this._parseVariableDeclaration() // Variable declarations

@@ -229,2 +229,3 @@ (function (factory) {

|| this._parseLayer() // @layer
|| this._parsePropertyAtRule() // @property
|| super._parseRuleSetDeclarationAtStatement();

@@ -231,0 +232,0 @@ }

@@ -129,3 +129,3 @@ (function (factory) {

else {
const resolvedTarget = await this.resolveRelativeReference(target, document.uri, documentContext, data.isRawLink);
const resolvedTarget = await this.resolveReference(target, document.uri, documentContext, data.isRawLink);
if (resolvedTarget !== undefined) {

@@ -319,8 +319,10 @@ link.target = resolvedTarget;

const moduleName = getModuleNameFromPath(ref);
const rootFolderUri = documentContext.resolveReference('/', documentUri);
const documentFolderUri = (0, resources_1.dirname)(documentUri);
const modulePath = await this.resolvePathToModule(moduleName, documentFolderUri, rootFolderUri);
if (modulePath) {
const pathWithinModule = ref.substring(moduleName.length + 1);
return (0, resources_1.joinPath)(modulePath, pathWithinModule);
if (moduleName && moduleName !== '.' && moduleName !== '..') {
const rootFolderUri = documentContext.resolveReference('/', documentUri);
const documentFolderUri = (0, resources_1.dirname)(documentUri);
const modulePath = await this.resolvePathToModule(moduleName, documentFolderUri, rootFolderUri);
if (modulePath) {
const pathWithinModule = ref.substring(moduleName.length + 1);
return (0, resources_1.joinPath)(modulePath, pathWithinModule);
}
}

@@ -330,4 +332,6 @@ }

}
async resolveRelativeReference(ref, documentUri, documentContext, isRawLink) {
const relativeReference = documentContext.resolveReference(ref, documentUri);
async mapReference(target, isRawLink) {
return target;
}
async resolveReference(target, documentUri, documentContext, isRawLink = false) {
// Following [css-loader](https://github.com/webpack-contrib/css-loader#url)

@@ -337,19 +341,22 @@ // and [sass-loader's](https://github.com/webpack-contrib/sass-loader#imports)

// *unless* it starts with "~/" as this refers to the user's home directory.
if (ref[0] === '~' && ref[1] !== '/' && this.fileSystemProvider) {
ref = ref.substring(1);
return await this.resolveModuleReference(ref, documentUri, documentContext) || relativeReference;
if (target[0] === '~' && target[1] !== '/' && this.fileSystemProvider) {
target = target.substring(1);
return this.mapReference(await this.resolveModuleReference(target, documentUri, documentContext), isRawLink);
}
const ref = await this.mapReference(documentContext.resolveReference(target, documentUri), isRawLink);
// Following [less-loader](https://github.com/webpack-contrib/less-loader#imports)
// and [sass-loader's](https://github.com/webpack-contrib/sass-loader#resolving-import-at-rules)
// new resolving import at-rules (~ is deprecated). The loader will first try to resolve @import as a relative path. If it cannot be resolved,
// new resolving import at-rules (~ is deprecated). The loader will first try to resolve @import as a relative path. If it cannot be resolved,
// then the loader will try to resolve @import inside node_modules.
if (this.resolveModuleReferences) {
if (relativeReference && await this.fileExists(relativeReference)) {
return relativeReference;
if (ref && await this.fileExists(ref)) {
return ref;
}
else {
return await this.resolveModuleReference(ref, documentUri, documentContext) || relativeReference;
const moduleReference = await this.mapReference(await this.resolveModuleReference(target, documentUri, documentContext), isRawLink);
if (moduleReference) {
return moduleReference;
}
}
return relativeReference;
// fall back. it might not exists
return ref;
}

@@ -356,0 +363,0 @@ async resolvePathToModule(_moduleName, documentFolderUri, rootFolderUri) {

@@ -30,67 +30,45 @@ (function (factory) {

}
async resolveRelativeReference(ref, documentUri, documentContext, isRawLink) {
if ((0, strings_1.startsWith)(ref, 'sass:')) {
return undefined; // sass library
}
const target = await super.resolveRelativeReference(ref, documentUri, documentContext, isRawLink);
async mapReference(target, isRawLink) {
if (this.fileSystemProvider && target && isRawLink) {
const parsedUri = vscode_uri_1.URI.parse(target);
try {
const pathVariations = toPathVariations(parsedUri);
if (pathVariations) {
for (let j = 0; j < pathVariations.length; j++) {
if (await this.fileExists(pathVariations[j])) {
return pathVariations[j];
}
}
const pathVariations = toPathVariations(target);
for (const variation of pathVariations) {
if (await this.fileExists(variation)) {
return variation;
}
}
catch (e) {
// ignore
}
}
return target;
function toPathVariations(uri) {
// No valid path
if (uri.path === '') {
return undefined;
}
// No variation for links that ends with suffix
if (uri.path.endsWith('.scss') || uri.path.endsWith('.css')) {
return undefined;
}
// If a link is like a/, try resolving a/index.scss and a/_index.scss
if (uri.path.endsWith('/')) {
return [
uri.with({ path: uri.path + 'index.scss' }).toString(true),
uri.with({ path: uri.path + '_index.scss' }).toString(true)
];
}
// Use `uri.path` since it's normalized to use `/` in all platforms
const pathFragments = uri.path.split('/');
const basename = pathFragments[pathFragments.length - 1];
const pathWithoutBasename = uri.path.slice(0, -basename.length);
// No variation for links such as _a
if (basename.startsWith('_')) {
if (uri.path.endsWith('.scss')) {
return undefined;
}
else {
return [uri.with({ path: uri.path + '.scss' }).toString(true)];
}
}
const normalizedBasename = basename + '.scss';
const documentUriWithBasename = (newBasename) => {
return uri.with({ path: pathWithoutBasename + newBasename }).toString(true);
};
const normalizedPath = documentUriWithBasename(normalizedBasename);
const underScorePath = documentUriWithBasename('_' + normalizedBasename);
const indexPath = documentUriWithBasename(normalizedBasename.slice(0, -5) + '/index.scss');
const indexUnderscoreUri = documentUriWithBasename(normalizedBasename.slice(0, -5) + '/_index.scss');
const cssPath = documentUriWithBasename(normalizedBasename.slice(0, -5) + '.css');
return [normalizedPath, underScorePath, indexPath, indexUnderscoreUri, cssPath];
}
async resolveReference(target, documentUri, documentContext, isRawLink = false) {
if ((0, strings_1.startsWith)(target, 'sass:')) {
return undefined; // sass library
}
return super.resolveReference(target, documentUri, documentContext, isRawLink);
}
}
exports.SCSSNavigation = SCSSNavigation;
function toPathVariations(target) {
// No variation for links that ends with suffix
if (target.endsWith('.scss') || target.endsWith('.css')) {
return [target];
}
// If a link is like a/, try resolving a/index.scss and a/_index.scss
if (target.endsWith('/')) {
return [target + 'index.scss', target + '_index.scss'];
}
const targetUri = vscode_uri_1.URI.parse(target);
const basename = vscode_uri_1.Utils.basename(targetUri);
const dirname = vscode_uri_1.Utils.dirname(targetUri);
if (basename.startsWith('_')) {
// No variation for links such as _a
return [vscode_uri_1.Utils.joinPath(dirname, basename + '.scss').toString(true)];
}
return [
vscode_uri_1.Utils.joinPath(dirname, basename + '.scss').toString(true),
vscode_uri_1.Utils.joinPath(dirname, '_' + basename + '.scss').toString(true),
target + '/index.scss',
target + '/_index.scss',
vscode_uri_1.Utils.joinPath(dirname, basename + '.css').toString(true)
];
}
});
{
"name": "vscode-css-languageservice",
"version": "6.1.0",
"version": "6.1.1",
"description": "Language service for CSS, LESS and SCSS",

@@ -20,6 +20,6 @@ "main": "./lib/umd/cssLanguageService.js",

"@types/node": "16.x",
"@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1",
"@typescript-eslint/eslint-plugin": "^5.37.0",
"@typescript-eslint/parser": "^5.37.0",
"@vscode/web-custom-data": "^0.4.2",
"eslint": "^8.23.0",
"eslint": "^8.23.1",
"js-beautify": "^1.14.6",

@@ -29,3 +29,3 @@ "mocha": "^10.0.0",

"source-map-support": "^0.5.21",
"typescript": "^4.8.2"
"typescript": "^4.8.3"
},

@@ -36,3 +36,3 @@ "dependencies": {

"vscode-nls": "^5.2.0",
"vscode-uri": "^3.0.3"
"vscode-uri": "^3.0.4"
},

@@ -39,0 +39,0 @@ "scripts": {

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc