mirror of https://github.com/status-im/metro.git
Use `jest-docblock`
Summary: Remove our internal docbloc module and use `jest-docblock` instead. The development server is using `jest-haste-map` exclusively, which in turn relies on `jest-docblock`, which differs slightly from our own docblock module. Depending on only one version greatly reduces the number of edge cases Reviewed By: cpojer Differential Revision: D5328472 fbshipit-source-id: 4a31d8159519e01a83fda04b76e8f14f0beb16af
This commit is contained in:
parent
f7ad406c23
commit
429c1e8032
|
@ -30,6 +30,7 @@
|
|||
"fbjs": "0.8.12",
|
||||
"graceful-fs": "^4.1.3",
|
||||
"image-size": "^0.3.5",
|
||||
"jest-docblock": "^20.0.3",
|
||||
"jest-haste-map": "^20.0.4",
|
||||
"json-stable-stringify": "^1.0.1",
|
||||
"json5": "^0.4.0",
|
||||
|
|
|
@ -16,7 +16,7 @@ const JsFileWrapping = require('./JsFileWrapping');
|
|||
const asyncify = require('async/asyncify');
|
||||
const collectDependencies = require('./collect-dependencies');
|
||||
const defaults = require('../../defaults');
|
||||
const docblock = require('../../node-haste/DependencyGraph/docblock');
|
||||
const docblock = require('jest-docblock');
|
||||
const generate = require('./generate');
|
||||
const path = require('path');
|
||||
const series = require('async/series');
|
||||
|
@ -99,7 +99,7 @@ function transformModule(
|
|||
);
|
||||
});
|
||||
|
||||
const annotations = docblock.parseAsObject(docblock.extract(code));
|
||||
const annotations = docblock.parse(docblock.extract(code));
|
||||
|
||||
callback(null, {
|
||||
type: 'code',
|
||||
|
|
|
@ -1,83 +0,0 @@
|
|||
/**
|
||||
* 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.
|
||||
*
|
||||
* @flow
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var docblockRe = /^\s*(\/\*\*(.|\r?\n)*?\*\/)/;
|
||||
|
||||
var ltrimRe = /^\s*/;
|
||||
/**
|
||||
* @param {String} contents
|
||||
* @return {String}
|
||||
*/
|
||||
function extract(contents: string): string {
|
||||
var match = contents.match(docblockRe);
|
||||
if (match) {
|
||||
return match[0].replace(ltrimRe, '') || '';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
var commentStartRe = /^\/\*\*/;
|
||||
var commentEndRe = /\*\/$/;
|
||||
var wsRe = /[\t ]+/g;
|
||||
var stringStartRe = /(\r?\n|^) *\*/g;
|
||||
var multilineRe = /(?:^|\r?\n) *(@[^\r\n]*?) *\r?\n *([^@\r\n\s][^@\r\n]+?) *\r?\n/g;
|
||||
var propertyRe = /(?:^|\r?\n) *@(\S+) *([^\r\n]*)/g;
|
||||
|
||||
/**
|
||||
* @param {String} contents
|
||||
* @return {Array}
|
||||
*/
|
||||
function parse(docblock: string): Array<[string, string]> {
|
||||
docblock = docblock
|
||||
.replace(commentStartRe, '')
|
||||
.replace(commentEndRe, '')
|
||||
.replace(wsRe, ' ')
|
||||
.replace(stringStartRe, '$1');
|
||||
|
||||
// Normalize multi-line directives
|
||||
var prev = '';
|
||||
while (prev !== docblock) {
|
||||
prev = docblock;
|
||||
docblock = docblock.replace(multilineRe, '\n$1 $2\n');
|
||||
}
|
||||
docblock = docblock.trim();
|
||||
|
||||
var result = [];
|
||||
var match;
|
||||
while ((match = propertyRe.exec(docblock))) {
|
||||
result.push([match[1], match[2].trim()]);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as parse but returns an object of prop: value instead of array of paris
|
||||
* If a property appers more than once the last one will be returned
|
||||
*
|
||||
* @param {String} contents
|
||||
* @return {Object}
|
||||
*/
|
||||
function parseAsObject(docblock: string): {[string]: string} {
|
||||
var pairs = parse(docblock);
|
||||
var result = {};
|
||||
for (var i = 0; i < pairs.length; i++) {
|
||||
result[pairs[i][0]] = pairs[i][1];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
exports.extract = extract;
|
||||
exports.parse = parse;
|
||||
exports.parseAsObject = parseAsObject;
|
|
@ -13,7 +13,7 @@
|
|||
'use strict';
|
||||
|
||||
const crypto = require('crypto');
|
||||
const docblock = require('./DependencyGraph/docblock');
|
||||
const docblock = require('jest-docblock');
|
||||
const fs = require('fs');
|
||||
const invariant = require('fbjs/lib/invariant');
|
||||
const isAbsolutePath = require('absolute-path');
|
||||
|
@ -209,7 +209,7 @@ class Module {
|
|||
|
||||
_readDocBlock(): DocBlock {
|
||||
if (this._docBlock == null) {
|
||||
this._docBlock = docblock.parseAsObject(this._readSourceCode());
|
||||
this._docBlock = docblock.parse(docblock.extract(this._readSourceCode()));
|
||||
}
|
||||
return this._docBlock;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue