Skip to content

Commit

Permalink
storing offsets in a Map instead of passing them down through an array (
Browse files Browse the repository at this point in the history
  • Loading branch information
Janther authored Nov 14, 2024
1 parent 7e34f9e commit 4c15c9b
Show file tree
Hide file tree
Showing 228 changed files with 873 additions and 2,020 deletions.
6 changes: 1 addition & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ const TEST_STANDALONE = Boolean(process.env.TEST_STANDALONE);
const testMatch = ['<rootDir>/tests/format/**/format.test.js'];

if (TEST_STANDALONE) {
testMatch.push(
'<rootDir>/tests/integration/**/*.test.js',
'<rootDir>/tests/unit/prettier-version/**/*.test.js'
);
testMatch.push('<rootDir>/tests/integration/**/*.test.js');
} else {
testMatch.push('<rootDir>/tests/unit/**/*.test.js');
testMatch.push('<rootDir>/tests/unit/**/*.test.ts');
}

export default {
Expand Down
7 changes: 3 additions & 4 deletions src/slang-nodes/AbicoderPragma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ export class AbicoderPragma implements SlangNode {

version: Identifier;

constructor(ast: ast.AbicoderPragma, offset: number) {
const metadata = getNodeMetadata(ast, offset);
const { offsets } = metadata;
constructor(ast: ast.AbicoderPragma) {
const metadata = getNodeMetadata(ast);

this.version = new Identifier(ast.version, offsets[0]);
this.version = new Identifier(ast.version);

this.comments = metadata.comments;
this.loc = metadata.loc;
Expand Down
13 changes: 4 additions & 9 deletions src/slang-nodes/AdditiveExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,12 @@ export class AdditiveExpression implements SlangNode {

rightOperand: Expression;

constructor(
ast: ast.AdditiveExpression,
offset: number,
options: ParserOptions<AstNode>
) {
let metadata = getNodeMetadata(ast, offset);
const { offsets } = metadata;
constructor(ast: ast.AdditiveExpression, options: ParserOptions<AstNode>) {
let metadata = getNodeMetadata(ast);

this.leftOperand = new Expression(ast.leftOperand, offsets[0], options);
this.leftOperand = new Expression(ast.leftOperand, options);
this.operator = ast.operator.unparse();
this.rightOperand = new Expression(ast.rightOperand, offsets[1], options);
this.rightOperand = new Expression(ast.rightOperand, options);

metadata = updateMetadata(metadata, [this.leftOperand, this.rightOperand]);

Expand Down
4 changes: 2 additions & 2 deletions src/slang-nodes/AddressType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export class AddressType implements SlangNode {

payableKeyword?: string;

constructor(ast: ast.AddressType, offset: number) {
const metadata = getNodeMetadata(ast, offset);
constructor(ast: ast.AddressType) {
const metadata = getNodeMetadata(ast);

this.payableKeyword = ast.payableKeyword?.unparse();

Expand Down
13 changes: 4 additions & 9 deletions src/slang-nodes/AndExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,12 @@ export class AndExpression implements SlangNode {

rightOperand: Expression;

constructor(
ast: ast.AndExpression,
offset: number,
options: ParserOptions<AstNode>
) {
let metadata = getNodeMetadata(ast, offset);
const { offsets } = metadata;
constructor(ast: ast.AndExpression, options: ParserOptions<AstNode>) {
let metadata = getNodeMetadata(ast);

this.leftOperand = new Expression(ast.leftOperand, offsets[0], options);
this.leftOperand = new Expression(ast.leftOperand, options);
this.operator = ast.operator.unparse();
this.rightOperand = new Expression(ast.rightOperand, offsets[1], options);
this.rightOperand = new Expression(ast.rightOperand, options);

metadata = updateMetadata(metadata, [this.leftOperand, this.rightOperand]);

Expand Down
11 changes: 2 additions & 9 deletions src/slang-nodes/ArgumentsDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,19 @@ export class ArgumentsDeclaration implements SlangNode {

variant: PositionalArgumentsDeclaration | NamedArgumentsDeclaration;

constructor(
ast: ast.ArgumentsDeclaration,
offset: number,
options: ParserOptions<AstNode>
) {
let metadata = getNodeMetadata(ast, offset);
const { offsets } = metadata;
constructor(ast: ast.ArgumentsDeclaration, options: ParserOptions<AstNode>) {
let metadata = getNodeMetadata(ast);

switch (ast.variant.cst.kind) {
case NonterminalKind.PositionalArgumentsDeclaration:
this.variant = new PositionalArgumentsDeclaration(
ast.variant as ast.PositionalArgumentsDeclaration,
offsets[0],
options
);
break;
case NonterminalKind.NamedArgumentsDeclaration:
this.variant = new NamedArgumentsDeclaration(
ast.variant as ast.NamedArgumentsDeclaration,
offsets[0],
options
);
break;
Expand Down
13 changes: 4 additions & 9 deletions src/slang-nodes/ArrayExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,10 @@ export class ArrayExpression implements SlangNode {

items: ArrayValues;

constructor(
ast: ast.ArrayExpression,
offset: number,
options: ParserOptions<AstNode>
) {
let metadata = getNodeMetadata(ast, offset);
const { offsets } = metadata;

this.items = new ArrayValues(ast.items, offsets[0], options);
constructor(ast: ast.ArrayExpression, options: ParserOptions<AstNode>) {
let metadata = getNodeMetadata(ast);

this.items = new ArrayValues(ast.items, options);

metadata = updateMetadata(metadata, [this.items]);

Expand Down
15 changes: 5 additions & 10 deletions src/slang-nodes/ArrayTypeName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,12 @@ export class ArrayTypeName implements SlangNode {

index?: Expression;

constructor(
ast: ast.ArrayTypeName,
offset: number,
options: ParserOptions<AstNode>
) {
let metadata = getNodeMetadata(ast, offset);
const { offsets } = metadata;

this.operand = new TypeName(ast.operand, offsets[0], options);
constructor(ast: ast.ArrayTypeName, options: ParserOptions<AstNode>) {
let metadata = getNodeMetadata(ast);

this.operand = new TypeName(ast.operand, options);
if (ast.index) {
this.index = new Expression(ast.index, offsets[1], options);
this.index = new Expression(ast.index, options);
}

metadata = updateMetadata(metadata, [this.operand, this.index]);
Expand Down
15 changes: 4 additions & 11 deletions src/slang-nodes/ArrayValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,10 @@ export class ArrayValues implements SlangNode {

separators: string[];

constructor(
ast: ast.ArrayValues,
offset: number,
options: ParserOptions<AstNode>
) {
let metadata = getNodeMetadata(ast, offset, true);
const { offsets } = metadata;

this.items = ast.items.map(
(item, index) => new Expression(item, offsets[index], options)
);
constructor(ast: ast.ArrayValues, options: ParserOptions<AstNode>) {
let metadata = getNodeMetadata(ast, true);

this.items = ast.items.map((item) => new Expression(item, options));
this.separators = ast.separators.map((separator) => separator.unparse());

metadata = updateMetadata(metadata, [this.items]);
Expand Down
15 changes: 4 additions & 11 deletions src/slang-nodes/AssemblyFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,10 @@ export class AssemblyFlags implements SlangNode {

separators: string[];

constructor(
ast: ast.AssemblyFlags,
offset: number,
options: ParserOptions<AstNode>
) {
let metadata = getNodeMetadata(ast, offset, true);
const { offsets } = metadata;

this.items = ast.items.map(
(item, index) => new StringLiteral(item, offsets[index], options)
);
constructor(ast: ast.AssemblyFlags, options: ParserOptions<AstNode>) {
let metadata = getNodeMetadata(ast, true);

this.items = ast.items.map((item) => new StringLiteral(item, options));
this.separators = ast.separators.map((separator) => separator.unparse());

metadata = updateMetadata(metadata, [this.items]);
Expand Down
6 changes: 2 additions & 4 deletions src/slang-nodes/AssemblyFlagsDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ export class AssemblyFlagsDeclaration implements SlangNode {

constructor(
ast: ast.AssemblyFlagsDeclaration,
offset: number,
options: ParserOptions<AstNode>
) {
let metadata = getNodeMetadata(ast, offset);
const { offsets } = metadata;
let metadata = getNodeMetadata(ast);

this.flags = new AssemblyFlags(ast.flags, offsets[0], options);
this.flags = new AssemblyFlags(ast.flags, options);

metadata = updateMetadata(metadata, [this.flags]);

Expand Down
20 changes: 6 additions & 14 deletions src/slang-nodes/AssemblyStatement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,16 @@ export class AssemblyStatement implements SlangNode {

body: YulBlock;

constructor(
ast: ast.AssemblyStatement,
offset: number,
options: ParserOptions<AstNode>
) {
let metadata = getNodeMetadata(ast, offset);
const { offsets } = metadata;

let i = 0;
constructor(ast: ast.AssemblyStatement, options: ParserOptions<AstNode>) {
let metadata = getNodeMetadata(ast);

if (ast.label) {
this.label = new StringLiteral(ast.label, offsets[i], options);
i += 1;
this.label = new StringLiteral(ast.label, options);
}
if (ast.flags) {
this.flags = new AssemblyFlagsDeclaration(ast.flags, offsets[i], options);
i += 1;
this.flags = new AssemblyFlagsDeclaration(ast.flags, options);
}
this.body = new YulBlock(ast.body, offsets[i], options);
this.body = new YulBlock(ast.body, options);

metadata = updateMetadata(metadata, [this.label, this.flags, this.body]);

Expand Down
15 changes: 5 additions & 10 deletions src/slang-nodes/AssignmentExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,12 @@ export class AssignmentExpression implements SlangNode {

rightOperand: Expression;

constructor(
ast: ast.AssignmentExpression,
offset: number,
options: ParserOptions<AstNode>
) {
let metadata = getNodeMetadata(ast, offset);
const { offsets } = metadata;

this.leftOperand = new Expression(ast.leftOperand, offsets[0], options);
constructor(ast: ast.AssignmentExpression, options: ParserOptions<AstNode>) {
let metadata = getNodeMetadata(ast);

this.leftOperand = new Expression(ast.leftOperand, options);
this.operator = ast.operator.unparse();
this.rightOperand = new Expression(ast.rightOperand, offsets[1], options);
this.rightOperand = new Expression(ast.rightOperand, options);

metadata = updateMetadata(metadata, [this.leftOperand, this.rightOperand]);

Expand Down
13 changes: 4 additions & 9 deletions src/slang-nodes/BitwiseAndExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,12 @@ export class BitwiseAndExpression implements SlangNode {

rightOperand: Expression;

constructor(
ast: ast.BitwiseAndExpression,
offset: number,
options: ParserOptions<AstNode>
) {
let metadata = getNodeMetadata(ast, offset);
const { offsets } = metadata;
constructor(ast: ast.BitwiseAndExpression, options: ParserOptions<AstNode>) {
let metadata = getNodeMetadata(ast);

this.leftOperand = new Expression(ast.leftOperand, offsets[0], options);
this.leftOperand = new Expression(ast.leftOperand, options);
this.operator = ast.operator.unparse();
this.rightOperand = new Expression(ast.rightOperand, offsets[1], options);
this.rightOperand = new Expression(ast.rightOperand, options);

metadata = updateMetadata(metadata, [this.leftOperand, this.rightOperand]);

Expand Down
13 changes: 4 additions & 9 deletions src/slang-nodes/BitwiseOrExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,12 @@ export class BitwiseOrExpression implements SlangNode {

rightOperand;

constructor(
ast: ast.BitwiseOrExpression,
offset: number,
options: ParserOptions<AstNode>
) {
let metadata = getNodeMetadata(ast, offset);
const { offsets } = metadata;
constructor(ast: ast.BitwiseOrExpression, options: ParserOptions<AstNode>) {
let metadata = getNodeMetadata(ast);

this.leftOperand = new Expression(ast.leftOperand, offsets[0], options);
this.leftOperand = new Expression(ast.leftOperand, options);
this.operator = ast.operator.unparse();
this.rightOperand = new Expression(ast.rightOperand, offsets[1], options);
this.rightOperand = new Expression(ast.rightOperand, options);

metadata = updateMetadata(metadata, [this.leftOperand, this.rightOperand]);

Expand Down
13 changes: 4 additions & 9 deletions src/slang-nodes/BitwiseXorExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,12 @@ export class BitwiseXorExpression implements SlangNode {

rightOperand: Expression;

constructor(
ast: ast.BitwiseXorExpression,
offset: number,
options: ParserOptions<AstNode>
) {
let metadata = getNodeMetadata(ast, offset);
const { offsets } = metadata;
constructor(ast: ast.BitwiseXorExpression, options: ParserOptions<AstNode>) {
let metadata = getNodeMetadata(ast);

this.leftOperand = new Expression(ast.leftOperand, offsets[0], options);
this.leftOperand = new Expression(ast.leftOperand, options);
this.operator = ast.operator.unparse();
this.rightOperand = new Expression(ast.rightOperand, offsets[1], options);
this.rightOperand = new Expression(ast.rightOperand, options);

metadata = updateMetadata(metadata, [this.leftOperand, this.rightOperand]);

Expand Down
7 changes: 3 additions & 4 deletions src/slang-nodes/Block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ export class Block implements SlangNode {

statements: Statements;

constructor(ast: ast.Block, offset: number, options: ParserOptions<AstNode>) {
let metadata = getNodeMetadata(ast, offset);
const { offsets } = metadata;
constructor(ast: ast.Block, options: ParserOptions<AstNode>) {
let metadata = getNodeMetadata(ast);

this.statements = new Statements(ast.statements, offsets[0], options);
this.statements = new Statements(ast.statements, options);

metadata = updateMetadata(metadata, [this.statements]);

Expand Down
4 changes: 2 additions & 2 deletions src/slang-nodes/BreakStatement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export class BreakStatement implements SlangNode {

loc;

constructor(ast: ast.BreakStatement, offset: number) {
const metadata = getNodeMetadata(ast, offset);
constructor(ast: ast.BreakStatement) {
const metadata = getNodeMetadata(ast);

this.comments = metadata.comments;
this.loc = metadata.loc;
Expand Down
13 changes: 3 additions & 10 deletions src/slang-nodes/CallOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,10 @@ export class CallOptions implements SlangNode {

separators: string[];

constructor(
ast: ast.CallOptions,
offset: number,
options: ParserOptions<AstNode>
) {
let metadata = getNodeMetadata(ast, offset, true);
const { offsets } = metadata;
constructor(ast: ast.CallOptions, options: ParserOptions<AstNode>) {
let metadata = getNodeMetadata(ast, true);

this.items = ast.items.map(
(item, index) => new NamedArgument(item, offsets[index], options)
);
this.items = ast.items.map((item) => new NamedArgument(item, options));
this.separators = ast.separators.map((separator) => separator.unparse());

metadata = updateMetadata(metadata, [this.items]);
Expand Down
Loading

0 comments on commit 4c15c9b

Please sign in to comment.