Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1049)

Unified Diff: node_modules/vulcanize/node_modules/update-notifier/node_modules/configstore/node_modules/js-yaml/lib/js-yaml/type/js/function.js

Issue 800513006: Added vulcanize under third_party/npm_modules (Closed) Base URL: https://chromium.googlesource.com/infra/third_party/npm_modules.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: node_modules/vulcanize/node_modules/update-notifier/node_modules/configstore/node_modules/js-yaml/lib/js-yaml/type/js/function.js
diff --git a/node_modules/vulcanize/node_modules/update-notifier/node_modules/configstore/node_modules/js-yaml/lib/js-yaml/type/js/function.js b/node_modules/vulcanize/node_modules/update-notifier/node_modules/configstore/node_modules/js-yaml/lib/js-yaml/type/js/function.js
new file mode 100644
index 0000000000000000000000000000000000000000..65dcf7f8a9f9603ab26a55bb4bd22d7f8c6a802c
--- /dev/null
+++ b/node_modules/vulcanize/node_modules/update-notifier/node_modules/configstore/node_modules/js-yaml/lib/js-yaml/type/js/function.js
@@ -0,0 +1,71 @@
+'use strict';
+
+
+var esprima;
+
+// Browserified version does not have esprima
+//
+// 1. For node.js just require module as deps
+// 2. For browser try to require mudule via external AMD system.
+// If not found - try to fallback to window.esprima. If not
+// found too - then fail to parse.
+//
+try {
+ esprima = require('esprima');
+} catch (_) {
+ /*global window */
+ if (window) { esprima = window.esprima; }
+}
+
+
+var Type = require('../../type');
+
+
+function resolveJavascriptFunction(state) {
+ /*jslint evil:true*/
+
+ try {
+ var source = '(' + state.result + ')',
+ ast = esprima.parse(source, { range: true }),
+ params = [],
+ body;
+
+ if ('Program' !== ast.type ||
+ 1 !== ast.body.length ||
+ 'ExpressionStatement' !== ast.body[0].type ||
+ 'FunctionExpression' !== ast.body[0].expression.type) {
+ return false;
+ }
+
+ ast.body[0].expression.params.forEach(function (param) {
+ params.push(param.name);
+ });
+
+ body = ast.body[0].expression.body.range;
+
+ // Esprima's ranges include the first '{' and the last '}' characters on
+ // function expressions. So cut them out.
+ state.result = new Function(params, source.slice(body[0]+1, body[1]-1));
+ return true;
+ } catch (err) {
+ return false;
+ }
+}
+
+
+function representJavascriptFunction(object /*, style*/) {
+ return object.toString();
+}
+
+
+function isFunction(object) {
+ return '[object Function]' === Object.prototype.toString.call(object);
+}
+
+
+module.exports = new Type('tag:yaml.org,2002:js/function', {
+ loadKind: 'scalar',
+ loadResolver: resolveJavascriptFunction,
+ dumpPredicate: isFunction,
+ dumpRepresenter: representJavascriptFunction
+});

Powered by Google App Engine
This is Rietveld 408576698