Skip to content

Commit ca61f3b

Browse files
danbevMylesBorins
authored andcommitted
tools: fix tools/addon-verify.js
The current implementation of addon-verify.js is including the code for the "Function arguments" section in test/addons/01_callbacks and there is no directory generated or the "Function arguments section". This continues and leads to the last section, "AtExit", code to be excluded. There is an test/addons/07_atexit_hooks but it contains code from the "Passing wrapped objects around" section. This commit modifies addon-verify to associate headers with code and then iterates over the set and generates the files as a separate step. PR-URL: #14048 Reviewed-By: Michaël Zasso <[email protected]>
1 parent b5904a2 commit ca61f3b

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

doc/api/addons.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ Test in JavaScript by running:
11041104
11051105
```js
11061106
// test.js
1107-
const addon = require('./build/Release/addon');
1107+
require('./build/Release/addon');
11081108
```
11091109

11101110
[bindings]: https://github.com/TooTallNate/node-bindings

tools/doc/addon-verify.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,29 @@ const verifyDir = path.resolve(rootDir, 'test', 'addons');
1111
const contents = fs.readFileSync(doc).toString();
1212

1313
const tokens = marked.lexer(contents);
14-
let files = null;
1514
let id = 0;
1615

17-
// Just to make sure that all examples will be processed
18-
tokens.push({ type: 'heading' });
19-
20-
for (var i = 0; i < tokens.length; i++) {
21-
var token = tokens[i];
16+
let currentHeader;
17+
const addons = {};
18+
tokens.forEach((token) => {
2219
if (token.type === 'heading' && token.text) {
23-
const blockName = token.text;
24-
if (files && Object.keys(files).length !== 0) {
25-
verifyFiles(files,
26-
blockName,
27-
console.log.bind(null, 'wrote'),
28-
function(err) { if (err) throw err; });
29-
}
30-
files = {};
31-
} else if (token.type === 'code') {
20+
currentHeader = token.text;
21+
addons[currentHeader] = {
22+
files: {}
23+
};
24+
}
25+
if (token.type === 'code') {
3226
var match = token.text.match(/^\/\/\s+(.*\.(?:cc|h|js))[\r\n]/);
33-
if (match === null)
34-
continue;
35-
files[match[1]] = token.text;
27+
if (match !== null) {
28+
addons[currentHeader].files[match[1]] = token.text;
29+
}
3630
}
31+
});
32+
for (var header in addons) {
33+
verifyFiles(addons[header].files,
34+
header,
35+
console.log.bind(null, 'wrote'),
36+
function(err) { if (err) throw err; });
3737
}
3838

3939
function once(fn) {

0 commit comments

Comments
 (0)