mirror of
https://github.com/mgerb/mywebsite
synced 2026-01-12 18:52:50 +00:00
updated bunch of file paths and changed the way posts are loaded
This commit is contained in:
10
node_modules/swig/.npmignore
generated
vendored
Normal file
10
node_modules/swig/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
.DS_Store
|
||||
*.html
|
||||
browser/**
|
||||
docs/**
|
||||
examples/**
|
||||
Makefile
|
||||
scripts/**
|
||||
tests/**
|
||||
.travis.yml
|
||||
CONTRIBUTING.md
|
||||
498
node_modules/swig/HISTORY.md
generated
vendored
Normal file
498
node_modules/swig/HISTORY.md
generated
vendored
Normal file
@@ -0,0 +1,498 @@
|
||||
[1.4.2](https://github.com/paularmstrong/swig/tree/v1.4.2) / 2014-08-04
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Added** Report JS parse errors with template filenames. gh-492
|
||||
* **Fixed** Ensure block-level tags (`set`, etc) are parsed in correct order. gh-495
|
||||
* **Fixed** Ensure import tag uses current Swig instance's loader. gh-421, gh-503
|
||||
* **Fixed** Allow disabling cache on compile/render functions directly. gh-423
|
||||
* **Fixed** Ensure compilation does not leak global variables. gh-496
|
||||
* **Fixed** Fix for-loops to run on strings. gh-478, gh-479
|
||||
* **Fixed** Allow macro output to be assigned using `set` tag. gh-499, gh-502
|
||||
|
||||
[1.4.1](https://github.com/paularmstrong/swig/tree/v1.4.1) / 2014-07-03
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Fixed** `macro` argument names colliding with context variable names. gh-457
|
||||
* **Fixed** filter chaining within tags. gh-441
|
||||
|
||||
[1.4.0](https://github.com/paularmstrong/swig/tree/v1.4.0) / 2014-07-03
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Changed** Allow variable tokens to start with `$`. gh-455
|
||||
* **Changed** `fs` loader should take `cwd` as default base path. gh-419
|
||||
* **Changed** handle errors which occur at the time of rendering. gh-417
|
||||
* **Changed** default options in bin (`varControls`, `tagControls`, `cmtControls`). gh-415
|
||||
* **Changed** `null` should yield empty string when resolving variable. gh-408
|
||||
* **Added** Escape character for `date` filter argument. gh-427, gh-432
|
||||
* **Added** Make `if` and `elseif` throw a better error message when a tag body is omitted. gh-425
|
||||
* **Fixed** don't throw errors on accessing property of `null` object. gh-471
|
||||
* **Fixed** `loop` variables work correctly in nested loops. gh-433
|
||||
* **Fixed** Some IE8 compatibility (require es5). gh-428
|
||||
|
||||
[1.3.2](https://github.com/paularmstrong/swig/tree/v1.3.2) / 2014-01-27
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Fixed** `for` loop variables on objects. gh-409
|
||||
* **Fixed** Misc. IE8 fixes. gh-410
|
||||
* **Fixed** `include` files when loaders have base paths. gh-407
|
||||
|
||||
[1.3.0](https://github.com/paularmstrong/swig/tree/v1.3.0) / 2014-01-20
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Changed** Removed official node v0.8.x support
|
||||
* **Added** Custom template loader support. gh-377, gh-384, gh-382
|
||||
* **Added** Ability to set root path using template loaders. gh-382, gh-293
|
||||
* **Added** CLI now accepts custom filter and tag arguments. gh-391
|
||||
* **Added** Allow `set` tag to set keys on objects with bracket and dot-notation. gh-388
|
||||
* **Added** `groupBy` filter from swig-extras. gh-383
|
||||
* **Fixed** `swig.run` `filepath` arg is always optional. gh-402
|
||||
* **Fixed** Filters on non-empty functions apply correctly. gh-397
|
||||
* **Fixed** Filters applied to functions w/ & w/o dotkeys. gh-365
|
||||
* **Fixed** `date` filter `N` option returns correct number. gh-375
|
||||
* **Fixed** Ensure getting parent template checks cache if on. gh-378
|
||||
|
||||
[1.2.2](https://github.com/paularmstrong/swig/tree/v1.2.2) / 2013-12-02
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Fixed** CTX var output in imported macros. gh-363
|
||||
|
||||
[1.2.1](https://github.com/paularmstrong/swig/tree/v1.2.1) / 2013-12-02
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Fixed** Scoping for Express. gh-363
|
||||
|
||||
[1.2.0](https://github.com/paularmstrong/swig/tree/v1.2.0) / 2013-12-01
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Added** Filepath parameter can be passed to swig.run to allow extends in-browser. gh-349
|
||||
* **Changed** Use local-context first for var lookups. gh-344, gh-347
|
||||
* **Changed** Allow DOTKEY after functions/objects/filters. gh-355
|
||||
* **Changed** Context of for-tags carries into includes. gh-356
|
||||
* **Changed** When a callback is passed into compileFile, catch all errors thrown by compile and pass the error to callback. gh-340
|
||||
* **Fixed** Instances of Swig retain their options properly. gh-351
|
||||
* **Fixed** Fix misc documentation issues. gh-359, gh-358
|
||||
|
||||
[1.1.0](https://github.com/paularmstrong/swig/tree/v1.1.0) / 2013-10-02
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Added** Allow logic in default parsing. gh-326
|
||||
* **Fixed** Error when attempting to wrap spaceless tag around macro/function output. gh-336
|
||||
* **Fixed** Don't overwrite keys on the locals object. gh-337
|
||||
|
||||
[1.0.0](https://github.com/paularmstrong/swig/tree/v1.0.0) / 2013-09-23
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Fixed** Allow parent and other tags to work correctly nested in other tags. gh-331
|
||||
* **Fixed** Prevent lexer from matching partial logic/words in variables. gh-330
|
||||
|
||||
Migrating from v0.x.x? View the [Migration Guide](https://github.com/paularmstrong/swig/wiki/Migrating-from-v0.x.x-to-v1.0.0)
|
||||
|
||||
[1.0.0-rc3](https://github.com/paularmstrong/swig/tree/v1.0.0-rc3) / 2013-09-14
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
* **Fixed** Allow bools in token parser by default. gh-321
|
||||
* **Fixed** Allow variables as object values. gh-323
|
||||
* **Fixed** Don't partially match logic words. gh-322
|
||||
* **Fixed** Parent tag in parent's block with no local block edge case. gh-316
|
||||
|
||||
[1.0.0-rc2](https://github.com/paularmstrong/swig/tree/v1.0.0-rc2) / 2013-09-06
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
* **Changed** Function output from `variable` blocks are no longer auto-escaped. gh-309
|
||||
* **Fixed** Allow nested macros to work when importing. gh-310
|
||||
* **Fixed** swig.setDefaultTZOffset. gh-311
|
||||
* **Changed** `set` tag assigns to the local context, allowing setting within `for` loops, etc. gh-303
|
||||
* **Fixed** Standardize variable undefined checking. gh-301
|
||||
* **Fixed** Remove multiple redefinition of block-level tags in compiled templates.
|
||||
* **Fixed** Performance issue with compile if no default locals are defined.
|
||||
|
||||
[1.0.0-rc1](https://github.com/paularmstrong/swig/tree/v1.0.0-rc1) / 2013-08-28
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
* **Added** `include` tag now accepts `only` (and is preferred, if possible). gh-240
|
||||
* **Added** `swig.version` and `-v` to cli
|
||||
* **Changed** Deprecated `raw` filter. Use `safe`.
|
||||
* **Changed** Allow `import` and `macro` tags to be outside of blocks. gh-299
|
||||
* **Changed** Don't escape `macro` output. gh-297
|
||||
* **Changed** (Custom) Filters can be marked as `safe` to disable auto-escaping. gh-294
|
||||
* **Fixed** `{% for k,v ... %}` tag syntax assigned variables backwards.
|
||||
* **Fixed** Filters being applied to empty functions throwing errors. gh-296
|
||||
* **Fixed** `include` paths on windows. gh-295
|
||||
|
||||
[1.0.0-pre3](https://github.com/paularmstrong/swig/tree/v1.0.0-pre3) / 2013-08-20
|
||||
---------------------------------------------------------------------------------
|
||||
|
||||
* **Changed** Allow tags at block-level if specified. [gh-289](https://github.com/paularmstrong/swig/issues/289)
|
||||
* **Fixed** `swig.compileFile` runs callback template is found in cache. [gh-291](https://github.com/paularmstrong/swig/issues/291)
|
||||
* **Fixed** Accidental modification of Swig Options Object. [gh-287](https://github.com/paularmstrong/swig/issues/287)
|
||||
* **Fixed** Preserve forward-slashes in text chunks. [gh-285](https://github.com/paularmstrong/swig/issues/285)
|
||||
|
||||
[1.0.0-pre2](https://github.com/paularmstrong/swig/tree/v1.0.0-pre2) / 2013-08-18
|
||||
---------------------------------------------------------------------------------
|
||||
|
||||
* **Changed** Binary: Allow --method-name to be a shortcut for --wrap-start var setting.
|
||||
* **Changed** Make reverse filter an alias for `sort(true)`.
|
||||
* **Added** Allow asyncronous `compileFile` and `renderFile` operations. [gh-283](https://github.com/paularmstrong/swig/issues/283)
|
||||
* **Added** Filter: `sort`.
|
||||
* **Added** Allow {% end[tag] tokens... %}. [gh-278](https://github.com/paularmstrong/swig/issues/278)
|
||||
* **Added** Built source map for minified browser source.
|
||||
* **Added** Contextual support for object method calls. [gh-275](https://github.com/paularmstrong/swig/issues/275)
|
||||
* **Added** `parser.on('start'|'end'...` options. [gh-274](https://github.com/paularmstrong/swig/issues/274)
|
||||
* **Added** Allow object prototypal inheritance. [gh-273](https://github.com/paularmstrong/swig/issues/273)
|
||||
* **Fixed** Prevent circular extends. [gh-282](https://github.com/paularmstrong/swig/issues/282)
|
||||
* **Fixed** Throw an error if reserved word is used as var. [gh-276](https://github.com/paularmstrong/swig/issues/276)
|
||||
* **Fixed** Add filename to errors if possible. [gh-280](https://github.com/paularmstrong/swig/issues/280)
|
||||
* **Fixed** Filters work over arrays/objects if possible. [gh-259](https://github.com/paularmstrong/swig/issues/259)
|
||||
* **Fixed** Allow {% parent %} to work in middle parent templates. [gh-277](https://github.com/paularmstrong/swig/issues/277)
|
||||
* **Fixed** Allow newlines in tags/vars/comments. [gh-272](https://github.com/paularmstrong/swig/issues/272)
|
||||
|
||||
[1.0.0-pre1](https://github.com/paularmstrong/swig/tree/v1.0.0-pre1) / 2013-08-14
|
||||
---------------------------------------------------------------------------------
|
||||
|
||||
* **Changed** Completely rewritting parsing engine supports many more syntaxes and is much easier to extend.
|
||||
* **Changed** There is no more `swig.init` method.
|
||||
* **Changed** Custom filters can be added using `swig.addFilter`
|
||||
* **Changed** Custom tags can be added using `swig.addTag`
|
||||
* **Changed** Writing custom tags uses an entirely new, simplified format
|
||||
* **Changed** Removed the underscore/lodash dependency
|
||||
* **Changed** Template parsing has been completely rewritten
|
||||
* **Changed** `swig.compileFile` returns a function that renders templates, not an object
|
||||
* **Changed** Express-compatible using `swig.renderFile`.
|
||||
* **Changed** `extends`, `import`, and `include` now reference files with relative paths from the current file ([info](https://github.com/paularmstrong/swig/wiki/Migrating-from-v0.x.x-to-v1.0.0#extends-include-import-changes)).
|
||||
* **Changed** `extends` may no longer accept variables ([info](https://github.com/paularmstrong/swig/wiki/Migrating-from-v0.x.x-to-v1.0.0#extends-include-import-changes)).
|
||||
* **Changed** `else if` tag is now `elseif` or `elif`.
|
||||
* **Changed** Removed `only` argument from `include`.
|
||||
* **Changed** allow `_`, `$` to start var names in templates.
|
||||
* **Changed** Documentation is auto-generated from jsdoc comments in-files.
|
||||
* **Added** Ability to set custom var/tag/comment controls (`{{`, `}}`, etc, can be customized).
|
||||
* **Added** Variable/string concatenation [gh-135](https://github.com/paularmstrong/swig/issues/135).
|
||||
* **Added** Binary application for `compile`, `run`, and `render` (Lets you pre-compile templates into JS functions for client-side delivery).
|
||||
* **Fixed** Lots.
|
||||
|
||||
[0.14.0](https://github.com/paularmstrong/swig/tree/v0.14.0) / 2013-06-08
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
* **Added** Allow executing functions from within templates [gh-182](https://github.com/paularmstrong/swig/pull/182)
|
||||
* **Added** New `spaceless` tag [gh-193](https://github.com/paularmstrong/swig/pull/193)
|
||||
* **Fixed** bug when attempting to loop over nested vars with `for`. [gh-232](https://github.com/paularmstrong/swig/pull/232)
|
||||
|
||||
[0.13.5](https://github.com/paularmstrong/swig/tree/v0.13.5) / 2013-01-29
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
* **Fixed** date filter output for 'O' when time-zone offset is negative [gh-185](https://github.com/paularmstrong/swig/pull/185)
|
||||
|
||||
[0.13.4](https://github.com/paularmstrong/swig/tree/v0.13.4) / 2012-12-19
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
* **Fixed** Runaway loop on missing template [gh-162](https://github.com/paularmstrong/swig/pull/162) [gh-165](https://github.com/paularmstrong/swig/pull/165)
|
||||
* **Fixed** Allow variables in if tag conditionals to have filters with arguments [gh-167](https://github.com/paularmstrong/swig/pull/167)
|
||||
|
||||
[0.13.3](https://github.com/paularmstrong/swig/tree/v0.13.3) / 2012-12-07
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
* **Added** Support % (modulus) in if tags [gh-155](https://github.com/paularmstrong/swig/pull/155)
|
||||
* **Added** Support multi-root via array [gh-143](https://github.com/paularmstrong/swig/pull/143)
|
||||
|
||||
[0.13.2](https://github.com/paularmstrong/swig/tree/v0.13.2) / 2012-10-28
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
* **Changed** Allow variables, filters, arguments to span lines [gh-122](https://github.com/paularmstrong/swig/issues/122)
|
||||
* **Changed** Throw Errors when using undefined filters [gh-115](https://github.com/paularmstrong/swig/issues/115)
|
||||
* **Fixed** compiling files from absolute paths [gh-103](https://github.com/paularmstrong/swig/issues/103)
|
||||
* **Fixed** Prevent global variables from being used before context variables [gh-117](https://github.com/paularmstrong/swig/issues/117)
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.13.2/docs)
|
||||
|
||||
[0.13.1](https://github.com/paularmstrong/swig/tree/v0.13.1) / 2012-10-28
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
* **Fixed** Macros should be preserved when using inheritence [gh-132](https://github.com/paularmstrong/swig/issues/132) ([nsaun](https://github.com/nsaun))
|
||||
* **Fixed** bug in parent tag logic [gh-130](https://github.com/paularmstrong/swig/issues/130)
|
||||
* **Fixed** Error messaging when parent block failed compilation [gh-129](https://github.com/paularmstrong/swig/issues/129) ([nsaun](https://github.com/nsaun))
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.13.1/docs)
|
||||
|
||||
[0.13.0](https://github.com/paularmstrong/swig/tree/v0.13.0) / 2012-10-20
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
* **Added** Support for nested blocks! [gh-64](https://github.com/paularmstrong/swig/issues/64) [gh-129](https://github.com/paularmstrong/swig/issues/129) ([nsaun](https://github.com/nsaun))
|
||||
* **Changed** Removed the `parentBlock` argument from tags.
|
||||
* **Fixed** Object keys may now contain dots
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.13.0/docs)
|
||||
|
||||
[0.12.1](https://github.com/paularmstrong/swig/tree/v0.12.1) / 2012-10-05
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
* **Added** More information on some parser errors
|
||||
* **Added** indent parameter to json_encode filter to support pretty-printing.
|
||||
* **Added** support for variables as `extends` tag parameters
|
||||
* **Fixed** Compile errors in Android and other random browsers
|
||||
* **Fixed** Misc documentation
|
||||
* **Fixed** Leaking __keys variable into global scope
|
||||
*
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.12.1/docs)
|
||||
|
||||
[0.12.0](https://github.com/paularmstrong/swig/tree/v0.12.0) / 2012-07-26
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
* **Fixed** Misc documenation
|
||||
* **Changed** Support Node.js >=v0.6
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.12.0/docs)
|
||||
|
||||
[0.11.2](https://github.com/paularmstrong/swig/tree/v0.11.2) / 2012-04-10
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
* **Fixed** Update support for underscore@1.3.3 [gh-70](https://github.com/paularmstrong/swig/issues/70) [gh-71](https://github.com/paularmstrong/swig/issues/71)
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.11.2/docs)
|
||||
|
||||
[0.11.1](https://github.com/paularmstrong/swig/tree/v0.11.1) / 2012-04-01
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
* **Fixed** Duplicate (string) tokens were being removed when extending a base template. [gh-67](https://github.com/paularmstrong/swig/issues/67)
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.11.1/docs)
|
||||
|
||||
[0.11.0](https://github.com/paularmstrong/swig/tree/v0.11.0) / 2012-02-27
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
* **Added** Support for Windows style paths [gh-57](https://github.com/paularmstrong/swig/issues/57)
|
||||
* **Added** `ignore missing` tokens to include tag
|
||||
* **Changed** include tag `with context` to only work if `context` is an object
|
||||
* **Changed** `autoescape` tag controls no longer 'yes' or 'no'. Use `true` and `false`
|
||||
* **Changed** parser is now passed into tags as an argument
|
||||
* **Changed** don't require passing context object when rendering template
|
||||
* **Fixed** dateformats `N` and `w` [gh-59](https://github.com/paularmstrong/swig/issues/59)
|
||||
* **Fixed** number changing to string after add filter or set from variable [gh-53](https://github.com/paularmstrong/swig/issues/53) [gh-58](https://github.com/paularmstrong/swig/issues/58)
|
||||
* **Fixed** speed decrease caused by loop.cycle fixed
|
||||
* **Fixed** Ensure set tag bubbles through extends and blocks
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.11.0/docs)
|
||||
|
||||
[0.10.0](https://github.com/paularmstrong/swig/tree/v0.10.0) / 2012-02-13
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
* **Added** loop.index0, loop.revindex, loop.revindex0, and loop.cycle [gh-48](https://github.com/paularmstrong/swig/issues/48)
|
||||
* **Added** init config `extensions` for 3rd party extension access in custom tags [gh-44](https://github.com/paularmstrong/swig/issues/44)
|
||||
* **Added** Whitespace Control [gh-46](https://github.com/paularmstrong/swig/issues/46)
|
||||
* **Changed** The `empty` tag in `for` loops is now `else` [gh-49](https://github.com/paularmstrong/swig/issues/49)
|
||||
* **Changed** `forloop` vars to `loop` closes [gh-47](https://github.com/paularmstrong/swig/issues/47)
|
||||
* **Fixed** `include` tag's `with` and `only` args documentation [gh-50](https://github.com/paularmstrong/swig/issues/50)
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.10.0/docs)
|
||||
|
||||
[0.9.4](https://github.com/paularmstrong/swig/tree/v0.9.4) / 2012-02-07
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Fixed** `parent` tag would not render when called within tags [gh-41](https://github.com/paularmstrong/swig/issues/41)
|
||||
* **Fixed** Documentation for forloop.index & forloop.key [gh-42](https://github.com/paularmstrong/swig/issues/42)
|
||||
* **Fixed** Errors when using `include` inside base template `block` tags [gh-43](https://github.com/paularmstrong/swig/issues/43)
|
||||
* **Fixed** Allow `set` tag to set values to numbers [gh-45](https://github.com/paularmstrong/swig/issues/45)
|
||||
* **Fixed** `set` tag for booleans using too many checks
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.9.4/docs)
|
||||
|
||||
[0.9.3](https://github.com/paularmstrong/swig/tree/v0.9.3) / 2012-01-28
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Fixed** Allow object and array values to be accessed via context variables [gh-40](https://github.com/paularmstrong/swig/issues/40)
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.9.3/docs)
|
||||
|
||||
[0.9.2](https://github.com/paularmstrong/swig/tree/v0.9.2) / 2012-01-23
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Fixed** Correctly reset autoescape after closing an autoescape tag. [gh-39](https://github.com/paularmstrong/swig/issues/39)
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.9.2/docs)
|
||||
|
||||
[0.9.1](https://github.com/paularmstrong/swig/tree/v0.9.1) / 2012-01-18
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Fixed** Allow multi-line tags and comments. [gh-30](https://github.com/paularmstrong/swig/issues/30)
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.9.1/docs)
|
||||
|
||||
[0.9.0](https://github.com/paularmstrong/swig/tree/v0.9.0) / 2011-12-30
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Added** DateZ license to browser header, use link to underscore license.
|
||||
* **Added** Timezone support in `date` filter [gh-27](https://github.com/paularmstrong/swig/issues/27).
|
||||
* **Added** New `raw` tag.
|
||||
* **Changed** Swig is no longer node 0.4 compatible.
|
||||
* **Fixed** Filter `date('f')` for 10am times.
|
||||
* **Fixed** Filter `date('r')` returns in UTC date format. This is more correct tospec RFC2822, per [php.net/date](http://php.net/date).
|
||||
* **Fixed** Filter `add` when adding numbers/numbers+strings together.
|
||||
* **Fixed** Tests for error messages that changed in node >0.6.0.
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.9.0/docs)
|
||||
|
||||
[0.8.0](https://github.com/paularmstrong/swig/tree/v0.8.0) / 2011-11-04
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Added** date filter formats `z`, `W`, `t`, `L`, `o`, `B`, and `c`.
|
||||
* **Added** New `filter` tag.
|
||||
* **Added** Node.js compatible 0.4.1 - 0.6.X
|
||||
* **Added** Allow setting cache globally or per-template.
|
||||
* **Changed** Removed `swig.render` and `swig.fromString`.
|
||||
* **Changed** `swig.fromFile` is now `swig.compileFile`.
|
||||
* **Changed** `swig.init()` will clear template cache.
|
||||
* **Changed** `swig.init()` is now optional for browser mode with no custom settings.
|
||||
* **Changed** Development dependencies are be more lenient.
|
||||
* **Fixed** Parser will properly preserver '\' escaping. [gh-24](https://github.com/paularmstrong/swig/issues/24)
|
||||
* **Fixed** Rewrote tag argument parsing for proper space handling.
|
||||
* **Fixed** Rewrote filter argument parsing. [gh-23](https://github.com/paularmstrong/swig/issues/23)
|
||||
* **Fixed** Allow pipe `|` characters in filter arguments. [gh-22](https://github.com/paularmstrong/swig/issues/22)
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.8.0/docs)
|
||||
|
||||
[0.7.0](https://github.com/paularmstrong/swig/tree/v0.7.0) / 2011-10-05
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Added** `make browser` will build Swig for use in major browsers. [gh-3](https://github.com/paularmstrong/swig/issues/3)
|
||||
* **Changed** Allow overriding `escape` filters. [gh-19](https://github.com/paularmstrong/swig/issues/19)
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.7.0/docs)
|
||||
|
||||
[0.6.1](https://github.com/paularmstrong/swig/tree/v0.6.1) / 2011-10-02
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Fixed** chaining filters when the first takes a variable as an argument will not crash parsing.
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.6.1/docs)
|
||||
|
||||
[0.6.0](https://github.com/paularmstrong/swig/tree/v0.6.0) / 2011-10-02
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Added** `{% import foo as bar %}` tag for importing macros.
|
||||
* **Added** Allow escaping for js in escape filter and autoescape tag.
|
||||
* **Added** `raw` filter to force variable to not be escaped.
|
||||
* **Added** `escape` and `e` filters to force variable to be escaped.
|
||||
* **Added** Allow filters to accept any JS objects, arrays, strings, and context variables.
|
||||
* **Changed** `if`, `else`, and `else if` tags support all JS-valid if-syntaxes + extra operators.
|
||||
* **Fixed** `default` filter for undefined variables. closes gh-18
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.6.0/docs)
|
||||
|
||||
[0.5.0](https://github.com/paularmstrong/swig/tree/v0.5.0) / 2011-09-27
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Added** More error messaging in some edge cases.
|
||||
* **Added** Better error messaging including context and line numbers.
|
||||
* **Changed** Improved compile and render speeds.
|
||||
* **Changed** `include` tags accept context variables instead of just strings.
|
||||
* **Changed** Templates can be compiled and rendered from an absolute path outside of the template root.
|
||||
* **Fixed** Will not double escape output.
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.5.0/docs)
|
||||
|
||||
[0.4.0](https://github.com/paularmstrong/swig/tree/v0.4.0) / 2011-09-24
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Added** Macro support [docs](docs/tags.md)
|
||||
* **Changed** Removed requirement to manually specify `locals` for express support.
|
||||
* **Changed** Increased cache lookup speed by removing crypto dependency.
|
||||
* **Fixed** `length` filter returns length of objects (number of keys).
|
||||
* **Fixed** Filters return empty string unless they can apply to the given object.
|
||||
* **Fixed** Filters will attempt to apply to all values in an object or array.
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.4.0/docs)
|
||||
|
||||
[0.3.0](https://github.com/paularmstrong/swig/tree/v0.3.0) / 2011-09-17
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Added** Support for `{% set ... %}` tag.
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.3.0/docs)
|
||||
|
||||
[0.2.3](https://github.com/paularmstrong/swig/tree/v0.2.3) / 2011-09-16
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Fixed** Critical fix for negations in `if` blocks.
|
||||
* **Added** Support for `forloop.first` in `for` blocks.
|
||||
* **Added** Support for `forloop.last` in `for` blocks.
|
||||
* **Added** Support for `forloop.key` in `for` blocks.
|
||||
* **Added** Support for `{% empty %}` in `for` blocks.
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.2.3/docs)
|
||||
|
||||
[0.2.2](https://github.com/paularmstrong/swig/tree/v0.2.2) / 2011-09-16
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Added** Support for `else if ...` within `if` blocks.
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.2.2/docs)
|
||||
|
||||
[0.2.1](https://github.com/paularmstrong/swig/tree/v0.2.1) / 2011-09-13
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Added** Support for `else` within `if` blocks.
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.2.1/docs)
|
||||
|
||||
[0.2.0](https://github.com/paularmstrong/swig/tree/v0.2.0) / 2011-09-11
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Fixed** `if` statements allow filters applied to operands.
|
||||
* **Fixed** `for` loops allow filters applied to the object that will be iterated over.
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.2.0/docs)
|
||||
|
||||
[0.1.9](https://github.com/paularmstrong/swig/tree/v0.1.9) / 2011-09-11
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Added** `allowErrors` flag will allow errors to be thrown and bubbled up. Default to catch errors.
|
||||
* **Changed** Internal speed improvements.
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.1.9/docs)
|
||||
|
||||
[0.1.8](https://github.com/paularmstrong/swig/tree/v0.1.8) / 2011-09-10
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Added** `add`, `addslashes`, and `replace` filters.
|
||||
* **Changed** All tags that 'end' must use named ends like `endblock`, `endif`, `endfor`, etc...
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.1.8/docs)
|
||||
|
||||
[0.1.7](https://github.com/paularmstrong/swig/tree/v0.1.7) / 2011-09-05
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Added** this History document
|
||||
* **Fixed** date filter to zero-pad correctly during september when using 'm' format
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.1.7/docs)
|
||||
|
||||
[0.1.6](https://github.com/paularmstrong/swig/tree/v0.1.6) / 2011-09-04
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Fixed** Template inheritance blocks messing up.
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.1.6/docs)
|
||||
|
||||
[0.1.5](https://github.com/paularmstrong/swig/tree/v0.1.5) / 2011-09-04
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Added** `first`, `last`, and `uniq` filters
|
||||
* **Added** ability to specify custom filters
|
||||
* **Added** ability to specify custom tags
|
||||
* **Changed** slots removed -- implement using custom tags if desired
|
||||
* **Fixed** ability to do either dot- or bracket-notation or mixed in variables
|
||||
* **Fixed** internal parsing helpers
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.1.5/docs)
|
||||
|
||||
[0.1.3](https://github.com/paularmstrong/swig/tree/v0.1.3) / 2011-09-01
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* **Fixed** filter parser to work correctly with single-quoted params in filters.
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.1.3/docs)
|
||||
|
||||
[0.1.2](https://github.com/paularmstrong/swig/tree/v0.1.2) / 2011-09-01
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
* Initial **swig** publish after forking from [node-t](https://github.com/skid/node-t)
|
||||
|
||||
[Documentation](https://github.com/paularmstrong/swig/tree/v0.1.2/docs)
|
||||
7
node_modules/swig/LICENSE
generated
vendored
Normal file
7
node_modules/swig/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
Copyright (c) 2010-2013 Paul Armstrong
|
||||
|
||||
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.
|
||||
88
node_modules/swig/README.md
generated
vendored
Normal file
88
node_modules/swig/README.md
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
Swig [](http://travis-ci.org/paularmstrong/swig) [](https://gemnasium.com/paularmstrong/swig) [](https://www.npmjs.org/package/swig) [](https://www.npmjs.org/package/swig)
|
||||
====
|
||||
|
||||
[Swig](http://paularmstrong.github.io/swig/) is an awesome, Django/Jinja-like template engine for node.js.
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
* Available for node.js **and** major web browsers!
|
||||
* [Express](http://expressjs.com/) compatible.
|
||||
* Object-Oriented template inheritance.
|
||||
* Apply filters and transformations to output in your templates.
|
||||
* Automatically escapes all output for safe HTML rendering.
|
||||
* Lots of iteration and conditionals supported.
|
||||
* Robust without the bloat.
|
||||
* Extendable and customizable. See [Swig-Extras](https://github.com/paularmstrong/swig-extras) for some examples.
|
||||
* Great [code coverage](http://paularmstrong.github.io/swig/coverage.html).
|
||||
|
||||
Need Help? Have Questions? Comments?
|
||||
------------------------------------
|
||||
|
||||
* [Mailing List/Google Group](http://groups.google.com/forum/#!forum/swig-templates)
|
||||
* [StackOverflow](http://stackoverflow.com/questions/tagged/swig-template)
|
||||
* [Migration Guide](https://github.com/paularmstrong/swig/wiki/Migrating-from-v0.x.x-to-v1.0.0)
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
npm install swig
|
||||
|
||||
Documentation
|
||||
-------------
|
||||
|
||||
All documentation can be viewed online on the [Swig Website](http://paularmstrong.github.io/swig/).
|
||||
|
||||
Basic Example
|
||||
-------------
|
||||
|
||||
### Template code
|
||||
|
||||
```html
|
||||
<h1>{{ pagename|title }}</h1>
|
||||
<ul>
|
||||
{% for author in authors %}
|
||||
<li{% if loop.first %} class="first"{% endif %}>{{ author }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
```
|
||||
|
||||
### node.js code
|
||||
|
||||
```js
|
||||
var swig = require('swig');
|
||||
var template = swig.compileFile('/absolute/path/to/template.html');
|
||||
var output = template({
|
||||
pagename: 'awesome people',
|
||||
authors: ['Paul', 'Jim', 'Jane']
|
||||
});
|
||||
```
|
||||
|
||||
### Output
|
||||
|
||||
```html
|
||||
<h1>Awesome People</h1>
|
||||
<ul>
|
||||
<li class="first">Paul</li>
|
||||
<li>Jim</li>
|
||||
<li>Jane</li>
|
||||
</ul>
|
||||
```
|
||||
|
||||
For working example see [examples/basic](https://github.com/paularmstrong/swig/tree/master/examples/basic)
|
||||
|
||||
How it works
|
||||
------------
|
||||
|
||||
Swig reads template files and translates them into cached javascript functions. When we later render a template we call the evaluated function, passing a context object as an argument.
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
Copyright (c) 2010-2013 Paul Armstrong
|
||||
|
||||
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.
|
||||
161
node_modules/swig/bin/swig.js
generated
vendored
Executable file
161
node_modules/swig/bin/swig.js
generated
vendored
Executable file
@@ -0,0 +1,161 @@
|
||||
#!/usr/bin/env node
|
||||
/*jslint es5: true */
|
||||
|
||||
var swig = require('../index'),
|
||||
optimist = require('optimist'),
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
filters = require('../lib/filters'),
|
||||
utils = require('../lib/utils'),
|
||||
uglify = require('uglify-js');
|
||||
|
||||
var command,
|
||||
argv = optimist
|
||||
.usage('\n Usage:\n' +
|
||||
' $0 compile [files] [options]\n' +
|
||||
' $0 run [files] [options]\n' +
|
||||
' $0 render [files] [options]\n'
|
||||
)
|
||||
.describe({
|
||||
v: 'Show the Swig version number.',
|
||||
o: 'Output location.',
|
||||
h: 'Show this help screen.',
|
||||
j: 'Variable context as a JSON file.',
|
||||
c: 'Variable context as a CommonJS-style file. Used only if option `j` is not provided.',
|
||||
m: 'Minify compiled functions with uglify-js',
|
||||
'filters': 'Custom filters as a CommonJS-style file',
|
||||
'tags': 'Custom tags as a CommonJS-style file',
|
||||
'options': 'Customize Swig\'s Options from a CommonJS-style file',
|
||||
'wrap-start': 'Template wrapper beginning for "compile".',
|
||||
'wrap-end': 'Template wrapper end for "compile".',
|
||||
'method-name': 'Method name to set template to and run from.'
|
||||
})
|
||||
.alias('v', 'version')
|
||||
.alias('o', 'output')
|
||||
.default('o', 'stdout')
|
||||
.alias('h', 'help')
|
||||
.alias('j', 'json')
|
||||
.alias('c', 'context')
|
||||
.alias('m', 'minify')
|
||||
.default('wrap-start', 'var tpl = ')
|
||||
.default('wrap-end', ';')
|
||||
.default('method-name', 'tpl')
|
||||
.check(function (argv) {
|
||||
if (argv.v) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!argv._.length) {
|
||||
throw new Error('');
|
||||
}
|
||||
|
||||
command = argv._.shift();
|
||||
if (command !== 'compile' && command !== 'render' && command !== 'run') {
|
||||
throw new Error('Unrecognized command "' + command + '". Use -h for help.');
|
||||
}
|
||||
|
||||
if (argv['method-name'] !== 'tpl' && argv['wrap-start'] !== 'var tpl =') {
|
||||
throw new Error('Cannot use arguments "--method-name" and "--wrap-start" together.');
|
||||
}
|
||||
|
||||
if (argv['method-name'] !== 'tpl') {
|
||||
argv['wrap-start'] = 'var ' + argv['method-name'] + ' = ';
|
||||
}
|
||||
})
|
||||
.argv,
|
||||
ctx = {},
|
||||
out = function (file, str) {
|
||||
console.log(str);
|
||||
},
|
||||
efn = function () {},
|
||||
anonymous,
|
||||
files,
|
||||
fn;
|
||||
|
||||
// What version?
|
||||
if (argv.v) {
|
||||
console.log(require('../package').version);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// Pull in any context data provided
|
||||
if (argv.j) {
|
||||
ctx = JSON.parse(fs.readFileSync(argv.j, 'utf8'));
|
||||
} else if (argv.c) {
|
||||
ctx = require(argv.c);
|
||||
}
|
||||
|
||||
if (argv.o !== 'stdout') {
|
||||
argv.o += '/';
|
||||
argv.o = path.normalize(argv.o);
|
||||
|
||||
try {
|
||||
fs.mkdirSync(argv.o);
|
||||
} catch (e) {
|
||||
if (e.errno !== 47) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
out = function (file, str) {
|
||||
file = path.basename(file);
|
||||
fs.writeFileSync(argv.o + file, str, { flags: 'w' });
|
||||
console.log('Wrote', argv.o + file);
|
||||
};
|
||||
}
|
||||
|
||||
// Set any custom filters
|
||||
if (argv.filters) {
|
||||
utils.each(require(path.resolve(argv.filters)), function (filter, name) {
|
||||
swig.setFilter(name, filter);
|
||||
});
|
||||
}
|
||||
|
||||
// Set any custom tags
|
||||
if (argv.tags) {
|
||||
utils.each(require(path.resolve(argv.tags)), function (tag, name) {
|
||||
swig.setTag(name, tag.parse, tag.compile, tag.ends, tag.block);
|
||||
});
|
||||
}
|
||||
|
||||
// Specify swig default options
|
||||
if (argv.options) {
|
||||
swig.setDefaults(require(argv.options));
|
||||
}
|
||||
|
||||
switch (command) {
|
||||
case 'compile':
|
||||
fn = function (file, str) {
|
||||
var r = swig.precompile(str, { filename: file, locals: ctx }).tpl.toString().replace('anonymous', '');
|
||||
|
||||
r = argv['wrap-start'] + r + argv['wrap-end'];
|
||||
|
||||
if (argv.m) {
|
||||
r = uglify.minify(r, { fromString: true }).code;
|
||||
}
|
||||
|
||||
out(file, r);
|
||||
};
|
||||
break;
|
||||
|
||||
case 'run':
|
||||
fn = function (file, str) {
|
||||
(function () {
|
||||
eval(str);
|
||||
var __tpl = eval(argv['method-name']);
|
||||
out(file, __tpl(swig, ctx, filters, utils, efn));
|
||||
}());
|
||||
};
|
||||
break;
|
||||
|
||||
case 'render':
|
||||
fn = function (file, str) {
|
||||
out(file, swig.render(str, { filename: file, locals: ctx }));
|
||||
};
|
||||
break;
|
||||
}
|
||||
|
||||
argv._.forEach(function (file) {
|
||||
var str = fs.readFileSync(file, 'utf8');
|
||||
fn(file, str);
|
||||
});
|
||||
5006
node_modules/swig/dist/swig.js
generated
vendored
Normal file
5006
node_modules/swig/dist/swig.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
node_modules/swig/dist/swig.js.map
generated
vendored
Normal file
1
node_modules/swig/dist/swig.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
5
node_modules/swig/dist/swig.min.js
generated
vendored
Normal file
5
node_modules/swig/dist/swig.min.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1
node_modules/swig/index.js
generated
vendored
Normal file
1
node_modules/swig/index.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require('./lib/swig');
|
||||
198
node_modules/swig/lib/dateformatter.js
generated
vendored
Normal file
198
node_modules/swig/lib/dateformatter.js
generated
vendored
Normal file
@@ -0,0 +1,198 @@
|
||||
var utils = require('./utils');
|
||||
|
||||
var _months = {
|
||||
full: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
|
||||
abbr: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
||||
},
|
||||
_days = {
|
||||
full: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
|
||||
abbr: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
|
||||
alt: {'-1': 'Yesterday', 0: 'Today', 1: 'Tomorrow'}
|
||||
};
|
||||
|
||||
/*
|
||||
DateZ is licensed under the MIT License:
|
||||
Copyright (c) 2011 Tomo Universalis (http://tomouniversalis.com)
|
||||
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.
|
||||
*/
|
||||
exports.tzOffset = 0;
|
||||
exports.DateZ = function () {
|
||||
var members = {
|
||||
'default': ['getUTCDate', 'getUTCDay', 'getUTCFullYear', 'getUTCHours', 'getUTCMilliseconds', 'getUTCMinutes', 'getUTCMonth', 'getUTCSeconds', 'toISOString', 'toGMTString', 'toUTCString', 'valueOf', 'getTime'],
|
||||
z: ['getDate', 'getDay', 'getFullYear', 'getHours', 'getMilliseconds', 'getMinutes', 'getMonth', 'getSeconds', 'getYear', 'toDateString', 'toLocaleDateString', 'toLocaleTimeString']
|
||||
},
|
||||
d = this;
|
||||
|
||||
d.date = d.dateZ = (arguments.length > 1) ? new Date(Date.UTC.apply(Date, arguments) + ((new Date()).getTimezoneOffset() * 60000)) : (arguments.length === 1) ? new Date(new Date(arguments['0'])) : new Date();
|
||||
|
||||
d.timezoneOffset = d.dateZ.getTimezoneOffset();
|
||||
|
||||
utils.each(members.z, function (name) {
|
||||
d[name] = function () {
|
||||
return d.dateZ[name]();
|
||||
};
|
||||
});
|
||||
utils.each(members['default'], function (name) {
|
||||
d[name] = function () {
|
||||
return d.date[name]();
|
||||
};
|
||||
});
|
||||
|
||||
this.setTimezoneOffset(exports.tzOffset);
|
||||
};
|
||||
exports.DateZ.prototype = {
|
||||
getTimezoneOffset: function () {
|
||||
return this.timezoneOffset;
|
||||
},
|
||||
setTimezoneOffset: function (offset) {
|
||||
this.timezoneOffset = offset;
|
||||
this.dateZ = new Date(this.date.getTime() + this.date.getTimezoneOffset() * 60000 - this.timezoneOffset * 60000);
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
// Day
|
||||
exports.d = function (input) {
|
||||
return (input.getDate() < 10 ? '0' : '') + input.getDate();
|
||||
};
|
||||
exports.D = function (input) {
|
||||
return _days.abbr[input.getDay()];
|
||||
};
|
||||
exports.j = function (input) {
|
||||
return input.getDate();
|
||||
};
|
||||
exports.l = function (input) {
|
||||
return _days.full[input.getDay()];
|
||||
};
|
||||
exports.N = function (input) {
|
||||
var d = input.getDay();
|
||||
return (d >= 1) ? d : 7;
|
||||
};
|
||||
exports.S = function (input) {
|
||||
var d = input.getDate();
|
||||
return (d % 10 === 1 && d !== 11 ? 'st' : (d % 10 === 2 && d !== 12 ? 'nd' : (d % 10 === 3 && d !== 13 ? 'rd' : 'th')));
|
||||
};
|
||||
exports.w = function (input) {
|
||||
return input.getDay();
|
||||
};
|
||||
exports.z = function (input, offset, abbr) {
|
||||
var year = input.getFullYear(),
|
||||
e = new exports.DateZ(year, input.getMonth(), input.getDate(), 12, 0, 0),
|
||||
d = new exports.DateZ(year, 0, 1, 12, 0, 0);
|
||||
|
||||
e.setTimezoneOffset(offset, abbr);
|
||||
d.setTimezoneOffset(offset, abbr);
|
||||
return Math.round((e - d) / 86400000);
|
||||
};
|
||||
|
||||
// Week
|
||||
exports.W = function (input) {
|
||||
var target = new Date(input.valueOf()),
|
||||
dayNr = (input.getDay() + 6) % 7,
|
||||
fThurs;
|
||||
|
||||
target.setDate(target.getDate() - dayNr + 3);
|
||||
fThurs = target.valueOf();
|
||||
target.setMonth(0, 1);
|
||||
if (target.getDay() !== 4) {
|
||||
target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7);
|
||||
}
|
||||
|
||||
return 1 + Math.ceil((fThurs - target) / 604800000);
|
||||
};
|
||||
|
||||
// Month
|
||||
exports.F = function (input) {
|
||||
return _months.full[input.getMonth()];
|
||||
};
|
||||
exports.m = function (input) {
|
||||
return (input.getMonth() < 9 ? '0' : '') + (input.getMonth() + 1);
|
||||
};
|
||||
exports.M = function (input) {
|
||||
return _months.abbr[input.getMonth()];
|
||||
};
|
||||
exports.n = function (input) {
|
||||
return input.getMonth() + 1;
|
||||
};
|
||||
exports.t = function (input) {
|
||||
return 32 - (new Date(input.getFullYear(), input.getMonth(), 32).getDate());
|
||||
};
|
||||
|
||||
// Year
|
||||
exports.L = function (input) {
|
||||
return new Date(input.getFullYear(), 1, 29).getDate() === 29;
|
||||
};
|
||||
exports.o = function (input) {
|
||||
var target = new Date(input.valueOf());
|
||||
target.setDate(target.getDate() - ((input.getDay() + 6) % 7) + 3);
|
||||
return target.getFullYear();
|
||||
};
|
||||
exports.Y = function (input) {
|
||||
return input.getFullYear();
|
||||
};
|
||||
exports.y = function (input) {
|
||||
return (input.getFullYear().toString()).substr(2);
|
||||
};
|
||||
|
||||
// Time
|
||||
exports.a = function (input) {
|
||||
return input.getHours() < 12 ? 'am' : 'pm';
|
||||
};
|
||||
exports.A = function (input) {
|
||||
return input.getHours() < 12 ? 'AM' : 'PM';
|
||||
};
|
||||
exports.B = function (input) {
|
||||
var hours = input.getUTCHours(), beats;
|
||||
hours = (hours === 23) ? 0 : hours + 1;
|
||||
beats = Math.abs(((((hours * 60) + input.getUTCMinutes()) * 60) + input.getUTCSeconds()) / 86.4).toFixed(0);
|
||||
return ('000'.concat(beats).slice(beats.length));
|
||||
};
|
||||
exports.g = function (input) {
|
||||
var h = input.getHours();
|
||||
return h === 0 ? 12 : (h > 12 ? h - 12 : h);
|
||||
};
|
||||
exports.G = function (input) {
|
||||
return input.getHours();
|
||||
};
|
||||
exports.h = function (input) {
|
||||
var h = input.getHours();
|
||||
return ((h < 10 || (12 < h && 22 > h)) ? '0' : '') + ((h < 12) ? h : h - 12);
|
||||
};
|
||||
exports.H = function (input) {
|
||||
var h = input.getHours();
|
||||
return (h < 10 ? '0' : '') + h;
|
||||
};
|
||||
exports.i = function (input) {
|
||||
var m = input.getMinutes();
|
||||
return (m < 10 ? '0' : '') + m;
|
||||
};
|
||||
exports.s = function (input) {
|
||||
var s = input.getSeconds();
|
||||
return (s < 10 ? '0' : '') + s;
|
||||
};
|
||||
//u = function () { return ''; },
|
||||
|
||||
// Timezone
|
||||
//e = function () { return ''; },
|
||||
//I = function () { return ''; },
|
||||
exports.O = function (input) {
|
||||
var tz = input.getTimezoneOffset();
|
||||
return (tz < 0 ? '-' : '+') + (tz / 60 < 10 ? '0' : '') + Math.abs((tz / 60)) + '00';
|
||||
};
|
||||
//T = function () { return ''; },
|
||||
exports.Z = function (input) {
|
||||
return input.getTimezoneOffset() * 60;
|
||||
};
|
||||
|
||||
// Full Date/Time
|
||||
exports.c = function (input) {
|
||||
return input.toISOString();
|
||||
};
|
||||
exports.r = function (input) {
|
||||
return input.toUTCString();
|
||||
};
|
||||
exports.U = function (input) {
|
||||
return input.getTime() / 1000;
|
||||
};
|
||||
630
node_modules/swig/lib/filters.js
generated
vendored
Normal file
630
node_modules/swig/lib/filters.js
generated
vendored
Normal file
@@ -0,0 +1,630 @@
|
||||
var utils = require('./utils'),
|
||||
dateFormatter = require('./dateformatter');
|
||||
|
||||
/**
|
||||
* Helper method to recursively run a filter across an object/array and apply it to all of the object/array's values.
|
||||
* @param {*} input
|
||||
* @return {*}
|
||||
* @private
|
||||
*/
|
||||
function iterateFilter(input) {
|
||||
var self = this,
|
||||
out = {};
|
||||
|
||||
if (utils.isArray(input)) {
|
||||
return utils.map(input, function (value) {
|
||||
return self.apply(null, arguments);
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof input === 'object') {
|
||||
utils.each(input, function (value, key) {
|
||||
out[key] = self.apply(null, arguments);
|
||||
});
|
||||
return out;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Backslash-escape characters that need to be escaped.
|
||||
*
|
||||
* @example
|
||||
* {{ "\"quoted string\""|addslashes }}
|
||||
* // => \"quoted string\"
|
||||
*
|
||||
* @param {*} input
|
||||
* @return {*} Backslash-escaped string.
|
||||
*/
|
||||
exports.addslashes = function (input) {
|
||||
var out = iterateFilter.apply(exports.addslashes, arguments);
|
||||
if (out !== undefined) {
|
||||
return out;
|
||||
}
|
||||
|
||||
return input.replace(/\\/g, '\\\\').replace(/\'/g, "\\'").replace(/\"/g, '\\"');
|
||||
};
|
||||
|
||||
/**
|
||||
* Upper-case the first letter of the input and lower-case the rest.
|
||||
*
|
||||
* @example
|
||||
* {{ "i like Burritos"|capitalize }}
|
||||
* // => I like burritos
|
||||
*
|
||||
* @param {*} input If given an array or object, each string member will be run through the filter individually.
|
||||
* @return {*} Returns the same type as the input.
|
||||
*/
|
||||
exports.capitalize = function (input) {
|
||||
var out = iterateFilter.apply(exports.capitalize, arguments);
|
||||
if (out !== undefined) {
|
||||
return out;
|
||||
}
|
||||
|
||||
return input.toString().charAt(0).toUpperCase() + input.toString().substr(1).toLowerCase();
|
||||
};
|
||||
|
||||
/**
|
||||
* Format a date or Date-compatible string.
|
||||
*
|
||||
* @example
|
||||
* // now = new Date();
|
||||
* {{ now|date('Y-m-d') }}
|
||||
* // => 2013-08-14
|
||||
* @example
|
||||
* // now = new Date();
|
||||
* {{ now|date('jS \o\f F') }}
|
||||
* // => 4th of July
|
||||
*
|
||||
* @param {?(string|date)} input
|
||||
* @param {string} format PHP-style date format compatible string. Escape characters with <code>\</code> for string literals.
|
||||
* @param {number=} offset Timezone offset from GMT in minutes.
|
||||
* @param {string=} abbr Timezone abbreviation. Used for output only.
|
||||
* @return {string} Formatted date string.
|
||||
*/
|
||||
exports.date = function (input, format, offset, abbr) {
|
||||
var l = format.length,
|
||||
date = new dateFormatter.DateZ(input),
|
||||
cur,
|
||||
i = 0,
|
||||
out = '';
|
||||
|
||||
if (offset) {
|
||||
date.setTimezoneOffset(offset, abbr);
|
||||
}
|
||||
|
||||
for (i; i < l; i += 1) {
|
||||
cur = format.charAt(i);
|
||||
if (cur === '\\') {
|
||||
i += 1;
|
||||
out += (i < l) ? format.charAt(i) : cur;
|
||||
} else if (dateFormatter.hasOwnProperty(cur)) {
|
||||
out += dateFormatter[cur](date, offset, abbr);
|
||||
} else {
|
||||
out += cur;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
};
|
||||
|
||||
/**
|
||||
* If the input is `undefined`, `null`, or `false`, a default return value can be specified.
|
||||
*
|
||||
* @example
|
||||
* {{ null_value|default('Tacos') }}
|
||||
* // => Tacos
|
||||
*
|
||||
* @example
|
||||
* {{ "Burritos"|default("Tacos") }}
|
||||
* // => Burritos
|
||||
*
|
||||
* @param {*} input
|
||||
* @param {*} def Value to return if `input` is `undefined`, `null`, or `false`.
|
||||
* @return {*} `input` or `def` value.
|
||||
*/
|
||||
exports["default"] = function (input, def) {
|
||||
return (typeof input !== 'undefined' && (input || typeof input === 'number')) ? input : def;
|
||||
};
|
||||
|
||||
/**
|
||||
* Force escape the output of the variable. Optionally use `e` as a shortcut filter name. This filter will be applied by default if autoescape is turned on.
|
||||
*
|
||||
* @example
|
||||
* {{ "<blah>"|escape }}
|
||||
* // => <blah>
|
||||
*
|
||||
* @example
|
||||
* {{ "<blah>"|e("js") }}
|
||||
* // => \u003Cblah\u003E
|
||||
*
|
||||
* @param {*} input
|
||||
* @param {string} [type='html'] If you pass the string js in as the type, output will be escaped so that it is safe for JavaScript execution.
|
||||
* @return {string} Escaped string.
|
||||
*/
|
||||
exports.escape = function (input, type) {
|
||||
var out = iterateFilter.apply(exports.escape, arguments),
|
||||
inp = input,
|
||||
i = 0,
|
||||
code;
|
||||
|
||||
if (out !== undefined) {
|
||||
return out;
|
||||
}
|
||||
|
||||
if (typeof input !== 'string') {
|
||||
return input;
|
||||
}
|
||||
|
||||
out = '';
|
||||
|
||||
switch (type) {
|
||||
case 'js':
|
||||
inp = inp.replace(/\\/g, '\\u005C');
|
||||
for (i; i < inp.length; i += 1) {
|
||||
code = inp.charCodeAt(i);
|
||||
if (code < 32) {
|
||||
code = code.toString(16).toUpperCase();
|
||||
code = (code.length < 2) ? '0' + code : code;
|
||||
out += '\\u00' + code;
|
||||
} else {
|
||||
out += inp[i];
|
||||
}
|
||||
}
|
||||
return out.replace(/&/g, '\\u0026')
|
||||
.replace(/</g, '\\u003C')
|
||||
.replace(/>/g, '\\u003E')
|
||||
.replace(/\'/g, '\\u0027')
|
||||
.replace(/"/g, '\\u0022')
|
||||
.replace(/\=/g, '\\u003D')
|
||||
.replace(/-/g, '\\u002D')
|
||||
.replace(/;/g, '\\u003B');
|
||||
|
||||
default:
|
||||
return inp.replace(/&(?!amp;|lt;|gt;|quot;|#39;)/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
}
|
||||
};
|
||||
exports.e = exports.escape;
|
||||
|
||||
/**
|
||||
* Get the first item in an array or character in a string. All other objects will attempt to return the first value available.
|
||||
*
|
||||
* @example
|
||||
* // my_arr = ['a', 'b', 'c']
|
||||
* {{ my_arr|first }}
|
||||
* // => a
|
||||
*
|
||||
* @example
|
||||
* // my_val = 'Tacos'
|
||||
* {{ my_val|first }}
|
||||
* // T
|
||||
*
|
||||
* @param {*} input
|
||||
* @return {*} The first item of the array or first character of the string input.
|
||||
*/
|
||||
exports.first = function (input) {
|
||||
if (typeof input === 'object' && !utils.isArray(input)) {
|
||||
var keys = utils.keys(input);
|
||||
return input[keys[0]];
|
||||
}
|
||||
|
||||
if (typeof input === 'string') {
|
||||
return input.substr(0, 1);
|
||||
}
|
||||
|
||||
return input[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* Group an array of objects by a common key. If an array is not provided, the input value will be returned untouched.
|
||||
*
|
||||
* @example
|
||||
* // people = [{ age: 23, name: 'Paul' }, { age: 26, name: 'Jane' }, { age: 23, name: 'Jim' }];
|
||||
* {% for agegroup in people|groupBy('age') %}
|
||||
* <h2>{{ loop.key }}</h2>
|
||||
* <ul>
|
||||
* {% for person in agegroup %}
|
||||
* <li>{{ person.name }}</li>
|
||||
* {% endfor %}
|
||||
* </ul>
|
||||
* {% endfor %}
|
||||
*
|
||||
* @param {*} input Input object.
|
||||
* @param {string} key Key to group by.
|
||||
* @return {object} Grouped arrays by given key.
|
||||
*/
|
||||
exports.groupBy = function (input, key) {
|
||||
if (!utils.isArray(input)) {
|
||||
return input;
|
||||
}
|
||||
|
||||
var out = {};
|
||||
|
||||
utils.each(input, function (value) {
|
||||
if (!value.hasOwnProperty(key)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var keyname = value[key],
|
||||
newVal = utils.extend({}, value);
|
||||
delete value[key];
|
||||
|
||||
if (!out[keyname]) {
|
||||
out[keyname] = [];
|
||||
}
|
||||
|
||||
out[keyname].push(value);
|
||||
});
|
||||
|
||||
return out;
|
||||
};
|
||||
|
||||
/**
|
||||
* Join the input with a string.
|
||||
*
|
||||
* @example
|
||||
* // my_array = ['foo', 'bar', 'baz']
|
||||
* {{ my_array|join(', ') }}
|
||||
* // => foo, bar, baz
|
||||
*
|
||||
* @example
|
||||
* // my_key_object = { a: 'foo', b: 'bar', c: 'baz' }
|
||||
* {{ my_key_object|join(' and ') }}
|
||||
* // => foo and bar and baz
|
||||
*
|
||||
* @param {*} input
|
||||
* @param {string} glue String value to join items together.
|
||||
* @return {string}
|
||||
*/
|
||||
exports.join = function (input, glue) {
|
||||
if (utils.isArray(input)) {
|
||||
return input.join(glue);
|
||||
}
|
||||
|
||||
if (typeof input === 'object') {
|
||||
var out = [];
|
||||
utils.each(input, function (value) {
|
||||
out.push(value);
|
||||
});
|
||||
return out.join(glue);
|
||||
}
|
||||
return input;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return a string representation of an JavaScript object.
|
||||
*
|
||||
* Backwards compatible with swig@0.x.x using `json_encode`.
|
||||
*
|
||||
* @example
|
||||
* // val = { a: 'b' }
|
||||
* {{ val|json }}
|
||||
* // => {"a":"b"}
|
||||
*
|
||||
* @example
|
||||
* // val = { a: 'b' }
|
||||
* {{ val|json(4) }}
|
||||
* // => {
|
||||
* // "a": "b"
|
||||
* // }
|
||||
*
|
||||
* @param {*} input
|
||||
* @param {number} [indent] Number of spaces to indent for pretty-formatting.
|
||||
* @return {string} A valid JSON string.
|
||||
*/
|
||||
exports.json = function (input, indent) {
|
||||
return JSON.stringify(input, null, indent || 0);
|
||||
};
|
||||
exports.json_encode = exports.json;
|
||||
|
||||
/**
|
||||
* Get the last item in an array or character in a string. All other objects will attempt to return the last value available.
|
||||
*
|
||||
* @example
|
||||
* // my_arr = ['a', 'b', 'c']
|
||||
* {{ my_arr|last }}
|
||||
* // => c
|
||||
*
|
||||
* @example
|
||||
* // my_val = 'Tacos'
|
||||
* {{ my_val|last }}
|
||||
* // s
|
||||
*
|
||||
* @param {*} input
|
||||
* @return {*} The last item of the array or last character of the string.input.
|
||||
*/
|
||||
exports.last = function (input) {
|
||||
if (typeof input === 'object' && !utils.isArray(input)) {
|
||||
var keys = utils.keys(input);
|
||||
return input[keys[keys.length - 1]];
|
||||
}
|
||||
|
||||
if (typeof input === 'string') {
|
||||
return input.charAt(input.length - 1);
|
||||
}
|
||||
|
||||
return input[input.length - 1];
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the input in all lowercase letters.
|
||||
*
|
||||
* @example
|
||||
* {{ "FOOBAR"|lower }}
|
||||
* // => foobar
|
||||
*
|
||||
* @example
|
||||
* // myObj = { a: 'FOO', b: 'BAR' }
|
||||
* {{ myObj|lower|join('') }}
|
||||
* // => foobar
|
||||
*
|
||||
* @param {*} input
|
||||
* @return {*} Returns the same type as the input.
|
||||
*/
|
||||
exports.lower = function (input) {
|
||||
var out = iterateFilter.apply(exports.lower, arguments);
|
||||
if (out !== undefined) {
|
||||
return out;
|
||||
}
|
||||
|
||||
return input.toString().toLowerCase();
|
||||
};
|
||||
|
||||
/**
|
||||
* Deprecated in favor of <a href="#safe">safe</a>.
|
||||
*/
|
||||
exports.raw = function (input) {
|
||||
return exports.safe(input);
|
||||
};
|
||||
exports.raw.safe = true;
|
||||
|
||||
/**
|
||||
* Returns a new string with the matched search pattern replaced by the given replacement string. Uses JavaScript's built-in String.replace() method.
|
||||
*
|
||||
* @example
|
||||
* // my_var = 'foobar';
|
||||
* {{ my_var|replace('o', 'e', 'g') }}
|
||||
* // => feebar
|
||||
*
|
||||
* @example
|
||||
* // my_var = "farfegnugen";
|
||||
* {{ my_var|replace('^f', 'p') }}
|
||||
* // => parfegnugen
|
||||
*
|
||||
* @example
|
||||
* // my_var = 'a1b2c3';
|
||||
* {{ my_var|replace('\w', '0', 'g') }}
|
||||
* // => 010203
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {string} search String or pattern to replace from the input.
|
||||
* @param {string} replacement String to replace matched pattern.
|
||||
* @param {string} [flags] Regular Expression flags. 'g': global match, 'i': ignore case, 'm': match over multiple lines
|
||||
* @return {string} Replaced string.
|
||||
*/
|
||||
exports.replace = function (input, search, replacement, flags) {
|
||||
var r = new RegExp(search, flags);
|
||||
return input.replace(r, replacement);
|
||||
};
|
||||
|
||||
/**
|
||||
* Reverse sort the input. This is an alias for <code data-language="swig">{{ input|sort(true) }}</code>.
|
||||
*
|
||||
* @example
|
||||
* // val = [1, 2, 3];
|
||||
* {{ val|reverse }}
|
||||
* // => 3,2,1
|
||||
*
|
||||
* @param {array} input
|
||||
* @return {array} Reversed array. The original input object is returned if it was not an array.
|
||||
*/
|
||||
exports.reverse = function (input) {
|
||||
return exports.sort(input, true);
|
||||
};
|
||||
|
||||
/**
|
||||
* Forces the input to not be auto-escaped. Use this only on content that you know is safe to be rendered on your page.
|
||||
*
|
||||
* @example
|
||||
* // my_var = "<p>Stuff</p>";
|
||||
* {{ my_var|safe }}
|
||||
* // => <p>Stuff</p>
|
||||
*
|
||||
* @param {*} input
|
||||
* @return {*} The input exactly how it was given, regardless of autoescaping status.
|
||||
*/
|
||||
exports.safe = function (input) {
|
||||
// This is a magic filter. Its logic is hard-coded into Swig's parser.
|
||||
return input;
|
||||
};
|
||||
exports.safe.safe = true;
|
||||
|
||||
/**
|
||||
* Sort the input in an ascending direction.
|
||||
* If given an object, will return the keys as a sorted array.
|
||||
* If given a string, each character will be sorted individually.
|
||||
*
|
||||
* @example
|
||||
* // val = [2, 6, 4];
|
||||
* {{ val|sort }}
|
||||
* // => 2,4,6
|
||||
*
|
||||
* @example
|
||||
* // val = 'zaq';
|
||||
* {{ val|sort }}
|
||||
* // => aqz
|
||||
*
|
||||
* @example
|
||||
* // val = { bar: 1, foo: 2 }
|
||||
* {{ val|sort(true) }}
|
||||
* // => foo,bar
|
||||
*
|
||||
* @param {*} input
|
||||
* @param {boolean} [reverse=false] Output is given reverse-sorted if true.
|
||||
* @return {*} Sorted array;
|
||||
*/
|
||||
exports.sort = function (input, reverse) {
|
||||
var out;
|
||||
if (utils.isArray(input)) {
|
||||
out = input.sort();
|
||||
} else {
|
||||
switch (typeof input) {
|
||||
case 'object':
|
||||
out = utils.keys(input).sort();
|
||||
break;
|
||||
case 'string':
|
||||
out = input.split('');
|
||||
if (reverse) {
|
||||
return out.reverse().join('');
|
||||
}
|
||||
return out.sort().join('');
|
||||
}
|
||||
}
|
||||
|
||||
if (out && reverse) {
|
||||
return out.reverse();
|
||||
}
|
||||
|
||||
return out || input;
|
||||
};
|
||||
|
||||
/**
|
||||
* Strip HTML tags.
|
||||
*
|
||||
* @example
|
||||
* // stuff = '<p>foobar</p>';
|
||||
* {{ stuff|striptags }}
|
||||
* // => foobar
|
||||
*
|
||||
* @param {*} input
|
||||
* @return {*} Returns the same object as the input, but with all string values stripped of tags.
|
||||
*/
|
||||
exports.striptags = function (input) {
|
||||
var out = iterateFilter.apply(exports.striptags, arguments);
|
||||
if (out !== undefined) {
|
||||
return out;
|
||||
}
|
||||
|
||||
return input.toString().replace(/(<([^>]+)>)/ig, '');
|
||||
};
|
||||
|
||||
/**
|
||||
* Capitalizes every word given and lower-cases all other letters.
|
||||
*
|
||||
* @example
|
||||
* // my_str = 'this is soMe text';
|
||||
* {{ my_str|title }}
|
||||
* // => This Is Some Text
|
||||
*
|
||||
* @example
|
||||
* // my_arr = ['hi', 'this', 'is', 'an', 'array'];
|
||||
* {{ my_arr|title|join(' ') }}
|
||||
* // => Hi This Is An Array
|
||||
*
|
||||
* @param {*} input
|
||||
* @return {*} Returns the same object as the input, but with all words in strings title-cased.
|
||||
*/
|
||||
exports.title = function (input) {
|
||||
var out = iterateFilter.apply(exports.title, arguments);
|
||||
if (out !== undefined) {
|
||||
return out;
|
||||
}
|
||||
|
||||
return input.toString().replace(/\w\S*/g, function (str) {
|
||||
return str.charAt(0).toUpperCase() + str.substr(1).toLowerCase();
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove all duplicate items from an array.
|
||||
*
|
||||
* @example
|
||||
* // my_arr = [1, 2, 3, 4, 4, 3, 2, 1];
|
||||
* {{ my_arr|uniq|join(',') }}
|
||||
* // => 1,2,3,4
|
||||
*
|
||||
* @param {array} input
|
||||
* @return {array} Array with unique items. If input was not an array, the original item is returned untouched.
|
||||
*/
|
||||
exports.uniq = function (input) {
|
||||
var result;
|
||||
|
||||
if (!input || !utils.isArray(input)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
result = [];
|
||||
utils.each(input, function (v) {
|
||||
if (result.indexOf(v) === -1) {
|
||||
result.push(v);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert the input to all uppercase letters. If an object or array is provided, all values will be uppercased.
|
||||
*
|
||||
* @example
|
||||
* // my_str = 'tacos';
|
||||
* {{ my_str|upper }}
|
||||
* // => TACOS
|
||||
*
|
||||
* @example
|
||||
* // my_arr = ['tacos', 'burritos'];
|
||||
* {{ my_arr|upper|join(' & ') }}
|
||||
* // => TACOS & BURRITOS
|
||||
*
|
||||
* @param {*} input
|
||||
* @return {*} Returns the same type as the input, with all strings upper-cased.
|
||||
*/
|
||||
exports.upper = function (input) {
|
||||
var out = iterateFilter.apply(exports.upper, arguments);
|
||||
if (out !== undefined) {
|
||||
return out;
|
||||
}
|
||||
|
||||
return input.toString().toUpperCase();
|
||||
};
|
||||
|
||||
/**
|
||||
* URL-encode a string. If an object or array is passed, all values will be URL-encoded.
|
||||
*
|
||||
* @example
|
||||
* // my_str = 'param=1&anotherParam=2';
|
||||
* {{ my_str|url_encode }}
|
||||
* // => param%3D1%26anotherParam%3D2
|
||||
*
|
||||
* @param {*} input
|
||||
* @return {*} URL-encoded string.
|
||||
*/
|
||||
exports.url_encode = function (input) {
|
||||
var out = iterateFilter.apply(exports.url_encode, arguments);
|
||||
if (out !== undefined) {
|
||||
return out;
|
||||
}
|
||||
return encodeURIComponent(input);
|
||||
};
|
||||
|
||||
/**
|
||||
* URL-decode a string. If an object or array is passed, all values will be URL-decoded.
|
||||
*
|
||||
* @example
|
||||
* // my_str = 'param%3D1%26anotherParam%3D2';
|
||||
* {{ my_str|url_decode }}
|
||||
* // => param=1&anotherParam=2
|
||||
*
|
||||
* @param {*} input
|
||||
* @return {*} URL-decoded string.
|
||||
*/
|
||||
exports.url_decode = function (input) {
|
||||
var out = iterateFilter.apply(exports.url_decode, arguments);
|
||||
if (out !== undefined) {
|
||||
return out;
|
||||
}
|
||||
return decodeURIComponent(input);
|
||||
};
|
||||
306
node_modules/swig/lib/lexer.js
generated
vendored
Normal file
306
node_modules/swig/lib/lexer.js
generated
vendored
Normal file
@@ -0,0 +1,306 @@
|
||||
var utils = require('./utils');
|
||||
|
||||
/**
|
||||
* A lexer token.
|
||||
* @typedef {object} LexerToken
|
||||
* @property {string} match The string that was matched.
|
||||
* @property {number} type Lexer type enum.
|
||||
* @property {number} length Length of the original string processed.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Enum for token types.
|
||||
* @readonly
|
||||
* @enum {number}
|
||||
*/
|
||||
var TYPES = {
|
||||
/** Whitespace */
|
||||
WHITESPACE: 0,
|
||||
/** Plain string */
|
||||
STRING: 1,
|
||||
/** Variable filter */
|
||||
FILTER: 2,
|
||||
/** Empty variable filter */
|
||||
FILTEREMPTY: 3,
|
||||
/** Function */
|
||||
FUNCTION: 4,
|
||||
/** Function with no arguments */
|
||||
FUNCTIONEMPTY: 5,
|
||||
/** Open parenthesis */
|
||||
PARENOPEN: 6,
|
||||
/** Close parenthesis */
|
||||
PARENCLOSE: 7,
|
||||
/** Comma */
|
||||
COMMA: 8,
|
||||
/** Variable */
|
||||
VAR: 9,
|
||||
/** Number */
|
||||
NUMBER: 10,
|
||||
/** Math operator */
|
||||
OPERATOR: 11,
|
||||
/** Open square bracket */
|
||||
BRACKETOPEN: 12,
|
||||
/** Close square bracket */
|
||||
BRACKETCLOSE: 13,
|
||||
/** Key on an object using dot-notation */
|
||||
DOTKEY: 14,
|
||||
/** Start of an array */
|
||||
ARRAYOPEN: 15,
|
||||
/** End of an array
|
||||
* Currently unused
|
||||
ARRAYCLOSE: 16, */
|
||||
/** Open curly brace */
|
||||
CURLYOPEN: 17,
|
||||
/** Close curly brace */
|
||||
CURLYCLOSE: 18,
|
||||
/** Colon (:) */
|
||||
COLON: 19,
|
||||
/** JavaScript-valid comparator */
|
||||
COMPARATOR: 20,
|
||||
/** Boolean logic */
|
||||
LOGIC: 21,
|
||||
/** Boolean logic "not" */
|
||||
NOT: 22,
|
||||
/** true or false */
|
||||
BOOL: 23,
|
||||
/** Variable assignment */
|
||||
ASSIGNMENT: 24,
|
||||
/** Start of a method */
|
||||
METHODOPEN: 25,
|
||||
/** End of a method
|
||||
* Currently unused
|
||||
METHODEND: 26, */
|
||||
/** Unknown type */
|
||||
UNKNOWN: 100
|
||||
},
|
||||
rules = [
|
||||
{
|
||||
type: TYPES.WHITESPACE,
|
||||
regex: [
|
||||
/^\s+/
|
||||
]
|
||||
},
|
||||
{
|
||||
type: TYPES.STRING,
|
||||
regex: [
|
||||
/^""/,
|
||||
/^".*?[^\\]"/,
|
||||
/^''/,
|
||||
/^'.*?[^\\]'/
|
||||
]
|
||||
},
|
||||
{
|
||||
type: TYPES.FILTER,
|
||||
regex: [
|
||||
/^\|\s*(\w+)\(/
|
||||
],
|
||||
idx: 1
|
||||
},
|
||||
{
|
||||
type: TYPES.FILTEREMPTY,
|
||||
regex: [
|
||||
/^\|\s*(\w+)/
|
||||
],
|
||||
idx: 1
|
||||
},
|
||||
{
|
||||
type: TYPES.FUNCTIONEMPTY,
|
||||
regex: [
|
||||
/^\s*(\w+)\(\)/
|
||||
],
|
||||
idx: 1
|
||||
},
|
||||
{
|
||||
type: TYPES.FUNCTION,
|
||||
regex: [
|
||||
/^\s*(\w+)\(/
|
||||
],
|
||||
idx: 1
|
||||
},
|
||||
{
|
||||
type: TYPES.PARENOPEN,
|
||||
regex: [
|
||||
/^\(/
|
||||
]
|
||||
},
|
||||
{
|
||||
type: TYPES.PARENCLOSE,
|
||||
regex: [
|
||||
/^\)/
|
||||
]
|
||||
},
|
||||
{
|
||||
type: TYPES.COMMA,
|
||||
regex: [
|
||||
/^,/
|
||||
]
|
||||
},
|
||||
{
|
||||
type: TYPES.LOGIC,
|
||||
regex: [
|
||||
/^(&&|\|\|)\s*/,
|
||||
/^(and|or)\s+/
|
||||
],
|
||||
idx: 1,
|
||||
replace: {
|
||||
'and': '&&',
|
||||
'or': '||'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: TYPES.COMPARATOR,
|
||||
regex: [
|
||||
/^(===|==|\!==|\!=|<=|<|>=|>|in\s|gte\s|gt\s|lte\s|lt\s)\s*/
|
||||
],
|
||||
idx: 1,
|
||||
replace: {
|
||||
'gte': '>=',
|
||||
'gt': '>',
|
||||
'lte': '<=',
|
||||
'lt': '<'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: TYPES.ASSIGNMENT,
|
||||
regex: [
|
||||
/^(=|\+=|-=|\*=|\/=)/
|
||||
]
|
||||
},
|
||||
{
|
||||
type: TYPES.NOT,
|
||||
regex: [
|
||||
/^\!\s*/,
|
||||
/^not\s+/
|
||||
],
|
||||
replace: {
|
||||
'not': '!'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: TYPES.BOOL,
|
||||
regex: [
|
||||
/^(true|false)\s+/,
|
||||
/^(true|false)$/
|
||||
],
|
||||
idx: 1
|
||||
},
|
||||
{
|
||||
type: TYPES.VAR,
|
||||
regex: [
|
||||
/^[a-zA-Z_$]\w*((\.\$?\w*)+)?/,
|
||||
/^[a-zA-Z_$]\w*/
|
||||
]
|
||||
},
|
||||
{
|
||||
type: TYPES.BRACKETOPEN,
|
||||
regex: [
|
||||
/^\[/
|
||||
]
|
||||
},
|
||||
{
|
||||
type: TYPES.BRACKETCLOSE,
|
||||
regex: [
|
||||
/^\]/
|
||||
]
|
||||
},
|
||||
{
|
||||
type: TYPES.CURLYOPEN,
|
||||
regex: [
|
||||
/^\{/
|
||||
]
|
||||
},
|
||||
{
|
||||
type: TYPES.COLON,
|
||||
regex: [
|
||||
/^\:/
|
||||
]
|
||||
},
|
||||
{
|
||||
type: TYPES.CURLYCLOSE,
|
||||
regex: [
|
||||
/^\}/
|
||||
]
|
||||
},
|
||||
{
|
||||
type: TYPES.DOTKEY,
|
||||
regex: [
|
||||
/^\.(\w+)/
|
||||
],
|
||||
idx: 1
|
||||
},
|
||||
{
|
||||
type: TYPES.NUMBER,
|
||||
regex: [
|
||||
/^[+\-]?\d+(\.\d+)?/
|
||||
]
|
||||
},
|
||||
{
|
||||
type: TYPES.OPERATOR,
|
||||
regex: [
|
||||
/^(\+|\-|\/|\*|%)/
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
exports.types = TYPES;
|
||||
|
||||
/**
|
||||
* Return the token type object for a single chunk of a string.
|
||||
* @param {string} str String chunk.
|
||||
* @return {LexerToken} Defined type, potentially stripped or replaced with more suitable content.
|
||||
* @private
|
||||
*/
|
||||
function reader(str) {
|
||||
var matched;
|
||||
|
||||
utils.some(rules, function (rule) {
|
||||
return utils.some(rule.regex, function (regex) {
|
||||
var match = str.match(regex),
|
||||
normalized;
|
||||
|
||||
if (!match) {
|
||||
return;
|
||||
}
|
||||
|
||||
normalized = match[rule.idx || 0].replace(/\s*$/, '');
|
||||
normalized = (rule.hasOwnProperty('replace') && rule.replace.hasOwnProperty(normalized)) ? rule.replace[normalized] : normalized;
|
||||
|
||||
matched = {
|
||||
match: normalized,
|
||||
type: rule.type,
|
||||
length: match[0].length
|
||||
};
|
||||
return true;
|
||||
});
|
||||
});
|
||||
|
||||
if (!matched) {
|
||||
matched = {
|
||||
match: str,
|
||||
type: TYPES.UNKNOWN,
|
||||
length: str.length
|
||||
};
|
||||
}
|
||||
|
||||
return matched;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a string and break it into separate token types.
|
||||
* @param {string} str
|
||||
* @return {Array.LexerToken} Array of defined types, potentially stripped or replaced with more suitable content.
|
||||
* @private
|
||||
*/
|
||||
exports.read = function (str) {
|
||||
var offset = 0,
|
||||
tokens = [],
|
||||
substr,
|
||||
match;
|
||||
while (offset < str.length) {
|
||||
substr = str.substring(offset);
|
||||
match = reader(substr);
|
||||
offset += match.length;
|
||||
tokens.push(match);
|
||||
}
|
||||
return tokens;
|
||||
};
|
||||
59
node_modules/swig/lib/loaders/filesystem.js
generated
vendored
Normal file
59
node_modules/swig/lib/loaders/filesystem.js
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
var fs = require('fs'),
|
||||
path = require('path');
|
||||
|
||||
/**
|
||||
* Loads templates from the file system.
|
||||
* @alias swig.loaders.fs
|
||||
* @example
|
||||
* swig.setDefaults({ loader: swig.loaders.fs() });
|
||||
* @example
|
||||
* // Load Templates from a specific directory (does not require using relative paths in your templates)
|
||||
* swig.setDefaults({ loader: swig.loaders.fs(__dirname + '/templates' )});
|
||||
* @param {string} [basepath=''] Path to the templates as string. Assigning this value allows you to use semi-absolute paths to templates instead of relative paths.
|
||||
* @param {string} [encoding='utf8'] Template encoding
|
||||
*/
|
||||
module.exports = function (basepath, encoding) {
|
||||
var ret = {};
|
||||
|
||||
encoding = encoding || 'utf8';
|
||||
basepath = (basepath) ? path.normalize(basepath) : null;
|
||||
|
||||
/**
|
||||
* Resolves <var>to</var> to an absolute path or unique identifier. This is used for building correct, normalized, and absolute paths to a given template.
|
||||
* @alias resolve
|
||||
* @param {string} to Non-absolute identifier or pathname to a file.
|
||||
* @param {string} [from] If given, should attempt to find the <var>to</var> path in relation to this given, known path.
|
||||
* @return {string}
|
||||
*/
|
||||
ret.resolve = function (to, from) {
|
||||
if (basepath) {
|
||||
from = basepath;
|
||||
} else {
|
||||
from = (from) ? path.dirname(from) : process.cwd();
|
||||
}
|
||||
return path.resolve(from, to);
|
||||
};
|
||||
|
||||
/**
|
||||
* Loads a single template. Given a unique <var>identifier</var> found by the <var>resolve</var> method this should return the given template.
|
||||
* @alias load
|
||||
* @param {string} identifier Unique identifier of a template (possibly an absolute path).
|
||||
* @param {function} [cb] Asynchronous callback function. If not provided, this method should run synchronously.
|
||||
* @return {string} Template source string.
|
||||
*/
|
||||
ret.load = function (identifier, cb) {
|
||||
if (!fs || (cb && !fs.readFile) || !fs.readFileSync) {
|
||||
throw new Error('Unable to find file ' + identifier + ' because there is no filesystem to read from.');
|
||||
}
|
||||
|
||||
identifier = ret.resolve(identifier);
|
||||
|
||||
if (cb) {
|
||||
fs.readFile(identifier, encoding, cb);
|
||||
return;
|
||||
}
|
||||
return fs.readFileSync(identifier, encoding);
|
||||
};
|
||||
|
||||
return ret;
|
||||
};
|
||||
53
node_modules/swig/lib/loaders/index.js
generated
vendored
Normal file
53
node_modules/swig/lib/loaders/index.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* @namespace TemplateLoader
|
||||
* @description Swig is able to accept custom template loaders written by you, so that your templates can come from your favorite storage medium without needing to be part of the core library.
|
||||
* A template loader consists of two methods: <var>resolve</var> and <var>load</var>. Each method is used internally by Swig to find and load the source of the template before attempting to parse and compile it.
|
||||
* @example
|
||||
* // A theoretical memcached loader
|
||||
* var path = require('path'),
|
||||
* Memcached = require('memcached');
|
||||
* function memcachedLoader(locations, options) {
|
||||
* var memcached = new Memcached(locations, options);
|
||||
* return {
|
||||
* resolve: function (to, from) {
|
||||
* return path.resolve(from, to);
|
||||
* },
|
||||
* load: function (identifier, cb) {
|
||||
* memcached.get(identifier, function (err, data) {
|
||||
* // if (!data) { load from filesystem; }
|
||||
* cb(err, data);
|
||||
* });
|
||||
* }
|
||||
* };
|
||||
* };
|
||||
* // Tell swig about the loader:
|
||||
* swig.setDefaults({ loader: memcachedLoader(['192.168.0.2']) });
|
||||
*/
|
||||
|
||||
/**
|
||||
* @function
|
||||
* @name resolve
|
||||
* @memberof TemplateLoader
|
||||
* @description
|
||||
* Resolves <var>to</var> to an absolute path or unique identifier. This is used for building correct, normalized, and absolute paths to a given template.
|
||||
* @param {string} to Non-absolute identifier or pathname to a file.
|
||||
* @param {string} [from] If given, should attempt to find the <var>to</var> path in relation to this given, known path.
|
||||
* @return {string}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @function
|
||||
* @name load
|
||||
* @memberof TemplateLoader
|
||||
* @description
|
||||
* Loads a single template. Given a unique <var>identifier</var> found by the <var>resolve</var> method this should return the given template.
|
||||
* @param {string} identifier Unique identifier of a template (possibly an absolute path).
|
||||
* @param {function} [cb] Asynchronous callback function. If not provided, this method should run synchronously.
|
||||
* @return {string} Template source string.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
exports.fs = require('./filesystem');
|
||||
exports.memory = require('./memory');
|
||||
63
node_modules/swig/lib/loaders/memory.js
generated
vendored
Normal file
63
node_modules/swig/lib/loaders/memory.js
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
var path = require('path'),
|
||||
utils = require('../utils');
|
||||
|
||||
/**
|
||||
* Loads templates from a provided object mapping.
|
||||
* @alias swig.loaders.memory
|
||||
* @example
|
||||
* var templates = {
|
||||
* "layout": "{% block content %}{% endblock %}",
|
||||
* "home.html": "{% extends 'layout.html' %}{% block content %}...{% endblock %}"
|
||||
* };
|
||||
* swig.setDefaults({ loader: swig.loaders.memory(templates) });
|
||||
*
|
||||
* @param {object} mapping Hash object with template paths as keys and template sources as values.
|
||||
* @param {string} [basepath] Path to the templates as string. Assigning this value allows you to use semi-absolute paths to templates instead of relative paths.
|
||||
*/
|
||||
module.exports = function (mapping, basepath) {
|
||||
var ret = {};
|
||||
|
||||
basepath = (basepath) ? path.normalize(basepath) : null;
|
||||
|
||||
/**
|
||||
* Resolves <var>to</var> to an absolute path or unique identifier. This is used for building correct, normalized, and absolute paths to a given template.
|
||||
* @alias resolve
|
||||
* @param {string} to Non-absolute identifier or pathname to a file.
|
||||
* @param {string} [from] If given, should attempt to find the <var>to</var> path in relation to this given, known path.
|
||||
* @return {string}
|
||||
*/
|
||||
ret.resolve = function (to, from) {
|
||||
if (basepath) {
|
||||
from = basepath;
|
||||
} else {
|
||||
from = (from) ? path.dirname(from) : '/';
|
||||
}
|
||||
return path.resolve(from, to);
|
||||
};
|
||||
|
||||
/**
|
||||
* Loads a single template. Given a unique <var>identifier</var> found by the <var>resolve</var> method this should return the given template.
|
||||
* @alias load
|
||||
* @param {string} identifier Unique identifier of a template (possibly an absolute path).
|
||||
* @param {function} [cb] Asynchronous callback function. If not provided, this method should run synchronously.
|
||||
* @return {string} Template source string.
|
||||
*/
|
||||
ret.load = function (pathname, cb) {
|
||||
var src, paths;
|
||||
|
||||
paths = [pathname, pathname.replace(/^(\/|\\)/, '')];
|
||||
|
||||
src = mapping[paths[0]] || mapping[paths[1]];
|
||||
if (!src) {
|
||||
utils.throwError('Unable to find template "' + pathname + '".');
|
||||
}
|
||||
|
||||
if (cb) {
|
||||
cb(null, src);
|
||||
return;
|
||||
}
|
||||
return src;
|
||||
};
|
||||
|
||||
return ret;
|
||||
};
|
||||
744
node_modules/swig/lib/parser.js
generated
vendored
Normal file
744
node_modules/swig/lib/parser.js
generated
vendored
Normal file
@@ -0,0 +1,744 @@
|
||||
var utils = require('./utils'),
|
||||
lexer = require('./lexer');
|
||||
|
||||
var _t = lexer.types,
|
||||
_reserved = ['break', 'case', 'catch', 'continue', 'debugger', 'default', 'delete', 'do', 'else', 'finally', 'for', 'function', 'if', 'in', 'instanceof', 'new', 'return', 'switch', 'this', 'throw', 'try', 'typeof', 'var', 'void', 'while', 'with'];
|
||||
|
||||
|
||||
/**
|
||||
* Filters are simply functions that perform transformations on their first input argument.
|
||||
* Filters are run at render time, so they may not directly modify the compiled template structure in any way.
|
||||
* All of Swig's built-in filters are written in this same way. For more examples, reference the `filters.js` file in Swig's source.
|
||||
*
|
||||
* To disable auto-escaping on a custom filter, simply add a property to the filter method `safe = true;` and the output from this will not be escaped, no matter what the global settings are for Swig.
|
||||
*
|
||||
* @typedef {function} Filter
|
||||
*
|
||||
* @example
|
||||
* // This filter will return 'bazbop' if the idx on the input is not 'foobar'
|
||||
* swig.setFilter('foobar', function (input, idx) {
|
||||
* return input[idx] === 'foobar' ? input[idx] : 'bazbop';
|
||||
* });
|
||||
* // myvar = ['foo', 'bar', 'baz', 'bop'];
|
||||
* // => {{ myvar|foobar(3) }}
|
||||
* // Since myvar[3] !== 'foobar', we render:
|
||||
* // => bazbop
|
||||
*
|
||||
* @example
|
||||
* // This filter will disable auto-escaping on its output:
|
||||
* function bazbop (input) { return input; }
|
||||
* bazbop.safe = true;
|
||||
* swig.setFilter('bazbop', bazbop);
|
||||
* // => {{ "<p>"|bazbop }}
|
||||
* // => <p>
|
||||
*
|
||||
* @param {*} input Input argument, automatically sent from Swig's built-in parser.
|
||||
* @param {...*} [args] All other arguments are defined by the Filter author.
|
||||
* @return {*}
|
||||
*/
|
||||
|
||||
/*!
|
||||
* Makes a string safe for a regular expression.
|
||||
* @param {string} str
|
||||
* @return {string}
|
||||
* @private
|
||||
*/
|
||||
function escapeRegExp(str) {
|
||||
return str.replace(/[\-\/\\\^$*+?.()|\[\]{}]/g, '\\$&');
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse strings of variables and tags into tokens for future compilation.
|
||||
* @class
|
||||
* @param {array} tokens Pre-split tokens read by the Lexer.
|
||||
* @param {object} filters Keyed object of filters that may be applied to variables.
|
||||
* @param {boolean} autoescape Whether or not this should be autoescaped.
|
||||
* @param {number} line Beginning line number for the first token.
|
||||
* @param {string} [filename] Name of the file being parsed.
|
||||
* @private
|
||||
*/
|
||||
function TokenParser(tokens, filters, autoescape, line, filename) {
|
||||
this.out = [];
|
||||
this.state = [];
|
||||
this.filterApplyIdx = [];
|
||||
this._parsers = {};
|
||||
this.line = line;
|
||||
this.filename = filename;
|
||||
this.filters = filters;
|
||||
this.escape = autoescape;
|
||||
|
||||
this.parse = function () {
|
||||
var self = this;
|
||||
|
||||
if (self._parsers.start) {
|
||||
self._parsers.start.call(self);
|
||||
}
|
||||
utils.each(tokens, function (token, i) {
|
||||
var prevToken = tokens[i - 1];
|
||||
self.isLast = (i === tokens.length - 1);
|
||||
if (prevToken) {
|
||||
while (prevToken.type === _t.WHITESPACE) {
|
||||
i -= 1;
|
||||
prevToken = tokens[i - 1];
|
||||
}
|
||||
}
|
||||
self.prevToken = prevToken;
|
||||
self.parseToken(token);
|
||||
});
|
||||
if (self._parsers.end) {
|
||||
self._parsers.end.call(self);
|
||||
}
|
||||
|
||||
if (self.escape) {
|
||||
self.filterApplyIdx = [0];
|
||||
if (typeof self.escape === 'string') {
|
||||
self.parseToken({ type: _t.FILTER, match: 'e' });
|
||||
self.parseToken({ type: _t.COMMA, match: ',' });
|
||||
self.parseToken({ type: _t.STRING, match: String(autoescape) });
|
||||
self.parseToken({ type: _t.PARENCLOSE, match: ')'});
|
||||
} else {
|
||||
self.parseToken({ type: _t.FILTEREMPTY, match: 'e' });
|
||||
}
|
||||
}
|
||||
|
||||
return self.out;
|
||||
};
|
||||
}
|
||||
|
||||
TokenParser.prototype = {
|
||||
/**
|
||||
* Set a custom method to be called when a token type is found.
|
||||
*
|
||||
* @example
|
||||
* parser.on(types.STRING, function (token) {
|
||||
* this.out.push(token.match);
|
||||
* });
|
||||
* @example
|
||||
* parser.on('start', function () {
|
||||
* this.out.push('something at the beginning of your args')
|
||||
* });
|
||||
* parser.on('end', function () {
|
||||
* this.out.push('something at the end of your args');
|
||||
* });
|
||||
*
|
||||
* @param {number} type Token type ID. Found in the Lexer.
|
||||
* @param {Function} fn Callback function. Return true to continue executing the default parsing function.
|
||||
* @return {undefined}
|
||||
*/
|
||||
on: function (type, fn) {
|
||||
this._parsers[type] = fn;
|
||||
},
|
||||
|
||||
/**
|
||||
* Parse a single token.
|
||||
* @param {{match: string, type: number, line: number}} token Lexer token object.
|
||||
* @return {undefined}
|
||||
* @private
|
||||
*/
|
||||
parseToken: function (token) {
|
||||
var self = this,
|
||||
fn = self._parsers[token.type] || self._parsers['*'],
|
||||
match = token.match,
|
||||
prevToken = self.prevToken,
|
||||
prevTokenType = prevToken ? prevToken.type : null,
|
||||
lastState = (self.state.length) ? self.state[self.state.length - 1] : null,
|
||||
temp;
|
||||
|
||||
if (fn && typeof fn === 'function') {
|
||||
if (!fn.call(this, token)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (lastState && prevToken &&
|
||||
lastState === _t.FILTER &&
|
||||
prevTokenType === _t.FILTER &&
|
||||
token.type !== _t.PARENCLOSE &&
|
||||
token.type !== _t.COMMA &&
|
||||
token.type !== _t.OPERATOR &&
|
||||
token.type !== _t.FILTER &&
|
||||
token.type !== _t.FILTEREMPTY) {
|
||||
self.out.push(', ');
|
||||
}
|
||||
|
||||
if (lastState && lastState === _t.METHODOPEN) {
|
||||
self.state.pop();
|
||||
if (token.type !== _t.PARENCLOSE) {
|
||||
self.out.push(', ');
|
||||
}
|
||||
}
|
||||
|
||||
switch (token.type) {
|
||||
case _t.WHITESPACE:
|
||||
break;
|
||||
|
||||
case _t.STRING:
|
||||
self.filterApplyIdx.push(self.out.length);
|
||||
self.out.push(match.replace(/\\/g, '\\\\'));
|
||||
break;
|
||||
|
||||
case _t.NUMBER:
|
||||
case _t.BOOL:
|
||||
self.filterApplyIdx.push(self.out.length);
|
||||
self.out.push(match);
|
||||
break;
|
||||
|
||||
case _t.FILTER:
|
||||
if (!self.filters.hasOwnProperty(match) || typeof self.filters[match] !== "function") {
|
||||
utils.throwError('Invalid filter "' + match + '"', self.line, self.filename);
|
||||
}
|
||||
self.escape = self.filters[match].safe ? false : self.escape;
|
||||
self.out.splice(self.filterApplyIdx[self.filterApplyIdx.length - 1], 0, '_filters["' + match + '"](');
|
||||
self.state.push(token.type);
|
||||
break;
|
||||
|
||||
case _t.FILTEREMPTY:
|
||||
if (!self.filters.hasOwnProperty(match) || typeof self.filters[match] !== "function") {
|
||||
utils.throwError('Invalid filter "' + match + '"', self.line, self.filename);
|
||||
}
|
||||
self.escape = self.filters[match].safe ? false : self.escape;
|
||||
self.out.splice(self.filterApplyIdx[self.filterApplyIdx.length - 1], 0, '_filters["' + match + '"](');
|
||||
self.out.push(')');
|
||||
break;
|
||||
|
||||
case _t.FUNCTION:
|
||||
case _t.FUNCTIONEMPTY:
|
||||
self.out.push('((typeof _ctx.' + match + ' !== "undefined") ? _ctx.' + match +
|
||||
' : ((typeof ' + match + ' !== "undefined") ? ' + match +
|
||||
' : _fn))(');
|
||||
self.escape = false;
|
||||
if (token.type === _t.FUNCTIONEMPTY) {
|
||||
self.out[self.out.length - 1] = self.out[self.out.length - 1] + ')';
|
||||
} else {
|
||||
self.state.push(token.type);
|
||||
}
|
||||
self.filterApplyIdx.push(self.out.length - 1);
|
||||
break;
|
||||
|
||||
case _t.PARENOPEN:
|
||||
self.state.push(token.type);
|
||||
if (self.filterApplyIdx.length) {
|
||||
self.out.splice(self.filterApplyIdx[self.filterApplyIdx.length - 1], 0, '(');
|
||||
if (prevToken && prevTokenType === _t.VAR) {
|
||||
temp = prevToken.match.split('.').slice(0, -1);
|
||||
self.out.push(' || _fn).call(' + self.checkMatch(temp));
|
||||
self.state.push(_t.METHODOPEN);
|
||||
self.escape = false;
|
||||
} else {
|
||||
self.out.push(' || _fn)(');
|
||||
}
|
||||
self.filterApplyIdx.push(self.out.length - 3);
|
||||
} else {
|
||||
self.out.push('(');
|
||||
self.filterApplyIdx.push(self.out.length - 1);
|
||||
}
|
||||
break;
|
||||
|
||||
case _t.PARENCLOSE:
|
||||
temp = self.state.pop();
|
||||
if (temp !== _t.PARENOPEN && temp !== _t.FUNCTION && temp !== _t.FILTER) {
|
||||
utils.throwError('Mismatched nesting state', self.line, self.filename);
|
||||
}
|
||||
self.out.push(')');
|
||||
// Once off the previous entry
|
||||
self.filterApplyIdx.pop();
|
||||
if (temp !== _t.FILTER) {
|
||||
// Once for the open paren
|
||||
self.filterApplyIdx.pop();
|
||||
}
|
||||
break;
|
||||
|
||||
case _t.COMMA:
|
||||
if (lastState !== _t.FUNCTION &&
|
||||
lastState !== _t.FILTER &&
|
||||
lastState !== _t.ARRAYOPEN &&
|
||||
lastState !== _t.CURLYOPEN &&
|
||||
lastState !== _t.PARENOPEN &&
|
||||
lastState !== _t.COLON) {
|
||||
utils.throwError('Unexpected comma', self.line, self.filename);
|
||||
}
|
||||
if (lastState === _t.COLON) {
|
||||
self.state.pop();
|
||||
}
|
||||
self.out.push(', ');
|
||||
self.filterApplyIdx.pop();
|
||||
break;
|
||||
|
||||
case _t.LOGIC:
|
||||
case _t.COMPARATOR:
|
||||
if (!prevToken ||
|
||||
prevTokenType === _t.COMMA ||
|
||||
prevTokenType === token.type ||
|
||||
prevTokenType === _t.BRACKETOPEN ||
|
||||
prevTokenType === _t.CURLYOPEN ||
|
||||
prevTokenType === _t.PARENOPEN ||
|
||||
prevTokenType === _t.FUNCTION) {
|
||||
utils.throwError('Unexpected logic', self.line, self.filename);
|
||||
}
|
||||
self.out.push(token.match);
|
||||
break;
|
||||
|
||||
case _t.NOT:
|
||||
self.out.push(token.match);
|
||||
break;
|
||||
|
||||
case _t.VAR:
|
||||
self.parseVar(token, match, lastState);
|
||||
break;
|
||||
|
||||
case _t.BRACKETOPEN:
|
||||
if (!prevToken ||
|
||||
(prevTokenType !== _t.VAR &&
|
||||
prevTokenType !== _t.BRACKETCLOSE &&
|
||||
prevTokenType !== _t.PARENCLOSE)) {
|
||||
self.state.push(_t.ARRAYOPEN);
|
||||
self.filterApplyIdx.push(self.out.length);
|
||||
} else {
|
||||
self.state.push(token.type);
|
||||
}
|
||||
self.out.push('[');
|
||||
break;
|
||||
|
||||
case _t.BRACKETCLOSE:
|
||||
temp = self.state.pop();
|
||||
if (temp !== _t.BRACKETOPEN && temp !== _t.ARRAYOPEN) {
|
||||
utils.throwError('Unexpected closing square bracket', self.line, self.filename);
|
||||
}
|
||||
self.out.push(']');
|
||||
self.filterApplyIdx.pop();
|
||||
break;
|
||||
|
||||
case _t.CURLYOPEN:
|
||||
self.state.push(token.type);
|
||||
self.out.push('{');
|
||||
self.filterApplyIdx.push(self.out.length - 1);
|
||||
break;
|
||||
|
||||
case _t.COLON:
|
||||
if (lastState !== _t.CURLYOPEN) {
|
||||
utils.throwError('Unexpected colon', self.line, self.filename);
|
||||
}
|
||||
self.state.push(token.type);
|
||||
self.out.push(':');
|
||||
self.filterApplyIdx.pop();
|
||||
break;
|
||||
|
||||
case _t.CURLYCLOSE:
|
||||
if (lastState === _t.COLON) {
|
||||
self.state.pop();
|
||||
}
|
||||
if (self.state.pop() !== _t.CURLYOPEN) {
|
||||
utils.throwError('Unexpected closing curly brace', self.line, self.filename);
|
||||
}
|
||||
self.out.push('}');
|
||||
|
||||
self.filterApplyIdx.pop();
|
||||
break;
|
||||
|
||||
case _t.DOTKEY:
|
||||
if (!prevToken || (
|
||||
prevTokenType !== _t.VAR &&
|
||||
prevTokenType !== _t.BRACKETCLOSE &&
|
||||
prevTokenType !== _t.DOTKEY &&
|
||||
prevTokenType !== _t.PARENCLOSE &&
|
||||
prevTokenType !== _t.FUNCTIONEMPTY &&
|
||||
prevTokenType !== _t.FILTEREMPTY &&
|
||||
prevTokenType !== _t.CURLYCLOSE
|
||||
)) {
|
||||
utils.throwError('Unexpected key "' + match + '"', self.line, self.filename);
|
||||
}
|
||||
self.out.push('.' + match);
|
||||
break;
|
||||
|
||||
case _t.OPERATOR:
|
||||
self.out.push(' ' + match + ' ');
|
||||
self.filterApplyIdx.pop();
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Parse variable token
|
||||
* @param {{match: string, type: number, line: number}} token Lexer token object.
|
||||
* @param {string} match Shortcut for token.match
|
||||
* @param {number} lastState Lexer token type state.
|
||||
* @return {undefined}
|
||||
* @private
|
||||
*/
|
||||
parseVar: function (token, match, lastState) {
|
||||
var self = this;
|
||||
|
||||
match = match.split('.');
|
||||
|
||||
if (_reserved.indexOf(match[0]) !== -1) {
|
||||
utils.throwError('Reserved keyword "' + match[0] + '" attempted to be used as a variable', self.line, self.filename);
|
||||
}
|
||||
|
||||
self.filterApplyIdx.push(self.out.length);
|
||||
if (lastState === _t.CURLYOPEN) {
|
||||
if (match.length > 1) {
|
||||
utils.throwError('Unexpected dot', self.line, self.filename);
|
||||
}
|
||||
self.out.push(match[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
self.out.push(self.checkMatch(match));
|
||||
},
|
||||
|
||||
/**
|
||||
* Return contextual dot-check string for a match
|
||||
* @param {string} match Shortcut for token.match
|
||||
* @private
|
||||
*/
|
||||
checkMatch: function (match) {
|
||||
var temp = match[0], result;
|
||||
|
||||
function checkDot(ctx) {
|
||||
var c = ctx + temp,
|
||||
m = match,
|
||||
build = '';
|
||||
|
||||
build = '(typeof ' + c + ' !== "undefined" && ' + c + ' !== null';
|
||||
utils.each(m, function (v, i) {
|
||||
if (i === 0) {
|
||||
return;
|
||||
}
|
||||
build += ' && ' + c + '.' + v + ' !== undefined && ' + c + '.' + v + ' !== null';
|
||||
c += '.' + v;
|
||||
});
|
||||
build += ')';
|
||||
|
||||
return build;
|
||||
}
|
||||
|
||||
function buildDot(ctx) {
|
||||
return '(' + checkDot(ctx) + ' ? ' + ctx + match.join('.') + ' : "")';
|
||||
}
|
||||
result = '(' + checkDot('_ctx.') + ' ? ' + buildDot('_ctx.') + ' : ' + buildDot('') + ')';
|
||||
return '(' + result + ' !== null ? ' + result + ' : ' + '"" )';
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse a source string into tokens that are ready for compilation.
|
||||
*
|
||||
* @example
|
||||
* exports.parse('{{ tacos }}', {}, tags, filters);
|
||||
* // => [{ compile: [Function], ... }]
|
||||
*
|
||||
* @params {object} swig The current Swig instance
|
||||
* @param {string} source Swig template source.
|
||||
* @param {object} opts Swig options object.
|
||||
* @param {object} tags Keyed object of tags that can be parsed and compiled.
|
||||
* @param {object} filters Keyed object of filters that may be applied to variables.
|
||||
* @return {array} List of tokens ready for compilation.
|
||||
*/
|
||||
exports.parse = function (swig, source, opts, tags, filters) {
|
||||
source = source.replace(/\r\n/g, '\n');
|
||||
var escape = opts.autoescape,
|
||||
tagOpen = opts.tagControls[0],
|
||||
tagClose = opts.tagControls[1],
|
||||
varOpen = opts.varControls[0],
|
||||
varClose = opts.varControls[1],
|
||||
escapedTagOpen = escapeRegExp(tagOpen),
|
||||
escapedTagClose = escapeRegExp(tagClose),
|
||||
escapedVarOpen = escapeRegExp(varOpen),
|
||||
escapedVarClose = escapeRegExp(varClose),
|
||||
tagStrip = new RegExp('^' + escapedTagOpen + '-?\\s*-?|-?\\s*-?' + escapedTagClose + '$', 'g'),
|
||||
tagStripBefore = new RegExp('^' + escapedTagOpen + '-'),
|
||||
tagStripAfter = new RegExp('-' + escapedTagClose + '$'),
|
||||
varStrip = new RegExp('^' + escapedVarOpen + '-?\\s*-?|-?\\s*-?' + escapedVarClose + '$', 'g'),
|
||||
varStripBefore = new RegExp('^' + escapedVarOpen + '-'),
|
||||
varStripAfter = new RegExp('-' + escapedVarClose + '$'),
|
||||
cmtOpen = opts.cmtControls[0],
|
||||
cmtClose = opts.cmtControls[1],
|
||||
anyChar = '[\\s\\S]*?',
|
||||
// Split the template source based on variable, tag, and comment blocks
|
||||
// /(\{%[\s\S]*?%\}|\{\{[\s\S]*?\}\}|\{#[\s\S]*?#\})/
|
||||
splitter = new RegExp(
|
||||
'(' +
|
||||
escapedTagOpen + anyChar + escapedTagClose + '|' +
|
||||
escapedVarOpen + anyChar + escapedVarClose + '|' +
|
||||
escapeRegExp(cmtOpen) + anyChar + escapeRegExp(cmtClose) +
|
||||
')'
|
||||
),
|
||||
line = 1,
|
||||
stack = [],
|
||||
parent = null,
|
||||
tokens = [],
|
||||
blocks = {},
|
||||
inRaw = false,
|
||||
stripNext;
|
||||
|
||||
/**
|
||||
* Parse a variable.
|
||||
* @param {string} str String contents of the variable, between <i>{{</i> and <i>}}</i>
|
||||
* @param {number} line The line number that this variable starts on.
|
||||
* @return {VarToken} Parsed variable token object.
|
||||
* @private
|
||||
*/
|
||||
function parseVariable(str, line) {
|
||||
var tokens = lexer.read(utils.strip(str)),
|
||||
parser,
|
||||
out;
|
||||
|
||||
parser = new TokenParser(tokens, filters, escape, line, opts.filename);
|
||||
out = parser.parse().join('');
|
||||
|
||||
if (parser.state.length) {
|
||||
utils.throwError('Unable to parse "' + str + '"', line, opts.filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* A parsed variable token.
|
||||
* @typedef {object} VarToken
|
||||
* @property {function} compile Method for compiling this token.
|
||||
*/
|
||||
return {
|
||||
compile: function () {
|
||||
return '_output += ' + out + ';\n';
|
||||
}
|
||||
};
|
||||
}
|
||||
exports.parseVariable = parseVariable;
|
||||
|
||||
/**
|
||||
* Parse a tag.
|
||||
* @param {string} str String contents of the tag, between <i>{%</i> and <i>%}</i>
|
||||
* @param {number} line The line number that this tag starts on.
|
||||
* @return {TagToken} Parsed token object.
|
||||
* @private
|
||||
*/
|
||||
function parseTag(str, line) {
|
||||
var tokens, parser, chunks, tagName, tag, args, last;
|
||||
|
||||
if (utils.startsWith(str, 'end')) {
|
||||
last = stack[stack.length - 1];
|
||||
if (last && last.name === str.split(/\s+/)[0].replace(/^end/, '') && last.ends) {
|
||||
switch (last.name) {
|
||||
case 'autoescape':
|
||||
escape = opts.autoescape;
|
||||
break;
|
||||
case 'raw':
|
||||
inRaw = false;
|
||||
break;
|
||||
}
|
||||
stack.pop();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!inRaw) {
|
||||
utils.throwError('Unexpected end of tag "' + str.replace(/^end/, '') + '"', line, opts.filename);
|
||||
}
|
||||
}
|
||||
|
||||
if (inRaw) {
|
||||
return;
|
||||
}
|
||||
|
||||
chunks = str.split(/\s+(.+)?/);
|
||||
tagName = chunks.shift();
|
||||
|
||||
if (!tags.hasOwnProperty(tagName)) {
|
||||
utils.throwError('Unexpected tag "' + str + '"', line, opts.filename);
|
||||
}
|
||||
|
||||
tokens = lexer.read(utils.strip(chunks.join(' ')));
|
||||
parser = new TokenParser(tokens, filters, false, line, opts.filename);
|
||||
tag = tags[tagName];
|
||||
|
||||
/**
|
||||
* Define custom parsing methods for your tag.
|
||||
* @callback parse
|
||||
*
|
||||
* @example
|
||||
* exports.parse = function (str, line, parser, types, options, swig) {
|
||||
* parser.on('start', function () {
|
||||
* // ...
|
||||
* });
|
||||
* parser.on(types.STRING, function (token) {
|
||||
* // ...
|
||||
* });
|
||||
* };
|
||||
*
|
||||
* @param {string} str The full token string of the tag.
|
||||
* @param {number} line The line number that this tag appears on.
|
||||
* @param {TokenParser} parser A TokenParser instance.
|
||||
* @param {TYPES} types Lexer token type enum.
|
||||
* @param {TagToken[]} stack The current stack of open tags.
|
||||
* @param {SwigOpts} options Swig Options Object.
|
||||
* @param {object} swig The Swig instance (gives acces to loaders, parsers, etc)
|
||||
*/
|
||||
if (!tag.parse(chunks[1], line, parser, _t, stack, opts, swig)) {
|
||||
utils.throwError('Unexpected tag "' + tagName + '"', line, opts.filename);
|
||||
}
|
||||
|
||||
parser.parse();
|
||||
args = parser.out;
|
||||
|
||||
switch (tagName) {
|
||||
case 'autoescape':
|
||||
escape = (args[0] !== 'false') ? args[0] : false;
|
||||
break;
|
||||
case 'raw':
|
||||
inRaw = true;
|
||||
break;
|
||||
}
|
||||
|
||||
/**
|
||||
* A parsed tag token.
|
||||
* @typedef {Object} TagToken
|
||||
* @property {compile} [compile] Method for compiling this token.
|
||||
* @property {array} [args] Array of arguments for the tag.
|
||||
* @property {Token[]} [content=[]] An array of tokens that are children of this Token.
|
||||
* @property {boolean} [ends] Whether or not this tag requires an end tag.
|
||||
* @property {string} name The name of this tag.
|
||||
*/
|
||||
return {
|
||||
block: !!tags[tagName].block,
|
||||
compile: tag.compile,
|
||||
args: args,
|
||||
content: [],
|
||||
ends: tag.ends,
|
||||
name: tagName
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip the whitespace from the previous token, if it is a string.
|
||||
* @param {object} token Parsed token.
|
||||
* @return {object} If the token was a string, trailing whitespace will be stripped.
|
||||
*/
|
||||
function stripPrevToken(token) {
|
||||
if (typeof token === 'string') {
|
||||
token = token.replace(/\s*$/, '');
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Loop over the source, split via the tag/var/comment regular expression splitter.
|
||||
* Send each chunk to the appropriate parser.
|
||||
*/
|
||||
utils.each(source.split(splitter), function (chunk) {
|
||||
var token, lines, stripPrev, prevToken, prevChildToken;
|
||||
|
||||
if (!chunk) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Is a variable?
|
||||
if (!inRaw && utils.startsWith(chunk, varOpen) && utils.endsWith(chunk, varClose)) {
|
||||
stripPrev = varStripBefore.test(chunk);
|
||||
stripNext = varStripAfter.test(chunk);
|
||||
token = parseVariable(chunk.replace(varStrip, ''), line);
|
||||
// Is a tag?
|
||||
} else if (utils.startsWith(chunk, tagOpen) && utils.endsWith(chunk, tagClose)) {
|
||||
stripPrev = tagStripBefore.test(chunk);
|
||||
stripNext = tagStripAfter.test(chunk);
|
||||
token = parseTag(chunk.replace(tagStrip, ''), line);
|
||||
if (token) {
|
||||
if (token.name === 'extends') {
|
||||
parent = token.args.join('').replace(/^\'|\'$/g, '').replace(/^\"|\"$/g, '');
|
||||
} else if (token.block && !stack.length) {
|
||||
blocks[token.args.join('')] = token;
|
||||
}
|
||||
}
|
||||
if (inRaw && !token) {
|
||||
token = chunk;
|
||||
}
|
||||
// Is a content string?
|
||||
} else if (inRaw || (!utils.startsWith(chunk, cmtOpen) && !utils.endsWith(chunk, cmtClose))) {
|
||||
token = (stripNext) ? chunk.replace(/^\s*/, '') : chunk;
|
||||
stripNext = false;
|
||||
} else if (utils.startsWith(chunk, cmtOpen) && utils.endsWith(chunk, cmtClose)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Did this tag ask to strip previous whitespace? <code>{%- ... %}</code> or <code>{{- ... }}</code>
|
||||
if (stripPrev && tokens.length) {
|
||||
prevToken = tokens.pop();
|
||||
if (typeof prevToken === 'string') {
|
||||
prevToken = stripPrevToken(prevToken);
|
||||
} else if (prevToken.content && prevToken.content.length) {
|
||||
prevChildToken = stripPrevToken(prevToken.content.pop());
|
||||
prevToken.content.push(prevChildToken);
|
||||
}
|
||||
tokens.push(prevToken);
|
||||
}
|
||||
|
||||
// This was a comment, so let's just keep going.
|
||||
if (!token) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If there's an open item in the stack, add this to its content.
|
||||
if (stack.length) {
|
||||
stack[stack.length - 1].content.push(token);
|
||||
} else {
|
||||
tokens.push(token);
|
||||
}
|
||||
|
||||
// If the token is a tag that requires an end tag, open it on the stack.
|
||||
if (token.name && token.ends) {
|
||||
stack.push(token);
|
||||
}
|
||||
|
||||
lines = chunk.match(/\n/g);
|
||||
line += (lines) ? lines.length : 0;
|
||||
});
|
||||
|
||||
return {
|
||||
name: opts.filename,
|
||||
parent: parent,
|
||||
tokens: tokens,
|
||||
blocks: blocks
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Compile an array of tokens.
|
||||
* @param {Token[]} template An array of template tokens.
|
||||
* @param {Templates[]} parents Array of parent templates.
|
||||
* @param {SwigOpts} [options] Swig options object.
|
||||
* @param {string} [blockName] Name of the current block context.
|
||||
* @return {string} Partial for a compiled JavaScript method that will output a rendered template.
|
||||
*/
|
||||
exports.compile = function (template, parents, options, blockName) {
|
||||
var out = '',
|
||||
tokens = utils.isArray(template) ? template : template.tokens;
|
||||
|
||||
utils.each(tokens, function (token) {
|
||||
var o;
|
||||
if (typeof token === 'string') {
|
||||
out += '_output += "' + token.replace(/\\/g, '\\\\').replace(/\n|\r/g, '\\n').replace(/"/g, '\\"') + '";\n';
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile callback for VarToken and TagToken objects.
|
||||
* @callback compile
|
||||
*
|
||||
* @example
|
||||
* exports.compile = function (compiler, args, content, parents, options, blockName) {
|
||||
* if (args[0] === 'foo') {
|
||||
* return compiler(content, parents, options, blockName) + '\n';
|
||||
* }
|
||||
* return '_output += "fallback";\n';
|
||||
* };
|
||||
*
|
||||
* @param {parserCompiler} compiler
|
||||
* @param {array} [args] Array of parsed arguments on the for the token.
|
||||
* @param {array} [content] Array of content within the token.
|
||||
* @param {array} [parents] Array of parent templates for the current template context.
|
||||
* @param {SwigOpts} [options] Swig Options Object
|
||||
* @param {string} [blockName] Name of the direct block parent, if any.
|
||||
*/
|
||||
o = token.compile(exports.compile, token.args ? token.args.slice(0) : [], token.content ? token.content.slice(0) : [], parents, options, blockName);
|
||||
out += o || '';
|
||||
});
|
||||
|
||||
return out;
|
||||
};
|
||||
740
node_modules/swig/lib/swig.js
generated
vendored
Normal file
740
node_modules/swig/lib/swig.js
generated
vendored
Normal file
@@ -0,0 +1,740 @@
|
||||
var utils = require('./utils'),
|
||||
_tags = require('./tags'),
|
||||
_filters = require('./filters'),
|
||||
parser = require('./parser'),
|
||||
dateformatter = require('./dateformatter'),
|
||||
loaders = require('./loaders');
|
||||
|
||||
/**
|
||||
* Swig version number as a string.
|
||||
* @example
|
||||
* if (swig.version === "1.4.2") { ... }
|
||||
*
|
||||
* @type {String}
|
||||
*/
|
||||
exports.version = "1.4.2";
|
||||
|
||||
/**
|
||||
* Swig Options Object. This object can be passed to many of the API-level Swig methods to control various aspects of the engine. All keys are optional.
|
||||
* @typedef {Object} SwigOpts
|
||||
* @property {boolean} autoescape Controls whether or not variable output will automatically be escaped for safe HTML output. Defaults to <code data-language="js">true</code>. Functions executed in variable statements will not be auto-escaped. Your application/functions should take care of their own auto-escaping.
|
||||
* @property {array} varControls Open and close controls for variables. Defaults to <code data-language="js">['{{', '}}']</code>.
|
||||
* @property {array} tagControls Open and close controls for tags. Defaults to <code data-language="js">['{%', '%}']</code>.
|
||||
* @property {array} cmtControls Open and close controls for comments. Defaults to <code data-language="js">['{#', '#}']</code>.
|
||||
* @property {object} locals Default variable context to be passed to <strong>all</strong> templates.
|
||||
* @property {CacheOptions} cache Cache control for templates. Defaults to saving in <code data-language="js">'memory'</code>. Send <code data-language="js">false</code> to disable. Send an object with <code data-language="js">get</code> and <code data-language="js">set</code> functions to customize.
|
||||
* @property {TemplateLoader} loader The method that Swig will use to load templates. Defaults to <var>swig.loaders.fs</var>.
|
||||
*/
|
||||
var defaultOptions = {
|
||||
autoescape: true,
|
||||
varControls: ['{{', '}}'],
|
||||
tagControls: ['{%', '%}'],
|
||||
cmtControls: ['{#', '#}'],
|
||||
locals: {},
|
||||
/**
|
||||
* Cache control for templates. Defaults to saving all templates into memory.
|
||||
* @typedef {boolean|string|object} CacheOptions
|
||||
* @example
|
||||
* // Default
|
||||
* swig.setDefaults({ cache: 'memory' });
|
||||
* @example
|
||||
* // Disables caching in Swig.
|
||||
* swig.setDefaults({ cache: false });
|
||||
* @example
|
||||
* // Custom cache storage and retrieval
|
||||
* swig.setDefaults({
|
||||
* cache: {
|
||||
* get: function (key) { ... },
|
||||
* set: function (key, val) { ... }
|
||||
* }
|
||||
* });
|
||||
*/
|
||||
cache: 'memory',
|
||||
/**
|
||||
* Configure Swig to use either the <var>swig.loaders.fs</var> or <var>swig.loaders.memory</var> template loader. Or, you can write your own!
|
||||
* For more information, please see the <a href="../loaders/">Template Loaders documentation</a>.
|
||||
* @typedef {class} TemplateLoader
|
||||
* @example
|
||||
* // Default, FileSystem loader
|
||||
* swig.setDefaults({ loader: swig.loaders.fs() });
|
||||
* @example
|
||||
* // FileSystem loader allowing a base path
|
||||
* // With this, you don't use relative URLs in your template references
|
||||
* swig.setDefaults({ loader: swig.loaders.fs(__dirname + '/templates') });
|
||||
* @example
|
||||
* // Memory Loader
|
||||
* swig.setDefaults({ loader: swig.loaders.memory({
|
||||
* layout: '{% block foo %}{% endblock %}',
|
||||
* page1: '{% extends "layout" %}{% block foo %}Tacos!{% endblock %}'
|
||||
* })});
|
||||
*/
|
||||
loader: loaders.fs()
|
||||
},
|
||||
defaultInstance;
|
||||
|
||||
/**
|
||||
* Empty function, used in templates.
|
||||
* @return {string} Empty string
|
||||
* @private
|
||||
*/
|
||||
function efn() { return ''; }
|
||||
|
||||
/**
|
||||
* Validate the Swig options object.
|
||||
* @param {?SwigOpts} options Swig options object.
|
||||
* @return {undefined} This method will throw errors if anything is wrong.
|
||||
* @private
|
||||
*/
|
||||
function validateOptions(options) {
|
||||
if (!options) {
|
||||
return;
|
||||
}
|
||||
|
||||
utils.each(['varControls', 'tagControls', 'cmtControls'], function (key) {
|
||||
if (!options.hasOwnProperty(key)) {
|
||||
return;
|
||||
}
|
||||
if (!utils.isArray(options[key]) || options[key].length !== 2) {
|
||||
throw new Error('Option "' + key + '" must be an array containing 2 different control strings.');
|
||||
}
|
||||
if (options[key][0] === options[key][1]) {
|
||||
throw new Error('Option "' + key + '" open and close controls must not be the same.');
|
||||
}
|
||||
utils.each(options[key], function (a, i) {
|
||||
if (a.length < 2) {
|
||||
throw new Error('Option "' + key + '" ' + ((i) ? 'open ' : 'close ') + 'control must be at least 2 characters. Saw "' + a + '" instead.');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (options.hasOwnProperty('cache')) {
|
||||
if (options.cache && options.cache !== 'memory') {
|
||||
if (!options.cache.get || !options.cache.set) {
|
||||
throw new Error('Invalid cache option ' + JSON.stringify(options.cache) + ' found. Expected "memory" or { get: function (key) { ... }, set: function (key, value) { ... } }.');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (options.hasOwnProperty('loader')) {
|
||||
if (options.loader) {
|
||||
if (!options.loader.load || !options.loader.resolve) {
|
||||
throw new Error('Invalid loader option ' + JSON.stringify(options.loader) + ' found. Expected { load: function (pathname, cb) { ... }, resolve: function (to, from) { ... } }.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set defaults for the base and all new Swig environments.
|
||||
*
|
||||
* @example
|
||||
* swig.setDefaults({ cache: false });
|
||||
* // => Disables Cache
|
||||
*
|
||||
* @example
|
||||
* swig.setDefaults({ locals: { now: function () { return new Date(); } }});
|
||||
* // => sets a globally accessible method for all template
|
||||
* // contexts, allowing you to print the current date
|
||||
* // => {{ now()|date('F jS, Y') }}
|
||||
*
|
||||
* @param {SwigOpts} [options={}] Swig options object.
|
||||
* @return {undefined}
|
||||
*/
|
||||
exports.setDefaults = function (options) {
|
||||
validateOptions(options);
|
||||
defaultInstance.options = utils.extend(defaultInstance.options, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the default TimeZone offset for date formatting via the date filter. This is a global setting and will affect all Swig environments, old or new.
|
||||
* @param {number} offset Offset from GMT, in minutes.
|
||||
* @return {undefined}
|
||||
*/
|
||||
exports.setDefaultTZOffset = function (offset) {
|
||||
dateformatter.tzOffset = offset;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new, separate Swig compile/render environment.
|
||||
*
|
||||
* @example
|
||||
* var swig = require('swig');
|
||||
* var myswig = new swig.Swig({varControls: ['<%=', '%>']});
|
||||
* myswig.render('Tacos are <%= tacos =>!', { locals: { tacos: 'delicious' }});
|
||||
* // => Tacos are delicious!
|
||||
* swig.render('Tacos are <%= tacos =>!', { locals: { tacos: 'delicious' }});
|
||||
* // => 'Tacos are <%= tacos =>!'
|
||||
*
|
||||
* @param {SwigOpts} [opts={}] Swig options object.
|
||||
* @return {object} New Swig environment.
|
||||
*/
|
||||
exports.Swig = function (opts) {
|
||||
validateOptions(opts);
|
||||
this.options = utils.extend({}, defaultOptions, opts || {});
|
||||
this.cache = {};
|
||||
this.extensions = {};
|
||||
var self = this,
|
||||
tags = _tags,
|
||||
filters = _filters;
|
||||
|
||||
/**
|
||||
* Get combined locals context.
|
||||
* @param {?SwigOpts} [options] Swig options object.
|
||||
* @return {object} Locals context.
|
||||
* @private
|
||||
*/
|
||||
function getLocals(options) {
|
||||
if (!options || !options.locals) {
|
||||
return self.options.locals;
|
||||
}
|
||||
|
||||
return utils.extend({}, self.options.locals, options.locals);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether caching is enabled via the options provided and/or defaults
|
||||
* @param {SwigOpts} [options={}] Swig Options Object
|
||||
* @return {boolean}
|
||||
* @private
|
||||
*/
|
||||
function shouldCache(options) {
|
||||
options = options || {};
|
||||
return (options.hasOwnProperty('cache') && !options.cache) || !self.options.cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get compiled template from the cache.
|
||||
* @param {string} key Name of template.
|
||||
* @return {object|undefined} Template function and tokens.
|
||||
* @private
|
||||
*/
|
||||
function cacheGet(key, options) {
|
||||
if (shouldCache(options)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.options.cache === 'memory') {
|
||||
return self.cache[key];
|
||||
}
|
||||
|
||||
return self.options.cache.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a template in the cache.
|
||||
* @param {string} key Name of template.
|
||||
* @param {object} val Template function and tokens.
|
||||
* @return {undefined}
|
||||
* @private
|
||||
*/
|
||||
function cacheSet(key, options, val) {
|
||||
if (shouldCache(options)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.options.cache === 'memory') {
|
||||
self.cache[key] = val;
|
||||
return;
|
||||
}
|
||||
|
||||
self.options.cache.set(key, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the in-memory template cache.
|
||||
*
|
||||
* @example
|
||||
* swig.invalidateCache();
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
this.invalidateCache = function () {
|
||||
if (self.options.cache === 'memory') {
|
||||
self.cache = {};
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a custom filter for swig variables.
|
||||
*
|
||||
* @example
|
||||
* function replaceMs(input) { return input.replace(/m/g, 'f'); }
|
||||
* swig.setFilter('replaceMs', replaceMs);
|
||||
* // => {{ "onomatopoeia"|replaceMs }}
|
||||
* // => onofatopeia
|
||||
*
|
||||
* @param {string} name Name of filter, used in templates. <strong>Will</strong> overwrite previously defined filters, if using the same name.
|
||||
* @param {function} method Function that acts against the input. See <a href="/docs/filters/#custom">Custom Filters</a> for more information.
|
||||
* @return {undefined}
|
||||
*/
|
||||
this.setFilter = function (name, method) {
|
||||
if (typeof method !== "function") {
|
||||
throw new Error('Filter "' + name + '" is not a valid function.');
|
||||
}
|
||||
filters[name] = method;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a custom tag. To expose your own extensions to compiled template code, see <code data-language="js">swig.setExtension</code>.
|
||||
*
|
||||
* For a more in-depth explanation of writing custom tags, see <a href="../extending/#tags">Custom Tags</a>.
|
||||
*
|
||||
* @example
|
||||
* var tacotag = require('./tacotag');
|
||||
* swig.setTag('tacos', tacotag.parse, tacotag.compile, tacotag.ends, tacotag.blockLevel);
|
||||
* // => {% tacos %}Make this be tacos.{% endtacos %}
|
||||
* // => Tacos tacos tacos tacos.
|
||||
*
|
||||
* @param {string} name Tag name.
|
||||
* @param {function} parse Method for parsing tokens.
|
||||
* @param {function} compile Method for compiling renderable output.
|
||||
* @param {boolean} [ends=false] Whether or not this tag requires an <i>end</i> tag.
|
||||
* @param {boolean} [blockLevel=false] If false, this tag will not be compiled outside of <code>block</code> tags when extending a parent template.
|
||||
* @return {undefined}
|
||||
*/
|
||||
this.setTag = function (name, parse, compile, ends, blockLevel) {
|
||||
if (typeof parse !== 'function') {
|
||||
throw new Error('Tag "' + name + '" parse method is not a valid function.');
|
||||
}
|
||||
|
||||
if (typeof compile !== 'function') {
|
||||
throw new Error('Tag "' + name + '" compile method is not a valid function.');
|
||||
}
|
||||
|
||||
tags[name] = {
|
||||
parse: parse,
|
||||
compile: compile,
|
||||
ends: ends || false,
|
||||
block: !!blockLevel
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Add extensions for custom tags. This allows any custom tag to access a globally available methods via a special globally available object, <var>_ext</var>, in templates.
|
||||
*
|
||||
* @example
|
||||
* swig.setExtension('trans', function (v) { return translate(v); });
|
||||
* function compileTrans(compiler, args, content, parent, options) {
|
||||
* return '_output += _ext.trans(' + args[0] + ');'
|
||||
* };
|
||||
* swig.setTag('trans', parseTrans, compileTrans, true);
|
||||
*
|
||||
* @param {string} name Key name of the extension. Accessed via <code data-language="js">_ext[name]</code>.
|
||||
* @param {*} object The method, value, or object that should be available via the given name.
|
||||
* @return {undefined}
|
||||
*/
|
||||
this.setExtension = function (name, object) {
|
||||
self.extensions[name] = object;
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse a given source string into tokens.
|
||||
*
|
||||
* @param {string} source Swig template source.
|
||||
* @param {SwigOpts} [options={}] Swig options object.
|
||||
* @return {object} parsed Template tokens object.
|
||||
* @private
|
||||
*/
|
||||
this.parse = function (source, options) {
|
||||
validateOptions(options);
|
||||
|
||||
var locals = getLocals(options),
|
||||
opts = {},
|
||||
k;
|
||||
|
||||
for (k in options) {
|
||||
if (options.hasOwnProperty(k) && k !== 'locals') {
|
||||
opts[k] = options[k];
|
||||
}
|
||||
}
|
||||
|
||||
options = utils.extend({}, self.options, opts);
|
||||
options.locals = locals;
|
||||
|
||||
return parser.parse(this, source, options, tags, filters);
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse a given file into tokens.
|
||||
*
|
||||
* @param {string} pathname Full path to file to parse.
|
||||
* @param {SwigOpts} [options={}] Swig options object.
|
||||
* @return {object} parsed Template tokens object.
|
||||
* @private
|
||||
*/
|
||||
this.parseFile = function (pathname, options) {
|
||||
var src;
|
||||
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
pathname = self.options.loader.resolve(pathname, options.resolveFrom);
|
||||
|
||||
src = self.options.loader.load(pathname);
|
||||
|
||||
if (!options.filename) {
|
||||
options = utils.extend({ filename: pathname }, options);
|
||||
}
|
||||
|
||||
return self.parse(src, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Re-Map blocks within a list of tokens to the template's block objects.
|
||||
* @param {array} tokens List of tokens for the parent object.
|
||||
* @param {object} template Current template that needs to be mapped to the parent's block and token list.
|
||||
* @return {array}
|
||||
* @private
|
||||
*/
|
||||
function remapBlocks(blocks, tokens) {
|
||||
return utils.map(tokens, function (token) {
|
||||
var args = token.args ? token.args.join('') : '';
|
||||
if (token.name === 'block' && blocks[args]) {
|
||||
token = blocks[args];
|
||||
}
|
||||
if (token.content && token.content.length) {
|
||||
token.content = remapBlocks(blocks, token.content);
|
||||
}
|
||||
return token;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Import block-level tags to the token list that are not actual block tags.
|
||||
* @param {array} blocks List of block-level tags.
|
||||
* @param {array} tokens List of tokens to render.
|
||||
* @return {undefined}
|
||||
* @private
|
||||
*/
|
||||
function importNonBlocks(blocks, tokens) {
|
||||
var temp = [];
|
||||
utils.each(blocks, function (block) { temp.push(block); });
|
||||
utils.each(temp.reverse(), function (block) {
|
||||
if (block.name !== 'block') {
|
||||
tokens.unshift(block);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively compile and get parents of given parsed token object.
|
||||
*
|
||||
* @param {object} tokens Parsed tokens from template.
|
||||
* @param {SwigOpts} [options={}] Swig options object.
|
||||
* @return {object} Parsed tokens from parent templates.
|
||||
* @private
|
||||
*/
|
||||
function getParents(tokens, options) {
|
||||
var parentName = tokens.parent,
|
||||
parentFiles = [],
|
||||
parents = [],
|
||||
parentFile,
|
||||
parent,
|
||||
l;
|
||||
|
||||
while (parentName) {
|
||||
if (!options || !options.filename) {
|
||||
throw new Error('Cannot extend "' + parentName + '" because current template has no filename.');
|
||||
}
|
||||
|
||||
parentFile = parentFile || options.filename;
|
||||
parentFile = self.options.loader.resolve(parentName, parentFile);
|
||||
parent = cacheGet(parentFile, options) || self.parseFile(parentFile, utils.extend({}, options, { filename: parentFile }));
|
||||
parentName = parent.parent;
|
||||
|
||||
if (parentFiles.indexOf(parentFile) !== -1) {
|
||||
throw new Error('Illegal circular extends of "' + parentFile + '".');
|
||||
}
|
||||
parentFiles.push(parentFile);
|
||||
|
||||
parents.push(parent);
|
||||
}
|
||||
|
||||
// Remap each parents'(1) blocks onto its own parent(2), receiving the full token list for rendering the original parent(1) on its own.
|
||||
l = parents.length;
|
||||
for (l = parents.length - 2; l >= 0; l -= 1) {
|
||||
parents[l].tokens = remapBlocks(parents[l].blocks, parents[l + 1].tokens);
|
||||
importNonBlocks(parents[l].blocks, parents[l].tokens);
|
||||
}
|
||||
|
||||
return parents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre-compile a source string into a cache-able template function.
|
||||
*
|
||||
* @example
|
||||
* swig.precompile('{{ tacos }}');
|
||||
* // => {
|
||||
* // tpl: function (_swig, _locals, _filters, _utils, _fn) { ... },
|
||||
* // tokens: {
|
||||
* // name: undefined,
|
||||
* // parent: null,
|
||||
* // tokens: [...],
|
||||
* // blocks: {}
|
||||
* // }
|
||||
* // }
|
||||
*
|
||||
* In order to render a pre-compiled template, you must have access to filters and utils from Swig. <var>efn</var> is simply an empty function that does nothing.
|
||||
*
|
||||
* @param {string} source Swig template source string.
|
||||
* @param {SwigOpts} [options={}] Swig options object.
|
||||
* @return {object} Renderable function and tokens object.
|
||||
*/
|
||||
this.precompile = function (source, options) {
|
||||
var tokens = self.parse(source, options),
|
||||
parents = getParents(tokens, options),
|
||||
tpl,
|
||||
err;
|
||||
|
||||
if (parents.length) {
|
||||
// Remap the templates first-parent's tokens using this template's blocks.
|
||||
tokens.tokens = remapBlocks(tokens.blocks, parents[0].tokens);
|
||||
importNonBlocks(tokens.blocks, tokens.tokens);
|
||||
}
|
||||
|
||||
try {
|
||||
tpl = new Function('_swig', '_ctx', '_filters', '_utils', '_fn',
|
||||
' var _ext = _swig.extensions,\n' +
|
||||
' _output = "";\n' +
|
||||
parser.compile(tokens, parents, options) + '\n' +
|
||||
' return _output;\n'
|
||||
);
|
||||
} catch (e) {
|
||||
utils.throwError(e, null, options.filename);
|
||||
}
|
||||
|
||||
return { tpl: tpl, tokens: tokens };
|
||||
};
|
||||
|
||||
/**
|
||||
* Compile and render a template string for final output.
|
||||
*
|
||||
* When rendering a source string, a file path should be specified in the options object in order for <var>extends</var>, <var>include</var>, and <var>import</var> to work properly. Do this by adding <code data-language="js">{ filename: '/absolute/path/to/mytpl.html' }</code> to the options argument.
|
||||
*
|
||||
* @example
|
||||
* swig.render('{{ tacos }}', { locals: { tacos: 'Tacos!!!!' }});
|
||||
* // => Tacos!!!!
|
||||
*
|
||||
* @param {string} source Swig template source string.
|
||||
* @param {SwigOpts} [options={}] Swig options object.
|
||||
* @return {string} Rendered output.
|
||||
*/
|
||||
this.render = function (source, options) {
|
||||
return self.compile(source, options)();
|
||||
};
|
||||
|
||||
/**
|
||||
* Compile and render a template file for final output. This is most useful for libraries like Express.js.
|
||||
*
|
||||
* @example
|
||||
* swig.renderFile('./template.html', {}, function (err, output) {
|
||||
* if (err) {
|
||||
* throw err;
|
||||
* }
|
||||
* console.log(output);
|
||||
* });
|
||||
*
|
||||
* @example
|
||||
* swig.renderFile('./template.html', {});
|
||||
* // => output
|
||||
*
|
||||
* @param {string} pathName File location.
|
||||
* @param {object} [locals={}] Template variable context.
|
||||
* @param {Function} [cb] Asyncronous callback function. If not provided, <var>compileFile</var> will run syncronously.
|
||||
* @return {string} Rendered output.
|
||||
*/
|
||||
this.renderFile = function (pathName, locals, cb) {
|
||||
if (cb) {
|
||||
self.compileFile(pathName, {}, function (err, fn) {
|
||||
var result;
|
||||
|
||||
if (err) {
|
||||
cb(err);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
result = fn(locals);
|
||||
} catch (err2) {
|
||||
cb(err2);
|
||||
return;
|
||||
}
|
||||
|
||||
cb(null, result);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
return self.compileFile(pathName)(locals);
|
||||
};
|
||||
|
||||
/**
|
||||
* Compile string source into a renderable template function.
|
||||
*
|
||||
* @example
|
||||
* var tpl = swig.compile('{{ tacos }}');
|
||||
* // => {
|
||||
* // [Function: compiled]
|
||||
* // parent: null,
|
||||
* // tokens: [{ compile: [Function] }],
|
||||
* // blocks: {}
|
||||
* // }
|
||||
* tpl({ tacos: 'Tacos!!!!' });
|
||||
* // => Tacos!!!!
|
||||
*
|
||||
* When compiling a source string, a file path should be specified in the options object in order for <var>extends</var>, <var>include</var>, and <var>import</var> to work properly. Do this by adding <code data-language="js">{ filename: '/absolute/path/to/mytpl.html' }</code> to the options argument.
|
||||
*
|
||||
* @param {string} source Swig template source string.
|
||||
* @param {SwigOpts} [options={}] Swig options object.
|
||||
* @return {function} Renderable function with keys for parent, blocks, and tokens.
|
||||
*/
|
||||
this.compile = function (source, options) {
|
||||
var key = options ? options.filename : null,
|
||||
cached = key ? cacheGet(key, options) : null,
|
||||
context,
|
||||
contextLength,
|
||||
pre;
|
||||
|
||||
if (cached) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
context = getLocals(options);
|
||||
contextLength = utils.keys(context).length;
|
||||
pre = this.precompile(source, options);
|
||||
|
||||
function compiled(locals) {
|
||||
var lcls;
|
||||
if (locals && contextLength) {
|
||||
lcls = utils.extend({}, context, locals);
|
||||
} else if (locals && !contextLength) {
|
||||
lcls = locals;
|
||||
} else if (!locals && contextLength) {
|
||||
lcls = context;
|
||||
} else {
|
||||
lcls = {};
|
||||
}
|
||||
return pre.tpl(self, lcls, filters, utils, efn);
|
||||
}
|
||||
|
||||
utils.extend(compiled, pre.tokens);
|
||||
|
||||
if (key) {
|
||||
cacheSet(key, options, compiled);
|
||||
}
|
||||
|
||||
return compiled;
|
||||
};
|
||||
|
||||
/**
|
||||
* Compile a source file into a renderable template function.
|
||||
*
|
||||
* @example
|
||||
* var tpl = swig.compileFile('./mytpl.html');
|
||||
* // => {
|
||||
* // [Function: compiled]
|
||||
* // parent: null,
|
||||
* // tokens: [{ compile: [Function] }],
|
||||
* // blocks: {}
|
||||
* // }
|
||||
* tpl({ tacos: 'Tacos!!!!' });
|
||||
* // => Tacos!!!!
|
||||
*
|
||||
* @example
|
||||
* swig.compileFile('/myfile.txt', { varControls: ['<%=', '=%>'], tagControls: ['<%', '%>']});
|
||||
* // => will compile 'myfile.txt' using the var and tag controls as specified.
|
||||
*
|
||||
* @param {string} pathname File location.
|
||||
* @param {SwigOpts} [options={}] Swig options object.
|
||||
* @param {Function} [cb] Asyncronous callback function. If not provided, <var>compileFile</var> will run syncronously.
|
||||
* @return {function} Renderable function with keys for parent, blocks, and tokens.
|
||||
*/
|
||||
this.compileFile = function (pathname, options, cb) {
|
||||
var src, cached;
|
||||
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
pathname = self.options.loader.resolve(pathname, options.resolveFrom);
|
||||
if (!options.filename) {
|
||||
options = utils.extend({ filename: pathname }, options);
|
||||
}
|
||||
cached = cacheGet(pathname, options);
|
||||
|
||||
if (cached) {
|
||||
if (cb) {
|
||||
cb(null, cached);
|
||||
return;
|
||||
}
|
||||
return cached;
|
||||
}
|
||||
|
||||
if (cb) {
|
||||
self.options.loader.load(pathname, function (err, src) {
|
||||
if (err) {
|
||||
cb(err);
|
||||
return;
|
||||
}
|
||||
var compiled;
|
||||
|
||||
try {
|
||||
compiled = self.compile(src, options);
|
||||
} catch (err2) {
|
||||
cb(err2);
|
||||
return;
|
||||
}
|
||||
|
||||
cb(err, compiled);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
src = self.options.loader.load(pathname);
|
||||
return self.compile(src, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Run a pre-compiled template function. This is most useful in the browser when you've pre-compiled your templates with the Swig command-line tool.
|
||||
*
|
||||
* @example
|
||||
* $ swig compile ./mytpl.html --wrap-start="var mytpl = " > mytpl.js
|
||||
* @example
|
||||
* <script src="mytpl.js"></script>
|
||||
* <script>
|
||||
* swig.run(mytpl, {});
|
||||
* // => "rendered template..."
|
||||
* </script>
|
||||
*
|
||||
* @param {function} tpl Pre-compiled Swig template function. Use the Swig CLI to compile your templates.
|
||||
* @param {object} [locals={}] Template variable context.
|
||||
* @param {string} [filepath] Filename used for caching the template.
|
||||
* @return {string} Rendered output.
|
||||
*/
|
||||
this.run = function (tpl, locals, filepath) {
|
||||
var context = getLocals({ locals: locals });
|
||||
if (filepath) {
|
||||
cacheSet(filepath, {}, tpl);
|
||||
}
|
||||
return tpl(self, context, filters, utils, efn);
|
||||
};
|
||||
};
|
||||
|
||||
/*!
|
||||
* Export methods publicly
|
||||
*/
|
||||
defaultInstance = new exports.Swig();
|
||||
exports.setFilter = defaultInstance.setFilter;
|
||||
exports.setTag = defaultInstance.setTag;
|
||||
exports.setExtension = defaultInstance.setExtension;
|
||||
exports.parseFile = defaultInstance.parseFile;
|
||||
exports.precompile = defaultInstance.precompile;
|
||||
exports.compile = defaultInstance.compile;
|
||||
exports.compileFile = defaultInstance.compileFile;
|
||||
exports.render = defaultInstance.render;
|
||||
exports.renderFile = defaultInstance.renderFile;
|
||||
exports.run = defaultInstance.run;
|
||||
exports.invalidateCache = defaultInstance.invalidateCache;
|
||||
exports.loaders = loaders;
|
||||
37
node_modules/swig/lib/tags/autoescape.js
generated
vendored
Normal file
37
node_modules/swig/lib/tags/autoescape.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
var utils = require('../utils'),
|
||||
strings = ['html', 'js'];
|
||||
|
||||
/**
|
||||
* Control auto-escaping of variable output from within your templates.
|
||||
*
|
||||
* @alias autoescape
|
||||
*
|
||||
* @example
|
||||
* // myvar = '<foo>';
|
||||
* {% autoescape true %}{{ myvar }}{% endautoescape %}
|
||||
* // => <foo>
|
||||
* {% autoescape false %}{{ myvar }}{% endautoescape %}
|
||||
* // => <foo>
|
||||
*
|
||||
* @param {boolean|string} control One of `true`, `false`, `"js"` or `"html"`.
|
||||
*/
|
||||
exports.compile = function (compiler, args, content, parents, options, blockName) {
|
||||
return compiler(content, parents, options, blockName);
|
||||
};
|
||||
exports.parse = function (str, line, parser, types, stack, opts) {
|
||||
var matched;
|
||||
parser.on('*', function (token) {
|
||||
if (!matched &&
|
||||
(token.type === types.BOOL ||
|
||||
(token.type === types.STRING && strings.indexOf(token.match) === -1))
|
||||
) {
|
||||
this.out.push(token.match);
|
||||
matched = true;
|
||||
return;
|
||||
}
|
||||
utils.throwError('Unexpected token "' + token.match + '" in autoescape tag', line, opts.filename);
|
||||
});
|
||||
|
||||
return true;
|
||||
};
|
||||
exports.ends = true;
|
||||
25
node_modules/swig/lib/tags/block.js
generated
vendored
Normal file
25
node_modules/swig/lib/tags/block.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Defines a block in a template that can be overridden by a template extending this one and/or will override the current template's parent template block of the same name.
|
||||
*
|
||||
* See <a href="#inheritance">Template Inheritance</a> for more information.
|
||||
*
|
||||
* @alias block
|
||||
*
|
||||
* @example
|
||||
* {% block body %}...{% endblock %}
|
||||
*
|
||||
* @param {literal} name Name of the block for use in parent and extended templates.
|
||||
*/
|
||||
exports.compile = function (compiler, args, content, parents, options) {
|
||||
return compiler(content, parents, options, args.join(''));
|
||||
};
|
||||
|
||||
exports.parse = function (str, line, parser) {
|
||||
parser.on('*', function (token) {
|
||||
this.out.push(token.match);
|
||||
});
|
||||
return true;
|
||||
};
|
||||
|
||||
exports.ends = true;
|
||||
exports.block = true;
|
||||
25
node_modules/swig/lib/tags/else.js
generated
vendored
Normal file
25
node_modules/swig/lib/tags/else.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Used within an <code data-language="swig">{% if %}</code> tag, the code block following this tag up until <code data-language="swig">{% endif %}</code> will be rendered if the <i>if</i> statement returns false.
|
||||
*
|
||||
* @alias else
|
||||
*
|
||||
* @example
|
||||
* {% if false %}
|
||||
* statement1
|
||||
* {% else %}
|
||||
* statement2
|
||||
* {% endif %}
|
||||
* // => statement2
|
||||
*
|
||||
*/
|
||||
exports.compile = function () {
|
||||
return '} else {\n';
|
||||
};
|
||||
|
||||
exports.parse = function (str, line, parser, types, stack) {
|
||||
parser.on('*', function (token) {
|
||||
throw new Error('"else" tag does not accept any tokens. Found "' + token.match + '" on line ' + line + '.');
|
||||
});
|
||||
|
||||
return (stack.length && stack[stack.length - 1].name === 'if');
|
||||
};
|
||||
28
node_modules/swig/lib/tags/elseif.js
generated
vendored
Normal file
28
node_modules/swig/lib/tags/elseif.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
var ifparser = require('./if').parse;
|
||||
|
||||
/**
|
||||
* Like <code data-language="swig">{% else %}</code>, except this tag can take more conditional statements.
|
||||
*
|
||||
* @alias elseif
|
||||
* @alias elif
|
||||
*
|
||||
* @example
|
||||
* {% if false %}
|
||||
* Tacos
|
||||
* {% elseif true %}
|
||||
* Burritos
|
||||
* {% else %}
|
||||
* Churros
|
||||
* {% endif %}
|
||||
* // => Burritos
|
||||
*
|
||||
* @param {...mixed} conditional Conditional statement that returns a truthy or falsy value.
|
||||
*/
|
||||
exports.compile = function (compiler, args) {
|
||||
return '} else if (' + args.join(' ') + ') {\n';
|
||||
};
|
||||
|
||||
exports.parse = function (str, line, parser, types, stack) {
|
||||
var okay = ifparser(str, line, parser, types, stack);
|
||||
return okay && (stack.length && stack[stack.length - 1].name === 'if');
|
||||
};
|
||||
19
node_modules/swig/lib/tags/extends.js
generated
vendored
Normal file
19
node_modules/swig/lib/tags/extends.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Makes the current template extend a parent template. This tag must be the first item in your template.
|
||||
*
|
||||
* See <a href="#inheritance">Template Inheritance</a> for more information.
|
||||
*
|
||||
* @alias extends
|
||||
*
|
||||
* @example
|
||||
* {% extends "./layout.html" %}
|
||||
*
|
||||
* @param {string} parentFile Relative path to the file that this template extends.
|
||||
*/
|
||||
exports.compile = function () {};
|
||||
|
||||
exports.parse = function () {
|
||||
return true;
|
||||
};
|
||||
|
||||
exports.ends = false;
|
||||
68
node_modules/swig/lib/tags/filter.js
generated
vendored
Normal file
68
node_modules/swig/lib/tags/filter.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
var filters = require('../filters');
|
||||
|
||||
/**
|
||||
* Apply a filter to an entire block of template.
|
||||
*
|
||||
* @alias filter
|
||||
*
|
||||
* @example
|
||||
* {% filter uppercase %}oh hi, {{ name }}{% endfilter %}
|
||||
* // => OH HI, PAUL
|
||||
*
|
||||
* @example
|
||||
* {% filter replace(".", "!", "g") %}Hi. My name is Paul.{% endfilter %}
|
||||
* // => Hi! My name is Paul!
|
||||
*
|
||||
* @param {function} filter The filter that should be applied to the contents of the tag.
|
||||
*/
|
||||
|
||||
exports.compile = function (compiler, args, content, parents, options, blockName) {
|
||||
var filter = args.shift().replace(/\($/, ''),
|
||||
val = '(function () {\n' +
|
||||
' var _output = "";\n' +
|
||||
compiler(content, parents, options, blockName) +
|
||||
' return _output;\n' +
|
||||
'})()';
|
||||
|
||||
if (args[args.length - 1] === ')') {
|
||||
args.pop();
|
||||
}
|
||||
|
||||
args = (args.length) ? ', ' + args.join('') : '';
|
||||
return '_output += _filters["' + filter + '"](' + val + args + ');\n';
|
||||
};
|
||||
|
||||
exports.parse = function (str, line, parser, types) {
|
||||
var filter;
|
||||
|
||||
function check(filter) {
|
||||
if (!filters.hasOwnProperty(filter)) {
|
||||
throw new Error('Filter "' + filter + '" does not exist on line ' + line + '.');
|
||||
}
|
||||
}
|
||||
|
||||
parser.on(types.FUNCTION, function (token) {
|
||||
if (!filter) {
|
||||
filter = token.match.replace(/\($/, '');
|
||||
check(filter);
|
||||
this.out.push(token.match);
|
||||
this.state.push(token.type);
|
||||
return;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
parser.on(types.VAR, function (token) {
|
||||
if (!filter) {
|
||||
filter = token.match;
|
||||
check(filter);
|
||||
this.out.push(filter);
|
||||
return;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
exports.ends = true;
|
||||
130
node_modules/swig/lib/tags/for.js
generated
vendored
Normal file
130
node_modules/swig/lib/tags/for.js
generated
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
var ctx = '_ctx.',
|
||||
ctxloop = ctx + 'loop';
|
||||
|
||||
/**
|
||||
* Loop over objects and arrays.
|
||||
*
|
||||
* @alias for
|
||||
*
|
||||
* @example
|
||||
* // obj = { one: 'hi', two: 'bye' };
|
||||
* {% for x in obj %}
|
||||
* {% if loop.first %}<ul>{% endif %}
|
||||
* <li>{{ loop.index }} - {{ loop.key }}: {{ x }}</li>
|
||||
* {% if loop.last %}</ul>{% endif %}
|
||||
* {% endfor %}
|
||||
* // => <ul>
|
||||
* // <li>1 - one: hi</li>
|
||||
* // <li>2 - two: bye</li>
|
||||
* // </ul>
|
||||
*
|
||||
* @example
|
||||
* // arr = [1, 2, 3]
|
||||
* // Reverse the array, shortcut the key/index to `key`
|
||||
* {% for key, val in arr|reverse %}
|
||||
* {{ key }} -- {{ val }}
|
||||
* {% endfor %}
|
||||
* // => 0 -- 3
|
||||
* // 1 -- 2
|
||||
* // 2 -- 1
|
||||
*
|
||||
* @param {literal} [key] A shortcut to the index of the array or current key accessor.
|
||||
* @param {literal} variable The current value will be assigned to this variable name temporarily. The variable will be reset upon ending the for tag.
|
||||
* @param {literal} in Literally, "in". This token is required.
|
||||
* @param {object} object An enumerable object that will be iterated over.
|
||||
*
|
||||
* @return {loop.index} The current iteration of the loop (1-indexed)
|
||||
* @return {loop.index0} The current iteration of the loop (0-indexed)
|
||||
* @return {loop.revindex} The number of iterations from the end of the loop (1-indexed)
|
||||
* @return {loop.revindex0} The number of iterations from the end of the loop (0-indexed)
|
||||
* @return {loop.key} If the iterator is an object, this will be the key of the current item, otherwise it will be the same as the loop.index.
|
||||
* @return {loop.first} True if the current object is the first in the object or array.
|
||||
* @return {loop.last} True if the current object is the last in the object or array.
|
||||
*/
|
||||
exports.compile = function (compiler, args, content, parents, options, blockName) {
|
||||
var val = args.shift(),
|
||||
key = '__k',
|
||||
ctxloopcache = (ctx + '__loopcache' + Math.random()).replace(/\./g, ''),
|
||||
last;
|
||||
|
||||
if (args[0] && args[0] === ',') {
|
||||
args.shift();
|
||||
key = val;
|
||||
val = args.shift();
|
||||
}
|
||||
|
||||
last = args.join('');
|
||||
|
||||
return [
|
||||
'(function () {\n',
|
||||
' var __l = ' + last + ', __len = (_utils.isArray(__l) || typeof __l === "string") ? __l.length : _utils.keys(__l).length;\n',
|
||||
' if (!__l) { return; }\n',
|
||||
' var ' + ctxloopcache + ' = { loop: ' + ctxloop + ', ' + val + ': ' + ctx + val + ', ' + key + ': ' + ctx + key + ' };\n',
|
||||
' ' + ctxloop + ' = { first: false, index: 1, index0: 0, revindex: __len, revindex0: __len - 1, length: __len, last: false };\n',
|
||||
' _utils.each(__l, function (' + val + ', ' + key + ') {\n',
|
||||
' ' + ctx + val + ' = ' + val + ';\n',
|
||||
' ' + ctx + key + ' = ' + key + ';\n',
|
||||
' ' + ctxloop + '.key = ' + key + ';\n',
|
||||
' ' + ctxloop + '.first = (' + ctxloop + '.index0 === 0);\n',
|
||||
' ' + ctxloop + '.last = (' + ctxloop + '.revindex0 === 0);\n',
|
||||
' ' + compiler(content, parents, options, blockName),
|
||||
' ' + ctxloop + '.index += 1; ' + ctxloop + '.index0 += 1; ' + ctxloop + '.revindex -= 1; ' + ctxloop + '.revindex0 -= 1;\n',
|
||||
' });\n',
|
||||
' ' + ctxloop + ' = ' + ctxloopcache + '.loop;\n',
|
||||
' ' + ctx + val + ' = ' + ctxloopcache + '.' + val + ';\n',
|
||||
' ' + ctx + key + ' = ' + ctxloopcache + '.' + key + ';\n',
|
||||
' ' + ctxloopcache + ' = undefined;\n',
|
||||
'})();\n'
|
||||
].join('');
|
||||
};
|
||||
|
||||
exports.parse = function (str, line, parser, types) {
|
||||
var firstVar, ready;
|
||||
|
||||
parser.on(types.NUMBER, function (token) {
|
||||
var lastState = this.state.length ? this.state[this.state.length - 1] : null;
|
||||
if (!ready ||
|
||||
(lastState !== types.ARRAYOPEN &&
|
||||
lastState !== types.CURLYOPEN &&
|
||||
lastState !== types.CURLYCLOSE &&
|
||||
lastState !== types.FUNCTION &&
|
||||
lastState !== types.FILTER)
|
||||
) {
|
||||
throw new Error('Unexpected number "' + token.match + '" on line ' + line + '.');
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
parser.on(types.VAR, function (token) {
|
||||
if (ready && firstVar) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!this.out.length) {
|
||||
firstVar = true;
|
||||
}
|
||||
|
||||
this.out.push(token.match);
|
||||
});
|
||||
|
||||
parser.on(types.COMMA, function (token) {
|
||||
if (firstVar && this.prevToken.type === types.VAR) {
|
||||
this.out.push(token.match);
|
||||
return;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
parser.on(types.COMPARATOR, function (token) {
|
||||
if (token.match !== 'in' || !firstVar) {
|
||||
throw new Error('Unexpected token "' + token.match + '" on line ' + line + '.');
|
||||
}
|
||||
ready = true;
|
||||
this.filterApplyIdx.push(this.out.length);
|
||||
});
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
exports.ends = true;
|
||||
86
node_modules/swig/lib/tags/if.js
generated
vendored
Normal file
86
node_modules/swig/lib/tags/if.js
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* Used to create conditional statements in templates. Accepts most JavaScript valid comparisons.
|
||||
*
|
||||
* Can be used in conjunction with <a href="#elseif"><code data-language="swig">{% elseif ... %}</code></a> and <a href="#else"><code data-language="swig">{% else %}</code></a> tags.
|
||||
*
|
||||
* @alias if
|
||||
*
|
||||
* @example
|
||||
* {% if x %}{% endif %}
|
||||
* {% if !x %}{% endif %}
|
||||
* {% if not x %}{% endif %}
|
||||
*
|
||||
* @example
|
||||
* {% if x and y %}{% endif %}
|
||||
* {% if x && y %}{% endif %}
|
||||
* {% if x or y %}{% endif %}
|
||||
* {% if x || y %}{% endif %}
|
||||
* {% if x || (y && z) %}{% endif %}
|
||||
*
|
||||
* @example
|
||||
* {% if x [operator] y %}
|
||||
* Operators: ==, !=, <, <=, >, >=, ===, !==
|
||||
* {% endif %}
|
||||
*
|
||||
* @example
|
||||
* {% if x == 'five' %}
|
||||
* The operands can be also be string or number literals
|
||||
* {% endif %}
|
||||
*
|
||||
* @example
|
||||
* {% if x|lower === 'tacos' %}
|
||||
* You can use filters on any operand in the statement.
|
||||
* {% endif %}
|
||||
*
|
||||
* @example
|
||||
* {% if x in y %}
|
||||
* If x is a value that is present in y, this will return true.
|
||||
* {% endif %}
|
||||
*
|
||||
* @param {...mixed} conditional Conditional statement that returns a truthy or falsy value.
|
||||
*/
|
||||
exports.compile = function (compiler, args, content, parents, options, blockName) {
|
||||
return 'if (' + args.join(' ') + ') { \n' +
|
||||
compiler(content, parents, options, blockName) + '\n' +
|
||||
'}';
|
||||
};
|
||||
|
||||
exports.parse = function (str, line, parser, types) {
|
||||
if (typeof str === "undefined") {
|
||||
throw new Error('No conditional statement provided on line ' + line + '.');
|
||||
}
|
||||
|
||||
parser.on(types.COMPARATOR, function (token) {
|
||||
if (this.isLast) {
|
||||
throw new Error('Unexpected logic "' + token.match + '" on line ' + line + '.');
|
||||
}
|
||||
if (this.prevToken.type === types.NOT) {
|
||||
throw new Error('Attempted logic "not ' + token.match + '" on line ' + line + '. Use !(foo ' + token.match + ') instead.');
|
||||
}
|
||||
this.out.push(token.match);
|
||||
this.filterApplyIdx.push(this.out.length);
|
||||
});
|
||||
|
||||
parser.on(types.NOT, function (token) {
|
||||
if (this.isLast) {
|
||||
throw new Error('Unexpected logic "' + token.match + '" on line ' + line + '.');
|
||||
}
|
||||
this.out.push(token.match);
|
||||
});
|
||||
|
||||
parser.on(types.BOOL, function (token) {
|
||||
this.out.push(token.match);
|
||||
});
|
||||
|
||||
parser.on(types.LOGIC, function (token) {
|
||||
if (!this.out.length || this.isLast) {
|
||||
throw new Error('Unexpected logic "' + token.match + '" on line ' + line + '.');
|
||||
}
|
||||
this.out.push(token.match);
|
||||
this.filterApplyIdx.pop();
|
||||
});
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
exports.ends = true;
|
||||
91
node_modules/swig/lib/tags/import.js
generated
vendored
Normal file
91
node_modules/swig/lib/tags/import.js
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
var utils = require('../utils');
|
||||
|
||||
/**
|
||||
* Allows you to import macros from another file directly into your current context.
|
||||
* The import tag is specifically designed for importing macros into your template with a specific context scope. This is very useful for keeping your macros from overriding template context that is being injected by your server-side page generation.
|
||||
*
|
||||
* @alias import
|
||||
*
|
||||
* @example
|
||||
* {% import './formmacros.html' as forms %}
|
||||
* {{ form.input("text", "name") }}
|
||||
* // => <input type="text" name="name">
|
||||
*
|
||||
* @example
|
||||
* {% import "../shared/tags.html" as tags %}
|
||||
* {{ tags.stylesheet('global') }}
|
||||
* // => <link rel="stylesheet" href="/global.css">
|
||||
*
|
||||
* @param {string|var} file Relative path from the current template file to the file to import macros from.
|
||||
* @param {literal} as Literally, "as".
|
||||
* @param {literal} varname Local-accessible object name to assign the macros to.
|
||||
*/
|
||||
exports.compile = function (compiler, args) {
|
||||
var ctx = args.pop(),
|
||||
out = '_ctx.' + ctx + ' = {};\n var _output = "";\n',
|
||||
replacements = utils.map(args, function (arg) {
|
||||
return {
|
||||
ex: new RegExp('_ctx.' + arg.name, 'g'),
|
||||
re: '_ctx.' + ctx + '.' + arg.name
|
||||
};
|
||||
});
|
||||
|
||||
// Replace all occurrences of all macros in this file with
|
||||
// proper namespaced definitions and calls
|
||||
utils.each(args, function (arg) {
|
||||
var c = arg.compiled;
|
||||
utils.each(replacements, function (re) {
|
||||
c = c.replace(re.ex, re.re);
|
||||
});
|
||||
out += c;
|
||||
});
|
||||
|
||||
return out;
|
||||
};
|
||||
|
||||
exports.parse = function (str, line, parser, types, stack, opts, swig) {
|
||||
var compiler = require('../parser').compile,
|
||||
parseOpts = { resolveFrom: opts.filename },
|
||||
compileOpts = utils.extend({}, opts, parseOpts),
|
||||
tokens,
|
||||
ctx;
|
||||
|
||||
parser.on(types.STRING, function (token) {
|
||||
var self = this;
|
||||
if (!tokens) {
|
||||
tokens = swig.parseFile(token.match.replace(/^("|')|("|')$/g, ''), parseOpts).tokens;
|
||||
utils.each(tokens, function (token) {
|
||||
var out = '',
|
||||
macroName;
|
||||
if (!token || token.name !== 'macro' || !token.compile) {
|
||||
return;
|
||||
}
|
||||
macroName = token.args[0];
|
||||
out += token.compile(compiler, token.args, token.content, [], compileOpts) + '\n';
|
||||
self.out.push({compiled: out, name: macroName});
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Error('Unexpected string ' + token.match + ' on line ' + line + '.');
|
||||
});
|
||||
|
||||
parser.on(types.VAR, function (token) {
|
||||
var self = this;
|
||||
if (!tokens || ctx) {
|
||||
throw new Error('Unexpected variable "' + token.match + '" on line ' + line + '.');
|
||||
}
|
||||
|
||||
if (token.match === 'as') {
|
||||
return;
|
||||
}
|
||||
|
||||
ctx = token.match;
|
||||
self.out.push(ctx);
|
||||
return false;
|
||||
});
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
exports.block = true;
|
||||
100
node_modules/swig/lib/tags/include.js
generated
vendored
Normal file
100
node_modules/swig/lib/tags/include.js
generated
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
var ignore = 'ignore',
|
||||
missing = 'missing',
|
||||
only = 'only';
|
||||
|
||||
/**
|
||||
* Includes a template partial in place. The template is rendered within the current locals variable context.
|
||||
*
|
||||
* @alias include
|
||||
*
|
||||
* @example
|
||||
* // food = 'burritos';
|
||||
* // drink = 'lemonade';
|
||||
* {% include "./partial.html" %}
|
||||
* // => I like burritos and lemonade.
|
||||
*
|
||||
* @example
|
||||
* // my_obj = { food: 'tacos', drink: 'horchata' };
|
||||
* {% include "./partial.html" with my_obj only %}
|
||||
* // => I like tacos and horchata.
|
||||
*
|
||||
* @example
|
||||
* {% include "/this/file/does/not/exist" ignore missing %}
|
||||
* // => (Nothing! empty string)
|
||||
*
|
||||
* @param {string|var} file The path, relative to the template root, to render into the current context.
|
||||
* @param {literal} [with] Literally, "with".
|
||||
* @param {object} [context] Local variable key-value object context to provide to the included file.
|
||||
* @param {literal} [only] Restricts to <strong>only</strong> passing the <code>with context</code> as local variables–the included template will not be aware of any other local variables in the parent template. For best performance, usage of this option is recommended if possible.
|
||||
* @param {literal} [ignore missing] Will output empty string if not found instead of throwing an error.
|
||||
*/
|
||||
exports.compile = function (compiler, args) {
|
||||
var file = args.shift(),
|
||||
onlyIdx = args.indexOf(only),
|
||||
onlyCtx = onlyIdx !== -1 ? args.splice(onlyIdx, 1) : false,
|
||||
parentFile = (args.pop() || '').replace(/\\/g, '\\\\'),
|
||||
ignore = args[args.length - 1] === missing ? (args.pop()) : false,
|
||||
w = args.join('');
|
||||
|
||||
return (ignore ? ' try {\n' : '') +
|
||||
'_output += _swig.compileFile(' + file + ', {' +
|
||||
'resolveFrom: "' + parentFile + '"' +
|
||||
'})(' +
|
||||
((onlyCtx && w) ? w : (!w ? '_ctx' : '_utils.extend({}, _ctx, ' + w + ')')) +
|
||||
');\n' +
|
||||
(ignore ? '} catch (e) {}\n' : '');
|
||||
};
|
||||
|
||||
exports.parse = function (str, line, parser, types, stack, opts) {
|
||||
var file, w;
|
||||
parser.on(types.STRING, function (token) {
|
||||
if (!file) {
|
||||
file = token.match;
|
||||
this.out.push(file);
|
||||
return;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
parser.on(types.VAR, function (token) {
|
||||
if (!file) {
|
||||
file = token.match;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!w && token.match === 'with') {
|
||||
w = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (w && token.match === only && this.prevToken.match !== 'with') {
|
||||
this.out.push(token.match);
|
||||
return;
|
||||
}
|
||||
|
||||
if (token.match === ignore) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (token.match === missing) {
|
||||
if (this.prevToken.match !== ignore) {
|
||||
throw new Error('Unexpected token "' + missing + '" on line ' + line + '.');
|
||||
}
|
||||
this.out.push(token.match);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.prevToken.match === ignore) {
|
||||
throw new Error('Expected "' + missing + '" on line ' + line + ' but found "' + token.match + '".');
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
parser.on('end', function () {
|
||||
this.out.push(opts.filename || null);
|
||||
});
|
||||
|
||||
return true;
|
||||
};
|
||||
16
node_modules/swig/lib/tags/index.js
generated
vendored
Normal file
16
node_modules/swig/lib/tags/index.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
exports.autoescape = require('./autoescape');
|
||||
exports.block = require('./block');
|
||||
exports["else"] = require('./else');
|
||||
exports.elseif = require('./elseif');
|
||||
exports.elif = exports.elseif;
|
||||
exports["extends"] = require('./extends');
|
||||
exports.filter = require('./filter');
|
||||
exports["for"] = require('./for');
|
||||
exports["if"] = require('./if');
|
||||
exports["import"] = require('./import');
|
||||
exports.include = require('./include');
|
||||
exports.macro = require('./macro');
|
||||
exports.parent = require('./parent');
|
||||
exports.raw = require('./raw');
|
||||
exports.set = require('./set');
|
||||
exports.spaceless = require('./spaceless');
|
||||
79
node_modules/swig/lib/tags/macro.js
generated
vendored
Normal file
79
node_modules/swig/lib/tags/macro.js
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* Create custom, reusable snippets within your templates.
|
||||
* Can be imported from one template to another using the <a href="#import"><code data-language="swig">{% import ... %}</code></a> tag.
|
||||
*
|
||||
* @alias macro
|
||||
*
|
||||
* @example
|
||||
* {% macro input(type, name, id, label, value, error) %}
|
||||
* <label for="{{ name }}">{{ label }}</label>
|
||||
* <input type="{{ type }}" name="{{ name }}" id="{{ id }}" value="{{ value }}"{% if error %} class="error"{% endif %}>
|
||||
* {% endmacro %}
|
||||
*
|
||||
* {{ input("text", "fname", "fname", "First Name", fname.value, fname.errors) }}
|
||||
* // => <label for="fname">First Name</label>
|
||||
* // <input type="text" name="fname" id="fname" value="">
|
||||
*
|
||||
* @param {...arguments} arguments User-defined arguments.
|
||||
*/
|
||||
exports.compile = function (compiler, args, content, parents, options, blockName) {
|
||||
var fnName = args.shift();
|
||||
|
||||
return '_ctx.' + fnName + ' = function (' + args.join('') + ') {\n' +
|
||||
' var _output = "",\n' +
|
||||
' __ctx = _utils.extend({}, _ctx);\n' +
|
||||
' _utils.each(_ctx, function (v, k) {\n' +
|
||||
' if (["' + args.join('","') + '"].indexOf(k) !== -1) { delete _ctx[k]; }\n' +
|
||||
' });\n' +
|
||||
compiler(content, parents, options, blockName) + '\n' +
|
||||
' _ctx = _utils.extend(_ctx, __ctx);\n' +
|
||||
' return _output;\n' +
|
||||
'};\n' +
|
||||
'_ctx.' + fnName + '.safe = true;\n';
|
||||
};
|
||||
|
||||
exports.parse = function (str, line, parser, types) {
|
||||
var name;
|
||||
|
||||
parser.on(types.VAR, function (token) {
|
||||
if (token.match.indexOf('.') !== -1) {
|
||||
throw new Error('Unexpected dot in macro argument "' + token.match + '" on line ' + line + '.');
|
||||
}
|
||||
this.out.push(token.match);
|
||||
});
|
||||
|
||||
parser.on(types.FUNCTION, function (token) {
|
||||
if (!name) {
|
||||
name = token.match;
|
||||
this.out.push(name);
|
||||
this.state.push(types.FUNCTION);
|
||||
}
|
||||
});
|
||||
|
||||
parser.on(types.FUNCTIONEMPTY, function (token) {
|
||||
if (!name) {
|
||||
name = token.match;
|
||||
this.out.push(name);
|
||||
}
|
||||
});
|
||||
|
||||
parser.on(types.PARENCLOSE, function () {
|
||||
if (this.isLast) {
|
||||
return;
|
||||
}
|
||||
throw new Error('Unexpected parenthesis close on line ' + line + '.');
|
||||
});
|
||||
|
||||
parser.on(types.COMMA, function () {
|
||||
return true;
|
||||
});
|
||||
|
||||
parser.on('*', function () {
|
||||
return;
|
||||
});
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
exports.ends = true;
|
||||
exports.block = true;
|
||||
51
node_modules/swig/lib/tags/parent.js
generated
vendored
Normal file
51
node_modules/swig/lib/tags/parent.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Inject the content from the parent template's block of the same name into the current block.
|
||||
*
|
||||
* See <a href="#inheritance">Template Inheritance</a> for more information.
|
||||
*
|
||||
* @alias parent
|
||||
*
|
||||
* @example
|
||||
* {% extends "./foo.html" %}
|
||||
* {% block content %}
|
||||
* My content.
|
||||
* {% parent %}
|
||||
* {% endblock %}
|
||||
*
|
||||
*/
|
||||
exports.compile = function (compiler, args, content, parents, options, blockName) {
|
||||
if (!parents || !parents.length) {
|
||||
return '';
|
||||
}
|
||||
|
||||
var parentFile = args[0],
|
||||
breaker = true,
|
||||
l = parents.length,
|
||||
i = 0,
|
||||
parent,
|
||||
block;
|
||||
|
||||
for (i; i < l; i += 1) {
|
||||
parent = parents[i];
|
||||
if (!parent.blocks || !parent.blocks.hasOwnProperty(blockName)) {
|
||||
continue;
|
||||
}
|
||||
// Silly JSLint "Strange Loop" requires return to be in a conditional
|
||||
if (breaker && parentFile !== parent.name) {
|
||||
block = parent.blocks[blockName];
|
||||
return block.compile(compiler, [blockName], block.content, parents.slice(i + 1), options) + '\n';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.parse = function (str, line, parser, types, stack, opts) {
|
||||
parser.on('*', function (token) {
|
||||
throw new Error('Unexpected argument "' + token.match + '" on line ' + line + '.');
|
||||
});
|
||||
|
||||
parser.on('end', function () {
|
||||
this.out.push(opts.filename);
|
||||
});
|
||||
|
||||
return true;
|
||||
};
|
||||
23
node_modules/swig/lib/tags/raw.js
generated
vendored
Normal file
23
node_modules/swig/lib/tags/raw.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
// Magic tag, hardcoded into parser
|
||||
|
||||
/**
|
||||
* Forces the content to not be auto-escaped. All swig instructions will be ignored and the content will be rendered exactly as it was given.
|
||||
*
|
||||
* @alias raw
|
||||
*
|
||||
* @example
|
||||
* // foobar = '<p>'
|
||||
* {% raw %}{{ foobar }}{% endraw %}
|
||||
* // => {{ foobar }}
|
||||
*
|
||||
*/
|
||||
exports.compile = function (compiler, args, content, parents, options, blockName) {
|
||||
return compiler(content, parents, options, blockName);
|
||||
};
|
||||
exports.parse = function (str, line, parser) {
|
||||
parser.on('*', function (token) {
|
||||
throw new Error('Unexpected token "' + token.match + '" in raw tag on line ' + line + '.');
|
||||
});
|
||||
return true;
|
||||
};
|
||||
exports.ends = true;
|
||||
109
node_modules/swig/lib/tags/set.js
generated
vendored
Normal file
109
node_modules/swig/lib/tags/set.js
generated
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* Set a variable for re-use in the current context. This will over-write any value already set to the context for the given <var>varname</var>.
|
||||
*
|
||||
* @alias set
|
||||
*
|
||||
* @example
|
||||
* {% set foo = "anything!" %}
|
||||
* {{ foo }}
|
||||
* // => anything!
|
||||
*
|
||||
* @example
|
||||
* // index = 2;
|
||||
* {% set bar = 1 %}
|
||||
* {% set bar += index|default(3) %}
|
||||
* // => 3
|
||||
*
|
||||
* @example
|
||||
* // foods = {};
|
||||
* // food = 'chili';
|
||||
* {% set foods[food] = "con queso" %}
|
||||
* {{ foods.chili }}
|
||||
* // => con queso
|
||||
*
|
||||
* @example
|
||||
* // foods = { chili: 'chili con queso' }
|
||||
* {% set foods.chili = "guatamalan insanity pepper" %}
|
||||
* {{ foods.chili }}
|
||||
* // => guatamalan insanity pepper
|
||||
*
|
||||
* @param {literal} varname The variable name to assign the value to.
|
||||
* @param {literal} assignement Any valid JavaScript assignement. <code data-language="js">=, +=, *=, /=, -=</code>
|
||||
* @param {*} value Valid variable output.
|
||||
*/
|
||||
exports.compile = function (compiler, args) {
|
||||
return args.join(' ') + ';\n';
|
||||
};
|
||||
|
||||
exports.parse = function (str, line, parser, types) {
|
||||
var nameSet = '',
|
||||
propertyName;
|
||||
|
||||
parser.on(types.VAR, function (token) {
|
||||
if (propertyName) {
|
||||
// Tell the parser where to find the variable
|
||||
propertyName += '_ctx.' + token.match;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!parser.out.length) {
|
||||
nameSet += token.match;
|
||||
return;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
parser.on(types.BRACKETOPEN, function (token) {
|
||||
if (!propertyName && !this.out.length) {
|
||||
propertyName = token.match;
|
||||
return;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
parser.on(types.STRING, function (token) {
|
||||
if (propertyName && !this.out.length) {
|
||||
propertyName += token.match;
|
||||
return;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
parser.on(types.BRACKETCLOSE, function (token) {
|
||||
if (propertyName && !this.out.length) {
|
||||
nameSet += propertyName + token.match;
|
||||
propertyName = undefined;
|
||||
return;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
parser.on(types.DOTKEY, function (token) {
|
||||
if (!propertyName && !nameSet) {
|
||||
return true;
|
||||
}
|
||||
nameSet += '.' + token.match;
|
||||
return;
|
||||
});
|
||||
|
||||
parser.on(types.ASSIGNMENT, function (token) {
|
||||
if (this.out.length || !nameSet) {
|
||||
throw new Error('Unexpected assignment "' + token.match + '" on line ' + line + '.');
|
||||
}
|
||||
|
||||
this.out.push(
|
||||
// Prevent the set from spilling into global scope
|
||||
'_ctx.' + nameSet
|
||||
);
|
||||
this.out.push(token.match);
|
||||
this.filterApplyIdx.push(this.out.length);
|
||||
});
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
exports.block = true;
|
||||
42
node_modules/swig/lib/tags/spaceless.js
generated
vendored
Normal file
42
node_modules/swig/lib/tags/spaceless.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
var utils = require('../utils');
|
||||
|
||||
/**
|
||||
* Attempts to remove whitespace between HTML tags. Use at your own risk.
|
||||
*
|
||||
* @alias spaceless
|
||||
*
|
||||
* @example
|
||||
* {% spaceless %}
|
||||
* {% for num in foo %}
|
||||
* <li>{{ loop.index }}</li>
|
||||
* {% endfor %}
|
||||
* {% endspaceless %}
|
||||
* // => <li>1</li><li>2</li><li>3</li>
|
||||
*
|
||||
*/
|
||||
exports.compile = function (compiler, args, content, parents, options, blockName) {
|
||||
function stripWhitespace(tokens) {
|
||||
return utils.map(tokens, function (token) {
|
||||
if (token.content || typeof token !== 'string') {
|
||||
token.content = stripWhitespace(token.content);
|
||||
return token;
|
||||
}
|
||||
|
||||
return token.replace(/^\s+/, '')
|
||||
.replace(/>\s+</g, '><')
|
||||
.replace(/\s+$/, '');
|
||||
});
|
||||
}
|
||||
|
||||
return compiler(stripWhitespace(content), parents, options, blockName);
|
||||
};
|
||||
|
||||
exports.parse = function (str, line, parser) {
|
||||
parser.on('*', function (token) {
|
||||
throw new Error('Unexpected token "' + token.match + '" on line ' + line + '.');
|
||||
});
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
exports.ends = true;
|
||||
184
node_modules/swig/lib/utils.js
generated
vendored
Normal file
184
node_modules/swig/lib/utils.js
generated
vendored
Normal file
@@ -0,0 +1,184 @@
|
||||
var isArray;
|
||||
|
||||
/**
|
||||
* Strip leading and trailing whitespace from a string.
|
||||
* @param {string} input
|
||||
* @return {string} Stripped input.
|
||||
*/
|
||||
exports.strip = function (input) {
|
||||
return input.replace(/^\s+|\s+$/g, '');
|
||||
};
|
||||
|
||||
/**
|
||||
* Test if a string starts with a given prefix.
|
||||
* @param {string} str String to test against.
|
||||
* @param {string} prefix Prefix to check for.
|
||||
* @return {boolean}
|
||||
*/
|
||||
exports.startsWith = function (str, prefix) {
|
||||
return str.indexOf(prefix) === 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Test if a string ends with a given suffix.
|
||||
* @param {string} str String to test against.
|
||||
* @param {string} suffix Suffix to check for.
|
||||
* @return {boolean}
|
||||
*/
|
||||
exports.endsWith = function (str, suffix) {
|
||||
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Iterate over an array or object.
|
||||
* @param {array|object} obj Enumerable object.
|
||||
* @param {Function} fn Callback function executed for each item.
|
||||
* @return {array|object} The original input object.
|
||||
*/
|
||||
exports.each = function (obj, fn) {
|
||||
var i, l;
|
||||
|
||||
if (isArray(obj)) {
|
||||
i = 0;
|
||||
l = obj.length;
|
||||
for (i; i < l; i += 1) {
|
||||
if (fn(obj[i], i, obj) === false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (i in obj) {
|
||||
if (obj.hasOwnProperty(i)) {
|
||||
if (fn(obj[i], i, obj) === false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
/**
|
||||
* Test if an object is an Array.
|
||||
* @param {object} obj
|
||||
* @return {boolean}
|
||||
*/
|
||||
exports.isArray = isArray = (Array.hasOwnProperty('isArray')) ? Array.isArray : function (obj) {
|
||||
return (obj) ? (typeof obj === 'object' && Object.prototype.toString.call(obj).indexOf() !== -1) : false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Test if an item in an enumerable matches your conditions.
|
||||
* @param {array|object} obj Enumerable object.
|
||||
* @param {Function} fn Executed for each item. Return true if your condition is met.
|
||||
* @return {boolean}
|
||||
*/
|
||||
exports.some = function (obj, fn) {
|
||||
var i = 0,
|
||||
result,
|
||||
l;
|
||||
if (isArray(obj)) {
|
||||
l = obj.length;
|
||||
|
||||
for (i; i < l; i += 1) {
|
||||
result = fn(obj[i], i, obj);
|
||||
if (result) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
exports.each(obj, function (value, index) {
|
||||
result = fn(value, index, obj);
|
||||
return !(result);
|
||||
});
|
||||
}
|
||||
return !!result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return a new enumerable, mapped by a given iteration function.
|
||||
* @param {object} obj Enumerable object.
|
||||
* @param {Function} fn Executed for each item. Return the item to replace the original item with.
|
||||
* @return {object} New mapped object.
|
||||
*/
|
||||
exports.map = function (obj, fn) {
|
||||
var i = 0,
|
||||
result = [],
|
||||
l;
|
||||
|
||||
if (isArray(obj)) {
|
||||
l = obj.length;
|
||||
for (i; i < l; i += 1) {
|
||||
result[i] = fn(obj[i], i);
|
||||
}
|
||||
} else {
|
||||
for (i in obj) {
|
||||
if (obj.hasOwnProperty(i)) {
|
||||
result[i] = fn(obj[i], i);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Copy all of the properties in the source objects over to the destination object, and return the destination object. It's in-order, so the last source will override properties of the same name in previous arguments.
|
||||
* @param {...object} arguments
|
||||
* @return {object}
|
||||
*/
|
||||
exports.extend = function () {
|
||||
var args = arguments,
|
||||
target = args[0],
|
||||
objs = (args.length > 1) ? Array.prototype.slice.call(args, 1) : [],
|
||||
i = 0,
|
||||
l = objs.length,
|
||||
key,
|
||||
obj;
|
||||
|
||||
for (i; i < l; i += 1) {
|
||||
obj = objs[i] || {};
|
||||
for (key in obj) {
|
||||
if (obj.hasOwnProperty(key)) {
|
||||
target[key] = obj[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
return target;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get all of the keys on an object.
|
||||
* @param {object} obj
|
||||
* @return {array}
|
||||
*/
|
||||
exports.keys = function (obj) {
|
||||
if (!obj) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (Object.keys) {
|
||||
return Object.keys(obj);
|
||||
}
|
||||
|
||||
return exports.map(obj, function (v, k) {
|
||||
return k;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Throw an error with possible line number and source file.
|
||||
* @param {string} message Error message
|
||||
* @param {number} [line] Line number in template.
|
||||
* @param {string} [file] Template file the error occured in.
|
||||
* @throws {Error} No seriously, the point is to throw an error.
|
||||
*/
|
||||
exports.throwError = function (message, line, file) {
|
||||
if (line) {
|
||||
message += ' on line ' + line;
|
||||
}
|
||||
if (file) {
|
||||
message += ' in file ' + file;
|
||||
}
|
||||
throw new Error(message + '.');
|
||||
};
|
||||
1
node_modules/swig/node_modules/.bin/uglifyjs
generated
vendored
Symbolic link
1
node_modules/swig/node_modules/.bin/uglifyjs
generated
vendored
Symbolic link
@@ -0,0 +1 @@
|
||||
../uglify-js/bin/uglifyjs
|
||||
19
node_modules/swig/node_modules/async/LICENSE
generated
vendored
Normal file
19
node_modules/swig/node_modules/async/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2010 Caolan McMahon
|
||||
|
||||
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.
|
||||
1425
node_modules/swig/node_modules/async/README.md
generated
vendored
Normal file
1425
node_modules/swig/node_modules/async/README.md
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
11
node_modules/swig/node_modules/async/component.json
generated
vendored
Normal file
11
node_modules/swig/node_modules/async/component.json
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "async",
|
||||
"repo": "caolan/async",
|
||||
"description": "Higher-order functions and common patterns for asynchronous code",
|
||||
"version": "0.1.23",
|
||||
"keywords": [],
|
||||
"dependencies": {},
|
||||
"development": {},
|
||||
"main": "lib/async.js",
|
||||
"scripts": [ "lib/async.js" ]
|
||||
}
|
||||
958
node_modules/swig/node_modules/async/lib/async.js
generated
vendored
Executable file
958
node_modules/swig/node_modules/async/lib/async.js
generated
vendored
Executable file
@@ -0,0 +1,958 @@
|
||||
/*global setImmediate: false, setTimeout: false, console: false */
|
||||
(function () {
|
||||
|
||||
var async = {};
|
||||
|
||||
// global on the server, window in the browser
|
||||
var root, previous_async;
|
||||
|
||||
root = this;
|
||||
if (root != null) {
|
||||
previous_async = root.async;
|
||||
}
|
||||
|
||||
async.noConflict = function () {
|
||||
root.async = previous_async;
|
||||
return async;
|
||||
};
|
||||
|
||||
function only_once(fn) {
|
||||
var called = false;
|
||||
return function() {
|
||||
if (called) throw new Error("Callback was already called.");
|
||||
called = true;
|
||||
fn.apply(root, arguments);
|
||||
}
|
||||
}
|
||||
|
||||
//// cross-browser compatiblity functions ////
|
||||
|
||||
var _each = function (arr, iterator) {
|
||||
if (arr.forEach) {
|
||||
return arr.forEach(iterator);
|
||||
}
|
||||
for (var i = 0; i < arr.length; i += 1) {
|
||||
iterator(arr[i], i, arr);
|
||||
}
|
||||
};
|
||||
|
||||
var _map = function (arr, iterator) {
|
||||
if (arr.map) {
|
||||
return arr.map(iterator);
|
||||
}
|
||||
var results = [];
|
||||
_each(arr, function (x, i, a) {
|
||||
results.push(iterator(x, i, a));
|
||||
});
|
||||
return results;
|
||||
};
|
||||
|
||||
var _reduce = function (arr, iterator, memo) {
|
||||
if (arr.reduce) {
|
||||
return arr.reduce(iterator, memo);
|
||||
}
|
||||
_each(arr, function (x, i, a) {
|
||||
memo = iterator(memo, x, i, a);
|
||||
});
|
||||
return memo;
|
||||
};
|
||||
|
||||
var _keys = function (obj) {
|
||||
if (Object.keys) {
|
||||
return Object.keys(obj);
|
||||
}
|
||||
var keys = [];
|
||||
for (var k in obj) {
|
||||
if (obj.hasOwnProperty(k)) {
|
||||
keys.push(k);
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
};
|
||||
|
||||
//// exported async module functions ////
|
||||
|
||||
//// nextTick implementation with browser-compatible fallback ////
|
||||
if (typeof process === 'undefined' || !(process.nextTick)) {
|
||||
if (typeof setImmediate === 'function') {
|
||||
async.nextTick = function (fn) {
|
||||
// not a direct alias for IE10 compatibility
|
||||
setImmediate(fn);
|
||||
};
|
||||
async.setImmediate = async.nextTick;
|
||||
}
|
||||
else {
|
||||
async.nextTick = function (fn) {
|
||||
setTimeout(fn, 0);
|
||||
};
|
||||
async.setImmediate = async.nextTick;
|
||||
}
|
||||
}
|
||||
else {
|
||||
async.nextTick = process.nextTick;
|
||||
if (typeof setImmediate !== 'undefined') {
|
||||
async.setImmediate = function (fn) {
|
||||
// not a direct alias for IE10 compatibility
|
||||
setImmediate(fn);
|
||||
};
|
||||
}
|
||||
else {
|
||||
async.setImmediate = async.nextTick;
|
||||
}
|
||||
}
|
||||
|
||||
async.each = function (arr, iterator, callback) {
|
||||
callback = callback || function () {};
|
||||
if (!arr.length) {
|
||||
return callback();
|
||||
}
|
||||
var completed = 0;
|
||||
_each(arr, function (x) {
|
||||
iterator(x, only_once(function (err) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
callback = function () {};
|
||||
}
|
||||
else {
|
||||
completed += 1;
|
||||
if (completed >= arr.length) {
|
||||
callback(null);
|
||||
}
|
||||
}
|
||||
}));
|
||||
});
|
||||
};
|
||||
async.forEach = async.each;
|
||||
|
||||
async.eachSeries = function (arr, iterator, callback) {
|
||||
callback = callback || function () {};
|
||||
if (!arr.length) {
|
||||
return callback();
|
||||
}
|
||||
var completed = 0;
|
||||
var iterate = function () {
|
||||
iterator(arr[completed], function (err) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
callback = function () {};
|
||||
}
|
||||
else {
|
||||
completed += 1;
|
||||
if (completed >= arr.length) {
|
||||
callback(null);
|
||||
}
|
||||
else {
|
||||
iterate();
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
iterate();
|
||||
};
|
||||
async.forEachSeries = async.eachSeries;
|
||||
|
||||
async.eachLimit = function (arr, limit, iterator, callback) {
|
||||
var fn = _eachLimit(limit);
|
||||
fn.apply(null, [arr, iterator, callback]);
|
||||
};
|
||||
async.forEachLimit = async.eachLimit;
|
||||
|
||||
var _eachLimit = function (limit) {
|
||||
|
||||
return function (arr, iterator, callback) {
|
||||
callback = callback || function () {};
|
||||
if (!arr.length || limit <= 0) {
|
||||
return callback();
|
||||
}
|
||||
var completed = 0;
|
||||
var started = 0;
|
||||
var running = 0;
|
||||
|
||||
(function replenish () {
|
||||
if (completed >= arr.length) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
while (running < limit && started < arr.length) {
|
||||
started += 1;
|
||||
running += 1;
|
||||
iterator(arr[started - 1], function (err) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
callback = function () {};
|
||||
}
|
||||
else {
|
||||
completed += 1;
|
||||
running -= 1;
|
||||
if (completed >= arr.length) {
|
||||
callback();
|
||||
}
|
||||
else {
|
||||
replenish();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
})();
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
var doParallel = function (fn) {
|
||||
return function () {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
return fn.apply(null, [async.each].concat(args));
|
||||
};
|
||||
};
|
||||
var doParallelLimit = function(limit, fn) {
|
||||
return function () {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
return fn.apply(null, [_eachLimit(limit)].concat(args));
|
||||
};
|
||||
};
|
||||
var doSeries = function (fn) {
|
||||
return function () {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
return fn.apply(null, [async.eachSeries].concat(args));
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
var _asyncMap = function (eachfn, arr, iterator, callback) {
|
||||
var results = [];
|
||||
arr = _map(arr, function (x, i) {
|
||||
return {index: i, value: x};
|
||||
});
|
||||
eachfn(arr, function (x, callback) {
|
||||
iterator(x.value, function (err, v) {
|
||||
results[x.index] = v;
|
||||
callback(err);
|
||||
});
|
||||
}, function (err) {
|
||||
callback(err, results);
|
||||
});
|
||||
};
|
||||
async.map = doParallel(_asyncMap);
|
||||
async.mapSeries = doSeries(_asyncMap);
|
||||
async.mapLimit = function (arr, limit, iterator, callback) {
|
||||
return _mapLimit(limit)(arr, iterator, callback);
|
||||
};
|
||||
|
||||
var _mapLimit = function(limit) {
|
||||
return doParallelLimit(limit, _asyncMap);
|
||||
};
|
||||
|
||||
// reduce only has a series version, as doing reduce in parallel won't
|
||||
// work in many situations.
|
||||
async.reduce = function (arr, memo, iterator, callback) {
|
||||
async.eachSeries(arr, function (x, callback) {
|
||||
iterator(memo, x, function (err, v) {
|
||||
memo = v;
|
||||
callback(err);
|
||||
});
|
||||
}, function (err) {
|
||||
callback(err, memo);
|
||||
});
|
||||
};
|
||||
// inject alias
|
||||
async.inject = async.reduce;
|
||||
// foldl alias
|
||||
async.foldl = async.reduce;
|
||||
|
||||
async.reduceRight = function (arr, memo, iterator, callback) {
|
||||
var reversed = _map(arr, function (x) {
|
||||
return x;
|
||||
}).reverse();
|
||||
async.reduce(reversed, memo, iterator, callback);
|
||||
};
|
||||
// foldr alias
|
||||
async.foldr = async.reduceRight;
|
||||
|
||||
var _filter = function (eachfn, arr, iterator, callback) {
|
||||
var results = [];
|
||||
arr = _map(arr, function (x, i) {
|
||||
return {index: i, value: x};
|
||||
});
|
||||
eachfn(arr, function (x, callback) {
|
||||
iterator(x.value, function (v) {
|
||||
if (v) {
|
||||
results.push(x);
|
||||
}
|
||||
callback();
|
||||
});
|
||||
}, function (err) {
|
||||
callback(_map(results.sort(function (a, b) {
|
||||
return a.index - b.index;
|
||||
}), function (x) {
|
||||
return x.value;
|
||||
}));
|
||||
});
|
||||
};
|
||||
async.filter = doParallel(_filter);
|
||||
async.filterSeries = doSeries(_filter);
|
||||
// select alias
|
||||
async.select = async.filter;
|
||||
async.selectSeries = async.filterSeries;
|
||||
|
||||
var _reject = function (eachfn, arr, iterator, callback) {
|
||||
var results = [];
|
||||
arr = _map(arr, function (x, i) {
|
||||
return {index: i, value: x};
|
||||
});
|
||||
eachfn(arr, function (x, callback) {
|
||||
iterator(x.value, function (v) {
|
||||
if (!v) {
|
||||
results.push(x);
|
||||
}
|
||||
callback();
|
||||
});
|
||||
}, function (err) {
|
||||
callback(_map(results.sort(function (a, b) {
|
||||
return a.index - b.index;
|
||||
}), function (x) {
|
||||
return x.value;
|
||||
}));
|
||||
});
|
||||
};
|
||||
async.reject = doParallel(_reject);
|
||||
async.rejectSeries = doSeries(_reject);
|
||||
|
||||
var _detect = function (eachfn, arr, iterator, main_callback) {
|
||||
eachfn(arr, function (x, callback) {
|
||||
iterator(x, function (result) {
|
||||
if (result) {
|
||||
main_callback(x);
|
||||
main_callback = function () {};
|
||||
}
|
||||
else {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
}, function (err) {
|
||||
main_callback();
|
||||
});
|
||||
};
|
||||
async.detect = doParallel(_detect);
|
||||
async.detectSeries = doSeries(_detect);
|
||||
|
||||
async.some = function (arr, iterator, main_callback) {
|
||||
async.each(arr, function (x, callback) {
|
||||
iterator(x, function (v) {
|
||||
if (v) {
|
||||
main_callback(true);
|
||||
main_callback = function () {};
|
||||
}
|
||||
callback();
|
||||
});
|
||||
}, function (err) {
|
||||
main_callback(false);
|
||||
});
|
||||
};
|
||||
// any alias
|
||||
async.any = async.some;
|
||||
|
||||
async.every = function (arr, iterator, main_callback) {
|
||||
async.each(arr, function (x, callback) {
|
||||
iterator(x, function (v) {
|
||||
if (!v) {
|
||||
main_callback(false);
|
||||
main_callback = function () {};
|
||||
}
|
||||
callback();
|
||||
});
|
||||
}, function (err) {
|
||||
main_callback(true);
|
||||
});
|
||||
};
|
||||
// all alias
|
||||
async.all = async.every;
|
||||
|
||||
async.sortBy = function (arr, iterator, callback) {
|
||||
async.map(arr, function (x, callback) {
|
||||
iterator(x, function (err, criteria) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
}
|
||||
else {
|
||||
callback(null, {value: x, criteria: criteria});
|
||||
}
|
||||
});
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
else {
|
||||
var fn = function (left, right) {
|
||||
var a = left.criteria, b = right.criteria;
|
||||
return a < b ? -1 : a > b ? 1 : 0;
|
||||
};
|
||||
callback(null, _map(results.sort(fn), function (x) {
|
||||
return x.value;
|
||||
}));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
async.auto = function (tasks, callback) {
|
||||
callback = callback || function () {};
|
||||
var keys = _keys(tasks);
|
||||
if (!keys.length) {
|
||||
return callback(null);
|
||||
}
|
||||
|
||||
var results = {};
|
||||
|
||||
var listeners = [];
|
||||
var addListener = function (fn) {
|
||||
listeners.unshift(fn);
|
||||
};
|
||||
var removeListener = function (fn) {
|
||||
for (var i = 0; i < listeners.length; i += 1) {
|
||||
if (listeners[i] === fn) {
|
||||
listeners.splice(i, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
var taskComplete = function () {
|
||||
_each(listeners.slice(0), function (fn) {
|
||||
fn();
|
||||
});
|
||||
};
|
||||
|
||||
addListener(function () {
|
||||
if (_keys(results).length === keys.length) {
|
||||
callback(null, results);
|
||||
callback = function () {};
|
||||
}
|
||||
});
|
||||
|
||||
_each(keys, function (k) {
|
||||
var task = (tasks[k] instanceof Function) ? [tasks[k]]: tasks[k];
|
||||
var taskCallback = function (err) {
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
if (args.length <= 1) {
|
||||
args = args[0];
|
||||
}
|
||||
if (err) {
|
||||
var safeResults = {};
|
||||
_each(_keys(results), function(rkey) {
|
||||
safeResults[rkey] = results[rkey];
|
||||
});
|
||||
safeResults[k] = args;
|
||||
callback(err, safeResults);
|
||||
// stop subsequent errors hitting callback multiple times
|
||||
callback = function () {};
|
||||
}
|
||||
else {
|
||||
results[k] = args;
|
||||
async.setImmediate(taskComplete);
|
||||
}
|
||||
};
|
||||
var requires = task.slice(0, Math.abs(task.length - 1)) || [];
|
||||
var ready = function () {
|
||||
return _reduce(requires, function (a, x) {
|
||||
return (a && results.hasOwnProperty(x));
|
||||
}, true) && !results.hasOwnProperty(k);
|
||||
};
|
||||
if (ready()) {
|
||||
task[task.length - 1](taskCallback, results);
|
||||
}
|
||||
else {
|
||||
var listener = function () {
|
||||
if (ready()) {
|
||||
removeListener(listener);
|
||||
task[task.length - 1](taskCallback, results);
|
||||
}
|
||||
};
|
||||
addListener(listener);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
async.waterfall = function (tasks, callback) {
|
||||
callback = callback || function () {};
|
||||
if (tasks.constructor !== Array) {
|
||||
var err = new Error('First argument to waterfall must be an array of functions');
|
||||
return callback(err);
|
||||
}
|
||||
if (!tasks.length) {
|
||||
return callback();
|
||||
}
|
||||
var wrapIterator = function (iterator) {
|
||||
return function (err) {
|
||||
if (err) {
|
||||
callback.apply(null, arguments);
|
||||
callback = function () {};
|
||||
}
|
||||
else {
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
var next = iterator.next();
|
||||
if (next) {
|
||||
args.push(wrapIterator(next));
|
||||
}
|
||||
else {
|
||||
args.push(callback);
|
||||
}
|
||||
async.setImmediate(function () {
|
||||
iterator.apply(null, args);
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
wrapIterator(async.iterator(tasks))();
|
||||
};
|
||||
|
||||
var _parallel = function(eachfn, tasks, callback) {
|
||||
callback = callback || function () {};
|
||||
if (tasks.constructor === Array) {
|
||||
eachfn.map(tasks, function (fn, callback) {
|
||||
if (fn) {
|
||||
fn(function (err) {
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
if (args.length <= 1) {
|
||||
args = args[0];
|
||||
}
|
||||
callback.call(null, err, args);
|
||||
});
|
||||
}
|
||||
}, callback);
|
||||
}
|
||||
else {
|
||||
var results = {};
|
||||
eachfn.each(_keys(tasks), function (k, callback) {
|
||||
tasks[k](function (err) {
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
if (args.length <= 1) {
|
||||
args = args[0];
|
||||
}
|
||||
results[k] = args;
|
||||
callback(err);
|
||||
});
|
||||
}, function (err) {
|
||||
callback(err, results);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
async.parallel = function (tasks, callback) {
|
||||
_parallel({ map: async.map, each: async.each }, tasks, callback);
|
||||
};
|
||||
|
||||
async.parallelLimit = function(tasks, limit, callback) {
|
||||
_parallel({ map: _mapLimit(limit), each: _eachLimit(limit) }, tasks, callback);
|
||||
};
|
||||
|
||||
async.series = function (tasks, callback) {
|
||||
callback = callback || function () {};
|
||||
if (tasks.constructor === Array) {
|
||||
async.mapSeries(tasks, function (fn, callback) {
|
||||
if (fn) {
|
||||
fn(function (err) {
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
if (args.length <= 1) {
|
||||
args = args[0];
|
||||
}
|
||||
callback.call(null, err, args);
|
||||
});
|
||||
}
|
||||
}, callback);
|
||||
}
|
||||
else {
|
||||
var results = {};
|
||||
async.eachSeries(_keys(tasks), function (k, callback) {
|
||||
tasks[k](function (err) {
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
if (args.length <= 1) {
|
||||
args = args[0];
|
||||
}
|
||||
results[k] = args;
|
||||
callback(err);
|
||||
});
|
||||
}, function (err) {
|
||||
callback(err, results);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
async.iterator = function (tasks) {
|
||||
var makeCallback = function (index) {
|
||||
var fn = function () {
|
||||
if (tasks.length) {
|
||||
tasks[index].apply(null, arguments);
|
||||
}
|
||||
return fn.next();
|
||||
};
|
||||
fn.next = function () {
|
||||
return (index < tasks.length - 1) ? makeCallback(index + 1): null;
|
||||
};
|
||||
return fn;
|
||||
};
|
||||
return makeCallback(0);
|
||||
};
|
||||
|
||||
async.apply = function (fn) {
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
return function () {
|
||||
return fn.apply(
|
||||
null, args.concat(Array.prototype.slice.call(arguments))
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
var _concat = function (eachfn, arr, fn, callback) {
|
||||
var r = [];
|
||||
eachfn(arr, function (x, cb) {
|
||||
fn(x, function (err, y) {
|
||||
r = r.concat(y || []);
|
||||
cb(err);
|
||||
});
|
||||
}, function (err) {
|
||||
callback(err, r);
|
||||
});
|
||||
};
|
||||
async.concat = doParallel(_concat);
|
||||
async.concatSeries = doSeries(_concat);
|
||||
|
||||
async.whilst = function (test, iterator, callback) {
|
||||
if (test()) {
|
||||
iterator(function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
async.whilst(test, iterator, callback);
|
||||
});
|
||||
}
|
||||
else {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
async.doWhilst = function (iterator, test, callback) {
|
||||
iterator(function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
if (test()) {
|
||||
async.doWhilst(iterator, test, callback);
|
||||
}
|
||||
else {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
async.until = function (test, iterator, callback) {
|
||||
if (!test()) {
|
||||
iterator(function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
async.until(test, iterator, callback);
|
||||
});
|
||||
}
|
||||
else {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
async.doUntil = function (iterator, test, callback) {
|
||||
iterator(function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
if (!test()) {
|
||||
async.doUntil(iterator, test, callback);
|
||||
}
|
||||
else {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
async.queue = function (worker, concurrency) {
|
||||
if (concurrency === undefined) {
|
||||
concurrency = 1;
|
||||
}
|
||||
function _insert(q, data, pos, callback) {
|
||||
if(data.constructor !== Array) {
|
||||
data = [data];
|
||||
}
|
||||
_each(data, function(task) {
|
||||
var item = {
|
||||
data: task,
|
||||
callback: typeof callback === 'function' ? callback : null
|
||||
};
|
||||
|
||||
if (pos) {
|
||||
q.tasks.unshift(item);
|
||||
} else {
|
||||
q.tasks.push(item);
|
||||
}
|
||||
|
||||
if (q.saturated && q.tasks.length === concurrency) {
|
||||
q.saturated();
|
||||
}
|
||||
async.setImmediate(q.process);
|
||||
});
|
||||
}
|
||||
|
||||
var workers = 0;
|
||||
var q = {
|
||||
tasks: [],
|
||||
concurrency: concurrency,
|
||||
saturated: null,
|
||||
empty: null,
|
||||
drain: null,
|
||||
push: function (data, callback) {
|
||||
_insert(q, data, false, callback);
|
||||
},
|
||||
unshift: function (data, callback) {
|
||||
_insert(q, data, true, callback);
|
||||
},
|
||||
process: function () {
|
||||
if (workers < q.concurrency && q.tasks.length) {
|
||||
var task = q.tasks.shift();
|
||||
if (q.empty && q.tasks.length === 0) {
|
||||
q.empty();
|
||||
}
|
||||
workers += 1;
|
||||
var next = function () {
|
||||
workers -= 1;
|
||||
if (task.callback) {
|
||||
task.callback.apply(task, arguments);
|
||||
}
|
||||
if (q.drain && q.tasks.length + workers === 0) {
|
||||
q.drain();
|
||||
}
|
||||
q.process();
|
||||
};
|
||||
var cb = only_once(next);
|
||||
worker(task.data, cb);
|
||||
}
|
||||
},
|
||||
length: function () {
|
||||
return q.tasks.length;
|
||||
},
|
||||
running: function () {
|
||||
return workers;
|
||||
}
|
||||
};
|
||||
return q;
|
||||
};
|
||||
|
||||
async.cargo = function (worker, payload) {
|
||||
var working = false,
|
||||
tasks = [];
|
||||
|
||||
var cargo = {
|
||||
tasks: tasks,
|
||||
payload: payload,
|
||||
saturated: null,
|
||||
empty: null,
|
||||
drain: null,
|
||||
push: function (data, callback) {
|
||||
if(data.constructor !== Array) {
|
||||
data = [data];
|
||||
}
|
||||
_each(data, function(task) {
|
||||
tasks.push({
|
||||
data: task,
|
||||
callback: typeof callback === 'function' ? callback : null
|
||||
});
|
||||
if (cargo.saturated && tasks.length === payload) {
|
||||
cargo.saturated();
|
||||
}
|
||||
});
|
||||
async.setImmediate(cargo.process);
|
||||
},
|
||||
process: function process() {
|
||||
if (working) return;
|
||||
if (tasks.length === 0) {
|
||||
if(cargo.drain) cargo.drain();
|
||||
return;
|
||||
}
|
||||
|
||||
var ts = typeof payload === 'number'
|
||||
? tasks.splice(0, payload)
|
||||
: tasks.splice(0);
|
||||
|
||||
var ds = _map(ts, function (task) {
|
||||
return task.data;
|
||||
});
|
||||
|
||||
if(cargo.empty) cargo.empty();
|
||||
working = true;
|
||||
worker(ds, function () {
|
||||
working = false;
|
||||
|
||||
var args = arguments;
|
||||
_each(ts, function (data) {
|
||||
if (data.callback) {
|
||||
data.callback.apply(null, args);
|
||||
}
|
||||
});
|
||||
|
||||
process();
|
||||
});
|
||||
},
|
||||
length: function () {
|
||||
return tasks.length;
|
||||
},
|
||||
running: function () {
|
||||
return working;
|
||||
}
|
||||
};
|
||||
return cargo;
|
||||
};
|
||||
|
||||
var _console_fn = function (name) {
|
||||
return function (fn) {
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
fn.apply(null, args.concat([function (err) {
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
if (typeof console !== 'undefined') {
|
||||
if (err) {
|
||||
if (console.error) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
else if (console[name]) {
|
||||
_each(args, function (x) {
|
||||
console[name](x);
|
||||
});
|
||||
}
|
||||
}
|
||||
}]));
|
||||
};
|
||||
};
|
||||
async.log = _console_fn('log');
|
||||
async.dir = _console_fn('dir');
|
||||
/*async.info = _console_fn('info');
|
||||
async.warn = _console_fn('warn');
|
||||
async.error = _console_fn('error');*/
|
||||
|
||||
async.memoize = function (fn, hasher) {
|
||||
var memo = {};
|
||||
var queues = {};
|
||||
hasher = hasher || function (x) {
|
||||
return x;
|
||||
};
|
||||
var memoized = function () {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
var callback = args.pop();
|
||||
var key = hasher.apply(null, args);
|
||||
if (key in memo) {
|
||||
callback.apply(null, memo[key]);
|
||||
}
|
||||
else if (key in queues) {
|
||||
queues[key].push(callback);
|
||||
}
|
||||
else {
|
||||
queues[key] = [callback];
|
||||
fn.apply(null, args.concat([function () {
|
||||
memo[key] = arguments;
|
||||
var q = queues[key];
|
||||
delete queues[key];
|
||||
for (var i = 0, l = q.length; i < l; i++) {
|
||||
q[i].apply(null, arguments);
|
||||
}
|
||||
}]));
|
||||
}
|
||||
};
|
||||
memoized.memo = memo;
|
||||
memoized.unmemoized = fn;
|
||||
return memoized;
|
||||
};
|
||||
|
||||
async.unmemoize = function (fn) {
|
||||
return function () {
|
||||
return (fn.unmemoized || fn).apply(null, arguments);
|
||||
};
|
||||
};
|
||||
|
||||
async.times = function (count, iterator, callback) {
|
||||
var counter = [];
|
||||
for (var i = 0; i < count; i++) {
|
||||
counter.push(i);
|
||||
}
|
||||
return async.map(counter, iterator, callback);
|
||||
};
|
||||
|
||||
async.timesSeries = function (count, iterator, callback) {
|
||||
var counter = [];
|
||||
for (var i = 0; i < count; i++) {
|
||||
counter.push(i);
|
||||
}
|
||||
return async.mapSeries(counter, iterator, callback);
|
||||
};
|
||||
|
||||
async.compose = function (/* functions... */) {
|
||||
var fns = Array.prototype.reverse.call(arguments);
|
||||
return function () {
|
||||
var that = this;
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
var callback = args.pop();
|
||||
async.reduce(fns, args, function (newargs, fn, cb) {
|
||||
fn.apply(that, newargs.concat([function () {
|
||||
var err = arguments[0];
|
||||
var nextargs = Array.prototype.slice.call(arguments, 1);
|
||||
cb(err, nextargs);
|
||||
}]))
|
||||
},
|
||||
function (err, results) {
|
||||
callback.apply(that, [err].concat(results));
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
var _applyEach = function (eachfn, fns /*args...*/) {
|
||||
var go = function () {
|
||||
var that = this;
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
var callback = args.pop();
|
||||
return eachfn(fns, function (fn, cb) {
|
||||
fn.apply(that, args.concat([cb]));
|
||||
},
|
||||
callback);
|
||||
};
|
||||
if (arguments.length > 2) {
|
||||
var args = Array.prototype.slice.call(arguments, 2);
|
||||
return go.apply(this, args);
|
||||
}
|
||||
else {
|
||||
return go;
|
||||
}
|
||||
};
|
||||
async.applyEach = doParallel(_applyEach);
|
||||
async.applyEachSeries = doSeries(_applyEach);
|
||||
|
||||
async.forever = function (fn, callback) {
|
||||
function next(err) {
|
||||
if (err) {
|
||||
if (callback) {
|
||||
return callback(err);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
fn(next);
|
||||
}
|
||||
next();
|
||||
};
|
||||
|
||||
// AMD / RequireJS
|
||||
if (typeof define !== 'undefined' && define.amd) {
|
||||
define([], function () {
|
||||
return async;
|
||||
});
|
||||
}
|
||||
// Node.js
|
||||
else if (typeof module !== 'undefined' && module.exports) {
|
||||
module.exports = async;
|
||||
}
|
||||
// included directly via <script> tag
|
||||
else {
|
||||
root.async = async;
|
||||
}
|
||||
|
||||
}());
|
||||
86
node_modules/swig/node_modules/async/package.json
generated
vendored
Normal file
86
node_modules/swig/node_modules/async/package.json
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"async@~0.2.6",
|
||||
"/home/mitchell/Desktop/test-mywebsite/mywebsite/node_modules/swig/node_modules/uglify-js"
|
||||
]
|
||||
],
|
||||
"_from": "async@>=0.2.6 <0.3.0",
|
||||
"_id": "async@0.2.10",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/swig/async",
|
||||
"_npmUser": {
|
||||
"email": "caolan.mcmahon@gmail.com",
|
||||
"name": "caolan"
|
||||
},
|
||||
"_npmVersion": "1.3.2",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "async",
|
||||
"raw": "async@~0.2.6",
|
||||
"rawSpec": "~0.2.6",
|
||||
"scope": null,
|
||||
"spec": ">=0.2.6 <0.3.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/swig/uglify-js"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/async/-/async-0.2.10.tgz",
|
||||
"_shasum": "b6bbe0b0674b9d719708ca38de8c237cb526c3d1",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "async@~0.2.6",
|
||||
"_where": "/home/mitchell/Desktop/test-mywebsite/mywebsite/node_modules/swig/node_modules/uglify-js",
|
||||
"author": {
|
||||
"name": "Caolan McMahon"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/caolan/async/issues"
|
||||
},
|
||||
"dependencies": {},
|
||||
"description": "Higher-order functions and common patterns for asynchronous code",
|
||||
"devDependencies": {
|
||||
"nodelint": ">0.0.0",
|
||||
"nodeunit": ">0.0.0",
|
||||
"uglify-js": "1.2.x"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "b6bbe0b0674b9d719708ca38de8c237cb526c3d1",
|
||||
"tarball": "http://registry.npmjs.org/async/-/async-0.2.10.tgz"
|
||||
},
|
||||
"homepage": "https://github.com/caolan/async#readme",
|
||||
"jam": {
|
||||
"include": [
|
||||
"LICENSE",
|
||||
"README.md",
|
||||
"lib/async.js"
|
||||
],
|
||||
"main": "lib/async.js"
|
||||
},
|
||||
"licenses": [
|
||||
{
|
||||
"type": "MIT",
|
||||
"url": "https://github.com/caolan/async/raw/master/LICENSE"
|
||||
}
|
||||
],
|
||||
"main": "./lib/async",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "caolan",
|
||||
"email": "caolan@caolanmcmahon.com"
|
||||
}
|
||||
],
|
||||
"name": "async",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/caolan/async.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "nodeunit test/test-async.js"
|
||||
},
|
||||
"version": "0.2.10"
|
||||
}
|
||||
4
node_modules/swig/node_modules/optimist/.travis.yml
generated
vendored
Normal file
4
node_modules/swig/node_modules/optimist/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.8"
|
||||
- "0.10"
|
||||
21
node_modules/swig/node_modules/optimist/LICENSE
generated
vendored
Normal file
21
node_modules/swig/node_modules/optimist/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
Copyright 2010 James Halliday (mail@substack.net)
|
||||
|
||||
This project is free software released under the MIT/X11 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.
|
||||
10
node_modules/swig/node_modules/optimist/example/bool.js
generated
vendored
Normal file
10
node_modules/swig/node_modules/optimist/example/bool.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env node
|
||||
var util = require('util');
|
||||
var argv = require('optimist').argv;
|
||||
|
||||
if (argv.s) {
|
||||
util.print(argv.fr ? 'Le chat dit: ' : 'The cat says: ');
|
||||
}
|
||||
console.log(
|
||||
(argv.fr ? 'miaou' : 'meow') + (argv.p ? '.' : '')
|
||||
);
|
||||
7
node_modules/swig/node_modules/optimist/example/boolean_double.js
generated
vendored
Normal file
7
node_modules/swig/node_modules/optimist/example/boolean_double.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
var argv = require('optimist')
|
||||
.boolean(['x','y','z'])
|
||||
.argv
|
||||
;
|
||||
console.dir([ argv.x, argv.y, argv.z ]);
|
||||
console.dir(argv._);
|
||||
7
node_modules/swig/node_modules/optimist/example/boolean_single.js
generated
vendored
Normal file
7
node_modules/swig/node_modules/optimist/example/boolean_single.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
var argv = require('optimist')
|
||||
.boolean('v')
|
||||
.argv
|
||||
;
|
||||
console.dir(argv.v);
|
||||
console.dir(argv._);
|
||||
8
node_modules/swig/node_modules/optimist/example/default_hash.js
generated
vendored
Normal file
8
node_modules/swig/node_modules/optimist/example/default_hash.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var argv = require('optimist')
|
||||
.default({ x : 10, y : 10 })
|
||||
.argv
|
||||
;
|
||||
|
||||
console.log(argv.x + argv.y);
|
||||
7
node_modules/swig/node_modules/optimist/example/default_singles.js
generated
vendored
Normal file
7
node_modules/swig/node_modules/optimist/example/default_singles.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
var argv = require('optimist')
|
||||
.default('x', 10)
|
||||
.default('y', 10)
|
||||
.argv
|
||||
;
|
||||
console.log(argv.x + argv.y);
|
||||
8
node_modules/swig/node_modules/optimist/example/divide.js
generated
vendored
Normal file
8
node_modules/swig/node_modules/optimist/example/divide.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var argv = require('optimist')
|
||||
.usage('Usage: $0 -x [num] -y [num]')
|
||||
.demand(['x','y'])
|
||||
.argv;
|
||||
|
||||
console.log(argv.x / argv.y);
|
||||
20
node_modules/swig/node_modules/optimist/example/line_count.js
generated
vendored
Normal file
20
node_modules/swig/node_modules/optimist/example/line_count.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env node
|
||||
var argv = require('optimist')
|
||||
.usage('Count the lines in a file.\nUsage: $0')
|
||||
.demand('f')
|
||||
.alias('f', 'file')
|
||||
.describe('f', 'Load a file')
|
||||
.argv
|
||||
;
|
||||
|
||||
var fs = require('fs');
|
||||
var s = fs.createReadStream(argv.file);
|
||||
|
||||
var lines = 0;
|
||||
s.on('data', function (buf) {
|
||||
lines += buf.toString().match(/\n/g).length;
|
||||
});
|
||||
|
||||
s.on('end', function () {
|
||||
console.log(lines);
|
||||
});
|
||||
29
node_modules/swig/node_modules/optimist/example/line_count_options.js
generated
vendored
Normal file
29
node_modules/swig/node_modules/optimist/example/line_count_options.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env node
|
||||
var argv = require('optimist')
|
||||
.usage('Count the lines in a file.\nUsage: $0')
|
||||
.options({
|
||||
file : {
|
||||
demand : true,
|
||||
alias : 'f',
|
||||
description : 'Load a file'
|
||||
},
|
||||
base : {
|
||||
alias : 'b',
|
||||
description : 'Numeric base to use for output',
|
||||
default : 10,
|
||||
},
|
||||
})
|
||||
.argv
|
||||
;
|
||||
|
||||
var fs = require('fs');
|
||||
var s = fs.createReadStream(argv.file);
|
||||
|
||||
var lines = 0;
|
||||
s.on('data', function (buf) {
|
||||
lines += buf.toString().match(/\n/g).length;
|
||||
});
|
||||
|
||||
s.on('end', function () {
|
||||
console.log(lines.toString(argv.base));
|
||||
});
|
||||
29
node_modules/swig/node_modules/optimist/example/line_count_wrap.js
generated
vendored
Normal file
29
node_modules/swig/node_modules/optimist/example/line_count_wrap.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env node
|
||||
var argv = require('optimist')
|
||||
.usage('Count the lines in a file.\nUsage: $0')
|
||||
.wrap(80)
|
||||
.demand('f')
|
||||
.alias('f', [ 'file', 'filename' ])
|
||||
.describe('f',
|
||||
"Load a file. It's pretty important."
|
||||
+ " Required even. So you'd better specify it."
|
||||
)
|
||||
.alias('b', 'base')
|
||||
.describe('b', 'Numeric base to display the number of lines in')
|
||||
.default('b', 10)
|
||||
.describe('x', 'Super-secret optional parameter which is secret')
|
||||
.default('x', '')
|
||||
.argv
|
||||
;
|
||||
|
||||
var fs = require('fs');
|
||||
var s = fs.createReadStream(argv.file);
|
||||
|
||||
var lines = 0;
|
||||
s.on('data', function (buf) {
|
||||
lines += buf.toString().match(/\n/g).length;
|
||||
});
|
||||
|
||||
s.on('end', function () {
|
||||
console.log(lines.toString(argv.base));
|
||||
});
|
||||
4
node_modules/swig/node_modules/optimist/example/nonopt.js
generated
vendored
Normal file
4
node_modules/swig/node_modules/optimist/example/nonopt.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
var argv = require('optimist').argv;
|
||||
console.log('(%d,%d)', argv.x, argv.y);
|
||||
console.log(argv._);
|
||||
2
node_modules/swig/node_modules/optimist/example/reflect.js
generated
vendored
Normal file
2
node_modules/swig/node_modules/optimist/example/reflect.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
#!/usr/bin/env node
|
||||
console.dir(require('optimist').argv);
|
||||
3
node_modules/swig/node_modules/optimist/example/short.js
generated
vendored
Normal file
3
node_modules/swig/node_modules/optimist/example/short.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env node
|
||||
var argv = require('optimist').argv;
|
||||
console.log('(%d,%d)', argv.x, argv.y);
|
||||
11
node_modules/swig/node_modules/optimist/example/string.js
generated
vendored
Normal file
11
node_modules/swig/node_modules/optimist/example/string.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env node
|
||||
var argv = require('optimist')
|
||||
.string('x', 'y')
|
||||
.argv
|
||||
;
|
||||
console.dir([ argv.x, argv.y ]);
|
||||
|
||||
/* Turns off numeric coercion:
|
||||
./node string.js -x 000123 -y 9876
|
||||
[ '000123', '9876' ]
|
||||
*/
|
||||
19
node_modules/swig/node_modules/optimist/example/usage-options.js
generated
vendored
Normal file
19
node_modules/swig/node_modules/optimist/example/usage-options.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
var optimist = require('./../index');
|
||||
|
||||
var argv = optimist.usage('This is my awesome program', {
|
||||
'about': {
|
||||
description: 'Provide some details about the author of this program',
|
||||
required: true,
|
||||
short: 'a',
|
||||
},
|
||||
'info': {
|
||||
description: 'Provide some information about the node.js agains!!!!!!',
|
||||
boolean: true,
|
||||
short: 'i'
|
||||
}
|
||||
}).argv;
|
||||
|
||||
optimist.showHelp();
|
||||
|
||||
console.log('\n\nInspecting options');
|
||||
console.dir(argv);
|
||||
10
node_modules/swig/node_modules/optimist/example/xup.js
generated
vendored
Normal file
10
node_modules/swig/node_modules/optimist/example/xup.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env node
|
||||
var argv = require('optimist').argv;
|
||||
|
||||
if (argv.rif - 5 * argv.xup > 7.138) {
|
||||
console.log('Buy more riffiwobbles');
|
||||
}
|
||||
else {
|
||||
console.log('Sell the xupptumblers');
|
||||
}
|
||||
|
||||
343
node_modules/swig/node_modules/optimist/index.js
generated
vendored
Normal file
343
node_modules/swig/node_modules/optimist/index.js
generated
vendored
Normal file
@@ -0,0 +1,343 @@
|
||||
var path = require('path');
|
||||
var minimist = require('minimist');
|
||||
var wordwrap = require('wordwrap');
|
||||
|
||||
/* Hack an instance of Argv with process.argv into Argv
|
||||
so people can do
|
||||
require('optimist')(['--beeble=1','-z','zizzle']).argv
|
||||
to parse a list of args and
|
||||
require('optimist').argv
|
||||
to get a parsed version of process.argv.
|
||||
*/
|
||||
|
||||
var inst = Argv(process.argv.slice(2));
|
||||
Object.keys(inst).forEach(function (key) {
|
||||
Argv[key] = typeof inst[key] == 'function'
|
||||
? inst[key].bind(inst)
|
||||
: inst[key];
|
||||
});
|
||||
|
||||
var exports = module.exports = Argv;
|
||||
function Argv (processArgs, cwd) {
|
||||
var self = {};
|
||||
if (!cwd) cwd = process.cwd();
|
||||
|
||||
self.$0 = process.argv
|
||||
.slice(0,2)
|
||||
.map(function (x) {
|
||||
var b = rebase(cwd, x);
|
||||
return x.match(/^\//) && b.length < x.length
|
||||
? b : x
|
||||
})
|
||||
.join(' ')
|
||||
;
|
||||
|
||||
if (process.env._ != undefined && process.argv[1] == process.env._) {
|
||||
self.$0 = process.env._.replace(
|
||||
path.dirname(process.execPath) + '/', ''
|
||||
);
|
||||
}
|
||||
|
||||
var options = {
|
||||
boolean: [],
|
||||
string: [],
|
||||
alias: {},
|
||||
default: []
|
||||
};
|
||||
|
||||
self.boolean = function (bools) {
|
||||
options.boolean.push.apply(options.boolean, [].concat(bools));
|
||||
return self;
|
||||
};
|
||||
|
||||
self.string = function (strings) {
|
||||
options.string.push.apply(options.string, [].concat(strings));
|
||||
return self;
|
||||
};
|
||||
|
||||
self.default = function (key, value) {
|
||||
if (typeof key === 'object') {
|
||||
Object.keys(key).forEach(function (k) {
|
||||
self.default(k, key[k]);
|
||||
});
|
||||
}
|
||||
else {
|
||||
options.default[key] = value;
|
||||
}
|
||||
return self;
|
||||
};
|
||||
|
||||
self.alias = function (x, y) {
|
||||
if (typeof x === 'object') {
|
||||
Object.keys(x).forEach(function (key) {
|
||||
self.alias(key, x[key]);
|
||||
});
|
||||
}
|
||||
else {
|
||||
options.alias[x] = (options.alias[x] || []).concat(y);
|
||||
}
|
||||
return self;
|
||||
};
|
||||
|
||||
var demanded = {};
|
||||
self.demand = function (keys) {
|
||||
if (typeof keys == 'number') {
|
||||
if (!demanded._) demanded._ = 0;
|
||||
demanded._ += keys;
|
||||
}
|
||||
else if (Array.isArray(keys)) {
|
||||
keys.forEach(function (key) {
|
||||
self.demand(key);
|
||||
});
|
||||
}
|
||||
else {
|
||||
demanded[keys] = true;
|
||||
}
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
var usage;
|
||||
self.usage = function (msg, opts) {
|
||||
if (!opts && typeof msg === 'object') {
|
||||
opts = msg;
|
||||
msg = null;
|
||||
}
|
||||
|
||||
usage = msg;
|
||||
|
||||
if (opts) self.options(opts);
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
function fail (msg) {
|
||||
self.showHelp();
|
||||
if (msg) console.error(msg);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
var checks = [];
|
||||
self.check = function (f) {
|
||||
checks.push(f);
|
||||
return self;
|
||||
};
|
||||
|
||||
var descriptions = {};
|
||||
self.describe = function (key, desc) {
|
||||
if (typeof key === 'object') {
|
||||
Object.keys(key).forEach(function (k) {
|
||||
self.describe(k, key[k]);
|
||||
});
|
||||
}
|
||||
else {
|
||||
descriptions[key] = desc;
|
||||
}
|
||||
return self;
|
||||
};
|
||||
|
||||
self.parse = function (args) {
|
||||
return parseArgs(args);
|
||||
};
|
||||
|
||||
self.option = self.options = function (key, opt) {
|
||||
if (typeof key === 'object') {
|
||||
Object.keys(key).forEach(function (k) {
|
||||
self.options(k, key[k]);
|
||||
});
|
||||
}
|
||||
else {
|
||||
if (opt.alias) self.alias(key, opt.alias);
|
||||
if (opt.demand) self.demand(key);
|
||||
if (typeof opt.default !== 'undefined') {
|
||||
self.default(key, opt.default);
|
||||
}
|
||||
|
||||
if (opt.boolean || opt.type === 'boolean') {
|
||||
self.boolean(key);
|
||||
}
|
||||
if (opt.string || opt.type === 'string') {
|
||||
self.string(key);
|
||||
}
|
||||
|
||||
var desc = opt.describe || opt.description || opt.desc;
|
||||
if (desc) {
|
||||
self.describe(key, desc);
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
var wrap = null;
|
||||
self.wrap = function (cols) {
|
||||
wrap = cols;
|
||||
return self;
|
||||
};
|
||||
|
||||
self.showHelp = function (fn) {
|
||||
if (!fn) fn = console.error;
|
||||
fn(self.help());
|
||||
};
|
||||
|
||||
self.help = function () {
|
||||
var keys = Object.keys(
|
||||
Object.keys(descriptions)
|
||||
.concat(Object.keys(demanded))
|
||||
.concat(Object.keys(options.default))
|
||||
.reduce(function (acc, key) {
|
||||
if (key !== '_') acc[key] = true;
|
||||
return acc;
|
||||
}, {})
|
||||
);
|
||||
|
||||
var help = keys.length ? [ 'Options:' ] : [];
|
||||
|
||||
if (usage) {
|
||||
help.unshift(usage.replace(/\$0/g, self.$0), '');
|
||||
}
|
||||
|
||||
var switches = keys.reduce(function (acc, key) {
|
||||
acc[key] = [ key ].concat(options.alias[key] || [])
|
||||
.map(function (sw) {
|
||||
return (sw.length > 1 ? '--' : '-') + sw
|
||||
})
|
||||
.join(', ')
|
||||
;
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
var switchlen = longest(Object.keys(switches).map(function (s) {
|
||||
return switches[s] || '';
|
||||
}));
|
||||
|
||||
var desclen = longest(Object.keys(descriptions).map(function (d) {
|
||||
return descriptions[d] || '';
|
||||
}));
|
||||
|
||||
keys.forEach(function (key) {
|
||||
var kswitch = switches[key];
|
||||
var desc = descriptions[key] || '';
|
||||
|
||||
if (wrap) {
|
||||
desc = wordwrap(switchlen + 4, wrap)(desc)
|
||||
.slice(switchlen + 4)
|
||||
;
|
||||
}
|
||||
|
||||
var spadding = new Array(
|
||||
Math.max(switchlen - kswitch.length + 3, 0)
|
||||
).join(' ');
|
||||
|
||||
var dpadding = new Array(
|
||||
Math.max(desclen - desc.length + 1, 0)
|
||||
).join(' ');
|
||||
|
||||
var type = null;
|
||||
|
||||
if (options.boolean[key]) type = '[boolean]';
|
||||
if (options.string[key]) type = '[string]';
|
||||
|
||||
if (!wrap && dpadding.length > 0) {
|
||||
desc += dpadding;
|
||||
}
|
||||
|
||||
var prelude = ' ' + kswitch + spadding;
|
||||
var extra = [
|
||||
type,
|
||||
demanded[key]
|
||||
? '[required]'
|
||||
: null
|
||||
,
|
||||
options.default[key] !== undefined
|
||||
? '[default: ' + JSON.stringify(options.default[key]) + ']'
|
||||
: null
|
||||
,
|
||||
].filter(Boolean).join(' ');
|
||||
|
||||
var body = [ desc, extra ].filter(Boolean).join(' ');
|
||||
|
||||
if (wrap) {
|
||||
var dlines = desc.split('\n');
|
||||
var dlen = dlines.slice(-1)[0].length
|
||||
+ (dlines.length === 1 ? prelude.length : 0)
|
||||
|
||||
body = desc + (dlen + extra.length > wrap - 2
|
||||
? '\n'
|
||||
+ new Array(wrap - extra.length + 1).join(' ')
|
||||
+ extra
|
||||
: new Array(wrap - extra.length - dlen + 1).join(' ')
|
||||
+ extra
|
||||
);
|
||||
}
|
||||
|
||||
help.push(prelude + body);
|
||||
});
|
||||
|
||||
help.push('');
|
||||
return help.join('\n');
|
||||
};
|
||||
|
||||
Object.defineProperty(self, 'argv', {
|
||||
get : function () { return parseArgs(processArgs) },
|
||||
enumerable : true,
|
||||
});
|
||||
|
||||
function parseArgs (args) {
|
||||
var argv = minimist(args, options);
|
||||
argv.$0 = self.$0;
|
||||
|
||||
if (demanded._ && argv._.length < demanded._) {
|
||||
fail('Not enough non-option arguments: got '
|
||||
+ argv._.length + ', need at least ' + demanded._
|
||||
);
|
||||
}
|
||||
|
||||
var missing = [];
|
||||
Object.keys(demanded).forEach(function (key) {
|
||||
if (!argv[key]) missing.push(key);
|
||||
});
|
||||
|
||||
if (missing.length) {
|
||||
fail('Missing required arguments: ' + missing.join(', '));
|
||||
}
|
||||
|
||||
checks.forEach(function (f) {
|
||||
try {
|
||||
if (f(argv) === false) {
|
||||
fail('Argument check failed: ' + f.toString());
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
fail(err)
|
||||
}
|
||||
});
|
||||
|
||||
return argv;
|
||||
}
|
||||
|
||||
function longest (xs) {
|
||||
return Math.max.apply(
|
||||
null,
|
||||
xs.map(function (x) { return x.length })
|
||||
);
|
||||
}
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
// rebase an absolute path to a relative one with respect to a base directory
|
||||
// exported for tests
|
||||
exports.rebase = rebase;
|
||||
function rebase (base, dir) {
|
||||
var ds = path.normalize(dir).split('/').slice(1);
|
||||
var bs = path.normalize(base).split('/').slice(1);
|
||||
|
||||
for (var i = 0; ds[i] && ds[i] == bs[i]; i++);
|
||||
ds.splice(0, i); bs.splice(0, i);
|
||||
|
||||
var p = path.normalize(
|
||||
bs.map(function () { return '..' }).concat(ds).join('/')
|
||||
).replace(/\/$/,'').replace(/^$/, '.');
|
||||
return p.match(/^[.\/]/) ? p : './' + p;
|
||||
};
|
||||
89
node_modules/swig/node_modules/optimist/package.json
generated
vendored
Normal file
89
node_modules/swig/node_modules/optimist/package.json
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"optimist@~0.6",
|
||||
"/home/mitchell/Desktop/test-mywebsite/mywebsite/node_modules/swig"
|
||||
]
|
||||
],
|
||||
"_from": "optimist@>=0.6.0 <0.7.0",
|
||||
"_id": "optimist@0.6.1",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/swig/optimist",
|
||||
"_npmUser": {
|
||||
"email": "mail@substack.net",
|
||||
"name": "substack"
|
||||
},
|
||||
"_npmVersion": "1.3.21",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "optimist",
|
||||
"raw": "optimist@~0.6",
|
||||
"rawSpec": "~0.6",
|
||||
"scope": null,
|
||||
"spec": ">=0.6.0 <0.7.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/swig"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz",
|
||||
"_shasum": "da3ea74686fa21a19a111c326e90eb15a0196686",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "optimist@~0.6",
|
||||
"_where": "/home/mitchell/Desktop/test-mywebsite/mywebsite/node_modules/swig",
|
||||
"author": {
|
||||
"email": "mail@substack.net",
|
||||
"name": "James Halliday",
|
||||
"url": "http://substack.net"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/substack/node-optimist/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"minimist": "~0.0.1",
|
||||
"wordwrap": "~0.0.2"
|
||||
},
|
||||
"description": "Light-weight option parsing with an argv hash. No optstrings attached.",
|
||||
"devDependencies": {
|
||||
"hashish": "~0.0.4",
|
||||
"tap": "~0.4.0"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "da3ea74686fa21a19a111c326e90eb15a0196686",
|
||||
"tarball": "http://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz"
|
||||
},
|
||||
"engine": {
|
||||
"node": ">=0.4"
|
||||
},
|
||||
"homepage": "https://github.com/substack/node-optimist",
|
||||
"keywords": [
|
||||
"args",
|
||||
"argument",
|
||||
"cli",
|
||||
"command",
|
||||
"option",
|
||||
"parser",
|
||||
"parsing"
|
||||
],
|
||||
"license": "MIT/X11",
|
||||
"main": "./index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "substack",
|
||||
"email": "mail@substack.net"
|
||||
}
|
||||
],
|
||||
"name": "optimist",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/substack/node-optimist.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tap ./test/*.js"
|
||||
},
|
||||
"version": "0.6.1"
|
||||
}
|
||||
513
node_modules/swig/node_modules/optimist/readme.markdown
generated
vendored
Normal file
513
node_modules/swig/node_modules/optimist/readme.markdown
generated
vendored
Normal file
@@ -0,0 +1,513 @@
|
||||
# DEPRECATION NOTICE
|
||||
|
||||
I don't want to maintain this module anymore since I just use
|
||||
[minimist](https://npmjs.org/package/minimist), the argument parsing engine,
|
||||
directly instead nowadays.
|
||||
|
||||
See [yargs](https://github.com/chevex/yargs) for the modern, pirate-themed
|
||||
successor to optimist.
|
||||
|
||||
[](https://github.com/chevex/yargs)
|
||||
|
||||
You should also consider [nomnom](https://github.com/harthur/nomnom).
|
||||
|
||||
optimist
|
||||
========
|
||||
|
||||
Optimist is a node.js library for option parsing for people who hate option
|
||||
parsing. More specifically, this module is for people who like all the --bells
|
||||
and -whistlz of program usage but think optstrings are a waste of time.
|
||||
|
||||
With optimist, option parsing doesn't have to suck (as much).
|
||||
|
||||
[](http://travis-ci.org/substack/node-optimist)
|
||||
|
||||
examples
|
||||
========
|
||||
|
||||
With Optimist, the options are just a hash! No optstrings attached.
|
||||
-------------------------------------------------------------------
|
||||
|
||||
xup.js:
|
||||
|
||||
````javascript
|
||||
#!/usr/bin/env node
|
||||
var argv = require('optimist').argv;
|
||||
|
||||
if (argv.rif - 5 * argv.xup > 7.138) {
|
||||
console.log('Buy more riffiwobbles');
|
||||
}
|
||||
else {
|
||||
console.log('Sell the xupptumblers');
|
||||
}
|
||||
````
|
||||
|
||||
***
|
||||
|
||||
$ ./xup.js --rif=55 --xup=9.52
|
||||
Buy more riffiwobbles
|
||||
|
||||
$ ./xup.js --rif 12 --xup 8.1
|
||||
Sell the xupptumblers
|
||||
|
||||

|
||||
|
||||
But wait! There's more! You can do short options:
|
||||
-------------------------------------------------
|
||||
|
||||
short.js:
|
||||
|
||||
````javascript
|
||||
#!/usr/bin/env node
|
||||
var argv = require('optimist').argv;
|
||||
console.log('(%d,%d)', argv.x, argv.y);
|
||||
````
|
||||
|
||||
***
|
||||
|
||||
$ ./short.js -x 10 -y 21
|
||||
(10,21)
|
||||
|
||||
And booleans, both long and short (and grouped):
|
||||
----------------------------------
|
||||
|
||||
bool.js:
|
||||
|
||||
````javascript
|
||||
#!/usr/bin/env node
|
||||
var util = require('util');
|
||||
var argv = require('optimist').argv;
|
||||
|
||||
if (argv.s) {
|
||||
util.print(argv.fr ? 'Le chat dit: ' : 'The cat says: ');
|
||||
}
|
||||
console.log(
|
||||
(argv.fr ? 'miaou' : 'meow') + (argv.p ? '.' : '')
|
||||
);
|
||||
````
|
||||
|
||||
***
|
||||
|
||||
$ ./bool.js -s
|
||||
The cat says: meow
|
||||
|
||||
$ ./bool.js -sp
|
||||
The cat says: meow.
|
||||
|
||||
$ ./bool.js -sp --fr
|
||||
Le chat dit: miaou.
|
||||
|
||||
And non-hypenated options too! Just use `argv._`!
|
||||
-------------------------------------------------
|
||||
|
||||
nonopt.js:
|
||||
|
||||
````javascript
|
||||
#!/usr/bin/env node
|
||||
var argv = require('optimist').argv;
|
||||
console.log('(%d,%d)', argv.x, argv.y);
|
||||
console.log(argv._);
|
||||
````
|
||||
|
||||
***
|
||||
|
||||
$ ./nonopt.js -x 6.82 -y 3.35 moo
|
||||
(6.82,3.35)
|
||||
[ 'moo' ]
|
||||
|
||||
$ ./nonopt.js foo -x 0.54 bar -y 1.12 baz
|
||||
(0.54,1.12)
|
||||
[ 'foo', 'bar', 'baz' ]
|
||||
|
||||
Plus, Optimist comes with .usage() and .demand()!
|
||||
-------------------------------------------------
|
||||
|
||||
divide.js:
|
||||
|
||||
````javascript
|
||||
#!/usr/bin/env node
|
||||
var argv = require('optimist')
|
||||
.usage('Usage: $0 -x [num] -y [num]')
|
||||
.demand(['x','y'])
|
||||
.argv;
|
||||
|
||||
console.log(argv.x / argv.y);
|
||||
````
|
||||
|
||||
***
|
||||
|
||||
$ ./divide.js -x 55 -y 11
|
||||
5
|
||||
|
||||
$ node ./divide.js -x 4.91 -z 2.51
|
||||
Usage: node ./divide.js -x [num] -y [num]
|
||||
|
||||
Options:
|
||||
-x [required]
|
||||
-y [required]
|
||||
|
||||
Missing required arguments: y
|
||||
|
||||
EVEN MORE HOLY COW
|
||||
------------------
|
||||
|
||||
default_singles.js:
|
||||
|
||||
````javascript
|
||||
#!/usr/bin/env node
|
||||
var argv = require('optimist')
|
||||
.default('x', 10)
|
||||
.default('y', 10)
|
||||
.argv
|
||||
;
|
||||
console.log(argv.x + argv.y);
|
||||
````
|
||||
|
||||
***
|
||||
|
||||
$ ./default_singles.js -x 5
|
||||
15
|
||||
|
||||
default_hash.js:
|
||||
|
||||
````javascript
|
||||
#!/usr/bin/env node
|
||||
var argv = require('optimist')
|
||||
.default({ x : 10, y : 10 })
|
||||
.argv
|
||||
;
|
||||
console.log(argv.x + argv.y);
|
||||
````
|
||||
|
||||
***
|
||||
|
||||
$ ./default_hash.js -y 7
|
||||
17
|
||||
|
||||
And if you really want to get all descriptive about it...
|
||||
---------------------------------------------------------
|
||||
|
||||
boolean_single.js
|
||||
|
||||
````javascript
|
||||
#!/usr/bin/env node
|
||||
var argv = require('optimist')
|
||||
.boolean('v')
|
||||
.argv
|
||||
;
|
||||
console.dir(argv);
|
||||
````
|
||||
|
||||
***
|
||||
|
||||
$ ./boolean_single.js -v foo bar baz
|
||||
true
|
||||
[ 'bar', 'baz', 'foo' ]
|
||||
|
||||
boolean_double.js
|
||||
|
||||
````javascript
|
||||
#!/usr/bin/env node
|
||||
var argv = require('optimist')
|
||||
.boolean(['x','y','z'])
|
||||
.argv
|
||||
;
|
||||
console.dir([ argv.x, argv.y, argv.z ]);
|
||||
console.dir(argv._);
|
||||
````
|
||||
|
||||
***
|
||||
|
||||
$ ./boolean_double.js -x -z one two three
|
||||
[ true, false, true ]
|
||||
[ 'one', 'two', 'three' ]
|
||||
|
||||
Optimist is here to help...
|
||||
---------------------------
|
||||
|
||||
You can describe parameters for help messages and set aliases. Optimist figures
|
||||
out how to format a handy help string automatically.
|
||||
|
||||
line_count.js
|
||||
|
||||
````javascript
|
||||
#!/usr/bin/env node
|
||||
var argv = require('optimist')
|
||||
.usage('Count the lines in a file.\nUsage: $0')
|
||||
.demand('f')
|
||||
.alias('f', 'file')
|
||||
.describe('f', 'Load a file')
|
||||
.argv
|
||||
;
|
||||
|
||||
var fs = require('fs');
|
||||
var s = fs.createReadStream(argv.file);
|
||||
|
||||
var lines = 0;
|
||||
s.on('data', function (buf) {
|
||||
lines += buf.toString().match(/\n/g).length;
|
||||
});
|
||||
|
||||
s.on('end', function () {
|
||||
console.log(lines);
|
||||
});
|
||||
````
|
||||
|
||||
***
|
||||
|
||||
$ node line_count.js
|
||||
Count the lines in a file.
|
||||
Usage: node ./line_count.js
|
||||
|
||||
Options:
|
||||
-f, --file Load a file [required]
|
||||
|
||||
Missing required arguments: f
|
||||
|
||||
$ node line_count.js --file line_count.js
|
||||
20
|
||||
|
||||
$ node line_count.js -f line_count.js
|
||||
20
|
||||
|
||||
methods
|
||||
=======
|
||||
|
||||
By itself,
|
||||
|
||||
````javascript
|
||||
require('optimist').argv
|
||||
`````
|
||||
|
||||
will use `process.argv` array to construct the `argv` object.
|
||||
|
||||
You can pass in the `process.argv` yourself:
|
||||
|
||||
````javascript
|
||||
require('optimist')([ '-x', '1', '-y', '2' ]).argv
|
||||
````
|
||||
|
||||
or use .parse() to do the same thing:
|
||||
|
||||
````javascript
|
||||
require('optimist').parse([ '-x', '1', '-y', '2' ])
|
||||
````
|
||||
|
||||
The rest of these methods below come in just before the terminating `.argv`.
|
||||
|
||||
.alias(key, alias)
|
||||
------------------
|
||||
|
||||
Set key names as equivalent such that updates to a key will propagate to aliases
|
||||
and vice-versa.
|
||||
|
||||
Optionally `.alias()` can take an object that maps keys to aliases.
|
||||
|
||||
.default(key, value)
|
||||
--------------------
|
||||
|
||||
Set `argv[key]` to `value` if no option was specified on `process.argv`.
|
||||
|
||||
Optionally `.default()` can take an object that maps keys to default values.
|
||||
|
||||
.demand(key)
|
||||
------------
|
||||
|
||||
If `key` is a string, show the usage information and exit if `key` wasn't
|
||||
specified in `process.argv`.
|
||||
|
||||
If `key` is a number, demand at least as many non-option arguments, which show
|
||||
up in `argv._`.
|
||||
|
||||
If `key` is an Array, demand each element.
|
||||
|
||||
.describe(key, desc)
|
||||
--------------------
|
||||
|
||||
Describe a `key` for the generated usage information.
|
||||
|
||||
Optionally `.describe()` can take an object that maps keys to descriptions.
|
||||
|
||||
.options(key, opt)
|
||||
------------------
|
||||
|
||||
Instead of chaining together `.alias().demand().default()`, you can specify
|
||||
keys in `opt` for each of the chainable methods.
|
||||
|
||||
For example:
|
||||
|
||||
````javascript
|
||||
var argv = require('optimist')
|
||||
.options('f', {
|
||||
alias : 'file',
|
||||
default : '/etc/passwd',
|
||||
})
|
||||
.argv
|
||||
;
|
||||
````
|
||||
|
||||
is the same as
|
||||
|
||||
````javascript
|
||||
var argv = require('optimist')
|
||||
.alias('f', 'file')
|
||||
.default('f', '/etc/passwd')
|
||||
.argv
|
||||
;
|
||||
````
|
||||
|
||||
Optionally `.options()` can take an object that maps keys to `opt` parameters.
|
||||
|
||||
.usage(message)
|
||||
---------------
|
||||
|
||||
Set a usage message to show which commands to use. Inside `message`, the string
|
||||
`$0` will get interpolated to the current script name or node command for the
|
||||
present script similar to how `$0` works in bash or perl.
|
||||
|
||||
.check(fn)
|
||||
----------
|
||||
|
||||
Check that certain conditions are met in the provided arguments.
|
||||
|
||||
If `fn` throws or returns `false`, show the thrown error, usage information, and
|
||||
exit.
|
||||
|
||||
.boolean(key)
|
||||
-------------
|
||||
|
||||
Interpret `key` as a boolean. If a non-flag option follows `key` in
|
||||
`process.argv`, that string won't get set as the value of `key`.
|
||||
|
||||
If `key` never shows up as a flag in `process.arguments`, `argv[key]` will be
|
||||
`false`.
|
||||
|
||||
If `key` is an Array, interpret all the elements as booleans.
|
||||
|
||||
.string(key)
|
||||
------------
|
||||
|
||||
Tell the parser logic not to interpret `key` as a number or boolean.
|
||||
This can be useful if you need to preserve leading zeros in an input.
|
||||
|
||||
If `key` is an Array, interpret all the elements as strings.
|
||||
|
||||
.wrap(columns)
|
||||
--------------
|
||||
|
||||
Format usage output to wrap at `columns` many columns.
|
||||
|
||||
.help()
|
||||
-------
|
||||
|
||||
Return the generated usage string.
|
||||
|
||||
.showHelp(fn=console.error)
|
||||
---------------------------
|
||||
|
||||
Print the usage data using `fn` for printing.
|
||||
|
||||
.parse(args)
|
||||
------------
|
||||
|
||||
Parse `args` instead of `process.argv`. Returns the `argv` object.
|
||||
|
||||
.argv
|
||||
-----
|
||||
|
||||
Get the arguments as a plain old object.
|
||||
|
||||
Arguments without a corresponding flag show up in the `argv._` array.
|
||||
|
||||
The script name or node command is available at `argv.$0` similarly to how `$0`
|
||||
works in bash or perl.
|
||||
|
||||
parsing tricks
|
||||
==============
|
||||
|
||||
stop parsing
|
||||
------------
|
||||
|
||||
Use `--` to stop parsing flags and stuff the remainder into `argv._`.
|
||||
|
||||
$ node examples/reflect.js -a 1 -b 2 -- -c 3 -d 4
|
||||
{ _: [ '-c', '3', '-d', '4' ],
|
||||
'$0': 'node ./examples/reflect.js',
|
||||
a: 1,
|
||||
b: 2 }
|
||||
|
||||
negate fields
|
||||
-------------
|
||||
|
||||
If you want to explicity set a field to false instead of just leaving it
|
||||
undefined or to override a default you can do `--no-key`.
|
||||
|
||||
$ node examples/reflect.js -a --no-b
|
||||
{ _: [],
|
||||
'$0': 'node ./examples/reflect.js',
|
||||
a: true,
|
||||
b: false }
|
||||
|
||||
numbers
|
||||
-------
|
||||
|
||||
Every argument that looks like a number (`!isNaN(Number(arg))`) is converted to
|
||||
one. This way you can just `net.createConnection(argv.port)` and you can add
|
||||
numbers out of `argv` with `+` without having that mean concatenation,
|
||||
which is super frustrating.
|
||||
|
||||
duplicates
|
||||
----------
|
||||
|
||||
If you specify a flag multiple times it will get turned into an array containing
|
||||
all the values in order.
|
||||
|
||||
$ node examples/reflect.js -x 5 -x 8 -x 0
|
||||
{ _: [],
|
||||
'$0': 'node ./examples/reflect.js',
|
||||
x: [ 5, 8, 0 ] }
|
||||
|
||||
dot notation
|
||||
------------
|
||||
|
||||
When you use dots (`.`s) in argument names, an implicit object path is assumed.
|
||||
This lets you organize arguments into nested objects.
|
||||
|
||||
$ node examples/reflect.js --foo.bar.baz=33 --foo.quux=5
|
||||
{ _: [],
|
||||
'$0': 'node ./examples/reflect.js',
|
||||
foo: { bar: { baz: 33 }, quux: 5 } }
|
||||
|
||||
short numbers
|
||||
-------------
|
||||
|
||||
Short numeric `head -n5` style argument work too:
|
||||
|
||||
$ node reflect.js -n123 -m456
|
||||
{ '3': true,
|
||||
'6': true,
|
||||
_: [],
|
||||
'$0': 'node ./reflect.js',
|
||||
n: 123,
|
||||
m: 456 }
|
||||
|
||||
installation
|
||||
============
|
||||
|
||||
With [npm](http://github.com/isaacs/npm), just do:
|
||||
npm install optimist
|
||||
|
||||
or clone this project on github:
|
||||
|
||||
git clone http://github.com/substack/node-optimist.git
|
||||
|
||||
To run the tests with [expresso](http://github.com/visionmedia/expresso),
|
||||
just do:
|
||||
|
||||
expresso
|
||||
|
||||
inspired By
|
||||
===========
|
||||
|
||||
This module is loosely inspired by Perl's
|
||||
[Getopt::Casual](http://search.cpan.org/~photo/Getopt-Casual-0.13.1/Casual.pm).
|
||||
71
node_modules/swig/node_modules/optimist/test/_.js
generated
vendored
Normal file
71
node_modules/swig/node_modules/optimist/test/_.js
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
var spawn = require('child_process').spawn;
|
||||
var test = require('tap').test;
|
||||
|
||||
test('dotSlashEmpty', testCmd('./bin.js', []));
|
||||
|
||||
test('dotSlashArgs', testCmd('./bin.js', [ 'a', 'b', 'c' ]));
|
||||
|
||||
test('nodeEmpty', testCmd('node bin.js', []));
|
||||
|
||||
test('nodeArgs', testCmd('node bin.js', [ 'x', 'y', 'z' ]));
|
||||
|
||||
test('whichNodeEmpty', function (t) {
|
||||
var which = spawn('which', ['node']);
|
||||
|
||||
which.stdout.on('data', function (buf) {
|
||||
t.test(
|
||||
testCmd(buf.toString().trim() + ' bin.js', [])
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
which.stderr.on('data', function (err) {
|
||||
assert.error(err);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('whichNodeArgs', function (t) {
|
||||
var which = spawn('which', ['node']);
|
||||
|
||||
which.stdout.on('data', function (buf) {
|
||||
t.test(
|
||||
testCmd(buf.toString().trim() + ' bin.js', [ 'q', 'r' ])
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
which.stderr.on('data', function (err) {
|
||||
t.error(err);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
function testCmd (cmd, args) {
|
||||
|
||||
return function (t) {
|
||||
var to = setTimeout(function () {
|
||||
assert.fail('Never got stdout data.')
|
||||
}, 5000);
|
||||
|
||||
var oldDir = process.cwd();
|
||||
process.chdir(__dirname + '/_');
|
||||
|
||||
var cmds = cmd.split(' ');
|
||||
|
||||
var bin = spawn(cmds[0], cmds.slice(1).concat(args.map(String)));
|
||||
process.chdir(oldDir);
|
||||
|
||||
bin.stderr.on('data', function (err) {
|
||||
t.error(err);
|
||||
t.end();
|
||||
});
|
||||
|
||||
bin.stdout.on('data', function (buf) {
|
||||
clearTimeout(to);
|
||||
var _ = JSON.parse(buf.toString());
|
||||
t.same(_.map(String), args.map(String));
|
||||
t.end();
|
||||
});
|
||||
};
|
||||
}
|
||||
2
node_modules/swig/node_modules/optimist/test/_/argv.js
generated
vendored
Normal file
2
node_modules/swig/node_modules/optimist/test/_/argv.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
#!/usr/bin/env node
|
||||
console.log(JSON.stringify(process.argv));
|
||||
3
node_modules/swig/node_modules/optimist/test/_/bin.js
generated
vendored
Executable file
3
node_modules/swig/node_modules/optimist/test/_/bin.js
generated
vendored
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env node
|
||||
var argv = require('../../index').argv
|
||||
console.log(JSON.stringify(argv._));
|
||||
31
node_modules/swig/node_modules/optimist/test/dash.js
generated
vendored
Normal file
31
node_modules/swig/node_modules/optimist/test/dash.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
var optimist = require('../index');
|
||||
var test = require('tap').test;
|
||||
|
||||
test('-', function (t) {
|
||||
t.plan(5);
|
||||
t.deepEqual(
|
||||
fix(optimist.parse([ '-n', '-' ])),
|
||||
{ n: '-', _: [] }
|
||||
);
|
||||
t.deepEqual(
|
||||
fix(optimist.parse([ '-' ])),
|
||||
{ _: [ '-' ] }
|
||||
);
|
||||
t.deepEqual(
|
||||
fix(optimist.parse([ '-f-' ])),
|
||||
{ f: '-', _: [] }
|
||||
);
|
||||
t.deepEqual(
|
||||
fix(optimist([ '-b', '-' ]).boolean('b').argv),
|
||||
{ b: true, _: [ '-' ] }
|
||||
);
|
||||
t.deepEqual(
|
||||
fix(optimist([ '-s', '-' ]).string('s').argv),
|
||||
{ s: '-', _: [] }
|
||||
);
|
||||
});
|
||||
|
||||
function fix (obj) {
|
||||
delete obj.$0;
|
||||
return obj;
|
||||
}
|
||||
446
node_modules/swig/node_modules/optimist/test/parse.js
generated
vendored
Normal file
446
node_modules/swig/node_modules/optimist/test/parse.js
generated
vendored
Normal file
@@ -0,0 +1,446 @@
|
||||
var optimist = require('../index');
|
||||
var path = require('path');
|
||||
var test = require('tap').test;
|
||||
|
||||
var $0 = 'node ./' + path.relative(process.cwd(), __filename);
|
||||
|
||||
test('short boolean', function (t) {
|
||||
var parse = optimist.parse([ '-b' ]);
|
||||
t.same(parse, { b : true, _ : [], $0 : $0 });
|
||||
t.same(typeof parse.b, 'boolean');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('long boolean', function (t) {
|
||||
t.same(
|
||||
optimist.parse([ '--bool' ]),
|
||||
{ bool : true, _ : [], $0 : $0 }
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('bare', function (t) {
|
||||
t.same(
|
||||
optimist.parse([ 'foo', 'bar', 'baz' ]),
|
||||
{ _ : [ 'foo', 'bar', 'baz' ], $0 : $0 }
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('short group', function (t) {
|
||||
t.same(
|
||||
optimist.parse([ '-cats' ]),
|
||||
{ c : true, a : true, t : true, s : true, _ : [], $0 : $0 }
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('short group next', function (t) {
|
||||
t.same(
|
||||
optimist.parse([ '-cats', 'meow' ]),
|
||||
{ c : true, a : true, t : true, s : 'meow', _ : [], $0 : $0 }
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('short capture', function (t) {
|
||||
t.same(
|
||||
optimist.parse([ '-h', 'localhost' ]),
|
||||
{ h : 'localhost', _ : [], $0 : $0 }
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('short captures', function (t) {
|
||||
t.same(
|
||||
optimist.parse([ '-h', 'localhost', '-p', '555' ]),
|
||||
{ h : 'localhost', p : 555, _ : [], $0 : $0 }
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('long capture sp', function (t) {
|
||||
t.same(
|
||||
optimist.parse([ '--pow', 'xixxle' ]),
|
||||
{ pow : 'xixxle', _ : [], $0 : $0 }
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('long capture eq', function (t) {
|
||||
t.same(
|
||||
optimist.parse([ '--pow=xixxle' ]),
|
||||
{ pow : 'xixxle', _ : [], $0 : $0 }
|
||||
);
|
||||
t.end()
|
||||
});
|
||||
|
||||
test('long captures sp', function (t) {
|
||||
t.same(
|
||||
optimist.parse([ '--host', 'localhost', '--port', '555' ]),
|
||||
{ host : 'localhost', port : 555, _ : [], $0 : $0 }
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('long captures eq', function (t) {
|
||||
t.same(
|
||||
optimist.parse([ '--host=localhost', '--port=555' ]),
|
||||
{ host : 'localhost', port : 555, _ : [], $0 : $0 }
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('mixed short bool and capture', function (t) {
|
||||
t.same(
|
||||
optimist.parse([ '-h', 'localhost', '-fp', '555', 'script.js' ]),
|
||||
{
|
||||
f : true, p : 555, h : 'localhost',
|
||||
_ : [ 'script.js' ], $0 : $0,
|
||||
}
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('short and long', function (t) {
|
||||
t.same(
|
||||
optimist.parse([ '-h', 'localhost', '-fp', '555', 'script.js' ]),
|
||||
{
|
||||
f : true, p : 555, h : 'localhost',
|
||||
_ : [ 'script.js' ], $0 : $0,
|
||||
}
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('no', function (t) {
|
||||
t.same(
|
||||
optimist.parse([ '--no-moo' ]),
|
||||
{ moo : false, _ : [], $0 : $0 }
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('multi', function (t) {
|
||||
t.same(
|
||||
optimist.parse([ '-v', 'a', '-v', 'b', '-v', 'c' ]),
|
||||
{ v : ['a','b','c'], _ : [], $0 : $0 }
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('comprehensive', function (t) {
|
||||
t.same(
|
||||
optimist.parse([
|
||||
'--name=meowmers', 'bare', '-cats', 'woo',
|
||||
'-h', 'awesome', '--multi=quux',
|
||||
'--key', 'value',
|
||||
'-b', '--bool', '--no-meep', '--multi=baz',
|
||||
'--', '--not-a-flag', 'eek'
|
||||
]),
|
||||
{
|
||||
c : true,
|
||||
a : true,
|
||||
t : true,
|
||||
s : 'woo',
|
||||
h : 'awesome',
|
||||
b : true,
|
||||
bool : true,
|
||||
key : 'value',
|
||||
multi : [ 'quux', 'baz' ],
|
||||
meep : false,
|
||||
name : 'meowmers',
|
||||
_ : [ 'bare', '--not-a-flag', 'eek' ],
|
||||
$0 : $0
|
||||
}
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('nums', function (t) {
|
||||
var argv = optimist.parse([
|
||||
'-x', '1234',
|
||||
'-y', '5.67',
|
||||
'-z', '1e7',
|
||||
'-w', '10f',
|
||||
'--hex', '0xdeadbeef',
|
||||
'789',
|
||||
]);
|
||||
t.same(argv, {
|
||||
x : 1234,
|
||||
y : 5.67,
|
||||
z : 1e7,
|
||||
w : '10f',
|
||||
hex : 0xdeadbeef,
|
||||
_ : [ 789 ],
|
||||
$0 : $0
|
||||
});
|
||||
t.same(typeof argv.x, 'number');
|
||||
t.same(typeof argv.y, 'number');
|
||||
t.same(typeof argv.z, 'number');
|
||||
t.same(typeof argv.w, 'string');
|
||||
t.same(typeof argv.hex, 'number');
|
||||
t.same(typeof argv._[0], 'number');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('flag boolean', function (t) {
|
||||
var parse = optimist([ '-t', 'moo' ]).boolean(['t']).argv;
|
||||
t.same(parse, { t : true, _ : [ 'moo' ], $0 : $0 });
|
||||
t.same(typeof parse.t, 'boolean');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('flag boolean value', function (t) {
|
||||
var parse = optimist(['--verbose', 'false', 'moo', '-t', 'true'])
|
||||
.boolean(['t', 'verbose']).default('verbose', true).argv;
|
||||
|
||||
t.same(parse, {
|
||||
verbose: false,
|
||||
t: true,
|
||||
_: ['moo'],
|
||||
$0 : $0
|
||||
});
|
||||
|
||||
t.same(typeof parse.verbose, 'boolean');
|
||||
t.same(typeof parse.t, 'boolean');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('flag boolean default false', function (t) {
|
||||
var parse = optimist(['moo'])
|
||||
.boolean(['t', 'verbose'])
|
||||
.default('verbose', false)
|
||||
.default('t', false).argv;
|
||||
|
||||
t.same(parse, {
|
||||
verbose: false,
|
||||
t: false,
|
||||
_: ['moo'],
|
||||
$0 : $0
|
||||
});
|
||||
|
||||
t.same(typeof parse.verbose, 'boolean');
|
||||
t.same(typeof parse.t, 'boolean');
|
||||
t.end();
|
||||
|
||||
});
|
||||
|
||||
test('boolean groups', function (t) {
|
||||
var parse = optimist([ '-x', '-z', 'one', 'two', 'three' ])
|
||||
.boolean(['x','y','z']).argv;
|
||||
|
||||
t.same(parse, {
|
||||
x : true,
|
||||
y : false,
|
||||
z : true,
|
||||
_ : [ 'one', 'two', 'three' ],
|
||||
$0 : $0
|
||||
});
|
||||
|
||||
t.same(typeof parse.x, 'boolean');
|
||||
t.same(typeof parse.y, 'boolean');
|
||||
t.same(typeof parse.z, 'boolean');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('newlines in params' , function (t) {
|
||||
var args = optimist.parse([ '-s', "X\nX" ])
|
||||
t.same(args, { _ : [], s : "X\nX", $0 : $0 });
|
||||
|
||||
// reproduce in bash:
|
||||
// VALUE="new
|
||||
// line"
|
||||
// node program.js --s="$VALUE"
|
||||
args = optimist.parse([ "--s=X\nX" ])
|
||||
t.same(args, { _ : [], s : "X\nX", $0 : $0 });
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('strings' , function (t) {
|
||||
var s = optimist([ '-s', '0001234' ]).string('s').argv.s;
|
||||
t.same(s, '0001234');
|
||||
t.same(typeof s, 'string');
|
||||
|
||||
var x = optimist([ '-x', '56' ]).string('x').argv.x;
|
||||
t.same(x, '56');
|
||||
t.same(typeof x, 'string');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('stringArgs', function (t) {
|
||||
var s = optimist([ ' ', ' ' ]).string('_').argv._;
|
||||
t.same(s.length, 2);
|
||||
t.same(typeof s[0], 'string');
|
||||
t.same(s[0], ' ');
|
||||
t.same(typeof s[1], 'string');
|
||||
t.same(s[1], ' ');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('slashBreak', function (t) {
|
||||
t.same(
|
||||
optimist.parse([ '-I/foo/bar/baz' ]),
|
||||
{ I : '/foo/bar/baz', _ : [], $0 : $0 }
|
||||
);
|
||||
t.same(
|
||||
optimist.parse([ '-xyz/foo/bar/baz' ]),
|
||||
{ x : true, y : true, z : '/foo/bar/baz', _ : [], $0 : $0 }
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('alias', function (t) {
|
||||
var argv = optimist([ '-f', '11', '--zoom', '55' ])
|
||||
.alias('z', 'zoom')
|
||||
.argv
|
||||
;
|
||||
t.equal(argv.zoom, 55);
|
||||
t.equal(argv.z, argv.zoom);
|
||||
t.equal(argv.f, 11);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('multiAlias', function (t) {
|
||||
var argv = optimist([ '-f', '11', '--zoom', '55' ])
|
||||
.alias('z', [ 'zm', 'zoom' ])
|
||||
.argv
|
||||
;
|
||||
t.equal(argv.zoom, 55);
|
||||
t.equal(argv.z, argv.zoom);
|
||||
t.equal(argv.z, argv.zm);
|
||||
t.equal(argv.f, 11);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('boolean default true', function (t) {
|
||||
var argv = optimist.options({
|
||||
sometrue: {
|
||||
boolean: true,
|
||||
default: true
|
||||
}
|
||||
}).argv;
|
||||
|
||||
t.equal(argv.sometrue, true);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('boolean default false', function (t) {
|
||||
var argv = optimist.options({
|
||||
somefalse: {
|
||||
boolean: true,
|
||||
default: false
|
||||
}
|
||||
}).argv;
|
||||
|
||||
t.equal(argv.somefalse, false);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('nested dotted objects', function (t) {
|
||||
var argv = optimist([
|
||||
'--foo.bar', '3', '--foo.baz', '4',
|
||||
'--foo.quux.quibble', '5', '--foo.quux.o_O',
|
||||
'--beep.boop'
|
||||
]).argv;
|
||||
|
||||
t.same(argv.foo, {
|
||||
bar : 3,
|
||||
baz : 4,
|
||||
quux : {
|
||||
quibble : 5,
|
||||
o_O : true
|
||||
},
|
||||
});
|
||||
t.same(argv.beep, { boop : true });
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('boolean and alias with chainable api', function (t) {
|
||||
var aliased = [ '-h', 'derp' ];
|
||||
var regular = [ '--herp', 'derp' ];
|
||||
var opts = {
|
||||
herp: { alias: 'h', boolean: true }
|
||||
};
|
||||
var aliasedArgv = optimist(aliased)
|
||||
.boolean('herp')
|
||||
.alias('h', 'herp')
|
||||
.argv;
|
||||
var propertyArgv = optimist(regular)
|
||||
.boolean('herp')
|
||||
.alias('h', 'herp')
|
||||
.argv;
|
||||
var expected = {
|
||||
herp: true,
|
||||
h: true,
|
||||
'_': [ 'derp' ],
|
||||
'$0': $0,
|
||||
};
|
||||
|
||||
t.same(aliasedArgv, expected);
|
||||
t.same(propertyArgv, expected);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('boolean and alias with options hash', function (t) {
|
||||
var aliased = [ '-h', 'derp' ];
|
||||
var regular = [ '--herp', 'derp' ];
|
||||
var opts = {
|
||||
herp: { alias: 'h', boolean: true }
|
||||
};
|
||||
var aliasedArgv = optimist(aliased)
|
||||
.options(opts)
|
||||
.argv;
|
||||
var propertyArgv = optimist(regular).options(opts).argv;
|
||||
var expected = {
|
||||
herp: true,
|
||||
h: true,
|
||||
'_': [ 'derp' ],
|
||||
'$0': $0,
|
||||
};
|
||||
|
||||
t.same(aliasedArgv, expected);
|
||||
t.same(propertyArgv, expected);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('boolean and alias using explicit true', function (t) {
|
||||
var aliased = [ '-h', 'true' ];
|
||||
var regular = [ '--herp', 'true' ];
|
||||
var opts = {
|
||||
herp: { alias: 'h', boolean: true }
|
||||
};
|
||||
var aliasedArgv = optimist(aliased)
|
||||
.boolean('h')
|
||||
.alias('h', 'herp')
|
||||
.argv;
|
||||
var propertyArgv = optimist(regular)
|
||||
.boolean('h')
|
||||
.alias('h', 'herp')
|
||||
.argv;
|
||||
var expected = {
|
||||
herp: true,
|
||||
h: true,
|
||||
'_': [ ],
|
||||
'$0': $0,
|
||||
};
|
||||
|
||||
t.same(aliasedArgv, expected);
|
||||
t.same(propertyArgv, expected);
|
||||
t.end();
|
||||
});
|
||||
|
||||
// regression, see https://github.com/substack/node-optimist/issues/71
|
||||
test('boolean and --x=true', function(t) {
|
||||
var parsed = optimist(['--boool', '--other=true']).boolean('boool').argv;
|
||||
|
||||
t.same(parsed.boool, true);
|
||||
t.same(parsed.other, 'true');
|
||||
|
||||
parsed = optimist(['--boool', '--other=false']).boolean('boool').argv;
|
||||
|
||||
t.same(parsed.boool, true);
|
||||
t.same(parsed.other, 'false');
|
||||
t.end();
|
||||
});
|
||||
14
node_modules/swig/node_modules/optimist/test/parse_modified.js
generated
vendored
Normal file
14
node_modules/swig/node_modules/optimist/test/parse_modified.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
var optimist = require('../');
|
||||
var test = require('tap').test;
|
||||
|
||||
test('parse with modifier functions' , function (t) {
|
||||
t.plan(1);
|
||||
|
||||
var argv = optimist().boolean('b').parse([ '-b', '123' ]);
|
||||
t.deepEqual(fix(argv), { b: true, _: ['123'] });
|
||||
});
|
||||
|
||||
function fix (obj) {
|
||||
delete obj.$0;
|
||||
return obj;
|
||||
}
|
||||
16
node_modules/swig/node_modules/optimist/test/short.js
generated
vendored
Normal file
16
node_modules/swig/node_modules/optimist/test/short.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
var optimist = require('../index');
|
||||
var test = require('tap').test;
|
||||
|
||||
test('-n123', function (t) {
|
||||
t.plan(1);
|
||||
var parse = optimist.parse([ '-n123' ]);
|
||||
t.equal(parse.n, 123);
|
||||
});
|
||||
|
||||
test('-123', function (t) {
|
||||
t.plan(3);
|
||||
var parse = optimist.parse([ '-123', '456' ]);
|
||||
t.equal(parse['1'], true);
|
||||
t.equal(parse['2'], true);
|
||||
t.equal(parse['3'], 456);
|
||||
});
|
||||
292
node_modules/swig/node_modules/optimist/test/usage.js
generated
vendored
Normal file
292
node_modules/swig/node_modules/optimist/test/usage.js
generated
vendored
Normal file
@@ -0,0 +1,292 @@
|
||||
var Hash = require('hashish');
|
||||
var optimist = require('../index');
|
||||
var test = require('tap').test;
|
||||
|
||||
test('usageFail', function (t) {
|
||||
var r = checkUsage(function () {
|
||||
return optimist('-x 10 -z 20'.split(' '))
|
||||
.usage('Usage: $0 -x NUM -y NUM')
|
||||
.demand(['x','y'])
|
||||
.argv;
|
||||
});
|
||||
t.same(
|
||||
r.result,
|
||||
{ x : 10, z : 20, _ : [], $0 : './usage' }
|
||||
);
|
||||
|
||||
t.same(
|
||||
r.errors.join('\n').split(/\n+/),
|
||||
[
|
||||
'Usage: ./usage -x NUM -y NUM',
|
||||
'Options:',
|
||||
' -x [required]',
|
||||
' -y [required]',
|
||||
'Missing required arguments: y',
|
||||
]
|
||||
);
|
||||
t.same(r.logs, []);
|
||||
t.ok(r.exit);
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
||||
test('usagePass', function (t) {
|
||||
var r = checkUsage(function () {
|
||||
return optimist('-x 10 -y 20'.split(' '))
|
||||
.usage('Usage: $0 -x NUM -y NUM')
|
||||
.demand(['x','y'])
|
||||
.argv;
|
||||
});
|
||||
t.same(r, {
|
||||
result : { x : 10, y : 20, _ : [], $0 : './usage' },
|
||||
errors : [],
|
||||
logs : [],
|
||||
exit : false,
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('checkPass', function (t) {
|
||||
var r = checkUsage(function () {
|
||||
return optimist('-x 10 -y 20'.split(' '))
|
||||
.usage('Usage: $0 -x NUM -y NUM')
|
||||
.check(function (argv) {
|
||||
if (!('x' in argv)) throw 'You forgot about -x';
|
||||
if (!('y' in argv)) throw 'You forgot about -y';
|
||||
})
|
||||
.argv;
|
||||
});
|
||||
t.same(r, {
|
||||
result : { x : 10, y : 20, _ : [], $0 : './usage' },
|
||||
errors : [],
|
||||
logs : [],
|
||||
exit : false,
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('checkFail', function (t) {
|
||||
var r = checkUsage(function () {
|
||||
return optimist('-x 10 -z 20'.split(' '))
|
||||
.usage('Usage: $0 -x NUM -y NUM')
|
||||
.check(function (argv) {
|
||||
if (!('x' in argv)) throw 'You forgot about -x';
|
||||
if (!('y' in argv)) throw 'You forgot about -y';
|
||||
})
|
||||
.argv;
|
||||
});
|
||||
|
||||
t.same(
|
||||
r.result,
|
||||
{ x : 10, z : 20, _ : [], $0 : './usage' }
|
||||
);
|
||||
|
||||
t.same(
|
||||
r.errors.join('\n').split(/\n+/),
|
||||
[
|
||||
'Usage: ./usage -x NUM -y NUM',
|
||||
'You forgot about -y'
|
||||
]
|
||||
);
|
||||
|
||||
t.same(r.logs, []);
|
||||
t.ok(r.exit);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('checkCondPass', function (t) {
|
||||
function checker (argv) {
|
||||
return 'x' in argv && 'y' in argv;
|
||||
}
|
||||
|
||||
var r = checkUsage(function () {
|
||||
return optimist('-x 10 -y 20'.split(' '))
|
||||
.usage('Usage: $0 -x NUM -y NUM')
|
||||
.check(checker)
|
||||
.argv;
|
||||
});
|
||||
t.same(r, {
|
||||
result : { x : 10, y : 20, _ : [], $0 : './usage' },
|
||||
errors : [],
|
||||
logs : [],
|
||||
exit : false,
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('checkCondFail', function (t) {
|
||||
function checker (argv) {
|
||||
return 'x' in argv && 'y' in argv;
|
||||
}
|
||||
|
||||
var r = checkUsage(function () {
|
||||
return optimist('-x 10 -z 20'.split(' '))
|
||||
.usage('Usage: $0 -x NUM -y NUM')
|
||||
.check(checker)
|
||||
.argv;
|
||||
});
|
||||
|
||||
t.same(
|
||||
r.result,
|
||||
{ x : 10, z : 20, _ : [], $0 : './usage' }
|
||||
);
|
||||
|
||||
t.same(
|
||||
r.errors.join('\n').split(/\n+/).join('\n'),
|
||||
'Usage: ./usage -x NUM -y NUM\n'
|
||||
+ 'Argument check failed: ' + checker.toString()
|
||||
);
|
||||
|
||||
t.same(r.logs, []);
|
||||
t.ok(r.exit);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('countPass', function (t) {
|
||||
var r = checkUsage(function () {
|
||||
return optimist('1 2 3 --moo'.split(' '))
|
||||
.usage('Usage: $0 [x] [y] [z] {OPTIONS}')
|
||||
.demand(3)
|
||||
.argv;
|
||||
});
|
||||
t.same(r, {
|
||||
result : { _ : [ '1', '2', '3' ], moo : true, $0 : './usage' },
|
||||
errors : [],
|
||||
logs : [],
|
||||
exit : false,
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('countFail', function (t) {
|
||||
var r = checkUsage(function () {
|
||||
return optimist('1 2 --moo'.split(' '))
|
||||
.usage('Usage: $0 [x] [y] [z] {OPTIONS}')
|
||||
.demand(3)
|
||||
.argv;
|
||||
});
|
||||
t.same(
|
||||
r.result,
|
||||
{ _ : [ '1', '2' ], moo : true, $0 : './usage' }
|
||||
);
|
||||
|
||||
t.same(
|
||||
r.errors.join('\n').split(/\n+/),
|
||||
[
|
||||
'Usage: ./usage [x] [y] [z] {OPTIONS}',
|
||||
'Not enough non-option arguments: got 2, need at least 3',
|
||||
]
|
||||
);
|
||||
|
||||
t.same(r.logs, []);
|
||||
t.ok(r.exit);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('defaultSingles', function (t) {
|
||||
var r = checkUsage(function () {
|
||||
return optimist('--foo 50 --baz 70 --powsy'.split(' '))
|
||||
.default('foo', 5)
|
||||
.default('bar', 6)
|
||||
.default('baz', 7)
|
||||
.argv
|
||||
;
|
||||
});
|
||||
t.same(r.result, {
|
||||
foo : '50',
|
||||
bar : 6,
|
||||
baz : '70',
|
||||
powsy : true,
|
||||
_ : [],
|
||||
$0 : './usage',
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('defaultAliases', function (t) {
|
||||
var r = checkUsage(function () {
|
||||
return optimist('')
|
||||
.alias('f', 'foo')
|
||||
.default('f', 5)
|
||||
.argv
|
||||
;
|
||||
});
|
||||
t.same(r.result, {
|
||||
f : '5',
|
||||
foo : '5',
|
||||
_ : [],
|
||||
$0 : './usage',
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('defaultHash', function (t) {
|
||||
var r = checkUsage(function () {
|
||||
return optimist('--foo 50 --baz 70'.split(' '))
|
||||
.default({ foo : 10, bar : 20, quux : 30 })
|
||||
.argv
|
||||
;
|
||||
});
|
||||
t.same(r.result, {
|
||||
_ : [],
|
||||
$0 : './usage',
|
||||
foo : 50,
|
||||
baz : 70,
|
||||
bar : 20,
|
||||
quux : 30,
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('rebase', function (t) {
|
||||
t.equal(
|
||||
optimist.rebase('/home/substack', '/home/substack/foo/bar/baz'),
|
||||
'./foo/bar/baz'
|
||||
);
|
||||
t.equal(
|
||||
optimist.rebase('/home/substack/foo/bar/baz', '/home/substack'),
|
||||
'../../..'
|
||||
);
|
||||
t.equal(
|
||||
optimist.rebase('/home/substack/foo', '/home/substack/pow/zoom.txt'),
|
||||
'../pow/zoom.txt'
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
function checkUsage (f) {
|
||||
|
||||
var exit = false;
|
||||
|
||||
process._exit = process.exit;
|
||||
process._env = process.env;
|
||||
process._argv = process.argv;
|
||||
|
||||
process.exit = function (t) { exit = true };
|
||||
process.env = Hash.merge(process.env, { _ : 'node' });
|
||||
process.argv = [ './usage' ];
|
||||
|
||||
var errors = [];
|
||||
var logs = [];
|
||||
|
||||
console._error = console.error;
|
||||
console.error = function (msg) { errors.push(msg) };
|
||||
console._log = console.log;
|
||||
console.log = function (msg) { logs.push(msg) };
|
||||
|
||||
var result = f();
|
||||
|
||||
process.exit = process._exit;
|
||||
process.env = process._env;
|
||||
process.argv = process._argv;
|
||||
|
||||
console.error = console._error;
|
||||
console.log = console._log;
|
||||
|
||||
return {
|
||||
errors : errors,
|
||||
logs : logs,
|
||||
exit : exit,
|
||||
result : result,
|
||||
};
|
||||
};
|
||||
8
node_modules/swig/node_modules/optimist/test/whitespace.js
generated
vendored
Normal file
8
node_modules/swig/node_modules/optimist/test/whitespace.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
var optimist = require('../');
|
||||
var test = require('tap').test;
|
||||
|
||||
test('whitespace should be whitespace' , function (t) {
|
||||
t.plan(1);
|
||||
var x = optimist.parse([ '-x', '\t' ]).x;
|
||||
t.equal(x, '\t');
|
||||
});
|
||||
2
node_modules/swig/node_modules/source-map/.npmignore
generated
vendored
Normal file
2
node_modules/swig/node_modules/source-map/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
dist/*
|
||||
node_modules/*
|
||||
1
node_modules/swig/node_modules/source-map/.tern-port
generated
vendored
Normal file
1
node_modules/swig/node_modules/source-map/.tern-port
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
55494
|
||||
4
node_modules/swig/node_modules/source-map/.travis.yml
generated
vendored
Normal file
4
node_modules/swig/node_modules/source-map/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- 0.8
|
||||
- "0.10"
|
||||
137
node_modules/swig/node_modules/source-map/CHANGELOG.md
generated
vendored
Normal file
137
node_modules/swig/node_modules/source-map/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,137 @@
|
||||
# Change Log
|
||||
|
||||
## 0.1.34
|
||||
|
||||
* Make `SourceNode` work with windows style ("\r\n") newlines. Issue #103.
|
||||
|
||||
* Fix bug involving source contents and the
|
||||
`SourceMapGenerator.prototype.applySourceMap`. Issue #100.
|
||||
|
||||
## 0.1.33
|
||||
|
||||
* Fix some edge cases surrounding path joining and URL resolution.
|
||||
|
||||
* Add a third parameter for relative path to
|
||||
`SourceMapGenerator.prototype.applySourceMap`.
|
||||
|
||||
* Fix issues with mappings and EOLs.
|
||||
|
||||
## 0.1.32
|
||||
|
||||
* Fixed a bug where SourceMapConsumer couldn't handle negative relative columns
|
||||
(issue 92).
|
||||
|
||||
* Fixed test runner to actually report number of failed tests as its process
|
||||
exit code.
|
||||
|
||||
* Fixed a typo when reporting bad mappings (issue 87).
|
||||
|
||||
## 0.1.31
|
||||
|
||||
* Delay parsing the mappings in SourceMapConsumer until queried for a source
|
||||
location.
|
||||
|
||||
* Support Sass source maps (which at the time of writing deviate from the spec
|
||||
in small ways) in SourceMapConsumer.
|
||||
|
||||
## 0.1.30
|
||||
|
||||
* Do not join source root with a source, when the source is a data URI.
|
||||
|
||||
* Extend the test runner to allow running single specific test files at a time.
|
||||
|
||||
* Performance improvements in `SourceNode.prototype.walk` and
|
||||
`SourceMapConsumer.prototype.eachMapping`.
|
||||
|
||||
* Source map browser builds will now work inside Workers.
|
||||
|
||||
* Better error messages when attempting to add an invalid mapping to a
|
||||
`SourceMapGenerator`.
|
||||
|
||||
## 0.1.29
|
||||
|
||||
* Allow duplicate entries in the `names` and `sources` arrays of source maps
|
||||
(usually from TypeScript) we are parsing. Fixes github issue 72.
|
||||
|
||||
## 0.1.28
|
||||
|
||||
* Skip duplicate mappings when creating source maps from SourceNode; github
|
||||
issue 75.
|
||||
|
||||
## 0.1.27
|
||||
|
||||
* Don't throw an error when the `file` property is missing in SourceMapConsumer,
|
||||
we don't use it anyway.
|
||||
|
||||
## 0.1.26
|
||||
|
||||
* Fix SourceNode.fromStringWithSourceMap for empty maps. Fixes github issue 70.
|
||||
|
||||
## 0.1.25
|
||||
|
||||
* Make compatible with browserify
|
||||
|
||||
## 0.1.24
|
||||
|
||||
* Fix issue with absolute paths and `file://` URIs. See
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=885597
|
||||
|
||||
## 0.1.23
|
||||
|
||||
* Fix issue with absolute paths and sourcesContent, github issue 64.
|
||||
|
||||
## 0.1.22
|
||||
|
||||
* Ignore duplicate mappings in SourceMapGenerator. Fixes github issue 21.
|
||||
|
||||
## 0.1.21
|
||||
|
||||
* Fixed handling of sources that start with a slash so that they are relative to
|
||||
the source root's host.
|
||||
|
||||
## 0.1.20
|
||||
|
||||
* Fixed github issue #43: absolute URLs aren't joined with the source root
|
||||
anymore.
|
||||
|
||||
## 0.1.19
|
||||
|
||||
* Using Travis CI to run tests.
|
||||
|
||||
## 0.1.18
|
||||
|
||||
* Fixed a bug in the handling of sourceRoot.
|
||||
|
||||
## 0.1.17
|
||||
|
||||
* Added SourceNode.fromStringWithSourceMap.
|
||||
|
||||
## 0.1.16
|
||||
|
||||
* Added missing documentation.
|
||||
|
||||
* Fixed the generating of empty mappings in SourceNode.
|
||||
|
||||
## 0.1.15
|
||||
|
||||
* Added SourceMapGenerator.applySourceMap.
|
||||
|
||||
## 0.1.14
|
||||
|
||||
* The sourceRoot is now handled consistently.
|
||||
|
||||
## 0.1.13
|
||||
|
||||
* Added SourceMapGenerator.fromSourceMap.
|
||||
|
||||
## 0.1.12
|
||||
|
||||
* SourceNode now generates empty mappings too.
|
||||
|
||||
## 0.1.11
|
||||
|
||||
* Added name support to SourceNode.
|
||||
|
||||
## 0.1.10
|
||||
|
||||
* Added sourcesContent support to the customer and generator.
|
||||
28
node_modules/swig/node_modules/source-map/LICENSE
generated
vendored
Normal file
28
node_modules/swig/node_modules/source-map/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
Copyright (c) 2009-2011, Mozilla Foundation and contributors
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the names of the Mozilla Foundation nor the names of project
|
||||
contributors may be used to endorse or promote products derived from this
|
||||
software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
166
node_modules/swig/node_modules/source-map/Makefile.dryice.js
generated
vendored
Normal file
166
node_modules/swig/node_modules/source-map/Makefile.dryice.js
generated
vendored
Normal file
@@ -0,0 +1,166 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var copy = require('dryice').copy;
|
||||
|
||||
function removeAmdefine(src) {
|
||||
src = String(src).replace(
|
||||
/if\s*\(typeof\s*define\s*!==\s*'function'\)\s*{\s*var\s*define\s*=\s*require\('amdefine'\)\(module,\s*require\);\s*}\s*/g,
|
||||
'');
|
||||
src = src.replace(
|
||||
/\b(define\(.*)('amdefine',?)/gm,
|
||||
'$1');
|
||||
return src;
|
||||
}
|
||||
removeAmdefine.onRead = true;
|
||||
|
||||
function makeNonRelative(src) {
|
||||
return src
|
||||
.replace(/require\('.\//g, 'require(\'source-map/')
|
||||
.replace(/\.\.\/\.\.\/lib\//g, '');
|
||||
}
|
||||
makeNonRelative.onRead = true;
|
||||
|
||||
function buildBrowser() {
|
||||
console.log('\nCreating dist/source-map.js');
|
||||
|
||||
var project = copy.createCommonJsProject({
|
||||
roots: [ path.join(__dirname, 'lib') ]
|
||||
});
|
||||
|
||||
copy({
|
||||
source: [
|
||||
'build/mini-require.js',
|
||||
{
|
||||
project: project,
|
||||
require: [ 'source-map/source-map-generator',
|
||||
'source-map/source-map-consumer',
|
||||
'source-map/source-node']
|
||||
},
|
||||
'build/suffix-browser.js'
|
||||
],
|
||||
filter: [
|
||||
copy.filter.moduleDefines,
|
||||
removeAmdefine
|
||||
],
|
||||
dest: 'dist/source-map.js'
|
||||
});
|
||||
}
|
||||
|
||||
function buildBrowserMin() {
|
||||
console.log('\nCreating dist/source-map.min.js');
|
||||
|
||||
copy({
|
||||
source: 'dist/source-map.js',
|
||||
filter: copy.filter.uglifyjs,
|
||||
dest: 'dist/source-map.min.js'
|
||||
});
|
||||
}
|
||||
|
||||
function buildFirefox() {
|
||||
console.log('\nCreating dist/SourceMap.jsm');
|
||||
|
||||
var project = copy.createCommonJsProject({
|
||||
roots: [ path.join(__dirname, 'lib') ]
|
||||
});
|
||||
|
||||
copy({
|
||||
source: [
|
||||
'build/prefix-source-map.jsm',
|
||||
{
|
||||
project: project,
|
||||
require: [ 'source-map/source-map-consumer',
|
||||
'source-map/source-map-generator',
|
||||
'source-map/source-node' ]
|
||||
},
|
||||
'build/suffix-source-map.jsm'
|
||||
],
|
||||
filter: [
|
||||
copy.filter.moduleDefines,
|
||||
removeAmdefine,
|
||||
makeNonRelative
|
||||
],
|
||||
dest: 'dist/SourceMap.jsm'
|
||||
});
|
||||
|
||||
// Create dist/test/Utils.jsm
|
||||
console.log('\nCreating dist/test/Utils.jsm');
|
||||
|
||||
project = copy.createCommonJsProject({
|
||||
roots: [ __dirname, path.join(__dirname, 'lib') ]
|
||||
});
|
||||
|
||||
copy({
|
||||
source: [
|
||||
'build/prefix-utils.jsm',
|
||||
'build/assert-shim.js',
|
||||
{
|
||||
project: project,
|
||||
require: [ 'test/source-map/util' ]
|
||||
},
|
||||
'build/suffix-utils.jsm'
|
||||
],
|
||||
filter: [
|
||||
copy.filter.moduleDefines,
|
||||
removeAmdefine,
|
||||
makeNonRelative
|
||||
],
|
||||
dest: 'dist/test/Utils.jsm'
|
||||
});
|
||||
|
||||
function isTestFile(f) {
|
||||
return /^test\-.*?\.js/.test(f);
|
||||
}
|
||||
|
||||
var testFiles = fs.readdirSync(path.join(__dirname, 'test', 'source-map')).filter(isTestFile);
|
||||
|
||||
testFiles.forEach(function (testFile) {
|
||||
console.log('\nCreating', path.join('dist', 'test', testFile.replace(/\-/g, '_')));
|
||||
|
||||
copy({
|
||||
source: [
|
||||
'build/test-prefix.js',
|
||||
path.join('test', 'source-map', testFile),
|
||||
'build/test-suffix.js'
|
||||
],
|
||||
filter: [
|
||||
removeAmdefine,
|
||||
makeNonRelative,
|
||||
function (input, source) {
|
||||
return input.replace('define(',
|
||||
'define("'
|
||||
+ path.join('test', 'source-map', testFile.replace(/\.js$/, ''))
|
||||
+ '", ["require", "exports", "module"], ');
|
||||
},
|
||||
function (input, source) {
|
||||
return input.replace('{THIS_MODULE}', function () {
|
||||
return "test/source-map/" + testFile.replace(/\.js$/, '');
|
||||
});
|
||||
}
|
||||
],
|
||||
dest: path.join('dist', 'test', testFile.replace(/\-/g, '_'))
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function ensureDir(name) {
|
||||
var dirExists = false;
|
||||
try {
|
||||
dirExists = fs.statSync(name).isDirectory();
|
||||
} catch (err) {}
|
||||
|
||||
if (!dirExists) {
|
||||
fs.mkdirSync(name, 0777);
|
||||
}
|
||||
}
|
||||
|
||||
ensureDir("dist");
|
||||
ensureDir("dist/test");
|
||||
buildFirefox();
|
||||
buildBrowser();
|
||||
buildBrowserMin();
|
||||
446
node_modules/swig/node_modules/source-map/README.md
generated
vendored
Normal file
446
node_modules/swig/node_modules/source-map/README.md
generated
vendored
Normal file
@@ -0,0 +1,446 @@
|
||||
# Source Map
|
||||
|
||||
This is a library to generate and consume the source map format
|
||||
[described here][format].
|
||||
|
||||
This library is written in the Asynchronous Module Definition format, and works
|
||||
in the following environments:
|
||||
|
||||
* Modern Browsers supporting ECMAScript 5 (either after the build, or with an
|
||||
AMD loader such as RequireJS)
|
||||
|
||||
* Inside Firefox (as a JSM file, after the build)
|
||||
|
||||
* With NodeJS versions 0.8.X and higher
|
||||
|
||||
## Node
|
||||
|
||||
$ npm install source-map
|
||||
|
||||
## Building from Source (for everywhere else)
|
||||
|
||||
Install Node and then run
|
||||
|
||||
$ git clone https://fitzgen@github.com/mozilla/source-map.git
|
||||
$ cd source-map
|
||||
$ npm link .
|
||||
|
||||
Next, run
|
||||
|
||||
$ node Makefile.dryice.js
|
||||
|
||||
This should spew a bunch of stuff to stdout, and create the following files:
|
||||
|
||||
* `dist/source-map.js` - The unminified browser version.
|
||||
|
||||
* `dist/source-map.min.js` - The minified browser version.
|
||||
|
||||
* `dist/SourceMap.jsm` - The JavaScript Module for inclusion in Firefox source.
|
||||
|
||||
## Examples
|
||||
|
||||
### Consuming a source map
|
||||
|
||||
var rawSourceMap = {
|
||||
version: 3,
|
||||
file: 'min.js',
|
||||
names: ['bar', 'baz', 'n'],
|
||||
sources: ['one.js', 'two.js'],
|
||||
sourceRoot: 'http://example.com/www/js/',
|
||||
mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA'
|
||||
};
|
||||
|
||||
var smc = new SourceMapConsumer(rawSourceMap);
|
||||
|
||||
console.log(smc.sources);
|
||||
// [ 'http://example.com/www/js/one.js',
|
||||
// 'http://example.com/www/js/two.js' ]
|
||||
|
||||
console.log(smc.originalPositionFor({
|
||||
line: 2,
|
||||
column: 28
|
||||
}));
|
||||
// { source: 'http://example.com/www/js/two.js',
|
||||
// line: 2,
|
||||
// column: 10,
|
||||
// name: 'n' }
|
||||
|
||||
console.log(smc.generatedPositionFor({
|
||||
source: 'http://example.com/www/js/two.js',
|
||||
line: 2,
|
||||
column: 10
|
||||
}));
|
||||
// { line: 2, column: 28 }
|
||||
|
||||
smc.eachMapping(function (m) {
|
||||
// ...
|
||||
});
|
||||
|
||||
### Generating a source map
|
||||
|
||||
In depth guide:
|
||||
[**Compiling to JavaScript, and Debugging with Source Maps**](https://hacks.mozilla.org/2013/05/compiling-to-javascript-and-debugging-with-source-maps/)
|
||||
|
||||
#### With SourceNode (high level API)
|
||||
|
||||
function compile(ast) {
|
||||
switch (ast.type) {
|
||||
case 'BinaryExpression':
|
||||
return new SourceNode(
|
||||
ast.location.line,
|
||||
ast.location.column,
|
||||
ast.location.source,
|
||||
[compile(ast.left), " + ", compile(ast.right)]
|
||||
);
|
||||
case 'Literal':
|
||||
return new SourceNode(
|
||||
ast.location.line,
|
||||
ast.location.column,
|
||||
ast.location.source,
|
||||
String(ast.value)
|
||||
);
|
||||
// ...
|
||||
default:
|
||||
throw new Error("Bad AST");
|
||||
}
|
||||
}
|
||||
|
||||
var ast = parse("40 + 2", "add.js");
|
||||
console.log(compile(ast).toStringWithSourceMap({
|
||||
file: 'add.js'
|
||||
}));
|
||||
// { code: '40 + 2',
|
||||
// map: [object SourceMapGenerator] }
|
||||
|
||||
#### With SourceMapGenerator (low level API)
|
||||
|
||||
var map = new SourceMapGenerator({
|
||||
file: "source-mapped.js"
|
||||
});
|
||||
|
||||
map.addMapping({
|
||||
generated: {
|
||||
line: 10,
|
||||
column: 35
|
||||
},
|
||||
source: "foo.js",
|
||||
original: {
|
||||
line: 33,
|
||||
column: 2
|
||||
},
|
||||
name: "christopher"
|
||||
});
|
||||
|
||||
console.log(map.toString());
|
||||
// '{"version":3,"file":"source-mapped.js","sources":["foo.js"],"names":["christopher"],"mappings":";;;;;;;;;mCAgCEA"}'
|
||||
|
||||
## API
|
||||
|
||||
Get a reference to the module:
|
||||
|
||||
// NodeJS
|
||||
var sourceMap = require('source-map');
|
||||
|
||||
// Browser builds
|
||||
var sourceMap = window.sourceMap;
|
||||
|
||||
// Inside Firefox
|
||||
let sourceMap = {};
|
||||
Components.utils.import('resource:///modules/devtools/SourceMap.jsm', sourceMap);
|
||||
|
||||
### SourceMapConsumer
|
||||
|
||||
A SourceMapConsumer instance represents a parsed source map which we can query
|
||||
for information about the original file positions by giving it a file position
|
||||
in the generated source.
|
||||
|
||||
#### new SourceMapConsumer(rawSourceMap)
|
||||
|
||||
The only parameter is the raw source map (either as a string which can be
|
||||
`JSON.parse`'d, or an object). According to the spec, source maps have the
|
||||
following attributes:
|
||||
|
||||
* `version`: Which version of the source map spec this map is following.
|
||||
|
||||
* `sources`: An array of URLs to the original source files.
|
||||
|
||||
* `names`: An array of identifiers which can be referrenced by individual
|
||||
mappings.
|
||||
|
||||
* `sourceRoot`: Optional. The URL root from which all sources are relative.
|
||||
|
||||
* `sourcesContent`: Optional. An array of contents of the original source files.
|
||||
|
||||
* `mappings`: A string of base64 VLQs which contain the actual mappings.
|
||||
|
||||
* `file`: Optional. The generated filename this source map is associated with.
|
||||
|
||||
#### SourceMapConsumer.prototype.originalPositionFor(generatedPosition)
|
||||
|
||||
Returns the original source, line, and column information for the generated
|
||||
source's line and column positions provided. The only argument is an object with
|
||||
the following properties:
|
||||
|
||||
* `line`: The line number in the generated source.
|
||||
|
||||
* `column`: The column number in the generated source.
|
||||
|
||||
and an object is returned with the following properties:
|
||||
|
||||
* `source`: The original source file, or null if this information is not
|
||||
available.
|
||||
|
||||
* `line`: The line number in the original source, or null if this information is
|
||||
not available.
|
||||
|
||||
* `column`: The column number in the original source, or null or null if this
|
||||
information is not available.
|
||||
|
||||
* `name`: The original identifier, or null if this information is not available.
|
||||
|
||||
#### SourceMapConsumer.prototype.generatedPositionFor(originalPosition)
|
||||
|
||||
Returns the generated line and column information for the original source,
|
||||
line, and column positions provided. The only argument is an object with
|
||||
the following properties:
|
||||
|
||||
* `source`: The filename of the original source.
|
||||
|
||||
* `line`: The line number in the original source.
|
||||
|
||||
* `column`: The column number in the original source.
|
||||
|
||||
and an object is returned with the following properties:
|
||||
|
||||
* `line`: The line number in the generated source, or null.
|
||||
|
||||
* `column`: The column number in the generated source, or null.
|
||||
|
||||
#### SourceMapConsumer.prototype.sourceContentFor(source)
|
||||
|
||||
Returns the original source content for the source provided. The only
|
||||
argument is the URL of the original source file.
|
||||
|
||||
#### SourceMapConsumer.prototype.eachMapping(callback, context, order)
|
||||
|
||||
Iterate over each mapping between an original source/line/column and a
|
||||
generated line/column in this source map.
|
||||
|
||||
* `callback`: The function that is called with each mapping. Mappings have the
|
||||
form `{ source, generatedLine, generatedColumn, originalLine, originalColumn,
|
||||
name }`
|
||||
|
||||
* `context`: Optional. If specified, this object will be the value of `this`
|
||||
every time that `callback` is called.
|
||||
|
||||
* `order`: Either `SourceMapConsumer.GENERATED_ORDER` or
|
||||
`SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to iterate over
|
||||
the mappings sorted by the generated file's line/column order or the
|
||||
original's source/line/column order, respectively. Defaults to
|
||||
`SourceMapConsumer.GENERATED_ORDER`.
|
||||
|
||||
### SourceMapGenerator
|
||||
|
||||
An instance of the SourceMapGenerator represents a source map which is being
|
||||
built incrementally.
|
||||
|
||||
#### new SourceMapGenerator([startOfSourceMap])
|
||||
|
||||
You may pass an object with the following properties:
|
||||
|
||||
* `file`: The filename of the generated source that this source map is
|
||||
associated with.
|
||||
|
||||
* `sourceRoot`: A root for all relative URLs in this source map.
|
||||
|
||||
#### SourceMapGenerator.fromSourceMap(sourceMapConsumer)
|
||||
|
||||
Creates a new SourceMapGenerator based on a SourceMapConsumer
|
||||
|
||||
* `sourceMapConsumer` The SourceMap.
|
||||
|
||||
#### SourceMapGenerator.prototype.addMapping(mapping)
|
||||
|
||||
Add a single mapping from original source line and column to the generated
|
||||
source's line and column for this source map being created. The mapping object
|
||||
should have the following properties:
|
||||
|
||||
* `generated`: An object with the generated line and column positions.
|
||||
|
||||
* `original`: An object with the original line and column positions.
|
||||
|
||||
* `source`: The original source file (relative to the sourceRoot).
|
||||
|
||||
* `name`: An optional original token name for this mapping.
|
||||
|
||||
#### SourceMapGenerator.prototype.setSourceContent(sourceFile, sourceContent)
|
||||
|
||||
Set the source content for an original source file.
|
||||
|
||||
* `sourceFile` the URL of the original source file.
|
||||
|
||||
* `sourceContent` the content of the source file.
|
||||
|
||||
#### SourceMapGenerator.prototype.applySourceMap(sourceMapConsumer[, sourceFile[, sourceMapPath]])
|
||||
|
||||
Applies a SourceMap for a source file to the SourceMap.
|
||||
Each mapping to the supplied source file is rewritten using the
|
||||
supplied SourceMap. Note: The resolution for the resulting mappings
|
||||
is the minimium of this map and the supplied map.
|
||||
|
||||
* `sourceMapConsumer`: The SourceMap to be applied.
|
||||
|
||||
* `sourceFile`: Optional. The filename of the source file.
|
||||
If omitted, sourceMapConsumer.file will be used, if it exists.
|
||||
Otherwise an error will be thrown.
|
||||
|
||||
* `sourceMapPath`: Optional. The dirname of the path to the SourceMap
|
||||
to be applied. If relative, it is relative to the SourceMap.
|
||||
|
||||
This parameter is needed when the two SourceMaps aren't in the same
|
||||
directory, and the SourceMap to be applied contains relative source
|
||||
paths. If so, those relative source paths need to be rewritten
|
||||
relative to the SourceMap.
|
||||
|
||||
If omitted, it is assumed that both SourceMaps are in the same directory,
|
||||
thus not needing any rewriting. (Supplying `'.'` has the same effect.)
|
||||
|
||||
#### SourceMapGenerator.prototype.toString()
|
||||
|
||||
Renders the source map being generated to a string.
|
||||
|
||||
### SourceNode
|
||||
|
||||
SourceNodes provide a way to abstract over interpolating and/or concatenating
|
||||
snippets of generated JavaScript source code, while maintaining the line and
|
||||
column information associated between those snippets and the original source
|
||||
code. This is useful as the final intermediate representation a compiler might
|
||||
use before outputting the generated JS and source map.
|
||||
|
||||
#### new SourceNode([line, column, source[, chunk[, name]]])
|
||||
|
||||
* `line`: The original line number associated with this source node, or null if
|
||||
it isn't associated with an original line.
|
||||
|
||||
* `column`: The original column number associated with this source node, or null
|
||||
if it isn't associated with an original column.
|
||||
|
||||
* `source`: The original source's filename; null if no filename is provided.
|
||||
|
||||
* `chunk`: Optional. Is immediately passed to `SourceNode.prototype.add`, see
|
||||
below.
|
||||
|
||||
* `name`: Optional. The original identifier.
|
||||
|
||||
#### SourceNode.fromStringWithSourceMap(code, sourceMapConsumer)
|
||||
|
||||
Creates a SourceNode from generated code and a SourceMapConsumer.
|
||||
|
||||
* `code`: The generated code
|
||||
|
||||
* `sourceMapConsumer` The SourceMap for the generated code
|
||||
|
||||
#### SourceNode.prototype.add(chunk)
|
||||
|
||||
Add a chunk of generated JS to this source node.
|
||||
|
||||
* `chunk`: A string snippet of generated JS code, another instance of
|
||||
`SourceNode`, or an array where each member is one of those things.
|
||||
|
||||
#### SourceNode.prototype.prepend(chunk)
|
||||
|
||||
Prepend a chunk of generated JS to this source node.
|
||||
|
||||
* `chunk`: A string snippet of generated JS code, another instance of
|
||||
`SourceNode`, or an array where each member is one of those things.
|
||||
|
||||
#### SourceNode.prototype.setSourceContent(sourceFile, sourceContent)
|
||||
|
||||
Set the source content for a source file. This will be added to the
|
||||
`SourceMap` in the `sourcesContent` field.
|
||||
|
||||
* `sourceFile`: The filename of the source file
|
||||
|
||||
* `sourceContent`: The content of the source file
|
||||
|
||||
#### SourceNode.prototype.walk(fn)
|
||||
|
||||
Walk over the tree of JS snippets in this node and its children. The walking
|
||||
function is called once for each snippet of JS and is passed that snippet and
|
||||
the its original associated source's line/column location.
|
||||
|
||||
* `fn`: The traversal function.
|
||||
|
||||
#### SourceNode.prototype.walkSourceContents(fn)
|
||||
|
||||
Walk over the tree of SourceNodes. The walking function is called for each
|
||||
source file content and is passed the filename and source content.
|
||||
|
||||
* `fn`: The traversal function.
|
||||
|
||||
#### SourceNode.prototype.join(sep)
|
||||
|
||||
Like `Array.prototype.join` except for SourceNodes. Inserts the separator
|
||||
between each of this source node's children.
|
||||
|
||||
* `sep`: The separator.
|
||||
|
||||
#### SourceNode.prototype.replaceRight(pattern, replacement)
|
||||
|
||||
Call `String.prototype.replace` on the very right-most source snippet. Useful
|
||||
for trimming whitespace from the end of a source node, etc.
|
||||
|
||||
* `pattern`: The pattern to replace.
|
||||
|
||||
* `replacement`: The thing to replace the pattern with.
|
||||
|
||||
#### SourceNode.prototype.toString()
|
||||
|
||||
Return the string representation of this source node. Walks over the tree and
|
||||
concatenates all the various snippets together to one string.
|
||||
|
||||
### SourceNode.prototype.toStringWithSourceMap([startOfSourceMap])
|
||||
|
||||
Returns the string representation of this tree of source nodes, plus a
|
||||
SourceMapGenerator which contains all the mappings between the generated and
|
||||
original sources.
|
||||
|
||||
The arguments are the same as those to `new SourceMapGenerator`.
|
||||
|
||||
## Tests
|
||||
|
||||
[](https://travis-ci.org/mozilla/source-map)
|
||||
|
||||
Install NodeJS version 0.8.0 or greater, then run `node test/run-tests.js`.
|
||||
|
||||
To add new tests, create a new file named `test/test-<your new test name>.js`
|
||||
and export your test functions with names that start with "test", for example
|
||||
|
||||
exports["test doing the foo bar"] = function (assert, util) {
|
||||
...
|
||||
};
|
||||
|
||||
The new test will be located automatically when you run the suite.
|
||||
|
||||
The `util` argument is the test utility module located at `test/source-map/util`.
|
||||
|
||||
The `assert` argument is a cut down version of node's assert module. You have
|
||||
access to the following assertion functions:
|
||||
|
||||
* `doesNotThrow`
|
||||
|
||||
* `equal`
|
||||
|
||||
* `ok`
|
||||
|
||||
* `strictEqual`
|
||||
|
||||
* `throws`
|
||||
|
||||
(The reason for the restricted set of test functions is because we need the
|
||||
tests to run inside Firefox's test suite as well and so the assert module is
|
||||
shimmed in that environment. See `build/assert-shim.js`.)
|
||||
|
||||
[format]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit
|
||||
[feature]: https://wiki.mozilla.org/DevTools/Features/SourceMap
|
||||
[Dryice]: https://github.com/mozilla/dryice
|
||||
56
node_modules/swig/node_modules/source-map/build/assert-shim.js
generated
vendored
Normal file
56
node_modules/swig/node_modules/source-map/build/assert-shim.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
define('test/source-map/assert', ['exports'], function (exports) {
|
||||
|
||||
let do_throw = function (msg) {
|
||||
throw new Error(msg);
|
||||
};
|
||||
|
||||
exports.init = function (throw_fn) {
|
||||
do_throw = throw_fn;
|
||||
};
|
||||
|
||||
exports.doesNotThrow = function (fn) {
|
||||
try {
|
||||
fn();
|
||||
}
|
||||
catch (e) {
|
||||
do_throw(e.message);
|
||||
}
|
||||
};
|
||||
|
||||
exports.equal = function (actual, expected, msg) {
|
||||
msg = msg || String(actual) + ' != ' + String(expected);
|
||||
if (actual != expected) {
|
||||
do_throw(msg);
|
||||
}
|
||||
};
|
||||
|
||||
exports.ok = function (val, msg) {
|
||||
msg = msg || String(val) + ' is falsey';
|
||||
if (!Boolean(val)) {
|
||||
do_throw(msg);
|
||||
}
|
||||
};
|
||||
|
||||
exports.strictEqual = function (actual, expected, msg) {
|
||||
msg = msg || String(actual) + ' !== ' + String(expected);
|
||||
if (actual !== expected) {
|
||||
do_throw(msg);
|
||||
}
|
||||
};
|
||||
|
||||
exports.throws = function (fn) {
|
||||
try {
|
||||
fn();
|
||||
do_throw('Expected an error to be thrown, but it wasn\'t.');
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
152
node_modules/swig/node_modules/source-map/build/mini-require.js
generated
vendored
Normal file
152
node_modules/swig/node_modules/source-map/build/mini-require.js
generated
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
|
||||
/**
|
||||
* Define a module along with a payload.
|
||||
* @param {string} moduleName Name for the payload
|
||||
* @param {ignored} deps Ignored. For compatibility with CommonJS AMD Spec
|
||||
* @param {function} payload Function with (require, exports, module) params
|
||||
*/
|
||||
function define(moduleName, deps, payload) {
|
||||
if (typeof moduleName != "string") {
|
||||
throw new TypeError('Expected string, got: ' + moduleName);
|
||||
}
|
||||
|
||||
if (arguments.length == 2) {
|
||||
payload = deps;
|
||||
}
|
||||
|
||||
if (moduleName in define.modules) {
|
||||
throw new Error("Module already defined: " + moduleName);
|
||||
}
|
||||
define.modules[moduleName] = payload;
|
||||
};
|
||||
|
||||
/**
|
||||
* The global store of un-instantiated modules
|
||||
*/
|
||||
define.modules = {};
|
||||
|
||||
|
||||
/**
|
||||
* We invoke require() in the context of a Domain so we can have multiple
|
||||
* sets of modules running separate from each other.
|
||||
* This contrasts with JSMs which are singletons, Domains allows us to
|
||||
* optionally load a CommonJS module twice with separate data each time.
|
||||
* Perhaps you want 2 command lines with a different set of commands in each,
|
||||
* for example.
|
||||
*/
|
||||
function Domain() {
|
||||
this.modules = {};
|
||||
this._currentModule = null;
|
||||
}
|
||||
|
||||
(function () {
|
||||
|
||||
/**
|
||||
* Lookup module names and resolve them by calling the definition function if
|
||||
* needed.
|
||||
* There are 2 ways to call this, either with an array of dependencies and a
|
||||
* callback to call when the dependencies are found (which can happen
|
||||
* asynchronously in an in-page context) or with a single string an no callback
|
||||
* where the dependency is resolved synchronously and returned.
|
||||
* The API is designed to be compatible with the CommonJS AMD spec and
|
||||
* RequireJS.
|
||||
* @param {string[]|string} deps A name, or names for the payload
|
||||
* @param {function|undefined} callback Function to call when the dependencies
|
||||
* are resolved
|
||||
* @return {undefined|object} The module required or undefined for
|
||||
* array/callback method
|
||||
*/
|
||||
Domain.prototype.require = function(deps, callback) {
|
||||
if (Array.isArray(deps)) {
|
||||
var params = deps.map(function(dep) {
|
||||
return this.lookup(dep);
|
||||
}, this);
|
||||
if (callback) {
|
||||
callback.apply(null, params);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
else {
|
||||
return this.lookup(deps);
|
||||
}
|
||||
};
|
||||
|
||||
function normalize(path) {
|
||||
var bits = path.split('/');
|
||||
var i = 1;
|
||||
while (i < bits.length) {
|
||||
if (bits[i] === '..') {
|
||||
bits.splice(i-1, 1);
|
||||
} else if (bits[i] === '.') {
|
||||
bits.splice(i, 1);
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return bits.join('/');
|
||||
}
|
||||
|
||||
function join(a, b) {
|
||||
a = a.trim();
|
||||
b = b.trim();
|
||||
if (/^\//.test(b)) {
|
||||
return b;
|
||||
} else {
|
||||
return a.replace(/\/*$/, '/') + b;
|
||||
}
|
||||
}
|
||||
|
||||
function dirname(path) {
|
||||
var bits = path.split('/');
|
||||
bits.pop();
|
||||
return bits.join('/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup module names and resolve them by calling the definition function if
|
||||
* needed.
|
||||
* @param {string} moduleName A name for the payload to lookup
|
||||
* @return {object} The module specified by aModuleName or null if not found.
|
||||
*/
|
||||
Domain.prototype.lookup = function(moduleName) {
|
||||
if (/^\./.test(moduleName)) {
|
||||
moduleName = normalize(join(dirname(this._currentModule), moduleName));
|
||||
}
|
||||
|
||||
if (moduleName in this.modules) {
|
||||
var module = this.modules[moduleName];
|
||||
return module;
|
||||
}
|
||||
|
||||
if (!(moduleName in define.modules)) {
|
||||
throw new Error("Module not defined: " + moduleName);
|
||||
}
|
||||
|
||||
var module = define.modules[moduleName];
|
||||
|
||||
if (typeof module == "function") {
|
||||
var exports = {};
|
||||
var previousModule = this._currentModule;
|
||||
this._currentModule = moduleName;
|
||||
module(this.require.bind(this), exports, { id: moduleName, uri: "" });
|
||||
this._currentModule = previousModule;
|
||||
module = exports;
|
||||
}
|
||||
|
||||
// cache the resulting module object for next time
|
||||
this.modules[moduleName] = module;
|
||||
|
||||
return module;
|
||||
};
|
||||
|
||||
}());
|
||||
|
||||
define.Domain = Domain;
|
||||
define.globalDomain = new Domain();
|
||||
var require = define.globalDomain.require.bind(define.globalDomain);
|
||||
20
node_modules/swig/node_modules/source-map/build/prefix-source-map.jsm
generated
vendored
Normal file
20
node_modules/swig/node_modules/source-map/build/prefix-source-map.jsm
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
|
||||
/*
|
||||
* WARNING!
|
||||
*
|
||||
* Do not edit this file directly, it is built from the sources at
|
||||
* https://github.com/mozilla/source-map/
|
||||
*/
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
this.EXPORTED_SYMBOLS = [ "SourceMapConsumer", "SourceMapGenerator", "SourceNode" ];
|
||||
|
||||
Components.utils.import('resource://gre/modules/devtools/Require.jsm');
|
||||
18
node_modules/swig/node_modules/source-map/build/prefix-utils.jsm
generated
vendored
Normal file
18
node_modules/swig/node_modules/source-map/build/prefix-utils.jsm
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
|
||||
/*
|
||||
* WARNING!
|
||||
*
|
||||
* Do not edit this file directly, it is built from the sources at
|
||||
* https://github.com/mozilla/source-map/
|
||||
*/
|
||||
|
||||
Components.utils.import('resource://gre/modules/devtools/Require.jsm');
|
||||
Components.utils.import('resource://gre/modules/devtools/SourceMap.jsm');
|
||||
|
||||
this.EXPORTED_SYMBOLS = [ "define", "runSourceMapTests" ];
|
||||
8
node_modules/swig/node_modules/source-map/build/suffix-browser.js
generated
vendored
Normal file
8
node_modules/swig/node_modules/source-map/build/suffix-browser.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
this.sourceMap = {
|
||||
SourceMapConsumer: require('source-map/source-map-consumer').SourceMapConsumer,
|
||||
SourceMapGenerator: require('source-map/source-map-generator').SourceMapGenerator,
|
||||
SourceNode: require('source-map/source-node').SourceNode
|
||||
};
|
||||
6
node_modules/swig/node_modules/source-map/build/suffix-source-map.jsm
generated
vendored
Normal file
6
node_modules/swig/node_modules/source-map/build/suffix-source-map.jsm
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
this.SourceMapConsumer = require('source-map/source-map-consumer').SourceMapConsumer;
|
||||
this.SourceMapGenerator = require('source-map/source-map-generator').SourceMapGenerator;
|
||||
this.SourceNode = require('source-map/source-node').SourceNode;
|
||||
21
node_modules/swig/node_modules/source-map/build/suffix-utils.jsm
generated
vendored
Normal file
21
node_modules/swig/node_modules/source-map/build/suffix-utils.jsm
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
function runSourceMapTests(modName, do_throw) {
|
||||
let mod = require(modName);
|
||||
let assert = require('test/source-map/assert');
|
||||
let util = require('test/source-map/util');
|
||||
|
||||
assert.init(do_throw);
|
||||
|
||||
for (let k in mod) {
|
||||
if (/^test/.test(k)) {
|
||||
mod[k](assert, util);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
this.runSourceMapTests = runSourceMapTests;
|
||||
8
node_modules/swig/node_modules/source-map/build/test-prefix.js
generated
vendored
Normal file
8
node_modules/swig/node_modules/source-map/build/test-prefix.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
* WARNING!
|
||||
*
|
||||
* Do not edit this file directly, it is built from the sources at
|
||||
* https://github.com/mozilla/source-map/
|
||||
*/
|
||||
|
||||
Components.utils.import('resource://test/Utils.jsm');
|
||||
3
node_modules/swig/node_modules/source-map/build/test-suffix.js
generated
vendored
Normal file
3
node_modules/swig/node_modules/source-map/build/test-suffix.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
function run_test() {
|
||||
runSourceMapTests('{THIS_MODULE}', do_throw);
|
||||
}
|
||||
8
node_modules/swig/node_modules/source-map/lib/source-map.js
generated
vendored
Normal file
8
node_modules/swig/node_modules/source-map/lib/source-map.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
* Copyright 2009-2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE.txt or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
exports.SourceMapGenerator = require('./source-map/source-map-generator').SourceMapGenerator;
|
||||
exports.SourceMapConsumer = require('./source-map/source-map-consumer').SourceMapConsumer;
|
||||
exports.SourceNode = require('./source-map/source-node').SourceNode;
|
||||
97
node_modules/swig/node_modules/source-map/lib/source-map/array-set.js
generated
vendored
Normal file
97
node_modules/swig/node_modules/source-map/lib/source-map/array-set.js
generated
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
if (typeof define !== 'function') {
|
||||
var define = require('amdefine')(module, require);
|
||||
}
|
||||
define(function (require, exports, module) {
|
||||
|
||||
var util = require('./util');
|
||||
|
||||
/**
|
||||
* A data structure which is a combination of an array and a set. Adding a new
|
||||
* member is O(1), testing for membership is O(1), and finding the index of an
|
||||
* element is O(1). Removing elements from the set is not supported. Only
|
||||
* strings are supported for membership.
|
||||
*/
|
||||
function ArraySet() {
|
||||
this._array = [];
|
||||
this._set = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Static method for creating ArraySet instances from an existing array.
|
||||
*/
|
||||
ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
|
||||
var set = new ArraySet();
|
||||
for (var i = 0, len = aArray.length; i < len; i++) {
|
||||
set.add(aArray[i], aAllowDuplicates);
|
||||
}
|
||||
return set;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add the given string to this set.
|
||||
*
|
||||
* @param String aStr
|
||||
*/
|
||||
ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
|
||||
var isDuplicate = this.has(aStr);
|
||||
var idx = this._array.length;
|
||||
if (!isDuplicate || aAllowDuplicates) {
|
||||
this._array.push(aStr);
|
||||
}
|
||||
if (!isDuplicate) {
|
||||
this._set[util.toSetString(aStr)] = idx;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Is the given string a member of this set?
|
||||
*
|
||||
* @param String aStr
|
||||
*/
|
||||
ArraySet.prototype.has = function ArraySet_has(aStr) {
|
||||
return Object.prototype.hasOwnProperty.call(this._set,
|
||||
util.toSetString(aStr));
|
||||
};
|
||||
|
||||
/**
|
||||
* What is the index of the given string in the array?
|
||||
*
|
||||
* @param String aStr
|
||||
*/
|
||||
ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
|
||||
if (this.has(aStr)) {
|
||||
return this._set[util.toSetString(aStr)];
|
||||
}
|
||||
throw new Error('"' + aStr + '" is not in the set.');
|
||||
};
|
||||
|
||||
/**
|
||||
* What is the element at the given index?
|
||||
*
|
||||
* @param Number aIdx
|
||||
*/
|
||||
ArraySet.prototype.at = function ArraySet_at(aIdx) {
|
||||
if (aIdx >= 0 && aIdx < this._array.length) {
|
||||
return this._array[aIdx];
|
||||
}
|
||||
throw new Error('No element indexed by ' + aIdx);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the array representation of this set (which has the proper indices
|
||||
* indicated by indexOf). Note that this is a copy of the internal array used
|
||||
* for storing the members so that no one can mess with internal state.
|
||||
*/
|
||||
ArraySet.prototype.toArray = function ArraySet_toArray() {
|
||||
return this._array.slice();
|
||||
};
|
||||
|
||||
exports.ArraySet = ArraySet;
|
||||
|
||||
});
|
||||
144
node_modules/swig/node_modules/source-map/lib/source-map/base64-vlq.js
generated
vendored
Normal file
144
node_modules/swig/node_modules/source-map/lib/source-map/base64-vlq.js
generated
vendored
Normal file
@@ -0,0 +1,144 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
* Based on the Base 64 VLQ implementation in Closure Compiler:
|
||||
* https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
|
||||
*
|
||||
* Copyright 2011 The Closure Compiler Authors. All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
if (typeof define !== 'function') {
|
||||
var define = require('amdefine')(module, require);
|
||||
}
|
||||
define(function (require, exports, module) {
|
||||
|
||||
var base64 = require('./base64');
|
||||
|
||||
// A single base 64 digit can contain 6 bits of data. For the base 64 variable
|
||||
// length quantities we use in the source map spec, the first bit is the sign,
|
||||
// the next four bits are the actual value, and the 6th bit is the
|
||||
// continuation bit. The continuation bit tells us whether there are more
|
||||
// digits in this value following this digit.
|
||||
//
|
||||
// Continuation
|
||||
// | Sign
|
||||
// | |
|
||||
// V V
|
||||
// 101011
|
||||
|
||||
var VLQ_BASE_SHIFT = 5;
|
||||
|
||||
// binary: 100000
|
||||
var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
|
||||
|
||||
// binary: 011111
|
||||
var VLQ_BASE_MASK = VLQ_BASE - 1;
|
||||
|
||||
// binary: 100000
|
||||
var VLQ_CONTINUATION_BIT = VLQ_BASE;
|
||||
|
||||
/**
|
||||
* Converts from a two-complement value to a value where the sign bit is
|
||||
* is placed in the least significant bit. For example, as decimals:
|
||||
* 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
|
||||
* 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
|
||||
*/
|
||||
function toVLQSigned(aValue) {
|
||||
return aValue < 0
|
||||
? ((-aValue) << 1) + 1
|
||||
: (aValue << 1) + 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts to a two-complement value from a value where the sign bit is
|
||||
* is placed in the least significant bit. For example, as decimals:
|
||||
* 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
|
||||
* 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
|
||||
*/
|
||||
function fromVLQSigned(aValue) {
|
||||
var isNegative = (aValue & 1) === 1;
|
||||
var shifted = aValue >> 1;
|
||||
return isNegative
|
||||
? -shifted
|
||||
: shifted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the base 64 VLQ encoded value.
|
||||
*/
|
||||
exports.encode = function base64VLQ_encode(aValue) {
|
||||
var encoded = "";
|
||||
var digit;
|
||||
|
||||
var vlq = toVLQSigned(aValue);
|
||||
|
||||
do {
|
||||
digit = vlq & VLQ_BASE_MASK;
|
||||
vlq >>>= VLQ_BASE_SHIFT;
|
||||
if (vlq > 0) {
|
||||
// There are still more digits in this value, so we must make sure the
|
||||
// continuation bit is marked.
|
||||
digit |= VLQ_CONTINUATION_BIT;
|
||||
}
|
||||
encoded += base64.encode(digit);
|
||||
} while (vlq > 0);
|
||||
|
||||
return encoded;
|
||||
};
|
||||
|
||||
/**
|
||||
* Decodes the next base 64 VLQ value from the given string and returns the
|
||||
* value and the rest of the string.
|
||||
*/
|
||||
exports.decode = function base64VLQ_decode(aStr) {
|
||||
var i = 0;
|
||||
var strLen = aStr.length;
|
||||
var result = 0;
|
||||
var shift = 0;
|
||||
var continuation, digit;
|
||||
|
||||
do {
|
||||
if (i >= strLen) {
|
||||
throw new Error("Expected more digits in base 64 VLQ value.");
|
||||
}
|
||||
digit = base64.decode(aStr.charAt(i++));
|
||||
continuation = !!(digit & VLQ_CONTINUATION_BIT);
|
||||
digit &= VLQ_BASE_MASK;
|
||||
result = result + (digit << shift);
|
||||
shift += VLQ_BASE_SHIFT;
|
||||
} while (continuation);
|
||||
|
||||
return {
|
||||
value: fromVLQSigned(result),
|
||||
rest: aStr.slice(i)
|
||||
};
|
||||
};
|
||||
|
||||
});
|
||||
42
node_modules/swig/node_modules/source-map/lib/source-map/base64.js
generated
vendored
Normal file
42
node_modules/swig/node_modules/source-map/lib/source-map/base64.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
if (typeof define !== 'function') {
|
||||
var define = require('amdefine')(module, require);
|
||||
}
|
||||
define(function (require, exports, module) {
|
||||
|
||||
var charToIntMap = {};
|
||||
var intToCharMap = {};
|
||||
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
||||
.split('')
|
||||
.forEach(function (ch, index) {
|
||||
charToIntMap[ch] = index;
|
||||
intToCharMap[index] = ch;
|
||||
});
|
||||
|
||||
/**
|
||||
* Encode an integer in the range of 0 to 63 to a single base 64 digit.
|
||||
*/
|
||||
exports.encode = function base64_encode(aNumber) {
|
||||
if (aNumber in intToCharMap) {
|
||||
return intToCharMap[aNumber];
|
||||
}
|
||||
throw new TypeError("Must be between 0 and 63: " + aNumber);
|
||||
};
|
||||
|
||||
/**
|
||||
* Decode a single base 64 digit to an integer.
|
||||
*/
|
||||
exports.decode = function base64_decode(aChar) {
|
||||
if (aChar in charToIntMap) {
|
||||
return charToIntMap[aChar];
|
||||
}
|
||||
throw new TypeError("Not a valid base 64 digit: " + aChar);
|
||||
};
|
||||
|
||||
});
|
||||
81
node_modules/swig/node_modules/source-map/lib/source-map/binary-search.js
generated
vendored
Normal file
81
node_modules/swig/node_modules/source-map/lib/source-map/binary-search.js
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
if (typeof define !== 'function') {
|
||||
var define = require('amdefine')(module, require);
|
||||
}
|
||||
define(function (require, exports, module) {
|
||||
|
||||
/**
|
||||
* Recursive implementation of binary search.
|
||||
*
|
||||
* @param aLow Indices here and lower do not contain the needle.
|
||||
* @param aHigh Indices here and higher do not contain the needle.
|
||||
* @param aNeedle The element being searched for.
|
||||
* @param aHaystack The non-empty array being searched.
|
||||
* @param aCompare Function which takes two elements and returns -1, 0, or 1.
|
||||
*/
|
||||
function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare) {
|
||||
// This function terminates when one of the following is true:
|
||||
//
|
||||
// 1. We find the exact element we are looking for.
|
||||
//
|
||||
// 2. We did not find the exact element, but we can return the next
|
||||
// closest element that is less than that element.
|
||||
//
|
||||
// 3. We did not find the exact element, and there is no next-closest
|
||||
// element which is less than the one we are searching for, so we
|
||||
// return null.
|
||||
var mid = Math.floor((aHigh - aLow) / 2) + aLow;
|
||||
var cmp = aCompare(aNeedle, aHaystack[mid], true);
|
||||
if (cmp === 0) {
|
||||
// Found the element we are looking for.
|
||||
return aHaystack[mid];
|
||||
}
|
||||
else if (cmp > 0) {
|
||||
// aHaystack[mid] is greater than our needle.
|
||||
if (aHigh - mid > 1) {
|
||||
// The element is in the upper half.
|
||||
return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare);
|
||||
}
|
||||
// We did not find an exact match, return the next closest one
|
||||
// (termination case 2).
|
||||
return aHaystack[mid];
|
||||
}
|
||||
else {
|
||||
// aHaystack[mid] is less than our needle.
|
||||
if (mid - aLow > 1) {
|
||||
// The element is in the lower half.
|
||||
return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare);
|
||||
}
|
||||
// The exact needle element was not found in this haystack. Determine if
|
||||
// we are in termination case (2) or (3) and return the appropriate thing.
|
||||
return aLow < 0
|
||||
? null
|
||||
: aHaystack[aLow];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is an implementation of binary search which will always try and return
|
||||
* the next lowest value checked if there is no exact hit. This is because
|
||||
* mappings between original and generated line/col pairs are single points,
|
||||
* and there is an implicit region between each of them, so a miss just means
|
||||
* that you aren't on the very start of a region.
|
||||
*
|
||||
* @param aNeedle The element you are looking for.
|
||||
* @param aHaystack The array that is being searched.
|
||||
* @param aCompare A function which takes the needle and an element in the
|
||||
* array and returns -1, 0, or 1 depending on whether the needle is less
|
||||
* than, equal to, or greater than the element, respectively.
|
||||
*/
|
||||
exports.search = function search(aNeedle, aHaystack, aCompare) {
|
||||
return aHaystack.length > 0
|
||||
? recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, aCompare)
|
||||
: null;
|
||||
};
|
||||
|
||||
});
|
||||
478
node_modules/swig/node_modules/source-map/lib/source-map/source-map-consumer.js
generated
vendored
Normal file
478
node_modules/swig/node_modules/source-map/lib/source-map/source-map-consumer.js
generated
vendored
Normal file
@@ -0,0 +1,478 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
if (typeof define !== 'function') {
|
||||
var define = require('amdefine')(module, require);
|
||||
}
|
||||
define(function (require, exports, module) {
|
||||
|
||||
var util = require('./util');
|
||||
var binarySearch = require('./binary-search');
|
||||
var ArraySet = require('./array-set').ArraySet;
|
||||
var base64VLQ = require('./base64-vlq');
|
||||
|
||||
/**
|
||||
* A SourceMapConsumer instance represents a parsed source map which we can
|
||||
* query for information about the original file positions by giving it a file
|
||||
* position in the generated source.
|
||||
*
|
||||
* The only parameter is the raw source map (either as a JSON string, or
|
||||
* already parsed to an object). According to the spec, source maps have the
|
||||
* following attributes:
|
||||
*
|
||||
* - version: Which version of the source map spec this map is following.
|
||||
* - sources: An array of URLs to the original source files.
|
||||
* - names: An array of identifiers which can be referrenced by individual mappings.
|
||||
* - sourceRoot: Optional. The URL root from which all sources are relative.
|
||||
* - sourcesContent: Optional. An array of contents of the original source files.
|
||||
* - mappings: A string of base64 VLQs which contain the actual mappings.
|
||||
* - file: Optional. The generated file this source map is associated with.
|
||||
*
|
||||
* Here is an example source map, taken from the source map spec[0]:
|
||||
*
|
||||
* {
|
||||
* version : 3,
|
||||
* file: "out.js",
|
||||
* sourceRoot : "",
|
||||
* sources: ["foo.js", "bar.js"],
|
||||
* names: ["src", "maps", "are", "fun"],
|
||||
* mappings: "AA,AB;;ABCDE;"
|
||||
* }
|
||||
*
|
||||
* [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
|
||||
*/
|
||||
function SourceMapConsumer(aSourceMap) {
|
||||
var sourceMap = aSourceMap;
|
||||
if (typeof aSourceMap === 'string') {
|
||||
sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, ''));
|
||||
}
|
||||
|
||||
var version = util.getArg(sourceMap, 'version');
|
||||
var sources = util.getArg(sourceMap, 'sources');
|
||||
// Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
|
||||
// requires the array) to play nice here.
|
||||
var names = util.getArg(sourceMap, 'names', []);
|
||||
var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null);
|
||||
var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null);
|
||||
var mappings = util.getArg(sourceMap, 'mappings');
|
||||
var file = util.getArg(sourceMap, 'file', null);
|
||||
|
||||
// Once again, Sass deviates from the spec and supplies the version as a
|
||||
// string rather than a number, so we use loose equality checking here.
|
||||
if (version != this._version) {
|
||||
throw new Error('Unsupported version: ' + version);
|
||||
}
|
||||
|
||||
// Pass `true` below to allow duplicate names and sources. While source maps
|
||||
// are intended to be compressed and deduplicated, the TypeScript compiler
|
||||
// sometimes generates source maps with duplicates in them. See Github issue
|
||||
// #72 and bugzil.la/889492.
|
||||
this._names = ArraySet.fromArray(names, true);
|
||||
this._sources = ArraySet.fromArray(sources, true);
|
||||
|
||||
this.sourceRoot = sourceRoot;
|
||||
this.sourcesContent = sourcesContent;
|
||||
this._mappings = mappings;
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a SourceMapConsumer from a SourceMapGenerator.
|
||||
*
|
||||
* @param SourceMapGenerator aSourceMap
|
||||
* The source map that will be consumed.
|
||||
* @returns SourceMapConsumer
|
||||
*/
|
||||
SourceMapConsumer.fromSourceMap =
|
||||
function SourceMapConsumer_fromSourceMap(aSourceMap) {
|
||||
var smc = Object.create(SourceMapConsumer.prototype);
|
||||
|
||||
smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
|
||||
smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
|
||||
smc.sourceRoot = aSourceMap._sourceRoot;
|
||||
smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
|
||||
smc.sourceRoot);
|
||||
smc.file = aSourceMap._file;
|
||||
|
||||
smc.__generatedMappings = aSourceMap._mappings.slice()
|
||||
.sort(util.compareByGeneratedPositions);
|
||||
smc.__originalMappings = aSourceMap._mappings.slice()
|
||||
.sort(util.compareByOriginalPositions);
|
||||
|
||||
return smc;
|
||||
};
|
||||
|
||||
/**
|
||||
* The version of the source mapping spec that we are consuming.
|
||||
*/
|
||||
SourceMapConsumer.prototype._version = 3;
|
||||
|
||||
/**
|
||||
* The list of original sources.
|
||||
*/
|
||||
Object.defineProperty(SourceMapConsumer.prototype, 'sources', {
|
||||
get: function () {
|
||||
return this._sources.toArray().map(function (s) {
|
||||
return this.sourceRoot ? util.join(this.sourceRoot, s) : s;
|
||||
}, this);
|
||||
}
|
||||
});
|
||||
|
||||
// `__generatedMappings` and `__originalMappings` are arrays that hold the
|
||||
// parsed mapping coordinates from the source map's "mappings" attribute. They
|
||||
// are lazily instantiated, accessed via the `_generatedMappings` and
|
||||
// `_originalMappings` getters respectively, and we only parse the mappings
|
||||
// and create these arrays once queried for a source location. We jump through
|
||||
// these hoops because there can be many thousands of mappings, and parsing
|
||||
// them is expensive, so we only want to do it if we must.
|
||||
//
|
||||
// Each object in the arrays is of the form:
|
||||
//
|
||||
// {
|
||||
// generatedLine: The line number in the generated code,
|
||||
// generatedColumn: The column number in the generated code,
|
||||
// source: The path to the original source file that generated this
|
||||
// chunk of code,
|
||||
// originalLine: The line number in the original source that
|
||||
// corresponds to this chunk of generated code,
|
||||
// originalColumn: The column number in the original source that
|
||||
// corresponds to this chunk of generated code,
|
||||
// name: The name of the original symbol which generated this chunk of
|
||||
// code.
|
||||
// }
|
||||
//
|
||||
// All properties except for `generatedLine` and `generatedColumn` can be
|
||||
// `null`.
|
||||
//
|
||||
// `_generatedMappings` is ordered by the generated positions.
|
||||
//
|
||||
// `_originalMappings` is ordered by the original positions.
|
||||
|
||||
SourceMapConsumer.prototype.__generatedMappings = null;
|
||||
Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
|
||||
get: function () {
|
||||
if (!this.__generatedMappings) {
|
||||
this.__generatedMappings = [];
|
||||
this.__originalMappings = [];
|
||||
this._parseMappings(this._mappings, this.sourceRoot);
|
||||
}
|
||||
|
||||
return this.__generatedMappings;
|
||||
}
|
||||
});
|
||||
|
||||
SourceMapConsumer.prototype.__originalMappings = null;
|
||||
Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', {
|
||||
get: function () {
|
||||
if (!this.__originalMappings) {
|
||||
this.__generatedMappings = [];
|
||||
this.__originalMappings = [];
|
||||
this._parseMappings(this._mappings, this.sourceRoot);
|
||||
}
|
||||
|
||||
return this.__originalMappings;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Parse the mappings in a string in to a data structure which we can easily
|
||||
* query (the ordered arrays in the `this.__generatedMappings` and
|
||||
* `this.__originalMappings` properties).
|
||||
*/
|
||||
SourceMapConsumer.prototype._parseMappings =
|
||||
function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
|
||||
var generatedLine = 1;
|
||||
var previousGeneratedColumn = 0;
|
||||
var previousOriginalLine = 0;
|
||||
var previousOriginalColumn = 0;
|
||||
var previousSource = 0;
|
||||
var previousName = 0;
|
||||
var mappingSeparator = /^[,;]/;
|
||||
var str = aStr;
|
||||
var mapping;
|
||||
var temp;
|
||||
|
||||
while (str.length > 0) {
|
||||
if (str.charAt(0) === ';') {
|
||||
generatedLine++;
|
||||
str = str.slice(1);
|
||||
previousGeneratedColumn = 0;
|
||||
}
|
||||
else if (str.charAt(0) === ',') {
|
||||
str = str.slice(1);
|
||||
}
|
||||
else {
|
||||
mapping = {};
|
||||
mapping.generatedLine = generatedLine;
|
||||
|
||||
// Generated column.
|
||||
temp = base64VLQ.decode(str);
|
||||
mapping.generatedColumn = previousGeneratedColumn + temp.value;
|
||||
previousGeneratedColumn = mapping.generatedColumn;
|
||||
str = temp.rest;
|
||||
|
||||
if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) {
|
||||
// Original source.
|
||||
temp = base64VLQ.decode(str);
|
||||
mapping.source = this._sources.at(previousSource + temp.value);
|
||||
previousSource += temp.value;
|
||||
str = temp.rest;
|
||||
if (str.length === 0 || mappingSeparator.test(str.charAt(0))) {
|
||||
throw new Error('Found a source, but no line and column');
|
||||
}
|
||||
|
||||
// Original line.
|
||||
temp = base64VLQ.decode(str);
|
||||
mapping.originalLine = previousOriginalLine + temp.value;
|
||||
previousOriginalLine = mapping.originalLine;
|
||||
// Lines are stored 0-based
|
||||
mapping.originalLine += 1;
|
||||
str = temp.rest;
|
||||
if (str.length === 0 || mappingSeparator.test(str.charAt(0))) {
|
||||
throw new Error('Found a source and line, but no column');
|
||||
}
|
||||
|
||||
// Original column.
|
||||
temp = base64VLQ.decode(str);
|
||||
mapping.originalColumn = previousOriginalColumn + temp.value;
|
||||
previousOriginalColumn = mapping.originalColumn;
|
||||
str = temp.rest;
|
||||
|
||||
if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) {
|
||||
// Original name.
|
||||
temp = base64VLQ.decode(str);
|
||||
mapping.name = this._names.at(previousName + temp.value);
|
||||
previousName += temp.value;
|
||||
str = temp.rest;
|
||||
}
|
||||
}
|
||||
|
||||
this.__generatedMappings.push(mapping);
|
||||
if (typeof mapping.originalLine === 'number') {
|
||||
this.__originalMappings.push(mapping);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.__generatedMappings.sort(util.compareByGeneratedPositions);
|
||||
this.__originalMappings.sort(util.compareByOriginalPositions);
|
||||
};
|
||||
|
||||
/**
|
||||
* Find the mapping that best matches the hypothetical "needle" mapping that
|
||||
* we are searching for in the given "haystack" of mappings.
|
||||
*/
|
||||
SourceMapConsumer.prototype._findMapping =
|
||||
function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
|
||||
aColumnName, aComparator) {
|
||||
// To return the position we are searching for, we must first find the
|
||||
// mapping for the given position and then return the opposite position it
|
||||
// points to. Because the mappings are sorted, we can use binary search to
|
||||
// find the best mapping.
|
||||
|
||||
if (aNeedle[aLineName] <= 0) {
|
||||
throw new TypeError('Line must be greater than or equal to 1, got '
|
||||
+ aNeedle[aLineName]);
|
||||
}
|
||||
if (aNeedle[aColumnName] < 0) {
|
||||
throw new TypeError('Column must be greater than or equal to 0, got '
|
||||
+ aNeedle[aColumnName]);
|
||||
}
|
||||
|
||||
return binarySearch.search(aNeedle, aMappings, aComparator);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the original source, line, and column information for the generated
|
||||
* source's line and column positions provided. The only argument is an object
|
||||
* with the following properties:
|
||||
*
|
||||
* - line: The line number in the generated source.
|
||||
* - column: The column number in the generated source.
|
||||
*
|
||||
* and an object is returned with the following properties:
|
||||
*
|
||||
* - source: The original source file, or null.
|
||||
* - line: The line number in the original source, or null.
|
||||
* - column: The column number in the original source, or null.
|
||||
* - name: The original identifier, or null.
|
||||
*/
|
||||
SourceMapConsumer.prototype.originalPositionFor =
|
||||
function SourceMapConsumer_originalPositionFor(aArgs) {
|
||||
var needle = {
|
||||
generatedLine: util.getArg(aArgs, 'line'),
|
||||
generatedColumn: util.getArg(aArgs, 'column')
|
||||
};
|
||||
|
||||
var mapping = this._findMapping(needle,
|
||||
this._generatedMappings,
|
||||
"generatedLine",
|
||||
"generatedColumn",
|
||||
util.compareByGeneratedPositions);
|
||||
|
||||
if (mapping && mapping.generatedLine === needle.generatedLine) {
|
||||
var source = util.getArg(mapping, 'source', null);
|
||||
if (source && this.sourceRoot) {
|
||||
source = util.join(this.sourceRoot, source);
|
||||
}
|
||||
return {
|
||||
source: source,
|
||||
line: util.getArg(mapping, 'originalLine', null),
|
||||
column: util.getArg(mapping, 'originalColumn', null),
|
||||
name: util.getArg(mapping, 'name', null)
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
source: null,
|
||||
line: null,
|
||||
column: null,
|
||||
name: null
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the original source content. The only argument is the url of the
|
||||
* original source file. Returns null if no original source content is
|
||||
* availible.
|
||||
*/
|
||||
SourceMapConsumer.prototype.sourceContentFor =
|
||||
function SourceMapConsumer_sourceContentFor(aSource) {
|
||||
if (!this.sourcesContent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (this.sourceRoot) {
|
||||
aSource = util.relative(this.sourceRoot, aSource);
|
||||
}
|
||||
|
||||
if (this._sources.has(aSource)) {
|
||||
return this.sourcesContent[this._sources.indexOf(aSource)];
|
||||
}
|
||||
|
||||
var url;
|
||||
if (this.sourceRoot
|
||||
&& (url = util.urlParse(this.sourceRoot))) {
|
||||
// XXX: file:// URIs and absolute paths lead to unexpected behavior for
|
||||
// many users. We can help them out when they expect file:// URIs to
|
||||
// behave like it would if they were running a local HTTP server. See
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
|
||||
var fileUriAbsPath = aSource.replace(/^file:\/\//, "");
|
||||
if (url.scheme == "file"
|
||||
&& this._sources.has(fileUriAbsPath)) {
|
||||
return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
|
||||
}
|
||||
|
||||
if ((!url.path || url.path == "/")
|
||||
&& this._sources.has("/" + aSource)) {
|
||||
return this.sourcesContent[this._sources.indexOf("/" + aSource)];
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error('"' + aSource + '" is not in the SourceMap.');
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the generated line and column information for the original source,
|
||||
* line, and column positions provided. The only argument is an object with
|
||||
* the following properties:
|
||||
*
|
||||
* - source: The filename of the original source.
|
||||
* - line: The line number in the original source.
|
||||
* - column: The column number in the original source.
|
||||
*
|
||||
* and an object is returned with the following properties:
|
||||
*
|
||||
* - line: The line number in the generated source, or null.
|
||||
* - column: The column number in the generated source, or null.
|
||||
*/
|
||||
SourceMapConsumer.prototype.generatedPositionFor =
|
||||
function SourceMapConsumer_generatedPositionFor(aArgs) {
|
||||
var needle = {
|
||||
source: util.getArg(aArgs, 'source'),
|
||||
originalLine: util.getArg(aArgs, 'line'),
|
||||
originalColumn: util.getArg(aArgs, 'column')
|
||||
};
|
||||
|
||||
if (this.sourceRoot) {
|
||||
needle.source = util.relative(this.sourceRoot, needle.source);
|
||||
}
|
||||
|
||||
var mapping = this._findMapping(needle,
|
||||
this._originalMappings,
|
||||
"originalLine",
|
||||
"originalColumn",
|
||||
util.compareByOriginalPositions);
|
||||
|
||||
if (mapping) {
|
||||
return {
|
||||
line: util.getArg(mapping, 'generatedLine', null),
|
||||
column: util.getArg(mapping, 'generatedColumn', null)
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
line: null,
|
||||
column: null
|
||||
};
|
||||
};
|
||||
|
||||
SourceMapConsumer.GENERATED_ORDER = 1;
|
||||
SourceMapConsumer.ORIGINAL_ORDER = 2;
|
||||
|
||||
/**
|
||||
* Iterate over each mapping between an original source/line/column and a
|
||||
* generated line/column in this source map.
|
||||
*
|
||||
* @param Function aCallback
|
||||
* The function that is called with each mapping.
|
||||
* @param Object aContext
|
||||
* Optional. If specified, this object will be the value of `this` every
|
||||
* time that `aCallback` is called.
|
||||
* @param aOrder
|
||||
* Either `SourceMapConsumer.GENERATED_ORDER` or
|
||||
* `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
|
||||
* iterate over the mappings sorted by the generated file's line/column
|
||||
* order or the original's source/line/column order, respectively. Defaults to
|
||||
* `SourceMapConsumer.GENERATED_ORDER`.
|
||||
*/
|
||||
SourceMapConsumer.prototype.eachMapping =
|
||||
function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
|
||||
var context = aContext || null;
|
||||
var order = aOrder || SourceMapConsumer.GENERATED_ORDER;
|
||||
|
||||
var mappings;
|
||||
switch (order) {
|
||||
case SourceMapConsumer.GENERATED_ORDER:
|
||||
mappings = this._generatedMappings;
|
||||
break;
|
||||
case SourceMapConsumer.ORIGINAL_ORDER:
|
||||
mappings = this._originalMappings;
|
||||
break;
|
||||
default:
|
||||
throw new Error("Unknown order of iteration.");
|
||||
}
|
||||
|
||||
var sourceRoot = this.sourceRoot;
|
||||
mappings.map(function (mapping) {
|
||||
var source = mapping.source;
|
||||
if (source && sourceRoot) {
|
||||
source = util.join(sourceRoot, source);
|
||||
}
|
||||
return {
|
||||
source: source,
|
||||
generatedLine: mapping.generatedLine,
|
||||
generatedColumn: mapping.generatedColumn,
|
||||
originalLine: mapping.originalLine,
|
||||
originalColumn: mapping.originalColumn,
|
||||
name: mapping.name
|
||||
};
|
||||
}).forEach(aCallback, context);
|
||||
};
|
||||
|
||||
exports.SourceMapConsumer = SourceMapConsumer;
|
||||
|
||||
});
|
||||
400
node_modules/swig/node_modules/source-map/lib/source-map/source-map-generator.js
generated
vendored
Normal file
400
node_modules/swig/node_modules/source-map/lib/source-map/source-map-generator.js
generated
vendored
Normal file
@@ -0,0 +1,400 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
if (typeof define !== 'function') {
|
||||
var define = require('amdefine')(module, require);
|
||||
}
|
||||
define(function (require, exports, module) {
|
||||
|
||||
var base64VLQ = require('./base64-vlq');
|
||||
var util = require('./util');
|
||||
var ArraySet = require('./array-set').ArraySet;
|
||||
|
||||
/**
|
||||
* An instance of the SourceMapGenerator represents a source map which is
|
||||
* being built incrementally. You may pass an object with the following
|
||||
* properties:
|
||||
*
|
||||
* - file: The filename of the generated source.
|
||||
* - sourceRoot: A root for all relative URLs in this source map.
|
||||
*/
|
||||
function SourceMapGenerator(aArgs) {
|
||||
if (!aArgs) {
|
||||
aArgs = {};
|
||||
}
|
||||
this._file = util.getArg(aArgs, 'file', null);
|
||||
this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null);
|
||||
this._sources = new ArraySet();
|
||||
this._names = new ArraySet();
|
||||
this._mappings = [];
|
||||
this._sourcesContents = null;
|
||||
}
|
||||
|
||||
SourceMapGenerator.prototype._version = 3;
|
||||
|
||||
/**
|
||||
* Creates a new SourceMapGenerator based on a SourceMapConsumer
|
||||
*
|
||||
* @param aSourceMapConsumer The SourceMap.
|
||||
*/
|
||||
SourceMapGenerator.fromSourceMap =
|
||||
function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) {
|
||||
var sourceRoot = aSourceMapConsumer.sourceRoot;
|
||||
var generator = new SourceMapGenerator({
|
||||
file: aSourceMapConsumer.file,
|
||||
sourceRoot: sourceRoot
|
||||
});
|
||||
aSourceMapConsumer.eachMapping(function (mapping) {
|
||||
var newMapping = {
|
||||
generated: {
|
||||
line: mapping.generatedLine,
|
||||
column: mapping.generatedColumn
|
||||
}
|
||||
};
|
||||
|
||||
if (mapping.source) {
|
||||
newMapping.source = mapping.source;
|
||||
if (sourceRoot) {
|
||||
newMapping.source = util.relative(sourceRoot, newMapping.source);
|
||||
}
|
||||
|
||||
newMapping.original = {
|
||||
line: mapping.originalLine,
|
||||
column: mapping.originalColumn
|
||||
};
|
||||
|
||||
if (mapping.name) {
|
||||
newMapping.name = mapping.name;
|
||||
}
|
||||
}
|
||||
|
||||
generator.addMapping(newMapping);
|
||||
});
|
||||
aSourceMapConsumer.sources.forEach(function (sourceFile) {
|
||||
var content = aSourceMapConsumer.sourceContentFor(sourceFile);
|
||||
if (content) {
|
||||
generator.setSourceContent(sourceFile, content);
|
||||
}
|
||||
});
|
||||
return generator;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a single mapping from original source line and column to the generated
|
||||
* source's line and column for this source map being created. The mapping
|
||||
* object should have the following properties:
|
||||
*
|
||||
* - generated: An object with the generated line and column positions.
|
||||
* - original: An object with the original line and column positions.
|
||||
* - source: The original source file (relative to the sourceRoot).
|
||||
* - name: An optional original token name for this mapping.
|
||||
*/
|
||||
SourceMapGenerator.prototype.addMapping =
|
||||
function SourceMapGenerator_addMapping(aArgs) {
|
||||
var generated = util.getArg(aArgs, 'generated');
|
||||
var original = util.getArg(aArgs, 'original', null);
|
||||
var source = util.getArg(aArgs, 'source', null);
|
||||
var name = util.getArg(aArgs, 'name', null);
|
||||
|
||||
this._validateMapping(generated, original, source, name);
|
||||
|
||||
if (source && !this._sources.has(source)) {
|
||||
this._sources.add(source);
|
||||
}
|
||||
|
||||
if (name && !this._names.has(name)) {
|
||||
this._names.add(name);
|
||||
}
|
||||
|
||||
this._mappings.push({
|
||||
generatedLine: generated.line,
|
||||
generatedColumn: generated.column,
|
||||
originalLine: original != null && original.line,
|
||||
originalColumn: original != null && original.column,
|
||||
source: source,
|
||||
name: name
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the source content for a source file.
|
||||
*/
|
||||
SourceMapGenerator.prototype.setSourceContent =
|
||||
function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
|
||||
var source = aSourceFile;
|
||||
if (this._sourceRoot) {
|
||||
source = util.relative(this._sourceRoot, source);
|
||||
}
|
||||
|
||||
if (aSourceContent !== null) {
|
||||
// Add the source content to the _sourcesContents map.
|
||||
// Create a new _sourcesContents map if the property is null.
|
||||
if (!this._sourcesContents) {
|
||||
this._sourcesContents = {};
|
||||
}
|
||||
this._sourcesContents[util.toSetString(source)] = aSourceContent;
|
||||
} else {
|
||||
// Remove the source file from the _sourcesContents map.
|
||||
// If the _sourcesContents map is empty, set the property to null.
|
||||
delete this._sourcesContents[util.toSetString(source)];
|
||||
if (Object.keys(this._sourcesContents).length === 0) {
|
||||
this._sourcesContents = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Applies the mappings of a sub-source-map for a specific source file to the
|
||||
* source map being generated. Each mapping to the supplied source file is
|
||||
* rewritten using the supplied source map. Note: The resolution for the
|
||||
* resulting mappings is the minimium of this map and the supplied map.
|
||||
*
|
||||
* @param aSourceMapConsumer The source map to be applied.
|
||||
* @param aSourceFile Optional. The filename of the source file.
|
||||
* If omitted, SourceMapConsumer's file property will be used.
|
||||
* @param aSourceMapPath Optional. The dirname of the path to the source map
|
||||
* to be applied. If relative, it is relative to the SourceMapConsumer.
|
||||
* This parameter is needed when the two source maps aren't in the same
|
||||
* directory, and the source map to be applied contains relative source
|
||||
* paths. If so, those relative source paths need to be rewritten
|
||||
* relative to the SourceMapGenerator.
|
||||
*/
|
||||
SourceMapGenerator.prototype.applySourceMap =
|
||||
function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) {
|
||||
// If aSourceFile is omitted, we will use the file property of the SourceMap
|
||||
if (!aSourceFile) {
|
||||
if (!aSourceMapConsumer.file) {
|
||||
throw new Error(
|
||||
'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' +
|
||||
'or the source map\'s "file" property. Both were omitted.'
|
||||
);
|
||||
}
|
||||
aSourceFile = aSourceMapConsumer.file;
|
||||
}
|
||||
var sourceRoot = this._sourceRoot;
|
||||
// Make "aSourceFile" relative if an absolute Url is passed.
|
||||
if (sourceRoot) {
|
||||
aSourceFile = util.relative(sourceRoot, aSourceFile);
|
||||
}
|
||||
// Applying the SourceMap can add and remove items from the sources and
|
||||
// the names array.
|
||||
var newSources = new ArraySet();
|
||||
var newNames = new ArraySet();
|
||||
|
||||
// Find mappings for the "aSourceFile"
|
||||
this._mappings.forEach(function (mapping) {
|
||||
if (mapping.source === aSourceFile && mapping.originalLine) {
|
||||
// Check if it can be mapped by the source map, then update the mapping.
|
||||
var original = aSourceMapConsumer.originalPositionFor({
|
||||
line: mapping.originalLine,
|
||||
column: mapping.originalColumn
|
||||
});
|
||||
if (original.source !== null) {
|
||||
// Copy mapping
|
||||
mapping.source = original.source;
|
||||
if (aSourceMapPath) {
|
||||
mapping.source = util.join(aSourceMapPath, mapping.source)
|
||||
}
|
||||
if (sourceRoot) {
|
||||
mapping.source = util.relative(sourceRoot, mapping.source);
|
||||
}
|
||||
mapping.originalLine = original.line;
|
||||
mapping.originalColumn = original.column;
|
||||
if (original.name !== null && mapping.name !== null) {
|
||||
// Only use the identifier name if it's an identifier
|
||||
// in both SourceMaps
|
||||
mapping.name = original.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var source = mapping.source;
|
||||
if (source && !newSources.has(source)) {
|
||||
newSources.add(source);
|
||||
}
|
||||
|
||||
var name = mapping.name;
|
||||
if (name && !newNames.has(name)) {
|
||||
newNames.add(name);
|
||||
}
|
||||
|
||||
}, this);
|
||||
this._sources = newSources;
|
||||
this._names = newNames;
|
||||
|
||||
// Copy sourcesContents of applied map.
|
||||
aSourceMapConsumer.sources.forEach(function (sourceFile) {
|
||||
var content = aSourceMapConsumer.sourceContentFor(sourceFile);
|
||||
if (content) {
|
||||
if (aSourceMapPath) {
|
||||
sourceFile = util.join(aSourceMapPath, sourceFile);
|
||||
}
|
||||
if (sourceRoot) {
|
||||
sourceFile = util.relative(sourceRoot, sourceFile);
|
||||
}
|
||||
this.setSourceContent(sourceFile, content);
|
||||
}
|
||||
}, this);
|
||||
};
|
||||
|
||||
/**
|
||||
* A mapping can have one of the three levels of data:
|
||||
*
|
||||
* 1. Just the generated position.
|
||||
* 2. The Generated position, original position, and original source.
|
||||
* 3. Generated and original position, original source, as well as a name
|
||||
* token.
|
||||
*
|
||||
* To maintain consistency, we validate that any new mapping being added falls
|
||||
* in to one of these categories.
|
||||
*/
|
||||
SourceMapGenerator.prototype._validateMapping =
|
||||
function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
|
||||
aName) {
|
||||
if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
|
||||
&& aGenerated.line > 0 && aGenerated.column >= 0
|
||||
&& !aOriginal && !aSource && !aName) {
|
||||
// Case 1.
|
||||
return;
|
||||
}
|
||||
else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
|
||||
&& aOriginal && 'line' in aOriginal && 'column' in aOriginal
|
||||
&& aGenerated.line > 0 && aGenerated.column >= 0
|
||||
&& aOriginal.line > 0 && aOriginal.column >= 0
|
||||
&& aSource) {
|
||||
// Cases 2 and 3.
|
||||
return;
|
||||
}
|
||||
else {
|
||||
throw new Error('Invalid mapping: ' + JSON.stringify({
|
||||
generated: aGenerated,
|
||||
source: aSource,
|
||||
original: aOriginal,
|
||||
name: aName
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Serialize the accumulated mappings in to the stream of base 64 VLQs
|
||||
* specified by the source map format.
|
||||
*/
|
||||
SourceMapGenerator.prototype._serializeMappings =
|
||||
function SourceMapGenerator_serializeMappings() {
|
||||
var previousGeneratedColumn = 0;
|
||||
var previousGeneratedLine = 1;
|
||||
var previousOriginalColumn = 0;
|
||||
var previousOriginalLine = 0;
|
||||
var previousName = 0;
|
||||
var previousSource = 0;
|
||||
var result = '';
|
||||
var mapping;
|
||||
|
||||
// The mappings must be guaranteed to be in sorted order before we start
|
||||
// serializing them or else the generated line numbers (which are defined
|
||||
// via the ';' separators) will be all messed up. Note: it might be more
|
||||
// performant to maintain the sorting as we insert them, rather than as we
|
||||
// serialize them, but the big O is the same either way.
|
||||
this._mappings.sort(util.compareByGeneratedPositions);
|
||||
|
||||
for (var i = 0, len = this._mappings.length; i < len; i++) {
|
||||
mapping = this._mappings[i];
|
||||
|
||||
if (mapping.generatedLine !== previousGeneratedLine) {
|
||||
previousGeneratedColumn = 0;
|
||||
while (mapping.generatedLine !== previousGeneratedLine) {
|
||||
result += ';';
|
||||
previousGeneratedLine++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (i > 0) {
|
||||
if (!util.compareByGeneratedPositions(mapping, this._mappings[i - 1])) {
|
||||
continue;
|
||||
}
|
||||
result += ',';
|
||||
}
|
||||
}
|
||||
|
||||
result += base64VLQ.encode(mapping.generatedColumn
|
||||
- previousGeneratedColumn);
|
||||
previousGeneratedColumn = mapping.generatedColumn;
|
||||
|
||||
if (mapping.source) {
|
||||
result += base64VLQ.encode(this._sources.indexOf(mapping.source)
|
||||
- previousSource);
|
||||
previousSource = this._sources.indexOf(mapping.source);
|
||||
|
||||
// lines are stored 0-based in SourceMap spec version 3
|
||||
result += base64VLQ.encode(mapping.originalLine - 1
|
||||
- previousOriginalLine);
|
||||
previousOriginalLine = mapping.originalLine - 1;
|
||||
|
||||
result += base64VLQ.encode(mapping.originalColumn
|
||||
- previousOriginalColumn);
|
||||
previousOriginalColumn = mapping.originalColumn;
|
||||
|
||||
if (mapping.name) {
|
||||
result += base64VLQ.encode(this._names.indexOf(mapping.name)
|
||||
- previousName);
|
||||
previousName = this._names.indexOf(mapping.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
SourceMapGenerator.prototype._generateSourcesContent =
|
||||
function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
|
||||
return aSources.map(function (source) {
|
||||
if (!this._sourcesContents) {
|
||||
return null;
|
||||
}
|
||||
if (aSourceRoot) {
|
||||
source = util.relative(aSourceRoot, source);
|
||||
}
|
||||
var key = util.toSetString(source);
|
||||
return Object.prototype.hasOwnProperty.call(this._sourcesContents,
|
||||
key)
|
||||
? this._sourcesContents[key]
|
||||
: null;
|
||||
}, this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Externalize the source map.
|
||||
*/
|
||||
SourceMapGenerator.prototype.toJSON =
|
||||
function SourceMapGenerator_toJSON() {
|
||||
var map = {
|
||||
version: this._version,
|
||||
file: this._file,
|
||||
sources: this._sources.toArray(),
|
||||
names: this._names.toArray(),
|
||||
mappings: this._serializeMappings()
|
||||
};
|
||||
if (this._sourceRoot) {
|
||||
map.sourceRoot = this._sourceRoot;
|
||||
}
|
||||
if (this._sourcesContents) {
|
||||
map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
|
||||
}
|
||||
|
||||
return map;
|
||||
};
|
||||
|
||||
/**
|
||||
* Render the source map being generated to a string.
|
||||
*/
|
||||
SourceMapGenerator.prototype.toString =
|
||||
function SourceMapGenerator_toString() {
|
||||
return JSON.stringify(this);
|
||||
};
|
||||
|
||||
exports.SourceMapGenerator = SourceMapGenerator;
|
||||
|
||||
});
|
||||
400
node_modules/swig/node_modules/source-map/lib/source-map/source-node.js
generated
vendored
Normal file
400
node_modules/swig/node_modules/source-map/lib/source-map/source-node.js
generated
vendored
Normal file
@@ -0,0 +1,400 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
if (typeof define !== 'function') {
|
||||
var define = require('amdefine')(module, require);
|
||||
}
|
||||
define(function (require, exports, module) {
|
||||
|
||||
var SourceMapGenerator = require('./source-map-generator').SourceMapGenerator;
|
||||
var util = require('./util');
|
||||
|
||||
// Matches a Windows-style `\r\n` newline or a `\n` newline used by all other
|
||||
// operating systems these days (capturing the result).
|
||||
var REGEX_NEWLINE = /(\r?\n)/g;
|
||||
|
||||
// Matches a Windows-style newline, or any character.
|
||||
var REGEX_CHARACTER = /\r\n|[\s\S]/g;
|
||||
|
||||
/**
|
||||
* SourceNodes provide a way to abstract over interpolating/concatenating
|
||||
* snippets of generated JavaScript source code while maintaining the line and
|
||||
* column information associated with the original source code.
|
||||
*
|
||||
* @param aLine The original line number.
|
||||
* @param aColumn The original column number.
|
||||
* @param aSource The original source's filename.
|
||||
* @param aChunks Optional. An array of strings which are snippets of
|
||||
* generated JS, or other SourceNodes.
|
||||
* @param aName The original identifier.
|
||||
*/
|
||||
function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
|
||||
this.children = [];
|
||||
this.sourceContents = {};
|
||||
this.line = aLine === undefined ? null : aLine;
|
||||
this.column = aColumn === undefined ? null : aColumn;
|
||||
this.source = aSource === undefined ? null : aSource;
|
||||
this.name = aName === undefined ? null : aName;
|
||||
if (aChunks != null) this.add(aChunks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a SourceNode from generated code and a SourceMapConsumer.
|
||||
*
|
||||
* @param aGeneratedCode The generated code
|
||||
* @param aSourceMapConsumer The SourceMap for the generated code
|
||||
*/
|
||||
SourceNode.fromStringWithSourceMap =
|
||||
function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer) {
|
||||
// The SourceNode we want to fill with the generated code
|
||||
// and the SourceMap
|
||||
var node = new SourceNode();
|
||||
|
||||
// All even indices of this array are one line of the generated code,
|
||||
// while all odd indices are the newlines between two adjacent lines
|
||||
// (since `REGEX_NEWLINE` captures its match).
|
||||
// Processed fragments are removed from this array, by calling `shiftNextLine`.
|
||||
var remainingLines = aGeneratedCode.split(REGEX_NEWLINE);
|
||||
var shiftNextLine = function() {
|
||||
var lineContents = remainingLines.shift();
|
||||
// The last line of a file might not have a newline.
|
||||
var newLine = remainingLines.shift() || "";
|
||||
return lineContents + newLine;
|
||||
};
|
||||
|
||||
// We need to remember the position of "remainingLines"
|
||||
var lastGeneratedLine = 1, lastGeneratedColumn = 0;
|
||||
|
||||
// The generate SourceNodes we need a code range.
|
||||
// To extract it current and last mapping is used.
|
||||
// Here we store the last mapping.
|
||||
var lastMapping = null;
|
||||
|
||||
aSourceMapConsumer.eachMapping(function (mapping) {
|
||||
if (lastMapping !== null) {
|
||||
// We add the code from "lastMapping" to "mapping":
|
||||
// First check if there is a new line in between.
|
||||
if (lastGeneratedLine < mapping.generatedLine) {
|
||||
var code = "";
|
||||
// Associate first line with "lastMapping"
|
||||
addMappingWithCode(lastMapping, shiftNextLine());
|
||||
lastGeneratedLine++;
|
||||
lastGeneratedColumn = 0;
|
||||
// The remaining code is added without mapping
|
||||
} else {
|
||||
// There is no new line in between.
|
||||
// Associate the code between "lastGeneratedColumn" and
|
||||
// "mapping.generatedColumn" with "lastMapping"
|
||||
var nextLine = remainingLines[0];
|
||||
var code = nextLine.substr(0, mapping.generatedColumn -
|
||||
lastGeneratedColumn);
|
||||
remainingLines[0] = nextLine.substr(mapping.generatedColumn -
|
||||
lastGeneratedColumn);
|
||||
lastGeneratedColumn = mapping.generatedColumn;
|
||||
addMappingWithCode(lastMapping, code);
|
||||
// No more remaining code, continue
|
||||
lastMapping = mapping;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// We add the generated code until the first mapping
|
||||
// to the SourceNode without any mapping.
|
||||
// Each line is added as separate string.
|
||||
while (lastGeneratedLine < mapping.generatedLine) {
|
||||
node.add(shiftNextLine());
|
||||
lastGeneratedLine++;
|
||||
}
|
||||
if (lastGeneratedColumn < mapping.generatedColumn) {
|
||||
var nextLine = remainingLines[0];
|
||||
node.add(nextLine.substr(0, mapping.generatedColumn));
|
||||
remainingLines[0] = nextLine.substr(mapping.generatedColumn);
|
||||
lastGeneratedColumn = mapping.generatedColumn;
|
||||
}
|
||||
lastMapping = mapping;
|
||||
}, this);
|
||||
// We have processed all mappings.
|
||||
if (remainingLines.length > 0) {
|
||||
if (lastMapping) {
|
||||
// Associate the remaining code in the current line with "lastMapping"
|
||||
addMappingWithCode(lastMapping, shiftNextLine());
|
||||
}
|
||||
// and add the remaining lines without any mapping
|
||||
node.add(remainingLines.join(""));
|
||||
}
|
||||
|
||||
// Copy sourcesContent into SourceNode
|
||||
aSourceMapConsumer.sources.forEach(function (sourceFile) {
|
||||
var content = aSourceMapConsumer.sourceContentFor(sourceFile);
|
||||
if (content) {
|
||||
node.setSourceContent(sourceFile, content);
|
||||
}
|
||||
});
|
||||
|
||||
return node;
|
||||
|
||||
function addMappingWithCode(mapping, code) {
|
||||
if (mapping === null || mapping.source === undefined) {
|
||||
node.add(code);
|
||||
} else {
|
||||
node.add(new SourceNode(mapping.originalLine,
|
||||
mapping.originalColumn,
|
||||
mapping.source,
|
||||
code,
|
||||
mapping.name));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a chunk of generated JS to this source node.
|
||||
*
|
||||
* @param aChunk A string snippet of generated JS code, another instance of
|
||||
* SourceNode, or an array where each member is one of those things.
|
||||
*/
|
||||
SourceNode.prototype.add = function SourceNode_add(aChunk) {
|
||||
if (Array.isArray(aChunk)) {
|
||||
aChunk.forEach(function (chunk) {
|
||||
this.add(chunk);
|
||||
}, this);
|
||||
}
|
||||
else if (aChunk instanceof SourceNode || typeof aChunk === "string") {
|
||||
if (aChunk) {
|
||||
this.children.push(aChunk);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new TypeError(
|
||||
"Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
|
||||
);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a chunk of generated JS to the beginning of this source node.
|
||||
*
|
||||
* @param aChunk A string snippet of generated JS code, another instance of
|
||||
* SourceNode, or an array where each member is one of those things.
|
||||
*/
|
||||
SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
|
||||
if (Array.isArray(aChunk)) {
|
||||
for (var i = aChunk.length-1; i >= 0; i--) {
|
||||
this.prepend(aChunk[i]);
|
||||
}
|
||||
}
|
||||
else if (aChunk instanceof SourceNode || typeof aChunk === "string") {
|
||||
this.children.unshift(aChunk);
|
||||
}
|
||||
else {
|
||||
throw new TypeError(
|
||||
"Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
|
||||
);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Walk over the tree of JS snippets in this node and its children. The
|
||||
* walking function is called once for each snippet of JS and is passed that
|
||||
* snippet and the its original associated source's line/column location.
|
||||
*
|
||||
* @param aFn The traversal function.
|
||||
*/
|
||||
SourceNode.prototype.walk = function SourceNode_walk(aFn) {
|
||||
var chunk;
|
||||
for (var i = 0, len = this.children.length; i < len; i++) {
|
||||
chunk = this.children[i];
|
||||
if (chunk instanceof SourceNode) {
|
||||
chunk.walk(aFn);
|
||||
}
|
||||
else {
|
||||
if (chunk !== '') {
|
||||
aFn(chunk, { source: this.source,
|
||||
line: this.line,
|
||||
column: this.column,
|
||||
name: this.name });
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
|
||||
* each of `this.children`.
|
||||
*
|
||||
* @param aSep The separator.
|
||||
*/
|
||||
SourceNode.prototype.join = function SourceNode_join(aSep) {
|
||||
var newChildren;
|
||||
var i;
|
||||
var len = this.children.length;
|
||||
if (len > 0) {
|
||||
newChildren = [];
|
||||
for (i = 0; i < len-1; i++) {
|
||||
newChildren.push(this.children[i]);
|
||||
newChildren.push(aSep);
|
||||
}
|
||||
newChildren.push(this.children[i]);
|
||||
this.children = newChildren;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Call String.prototype.replace on the very right-most source snippet. Useful
|
||||
* for trimming whitespace from the end of a source node, etc.
|
||||
*
|
||||
* @param aPattern The pattern to replace.
|
||||
* @param aReplacement The thing to replace the pattern with.
|
||||
*/
|
||||
SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
|
||||
var lastChild = this.children[this.children.length - 1];
|
||||
if (lastChild instanceof SourceNode) {
|
||||
lastChild.replaceRight(aPattern, aReplacement);
|
||||
}
|
||||
else if (typeof lastChild === 'string') {
|
||||
this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
|
||||
}
|
||||
else {
|
||||
this.children.push(''.replace(aPattern, aReplacement));
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the source content for a source file. This will be added to the SourceMapGenerator
|
||||
* in the sourcesContent field.
|
||||
*
|
||||
* @param aSourceFile The filename of the source file
|
||||
* @param aSourceContent The content of the source file
|
||||
*/
|
||||
SourceNode.prototype.setSourceContent =
|
||||
function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
|
||||
this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
|
||||
};
|
||||
|
||||
/**
|
||||
* Walk over the tree of SourceNodes. The walking function is called for each
|
||||
* source file content and is passed the filename and source content.
|
||||
*
|
||||
* @param aFn The traversal function.
|
||||
*/
|
||||
SourceNode.prototype.walkSourceContents =
|
||||
function SourceNode_walkSourceContents(aFn) {
|
||||
for (var i = 0, len = this.children.length; i < len; i++) {
|
||||
if (this.children[i] instanceof SourceNode) {
|
||||
this.children[i].walkSourceContents(aFn);
|
||||
}
|
||||
}
|
||||
|
||||
var sources = Object.keys(this.sourceContents);
|
||||
for (var i = 0, len = sources.length; i < len; i++) {
|
||||
aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the string representation of this source node. Walks over the tree
|
||||
* and concatenates all the various snippets together to one string.
|
||||
*/
|
||||
SourceNode.prototype.toString = function SourceNode_toString() {
|
||||
var str = "";
|
||||
this.walk(function (chunk) {
|
||||
str += chunk;
|
||||
});
|
||||
return str;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the string representation of this source node along with a source
|
||||
* map.
|
||||
*/
|
||||
SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
|
||||
var generated = {
|
||||
code: "",
|
||||
line: 1,
|
||||
column: 0
|
||||
};
|
||||
var map = new SourceMapGenerator(aArgs);
|
||||
var sourceMappingActive = false;
|
||||
var lastOriginalSource = null;
|
||||
var lastOriginalLine = null;
|
||||
var lastOriginalColumn = null;
|
||||
var lastOriginalName = null;
|
||||
this.walk(function (chunk, original) {
|
||||
generated.code += chunk;
|
||||
if (original.source !== null
|
||||
&& original.line !== null
|
||||
&& original.column !== null) {
|
||||
if(lastOriginalSource !== original.source
|
||||
|| lastOriginalLine !== original.line
|
||||
|| lastOriginalColumn !== original.column
|
||||
|| lastOriginalName !== original.name) {
|
||||
map.addMapping({
|
||||
source: original.source,
|
||||
original: {
|
||||
line: original.line,
|
||||
column: original.column
|
||||
},
|
||||
generated: {
|
||||
line: generated.line,
|
||||
column: generated.column
|
||||
},
|
||||
name: original.name
|
||||
});
|
||||
}
|
||||
lastOriginalSource = original.source;
|
||||
lastOriginalLine = original.line;
|
||||
lastOriginalColumn = original.column;
|
||||
lastOriginalName = original.name;
|
||||
sourceMappingActive = true;
|
||||
} else if (sourceMappingActive) {
|
||||
map.addMapping({
|
||||
generated: {
|
||||
line: generated.line,
|
||||
column: generated.column
|
||||
}
|
||||
});
|
||||
lastOriginalSource = null;
|
||||
sourceMappingActive = false;
|
||||
}
|
||||
chunk.match(REGEX_CHARACTER).forEach(function (ch, idx, array) {
|
||||
if (REGEX_NEWLINE.test(ch)) {
|
||||
generated.line++;
|
||||
generated.column = 0;
|
||||
// Mappings end at eol
|
||||
if (idx + 1 === array.length) {
|
||||
lastOriginalSource = null;
|
||||
sourceMappingActive = false;
|
||||
} else if (sourceMappingActive) {
|
||||
map.addMapping({
|
||||
source: original.source,
|
||||
original: {
|
||||
line: original.line,
|
||||
column: original.column
|
||||
},
|
||||
generated: {
|
||||
line: generated.line,
|
||||
column: generated.column
|
||||
},
|
||||
name: original.name
|
||||
});
|
||||
}
|
||||
} else {
|
||||
generated.column += ch.length;
|
||||
}
|
||||
});
|
||||
});
|
||||
this.walkSourceContents(function (sourceFile, sourceContent) {
|
||||
map.setSourceContent(sourceFile, sourceContent);
|
||||
});
|
||||
|
||||
return { code: generated.code, map: map };
|
||||
};
|
||||
|
||||
exports.SourceNode = SourceNode;
|
||||
|
||||
});
|
||||
302
node_modules/swig/node_modules/source-map/lib/source-map/util.js
generated
vendored
Normal file
302
node_modules/swig/node_modules/source-map/lib/source-map/util.js
generated
vendored
Normal file
@@ -0,0 +1,302 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
if (typeof define !== 'function') {
|
||||
var define = require('amdefine')(module, require);
|
||||
}
|
||||
define(function (require, exports, module) {
|
||||
|
||||
/**
|
||||
* This is a helper function for getting values from parameter/options
|
||||
* objects.
|
||||
*
|
||||
* @param args The object we are extracting values from
|
||||
* @param name The name of the property we are getting.
|
||||
* @param defaultValue An optional value to return if the property is missing
|
||||
* from the object. If this is not specified and the property is missing, an
|
||||
* error will be thrown.
|
||||
*/
|
||||
function getArg(aArgs, aName, aDefaultValue) {
|
||||
if (aName in aArgs) {
|
||||
return aArgs[aName];
|
||||
} else if (arguments.length === 3) {
|
||||
return aDefaultValue;
|
||||
} else {
|
||||
throw new Error('"' + aName + '" is a required argument.');
|
||||
}
|
||||
}
|
||||
exports.getArg = getArg;
|
||||
|
||||
var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.]*)(?::(\d+))?(\S*)$/;
|
||||
var dataUrlRegexp = /^data:.+\,.+$/;
|
||||
|
||||
function urlParse(aUrl) {
|
||||
var match = aUrl.match(urlRegexp);
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
scheme: match[1],
|
||||
auth: match[2],
|
||||
host: match[3],
|
||||
port: match[4],
|
||||
path: match[5]
|
||||
};
|
||||
}
|
||||
exports.urlParse = urlParse;
|
||||
|
||||
function urlGenerate(aParsedUrl) {
|
||||
var url = '';
|
||||
if (aParsedUrl.scheme) {
|
||||
url += aParsedUrl.scheme + ':';
|
||||
}
|
||||
url += '//';
|
||||
if (aParsedUrl.auth) {
|
||||
url += aParsedUrl.auth + '@';
|
||||
}
|
||||
if (aParsedUrl.host) {
|
||||
url += aParsedUrl.host;
|
||||
}
|
||||
if (aParsedUrl.port) {
|
||||
url += ":" + aParsedUrl.port
|
||||
}
|
||||
if (aParsedUrl.path) {
|
||||
url += aParsedUrl.path;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
exports.urlGenerate = urlGenerate;
|
||||
|
||||
/**
|
||||
* Normalizes a path, or the path portion of a URL:
|
||||
*
|
||||
* - Replaces consequtive slashes with one slash.
|
||||
* - Removes unnecessary '.' parts.
|
||||
* - Removes unnecessary '<dir>/..' parts.
|
||||
*
|
||||
* Based on code in the Node.js 'path' core module.
|
||||
*
|
||||
* @param aPath The path or url to normalize.
|
||||
*/
|
||||
function normalize(aPath) {
|
||||
var path = aPath;
|
||||
var url = urlParse(aPath);
|
||||
if (url) {
|
||||
if (!url.path) {
|
||||
return aPath;
|
||||
}
|
||||
path = url.path;
|
||||
}
|
||||
var isAbsolute = (path.charAt(0) === '/');
|
||||
|
||||
var parts = path.split(/\/+/);
|
||||
for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
|
||||
part = parts[i];
|
||||
if (part === '.') {
|
||||
parts.splice(i, 1);
|
||||
} else if (part === '..') {
|
||||
up++;
|
||||
} else if (up > 0) {
|
||||
if (part === '') {
|
||||
// The first part is blank if the path is absolute. Trying to go
|
||||
// above the root is a no-op. Therefore we can remove all '..' parts
|
||||
// directly after the root.
|
||||
parts.splice(i + 1, up);
|
||||
up = 0;
|
||||
} else {
|
||||
parts.splice(i, 2);
|
||||
up--;
|
||||
}
|
||||
}
|
||||
}
|
||||
path = parts.join('/');
|
||||
|
||||
if (path === '') {
|
||||
path = isAbsolute ? '/' : '.';
|
||||
}
|
||||
|
||||
if (url) {
|
||||
url.path = path;
|
||||
return urlGenerate(url);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
exports.normalize = normalize;
|
||||
|
||||
/**
|
||||
* Joins two paths/URLs.
|
||||
*
|
||||
* @param aRoot The root path or URL.
|
||||
* @param aPath The path or URL to be joined with the root.
|
||||
*
|
||||
* - If aPath is a URL or a data URI, aPath is returned, unless aPath is a
|
||||
* scheme-relative URL: Then the scheme of aRoot, if any, is prepended
|
||||
* first.
|
||||
* - Otherwise aPath is a path. If aRoot is a URL, then its path portion
|
||||
* is updated with the result and aRoot is returned. Otherwise the result
|
||||
* is returned.
|
||||
* - If aPath is absolute, the result is aPath.
|
||||
* - Otherwise the two paths are joined with a slash.
|
||||
* - Joining for example 'http://' and 'www.example.com' is also supported.
|
||||
*/
|
||||
function join(aRoot, aPath) {
|
||||
var aPathUrl = urlParse(aPath);
|
||||
var aRootUrl = urlParse(aRoot);
|
||||
if (aRootUrl) {
|
||||
aRoot = aRootUrl.path || '/';
|
||||
}
|
||||
|
||||
// `join(foo, '//www.example.org')`
|
||||
if (aPathUrl && !aPathUrl.scheme) {
|
||||
if (aRootUrl) {
|
||||
aPathUrl.scheme = aRootUrl.scheme;
|
||||
}
|
||||
return urlGenerate(aPathUrl);
|
||||
}
|
||||
|
||||
if (aPathUrl || aPath.match(dataUrlRegexp)) {
|
||||
return aPath;
|
||||
}
|
||||
|
||||
// `join('http://', 'www.example.com')`
|
||||
if (aRootUrl && !aRootUrl.host && !aRootUrl.path) {
|
||||
aRootUrl.host = aPath;
|
||||
return urlGenerate(aRootUrl);
|
||||
}
|
||||
|
||||
var joined = aPath.charAt(0) === '/'
|
||||
? aPath
|
||||
: normalize(aRoot.replace(/\/+$/, '') + '/' + aPath);
|
||||
|
||||
if (aRootUrl) {
|
||||
aRootUrl.path = joined;
|
||||
return urlGenerate(aRootUrl);
|
||||
}
|
||||
return joined;
|
||||
}
|
||||
exports.join = join;
|
||||
|
||||
/**
|
||||
* Because behavior goes wacky when you set `__proto__` on objects, we
|
||||
* have to prefix all the strings in our set with an arbitrary character.
|
||||
*
|
||||
* See https://github.com/mozilla/source-map/pull/31 and
|
||||
* https://github.com/mozilla/source-map/issues/30
|
||||
*
|
||||
* @param String aStr
|
||||
*/
|
||||
function toSetString(aStr) {
|
||||
return '$' + aStr;
|
||||
}
|
||||
exports.toSetString = toSetString;
|
||||
|
||||
function fromSetString(aStr) {
|
||||
return aStr.substr(1);
|
||||
}
|
||||
exports.fromSetString = fromSetString;
|
||||
|
||||
function relative(aRoot, aPath) {
|
||||
aRoot = aRoot.replace(/\/$/, '');
|
||||
|
||||
var url = urlParse(aRoot);
|
||||
if (aPath.charAt(0) == "/" && url && url.path == "/") {
|
||||
return aPath.slice(1);
|
||||
}
|
||||
|
||||
return aPath.indexOf(aRoot + '/') === 0
|
||||
? aPath.substr(aRoot.length + 1)
|
||||
: aPath;
|
||||
}
|
||||
exports.relative = relative;
|
||||
|
||||
function strcmp(aStr1, aStr2) {
|
||||
var s1 = aStr1 || "";
|
||||
var s2 = aStr2 || "";
|
||||
return (s1 > s2) - (s1 < s2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparator between two mappings where the original positions are compared.
|
||||
*
|
||||
* Optionally pass in `true` as `onlyCompareGenerated` to consider two
|
||||
* mappings with the same original source/line/column, but different generated
|
||||
* line and column the same. Useful when searching for a mapping with a
|
||||
* stubbed out mapping.
|
||||
*/
|
||||
function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
|
||||
var cmp;
|
||||
|
||||
cmp = strcmp(mappingA.source, mappingB.source);
|
||||
if (cmp) {
|
||||
return cmp;
|
||||
}
|
||||
|
||||
cmp = mappingA.originalLine - mappingB.originalLine;
|
||||
if (cmp) {
|
||||
return cmp;
|
||||
}
|
||||
|
||||
cmp = mappingA.originalColumn - mappingB.originalColumn;
|
||||
if (cmp || onlyCompareOriginal) {
|
||||
return cmp;
|
||||
}
|
||||
|
||||
cmp = strcmp(mappingA.name, mappingB.name);
|
||||
if (cmp) {
|
||||
return cmp;
|
||||
}
|
||||
|
||||
cmp = mappingA.generatedLine - mappingB.generatedLine;
|
||||
if (cmp) {
|
||||
return cmp;
|
||||
}
|
||||
|
||||
return mappingA.generatedColumn - mappingB.generatedColumn;
|
||||
};
|
||||
exports.compareByOriginalPositions = compareByOriginalPositions;
|
||||
|
||||
/**
|
||||
* Comparator between two mappings where the generated positions are
|
||||
* compared.
|
||||
*
|
||||
* Optionally pass in `true` as `onlyCompareGenerated` to consider two
|
||||
* mappings with the same generated line and column, but different
|
||||
* source/name/original line and column the same. Useful when searching for a
|
||||
* mapping with a stubbed out mapping.
|
||||
*/
|
||||
function compareByGeneratedPositions(mappingA, mappingB, onlyCompareGenerated) {
|
||||
var cmp;
|
||||
|
||||
cmp = mappingA.generatedLine - mappingB.generatedLine;
|
||||
if (cmp) {
|
||||
return cmp;
|
||||
}
|
||||
|
||||
cmp = mappingA.generatedColumn - mappingB.generatedColumn;
|
||||
if (cmp || onlyCompareGenerated) {
|
||||
return cmp;
|
||||
}
|
||||
|
||||
cmp = strcmp(mappingA.source, mappingB.source);
|
||||
if (cmp) {
|
||||
return cmp;
|
||||
}
|
||||
|
||||
cmp = mappingA.originalLine - mappingB.originalLine;
|
||||
if (cmp) {
|
||||
return cmp;
|
||||
}
|
||||
|
||||
cmp = mappingA.originalColumn - mappingB.originalColumn;
|
||||
if (cmp) {
|
||||
return cmp;
|
||||
}
|
||||
|
||||
return strcmp(mappingA.name, mappingB.name);
|
||||
};
|
||||
exports.compareByGeneratedPositions = compareByGeneratedPositions;
|
||||
|
||||
});
|
||||
179
node_modules/swig/node_modules/source-map/package.json
generated
vendored
Normal file
179
node_modules/swig/node_modules/source-map/package.json
generated
vendored
Normal file
@@ -0,0 +1,179 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"source-map@0.1.34",
|
||||
"/home/mitchell/Desktop/test-mywebsite/mywebsite/node_modules/swig/node_modules/uglify-js"
|
||||
]
|
||||
],
|
||||
"_from": "source-map@0.1.34",
|
||||
"_id": "source-map@0.1.34",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/swig/source-map",
|
||||
"_npmUser": {
|
||||
"email": "fitzgen@gmail.com",
|
||||
"name": "nickfitzgerald"
|
||||
},
|
||||
"_npmVersion": "1.4.9",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "source-map",
|
||||
"raw": "source-map@0.1.34",
|
||||
"rawSpec": "0.1.34",
|
||||
"scope": null,
|
||||
"spec": "0.1.34",
|
||||
"type": "version"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/swig/uglify-js"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/source-map/-/source-map-0.1.34.tgz",
|
||||
"_shasum": "a7cfe89aec7b1682c3b198d0acfb47d7d090566b",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "source-map@0.1.34",
|
||||
"_where": "/home/mitchell/Desktop/test-mywebsite/mywebsite/node_modules/swig/node_modules/uglify-js",
|
||||
"author": {
|
||||
"email": "nfitzgerald@mozilla.com",
|
||||
"name": "Nick Fitzgerald"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/mozilla/source-map/issues"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Conrad Irwin",
|
||||
"email": "conrad.irwin@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Tobias Koppers",
|
||||
"email": "tobias.koppers@googlemail.com"
|
||||
},
|
||||
{
|
||||
"name": "Stephen Crane",
|
||||
"email": "scrane@mozilla.com"
|
||||
},
|
||||
{
|
||||
"name": "Ryan Seddon",
|
||||
"email": "seddon.ryan@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Miles Elam",
|
||||
"email": "miles.elam@deem.com"
|
||||
},
|
||||
{
|
||||
"name": "Mihai Bazon",
|
||||
"email": "mihai.bazon@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Michael Ficarra",
|
||||
"email": "github.public.email@michael.ficarra.me"
|
||||
},
|
||||
{
|
||||
"name": "Todd Wolfson",
|
||||
"email": "todd@twolfson.com"
|
||||
},
|
||||
{
|
||||
"name": "Alexander Solovyov",
|
||||
"email": "alexander@solovyov.net"
|
||||
},
|
||||
{
|
||||
"name": "Felix Gnass",
|
||||
"email": "fgnass@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Duncan Beevers",
|
||||
"email": "duncan@dweebd.com"
|
||||
},
|
||||
{
|
||||
"name": "usrbincc",
|
||||
"email": "usrbincc@yahoo.com"
|
||||
},
|
||||
{
|
||||
"name": "David Glasser",
|
||||
"email": "glasser@davidglasser.net"
|
||||
},
|
||||
{
|
||||
"name": "Chase Douglas",
|
||||
"email": "chase@newrelic.com"
|
||||
},
|
||||
{
|
||||
"name": "Evan Wallace",
|
||||
"email": "evan.exe@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Heather Arthur",
|
||||
"email": "fayearthur@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Hugh Kennedy",
|
||||
"email": "hughskennedy@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "David Glasser",
|
||||
"email": "glasser@davidglasser.net"
|
||||
},
|
||||
{
|
||||
"name": "Simon Lydell",
|
||||
"email": "simon.lydell@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Jmeas Smith",
|
||||
"email": "jellyes2@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Michael Z Goddard",
|
||||
"email": "mzgoddard@gmail.com"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"amdefine": ">=0.0.4"
|
||||
},
|
||||
"description": "Generates and consumes source maps",
|
||||
"devDependencies": {
|
||||
"dryice": ">=0.4.8"
|
||||
},
|
||||
"directories": {
|
||||
"lib": "./lib"
|
||||
},
|
||||
"dist": {
|
||||
"shasum": "a7cfe89aec7b1682c3b198d0acfb47d7d090566b",
|
||||
"tarball": "http://registry.npmjs.org/source-map/-/source-map-0.1.34.tgz"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.8.0"
|
||||
},
|
||||
"homepage": "https://github.com/mozilla/source-map",
|
||||
"licenses": [
|
||||
{
|
||||
"type": "BSD",
|
||||
"url": "http://opensource.org/licenses/BSD-3-Clause"
|
||||
}
|
||||
],
|
||||
"main": "./lib/source-map.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "mozilla-devtools",
|
||||
"email": "mozilla-developer-tools@googlegroups.com"
|
||||
},
|
||||
{
|
||||
"name": "mozilla",
|
||||
"email": "dherman@mozilla.com"
|
||||
},
|
||||
{
|
||||
"name": "nickfitzgerald",
|
||||
"email": "fitzgen@gmail.com"
|
||||
}
|
||||
],
|
||||
"name": "source-map",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/mozilla/source-map.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "node Makefile.dryice.js",
|
||||
"test": "node test/run-tests.js"
|
||||
},
|
||||
"version": "0.1.34"
|
||||
}
|
||||
62
node_modules/swig/node_modules/source-map/test/run-tests.js
generated
vendored
Executable file
62
node_modules/swig/node_modules/source-map/test/run-tests.js
generated
vendored
Executable file
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env node
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
var assert = require('assert');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var util = require('./source-map/util');
|
||||
|
||||
function run(tests) {
|
||||
var total = 0;
|
||||
var passed = 0;
|
||||
|
||||
for (var i = 0; i < tests.length; i++) {
|
||||
for (var k in tests[i].testCase) {
|
||||
if (/^test/.test(k)) {
|
||||
total++;
|
||||
try {
|
||||
tests[i].testCase[k](assert, util);
|
||||
passed++;
|
||||
}
|
||||
catch (e) {
|
||||
console.log('FAILED ' + tests[i].name + ': ' + k + '!');
|
||||
console.log(e.stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log('');
|
||||
console.log(passed + ' / ' + total + ' tests passed.');
|
||||
console.log('');
|
||||
|
||||
return total - passed;
|
||||
}
|
||||
|
||||
function isTestFile(f) {
|
||||
var testToRun = process.argv[2];
|
||||
return testToRun
|
||||
? path.basename(testToRun) === f
|
||||
: /^test\-.*?\.js/.test(f);
|
||||
}
|
||||
|
||||
function toModule(f) {
|
||||
return './source-map/' + f.replace(/\.js$/, '');
|
||||
}
|
||||
|
||||
var requires = fs.readdirSync(path.join(__dirname, 'source-map'))
|
||||
.filter(isTestFile)
|
||||
.map(toModule);
|
||||
|
||||
var code = run(requires.map(require).map(function (mod, i) {
|
||||
return {
|
||||
name: requires[i],
|
||||
testCase: mod
|
||||
};
|
||||
}));
|
||||
|
||||
process.exit(code);
|
||||
26
node_modules/swig/node_modules/source-map/test/source-map/test-api.js
generated
vendored
Normal file
26
node_modules/swig/node_modules/source-map/test/source-map/test-api.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2012 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
if (typeof define !== 'function') {
|
||||
var define = require('amdefine')(module, require);
|
||||
}
|
||||
define(function (require, exports, module) {
|
||||
|
||||
var sourceMap;
|
||||
try {
|
||||
sourceMap = require('../../lib/source-map');
|
||||
} catch (e) {
|
||||
sourceMap = {};
|
||||
Components.utils.import('resource:///modules/devtools/SourceMap.jsm', sourceMap);
|
||||
}
|
||||
|
||||
exports['test that the api is properly exposed in the top level'] = function (assert, util) {
|
||||
assert.equal(typeof sourceMap.SourceMapGenerator, "function");
|
||||
assert.equal(typeof sourceMap.SourceMapConsumer, "function");
|
||||
assert.equal(typeof sourceMap.SourceNode, "function");
|
||||
};
|
||||
|
||||
});
|
||||
104
node_modules/swig/node_modules/source-map/test/source-map/test-array-set.js
generated
vendored
Normal file
104
node_modules/swig/node_modules/source-map/test/source-map/test-array-set.js
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
if (typeof define !== 'function') {
|
||||
var define = require('amdefine')(module, require);
|
||||
}
|
||||
define(function (require, exports, module) {
|
||||
|
||||
var ArraySet = require('../../lib/source-map/array-set').ArraySet;
|
||||
|
||||
function makeTestSet() {
|
||||
var set = new ArraySet();
|
||||
for (var i = 0; i < 100; i++) {
|
||||
set.add(String(i));
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
exports['test .has() membership'] = function (assert, util) {
|
||||
var set = makeTestSet();
|
||||
for (var i = 0; i < 100; i++) {
|
||||
assert.ok(set.has(String(i)));
|
||||
}
|
||||
};
|
||||
|
||||
exports['test .indexOf() elements'] = function (assert, util) {
|
||||
var set = makeTestSet();
|
||||
for (var i = 0; i < 100; i++) {
|
||||
assert.strictEqual(set.indexOf(String(i)), i);
|
||||
}
|
||||
};
|
||||
|
||||
exports['test .at() indexing'] = function (assert, util) {
|
||||
var set = makeTestSet();
|
||||
for (var i = 0; i < 100; i++) {
|
||||
assert.strictEqual(set.at(i), String(i));
|
||||
}
|
||||
};
|
||||
|
||||
exports['test creating from an array'] = function (assert, util) {
|
||||
var set = ArraySet.fromArray(['foo', 'bar', 'baz', 'quux', 'hasOwnProperty']);
|
||||
|
||||
assert.ok(set.has('foo'));
|
||||
assert.ok(set.has('bar'));
|
||||
assert.ok(set.has('baz'));
|
||||
assert.ok(set.has('quux'));
|
||||
assert.ok(set.has('hasOwnProperty'));
|
||||
|
||||
assert.strictEqual(set.indexOf('foo'), 0);
|
||||
assert.strictEqual(set.indexOf('bar'), 1);
|
||||
assert.strictEqual(set.indexOf('baz'), 2);
|
||||
assert.strictEqual(set.indexOf('quux'), 3);
|
||||
|
||||
assert.strictEqual(set.at(0), 'foo');
|
||||
assert.strictEqual(set.at(1), 'bar');
|
||||
assert.strictEqual(set.at(2), 'baz');
|
||||
assert.strictEqual(set.at(3), 'quux');
|
||||
};
|
||||
|
||||
exports['test that you can add __proto__; see github issue #30'] = function (assert, util) {
|
||||
var set = new ArraySet();
|
||||
set.add('__proto__');
|
||||
assert.ok(set.has('__proto__'));
|
||||
assert.strictEqual(set.at(0), '__proto__');
|
||||
assert.strictEqual(set.indexOf('__proto__'), 0);
|
||||
};
|
||||
|
||||
exports['test .fromArray() with duplicates'] = function (assert, util) {
|
||||
var set = ArraySet.fromArray(['foo', 'foo']);
|
||||
assert.ok(set.has('foo'));
|
||||
assert.strictEqual(set.at(0), 'foo');
|
||||
assert.strictEqual(set.indexOf('foo'), 0);
|
||||
assert.strictEqual(set.toArray().length, 1);
|
||||
|
||||
set = ArraySet.fromArray(['foo', 'foo'], true);
|
||||
assert.ok(set.has('foo'));
|
||||
assert.strictEqual(set.at(0), 'foo');
|
||||
assert.strictEqual(set.at(1), 'foo');
|
||||
assert.strictEqual(set.indexOf('foo'), 0);
|
||||
assert.strictEqual(set.toArray().length, 2);
|
||||
};
|
||||
|
||||
exports['test .add() with duplicates'] = function (assert, util) {
|
||||
var set = new ArraySet();
|
||||
set.add('foo');
|
||||
|
||||
set.add('foo');
|
||||
assert.ok(set.has('foo'));
|
||||
assert.strictEqual(set.at(0), 'foo');
|
||||
assert.strictEqual(set.indexOf('foo'), 0);
|
||||
assert.strictEqual(set.toArray().length, 1);
|
||||
|
||||
set.add('foo', true);
|
||||
assert.ok(set.has('foo'));
|
||||
assert.strictEqual(set.at(0), 'foo');
|
||||
assert.strictEqual(set.at(1), 'foo');
|
||||
assert.strictEqual(set.indexOf('foo'), 0);
|
||||
assert.strictEqual(set.toArray().length, 2);
|
||||
};
|
||||
|
||||
});
|
||||
24
node_modules/swig/node_modules/source-map/test/source-map/test-base64-vlq.js
generated
vendored
Normal file
24
node_modules/swig/node_modules/source-map/test/source-map/test-base64-vlq.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
if (typeof define !== 'function') {
|
||||
var define = require('amdefine')(module, require);
|
||||
}
|
||||
define(function (require, exports, module) {
|
||||
|
||||
var base64VLQ = require('../../lib/source-map/base64-vlq');
|
||||
|
||||
exports['test normal encoding and decoding'] = function (assert, util) {
|
||||
var result;
|
||||
for (var i = -255; i < 256; i++) {
|
||||
result = base64VLQ.decode(base64VLQ.encode(i));
|
||||
assert.ok(result);
|
||||
assert.equal(result.value, i);
|
||||
assert.equal(result.rest, "");
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
35
node_modules/swig/node_modules/source-map/test/source-map/test-base64.js
generated
vendored
Normal file
35
node_modules/swig/node_modules/source-map/test/source-map/test-base64.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
if (typeof define !== 'function') {
|
||||
var define = require('amdefine')(module, require);
|
||||
}
|
||||
define(function (require, exports, module) {
|
||||
|
||||
var base64 = require('../../lib/source-map/base64');
|
||||
|
||||
exports['test out of range encoding'] = function (assert, util) {
|
||||
assert.throws(function () {
|
||||
base64.encode(-1);
|
||||
});
|
||||
assert.throws(function () {
|
||||
base64.encode(64);
|
||||
});
|
||||
};
|
||||
|
||||
exports['test out of range decoding'] = function (assert, util) {
|
||||
assert.throws(function () {
|
||||
base64.decode('=');
|
||||
});
|
||||
};
|
||||
|
||||
exports['test normal encoding and decoding'] = function (assert, util) {
|
||||
for (var i = 0; i < 64; i++) {
|
||||
assert.equal(base64.decode(base64.encode(i)), i);
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user