Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const EXTERNALS = [
export const LEGACY_IMPORTS = [];
export const LEGACY_BINDINGS = [
'var yy = alasql.yy;',
'var schemaChanged = alasql.private.schemaChanged;',
'var schemaChanged = internal.schemaChanged;',
'var utils = alasql.utils;',
...[
'cloneDeep',
Expand All @@ -92,10 +92,10 @@ export const LEGACY_BINDINGS = [
].map(n => `var ${n} = utils.${n};`),
'var escapeqq = utils.undoubleq;',
'var loadFile = utils.loadFile;',
'var returnTrue = alasql.private.returnTrue;',
'var n2u = alasql.private.n2u;',
'var und = alasql.private.und;',
'var getXLSX = alasql.private.getXLSX;',
'var returnTrue = internal.returnTrue;',
'var n2u = internal.n2u;',
'var und = internal.und;',
'var getXLSX = internal.getXLSX;',
'var Query = alasql.Query;',
'var queryfn = internal.queryfn;',
];
Expand Down
4 changes: 2 additions & 2 deletions src/engine/core.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import makeParser from '../generated/parser.js';

export default function install(alasql) {
export default function install(alasql, internal) {
var alasqlparser = makeParser(alasql);
/**
Database class for Alasql.js
Expand Down Expand Up @@ -539,5 +539,5 @@ alasql.compile = function (sql, databaseid) {
return statement;
};

alasql.private.schemaChanged = schemaChanged;
internal.schemaChanged = schemaChanged;
}
8 changes: 4 additions & 4 deletions src/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export var deepEqual = function (x, y) {
return false;
};

export default function install(alasql) {
export default function install(alasql, internal) {
/*jshint unused:false*/
/*
Utilities for Alasql.js
Expand Down Expand Up @@ -692,9 +692,9 @@ utils.typeConverter = function (value, dbtypeid) {
return value;
};

alasql.private.returnTrue = returnTrue;
internal.returnTrue = returnTrue;

alasql.private.n2u = n2u;
internal.n2u = n2u;

alasql.private.und = und;
internal.und = und;
}
4 changes: 2 additions & 2 deletions src/utils/xlsx.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function install(alasql) {
export default function install(alasql, internal) {
var utils = alasql.utils;
/*
The XLSX loader: the SheetJS library found or handed in, split from src/15utility.js (docs/src-map.md). Same functions, same bodies.
Expand All @@ -25,5 +25,5 @@ var getXLSX = function () {
return XLSX;
};

alasql.private.getXLSX = getXLSX;
internal.getXLSX = getXLSX;
}
5 changes: 0 additions & 5 deletions test/parity/api-allowed.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
# compare.js reports them as allowed instead of failing; a path covers its prototype and
# constructor. Everything the conversion adds to the alasql object on purpose goes here, so
# that the API snapshot keeps catching what was not on purpose.
alasql.private.schemaChanged # step 2: the legacy files reach schemaChanged, declared in src/engine/core.js, through alasql.private (context/roadmap-phase-1.md, step 4 settles the general mechanism)
alasql.private.returnTrue # step 3: pure helpers of src/utils/helpers.js that legacy files call by bare name and that were never on alasql.utils
alasql.private.n2u # step 3: as above (nanToUndefined)
alasql.private.und # step 3: as above (undefinedOrValue)
alasql.private.getXLSX # step 3: the XLSX loader of src/utils/xlsx.js, called by bare name from 833xlsx.js and 84from.js
alasql.utils.hash # step 4: the stateless helpers are exports of src/utils/helpers.js now; as exports they have a .name, before they had none (a function assigned to utils.x has no inferred name)
alasql.utils.deepEqual # step 4: as above
alasql.utils.arrayUnionDeep # step 4: as above
Expand Down
24 changes: 11 additions & 13 deletions tools/wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
The codemod that turns a moved numbered file into an ES module with install(alasql)
(context/roadmap-phase-1.md, "Wrap with a codemod, not by hand").

bun tools/wrap.js <file in src/...> [--create] [--private name ...] [--internal name ...]
bun tools/wrap.js <file in src/...> [--create] [--internal name ...]
[--bind name=expr ...] [--import "<import line>" ...] [--forward name=path ...] [--write]

The file has been moved with git mv already (its own commit); this writes the wrap, which is
Expand All @@ -18,13 +18,14 @@
- for alasqlparser: the module that sets alasql.parser imports the generated parser wrapper
and makes the parser for this alasql object; every other module reads alasql.parser;
- the wrapper, export default function install(alasql) { ... };
- for every name the file declares and the legacy files still use, a line that puts it on
alasql.private (--private name, each named on purpose);
- for every name the file declares and other modules or the legacy files use, a line that
puts it on internal, the second install parameter (--internal name, each named on purpose);
internals never go on the alasql object;
- for a name that exists only after this module is installed (saveAs, set by the legacy
module), a forwarder (--forward name=alasql.utils.name) the body calls later;
- --internal name puts a name on the second install parameter instead of alasql.private, and
the wrapper becomes install(alasql, internal); --bind name=expr writes any binding
(var name = expr), --import writes an import line and counts its names as provided.
- with --internal or a bind from internal the wrapper is install(alasql, internal);
--bind name=expr writes any binding (var name = expr), --import writes an import line and
counts its names as provided.

--create is for the head file: the UMD head is cut, the wrapper is export function create()
returning alasql, and the fluent-interface branch reads yy through alasql.yy, because the
Expand All @@ -43,14 +44,12 @@ const args = process.argv.slice(2);
const file = args.find(a => !a.startsWith('--') && !isOption(args, a));
const create = args.includes('--create');
const write = args.includes('--write');
const privates = [];
const internals = [];
const forwards = [];
const binds = [];
const importLines = [];
const VALUED = ['--private', '--internal', '--forward', '--bind', '--import'];
const VALUED = ['--internal', '--forward', '--bind', '--import'];
for (let i = 0; i < args.length; i++) {
if (args[i] === '--private') privates.push(args[i + 1]);
if (args[i] === '--internal') internals.push(args[i + 1]);
if (args[i] === '--forward') forwards.push(args[i + 1].split('='));
if (args[i] === '--bind') binds.push(args[i + 1].split(/=(.*)/s).slice(0, 2));
Expand All @@ -74,7 +73,7 @@ function isOption(list, a) {

if (!file) {
console.error(
'usage: wrap.js <file> [--create] [--private name ...] [--forward name=path ...] [--write]'
'usage: wrap.js <file> [--create] [--internal name ...] [--bind name=expr ...] [--import line ...] [--forward name=path ...] [--write]'
);
process.exit(2);
}
Expand All @@ -98,7 +97,7 @@ const bindings = [];
for (const n of names) {
if (n === 'alasql' || n === 'internal' || forwards.some(([f]) => f === n) || provided.has(n))
continue;
if (n === 'schemaChanged') bindings.push('var schemaChanged = alasql.private.schemaChanged;');
if (n === 'schemaChanged') bindings.push('var schemaChanged = internal.schemaChanged;');
else if (n === 'alasqlparser') {
// The grammar reads alasql.options, alasql.fn and alasql.aggr, so the parser is made
// for the alasql object (src/generated/parser.js). The module that sets alasql.parser
Expand Down Expand Up @@ -140,15 +139,14 @@ if (create) {
)
.join('') +
text.replace(/\s*$/, '\n') +
privates.map(p => `\n\talasql.private.${p} = ${p};\n`).join('') +
internals.map(p => `\n\tinternal.${p} = ${p};\n`).join('') +
'}\n';
}

if (write) {
fs.writeFileSync(abs, out);
console.log(
`wrote ${file}: ${imports.length} imports, ${bindings.length} bindings, ${privates.length} on alasql.private`
`wrote ${file}: ${imports.length} imports, ${bindings.length} bindings, ${internals.length} on internal`
);
} else {
process.stdout.write(out);
Expand Down
Loading