🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

prettier-plugin-glsl

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prettier-plugin-glsl - npm Package Compare versions

Comparing version

to
0.0.4

13

lib/nodes.d.ts

@@ -194,8 +194,13 @@ import { IToken } from "chevrotain";

initExpression: Expression;
body: CompoundStatement;
cases: CaseBlock[];
}
export interface CaseLabel extends BaseNode {
kind: "caseLabel";
_case: Expression | undefined;
case_: Expression | undefined;
}
export interface CaseBlock extends BaseNode {
kind: "caseBlock";
caseLabel: CaseLabel;
statements: Statement[];
}
export interface FullySpecifiedType extends BaseNode {

@@ -270,3 +275,3 @@ kind: "fullySpecifiedType";

export declare type Statement = CaseLabel | CompoundStatement | ExpressionStatement | IterationStatement | JumpStatement | SelectionStatement | SwitchStatement | InitDeclaratorListDeclaration | PpNode;
export declare type Node = ArraySpecifier | Declaration | Declarator | Expression | FullySpecifiedType | LayoutQualifier | ParameterDeclaration | Statement | StorageQualifier | StructDeclaration | StructSpecifier | TranslationUnit | TypeQualifier | TypeSpecifier | PpNode;
export declare type Node = ArraySpecifier | CaseBlock | Declaration | Declarator | Expression | FullySpecifiedType | LayoutQualifier | ParameterDeclaration | PpNode | Statement | StorageQualifier | StructDeclaration | StructSpecifier | TranslationUnit | TypeQualifier | TypeSpecifier;
export declare class AbstractVisitor<R> {

@@ -306,2 +311,3 @@ protected visit(n: Node | undefined): R | undefined;

protected caseLabel(n: CaseLabel): R | undefined;
protected caseBlock(n: CaseBlock): R | undefined;
protected fullySpecifiedType(n: FullySpecifiedType): R | undefined;

@@ -320,2 +326,3 @@ protected typeQualifier(n: TypeQualifier): R | undefined;

protected ppCall(_n: PpCall): R | undefined;
protected ppPragma(_n: PpCall): R | undefined;
}

@@ -322,0 +329,0 @@ export declare function isToken(x: IToken | Node): x is IToken;

import { EmbeddedActionsParser, IRecognitionException, IRuleConfig, IToken, TokenType } from "chevrotain";
import { ArraySpecifier, CaseLabel, CompoundStatement, Declaration, Expression, ExpressionStatement, FullySpecifiedType, FunctionCall, InitDeclaratorListDeclaration, IterationStatement, JumpStatement, LayoutQualifier, Node, ParameterDeclaration, PpCall, PpDefine, PpDir, PpExtension, PpNode, PpPragma, SelectionStatement, Statement, StorageQualifier, StructDeclaration, StructSpecifier, SwitchStatement, Token, TranslationUnit, TypeQualifier, TypeSpecifier, UniformBlock } from "./nodes";
import { ArraySpecifier, CaseBlock, CaseLabel, CompoundStatement, Declaration, Expression, ExpressionStatement, FullySpecifiedType, FunctionCall, InitDeclaratorListDeclaration, IterationStatement, JumpStatement, LayoutQualifier, Node, ParameterDeclaration, PpCall, PpDefine, PpDir, PpExtension, PpNode, PpPragma, SelectionStatement, Statement, StorageQualifier, StructDeclaration, StructSpecifier, SwitchStatement, Token, TranslationUnit, TypeQualifier, TypeSpecifier, UniformBlock } from "./nodes";
declare class GLSLParser extends EmbeddedActionsParser {

@@ -19,2 +19,3 @@ multiplicativeExpression: () => Expression;

switchStatement: () => SwitchStatement;
caseBlock: () => CaseBlock;
jumpStatement: () => JumpStatement;

@@ -21,0 +22,0 @@ primaryExpression: () => Expression;

@@ -12,3 +12,3 @@ {

],
"version": "0.0.3",
"version": "0.0.4",
"description": "Prettier (https://prettier.io) plugin for GLSL (OpenGL Shading Language).",

@@ -50,8 +50,8 @@ "exports": "./lib/prettier-plugin.cjs.js",

"@types/lodash": "^4.14.180",
"@types/node": "^17.0.21",
"@types/node": "^17.0.23",
"@types/node-fetch": "^2.6.1",
"@types/prettier": "^2.4.4",
"@typescript-eslint/eslint-plugin": "^5.15.0",
"@typescript-eslint/parser": "^5.15.0",
"eslint": "^8.11.0",
"@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.16.0",
"eslint": "^8.12.0",
"eslint-config-prettier": "^8.5.0",

@@ -65,3 +65,3 @@ "eslint-plugin-cflint": "^1.0.0",

"rollup-plugin-terser": "^7.0.2",
"ts-jest": "^27.1.3",
"ts-jest": "^27.1.4",
"ts-node-dev": "^1.1.8"

@@ -68,0 +68,0 @@ },

@@ -1,3 +0,3 @@

![npm](https://img.shields.io/npm/v/prettier-plugin-glsl?style=flat-square)
![NPM](https://img.shields.io/npm/l/prettier-plugin-glsl?style=flat-square)
[![npm](https://img.shields.io/npm/v/prettier-plugin-glsl?style=flat-square)](https://www.npmjs.com/package/prettier-plugin-glsl)
[![NPM](https://img.shields.io/npm/l/prettier-plugin-glsl?style=flat-square)](https://github.com/NaridaL/glsl-language-toolkit/blob/main/packages/prettier-plugin-glsl/LICENSE)

@@ -8,3 +8,3 @@ # prettier-plugin-glsl

formatter, for GLSL, the shading language used in WebGL and other places. It
uses a custom parser based on [chevrotain](https://chevrotain.io/) and does not
uses a custom parser based on [Chevrotain](https://chevrotain.io/) and does not
require any external dependencies.

@@ -30,3 +30,3 @@

<!-- Printed at 60 wide, so it fits on npm.js renderer site. -->
<!-- Printed at 60 wide, so it fits on npmjs.com rendered site. -->

@@ -74,4 +74,4 @@ ```glsl

```glsl
#define LPAREN
void main() LPAREN
#define LBRACE {
void main() LBRACE
}

@@ -88,19 +88,19 @@ ```

void main() {
// ...
#if AA > 1
for (int m = ZERO; m < AA; m++)
for (int n = ZERO; n < AA; n++) {
// pixel coordinates
vec2 o = vec2(float(m), float(n)) / float(AA) - 0.5;
vec2 p = (2.0 * (fragCoord + o) - iResolution.xy) / iResolution.y;
#else
vec2 p = (2.0 * fragCoord - iResolution.xy) / iResolution.y;
#endif
// ...
#if AA > 1
for (int m = ZERO; m < AA; m++)
for (int n = ZERO; n < AA; n++) {
// pixel coordinates
vec2 o = vec2(float(m), float(n)) / float(AA) - 0.5;
vec2 p = (2.0 * (fragCoord + o) - iResolution.xy) / iResolution.y;
#else
vec2 p = (2.0 * fragCoord - iResolution.xy) / iResolution.y;
#endif
// use p
// use p
#if AA > 1
}
tot /= float(AA * AA);
#endif
#if AA > 1
}
tot /= float(AA * AA);
#endif
}

@@ -107,0 +107,0 @@ ```

@@ -269,3 +269,3 @@ import { IToken } from "chevrotain"

initExpression: Expression
body: CompoundStatement
cases: CaseBlock[]
}

@@ -275,5 +275,11 @@

kind: "caseLabel"
_case: Expression | undefined
case_: Expression | undefined
}
export interface CaseBlock extends BaseNode {
kind: "caseBlock"
caseLabel: CaseLabel
statements: Statement[]
}
export interface FullySpecifiedType extends BaseNode {

@@ -383,2 +389,3 @@ kind: "fullySpecifiedType"

| ArraySpecifier
| CaseBlock
| Declaration

@@ -390,2 +397,3 @@ | Declarator

| ParameterDeclaration
| PpNode
| Statement

@@ -398,3 +406,2 @@ | StorageQualifier

| TypeSpecifier
| PpNode

@@ -592,3 +599,5 @@ export class AbstractVisitor<R> {

this.visit(n.initExpression)
this.visit(n.body)
for (const c of n.cases) {
this.visit(c)
}
return

@@ -598,6 +607,11 @@ }

protected caseLabel(n: CaseLabel): R | undefined {
this.visit(n._case)
this.visit(n.case_)
return
}
protected caseBlock(n: CaseBlock): R | undefined {
this.visit(n.case_)
return
}
protected fullySpecifiedType(n: FullySpecifiedType): R | undefined {

@@ -671,2 +685,6 @@ this.visit(n.typeQualifier)

}
protected ppPragma(_n: PpCall): R | undefined {
return
}
}

@@ -673,0 +691,0 @@

@@ -14,2 +14,3 @@ /* eslint-disable @typescript-eslint/member-ordering */

ArraySpecifier,
CaseBlock,
CaseLabel,

@@ -57,9 +58,3 @@ CompoundStatement,

} from "./nodes"
import {
ALL_TOKENS,
checkLexingErrors,
GLSL_LEXER,
RESERVED_KEYWORDS,
TOKEN,
} from "./lexer"
import { ALL_TOKENS, checkLexingErrors, GLSL_LEXER, RESERVED_KEYWORDS, TOKEN } from "./lexer"
import { DEV, ExpandedLocation, substrContext } from "./util"

@@ -331,2 +326,10 @@ import { applyLineContinuations, fixLocations } from "./preprocessor"

//SPEC statement_list
// public switchStatement = this.RR("switchStatement", (): SwitchStatement => {
// this.CONSUME(TOKEN.SWITCH)
// this.CONSUME(TOKEN.LEFT_PAREN)
// const initExpression = this.SUBRULE(this.expression)
// this.CONSUME(TOKEN.RIGHT_PAREN)
// const body = this.SUBRULE(this.compoundStatement, { ARGS: [true] })
// return { kind: "switchStatement", initExpression, body }
// })
public switchStatement = this.RR("switchStatement", (): SwitchStatement => {

@@ -337,5 +340,15 @@ this.CONSUME(TOKEN.SWITCH)

this.CONSUME(TOKEN.RIGHT_PAREN)
const body = this.SUBRULE(this.compoundStatement, { ARGS: [true] })
return { kind: "switchStatement", initExpression, body }
this.CONSUME(TOKEN.LEFT_BRACE)
const cases: CaseBlock[] = []
this.MANY(() => cases.push(this.SUBRULE(this.caseBlock)))
this.CONSUME(TOKEN.RIGHT_BRACE)
return { kind: "switchStatement", initExpression, cases }
})
public caseBlock = this.RR("caseBlock", (): CaseBlock => {
const caseLabel = this.SUBRULE(this.caseLabel)
const statements: Statement[] = []
this.MANY1(() => statements.push(this.SUBRULE(this.statement)))
return { kind: "caseBlock", caseLabel, statements }
})
//SPEC init_declarator_list:

@@ -1076,5 +1089,5 @@ //SPEC single_declaration

this.CONSUME(TOKEN.CASE)
const _case = this.SUBRULE(this.expression)
const case_ = this.SUBRULE(this.expression)
this.CONSUME(TOKEN.COLON)
return { kind: "caseLabel", _case }
return { kind: "caseLabel", case_ }
},

@@ -1086,3 +1099,3 @@ },

this.CONSUME2(TOKEN.COLON)
return { kind: "caseLabel", _case: undefined }
return { kind: "caseLabel", case_: undefined }
},

@@ -1138,3 +1151,3 @@ },

{ ALT: () => this.SUBRULE(this.switchStatement) },
{ ALT: () => this.SUBRULE(this.caseLabel) },
// { ALT: () => this.SUBRULE(this.caseLabel) }, TODO
{ ALT: () => this.SUBRULE(this.iterationStatement) },

@@ -1141,0 +1154,0 @@ { ALT: () => this.SUBRULE(this.jumpStatement) },

@@ -25,2 +25,3 @@ // noinspection JSUnusedGlobalSymbols

Node,
StructDeclaration,
Token,

@@ -495,15 +496,2 @@ TypeQualifier,

const tok = <N extends Node>(
n: N,
tokenType: TokenType,
index = 0,
): Doc => {
if (!n.tokens) {
return tokenType.PATTERN! as string
} else {
// TODO: get preprocess stuff
return n.tokens.find((t) => t.tokenType === tokenType)!.image
}
}
try {

@@ -637,9 +625,11 @@ switch (n.kind) {

p<typeof n>("fsType"),
" ",
printed.length === 0 ? "" : " ",
printed.length === 1
? printed
: indent(
join(
[",", hasInit && !isParentForLoop ? hardline : line],
printed,
: group(
indent(
join(
[",", hasInit && !isParentForLoop ? hardline : line],
printed,
),
),

@@ -664,3 +654,8 @@ ),

case "arraySpecifier":
return ["[", p<typeof n>("size"), "]"]
return group([
"[",
indent([softline, p<typeof n>("size")]),
softline,
"]",
])
case "arrayAccess":

@@ -673,3 +668,15 @@ return [

]
case "structSpecifier":
case "structSpecifier": {
const parts: Doc = []
path.each((path, index, declarations: StructDeclaration[]) => {
const value = path.getValue()
parts.push(hardline)
parts.push(print(path))
if (
index !== declarations.length - 1 &&
util.isNextLineEmpty(options.originalText, value, locEnd)
) {
parts.push(hardline)
}
}, "declarations")
return group([

@@ -679,9 +686,7 @@ "struct",

" {",
indent([
hardline,
join(hardline, path.map(print, "declarations")),
]),
indent(parts),
hardline,
"}",
])
}

@@ -696,3 +701,3 @@ ///////// STATEMENTS

path.each((path, index, statements) => {
path.each((path, index) => {
const value = path.getValue()

@@ -836,7 +841,7 @@ if (index !== 0) {

return [
"do",
"do ",
p<typeof n>("statement"),
"while (",
" while (",
group(p<typeof n>("conditionExpression")),
")",
");",
]

@@ -1055,2 +1060,35 @@

}
case "switchStatement": {
return [
"switch (",
group([
indent([softline, p<typeof n>("initExpression")]),
softline,
]),
") {",
n.cases.length
? indent([hardline, join(hardline, path.map(print, "cases"))])
: "",
hardline,
"}",
]
}
case "caseBlock": {
const caseLabel = p<typeof n>("caseLabel")
const parts: Doc = []
path.each((path, index) => {
const value = path.getValue()
parts.push(hardline)
parts.push(print(path))
if (util.isNextLineEmpty(options.originalText, value, locEnd)) {
parts.push(hardline)
}
}, "statements")
return [caseLabel, indent(parts)]
}
case "caseLabel": {
return n.case_ === undefined
? "default:"
: ["case ", p<typeof n>("case_"), ":"]
}
default:

@@ -1099,3 +1137,3 @@ throw new Error(

.trim()
const formattedSource = format(src, {
const formattedComment = format(src, {
...options,

@@ -1107,9 +1145,9 @@ printWidth: options.printWidth - 3,

})
const formattedSourceLines = formattedSource.split("\n")
const formattedCommentLines = formattedComment.split("\n")
// Remove the final newline which markdown formatter always adds.
formattedSourceLines.pop()
formattedCommentLines.pop()
return (
"/**\n" +
formattedSourceLines
formattedCommentLines
.map((l) => (l === "" ? " *" : " * " + l))

@@ -1116,0 +1154,0 @@ .join("\n") +

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet