mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-09-30 01:07:01 +08:00
This also adds CC-BY-4.0 to the list of accepted licenses. DISABLE_THIRD_PARTY_CHECK=update dependencies Bug: chromium:1083142 Change-Id: I8612de2fba52dae32eeb71af79d5aacfde52142b Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2220097 Reviewed-by: Paul Lewis <aerotwist@chromium.org> Commit-Queue: Mathias Bynens <mathias@chromium.org>
35 lines
940 B
JavaScript
35 lines
940 B
JavaScript
"use strict";
|
|
|
|
const parser = require("./parser");
|
|
const processor = require("./processor");
|
|
const getLang = require("./get-lang");
|
|
const normalOpts = require("./normal-opts");
|
|
|
|
function getSyntax (opts, source) {
|
|
const rules = opts.syntax && opts.syntax.config && opts.syntax.config.rules;
|
|
const file = opts.from || "";
|
|
return (rules && rules.find(
|
|
rule => rule.test.test ? rule.test.test(file) : rule.test(file, source)
|
|
)) || getLang(file, source) || {
|
|
lang: "css",
|
|
};
|
|
}
|
|
|
|
function parse (source, opts) {
|
|
source = source.toString();
|
|
opts = normalOpts(opts, this);
|
|
const syntax = getSyntax(opts, source);
|
|
const syntaxOpts = Object.assign({}, opts, syntax.opts);
|
|
let root;
|
|
if (syntax.extract) {
|
|
root = processor(source, syntax.extract, syntaxOpts);
|
|
root.source.lang = syntax.extract;
|
|
} else {
|
|
root = parser(source, syntax.lang, syntaxOpts);
|
|
root.source.lang = syntax.lang;
|
|
}
|
|
return root;
|
|
}
|
|
|
|
module.exports = parse;
|