2015-03-23 17:55:49 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
2015-03-10 20:55:54 +00:00
|
|
|
|
|
|
|
/*global exports:true*/
|
|
|
|
/*jslint node:true*/
|
2015-03-26 18:14:54 +00:00
|
|
|
'use strict';
|
2015-03-10 20:55:54 +00:00
|
|
|
|
|
|
|
var util = require('util');
|
|
|
|
|
|
|
|
var Syntax = require('esprima-fb').Syntax;
|
|
|
|
var utils = require('jstransform/src/utils');
|
|
|
|
|
|
|
|
// Top level file pragmas that must not exist for the meta transform to
|
|
|
|
// be applied.
|
|
|
|
var mustNotHave = [
|
|
|
|
'nosourcemeta',
|
|
|
|
];
|
|
|
|
|
|
|
|
function shouldTraverseFile(state, pragmas) {
|
|
|
|
if (state.g.sourcemeta === undefined) {
|
|
|
|
var notHaves = true;
|
|
|
|
mustNotHave.forEach(function (value) {
|
|
|
|
notHaves = notHaves && !(value in pragmas);
|
|
|
|
});
|
|
|
|
state.g.sourcemeta = notHaves;
|
|
|
|
}
|
|
|
|
return state.g.sourcemeta;
|
|
|
|
}
|
|
|
|
|
|
|
|
var shouldTransformFile = shouldTraverseFile;
|
|
|
|
|
|
|
|
function shouldTransformFunction(node, state, pragmas, params) /*bool*/ {
|
|
|
|
if (!shouldTransformFile(state, pragmas)) {
|
|
|
|
throw new Error(
|
|
|
|
'shouldTransformFunction should not be called if shouldTransformFile ' +
|
|
|
|
'fails'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function wrapsBody() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function annotates() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.shouldTransformFile = shouldTransformFile;
|
|
|
|
exports.shouldTraverseFile = shouldTraverseFile;
|
|
|
|
exports.shouldTransformFunction = shouldTransformFunction;
|
|
|
|
exports.wrapsBody = wrapsBody;
|
|
|
|
exports.annotates = annotates;
|
|
|
|
exports.name = 'sourcemeta';
|