🚀 Socket Launch Week 🚀 Day 5: Introducing Socket Fix.Learn More →

@helios-lang/compiler-utils

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@helios-lang/compiler-utils - npm Package Compare versions

Comparing version

to
0.5.14

{
"name": "@helios-lang/compiler-utils",
"version": "0.5.13",
"version": "0.5.14",
"description": "Helios language compiler library",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -70,3 +70,3 @@ import { expectDefined, isUndefined, isDefined } from "@helios-lang/type-utils"

/**
* @readonly
* @readwrite
* @type {string | undefined}

@@ -77,2 +77,5 @@ */

/**
* To ensure the final fields of the group contains some non-whitespace/non-comment tokens:
* - if there is only 1 field, and that field only contains whitespace and comments -> the result is 0 fields
* - if there are 2 or more fields, and any of those fields only contains whitespace of comments -> error, but continue by removing those fields
* @param {GroupKind} kind - "(", "[" or "{"

@@ -84,4 +87,24 @@ * @param {F[]} fields

constructor(kind, fields, separators, site) {
this.error = undefined
const expectCount = Math.max(fields.length - 1, 0)
this.error = undefined
if (fields.length == 1) {
if (isEmptyField(fields[0])) {
fields = []
}
} else if (fields.length >= 2) {
fields = fields.filter((f, i) => {
if (isEmptyField(f)) {
if (!this.error) {
this.error = `group field ${i + 1} is empty`
}
return false
} else {
return true
}
})
}
if (separators.length > expectCount) {

@@ -245,1 +268,20 @@ const separatorType = separators[0].value

}
/**
* @template {Token[] | TokenReader} [F=Token[]]
* @param {F} f
* @returns {boolean}
*/
function isEmptyField(f) {
if (Array.isArray(f)) {
if (f.every((t) => t.kind == "newline" || t.kind == "comment")) {
return true
}
} else if (
f.tokens.every((t) => t.kind == "newline" || t.kind == "comment")
) {
return true
}
return false
}

@@ -974,5 +974,7 @@ import { encodeUtf8, hexToBytes } from "@helios-lang/codec-utils"

})
if (group.error) {
this.addSyntaxError(group.site, group.error)
}
return group

@@ -979,0 +981,0 @@ }

Sorry, the diff of this file is not supported yet