Skip to content
Closed
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
37 changes: 37 additions & 0 deletions src/parser/tokenizers/name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,43 @@ export default function nameTokenizer(): Tokenizer {
});
return spec;
}
} else {
const parts = name.split('=');
if (parts.length > 1) {
name = parts[0].trim();
defaultValue = parts.slice(1).join('=').trim();

if (name === '') {
spec.problems.push({
code: 'spec:name:empty-name',
message: 'empty name',
line: spec.source[0].number,
critical: true,
});
return spec;
}

if (defaultValue === '') {
spec.problems.push({
code: 'spec:name:empty-default',
message: 'empty default value',
line: spec.source[0].number,
critical: true,
});
return spec;
}

// has "=" and is not a string, except for "=>"
if (!isQuoted(defaultValue) && /=(?!>)/.test(defaultValue)) {
spec.problems.push({
code: 'spec:name:invalid-default',
message: 'invalid default value syntax',
line: spec.source[0].number,
critical: true,
});
return spec;
}
}
Comment on lines +114 to +150
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-optional default parsing diverges from the optional [name=value] path: it doesn’t trim around = and it skips the spec:name:invalid-default validation (e.g. name=value=value would now be accepted unbracketed but rejected when bracketed). Consider reusing the same split/join/trim + invalid-default check logic for both branches so defaults behave consistently.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already addressed in 786bf5f — the non-optional path now uses the same split/join/trim approach and spec:name:invalid-default check as the optional path.

}

spec.optional = optional;
Expand Down
30 changes: 30 additions & 0 deletions tests/e2e/issue-186.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const { parse } = require('../../lib/index.cjs');

test('non-optional property with default value', () => {
const parsed = parse(`
/**
* Some annoying set of bitmasks or something.
*
* @property {number} BITMASK_VALUE_A=16 - blah blah
* @property {number} BITMASK_VALUE_B=32 - the other thing
*/`);

expect(parsed[0].tags).toMatchObject([
{
tag: 'property',
type: 'number',
name: 'BITMASK_VALUE_A',
optional: false,
default: '16',
description: '- blah blah',
},
{
tag: 'property',
type: 'number',
name: 'BITMASK_VALUE_B',
optional: false,
default: '32',
description: '- the other thing',
},
]);
});
146 changes: 146 additions & 0 deletions tests/unit/spec-name-tokenizer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,152 @@ test('empty', () => {
);
});

test('non-optional with default', () => {
expect(
tokenize(
seedSpec({
source: [
{
number: 1,
source: '...',
tokens: seedTokens({
description: 'param=value param description',
}),
},
],
})
)
).toEqual(
seedSpec({
name: 'param',
optional: false,
default: 'value',
source: [
{
number: 1,
source: '...',
tokens: seedTokens({
name: 'param=value',
postName: ' ',
description: 'param description',
}),
},
],
})
);
});

test('non-optional with numeric default', () => {
expect(
tokenize(
seedSpec({
source: [
{
number: 1,
source: '...',
tokens: seedTokens({
description: 'BITMASK_VALUE_A=16 blah blah',
}),
},
],
})
)
).toEqual(
seedSpec({
name: 'BITMASK_VALUE_A',
optional: false,
default: '16',
source: [
{
number: 1,
source: '...',
tokens: seedTokens({
name: 'BITMASK_VALUE_A=16',
postName: ' ',
description: 'blah blah',
}),
},
],
})
);
});
Comment on lines +623 to +691
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the new non-optional name=value behavior, it would be good to add a unit test covering the same invalid-default edge case that exists for optional names (e.g. param=value=value should surface spec:name:invalid-default if you align validation across both paths). This helps ensure the bracketed and unbracketed default syntaxes don’t drift over time.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 786bf5f. The non-optional name=value path now uses the same split/join/trim approach as the optional path and includes the spec:name:invalid-default validation (rejecting param=value=value). A matching unit test was also added.


test('non-optional with empty default', () => {
expect(
tokenize(
seedSpec({
source: [
{
number: 1,
source: '...',
tokens: seedTokens({
description: 'param= param description',
}),
},
],
})
)
).toEqual(
seedSpec({
problems: [
{
code: 'spec:name:empty-default',
line: 1,
critical: true,
message: 'empty default value',
},
],
source: [
{
number: 1,
source: '...',
tokens: seedTokens({
description: 'param= param description',
}),
},
],
})
);
});

test('non-optional with invalid default syntax', () => {
expect(
tokenize(
seedSpec({
source: [
{
number: 1,
source: '...',
tokens: seedTokens({
description: 'param=value=value param description',
}),
},
],
})
)
).toEqual(
seedSpec({
problems: [
{
code: 'spec:name:invalid-default',
line: 1,
critical: true,
message: 'invalid default value syntax',
},
],
source: [
{
number: 1,
source: '...',
tokens: seedTokens({
description: 'param=value=value param description',
}),
},
],
})
);
});

test('default value syntax', () => {
expect(
tokenize(
Expand Down
Loading