Skip to content

Parse static scriptName field #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"engines": {
"node": ">=18.0.0"
},
"version": "1.5.0",
"version": "1.5.1",
"dependencies": {
"@playcanvas/eslint-config": "^1.7.4 || ^2.0.0",
"@typescript/vfs": "^1.6.0",
Expand Down
17 changes: 17 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,26 @@ export class JSDocParser {

const esmScriptClass = pcTypes.statements.find(node => node.kind === ts.SyntaxKind.ClassDeclaration && node.name.text === 'Script')?.symbol;

const isScriptNameMember = member => (
ts.isPropertyDeclaration(member) && // Is a property declaration
ts.isIdentifier(member.name) &&
member.name.text === 'scriptName' &&
(ts.getCombinedModifierFlags(member) & ts.ModifierFlags.Static) !== 0 &&
ts.isStringLiteral(member.initializer)
);

// Check if the file exports a class that inherits from `Script`
nodes.forEach((node, name) => {
if (isAliasedClassDeclaration(node, typeChecker) && inheritsFrom(node, typeChecker, esmScriptClass)) {

// Check for a static scriptName property and use that as the name if it exists
const scriptNameMember = node.members.find(isScriptNameMember);

// If the scriptName property exists, use that as the name
if (scriptNameMember) {
name = scriptNameMember.initializer.text;
}

esmScripts.set(name, node);
}
});
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/program.valid.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Script } from 'playcanvas';
export const MyEnum = { value: 0 };

class Example extends Script {
static scriptName = 'customExample';

/**
* @attribute
* @precision 1
Expand Down
7 changes: 6 additions & 1 deletion test/tests/valid/program.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ describe('VALID: Program ', function () {
data = await parseAttributes('./program.valid.js');
});

it('should have a customExample script', function () {
expect(data[0].customExample).to.exist;
expect(data[0].customExample.errors).to.be.empty;
});

it('only results should exist', function () {
expect(data).to.exist;
expect(data[0]).to.not.be.empty;
expect(data[1]).to.be.empty;
expect(data[0].example.errors).to.be.empty;
expect(data[0].customExample.errors).to.be.empty;
});
});