tools: fix tools/addon-verify.js · nodejs/node@ca61f3b

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) {