Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions check_acorn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const acorn = require('acorn');
const fs = require('fs');
const src = fs.readFileSync('tests/integration/auth-jwt-validation.test.ts', 'utf8');

// Strip TypeScript-specific syntax for acorn
// Let's try parsing with allowReturnOutsideFunction and other options
try {
const ast = acorn.parse(src, {
ecmaVersion: 2022,
sourceType: 'module',
allowReturnOutsideFunction: true,
allowImportExportEverywhere: true,
allowAwaitOutsideFunction: true,
allowSuperOutsideMethod: true,
locations: true,
});
console.log('Parse OK');
} catch (e) {
console.log('Parse error: ' + e.message);
console.log('At line ' + e.loc?.line + ' col ' + e.loc?.column);
}
27 changes: 27 additions & 0 deletions check_ast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const ts = require('typescript');
const fs = require('fs');
const src = fs.readFileSync('tests/integration/auth-jwt-validation.test.ts', 'utf8');

// Parse the source file with error recovery (scanning for syntax errors)
const sourceFile = ts.createSourceFile(
'test.ts',
src,
ts.ScriptTarget.ES2022,
/*setParentNodes*/ false,
ts.ScriptKind.TS
);

// Get diagnostics from the source file's parse
const parseDiagnostics = sourceFile.parseDiagnostics || [];
console.log('Parse diagnostics:', parseDiagnostics.length);
parseDiagnostics.forEach(d => {
const pos = sourceFile.getLineAndCharacterOfPosition(d.start);
console.log(' Line', pos.line + 1, 'col', pos.character + 1 + ':', ts.flattenDiagnosticMessageText(d.messageText, '\n'));
});

// Check the last token
const lastToken = ts.getLastToken(sourceFile);
console.log('\nLast token kind:', ts.SyntaxKind[lastToken.kind], 'at pos', lastToken.getStart());
const lines = src.split('\n');
console.log('Lines in file:', lines.length);
console.log('Last line:', JSON.stringify(lines[lines.length - 1]));
49 changes: 49 additions & 0 deletions check_ast2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const ts = require('typescript');
const fs = require('fs');

const filePath = 'tests/integration/auth-jwt-validation.test.ts';
const src = fs.readFileSync(filePath, 'utf8');

// Create program with minimal options
const options = {
target: ts.ScriptTarget.ES2022,
module: ts.ModuleKind.CommonJS,
strict: true,
esModuleInterop: true,
skipLibCheck: true,
experimentalDecorators: true,
emitDecoratorMetadata: true,
moduleResolution: ts.ModuleResolutionKind.NodeJs,
baseUrl: '.',
paths: { '@/*': ['src/*'] },
types: ['node', 'express', 'jest'],
noEmit: true,
};

const program = ts.createProgram([filePath], options);
const sourceFile = program.getSourceFile(filePath);

if (sourceFile) {
// Only syntax diagnostics (from parseDiagnostics)
console.log('=== Source file parse diagnostics ===');
const parseDiags = sourceFile.parseDiagnostics;
if (parseDiags && parseDiags.length > 0) {
parseDiags.forEach(d => {
const pos = sourceFile.getLineAndCharacterOfPosition(d.start);
const cat = ts.DiagnosticCategory[d.category];
console.log(' [' + cat + '] Line ' + (pos.line + 1) + ' col ' + (pos.character + 1) + ': ' + ts.flattenDiagnosticMessageText(d.messageText, '\n'));
});
} else {
console.log(' No parse diagnostics');
}

// Full diagnostics from program
console.log('\n=== Program diagnostics ===');
const allDiags = ts.getPreEmitDiagnostics(program, sourceFile);
allDiags.forEach(d => {
const pos = sourceFile.getLineAndCharacterOfPosition(d.start);
const cat = ts.DiagnosticCategory[d.category];
console.log(' [' + cat + '] Line ' + (pos.line + 1) + ' col ' + (pos.character + 1) + ': ' + ts.flattenDiagnosticMessageText(d.messageText, '\n'));
});
console.log('Total diagnostics:', allDiags.length);
}
32 changes: 32 additions & 0 deletions check_ast3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const ts = require('typescript');
const fs = require('fs');
const src = fs.readFileSync('tests/integration/auth-jwt-validation.test.ts', 'utf8');

// Parse without error recovery
const sourceFile = ts.createSourceFile('test.ts', src, ts.ScriptTarget.ES2022, false, ts.ScriptKind.TS);

// Walk the AST and track describe/it blocks
function walk(node, depth) {
if (ts.isExpressionStatement(node)) {
// Check if it's a describe() or it() call
if (ts.isCallExpression(node.expression)) {
const callee = node.expression.expression;
if (callee && ts.isIdentifier(callee)) {
const name = callee.text;
if (name === 'describe' || name === 'it' || name === 'it' || name === 'it.each') {
// Check if the callback has balanced braces
const args = node.expression.arguments;
if (args.length > 0 && ts.isArrowFunction(args[args.length - 1])) {
const arrow = args[args.length - 1];
if (arrow.body && ts.isBlock(arrow.body)) {
console.log(name + ' at pos ' + node.getStart() + ' end: ' + node.getEnd() + ' (body span: ' + arrow.body.getStart() + '-' + arrow.body.getEnd() + ')');
}
}
}
}
}
}
ts.forEachChild(node, child => walk(child, depth + 1));
}

walk(sourceFile, 0);
58 changes: 58 additions & 0 deletions check_braces.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const ts = require('typescript');
const fs = require('fs');
const src = fs.readFileSync('tests/integration/auth-jwt-validation.test.ts', 'utf8');

const sourceFile = ts.createSourceFile('test.ts', src, ts.ScriptTarget.ES2022, true, ts.ScriptKind.TS);
const scanner = ts.createScanner(ts.ScriptTarget.ES2022, false, ts.LanguageVariant.Standard, src);

let token;
let inTemplateExpr = false;
let realOpen = 0;
let realClose = 0;
let fakeClose = 0;
let openStack = [];
let closeStack = [];

while ((token = scanner.scan()) !== ts.SyntaxKind.EndOfFileToken) {
const pos = scanner.getStartPos();
const lineInfo = sourceFile.getLineAndCharacterOfPosition(pos);
const line = lineInfo.line + 1;
const col = lineInfo.character + 1;
const lines = src.split('\n');
const ctx = lines[line - 1]?.substring(col - 1, col + 20).replace(/\n/g, '');

if (!inTemplateExpr) {
if (token === ts.SyntaxKind.OpenBraceToken) {
realOpen++;
openStack.push({ line, col, ctx });
}
if (token === ts.SyntaxKind.CloseBraceToken) {
realClose++;
if (openStack.length > 0) {
closeStack.push({ line, col, matched: openStack.pop(), ctx });
} else {
console.log('EXTRA } at line ' + line + ' col ' + col + ' context: ' + ctx);
}
}
if (token === ts.SyntaxKind.TemplateHead || token === ts.SyntaxKind.TemplateMiddle) {
inTemplateExpr = true;
}
} else {
if (token === ts.SyntaxKind.CloseBraceToken) {
fakeClose++;
inTemplateExpr = false;
}
}
}

console.log('Real OpenBraceToken:', realOpen);
console.log('Real CloseBraceToken:', realClose);
console.log('Template CloseBrace (fake):', fakeClose);
console.log('Net unclosed (real):', realOpen - realClose);
console.log('Unclosed braces:', openStack.length);
if (openStack.length > 0) {
console.log('Unclosed brace locations:');
openStack.forEach(u => {
console.log(' line ' + u.line + ' col ' + u.col + ' context: ' + u.ctx);
});
}
57 changes: 57 additions & 0 deletions check_braces2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const ts = require('typescript');
const fs = require('fs');
const src = fs.readFileSync('tests/integration/auth-jwt-validation.test.ts', 'utf8');

const sourceFile = ts.createSourceFile('test.ts', src, ts.ScriptTarget.ES2022, true, ts.ScriptKind.TS);
const scanner = ts.createScanner(ts.ScriptTarget.ES2022, false, ts.LanguageVariant.Standard, src);

let token;
let stack = []; // stack of {line, col, kind: 'brace'|'template'}
let inTemplate = false;

// Track template expression depth
let templateExprDepth = 0;

while ((token = scanner.scan()) !== ts.SyntaxKind.EndOfFileToken) {
const pos = scanner.getStartPos();
const lineInfo = sourceFile.getLineAndCharacterOfPosition(pos);
const line = lineInfo.line + 1;
const col = lineInfo.character + 1;
const lines = src.split('\n');
const ctx = (lines[line-1] || '').substring(col-1, col+20);

if (inTemplate) {
// Inside template expression (${...})
if (token === ts.SyntaxKind.CloseBraceToken) {
// This } closes the template expression
inTemplate = false;
}
// Other tokens inside template expression are part of the expression - ignore
continue;
}

// Check if this starts a template literal with substitution
if (token === ts.SyntaxKind.TemplateHead || token === ts.SyntaxKind.TemplateMiddle) {
// TemplateHead/TemplateMiddle is followed by ${ - the scanner will produce
// expression tokens next, then a CloseBraceToken for the }
inTemplate = true;
continue;
}

// Not in template expression - count braces normally
if (token === ts.SyntaxKind.OpenBraceToken) {
stack.push({ line, col, ctx });
}
if (token === ts.SyntaxKind.CloseBraceToken) {
if (stack.length > 0) {
stack.pop();
} else {
console.log('EXTRA } at line ' + line + ' col ' + col + ' ctx: ' + ctx);
}
}
}

console.log('\nUnclosed braces: ' + stack.length);
stack.forEach(s => {
console.log(' line ' + s.line + ' col ' + s.col + ' ctx: ' + s.ctx);
});
48 changes: 48 additions & 0 deletions check_braces3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const ts = require('typescript');
const fs = require('fs');
const src = fs.readFileSync('tests/integration/auth-jwt-validation.test.ts', 'utf8');
const sourceFile = ts.createSourceFile('test.ts', src, ts.ScriptTarget.ES2022, true, ts.ScriptKind.TS);
const scanner = ts.createScanner(ts.ScriptTarget.ES2022, false, ts.LanguageVariant.Standard, src);

let token;
let stack = [];
let inTemplate = false;
const lines = src.split('\n');

while ((token = scanner.scan()) !== ts.SyntaxKind.EndOfFileToken) {
const pos = scanner.getStartPos();
const lineInfo = sourceFile.getLineAndCharacterOfPosition(pos);
const lineNum = lineInfo.line + 1;
const col = lineInfo.character + 1;
const ctx = (lines[lineNum-1] || '').substring(col-1, col+30);

if (inTemplate) {
if (token === ts.SyntaxKind.CloseBraceToken) {
inTemplate = false;
}
continue;
}

if (token === ts.SyntaxKind.TemplateHead || token === ts.SyntaxKind.TemplateMiddle) {
inTemplate = true;
continue;
}

if (token === ts.SyntaxKind.OpenBraceToken) {
stack.push({ line: lineNum, col, ctx });
}
if (token === ts.SyntaxKind.CloseBraceToken) {
if (stack.length > 0) {
const opened = stack.pop();
// Only show braces opened at depth 0-2 (top-level structures)
if (stack.length <= 2) {
console.log(' CLOSE line ' + lineNum + ' (closed { from line ' + opened.line + ') stack depth now: ' + stack.length);
}
} else {
console.log('EXTRA } at line ' + lineNum + ' ctx: ' + ctx);
}
}
}

console.log('\nUnclosed:', stack.length);
stack.forEach(s => console.log(' line ' + s.line));
39 changes: 39 additions & 0 deletions check_templates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const ts = require('typescript');
const fs = require('fs');
const src = fs.readFileSync('tests/integration/auth-jwt-validation.test.ts', 'utf8');
const sourceFile = ts.createSourceFile('test.ts', src, ts.ScriptTarget.ES2022, true, ts.ScriptKind.TS);
const scanner = ts.createScanner(ts.ScriptTarget.ES2022, false, ts.LanguageVariant.Standard, src);
let token;
let inTemplate = false;
const lines = src.split('\n');

while ((token = scanner.scan()) !== ts.SyntaxKind.EndOfFileToken) {
const pos = scanner.getStartPos();
const li = sourceFile.getLineAndCharacterOfPosition(pos);
const lineNum = li.line + 1;
const col = li.character + 1;
const ctx = (lines[lineNum-1] || '').substring(col-1, col+30);

// Print template-related tokens
if (token === ts.SyntaxKind.TemplateHead) {
console.log('TemplateHead L' + lineNum + ' val: "' + scanner.getTokenValue() + '"');
inTemplate = true;
} else if (token === ts.SyntaxKind.TemplateMiddle) {
console.log('TemplateMiddle L' + lineNum + ' val: "' + scanner.getTokenValue() + '"');
inTemplate = true;
} else if (token === ts.SyntaxKind.CloseBraceToken) {
if (inTemplate) {
console.log('CLOSE_BRACE (template) L' + lineNum);
inTemplate = false;
}
}
if (token === ts.SyntaxKind.TemplateTail) {
console.log('TemplateTail L' + lineNum + ' val: "' + scanner.getTokenValue() + '"');
inTemplate = false;
}
if (token === ts.SyntaxKind.NoSubstitutionTemplateLiteral) {
console.log('NoSubstitutionTemplate L' + lineNum + ' val: "' + scanner.getTokenValue() + '"');
}
}

console.log('\nTemplate tracking complete');
22 changes: 22 additions & 0 deletions check_tokens.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const ts = require('typescript');
const fs = require('fs');
const src = fs.readFileSync('tests/integration/auth-jwt-validation.test.ts', 'utf8');
const sourceFile = ts.createSourceFile('test.ts', src, ts.ScriptTarget.ES2022, true, ts.ScriptKind.TS);
const scanner = ts.createScanner(ts.ScriptTarget.ES2022, false, ts.LanguageVariant.Standard, src);
const lines = src.split('\n');

let token;
let lineNum = 0;

while ((token = scanner.scan()) !== ts.SyntaxKind.EndOfFileToken) {
const pos = scanner.getStartPos();
const li = sourceFile.getLineAndCharacterOfPosition(pos);
lineNum = li.line + 1;
const col = li.character + 1;

// Print tokens around lines 159 and 169
if (lineNum >= 159 && lineNum <= 172) {
const ctx = (lines[lineNum-1] || '').substring(col-1, col+40);
console.log('L' + lineNum + ':' + col + ' kind=' + token + '(' + ts.SyntaxKind[token] + ') val="' + scanner.getTokenValue() + '" ctx: ' + ctx.trim().substring(0, 60));
}
}
Loading