chore: source-ref add React.Fragment support

ignore it
pull/81/head
moonrailgun 3 years ago
parent 8d6db59aee
commit 01b3c11bb9

@ -2,9 +2,9 @@
"name": "rollup-plugin-source-ref",
"version": "1.0.0",
"description": "",
"main": "dist/index.js",
"main": "lib/index.js",
"files": [
"dist"
"lib"
],
"scripts": {
"build": "tsc",

@ -2,7 +2,13 @@ import type { Plugin } from 'rollup';
import { parse } from '@babel/parser';
import traverse from '@babel/traverse';
import generate from '@babel/generator';
import { jsxAttribute, jsxIdentifier, stringLiteral } from '@babel/types';
import {
isJSXIdentifier,
isJSXMemberExpression,
jsxAttribute,
jsxIdentifier,
stringLiteral,
} from '@babel/types';
const TRACE_ID = 'data-source';
@ -28,6 +34,17 @@ export default function sourceRef(): Plugin {
return;
}
const name = path.node.name;
if (isJSXIdentifier(name) && name.name === 'Fragment') {
return;
}
if (
isJSXMemberExpression(name) &&
name.property.name === 'Fragment'
) {
return;
}
const line = location.start.line;
const col = location.start.column;

@ -1,6 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"outDir": "lib",
"module": "commonjs",
"target": "ES5",
"lib": ["ESNext"],

@ -2,9 +2,9 @@
"name": "source-ref-loader",
"version": "1.0.0",
"description": "",
"main": "dist/index.js",
"main": "lib/index.js",
"files": [
"dist"
"lib"
],
"scripts": {
"build": "tsc",

@ -2,7 +2,13 @@ import type { LoaderContext } from 'webpack';
import { parse } from '@babel/parser';
import traverse from '@babel/traverse';
import generate from '@babel/generator';
import { jsxAttribute, jsxIdentifier, stringLiteral } from '@babel/types';
import {
isJSXIdentifier,
isJSXMemberExpression,
jsxAttribute,
jsxIdentifier,
stringLiteral,
} from '@babel/types';
const TRACE_ID = 'data-source';
@ -37,6 +43,14 @@ async function loader(this: LoaderContext<any>, source: string): Promise<void> {
return;
}
const name = path.node.name;
if (isJSXIdentifier(name) && name.name === 'Fragment') {
return;
}
if (isJSXMemberExpression(name) && name.property.name === 'Fragment') {
return;
}
const line = location.start.line;
const col = location.start.column;

@ -9,6 +9,8 @@ export const tsx = {
'/src/foo.tsx': `
export const HelloWorld = <><div>hello world</div></>;
export const HelloWorld2 = <React.Fragment><div>hello world</div></React.Fragment>;
export const HelloWorld3 = <Fragment><div>hello world</div></Fragment>;
export default class Foo {
render() {
return <div className="class-name">content</div>

@ -5,12 +5,13 @@ import { configureLoader } from './utils';
async function test() {
const built = await build(fixtures.tsx, (config) => {
configureLoader(config);
});
console.log(built.stats.endTime - built.stats.startTime);
console.log('configureLoader(config);', config.module.rules);
});
console.log(built.stats.compilation.errors.length);
console.log(built.stats.compilation.errors);
console.log('usage:', built.stats.endTime - built.stats.startTime, 'ms');
console.log('errors:', built.stats.compilation.errors.length);
// console.log(built.stats.compilation.errors);
}
test();

@ -1,14 +1,18 @@
import type { Configuration } from 'webpack';
import type { DefaultWebpackConfig } from 'webpack-test-utils';
const loaderPath = require.resolve('../src/index.ts');
export function configureLoader(config: Configuration) {
export function configureLoader(config: DefaultWebpackConfig & Configuration) {
config.resolveLoader.alias = {
'source-pointer-loader': loaderPath,
'source-ref-loader': loaderPath,
};
config.module.rules.push({
test: /\.tsx$/,
loader: 'source-pointer-loader',
loader: 'source-ref-loader',
options: {
available: true,
},
});
}

@ -1,6 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"outDir": "lib",
"module": "commonjs",
"target": "ES2018",

Loading…
Cancel
Save