mirror of
https://github.com/fooflington/selfdefined.git
synced 2025-06-10 21:01:41 +00:00
update
This commit is contained in:
2
node_modules/with/.npmignore
generated
vendored
Normal file
2
node_modules/with/.npmignore
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
test/
|
||||
.travis.yml
|
19
node_modules/with/LICENSE
generated
vendored
Normal file
19
node_modules/with/LICENSE
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright (c) 2013 Forbes Lindesay
|
||||
|
||||
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.
|
81
node_modules/with/README.md
generated
vendored
Normal file
81
node_modules/with/README.md
generated
vendored
Normal file
@ -0,0 +1,81 @@
|
||||
# with
|
||||
|
||||
Compile time `with` for strict mode JavaScript
|
||||
|
||||
[](http://travis-ci.org/pugjs/with)
|
||||
[](https://david-dm.org/pugjs/with)
|
||||
[](https://www.npmjs.com/package/with)
|
||||
|
||||
## Installation
|
||||
|
||||
$ npm install with
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
var addWith = require('with')
|
||||
|
||||
addWith('obj', 'console.log(a)')
|
||||
// => ';(function (console, a) {
|
||||
// console.log(a)
|
||||
// }("console" in obj ? obj.console :
|
||||
// typeof console!=="undefined" ? console : undefined,
|
||||
// "a" in obj ? obj.a :
|
||||
// typeof a !== "undefined" ? a : undefined));'
|
||||
|
||||
addWith('obj', 'console.log(a)', ['console'])
|
||||
// => ';(function (console, a) {
|
||||
// console.log(a)
|
||||
// }("a" in obj ? obj.a :
|
||||
// typeof a !== "undefined" ? a : undefined));'
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### addWith(obj, src[, exclude])
|
||||
|
||||
The idea is that this is roughly equivallent to:
|
||||
|
||||
```js
|
||||
with (obj) {
|
||||
src
|
||||
}
|
||||
```
|
||||
|
||||
There are a few differences though. For starters, assignments to variables will always remain contained within the with block.
|
||||
|
||||
e.g.
|
||||
|
||||
```js
|
||||
var foo = 'foo'
|
||||
with ({}) {
|
||||
foo = 'bar'
|
||||
}
|
||||
assert(foo === 'bar')// => This fails for compile time with but passes for native with
|
||||
|
||||
var obj = {foo: 'foo'}
|
||||
with ({}) {
|
||||
foo = 'bar'
|
||||
}
|
||||
assert(obj.foo === 'bar')// => This fails for compile time with but passes for native with
|
||||
```
|
||||
|
||||
It also makes everything be declared, so you can always do:
|
||||
|
||||
```js
|
||||
if (foo === undefined)
|
||||
```
|
||||
|
||||
instead of
|
||||
|
||||
```js
|
||||
if (typeof foo === 'undefined')
|
||||
```
|
||||
|
||||
This is not the case if foo is in `exclude`. If a variable is excluded, we ignore it entirely. This is useful if you know a variable will be global as it can lead to efficiency improvements.
|
||||
|
||||
It is also safe to use in strict mode (unlike `with`) and it minifies properly (`with` disables virtually all minification).
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
111
node_modules/with/index.js
generated
vendored
Normal file
111
node_modules/with/index.js
generated
vendored
Normal file
@ -0,0 +1,111 @@
|
||||
'use strict';
|
||||
|
||||
var detect = require('acorn-globals');
|
||||
var acorn = require('acorn');
|
||||
var walk = require('acorn/dist/walk');
|
||||
|
||||
// hacky fix for https://github.com/marijnh/acorn/issues/227
|
||||
function reallyParse(source) {
|
||||
return acorn.parse(source, {
|
||||
ecmaVersion: 6,
|
||||
allowReturnOutsideFunction: true
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = addWith
|
||||
|
||||
/**
|
||||
* Mimic `with` as far as possible but at compile time
|
||||
*
|
||||
* @param {String} obj The object part of a with expression
|
||||
* @param {String} src The body of the with expression
|
||||
* @param {Array.<String>} exclude A list of variable names to explicitly exclude
|
||||
*/
|
||||
function addWith(obj, src, exclude) {
|
||||
obj = obj + ''
|
||||
src = src + ''
|
||||
exclude = exclude || []
|
||||
exclude = exclude.concat(detect(obj).map(function (global) { return global.name; }))
|
||||
var vars = detect(src).map(function (global) { return global.name; })
|
||||
.filter(function (v) {
|
||||
return exclude.indexOf(v) === -1
|
||||
&& v !== 'undefined'
|
||||
&& v !== 'this'
|
||||
})
|
||||
|
||||
if (vars.length === 0) return src
|
||||
|
||||
var declareLocal = ''
|
||||
var local = 'locals_for_with'
|
||||
var result = 'result_of_with'
|
||||
if (/^[a-zA-Z0-9$_]+$/.test(obj)) {
|
||||
local = obj
|
||||
} else {
|
||||
while (vars.indexOf(local) != -1 || exclude.indexOf(local) != -1) {
|
||||
local += '_'
|
||||
}
|
||||
declareLocal = 'var ' + local + ' = (' + obj + ')'
|
||||
}
|
||||
while (vars.indexOf(result) != -1 || exclude.indexOf(result) != -1) {
|
||||
result += '_'
|
||||
}
|
||||
|
||||
var inputVars = vars.map(function (v) {
|
||||
return JSON.stringify(v) + ' in ' + local + '?' +
|
||||
local + '.' + v + ':' +
|
||||
'typeof ' + v + '!=="undefined"?' + v + ':undefined'
|
||||
})
|
||||
|
||||
src = '(function (' + vars.join(', ') + ') {' +
|
||||
src +
|
||||
'}.call(this' + inputVars.map(function (v) { return ',' + v; }).join('') + '))'
|
||||
|
||||
return ';' + declareLocal + ';' + unwrapReturns(src, result) + ';'
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a self calling function, and unwrap it such that return inside the function
|
||||
* results in return outside the function
|
||||
*
|
||||
* @param {String} src Some JavaScript code representing a self-calling function
|
||||
* @param {String} result A temporary variable to store the result in
|
||||
*/
|
||||
function unwrapReturns(src, result) {
|
||||
var originalSource = src
|
||||
var hasReturn = false
|
||||
var ast = reallyParse(src)
|
||||
var ref
|
||||
src = src.split('')
|
||||
|
||||
// get a reference to the function that was inserted to add an inner context
|
||||
if ((ref = ast.body).length !== 1
|
||||
|| (ref = ref[0]).type !== 'ExpressionStatement'
|
||||
|| (ref = ref.expression).type !== 'CallExpression'
|
||||
|| (ref = ref.callee).type !== 'MemberExpression' || ref.computed !== false || ref.property.name !== 'call'
|
||||
|| (ref = ref.object).type !== 'FunctionExpression')
|
||||
throw new Error('AST does not seem to represent a self-calling function')
|
||||
var fn = ref
|
||||
|
||||
walk.recursive(ast, null, {
|
||||
Function: function (node, st, c) {
|
||||
if (node === fn) {
|
||||
c(node.body, st, "ScopeBody");
|
||||
}
|
||||
},
|
||||
ReturnStatement: function (node) {
|
||||
hasReturn = true;
|
||||
replace(node, 'return {value: (' + (node.argument ? source(node.argument) : 'undefined') + ')};');
|
||||
}
|
||||
});
|
||||
function source(node) {
|
||||
return src.slice(node.start, node.end).join('')
|
||||
}
|
||||
function replace(node, str) {
|
||||
for (var i = node.start; i < node.end; i++) {
|
||||
src[i] = ''
|
||||
}
|
||||
src[node.start] = str
|
||||
}
|
||||
if (!hasReturn) return originalSource
|
||||
else return 'var ' + result + '=' + src.join('') + ';if (' + result + ') return ' + result + '.value'
|
||||
}
|
57
node_modules/with/package.json
generated
vendored
Normal file
57
node_modules/with/package.json
generated
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"with@5.1.1",
|
||||
"/Users/tatiana/selfdefined"
|
||||
]
|
||||
],
|
||||
"_from": "with@5.1.1",
|
||||
"_id": "with@5.1.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-+k2qktrzLE6pTtRTyB8EaGtXXf4=",
|
||||
"_location": "/with",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "with@5.1.1",
|
||||
"name": "with",
|
||||
"escapedName": "with",
|
||||
"rawSpec": "5.1.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "5.1.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/pug-code-gen"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/with/-/with-5.1.1.tgz",
|
||||
"_spec": "5.1.1",
|
||||
"_where": "/Users/tatiana/selfdefined",
|
||||
"author": {
|
||||
"name": "ForbesLindesay"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/pugjs/with/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"acorn": "^3.1.0",
|
||||
"acorn-globals": "^3.0.0"
|
||||
},
|
||||
"description": "Compile time `with` for strict mode JavaScript",
|
||||
"devDependencies": {
|
||||
"mocha": "~2.5.3",
|
||||
"uglify-js": "^2.4.15"
|
||||
},
|
||||
"homepage": "https://github.com/pugjs/with#readme",
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "with",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/pugjs/with.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha test/index.js -R spec"
|
||||
},
|
||||
"version": "5.1.1"
|
||||
}
|
Reference in New Issue
Block a user