Commit f9b80170 authored by xiabin's avatar xiabin

123

parent d8d5db17

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "browse_record".
*
* @property integer $id
* @property integer $cou_id
* @property integer $use_id
* @property string $time
*
* @property Course $cou
* @property Users $use
*/
class BrowseRecord extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'browse_record';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['cou_id', 'use_id', 'time'], 'required'],
[['cou_id', 'use_id'], 'integer'],
[['time'], 'safe'],
[['cou_id'], 'exist', 'skipOnError' => true, 'targetClass' => Course::className(), 'targetAttribute' => ['cou_id' => 'id']],
[['use_id'], 'exist', 'skipOnError' => true, 'targetClass' => Users::className(), 'targetAttribute' => ['use_id' => 'id']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'id',
'cou_id' => 'cou_id',
'use_id' => 'use_id',
'time' => 'time',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCou()
{
return $this->hasOne(Course::className(), ['id' => 'cou_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getUse()
{
return $this->hasOne(Users::className(), ['id' => 'use_id']);
}
}
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "classes".
*
* @property integer $id
* @property integer $use_id
* @property string $id_number
* @property string $id_name
* @property string $name
* @property string $intro
* @property integer $status
* @property string $craete_at
* @property string $update_at
*
* @property Users $use
* @property ClassesTeacher[] $classesTeachers
* @property Teacher[] $teas
* @property Course[] $courses
*/
class Classes extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'classes';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['use_id', 'name', 'intro', 'status', 'craete_at', 'update_at'], 'required'],
[['use_id', 'status'], 'integer'],
[['intro'], 'string'],
[['craete_at', 'update_at'], 'safe'],
[['id_number'], 'string', 'max' => 18],
[['id_name'], 'string', 'max' => 10],
[['name'], 'string', 'max' => 32],
[['use_id'], 'exist', 'skipOnError' => true, 'targetClass' => Users::className(), 'targetAttribute' => ['use_id' => 'id']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'id',
'use_id' => 'use_id',
'id_number' => 'id_number',
'id_name' => 'id_name',
'name' => 'name',
'intro' => 'intro',
'status' => 'status 0 ',
'craete_at' => 'craete_at',
'update_at' => 'update_at',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getUse()
{
return $this->hasOne(Users::className(), ['id' => 'use_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getClassesTeachers()
{
return $this->hasMany(ClassesTeacher::className(), ['id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getTeas()
{
return $this->hasMany(Teacher::className(), ['id' => 'tea_id'])->viaTable('classes_teacher', ['id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCourses()
{
return $this->hasMany(Course::className(), ['cla_id' => 'id']);
}
}
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "classes_teacher".
*
* @property integer $id
* @property integer $tea_id
*
* @property Classes $id0
* @property Teacher $tea
*/
class ClassesTeacher extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'classes_teacher';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'tea_id'], 'required'],
[['id', 'tea_id'], 'integer'],
[['id'], 'exist', 'skipOnError' => true, 'targetClass' => Classes::className(), 'targetAttribute' => ['id' => 'id']],
[['tea_id'], 'exist', 'skipOnError' => true, 'targetClass' => Teacher::className(), 'targetAttribute' => ['tea_id' => 'id']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'id',
'tea_id' => 'tea_id',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getId0()
{
return $this->hasOne(Classes::className(), ['id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getTea()
{
return $this->hasOne(Teacher::className(), ['id' => 'tea_id']);
}
}
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "collection".
*
* @property integer $id
* @property integer $cou_id
* @property integer $use_id
* @property string $create_at
*
* @property Courseware $cou
* @property Users $use
*/
class Collection extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'collection';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['cou_id', 'use_id', 'create_at'], 'required'],
[['cou_id', 'use_id'], 'integer'],
[['create_at'], 'safe'],
[['cou_id'], 'exist', 'skipOnError' => true, 'targetClass' => Courseware::className(), 'targetAttribute' => ['cou_id' => 'id']],
[['use_id'], 'exist', 'skipOnError' => true, 'targetClass' => Users::className(), 'targetAttribute' => ['use_id' => 'id']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'id',
'cou_id' => 'cou_id',
'use_id' => 'use_id',
'create_at' => 'create_at',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCou()
{
return $this->hasOne(Courseware::className(), ['id' => 'cou_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getUse()
{
return $this->hasOne(Users::className(), ['id' => 'use_id']);
}
}
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "comments".
*
* @property integer $id
* @property integer $use_id
* @property integer $cou_id
* @property integer $parent_id
* @property string $content
* @property string $ip
* @property string $create_at
*
* @property Courseware $cou
* @property Users $use
*/
class Comments extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'comments';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['use_id', 'cou_id', 'parent_id', 'content', 'ip', 'create_at'], 'required'],
[['use_id', 'cou_id', 'parent_id'], 'integer'],
[['content'], 'string'],
[['create_at'], 'safe'],
[['ip'], 'string', 'max' => 32],
[['cou_id'], 'exist', 'skipOnError' => true, 'targetClass' => Courseware::className(), 'targetAttribute' => ['cou_id' => 'id']],
[['use_id'], 'exist', 'skipOnError' => true, 'targetClass' => Users::className(), 'targetAttribute' => ['use_id' => 'id']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'id',
'use_id' => 'use_id',
'cou_id' => 'cou_id',
'parent_id' => 'parent_id',
'content' => 'content',
'ip' => 'ip',
'create_at' => 'create_at',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCou()
{
return $this->hasOne(Courseware::className(), ['id' => 'cou_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getUse()
{
return $this->hasOne(Users::className(), ['id' => 'use_id']);
}
}
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "consume".
*
* @property integer $id
* @property integer $use_id
* @property integer $ord_id
*
* @property Orders $ord
* @property Users $use
* @property Orders[] $orders
*/
class Consume extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'consume';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['use_id', 'ord_id'], 'required'],
[['use_id', 'ord_id'], 'integer'],
[['ord_id'], 'exist', 'skipOnError' => true, 'targetClass' => Orders::className(), 'targetAttribute' => ['ord_id' => 'id']],
[['use_id'], 'exist', 'skipOnError' => true, 'targetClass' => Users::className(), 'targetAttribute' => ['use_id' => 'id']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'id',
'use_id' => 'use_id',
'ord_id' => 'ord_id',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getOrd()
{
return $this->hasOne(Orders::className(), ['id' => 'ord_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getUse()
{
return $this->hasOne(Users::className(), ['id' => 'use_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getOrders()
{
return $this->hasMany(Orders::className(), ['con_id' => 'id']);
}
}
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "course".
*
* @property integer $id
* @property integer $cla_id
* @property string $name
* @property integer $price
* @property integer $free_time
* @property string $intro
* @property string $preview_pic
* @property integer $recommend
* @property integer $status
* @property string $create_at
* @property string $update_at
*
* @property BrowseRecord[] $browseRecords
* @property Classes $cla
* @property Courseware[] $coursewares
* @property Orders[] $orders
*/
class Course extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'course';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'cla_id', 'name', 'price', 'free_time', 'intro', 'preview_pic', 'recommend', 'status', 'create_at', 'update_at'], 'required'],
[['id', 'cla_id', 'price', 'free_time', 'recommend', 'status'], 'integer'],
[['intro'], 'string'],
[['create_at', 'update_at'], 'safe'],
[['name'], 'string', 'max' => 32],
[['preview_pic'], 'string', 'max' => 64],
[['cla_id'], 'exist', 'skipOnError' => true, 'targetClass' => Classes::className(), 'targetAttribute' => ['cla_id' => 'id']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'id',
'cla_id' => 'cla_id',
'name' => 'name',
'price' => 'Price',
'free_time' => 'Free Time',
'intro' => 'intro',
'preview_pic' => 'Ԥ',
'recommend' => 'Recommend',
'status' => 'status 0 ',
'create_at' => 'create_at',
'update_at' => 'update_at',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getBrowseRecords()
{
return $this->hasMany(BrowseRecord::className(), ['cou_id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCla()
{
return $this->hasOne(Classes::className(), ['id' => 'cla_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCoursewares()
{
return $this->hasMany(Courseware::className(), ['cou_id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getOrders()
{
return $this->hasMany(Orders::className(), ['cou_id' => 'id']);
}
}
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "courseware".
*
* @property integer $id
* @property integer $sup_id
* @property integer $cou_id
* @property integer $type
* @property string $name
* @property integer $status
* @property string $size
* @property integer $time
* @property string $format
* @property string $create_at
* @property string $update_at
*
* @property Collection[] $collections
* @property Comments[] $comments
* @property Course $cou
* @property Support $sup
*/
class Courseware extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'courseware';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['sup_id', 'cou_id', 'type', 'name', 'status', 'size', 'time', 'format', 'create_at', 'update_at'], 'required'],
[['sup_id', 'cou_id', 'type', 'status', 'time'], 'integer'],
[['create_at', 'update_at'], 'safe'],
[['name'], 'string', 'max' => 128],
[['size'], 'string', 'max' => 20],
[['format'], 'string', 'max' => 16],
[['cou_id'], 'exist', 'skipOnError' => true, 'targetClass' => Course::className(), 'targetAttribute' => ['cou_id' => 'id']],
[['sup_id'], 'exist', 'skipOnError' => true, 'targetClass' => Support::className(), 'targetAttribute' => ['sup_id' => 'id']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'id',
'sup_id' => 'sup_id',
'cou_id' => 'cou_id',
'type' => 'type',
'name' => 'name',
'status' => 'status 0 ',
'size' => 'Size',
'time' => 'time',
'format' => 'format',
'create_at' => 'create_at',
'update_at' => 'update_at',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCollections()
{
return $this->hasMany(Collection::className(), ['cou_id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getComments()
{
return $this->hasMany(Comments::className(), ['cou_id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCou()
{
return $this->hasOne(Course::className(), ['id' => 'cou_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getSup()
{
return $this->hasOne(Support::className(), ['id' => 'sup_id']);
}
}
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "income".
*
* @property integer $id
* @property integer $use_id
* @property integer $ord_id
* @property integer $status
* @property string $create_at
* @property string $update_at
*
* @property Orders $ord
* @property Users $use
* @property Orders[] $orders
*/
class Income extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'income';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['use_id', 'ord_id', 'status', 'create_at', 'update_at'], 'required'],
[['use_id', 'ord_id', 'status'], 'integer'],
[['create_at', 'update_at'], 'safe'],
[['ord_id'], 'exist', 'skipOnError' => true, 'targetClass' => Orders::className(), 'targetAttribute' => ['ord_id' => 'id']],
[['use_id'], 'exist', 'skipOnError' => true, 'targetClass' => Users::className(), 'targetAttribute' => ['use_id' => 'id']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'id',
'use_id' => 'use_id',
'ord_id' => 'ord_id',
'status' => 'status 0δ',
'create_at' => 'create_at',
'update_at' => 'update_at',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getOrd()
{
return $this->hasOne(Orders::className(), ['id' => 'ord_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getUse()
{
return $this->hasOne(Users::className(), ['id' => 'use_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getOrders()
{
return $this->hasMany(Orders::className(), ['inc_id' => 'id']);
}
}
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "support".
*
* @property integer $id
* @property integer $use_id
* @property string $create_at
*
* @property Courseware[] $coursewares
* @property Users $use
*/
class Support extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'support';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['use_id', 'create_at'], 'required'],
[['use_id'], 'integer'],
[['create_at'], 'safe'],
[['use_id'], 'exist', 'skipOnError' => true, 'targetClass' => Users::className(), 'targetAttribute' => ['use_id' => 'id']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'id',
'use_id' => 'use_id',
'create_at' => 'create_at',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCoursewares()
{
return $this->hasMany(Courseware::className(), ['sup_id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getUse()
{
return $this->hasOne(Users::className(), ['id' => 'use_id']);
}
}
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "teacher".
*
* @property integer $id
* @property integer $use_id
* @property string $name
* @property string $avatar
* @property string $intro
*
* @property ClassesTeacher[] $classesTeachers
* @property Classes[] $ids
* @property Users $use
*/
class Teacher extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'teacher';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['use_id', 'name', 'avatar', 'intro'], 'required'],
[['use_id'], 'integer'],
[['intro'], 'string'],
[['name'], 'string', 'max' => 12],
[['avatar'], 'string', 'max' => 128],
[['use_id'], 'exist', 'skipOnError' => true, 'targetClass' => Users::className(), 'targetAttribute' => ['use_id' => 'id']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'id',
'use_id' => 'use_id',
'name' => 'name',
'avatar' => 'avatar',
'intro' => 'intro',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getClassesTeachers()
{
return $this->hasMany(ClassesTeacher::className(), ['tea_id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getIds()
{
return $this->hasMany(Classes::className(), ['id' => 'id'])->viaTable('classes_teacher', ['tea_id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getUse()
{
return $this->hasOne(Users::className(), ['id' => 'use_id']);
}
}
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "weixin".
*
* @property integer $id
* @property integer $use_id
* @property string $name
* @property string $avatar
* @property string $open_id
* @property string $create_at
* @property string $update_at
*
* @property Users $use
*/
class Weixin extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'weixin';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['use_id', 'name', 'avatar', 'open_id', 'create_at', 'update_at'], 'required'],
[['use_id'], 'integer'],
[['create_at', 'update_at'], 'safe'],
[['name'], 'string', 'max' => 64],
[['avatar'], 'string', 'max' => 128],
[['open_id'], 'string', 'max' => 32],
[['use_id'], 'exist', 'skipOnError' => true, 'targetClass' => Users::className(), 'targetAttribute' => ['use_id' => 'id']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'id',
'use_id' => 'use_id',
'name' => 'name',
'avatar' => 'avatar',
'open_id' => 'open_id',
'create_at' => 'create_at',
'update_at' => 'update_at',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getUse()
{
return $this->hasOne(Users::className(), ['id' => 'use_id']);
}
}
...@@ -2,8 +2,11 @@ ...@@ -2,8 +2,11 @@
use yii\db\Migration; use yii\db\Migration;
class m130524_201442_init extends Migration class m160927_113951_weixin_init extends Migration
{ {
public $table = '{{%weixin}}';
public function up() public function up()
{ {
$tableOptions = NULL; $tableOptions = NULL;
...@@ -12,28 +15,32 @@ class m130524_201442_init extends Migration ...@@ -12,28 +15,32 @@ class m130524_201442_init extends Migration
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB'; $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
} }
$this->createTable('{{%users}}', [ $this->createTable($this->table, [
'id' => $this->primaryKey(), 'id' => $this->primaryKey()->unsigned(),
'username' => $this->string()->notNull()->unique(), 'user_id' => $this->integer()->notNull()->unsigned(),
'auth_key' => $this->string(32)->notNull(), 'name' => $this->string(64)->notNull(),
'password_hash' => $this->string()->notNull(), 'avatar' => $this->string(255)->notNull(),
'password_reset_token' => $this->string()->unique(), 'open_id' => $this->string(32)->notNull(''),
'telephone' => $this->string(15)->notNull()->unique(),
'role' => $this->smallInteger()->notNull()->defaultValue(0)->comment('0 普通 1 讲师'),
'status' => $this->smallInteger()->notNull()->defaultValue(10)->comment('0 正常 1 锁定'),
'avatar' => $this->string(128)->notNull()->defaultValue(''),
'wx_open_id' => $this->string(32)->defaultValue('')->comment('登录微信id'),
'ip' => $this->string(32)->notNull(),
'created_at' => $this->integer()->notNull(), 'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull(), 'updated_at' => $this->integer()->notNull(),
'logged_at' => $this->integer()->notNull()
], $tableOptions); ], $tableOptions);
$this->alterColumn('{{%users}}', 'id', $this->int() . ' NOT NULL AUTO_INCREMENT');
} }
public function down() public function down()
{ {
$this->dropTable('{{%users}}'); echo "m160927_113951_winxin_init cannot be reverted.\n";
$this->dropTable($this->table);
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
} }
*/
} }
...@@ -11,6 +11,7 @@ return [ ...@@ -11,6 +11,7 @@ return [
'basePath' => dirname(__DIR__), 'basePath' => dirname(__DIR__),
'bootstrap' => ['log'], 'bootstrap' => ['log'],
'controllerNamespace' => 'frontend\controllers', 'controllerNamespace' => 'frontend\controllers',
'defaultRoute' => 'user-center',
'components' => [ 'components' => [
'request' => [ 'request' => [
'csrfParam' => '_csrf-frontend', 'csrfParam' => '_csrf-frontend',
......
...@@ -19,6 +19,9 @@ use yii\helpers\HtmlPurifier; ...@@ -19,6 +19,9 @@ use yii\helpers\HtmlPurifier;
class UserCenterController extends Controller class UserCenterController extends Controller
{ {
public $defaultAction = 'info';
/** /**
* @inheritdoc * @inheritdoc
*/ */
...@@ -40,16 +43,14 @@ class UserCenterController extends Controller ...@@ -40,16 +43,14 @@ class UserCenterController extends Controller
public function actionTest() public function actionTest()
{ {
$message = new Message(); $user = Yii::$app->user->identity;
$result = $message->send('15395081586','xia12312321313213bin'); var_dump($user->getBrowseRecords());
} }
public function actionIndex() public function actionInfo()
{ {
echo 'index'; return $this->render('info');
$user = User::findByTelephone2('15395081586');
print_r($user);
// echo Yii::$app->user->identity->role;
} }
} }
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: xiabin
* Date: 2016/9/27
* Time: 下午4:16
*/
?>
info
../.npminstall/cross-env/1.0.8/cross-env/bin/cross-env.js
\ No newline at end of file
../.npminstall/webpack/1.13.2/webpack/bin/webpack.js
\ No newline at end of file
Tue Sep 27 2016 16:03:35 GMT+0800 (CST)
\ No newline at end of file
language: node_js
node_js:
- "0.8"
- "0.10"
- "0.11"
install: make setup
script: make test
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (c) 2011..2012 David Chambers <dc@hashify.me>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
ISTANBUL = node_modules/.bin/istanbul
UGLIFYJS = node_modules/.bin/uglifyjs
XYZ = node_modules/.bin/xyz --message X.Y.Z --tag X.Y.Z
SRC = base64.js
MIN = $(patsubst %.js,%.min.js,$(SRC))
.PHONY: all
all: $(MIN)
%.min.js: %.js
$(UGLIFYJS) $< --compress --mangle > $@
.PHONY: bytes
bytes: base64.min.js
gzip --best --stdout $< | wc -c | tr -d ' '
.PHONY: clean
clean:
rm -f -- $(MIN)
.PHONY: release-major release-minor release-patch
release-major:
$(XYZ) --increment major
release-minor:
$(XYZ) --increment minor
release-patch:
$(XYZ) --increment patch
.PHONY: setup
setup:
npm install
.PHONY: test
test:
$(ISTANBUL) cover node_modules/.bin/_mocha -- --compilers coffee:coffee-script/register
# Base64.js
≈ 500 byte* polyfill for browsers which don't provide [`window.btoa`][1] and
[`window.atob`][2].
Although the script does no harm in browsers which do provide these functions,
a conditional script loader such as [yepnope][3] can prevent unnecessary HTTP
requests.
```javascript
yepnope({
test: window.btoa && window.atob,
nope: 'base64.js',
callback: function () {
// `btoa` and `atob` are now safe to use
}
})
```
Base64.js stems from a [gist][4] by [yahiko][5].
### Running the test suite
make setup
make test
\* Minified and gzipped. Run `make bytes` to verify.
[1]: https://developer.mozilla.org/en/DOM/window.btoa
[2]: https://developer.mozilla.org/en/DOM/window.atob
[3]: http://yepnopejs.com/
[4]: https://gist.github.com/229984
[5]: https://github.com/yahiko
;(function () {
var object = typeof exports != 'undefined' ? exports : this; // #8: web workers
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
function InvalidCharacterError(message) {
this.message = message;
}
InvalidCharacterError.prototype = new Error;
InvalidCharacterError.prototype.name = 'InvalidCharacterError';
// encoder
// [https://gist.github.com/999166] by [https://github.com/nignag]
object.btoa || (
object.btoa = function (input) {
for (
// initialize result and counter
var block, charCode, idx = 0, map = chars, output = '';
// if the next input index does not exist:
// change the mapping table to "="
// check if d has no fractional digits
input.charAt(idx | 0) || (map = '=', idx % 1);
// "8 - idx % 1 * 8" generates the sequence 2, 4, 6, 8
output += map.charAt(63 & block >> 8 - idx % 1 * 8)
) {
charCode = input.charCodeAt(idx += 3/4);
if (charCode > 0xFF) {
throw new InvalidCharacterError("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");
}
block = block << 8 | charCode;
}
return output;
});
// decoder
// [https://gist.github.com/1020396] by [https://github.com/atk]
object.atob || (
object.atob = function (input) {
input = input.replace(/=+$/, '');
if (input.length % 4 == 1) {
throw new InvalidCharacterError("'atob' failed: The string to be decoded is not correctly encoded.");
}
for (
// initialize result and counters
var bc = 0, bs, buffer, idx = 0, output = '';
// get next character
buffer = input.charAt(idx++);
// character found in table? initialize bit storage and add its ascii value;
~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer,
// and if not first of each 4 characters,
// convert the first 8 bits to one ascii character
bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0
) {
// try to find character in table (0-63, not found => -1)
buffer = chars.indexOf(buffer);
}
return output;
});
}());
!function(){function t(t){this.message=t}var e="undefined"!=typeof exports?exports:this,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";t.prototype=new Error,t.prototype.name="InvalidCharacterError",e.btoa||(e.btoa=function(e){for(var o,n,a=0,i=r,c="";e.charAt(0|a)||(i="=",a%1);c+=i.charAt(63&o>>8-a%1*8)){if(n=e.charCodeAt(a+=.75),n>255)throw new t("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");o=o<<8|n}return c}),e.atob||(e.atob=function(e){if(e=e.replace(/=+$/,""),e.length%4==1)throw new t("'atob' failed: The string to be decoded is not correctly encoded.");for(var o,n,a=0,i=0,c="";n=e.charAt(i++);~n&&(o=a%4?64*o+n:n,a++%4)?c+=String.fromCharCode(255&o>>(-2*a&6)):0)n=r.indexOf(n);return c})}();
\ No newline at end of file
{
"name": "Base64",
"version": "0.2.1",
"description": "Base64 encoding and decoding",
"author": "David Chambers <dc@davidchambers.me>",
"main": "./base64.js",
"licenses": [
{
"type": "WTFPL",
"url": "https://raw.github.com/davidchambers/Base64.js/master/LICENSE"
}
],
"repository": {
"type": "git",
"url": "git://github.com/davidchambers/Base64.js.git"
},
"devDependencies": {
"coffee-script": "1.7.x",
"istanbul": "0.2.x",
"mocha": "1.18.x",
"uglify-js": "2.4.x",
"xyz": "0.1.x"
},
"_from": "Base64@0.2.1",
"_resolved": "http://registry.npm.taobao.org/Base64/download/Base64-0.2.1.tgz"
}
\ No newline at end of file
assert = require 'assert'
{btoa, atob} = require '..'
describe 'Base64.js', ->
it 'can encode ASCII input', ->
assert.strictEqual btoa(''), ''
assert.strictEqual btoa('f'), 'Zg=='
assert.strictEqual btoa('fo'), 'Zm8='
assert.strictEqual btoa('foo'), 'Zm9v'
assert.strictEqual btoa('quux'), 'cXV1eA=='
assert.strictEqual btoa('!"#$%'), 'ISIjJCU='
assert.strictEqual btoa("&'()*+"), 'JicoKSor'
assert.strictEqual btoa(',-./012'), 'LC0uLzAxMg=='
assert.strictEqual btoa('3456789:'), 'MzQ1Njc4OTo='
assert.strictEqual btoa(';<=>?@ABC'), 'Ozw9Pj9AQUJD'
assert.strictEqual btoa('DEFGHIJKLM'), 'REVGR0hJSktMTQ=='
assert.strictEqual btoa('NOPQRSTUVWX'), 'Tk9QUVJTVFVWV1g='
assert.strictEqual btoa('YZ[\\]^_`abc'), 'WVpbXF1eX2BhYmM='
assert.strictEqual btoa('defghijklmnop'), 'ZGVmZ2hpamtsbW5vcA=='
assert.strictEqual btoa('qrstuvwxyz{|}~'), 'cXJzdHV2d3h5ent8fX4='
it 'cannot encode non-ASCII input', ->
assert.throws (-> btoa '✈'), (err) ->
err instanceof Error and
err.name is 'InvalidCharacterError' and
err.message is "'btoa' failed: The string to be encoded contains characters outside of the Latin1 range."
it 'can decode Base64-encoded input', ->
assert.strictEqual atob(''), ''
assert.strictEqual atob('Zg=='), 'f'
assert.strictEqual atob('Zm8='), 'fo'
assert.strictEqual atob('Zm9v'), 'foo'
assert.strictEqual atob('cXV1eA=='), 'quux'
assert.strictEqual atob('ISIjJCU='), '!"#$%'
assert.strictEqual atob('JicoKSor'), "&'()*+"
assert.strictEqual atob('LC0uLzAxMg=='), ',-./012'
assert.strictEqual atob('MzQ1Njc4OTo='), '3456789:'
assert.strictEqual atob('Ozw9Pj9AQUJD'), ';<=>?@ABC'
assert.strictEqual atob('REVGR0hJSktMTQ=='), 'DEFGHIJKLM'
assert.strictEqual atob('Tk9QUVJTVFVWV1g='), 'NOPQRSTUVWX'
assert.strictEqual atob('WVpbXF1eX2BhYmM='), 'YZ[\\]^_`abc'
assert.strictEqual atob('ZGVmZ2hpamtsbW5vcA=='), 'defghijklmnop'
assert.strictEqual atob('cXJzdHV2d3h5ent8fX4='), 'qrstuvwxyz{|}~'
it 'cannot decode invalid input', ->
assert.throws (-> atob 'a'), (err) ->
err instanceof Error and
err.name is 'InvalidCharacterError' and
err.message is "'atob' failed: The string to be decoded is not correctly encoded."
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
Tue Sep 27 2016 16:03:33 GMT+0800 (CST)
\ No newline at end of file
List of Acorn contributors. Updated before every release.
Adrian Rakovsky
Alistair Braidwood
Andres Suarez
Aparajita Fishman
Arian Stolwijk
Artem Govorov
Brandon Mills
Charles Hughes
Conrad Irwin
David Bonnet
Forbes Lindesay
Gilad Peleg
impinball
Ingvar Stepanyan
Jiaxing Wang
Johannes Herr
Jürg Lehni
keeyipchan
krator
Marijn Haverbeke
Martin Carlberg
Mathias Bynens
Mathieu 'p01' Henri
Max Schaefer
Max Zerzouri
Mihai Bazon
Mike Rennie
Nick Fitzgerald
Oskar Schöldström
Paul Harper
Peter Rust
PlNG
r-e-d
Rich Harris
Sebastian McKenzie
zsjforcn
Copyright (C) 2012-2014 by various contributors (see AUTHORS)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
#!/usr/bin/env node
var path = require("path");
var fs = require("fs");
var acorn = require("../dist/acorn.js");
var infile, parsed, tokens, options = {}, silent = false, compact = false, tokenize = false;
function help(status) {
var print = (status == 0) ? console.log : console.error;
print("usage: " + path.basename(process.argv[1]) + " [--ecma3|--ecma5|--ecma6]");
print(" [--tokenize] [--locations] [---allow-hash-bang] [--compact] [--silent] [--help] [--] infile");
process.exit(status);
}
for (var i = 2; i < process.argv.length; ++i) {
var arg = process.argv[i];
if (arg[0] != "-" && !infile) infile = arg;
else if (arg == "--" && !infile && i + 2 == process.argv.length) infile = process.argv[++i];
else if (arg == "--ecma3") options.ecmaVersion = 3;
else if (arg == "--ecma5") options.ecmaVersion = 5;
else if (arg == "--ecma6") options.ecmaVersion = 6;
else if (arg == "--ecma7") options.ecmaVersion = 7;
else if (arg == "--locations") options.locations = true;
else if (arg == "--allow-hash-bang") options.allowHashBang = true;
else if (arg == "--silent") silent = true;
else if (arg == "--compact") compact = true;
else if (arg == "--help") help(0);
else if (arg == "--tokenize") tokenize = true;
else help(1);
}
try {
var code = fs.readFileSync(infile, "utf8");
if (!tokenize)
parsed = acorn.parse(code, options);
else {
var get = acorn.tokenize(code, options);
tokens = [];
while (true) {
var token = get();
tokens.push(token);
if (token.type.type == "eof")
break;
}
}
} catch(e) {
console.log(e.message);
process.exit(1);
}
if (!silent)
console.log(JSON.stringify(tokenize ? tokens : parsed, null, compact ? null : 2));
var fs = require("fs"), path = require("path")
var stream = require("stream")
var browserify = require("browserify")
var babelify = require("babelify").configure({loose: "all"})
process.chdir(path.resolve(__dirname, ".."))
browserify({standalone: "acorn"})
.plugin(require('browserify-derequire'))
.transform(babelify)
.require("./src/index.js", {entry: true})
.bundle()
.on("error", function (err) { console.log("Error: " + err.message) })
.pipe(fs.createWriteStream("dist/acorn.js"))
function acornShim(file) {
var tr = new stream.Transform
if (file == path.resolve(__dirname, "../src/index.js")) {
var sent = false
tr._transform = function(chunk, _, callback) {
if (!sent) {
sent = true
callback(null, "module.exports = typeof acorn != 'undefined' ? acorn : _dereq_(\"./acorn\")")
} else {
callback()
}
}
} else {
tr._transform = function(chunk, _, callback) { callback(null, chunk) }
}
return tr
}
browserify({standalone: "acorn.loose"})
.plugin(require('browserify-derequire'))
.transform(acornShim)
.transform(babelify)
.require("./src/loose/index.js", {entry: true})
.bundle()
.on("error", function (err) { console.log("Error: " + err.message) })
.pipe(fs.createWriteStream("dist/acorn_loose.js"))
browserify({standalone: "acorn.walk"})
.plugin(require('browserify-derequire'))
.transform(acornShim)
.transform(babelify)
.require("./src/walk/index.js", {entry: true})
.bundle()
.on("error", function (err) { console.log("Error: " + err.message) })
.pipe(fs.createWriteStream("dist/walk.js"))
// Note: run `npm install unicode-7.0.0` first.
// Which Unicode version should be used?
var version = '7.0.0';
var start = require('unicode-' + version + '/properties/ID_Start/code-points')
.filter(function(ch) { return ch > 127; });
var cont = [0x200c, 0x200d].concat(require('unicode-' + version + '/properties/ID_Continue/code-points')
.filter(function(ch) { return ch > 127 && start.indexOf(ch) == -1; }));
function pad(str, width) {
while (str.length < width) str = "0" + str;
return str;
}
function esc(code) {
var hex = code.toString(16);
if (hex.length <= 2) return "\\x" + pad(hex, 2);
else return "\\u" + pad(hex, 4);
}
function generate(chars) {
var astral = [], re = "";
for (var i = 0, at = 0x10000; i < chars.length; i++) {
var from = chars[i], to = from;
while (i < chars.length - 1 && chars[i + 1] == to + 1) {
i++;
to++;
}
if (to <= 0xffff) {
if (from == to) re += esc(from);
else if (from + 1 == to) re += esc(from) + esc(to);
else re += esc(from) + "-" + esc(to);
} else {
astral.push(from - at, to - from);
at = to;
}
}
return {nonASCII: re, astral: astral};
}
var startData = generate(start), contData = generate(cont);
console.log(" var nonASCIIidentifierStartChars = \"" + startData.nonASCII + "\";");
console.log(" var nonASCIIidentifierChars = \"" + contData.nonASCII + "\";");
console.log(" var astralIdentifierStartCodes = " + JSON.stringify(startData.astral) + ";");
console.log(" var astralIdentifierCodes = " + JSON.stringify(contData.astral) + ";");
node bin/build-acorn.js
node bin/without_eval > dist/acorn_csp.js
# Combine existing list of authors with everyone known in git, sort, add header.
tail --lines=+3 AUTHORS > AUTHORS.tmp
git log --format='%aN' | grep -v abraidwood >> AUTHORS.tmp
echo -e "List of Acorn contributors. Updated before every release.\n" > AUTHORS
sort -u AUTHORS.tmp >> AUTHORS
rm -f AUTHORS.tmp
#!/usr/bin/env node
var fs = require("fs")
var acornSrc = fs.readFileSync(require.resolve("../dist/acorn"), "utf8")
var acorn = require("../dist/acorn"), walk = require("../dist/walk")
var ast = acorn.parse(acornSrc)
var touchups = [], uses = []
var makePred
walk.simple(ast, {
FunctionDeclaration: function(node) {
if (node.id.name == "makePredicate") {
makePred = node
touchups.push({text: "// Removed to create an eval-free library", from: node.start, to: node.end})
}
},
ObjectExpression: function(node) {
node.properties.forEach(function(prop) {
if (prop.value.type == "CallExpression" &&
prop.value.callee.name == "makePredicate")
uses.push(prop.value)
})
}
})
var results = []
var dryRun = acornSrc.slice(0, makePred.end) + "; makePredicate = (function(mp) {" +
"return function(words) { var r = mp(words); predicates.push(r); return r }})(makePredicate);" +
acornSrc.slice(makePred.end)
;(new Function("predicates", dryRun))(results)
uses.forEach(function (node, i) {
touchups.push({text: results[i].toString(), from: node.start, to: node.end})
})
var result = "", pos = 0
touchups.sort(function(a, b) { return a.from - b.from })
touchups.forEach(function(touchup) {
result += acornSrc.slice(pos, touchup.from)
result += touchup.text
pos = touchup.to
})
result += acornSrc.slice(pos)
process.stdout.write(result)
{
"name": "acorn",
"description": "ECMAScript parser",
"homepage": "https://github.com/marijnh/acorn",
"main": "dist/acorn.js",
"version": "1.2.2",
"engines": {
"node": ">=0.4.0"
},
"maintainers": [
{
"name": "Marijn Haverbeke",
"email": "marijnh@gmail.com",
"web": "http://marijnhaverbeke.nl"
},
{
"name": "Ingvar Stepanyan",
"email": "me@rreverser.com",
"web": "http://rreverser.com/"
}
],
"repository": {
"type": "git",
"url": "https://github.com/marijnh/acorn.git"
},
"license": "MIT",
"scripts": {
"test": "node test/run.js",
"prepublish": "bin/prepublish.sh"
},
"bin": {
"acorn": "./bin/acorn"
},
"devDependencies": {
"babelify": "^5.0.4",
"browserify": "^9.0.3",
"browserify-derequire": "^0.9.4",
"unicode-7.0.0": "~0.1.5"
},
"_from": "acorn@1.2.2",
"_resolved": "http://registry.npm.taobao.org/acorn/download/acorn-1.2.2.tgz"
}
\ No newline at end of file
// Acorn is a tiny, fast JavaScript parser written in JavaScript.
//
// Acorn was written by Marijn Haverbeke, Ingvar Stepanyan, and
// various contributors and released under an MIT license.
//
// Git repositories for Acorn are available at
//
// http://marijnhaverbeke.nl/git/acorn
// https://github.com/marijnh/acorn.git
//
// Please use the [github bug tracker][ghbt] to report issues.
//
// [ghbt]: https://github.com/marijnh/acorn/issues
//
// This file defines the main parser interface. The library also comes
// with a [error-tolerant parser][dammit] and an
// [abstract syntax tree walker][walk], defined in other files.
//
// [dammit]: acorn_loose.js
// [walk]: util/walk.js
import {Parser} from "./state"
import {getOptions} from "./options"
import "./parseutil"
import "./statement"
import "./lval"
import "./expression"
export {Parser, plugins} from "./state"
export {defaultOptions} from "./options"
export {SourceLocation} from "./location"
export {getLineInfo} from "./location"
export {Node} from "./node"
export {TokenType, types as tokTypes} from "./tokentype"
export {TokContext, types as tokContexts} from "./tokencontext"
export {isIdentifierChar, isIdentifierStart} from "./identifier"
export {Token} from "./tokenize"
export {isNewLine, lineBreak, lineBreakG} from "./whitespace"
export const version = "1.2.2"
// The main exported interface (under `self.acorn` when in the
// browser) is a `parse` function that takes a code string and
// returns an abstract syntax tree as specified by [Mozilla parser
// API][api].
//
// [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
export function parse(input, options) {
let p = parser(options, input)
let startPos = p.pos, startLoc = p.options.locations && p.curPosition()
p.nextToken()
return p.parseTopLevel(p.options.program || p.startNodeAt(startPos, startLoc))
}
// This function tries to parse a single expression at a given
// offset in a string. Useful for parsing mixed-language formats
// that embed JavaScript expressions.
export function parseExpressionAt(input, pos, options) {
let p = parser(options, input, pos)
p.nextToken()
return p.parseExpression()
}
// Acorn is organized as a tokenizer and a recursive-descent parser.
// The `tokenize` export provides an interface to the tokenizer.
export function tokenizer(input, options) {
return parser(options, input)
}
function parser(options, input) {
return new Parser(getOptions(options), String(input))
}
import {Parser} from "./state"
import {lineBreakG} from "./whitespace"
import {deprecate} from "util"
// These are used when `options.locations` is on, for the
// `startLoc` and `endLoc` properties.
export class Position {
constructor(line, col) {
this.line = line
this.column = col
}
offset(n) {
return new Position(this.line, this.column + n)
}
}
export class SourceLocation {
constructor(p, start, end) {
this.start = start
this.end = end
if (p.sourceFile !== null) this.source = p.sourceFile
}
}
// The `getLineInfo` function is mostly useful when the
// `locations` option is off (for performance reasons) and you
// want to find the line/column position for a given character
// offset. `input` should be the code string that the offset refers
// into.
export function getLineInfo(input, offset) {
for (let line = 1, cur = 0;;) {
lineBreakG.lastIndex = cur
let match = lineBreakG.exec(input)
if (match && match.index < offset) {
++line
cur = match.index + match[0].length
} else {
return new Position(line, offset - cur)
}
}
}
const pp = Parser.prototype
// This function is used to raise exceptions on parse errors. It
// takes an offset integer (into the current `input`) to indicate
// the location of the error, attaches the position to the end
// of the error message, and then raises a `SyntaxError` with that
// message.
pp.raise = function(pos, message) {
let loc = getLineInfo(this.input, pos)
message += " (" + loc.line + ":" + loc.column + ")"
let err = new SyntaxError(message)
err.pos = pos; err.loc = loc; err.raisedAt = this.pos
throw err
}
pp.curPosition = function() {
return new Position(this.curLine, this.pos - this.lineStart)
}
pp.markPosition = function() {
return this.options.locations ? [this.start, this.startLoc] : this.start
}
// Acorn: Loose parser
//
// This module provides an alternative parser (`parse_dammit`) that
// exposes that same interface as `parse`, but will try to parse
// anything as JavaScript, repairing syntax error the best it can.
// There are circumstances in which it will raise an error and give
// up, but they are very rare. The resulting AST will be a mostly
// valid JavaScript AST (as per the [Mozilla parser API][api], except
// that:
//
// - Return outside functions is allowed
//
// - Label consistency (no conflicts, break only to existing labels)
// is not enforced.
//
// - Bogus Identifier nodes with a name of `"✖"` are inserted whenever
// the parser got too confused to return anything meaningful.
//
// [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
//
// The expected use for this is to *first* try `acorn.parse`, and only
// if that fails switch to `parse_dammit`. The loose parser might
// parse badly indented code incorrectly, so **don't** use it as
// your default parser.
//
// Quite a lot of acorn.js is duplicated here. The alternative was to
// add a *lot* of extra cruft to that file, making it less readable
// and slower. Copying and editing the code allowed me to make
// invasive changes and simplifications without creating a complicated
// tangle.
import * as acorn from ".."
import {LooseParser} from "./state"
import "./tokenize"
import "./parseutil"
import "./statement"
import "./expression"
export {LooseParser} from "./state"
acorn.defaultOptions.tabSize = 4
export function parse_dammit(input, options) {
let p = new LooseParser(input, options)
p.next()
return p.parseTopLevel()
}
acorn.parse_dammit = parse_dammit
acorn.LooseParser = LooseParser
import {LooseParser} from "./state"
import {Node, SourceLocation, lineBreak, isNewLine, tokTypes as tt} from ".."
const lp = LooseParser.prototype
lp.startNode = function() {
let node = new Node
node.start = this.tok.start
if (this.options.locations)
node.loc = new SourceLocation(this.toks, this.tok.loc.start)
if (this.options.directSourceFile)
node.sourceFile = this.options.directSourceFile
if (this.options.ranges)
node.range = [this.tok.start, 0]
return node
}
lp.storeCurrentPos = function() {
return this.options.locations ? [this.tok.start, this.tok.loc.start] : this.tok.start
}
lp.startNodeAt = function(pos) {
let node = new Node
if (this.options.locations) {
node.start = pos[0]
node.loc = new SourceLocation(this.toks, pos[1])
pos = pos[0]
} else {
node.start = pos
}
if (this.options.directSourceFile)
node.sourceFile = this.options.directSourceFile
if (this.options.ranges)
node.range = [pos, 0]
return node
}
lp.finishNode = function(node, type) {
node.type = type
node.end = this.last.end
if (this.options.locations)
node.loc.end = this.last.loc.end
if (this.options.ranges)
node.range[1] = this.last.end
return node
}
lp.dummyIdent = function() {
let dummy = this.startNode()
dummy.name = "✖"
return this.finishNode(dummy, "Identifier")
}
export function isDummy(node) { return node.name == "✖" }
lp.eat = function(type) {
if (this.tok.type === type) {
this.next()
return true
} else {
return false
}
}
lp.isContextual = function(name) {
return this.tok.type === tt.name && this.tok.value === name
}
lp.eatContextual = function(name) {
return this.tok.value === name && this.eat(tt.name)
}
lp.canInsertSemicolon = function() {
return this.tok.type === tt.eof || this.tok.type === tt.braceR ||
lineBreak.test(this.input.slice(this.last.end, this.tok.start))
}
lp.semicolon = function() {
return this.eat(tt.semi)
}
lp.expect = function(type) {
if (this.eat(type)) return true
for (let i = 1; i <= 2; i++) {
if (this.lookAhead(i).type == type) {
for (let j = 0; j < i; j++) this.next()
return true
}
}
}
lp.pushCx = function() {
this.context.push(this.curIndent)
}
lp.popCx = function() {
this.curIndent = this.context.pop()
}
lp.lineEnd = function(pos) {
while (pos < this.input.length && !isNewLine(this.input.charCodeAt(pos))) ++pos
return pos
}
lp.indentationAfter = function(pos) {
for (let count = 0;; ++pos) {
let ch = this.input.charCodeAt(pos)
if (ch === 32) ++count
else if (ch === 9) count += this.options.tabSize
else return count
}
}
lp.closes = function(closeTok, indent, line, blockHeuristic) {
if (this.tok.type === closeTok || this.tok.type === tt.eof) return true
return line != this.curLineStart && this.curIndent < indent && this.tokenStartsLine() &&
(!blockHeuristic || this.nextLineStart >= this.input.length ||
this.indentationAfter(this.nextLineStart) < indent)
}
lp.tokenStartsLine = function() {
for (let p = this.tok.start - 1; p >= this.curLineStart; --p) {
let ch = this.input.charCodeAt(p)
if (ch !== 9 && ch !== 32) return false
}
return true
}
import {tokenizer, SourceLocation, tokTypes as tt} from ".."
export function LooseParser(input, options) {
this.toks = tokenizer(input, options)
this.options = this.toks.options
this.input = this.toks.input
this.tok = this.last = {type: tt.eof, start: 0, end: 0}
if (this.options.locations) {
let here = this.toks.curPosition()
this.tok.loc = new SourceLocation(this.toks, here, here)
}
this.ahead = []; // Tokens ahead
this.context = []; // Indentation contexted
this.curIndent = 0
this.curLineStart = 0
this.nextLineStart = this.lineEnd(this.curLineStart) + 1
}
import {tokTypes as tt, Token, isNewLine, SourceLocation, getLineInfo, lineBreakG} from ".."
import {LooseParser} from "./state"
const lp = LooseParser.prototype
function isSpace(ch) {
return (ch < 14 && ch > 8) || ch === 32 || ch === 160 || isNewLine(ch)
}
lp.next = function() {
this.last = this.tok
if (this.ahead.length)
this.tok = this.ahead.shift()
else
this.tok = this.readToken()
if (this.tok.start >= this.nextLineStart) {
while (this.tok.start >= this.nextLineStart) {
this.curLineStart = this.nextLineStart
this.nextLineStart = this.lineEnd(this.curLineStart) + 1
}
this.curIndent = this.indentationAfter(this.curLineStart)
}
}
lp.readToken = function() {
for (;;) {
try {
this.toks.next()
if (this.toks.type === tt.dot &&
this.input.substr(this.toks.end, 1) === "." &&
this.options.ecmaVersion >= 6) {
this.toks.end++
this.toks.type = tt.ellipsis
}
return new Token(this.toks)
} catch(e) {
if (!(e instanceof SyntaxError)) throw e
// Try to skip some text, based on the error message, and then continue
let msg = e.message, pos = e.raisedAt, replace = true
if (/unterminated/i.test(msg)) {
pos = this.lineEnd(e.pos + 1)
if (/string/.test(msg)) {
replace = {start: e.pos, end: pos, type: tt.string, value: this.input.slice(e.pos + 1, pos)}
} else if (/regular expr/i.test(msg)) {
let re = this.input.slice(e.pos, pos)
try { re = new RegExp(re) } catch(e) {}
replace = {start: e.pos, end: pos, type: tt.regexp, value: re}
} else if (/template/.test(msg)) {
replace = {start: e.pos, end: pos,
type: tt.template,
value: this.input.slice(e.pos, pos)}
} else {
replace = false
}
} else if (/invalid (unicode|regexp|number)|expecting unicode|octal literal|is reserved|directly after number|expected number in radix/i.test(msg)) {
while (pos < this.input.length && !isSpace(this.input.charCodeAt(pos))) ++pos
} else if (/character escape|expected hexadecimal/i.test(msg)) {
while (pos < this.input.length) {
let ch = this.input.charCodeAt(pos++)
if (ch === 34 || ch === 39 || isNewLine(ch)) break
}
} else if (/unexpected character/i.test(msg)) {
pos++
replace = false
} else if (/regular expression/i.test(msg)) {
replace = true
} else {
throw e
}
this.resetTo(pos)
if (replace === true) replace = {start: pos, end: pos, type: tt.name, value: "✖"}
if (replace) {
if (this.options.locations)
replace.loc = new SourceLocation(
this.toks,
getLineInfo(this.input, replace.start),
getLineInfo(this.input, replace.end))
return replace
}
}
}
}
lp.resetTo = function(pos) {
this.toks.pos = pos
let ch = this.input.charAt(pos - 1)
this.toks.exprAllowed = !ch || /[\[\{\(,;:?\/*=+\-~!|&%^<>]/.test(ch) ||
/[enwfd]/.test(ch) &&
/\b(keywords|case|else|return|throw|new|in|(instance|type)of|delete|void)$/.test(this.input.slice(pos - 10, pos))
if (this.options.locations) {
this.toks.curLine = 1
this.toks.lineStart = lineBreakG.lastIndex = 0
let match
while ((match = lineBreakG.exec(this.input)) && match.index < pos) {
++this.toks.curLine
this.toks.lineStart = match.index + match[0].length
}
}
}
lp.lookAhead = function(n) {
while (n > this.ahead.length)
this.ahead.push(this.readToken())
return this.ahead[n - 1]
}
export function isArray(obj) {
return Object.prototype.toString.call(obj) === "[object Array]"
}
// Checks if an object has a property.
export function has(obj, propName) {
return Object.prototype.hasOwnProperty.call(obj, propName)
}
// Matches a whole line break (where CRLF is considered a single
// line break). Used to count lines.
export const lineBreak = /\r\n?|\n|\u2028|\u2029/
export const lineBreakG = new RegExp(lineBreak.source, "g")
export function isNewLine(code) {
return code === 10 || code === 13 || code === 0x2028 || code == 0x2029
}
export const nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
Tue Sep 27 2016 16:03:35 GMT+0800 (CST)
\ No newline at end of file
{
"plugins": {
"node": true,
"es_modules": true
}
}
\ No newline at end of file
language: node_js
sudo: false
node_js:
- '0.12'
- '4'
- '5'
- '6'
# Combine existing list of authors with everyone known in git, sort, add header.
tail --lines=+3 AUTHORS > AUTHORS.tmp
git log --format='%aN' | grep -v abraidwood >> AUTHORS.tmp
echo -e "List of Acorn contributors. Updated before every release.\n" > AUTHORS
sort -u AUTHORS.tmp >> AUTHORS
rm -f AUTHORS.tmp
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment