forked from nksaraf/vinxi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(changeset): use better parser for typescript/jsx in directives
- Loading branch information
Showing
14 changed files
with
981 additions
and
778 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@vinxi/plugin-directives": patch | ||
--- | ||
|
||
use better parser for typescript/jsx in directives |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parse = exports.parser = void 0; | ||
var tslib_1 = require("tslib"); | ||
var _babel_options_1 = tslib_1.__importDefault(require("recast/parsers/_babel_options")); | ||
// Prefer the new @babel/parser package, but fall back to babylon if | ||
// that's what's available. | ||
exports.parser = (function () { | ||
try { | ||
return require("@babel/parser"); | ||
} catch (_a) { | ||
try { | ||
return require("babylon"); | ||
} catch (_b) { | ||
throw new Error( | ||
"Install @babel/parser to use the `typescript`, `flow`, or `babel` parsers", | ||
); | ||
} | ||
} | ||
})(); | ||
// This module is suitable for passing as options.parser when calling | ||
// recast.parse to process JavaScript code with Babel: | ||
// | ||
// const ast = recast.parse(source, { | ||
// parser: require("recast/parsers/babel") | ||
// }); | ||
// | ||
function parse(source, options) { | ||
var babelOptions = (0, _babel_options_1.default)(options); | ||
babelOptions.plugins.push("jsx", "decoratorAutoAccessors", "typescript"); | ||
return exports.parser.parse(source, babelOptions); | ||
} | ||
exports.parse = parse; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { createReference } from "~/runtime"; | ||
import { isServer } from "solid-js/web"; | ||
|
||
const story = (path) => `https://node-hnapi.herokuapp.com/${path}`; | ||
const user = (path) => `https://hacker-news.firebaseio.com/v0/${path}.json`; | ||
|
||
export default createReference( | ||
async function fetchAPI(path: string) { | ||
const url = path.startsWith("user") ? user(path) : story(path); | ||
|
||
const headers: Record<string, string> = isServer | ||
? { | ||
"User-Agent": "chrome", | ||
} | ||
: {}; | ||
|
||
try { | ||
let response = await fetch(url, { | ||
headers, | ||
}); | ||
|
||
let text = await response.text(); | ||
|
||
try { | ||
if (text === null) { | ||
return { | ||
error: "Not found", | ||
}; | ||
} | ||
|
||
return JSON.parse(text); | ||
} catch (e) { | ||
console.error(`Received from API: ${text}`); | ||
console.error(e); | ||
|
||
return { | ||
error: e, | ||
}; | ||
} | ||
} catch (error) { | ||
return { | ||
error, | ||
}; | ||
} | ||
}, | ||
"test", | ||
"default", | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"use runtime"; | ||
|
||
import { isServer } from "solid-js/web"; | ||
|
||
const story = (path) => `https://node-hnapi.herokuapp.com/${path}`; | ||
const user = (path) => `https://hacker-news.firebaseio.com/v0/${path}.json`; | ||
|
||
export default async function fetchAPI(path: string) { | ||
const url = path.startsWith("user") ? user(path) : story(path); | ||
|
||
const headers: Record<string, string> = isServer | ||
? { | ||
"User-Agent": "chrome", | ||
} | ||
: {}; | ||
|
||
try { | ||
let response = await fetch(url, { | ||
headers, | ||
}); | ||
|
||
let text = await response.text(); | ||
|
||
try { | ||
if (text === null) { | ||
return { | ||
error: "Not found", | ||
}; | ||
} | ||
|
||
return JSON.parse(text); | ||
} catch (e) { | ||
console.error(`Received from API: ${text}`); | ||
console.error(e); | ||
|
||
return { | ||
error: e, | ||
}; | ||
} | ||
} catch (error) { | ||
return { | ||
error, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.