Skip to content

Add ToC & max clause depth to provide flexibility - #663

Open
gesa wants to merge 9 commits into
tc39:mainfrom
gesa:ToC-option
Open

gesa wants to merge 9 commits into
tc39:mainfrom
gesa:ToC-option

Conversation

@gesa

@gesa gesa commented Nov 13, 2025

Copy link
Copy Markdown
Member

Ecma house style is a ToC 3 deep and max clauses 6, but there may be scenarios where a TC wants to generate a draft with fewer or more in the context of their specific standard

Comment thread src/clauseNums.ts Outdated
Comment thread src/clauseNums.ts Outdated
@gesa
gesa requested a review from michaelficarra November 14, 2025 06:36
Comment thread spec/index.html Outdated
@gesa

gesa commented Nov 17, 2025

Copy link
Copy Markdown
Member Author

I received clarification on conflicting direction from the secretariat. The maximum total clause depth is 5 (1.2.3.4.5), not 5 subdivisions. I have updated the PR in 7c88604

Comment thread spec/index.html Outdated
Comment thread src/args.ts Outdated
@gesa
gesa force-pushed the ToC-option branch 2 times, most recently from 6c69669 to ce060f4 Compare September 19, 2026 10:55
gesa and others added 6 commits September 19, 2026 13:01
Ecma house style is a ToC 3 deep and max clauses 6, but there may be scenarios where a TC wants to generate a draft with fewer or more in the context of their specific standard
Ecma house style is a ToC 3 deep and max clauses 6, but there may be scenarios where a TC wants to generate a draft with fewer or more in the context of their specific standard
thanks Michael

Co-authored-by: Michael Ficarra <github@michael.ficarra.me>

@gibson042 gibson042 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it intentional to introduce errors when building the ECMA-262 draft?

Comment thread src/clauseNums.ts Outdated
Comment on lines +13 to +14
// Ecma house style calls for a maximum of 5 clause levels
const MAX_LEVELS = spec.opts.maxClauseDepth ? spec.opts.maxClauseDepth || Infinity : 5;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Defaulting to 5 results in errors when building ECMA-262... I'd rather keep the infinite default and encode this default in build scripts.

Suggested change
// Ecma house style calls for a maximum of 5 clause levels
const MAX_LEVELS = spec.opts.maxClauseDepth ? spec.opts.maxClauseDepth || Infinity : 5;
const MAX_LEVELS = spec.opts.maxClauseDepth || Infinity;

Comment thread src/args.ts
type: Number,
description:
'The maximum nesting depth for clauses; exceeding this will cause a warning. Defaults to no limit.',
'The maximum nesting depth for clauses; exceeding this will cause a warning. Defaults to five (per Ecma house style.)',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
'The maximum nesting depth for clauses; exceeding this will cause a warning. Defaults to five (per Ecma house style.)',
'The maximum nesting depth for clauses; exceeding this will cause a warning. Defaults to no limit; Ecma house style is 5.',

Comment thread spec/index.html Outdated
Comment thread src/cli.ts Outdated
if (args['max-clause-depth']) {
opts.maxClauseDepth = args['max-clause-depth'];
}
if (args['printed-toc-depth']) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

CLI --max-clause-depth=0 results in args['printed-toc-depth'] being the number 0, which is falsy but presumably should still be propagated.

Suggested change
if (args['printed-toc-depth']) {
if (args['printed-toc-depth'] != null) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should it just be required to be positive if provided?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It could be, but I find your argument for interpreting --max-clause-depth=0 as "no limit" to be persuasive.

@gesa

gesa commented Sep 22, 2026

Copy link
Copy Markdown
Member Author

Is it intentional to introduce errors when building the ECMA-262 draft?

@gibson042 Yes and no. Ecma house style limits clause depth to 5. ECMA-262's clauses exceed that. It's fine, in that we'll leave ECMA-262 specifically like that after 17 editions. spec.html can add maxClauseDepth: 6 (or even maxClauseDepth: 0, but I have a strong preference for the former) to its metadata. But any other standards that TC39 publishes which don't already have the legacy baggage should stick to the house style, and ECMA-262 should avoid subclauses any deeper than it already has.

As far as defaults go, I'm a fan of 0 == Infinity, unset == 5 for clause depth, unset == 3 for ToC depth. Also < 0 setting for ToC just omits it altogether.

@gibson042 gibson042 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[ECMA-262] spec.html can add maxClauseDepth: 6 (or even maxClauseDepth: 0, but I have a strong preference for the former) to its metadata. But any other standards that TC39 publishes which don't already have the legacy baggage should stick to the house style, and ECMA-262 should avoid subclauses any deeper than it already has.

Thanks, that clarifies expectations for how to continue running ecmarkup with --strict in ECMA-262.

This PR looks fine to me after fixing cli.ts.

Comment thread src/cli.ts Outdated
Co-authored-by: Richard Gibson <richard.gibson@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants