Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
chee
committed
Dec 18, 2017
0 parents
commit 22600b9
Showing
1,568 changed files
with
625,029 additions
and
0 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,2 @@ | ||
node_modules | ||
.cache |
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 @@ | ||
{ | ||
"printWidth": 79, | ||
"semi": false, | ||
"bracketSpacing": false | ||
} |
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,86 @@ | ||
const path = require('path') | ||
|
||
const HTMLAsset = require('parcel-bundler/src/assets/HTMLAsset') | ||
const PHPParser = require('php-parser') | ||
const Include = require('php-parser/src/ast/include') | ||
|
||
const parser = new PHPParser({ | ||
ast: { | ||
withPositions: true | ||
} | ||
}) | ||
|
||
module.exports = class PHPAsset extends HTMLAsset { | ||
constructor (name, pkg, options) { | ||
super(name, pkg, options) | ||
this.type = 'php' | ||
} | ||
|
||
parse (code) { | ||
this.ast = parser.parseCode(code) | ||
return this.ast | ||
} | ||
|
||
apologise (require) { | ||
console.warn(`Sorry, hit an unsupported ${require ? 'require' : 'include'}.`) | ||
} | ||
|
||
collectDependencies () { | ||
let offset = 0 | ||
this.ast.children.forEach(node => { | ||
if (node.constructor !== Include) return | ||
|
||
const { | ||
require, | ||
target: { | ||
kind, | ||
value, | ||
loc: { | ||
start, | ||
end | ||
}, | ||
inner | ||
} | ||
} = node | ||
|
||
let phpPath | ||
|
||
if (kind === 'string') { | ||
phpPath = value | ||
} else if (kind === 'parenthesis') { | ||
if (inner.left.what.name !== 'dirname') { | ||
return this.apologise(require) | ||
} | ||
const dirname = path.dirname(this.name) | ||
phpPath = `${dirname}/${inner.right.value}` | ||
} else { | ||
return this.apologise(require) | ||
} | ||
|
||
const assetPath = this.addURLDependency(phpPath) | ||
|
||
const untilStart = this.contents.slice(0, start.offset + offset) | ||
const afterEnd = this.contents.slice(end.offset + offset) | ||
|
||
const originalLength = end.offset - start.offset | ||
const newLength = assetPath.length + 2 | ||
|
||
offset += (newLength - originalLength) | ||
|
||
this.contents = `${untilStart}'${assetPath}'${afterEnd}` | ||
}) | ||
|
||
this.ast = super.parse(this.contents) | ||
super.collectDependencies() | ||
} | ||
|
||
generate () { | ||
const { | ||
html | ||
} = super.generate() | ||
|
||
return { | ||
php: html | ||
} | ||
} | ||
} |
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 @@ | ||
49207 |
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,3 @@ | ||
run `parcel watch index.php` in one terminal, | ||
then `cd` into `dist` with another, and run | ||
`php -S localhost:1234` |
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 @@ | ||
you got me all wrong! |
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 @@ | ||
<script src="/482c40a07028f88c5f8719da73c62ab4.js"></script> |
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,188 @@ | ||
// modules are defined as an array | ||
// [ module function, map of requires ] | ||
// | ||
// map of requires is short require name -> numeric require | ||
// | ||
// anything defined in a previous bundle is accessed via the | ||
// orig method which is the require for previous bundles | ||
|
||
require = (function (modules, cache, entry) { | ||
// Save the require from previous bundle to this closure if any | ||
var previousRequire = typeof require === "function" && require; | ||
|
||
function newRequire(name, jumped) { | ||
if (!cache[name]) { | ||
if (!modules[name]) { | ||
// if we cannot find the module within our internal map or | ||
// cache jump to the current global require ie. the last bundle | ||
// that was added to the page. | ||
var currentRequire = typeof require === "function" && require; | ||
if (!jumped && currentRequire) { | ||
return currentRequire(name, true); | ||
} | ||
|
||
// If there are other bundles on this page the require from the | ||
// previous one is saved to 'previousRequire'. Repeat this as | ||
// many times as there are bundles until the module is found or | ||
// we exhaust the require chain. | ||
if (previousRequire) { | ||
return previousRequire(name, true); | ||
} | ||
|
||
var err = new Error('Cannot find module \'' + name + '\''); | ||
err.code = 'MODULE_NOT_FOUND'; | ||
throw err; | ||
} | ||
|
||
function localRequire(x) { | ||
return newRequire(localRequire.resolve(x)); | ||
} | ||
|
||
localRequire.resolve = function (x) { | ||
return modules[name][1][x] || x; | ||
}; | ||
|
||
var module = cache[name] = new newRequire.Module; | ||
modules[name][0].call(module.exports, localRequire, module, module.exports); | ||
} | ||
|
||
return cache[name].exports; | ||
} | ||
|
||
function Module() { | ||
this.bundle = newRequire; | ||
this.exports = {}; | ||
} | ||
|
||
newRequire.Module = Module; | ||
newRequire.modules = modules; | ||
newRequire.cache = cache; | ||
newRequire.parent = previousRequire; | ||
|
||
for (var i = 0; i < entry.length; i++) { | ||
newRequire(entry[i]); | ||
} | ||
|
||
// Override the current require with this new one | ||
return newRequire; | ||
})({2:[function(require,module,exports) { | ||
console.log('come with me') | ||
console.log('merry christmas') | ||
|
||
},{}],0:[function(require,module,exports) { | ||
var global = (1, eval)('this'); | ||
var OldModule = module.bundle.Module; | ||
function Module() { | ||
OldModule.call(this); | ||
this.hot = { | ||
accept: function (fn) { | ||
this._acceptCallback = fn || function () {}; | ||
}, | ||
dispose: function (fn) { | ||
this._disposeCallback = fn; | ||
} | ||
}; | ||
} | ||
|
||
module.bundle.Module = Module; | ||
|
||
if (!module.bundle.parent) { | ||
var ws = new WebSocket('ws://localhost:49198/'); | ||
ws.onmessage = function(event) { | ||
var data = JSON.parse(event.data); | ||
|
||
if (data.type === 'update') { | ||
data.assets.forEach(function (asset) { | ||
hmrApply(global.require, asset); | ||
}); | ||
|
||
data.assets.forEach(function (asset) { | ||
if (!asset.isNew) { | ||
hmrAccept(global.require, asset.id); | ||
} | ||
}); | ||
} | ||
|
||
if (data.type === 'reload') { | ||
window.location.reload(); | ||
} | ||
|
||
if (data.type === 'error-resolved') { | ||
console.log('[parcel] ✨ Error resolved'); | ||
} | ||
|
||
if (data.type === 'error') { | ||
console.error(`[parcel] 🚨 ${data.error.message}\n${data.error.stack}`); | ||
} | ||
}; | ||
} | ||
|
||
function getParents(bundle, id) { | ||
var modules = bundle.modules; | ||
if (!modules) { | ||
return []; | ||
} | ||
|
||
var parents = []; | ||
var k, d, dep; | ||
|
||
for (k in modules) { | ||
for (d in modules[k][1]) { | ||
dep = modules[k][1][d]; | ||
if (dep === id || (Array.isArray(dep) && dep[dep.length - 1] === id)) { | ||
parents.push(+k); | ||
} | ||
} | ||
} | ||
|
||
if (bundle.parent) { | ||
parents = parents.concat(getParents(bundle.parent, id)); | ||
} | ||
|
||
return parents; | ||
} | ||
|
||
function hmrApply(bundle, asset) { | ||
var modules = bundle.modules; | ||
if (!modules) { | ||
return; | ||
} | ||
|
||
if (modules[asset.id] || !bundle.parent) { | ||
var fn = new Function('require', 'module', 'exports', asset.generated.js); | ||
asset.isNew = !modules[asset.id]; | ||
modules[asset.id] = [fn, asset.deps]; | ||
} else if (bundle.parent) { | ||
hmrApply(bundle.parent, asset); | ||
} | ||
} | ||
|
||
function hmrAccept(bundle, id) { | ||
var modules = bundle.modules; | ||
if (!modules) { | ||
return; | ||
} | ||
|
||
if (!modules[id] && bundle.parent) { | ||
return hmrAccept(bundle.parent, id); | ||
} | ||
|
||
var cached = bundle.cache[id]; | ||
if (cached && cached.hot._disposeCallback) { | ||
cached.hot._disposeCallback(); | ||
} | ||
|
||
delete bundle.cache[id]; | ||
bundle(id); | ||
|
||
cached = bundle.cache[id]; | ||
if (cached && cached.hot && cached.hot._acceptCallback) { | ||
cached.hot._acceptCallback(); | ||
return true; | ||
} | ||
|
||
return getParents(global.require, id).some(function (id) { | ||
return hmrAccept(global.require, id) | ||
}); | ||
} | ||
},{}]},{},[0,2]) |
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,3 @@ | ||
<?php | ||
print time(); | ||
print "come on let's go!!!"; |
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,14 @@ | ||
<!doctype html> | ||
|
||
<div>I am php</div> | ||
<div> | ||
<?php | ||
include '1d4c9315d9a6b7c64df6c9ef66ccf029.php'; | ||
?> | ||
</div> | ||
|
||
<div class="<?php date(); ?>"> | ||
goodbye | ||
<div> | ||
<p> | ||
<?php include '386e43e1347f5a02fb335e8e2f2a967b.php'; ?> |
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,3 @@ | ||
<?php | ||
include '../wog.php'; | ||
?> <script src="./spring.js"></script> |
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,2 @@ | ||
console.log('come with me') | ||
console.log('merry christmas') |
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,14 @@ | ||
<!doctype html> | ||
|
||
<div>I am php</div> | ||
<div> | ||
<?php | ||
include 'lol.php'; | ||
?> | ||
</div> | ||
|
||
<div class="<?php date(); ?>"> | ||
goodbye | ||
<div> | ||
<p> | ||
<?php include 'fox/dog.php'; ?> |
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 @@ | ||
you got me all wrong! |
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,10 @@ | ||
{ | ||
"name": "parcel-plugin-php-example", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"author": "chee <chee@snake.dog>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"parcel-plugin-php": "1.0.0" | ||
} | ||
} |
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,3 @@ | ||
<?php | ||
print time(); | ||
print "come on let's go!!!"; |
Oops, something went wrong.