Current Dev State

This commit is contained in:
Tim Lorsbach
2025-06-23 20:13:54 +02:00
parent b4f9bb277d
commit ded50edaa2
22617 changed files with 4345095 additions and 174 deletions

18
static/js/ketcher2/node_modules/lexical-scope/LICENSE generated vendored Normal file
View File

@ -0,0 +1,18 @@
This software is released under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,15 @@
$ git log|head -n1
commit ae85dfd4cc0284679ce21bb662427340fa966666
$ time node run.js >/dev/null
real 0m6.551s
user 0m6.336s
sys 0m0.288s
$ git log|head -n1
commit 9125bf1ec0cf78c77a852e0547a4cc69db7797bf
$ time node run.js>/dev/null
real 0m1.702s
user 0m1.644s
sys 0m0.084s

7
static/js/ketcher2/node_modules/lexical-scope/bench/run.js generated vendored Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/env node
var detect = require('../');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/jquery.js');
var scope = detect(src);
console.dir(scope);

View File

@ -0,0 +1,6 @@
var detect = require('../');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/src.js');
var scope = detect(src);
console.log(JSON.stringify(scope,null,2));

View File

@ -0,0 +1,27 @@
var x = 5;
var y = 3, z = 2;
w.foo();
w = 2;
RAWR=444;
RAWR.foo();
BLARG=3;
foo(function () {
var BAR = 3;
process.nextTick(function (ZZZZZZZZZZZZ) {
console.log('beep boop');
var xyz = 4;
x += 10;
x.zzzzzz;
ZZZ=6;
});
function doom () {
}
ZZZ.foo();
});
console.log(xyz);

194
static/js/ketcher2/node_modules/lexical-scope/index.js generated vendored Normal file
View File

@ -0,0 +1,194 @@
var astw = require('astw');
module.exports = function (src) {
var locals = {};
var implicit = {};
var exported = {};
var implicitProps = {};
if (typeof src === 'string') {
src = String(src).replace(/^#![^\n]*\n/, '');
}
if (src && typeof src === 'object'
&& typeof src.copy === 'function' && typeof src.toString === 'function') {
src = src.toString('utf8');
}
var walk = astw(src);
walk(function (node) {
if (node.type === 'VariableDeclaration') {
// take off the leading `var `
var id = getScope(node);
for (var i = 0; i < node.declarations.length; i++) {
var d = node.declarations[i];
locals[id][d.id.name] = d;
}
}
else if (node.type === 'CatchClause') {
var id = getScope(node);
locals[id][node.param.name] = node.param
}
else if (isFunction(node)) {
var id = getScope(node.parent);
if (node.id) locals[id][node.id.name] = node;
var nid = node.params.length && getScope(node);
if (nid && !locals[nid]) locals[nid] = {};
for (var i = 0; i < node.params.length; i++) {
var p = node.params[i];
locals[nid][p.name] = p;
}
}
});
walk(function (node) {
if (node.type === 'Identifier'
&& lookup(node) === undefined) {
if (node.parent.type === 'Property'
&& node.parent.key === node) return;
if (node.parent.type === 'MemberExpression'
&& node.parent.property === node) return;
if (isFunction(node.parent)) return;
if (node.parent.type === 'LabeledStatement') return;
if (node.parent.type === 'ContinueStatement') return;
if (node.parent.type === 'BreakStatement') return;
if (node.parent.type === 'AssignmentExpression') {
var isLeft0 = node.parent.left.type === 'MemberExpression'
&& node.parent.left.object === node.name
;
var isLeft1 = node.parent.left.type === 'Identifier'
&& node.parent.left.name === node.name
;
if (isLeft0 || isLeft1) {
exported[node.name] = keyOf(node).length;
}
}
if (!exported[node.name]
|| exported[node.name] < keyOf(node).length) {
implicit[node.name] = keyOf(node).length;
if (!implicitProps[node.name]) implicitProps[node.name] = {};
if (node.parent && node.parent.type === 'MemberExpression'
&& node.parent.property.type === 'Identifier') {
implicitProps[node.name][node.parent.property.name] = true;
}
else if (node.parent && node.parent.type === 'CallExpression'
&& node.parent.callee === node) {
implicitProps[node.name]['()'] = true;
}
else {
implicitProps[node.name]['*'] = true;
}
}
}
});
var localScopes = {};
var lks = objectKeys(locals);
for (var i = 0; i < lks.length; i++) {
var key = lks[i];
localScopes[key] = objectKeys(locals[key]);
}
var props = {};
var pkeys = objectKeys(implicitProps);
for (var i = 0; i < pkeys.length; i++) {
props[pkeys[i]] = objectKeys(implicitProps[pkeys[i]]);
}
return {
locals: localScopes,
globals: {
implicit: objectKeys(implicit),
implicitProperties: props,
exported: objectKeys(exported)
}
};
function lookup (node) {
for (var p = node; p; p = p.parent) {
if (isFunction(p) || p.type === 'Program') {
var id = getScope(p);
if (locals[id][node.name]) {
return id;
}
}
}
return undefined;
}
function getScope (node) {
for (
var p = node;
!isFunction(p) && p.type !== 'Program';
p = p.parent
);
var id = idOf(p);
if (!locals[id]) locals[id] = {};
return id;
}
};
function isFunction (x) {
return x.type === 'FunctionDeclaration'
|| x.type === 'FunctionExpression'
;
}
function idOf (node) {
var id = [];
for (var n = node; n.type !== 'Program'; n = n.parent) {
var key = keyOf(n).join('.');
id.unshift(key);
}
return id.join('.');
}
function keyOf (node) {
if (node.lexicalScopeKey) return node.lexicalScopeKey;
var p = node.parent;
var ks = objectKeys(p);
var kv = { keys : [], values : [], top : [] };
for (var i = 0; i < ks.length; i++) {
var key = ks[i];
kv.keys.push(key);
kv.values.push(p[key]);
kv.top.push(undefined);
if (isArray(p[key])) {
var keys = objectKeys(p[key]);
kv.keys.push.apply(kv.keys, keys);
kv.values.push.apply(kv.values, p[key]);
var nkeys = [];
for (var j = 0; j < keys.length; j++) nkeys.push(key);
kv.top.push.apply(kv.top, nkeys);
}
}
var ix = indexOf(kv.values, node);
var res = [];
if (kv.top[ix]) res.push(kv.top[ix]);
if (kv.keys[ix]) res.push(kv.keys[ix]);
if (node.parent.type === 'CallExpression') {
res.unshift.apply(res, keyOf(node.parent.parent));
}
return node.lexicalScopeKey = res;
}
var isArray = Array.isArray || function (xs) {
return Object.prototype.toString.call(xs) === '[object Array]';
};
var objectKeys = Object.keys || function (obj) {
var keys = [];
for (var key in obj) keys.push(key);
return keys;
};
function indexOf (xs, x) {
if (xs.indexOf) return xs.indexOf(x);
for (var i = 0; i < xs.length; i++) {
if (x === xs[i]) return i;
}
return -1;
}

View File

@ -0,0 +1,83 @@
{
"_from": "lexical-scope@^1.2.0",
"_id": "lexical-scope@1.2.0",
"_inBundle": false,
"_integrity": "sha1-/Ope3HBKSzqHls3KQZw6CvryLfQ=",
"_location": "/lexical-scope",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "lexical-scope@^1.2.0",
"name": "lexical-scope",
"escapedName": "lexical-scope",
"rawSpec": "^1.2.0",
"saveSpec": null,
"fetchSpec": "^1.2.0"
},
"_requiredBy": [
"/insert-module-globals"
],
"_resolved": "https://registry.npmjs.org/lexical-scope/-/lexical-scope-1.2.0.tgz",
"_shasum": "fcea5edc704a4b3a8796cdca419c3a0afaf22df4",
"_spec": "lexical-scope@^1.2.0",
"_where": "/home/manfred/enviPath/ketcher2/ketcher/node_modules/insert-module-globals",
"author": {
"name": "James Halliday",
"email": "mail@substack.net",
"url": "http://substack.net"
},
"bugs": {
"url": "https://github.com/substack/lexical-scope/issues"
},
"bundleDependencies": false,
"dependencies": {
"astw": "^2.0.0"
},
"deprecated": false,
"description": "detect global and local lexical identifiers from javascript source code",
"devDependencies": {
"brfs": "~0.0.3",
"tape": "~2.4.1"
},
"homepage": "https://github.com/substack/lexical-scope",
"keywords": [
"ast",
"variable",
"name",
"lexical",
"local",
"global",
"implicit",
"exported"
],
"license": "MIT",
"main": "index.js",
"name": "lexical-scope",
"repository": {
"type": "git",
"url": "git://github.com/substack/lexical-scope.git"
},
"scripts": {
"test": "tape test/*.js"
},
"testling": {
"files": "test/*.js",
"browsers": [
"ie/6",
"ie/7",
"ie/8",
"ie/9",
"ie/10",
"chrome/20",
"chrome/latest",
"firefox/10",
"firefox/15",
"firefox/latest",
"safari/latest",
"opera/11.0",
"opera/latest"
]
},
"version": "1.2.0"
}

View File

@ -0,0 +1,148 @@
# lexical-scope
detect global and local lexical identifiers from javascript source code
[![browser support](http://ci.testling.com/substack/lexical-scope.png)](http://ci.testling.com/substack/lexical-scope)
[![build status](https://secure.travis-ci.org/substack/lexical-scope.png)](http://travis-ci.org/substack/lexical-scope)
# example
``` js
var detect = require('lexical-scope');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/src.js');
var scope = detect(src);
console.log(JSON.stringify(scope,null,2));
```
input:
```
var x = 5;
var y = 3, z = 2;
w.foo();
w = 2;
RAWR=444;
RAWR.foo();
BLARG=3;
foo(function () {
var BAR = 3;
process.nextTick(function (ZZZZZZZZZZZZ) {
console.log('beep boop');
var xyz = 4;
x += 10;
x.zzzzzz;
ZZZ=6;
});
function doom () {
}
ZZZ.foo();
});
console.log(xyz);
```
output:
```
$ node example/detect.js
{
"locals": {
"": [
"x",
"y",
"z"
],
"body.7.expression.body.7.arguments.0": [
"BAR",
"doom"
],
"body.7.expression.body.7.arguments.0.body.body.1.expression.body.1.arguments.0": [
"xyz",
"ZZZZZZZZZZZZ"
],
"body.7.expression.body.7.arguments.0.body.body.2": []
},
"globals": {
"implicit": [
"w",
"foo",
"process",
"console",
"xyz"
],
"implicitProperties": {
"w": [
"foo"
],
"foo": [
"()"
],
"process": [
"nextTick"
],
"console": [
"log"
],
"xyz": [
"*"
]
},
"exported": [
"w",
"RAWR",
"BLARG",
"ZZZ"
]
}
}
```
# live demo
If you are using a modern browser, you can go to http://lexical-scope.forbeslindesay.co.uk/ for a live demo.
# methods
``` js
var detect = require('lexical-scope')
```
## var scope = detect(src)
Return a `scope` structure from a javascript source string `src`.
`scope.locals` maps scope name keys to an array of local variable names declared
with `var`. The key name `''` refers to the top-level scope.
`scope.globals.implicit` contains the global variable names that are expected to
already exist in the environment by the script.
`scope.globals.explicit` contains the global variable names that are exported by
the script.
`scope.globals.implicitProperties` contains the properties of global variable
names that have been used. There are two special implicit property names:
* `"()"` - when an implicit variable has been called
* `"*"` - when an implicit variable has been used in a context that is not a
property and not a call
# install
With [npm](https://npmjs.org) do:
```
npm install lexical-scope
```
# license
MIT

View File

@ -0,0 +1,17 @@
var test = require('tape');
var detect = require('../');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/files/argument.js');
test('parameters from inline arguments', function (t) {
t.plan(3);
var scope = detect(src);
t.same(scope.globals.implicit, []);
t.same(scope.globals.exported, []);
t.same(scope.locals, {
'body.0': [ 'a' ],
'': [ 'foo' ],
'body.0.body.body.1.argument': [ 'c' ]
});
});

View File

@ -0,0 +1,13 @@
var test = require('tape');
var detect = require('../');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/files/assign_implicit.js');
test('assign from an implicit global', function (t) {
t.plan(3);
var scope = detect(src);
t.same(scope.globals.implicit, [ 'bar' ]);
t.same(scope.globals.exported, []);
t.same(scope.locals, { '': [ 'foo' ] });
});

View File

@ -0,0 +1,17 @@
var test = require('tape');
var detect = require('../');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/files/detect.js');
test('check locals and globals', function (t) {
t.plan(3);
var scope = detect(src);
t.same(scope.globals.implicit, [
'w', 'foo', 'process', 'console', 'AAA', 'BBB', 'CCC', 'xyz'
]);
t.same(scope.globals.exported, [
'w', 'RAWR', 'BLARG', 'ZZZ'
]);
t.same(scope.locals[''], [ 'x', 'y', 'z', 'beep' ]);
});

View File

@ -0,0 +1,6 @@
function foo () {
var a;
return function (c) {
a = c;
};
}

View File

@ -0,0 +1,2 @@
var foo;
foo = bar;

View File

@ -0,0 +1 @@
console.log(Buffer('abc'))

View File

@ -0,0 +1 @@
console.log(Buffer.isBuffer('whatever'))

View File

@ -0,0 +1 @@
console.log(Buffer)

View File

@ -0,0 +1,32 @@
var x = 5;
var y = 3, z = 2;
w.foo();
w = 2;
RAWR=444;
RAWR.foo();
BLARG=3;
foo(function () {
var BAR = 3;
process.nextTick(function (ZZZZZZZZZZZZ) {
console.log('beep boop');
var xyz = 4;
x += 10;
x.zzzzzz;
ZZZ=6;
});
function doom () {
if (AAA.aaa) {}
BBB.bbb = 3;
var z = 2 + CCC.x * 5;
}
ZZZ.foo();
});
function beep () {}
console.log(xyz);

View File

@ -0,0 +1,11 @@
test_label1: while(true) {
break test_label1;
continue test_label1;
}
function nest() {
test_label2: while(true) {
break test_label2;
continue test_label2;
}
};

View File

@ -0,0 +1,6 @@
exports.foo = function () {
return bar;
};
exports.bar = function (bar) {
return bar;
};

View File

@ -0,0 +1,6 @@
function foo (x) {
var a = x;
return function (c) {
a += c;
};
}

View File

@ -0,0 +1 @@
module.exports = {foo: bar}

View File

@ -0,0 +1,5 @@
function foo() {
return {
bar: true
}
}

View File

@ -0,0 +1,2 @@
exports.filename = __filename;
exports.dirname = __dirname;

View File

@ -0,0 +1,7 @@
function foo() {
try {
} catch (ex) {
foo(ex)
}
}

View File

@ -0,0 +1,13 @@
var test = require('tape');
var detect = require('../');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/files/labels.js');
test('globals on the right-hand of a colon in an object literal', function (t) {
t.plan(3);
var scope = detect(src);
t.same(scope.globals.implicit, []);
t.same(scope.globals.exported, []);
t.same(scope.locals, { '': [ 'nest' ], 'body.1': [] });
});

View File

@ -0,0 +1,18 @@
var test = require('tape');
var detect = require('../');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/files/multiple-exports.js');
test('multiple-exports', function (t) {
t.plan(3);
var scope = detect(src);
t.same(scope.globals.implicit.sort(), ['bar', 'exports'].sort());
t.same(scope.globals.exported, []);
t.same(scope.locals, {
'':[],
'body.1.expression.right': ['bar'],
'body.0.expression.right': []
});
});

View File

@ -0,0 +1,17 @@
var test = require('tape');
var detect = require('../');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/files/named_arg.js');
test('named argument parameter', function (t) {
t.plan(3);
var scope = detect(src);
t.same(scope.globals.implicit, []);
t.same(scope.globals.exported, []);
t.same(scope.locals, {
'body.0': [ 'a', 'x' ],
'': [ 'foo' ],
'body.0.body.body.1.argument': [ 'c' ]
});
});

View File

@ -0,0 +1,16 @@
var test = require('tape');
var detect = require('../');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/files/obj.js');
test('globals on the right-hand of a colon in an object literal', function (t) {
t.plan(3);
var scope = detect(src);
t.same(
scope.globals.implicit.sort(),
[ 'bar', 'module' ].sort()
);
t.same(scope.globals.exported, []);
t.same(scope.locals, { '': [] });
});

View File

@ -0,0 +1,3 @@
{
"browserify": { "transform": "brfs" }
}

View File

@ -0,0 +1,41 @@
var test = require('tape');
var detect = require('../');
var fs = require('fs');
var src = {
call: fs.readFileSync(__dirname + '/files/buffer_call.js'),
isbuffer: fs.readFileSync(__dirname + '/files/buffer_isbuffer.js'),
v: fs.readFileSync(__dirname + '/files/buffer_var.js')
};
test('implicit props: call', function (t) {
t.plan(3);
var scope = detect(src.call);
t.deepEqual(scope.locals, { '': [] });
t.deepEqual(scope.globals.implicit, [ 'console', 'Buffer' ]);
t.deepEqual(scope.globals.implicitProperties, {
console: [ 'log' ],
Buffer: [ '()' ]
})
});
test('implicit props: isBuffer', function (t) {
t.plan(3);
var scope = detect(src.isbuffer);
t.deepEqual(scope.locals, { '': [] });
t.deepEqual(scope.globals.implicit, [ 'console', 'Buffer' ]);
t.deepEqual(scope.globals.implicitProperties, {
console: [ 'log' ],
Buffer: [ 'isBuffer' ]
})
});
test('implicit props: var', function (t) {
t.plan(3);
var scope = detect(src.v);
t.deepEqual(scope.locals, { '': [] });
t.deepEqual(scope.globals.implicit, [ 'console', 'Buffer' ]);
t.deepEqual(scope.globals.implicitProperties, {
console: [ 'log' ],
Buffer: [ '*' ]
})
});

View File

@ -0,0 +1,13 @@
var test = require('tape');
var detect = require('../');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/files/return_hash.js');
test('return hash', function (t) {
t.plan(3);
var scope = detect(src);
t.same(scope.globals.implicit, []);
t.same(scope.globals.exported, []);
t.same(scope.locals, { 'body.0': [], '': [ 'foo' ] });
});

View File

@ -0,0 +1,16 @@
var test = require('tape');
var detect = require('../');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/files/right_hand.js');
test('globals on the right-hand of assignment', function (t) {
t.plan(3);
var scope = detect(src);
t.same(
scope.globals.implicit.sort(),
[ 'exports', '__dirname', '__filename' ].sort()
);
t.same(scope.globals.exported, []);
t.same(scope.locals, { '': [] });
});

View File

@ -0,0 +1,19 @@
var test = require('tape');
var detect = require('../');
var fs = require('fs');
var src = '#!/beep/boop blah\n'
+ fs.readFileSync(__dirname + '/files/detect.js')
;
test('shebangs', function (t) {
t.plan(3);
var scope = detect(src);
t.same(scope.globals.implicit, [
'w', 'foo', 'process', 'console', 'AAA', 'BBB', 'CCC', 'xyz'
]);
t.same(scope.globals.exported, [
'w', 'RAWR', 'BLARG', 'ZZZ'
]);
t.same(scope.locals[''], [ 'x', 'y', 'z', 'beep' ]);
});

View File

@ -0,0 +1,13 @@
var test = require('tape');
var detect = require('../');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/files/try_catch.js');
test('the exception in a try catch block is a local', function (t) {
t.plan(3);
var scope = detect(src);
t.same(scope.globals.implicit, []);
t.same(scope.globals.exported, []);
t.same(scope.locals, { '': [ 'foo' ], 'body.0': [ 'ex' ] });
});