Skip to content

Commit

Permalink
Fix NumericLiteral raw field
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Mar 4, 2024
1 parent ac8ffe5 commit 7e5843a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion napi/parser/generate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ for (const [index, type] of types.entries()) {
type.name = type.name
.replace(/<(.)/g, (_, c) => c.toUpperCase())
.replace(/[>, ]/g, '')
.replace(/^&(.)/, (_, c) => `Ref${c.toUpperCase()}`)
.replace(/^(.)/, (_, c) => c.toUpperCase());
assert(!typesByName[type.name], `Repeated type name ${type.name}`);
typesByName[type.name] = type;
Expand Down Expand Up @@ -213,11 +214,20 @@ adaptTypeContainingAtom('JSXText', 'start', 'end');
adaptTypeForSpan(type);
addVarToPreamble(type, `flags = ${generateStructFieldCode(flagsField)}`);

regexField.code = `{pattern: source.slice(start + 1, end - flags.length - 1), flags}`
regexField.code = `{pattern: source.slice(start + 1, end - flags.length - 1), flags}`;
type.dependencies.delete(regexField.type);
type.dependencies.add(flagsField.type);
}

// NumericLiteral
{
const type = typesByName.NumericLiteral,
rawField = type.fields.find(field => field.name === 'raw');
adaptTypeForSpan(type);
rawField.code = `source.slice(start, end)`;
type.dependencies.delete(typesByName.RefStr);
}

// Generate deserializer
let code = '// Code generated by `generate/index.js`. Do not edit.\n\n'
+ fs.readFileSync(pathJoin(__dirname, 'base.js')) + '\n';
Expand Down

0 comments on commit 7e5843a

Please sign in to comment.