Skip to content

Commit

Permalink
Properly export the enums for Language and ReturnType
Browse files Browse the repository at this point in the history
  • Loading branch information
DrRataplan authored Jul 9, 2021
1 parent 7dc9846 commit 703dcd9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 31 deletions.
73 changes: 42 additions & 31 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@ const skipClosureBuild = process.env.npm_config_skip_closure;

const tscc = require('@tscc/tscc').default;
function doPegJsBuild() {
return new Promise((resolve, reject) =>
fs.readFile('./src/parsing/xpath.pegjs', 'utf8', (err, file) =>
err ? reject(err) : resolve(file)
return (
new Promise((resolve, reject) =>
fs.readFile('./src/parsing/xpath.pegjs', 'utf8', (err, file) =>
err ? reject(err) : resolve(file)
)
)
)
.then((pegJsString) =>
peg.generate(pegJsString, {
cache: true,
output: 'source',
format: 'globals',
exportVar: 'xPathParser',
})
)
// Note the ts-nocheck, the output of pegJs is not valid TypeScript. The tslint-disable disables
// linter errors. Also, don't measure code coverage on this file. It is generated.
.then((parserString) => `// @ts-nocheck
.then((pegJsString) =>
peg.generate(pegJsString, {
cache: true,
output: 'source',
format: 'globals',
exportVar: 'xPathParser',
})
)
// Note the ts-nocheck, the output of pegJs is not valid TypeScript. The tslint-disable disables
// linter errors. Also, don't measure code coverage on this file. It is generated.
.then(
(parserString) => `// @ts-nocheck
/* tslint:disable */
/* istanbul ignore file */
Expand All @@ -42,19 +44,24 @@ declare interface pegjs_internal {
export default function(globalThis) {
(function() {
${parserString.replace('var DESCRIBE_EXPECTATION_FNS = ', 'var DESCRIBE_EXPECTATION_FNS: pegjs_internal = ')}
${parserString.replace(
'var DESCRIBE_EXPECTATION_FNS = ',
'var DESCRIBE_EXPECTATION_FNS: pegjs_internal = '
)}
}).call(globalThis);
};`)
.then((parserString) =>
Promise.all([
new Promise((resolve, reject) =>
fs.writeFile('./src/parsing/xPathParser_raw.ts', parserString, (err) =>
err ? reject(err) : resolve()
)
),
])
)
.then(() => console.info('Parser generator done'));
};`
)
.then((parserString) =>
Promise.all([
new Promise((resolve, reject) =>
fs.writeFile('./src/parsing/xPathParser_raw.ts', parserString, (err) =>
err ? reject(err) : resolve()
)
),
])
)
.then(() => console.info('Parser generator done'))
);
}

function outputDeclarations() {
Expand Down Expand Up @@ -114,18 +121,22 @@ function doModuleBuild() {
const api = JSON.parse(fs.readFileSync('dist/fontoxpath.api.json', 'utf-8'));
const fontoxpathAPI = api.members.find((member) => member.kind === 'EntryPoint');
const members = fontoxpathAPI.members.filter(
(member) => member.kind === 'Function' || member.kind === 'Variable'
(member) =>
member.kind === 'Function' || member.kind === 'Variable' || member.kind === 'Enum'
);

const exports = members.map(
(member) => `export const ${member.name} = fontoxpath.${member.name};`
// Some part of the compiler is aliasing types with a `_2` postfix. Fix them.
const memberNames = members.map(({ name }) =>
name.endsWith('_2') ? name.substring(0, name.length - 2) : name
);

const exports = memberNames.map((name) => `export const ${name} = fontoxpath.${name};`);

const fontoxpathFunction = fs.readFileSync('./dist/fontoxpath-raw.js', 'utf8');
const fullModule = `import * as xspattern from 'xspattern';
const fontoxpath = (${fontoxpathFunction})
.call(typeof window === 'undefined' ? undefined : window, xspattern);
${exports.join('\n')};
${exports.join('\n')}
export default fontoxpath;
`;

Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ if (typeof fontoxpathGlobal !== 'undefined') {
fontoxpathGlobal['parseScript'] = parseScript;
fontoxpathGlobal['profiler'] = profiler;
fontoxpathGlobal['createTypedValueFactory'] = internalCreateTypedValueFactory;

// The two enums
fontoxpathGlobal['Language'] = Language;
fontoxpathGlobal['ReturnType'] = ReturnType;
}

/**
Expand Down

0 comments on commit 703dcd9

Please sign in to comment.