Skip to content

Commit

Permalink
feat: add platform-loader (#480)
Browse files Browse the repository at this point in the history
* feat: add platform-loader

* chore: lint

* Update package.json

Co-authored-by: 水澜 <shuilan.cj@taobao.com>
  • Loading branch information
SoloJiang and chenjun1011 authored Nov 12, 2020
1 parent 01d61b4 commit b47e122
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 661 deletions.
3 changes: 3 additions & 0 deletions packages/platform-loader/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# rax-platform-loader [![npm](https://img.shields.io/npm/v/rax-platform-loader.svg)](https://www.npmjs.com/package/rax-platform-loader)

For helping remove other platform code.
24 changes: 24 additions & 0 deletions packages/platform-loader/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "rax-platform-loader",
"version": "1.0.0",
"description": "rax platform loader for helping remove other platform code",
"license": "BSD-3-Clause",
"main": "lib/index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/raxjs/rax-scripts.git"
},
"bugs": {
"url": "https://github.com/raxjs/rax-scripts/issues"
},
"homepage": "https://github.com/raxjs/rax-scripts/tree/master/packages/platform-loader#readme",
"dependencies": {
"@babel/code-frame": "^7.5.5",
"@babel/generator": "^7.6.4",
"@babel/parser": "^7.6.4",
"@babel/traverse": "^7.6.3",
"@babel/types": "^7.6.3",
"loader-utils": "^1.1.0",
"source-map": "^0.7.3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const babelParser = require('@babel/parser');
const traverse = require('@babel/traverse').default;
const types = require('@babel/types');
const generate = require('@babel/generator').default;
const codeFrame = require('@babel/code-frame').default;
const { codeFrameColumns } = require('@babel/code-frame').default;

module.exports = function traverseImport(options, inputSource, sourceMapOption) {
let specified; // Collector import specifiers
Expand Down Expand Up @@ -102,17 +102,21 @@ module.exports = function traverseImport(options, inputSource, sourceMapOption)
});
} catch (err) {
if (err instanceof SyntaxError) {
err.lineNumber = err.loc.line;
err.column = err.loc.column + 1;
const location = {
start: {
line: err.loc.line,
column: err.loc.column + 1
}
};

// remove trailing "(LINE:COLUMN)" acorn message and add in esprima syntax error message start
err.message = `Line ${err.lineNumber}: ${err.message.replace(/ \((\d+):(\d+)\)$/, '')
// add codeframe
console.log(`Line ${err.lineNumber}: ${err.message.replace(/ \((\d+):(\d+)\)$/, '')
// add codeframe
}\n\n${
codeFrame(inputSource, err.lineNumber, err.column, { highlightCode: true })}`;
codeFrameColumns(inputSource, location, { highlightCode: true })}`);
} else {
console.log(err);
}

throw err;
}

traverse(ast, {
Expand Down
File renamed without changes.
3 changes: 0 additions & 3 deletions packages/rax-compile-config/README.md

This file was deleted.

51 changes: 0 additions & 51 deletions packages/rax-compile-config/package.json

This file was deleted.

121 changes: 0 additions & 121 deletions packages/rax-compile-config/src/getBabelConfig.js

This file was deleted.

27 changes: 0 additions & 27 deletions packages/rax-compile-config/src/getRouteName.js

This file was deleted.

45 changes: 0 additions & 45 deletions packages/rax-compile-config/src/handleWebpackErr.js

This file was deleted.

Loading

0 comments on commit b47e122

Please sign in to comment.